0.14.4 • Published 1 day ago

@equinor/mad-components v0.14.4

Weekly downloads
-
License
MIT
Repository
-
Last release
1 day ago

MAD Components

This is a library of EDS components for React Native. Using this library should feel similar as for EDS for React.

🧑‍🏫 How to use

Installation

npm

npm install @equinor/mad-components

yarn

yarn add @equinor/mad-components

NOTE:

The component library requires the following libraries to properly function:

Please make sure to follow these installation instructions before using this package.

Getting started

Before using the components in your app, make sure to load the fonts and assets required by the library somewhere in your root component. It is also recommended that you wrap your app in the EDSProvider. This will give you access to dynamically switching between tablet and phone mode as well as dark and light mode support:

export default function App() {
    const [hasLoadedEds, edsLoadError] = useEDS();
    if (!hasLoadedEds) {
        return null;
    } else {
        return (
            <SafeAreaProvider>
                <EDSProvider colorScheme="light" density="phone">
                    <Navigation colorScheme="light" />
                    <StatusBar />
                </EDSProvider>
            </SafeAreaProvider>
        );
    }
}

🖼️ Theming

Creating stylesheets that use EDS values is made to be easy and performant. Start by creating a EDSStyleSheet, almost just like for a normal React Native StyleSheet:

const themeStyles = EDSStyleSheet.create(theme => ({
    container: {
        backgroundColor: theme.colors.container.background,
        borderRadius: theme.geometry.border.containerBorderRadius,
    },
}));

Notice that we pass theme into our style sheet. This is a resolved token based on the current configuration of the app. This means that the value for theme.colors.container can change between light/dark mode without you having to worry about anything 😎

We resolve our stylesheet in our components using the provided useStyles hook:

const MyComponent = () => {
    const styles = useStyles(themeStyles);
    return <View style={styles.container} />;
};

Ideally, all styling, be it conditional or not should happen outside of our components to reduce clutter. The EDSStyleSheet.create callback method accepts a second optional argument which allows you to pass any additional props into the style sheet:

// Notice that we type our second argument!
const themeStylesWithProps = EDSStyleSheet.create((theme, props: { color?: string }) => {
    const backgroundColor = color ?? theme.colors.container.background;

    return {
        container: {
            backgroundColor,
        },
    };
});

We are then required by our useStyle hook to pass these props in with the EDSStyleSheet:

const MyOtherComponent = () => {
    // Normally you'd pass some of your component props into this hook.
    const styles = useStyles(themeStylesWithProps, { color: "red" });
    return <View style={styles.container} />;
};
0.14.4

1 day ago

0.14.3

15 days ago

0.14.2

21 days ago

0.14.1

23 days ago

0.13.2

1 month ago

0.14.0

29 days ago

0.13.1

1 month ago

0.13.0

3 months ago

0.12.10

3 months ago

0.12.8

3 months ago

0.12.9

3 months ago

0.12.7

3 months ago

0.12.6

3 months ago

0.12.3

3 months ago

0.12.4

3 months ago

0.12.5

3 months ago

0.12.0

3 months ago

0.12.1

3 months ago

0.12.2

3 months ago

0.11.3

3 months ago

0.11.2

4 months ago

0.11.1

4 months ago

0.11.0

4 months ago

0.10.0

4 months ago

0.9.0

4 months ago

0.8.6

4 months ago

0.8.5

5 months ago

0.8.4

5 months ago

0.8.3

5 months ago

0.8.2

5 months ago

0.6.7

7 months ago

0.6.6

7 months ago

0.6.9

7 months ago

0.6.8

7 months ago

0.8.1

5 months ago

0.6.3

7 months ago

0.5.4

8 months ago

0.8.0

6 months ago

0.6.2

7 months ago

0.5.3

8 months ago

0.6.5

7 months ago

0.6.4

7 months ago

0.5.0

8 months ago

0.4.1

9 months ago

0.4.0

9 months ago

0.7.0

6 months ago

0.6.1

7 months ago

0.5.2

8 months ago

0.6.0

7 months ago

0.5.1

8 months ago

0.4.2

8 months ago

0.3.2

11 months ago

0.3.1

11 months ago

0.3.0

12 months ago

0.2.5

12 months ago

0.2.4

12 months ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago