|
| 1 | + |
| 2 | + |
1 | 3 | --- |
2 | 4 | id: design-system |
3 | 5 | title: Design System Integration |
4 | 6 | sidebar_label: Design System Integration |
5 | 7 | --- |
6 | 8 |
|
7 | 9 | ## Introduction |
8 | | -A consistent design system is integrated to the all of the app types by using `styled-components` and `theme.js` file generated by [Theme Manager](http://theme-manager.com). |
9 | | - |
10 | | -`styled-component` is one of the most common ways to style components in the react ecosystem. It allows users to write styles in css within the js files. |
| 10 | +A consistent design system is integrated to the all of the app types by using `nextui` and `theme.js` file which can be generated by using the structure defined by [nextui create theme](https://nextui.org/docs/theme/typescript#create-theme) docs and using nextui `createTheme` method. |
11 | 11 |
|
12 | | -[Theme Manager](http://theme-manager.com) allows users to curate design tokens such as colors, space, border-radius, etc and then export them in a json object which then can be consumed within our apps. |
| 12 | +`nextui` is a library that uses [stitches](https://stitches.dev/) internally to style components in the react ecosystem. It allows users to write styles in css within the js files. It also has components and provides customized theming. To know more about nextui visit [nextui org](https://nextui.org/docs/guide/getting-started) docs. |
13 | 13 |
|
14 | | -`styled-components` provides `<ThemeProvider>` component which accepts a `theme` prop (json). The `<ThemeProvider>` is kept at the highest level in the component chain. This allows all of the components within it to inherit the `theme` prop. In case of our Next.js app the `<ThemeProvider>` is added in `src/pages/_app.js`. |
| 14 | +`nextui` provides `<NextUIProvider>` which is a theme provider component which accepts a `theme` prop (created using createTheme nextui method and json) which overrides the nextui default theme. |
15 | 15 |
|
16 | 16 | ## How to use |
17 | | -1. Create a theme using [Theme Manager](http://theme-manager.com). Download the theme and store it as `src/themes/theme.js`. |
18 | | -2. Now in all `styled-component`, theme prop is available to use as following: |
| 17 | +1. The `<NextUIProvider>` is kept at the highest level in the component chain. This allows all of the components within it to inherit the `theme` prop. In case of our Next.js app the `<NextUIProvider>` is added in `src/pages/_app.js`. |
| 18 | +2. `nextui` provides a default theme that can be used out of the box. |
| 19 | +3. To customize, create a theme using the structure defined by [nextui create theme](https://nextui.org/docs/theme/typescript#create-theme) and wrap it in `createTheme` nextui method and store it as `src/themes/theme.js`. |
| 20 | +4. Now in all `nextui` styled components, theme props is available to use as following: |
19 | 21 | ```jsx |
20 | | -export const Button = styled.button` |
21 | | - color: ${props => props.theme.colors.white[0]}; |
22 | | - font-size: 1em; |
23 | | - margin: 1em; |
24 | | - padding: 0.25em 1em; |
25 | | - border: 2px solid ${props => props.theme.colors.black[0]}; |
26 | | - background-color: ${props => props.theme.colors.black[0]}; |
27 | | - border-radius: 3px; |
28 | | - display: block; |
29 | | -`; |
| 22 | +export const Button = styled('button', { |
| 23 | + fontSize: '$3', |
| 24 | + color: '$fontColor', |
| 25 | + margin: '1em', |
| 26 | + padding: '0.25em 1em', |
| 27 | + border: '2px solid black', |
| 28 | + borderRadius: '$1', |
| 29 | + display: 'block', |
| 30 | + length: '1' |
| 31 | +}); |
30 | 32 | ``` |
31 | 33 |
|
32 | | -More about theming can be found in [styled-components](https://styled-components.com/docs/advanced#theming) docs. |
| 34 | +## Know Issue |
| 35 | +The `length` property used in styled method is added temporarily for the issue of nextui styled method with typescript v4.6.2. Will not be required once the issue is resolved. |
| 36 | +Issue: https://github.com/modulz/stitches/issues/947 |
| 37 | + |
| 38 | +--- |
| 39 | +More about cutomizing theming can be found in [nextui customize theme](https://nextui.org/docs/theme/customize-theme) docs. |
0 commit comments