v0.102.0 - Themes
Migration Guide
Note: this will be pasted into the release notes on release.
- Remove
sportsbet-tokensfrompackage.jsonand addsportsbet-themes. - Extend the
styled-componentstype to benefit from features such as auto-complete. - Wrap your application with
ThemeProvider, moveGlobalinside it./* App.tsx */ import * as React from 'react'; import { Global } from '@heathmont/sportsbet-global'; import { ThemeProvider, sportsbetDark } from '@heathmont/sportsbet-themes'; export const App = () => ( <ThemeProvider theme={sportsbetDark}> <React.Fragment> <Global /> {/* Your App… */} </React.Fragment> </ThemeProvider> );
tokens > theme
Theme values can be accessed by 2 methods:
styledprop destructure:const Button = styled.button(({ theme: { color, space }}) => ({ color: color.piccolo[100], margin: space.default }));
useTheme()hook oruseContext()for non-styled components:import * as React from 'react'; import { useTheme, ThemeContext } from '@heathmont/sportsbet-themes'; const Example = () => { const { color } = useTheme(); // or const { color } = React.useContext(ThemeContext); return <p color={color.piccolo[100]}>hello</p>; }
Remove all references from sportsbet-tokens and replace with values from theme:
animation.speedanimation.speed.fast=>transitionDuration.defaultanimation.speed.default=>transitionDuration.default
borderborder.radius.<key>=>radius.<key>border.style=>borderStyleborder.width=>borderWidth- 🆕 make use of
borderfor a combo of the above.
breakpoints.<key>=>breakpoint.<key>colorcolors.palette.<paletteKey>[<number>]=>color.<paletteKey>[<number>]colors.background=>color.backgroundcolors.brand=>color.piccolo[100]colors.border=>color.gohan[100]colors.error=>color.chiChi[100]colors.neutral[10]=>color.bulma[100]colors.neutral[20]=>color.trunks[100]colors.neutral[30]=>color.goku[80]colors.neutral[40]=>color.goku[40]colors.neutral[50]=>color.goku[80]colors.neutral[60]=>color.gohan[100]colors.neutral[70]=>color.gohan[100]colors.neutral[90]=>color.hit[80]colors.text=>color.textcolors.warning=>color.krillin[40]
container=>maxWidthspacing=>spacetypgraphytypography.fontWeight=>fontWeighttypography.fontFamily=>fontFamily
utils
As utils no longer have access to tokens and can't access theme values (because it would go against the rules of hooks), some adjustments need to be made:
- Remove all references of
spacing()and replace with values fromtheme:spacing()=>rem(space.default)spacing('large')=>rem(space.large)- …etc.
- Modify all 'string' (container key, space key) usage of
container()and replace with values fromtheme:container('default')=>container(maxWidth.default)container('large')=>container(maxWidth.large)container('default', 'large')=>container(maxWidth.default, space.large)- …etc.
- Modify all argument-less
focus()references to the themed color value:focus(color.picollo[100]).- N.B. as
picollois theme specific value, we unfortunately can't set this as a default value. The default value is nowwhis[100]which is a shared color value and mimics the browser default blue focus ring.
- N.B. as
- Modify all argument-less
disabled()references to the themed opacity value:disabled(opacity.disabled).
- N.B. as
opacityis theme specific value, we unfortunately can't set this as a default value. Instead we make use of the hard-coded value in shared. To ensure your styles are themable, be sure to make this change.