-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add CozyTheme provider to handle normal and inverted themes and adapt existing UI #1062
Conversation
Note that I'm not happy with the way styles has to be initialized. This code should be done in every stylized component: const { colors } = useCozyTheme()
const [styles, setStyles] = useState<ButtonStyles | undefined>(undefined)
useEffect(() => {
setStyles(computeStyles(colors))
}, [colors])
if (styles === undefined) {
return null
} If you know a better way to handle this? |
d858cf7
to
f0671d1
Compare
f0671d1
to
ff49720
Compare
src/ui/Button/index.tsx
Outdated
|
||
if (styles === undefined) { | ||
return null | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels weird to have to handle that at the component level. We should think about an abstraction to handle that automatically (or use an existing design system)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this based on @zatteo suggestion: #1062 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice !
About the If yes, my suggestion : const { colors } = useCozyTheme()
const styles = computeStyles(colors)
// Or even if we are afraid about performance
const { colors } = useCozyTheme()
const styles = useMemo(() => computeStyles(colors), [colors]) |
ff49720
to
05c5150
Compare
Seen during a visio: styles can be undefined because useEffect is called after the first render. But this is not the case is we use I made the edit here: https://github.com/cozy/cozy-flagship-app/compare/ff49720a0876d94cdf1f6a0aa56c36b1a87af1f6..05c51500c15acbd85305377d6a0f280f164acf5f |
05c5150
to
1046a7e
Compare
We want to be able to concatenate all palette colors with Opacity hexadecimal digits This imply that the base color is using 6 hex digits, then when adding Opacity digits we obtain an 8 digits hexadecimal color
We want the UI to adapt to `normal` and `inverted` themes Until now we did not support Theming in the UI and we manually applied colors to component based on the expected result (`normal` or `inverted`) In the IAP feature we will need to reuse the `PromptingPage` component using `normal` theme, but this component is implemented for the `inverted` theme only So it is time to implement some Theming mechanism The `CozyTheme` provider will be responsible to enforce a theme (`normal` or `inverted`) to all its children This provider is inspired by the one on cozy-ui Then `useCozyTheme` hook can be used on every component and should return the current theme name and its corresponding colors palette This hook takes a `forcedVariant` parameter that can be used by top level components that are not embedded in the provider Related files: https://github.com/cozy/cozy-ui/blob/master/react/providers/CozyTheme/index.jsx
Current Button implementation takes a `children` and renders it The common Button usage is to render a `Typography` component in its children This implies that we know the `Typography` color to render based on the `Button` variant (primary, disabled etc) This behavior + the fact that there was no theming mechanism introduced some incorrect typography colors when add the Theming mechanism Instead of fixing every `Typography` color, we want to handle this inside the `Button` component, so no error can be made in the future
1046a7e
to
23aaff9
Compare
Tip
As usual this PR is meant to be read commit by commit
Also, to ease reading
styles.ts
files diffs you can hide whitespace diffsWe want the UI to adapt to
normal
andinverted
themesUntil now we did not support Theming in the UI and we manually applied colors to component based on the expected result (
normal
orinverted
)In the IAP feature we will need to reuse the
PromptingPage
component usingnormal
theme, but this component is implemented for theinverted
theme onlySo it is time to implement some Theming mechanism
The
CozyTheme
provider will be responsible to enforce a theme (normal
orinverted
) to all its childrenThis provider is inspired by the one on cozy-ui
Then
useCozyTheme
hook can be used on every component and should return the current theme name and its corresponding colors paletteThis hook takes a
forcedVariant
parameter that can be used by top level components that are not embedded in the providerRelated files:
https://github.com/cozy/cozy-ui/blob/master/react/providers/CozyTheme/index.jsx
This PR also ports some of the following components:
And the following views:
Some other components still have to be adapted but this can be done in another PR. The requirement was to adapt the PromptingPage. All edits on previous components were side effects as they would have been broken when porting PromptingPage
Next to this PR, the goal would be to adapt remaining components AND to get rid of this code that should not be in the palette (its place is in colours.ts as semantic variables)
TODO: