Design System Integration
Introduction
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 docs and using nextui createTheme
method.
nextui
is a library that uses stitches 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 docs.
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.
How to use
- The
<NextUIProvider>
is kept at the highest level in the component chain. This allows all of the components within it to inherit thetheme
prop. In case of our Next.js app the<NextUIProvider>
is added insrc/pages/_app.js
. nextui
provides a default theme that can be used out of the box.- To customize, create a theme using the structure defined by nextui create theme and wrap it in
createTheme
nextui method and store it assrc/themes/theme.js
. - Now in all
nextui
styled components, theme props is available to use as following:
export const Button = styled('button', {
fontSize: '$3',
color: '$fontColor',
margin: '1em',
padding: '0.25em 1em',
border: '2px solid black',
borderRadius: '$1',
display: 'block',
length: '1'
});
Know Issue
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.
Issue: https://github.com/modulz/stitches/issues/947
More about cutomizing theming can be found in nextui customize theme docs.