1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00
unleash.unleash/website/docs/contributing/ADRs/front-end/preferred-styles-import-placement.md
Fredrik Strand Oseberg ad7c139992
fix: add ADR for domain language (#2541)
This PR puts our contributing guidelines in the sidebar of the unleash
documentation. Currently there was no way of navigating to them easily,
which made our contribution guides and ADRs less useful. This PR adds
them to the sidebar as their own category, and adds an ADR for domain
centric language.

Co-authored-by: Thomas Heartman <thomas@getunleash.ai>
2022-11-29 08:57:27 +01:00

1.6 KiB

title
ADR: preferred styles import placement

Background

SUPERSEDED BY ADR: Preferred styling method

In the codebase, we have found a need to standardise where to locate the styles import. When using CSS modules, the styles import placement matters for the priority of the styles if you are passing through styles to other components. IE:

// import order matters, because the useStyles in MyComponent now
// is after the useStyles import it will not take precedence if it has
// a styling conflict.
import useStyles from './SecondComponent.styles.ts';
import MyComponent from '../MyComponent/MyComponent.tsx';

const SecondComponent = () => {
    const styles = useStyles();

    return <MyComponent className={styles.overrideStyles} />
}

Decision

We have decided to always place style imports as the last import in the file, so that any components that the file may use can safely be overriden with styles from the parent component.

// Do:
import MyComponent from '../MyComponent/MyComponent.tsx';

import useStyles from './SecondComponent.styles.ts';

const SecondComponent = () => {
    const styles = useStyles();

    return <MyComponent className={styles.overrideStyles} />;
};

// Don't:
import useStyles from './SecondComponent.styles.ts';
import MyComponent from '../MyComponent/MyComponent.tsx';

const SecondComponent = () => {
    const styles = useStyles();

    return <MyComponent className={styles.overrideStyles} />;
};

The reason for this decision is to remove the posibillity for hard to find bugs, that are not obvious to detect and that might be time consuming to find a solution to.