-
Notifications
You must be signed in to change notification settings - Fork 0
feat(Theme): handle contextual tokens #1066
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
Open
pylafleur
wants to merge
8
commits into
master
Choose a base branch
from
dev/DS-1277
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6434b30
feat(Theme): add snapshot for default theme
pylafleur b002d12
feat(Theme): handle contextual tokens
pylafleur 4923f68
feat(Storybook): add toolbar menu for switching theme
pylafleur ae54024
feat(Storybook): remove theme switcher, fix viewport breakpoints
pylafleur ac69d7d
Merge remote-tracking branch 'origin/master' into dev/DS-1277
pylafleur ff87bca
feat(Storybook): revert viewport addon
pylafleur 43638c2
feat(Storybook): use refs for derived states
pylafleur b04f3ad
feat(Storybook): add desktop to token contexts
pylafleur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 45 additions & 16 deletions
61
packages/react/src/components/theme-wrapper/theme-wrapper.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,39 +1,68 @@ | ||
| import { FunctionComponent, PropsWithChildren, ReactNode } from 'react'; | ||
| import { FunctionComponent, PropsWithChildren } from 'react'; | ||
| import { ThemeProvider } from 'styled-components'; | ||
| import { useStyle } from '../../styles'; | ||
| import { equisoftTheme } from '../../theme'; | ||
| import { ResolvedTheme } from '../../themes/theme'; | ||
| import { buildTheme, equisoftThemeCustomization, ThemeCustomization, TokenContext } from '../../themes'; | ||
| import { ShadowWrapper } from '../shadow-wrapper/shadow-wrapper'; | ||
| import { DeviceContextProps, useDeviceContext } from '../device-context-provider/device-context-provider'; | ||
|
|
||
| export interface DisplayPreferences { | ||
| // User-provided preferences for display (density, contrast, motion, etc.) | ||
| } | ||
|
|
||
| export interface ThemeWrapperProps { | ||
| /** | ||
| * When true, components are mounted in the Shadow DOM | ||
| * @default false | ||
| */ | ||
| isolateStyles?: boolean; | ||
| theme?: ResolvedTheme; | ||
| themeCustomization?: ThemeCustomization; | ||
| displayPreferences?: DisplayPreferences; | ||
| } | ||
|
|
||
| // Context values should be added in order of importance. Later values will be applied over earlier values. | ||
| function getTokenContext( | ||
| deviceContext: DeviceContextProps, | ||
| // @ts-ignore Future use | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tu pourrais toujours switcher à |
||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| displayPreferences?: DisplayPreferences, | ||
| ): TokenContext[] { | ||
| const context: TokenContext[] = []; | ||
|
|
||
| if (deviceContext.isMobile) { | ||
| context.push('mobile'); | ||
| } | ||
|
|
||
| if (deviceContext.isTablet) { | ||
| context.push('tablet'); | ||
| } | ||
|
|
||
| if (deviceContext.isDesktop) { | ||
| context.push('desktop'); | ||
| } | ||
|
|
||
| return context; | ||
| } | ||
|
|
||
| /** | ||
| * @deprecated Use {@link DesignSystem} instead | ||
| */ | ||
| export const ThemeWrapper: FunctionComponent<PropsWithChildren<ThemeWrapperProps>> = ({ | ||
| children, | ||
| isolateStyles = false, | ||
| theme = equisoftTheme, | ||
| themeCustomization = equisoftThemeCustomization, | ||
| displayPreferences, | ||
| }) => { | ||
| let content: ReactNode; | ||
| if (isolateStyles) { | ||
| content = <ShadowWrapper>{children}</ShadowWrapper>; | ||
| } else { | ||
| content = children; | ||
| } | ||
| const deviceContext = useDeviceContext(); | ||
|
|
||
| const resolvedTheme = buildTheme( | ||
| themeCustomization, | ||
| getTokenContext(deviceContext, displayPreferences), | ||
| ); | ||
|
|
||
| useStyle(isolateStyles); | ||
|
|
||
| return ( | ||
| <ThemeProvider theme={theme}> | ||
| {content} | ||
| <ThemeProvider theme={resolvedTheme}> | ||
| {isolateStyles | ||
| ? <ShadowWrapper>{children}</ShadowWrapper> | ||
| : children} | ||
| </ThemeProvider> | ||
| ); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| export { equisoftTheme } from './themes/equisoft'; | ||
| export { ResolvedTheme, ThemeCustomization } from './themes/theme'; | ||
| export { buildTheme } from './themes/build-theme'; | ||
| export { | ||
| buildTheme, | ||
| equisoftThemeCustomization, | ||
| ResolvedTheme, | ||
| ThemeCustomization, | ||
| } from './themes'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Les modifs dans ce fichier sont essentiellement pour limiter les changements de state si les valeurs n'ont pas changé, et ainsi limiter les recompilations du thème