-
Notifications
You must be signed in to change notification settings - Fork 60
feat(react-cap-theme): Storybook Theme Switch #661
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
pixel-perfectionist
wants to merge
1
commit into
main
Choose a base branch
from
olkatruk/cap-theme/storybook-theme-switcher
base: main
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
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
7 changes: 7 additions & 0 deletions
7
change/@fluentui-contrib-react-cap-theme-3c82bedc-0a9f-45e0-9b6d-187286f83dd3.json
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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "none", | ||
| "comment": "add storybook theme switcher toolbar", | ||
| "packageName": "@fluentui-contrib/react-cap-theme", | ||
| "email": "Oleksandr.Katrukhin@microsoft.com", | ||
| "dependentChangeType": "none" | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| /* Let the themed FluentProvider fill the docs preview card instead of Storybook's default white frame. */ | ||
| #storybook-docs .sbdocs-preview { | ||
| background: transparent; | ||
| overflow: hidden; | ||
| } | ||
|
|
||
| #storybook-docs .innerZoomElementWrapper { | ||
| padding: 0; | ||
| } | ||
|
|
||
| #storybook-docs .docs-story .fui-FluentProvider { | ||
| width: 100%; | ||
| box-sizing: border-box; | ||
| padding: 30px; | ||
| border-radius: 9px; | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { | ||
| type Theme, | ||
| webDarkTheme, | ||
| webLightTheme, | ||
| } from '@fluentui/react-components'; | ||
| import type { FluentProviderProps } from '@fluentui/react-components'; | ||
| import { CAP_STYLE_HOOKS } from '../src/index'; | ||
| import type { CAPTokens } from '../src/components/tokens/types'; | ||
|
|
||
| const capLightTokens: CAPTokens = { | ||
| borderRadius2XLarge: '12px', | ||
| borderRadius3XLarge: '16px', | ||
| borderRadius4XLarge: '24px', | ||
| colorNeutralStroke4: '#ebebeb', | ||
| colorNeutralStroke4Hover: '#e0e0e0', | ||
| colorNeutralStroke4Pressed: '#d6d6d6', | ||
| colorNeutralStroke4Selected: '#ebebeb', | ||
| colorNeutralForeground5: '#616161', | ||
| colorNeutralForeground5Hover: '#242424', | ||
| colorNeutralForeground5Pressed: '#242424', | ||
| }; | ||
|
|
||
| const capDarkTokens: CAPTokens = { | ||
| borderRadius2XLarge: '12px', | ||
| borderRadius3XLarge: '16px', | ||
| borderRadius4XLarge: '24px', | ||
| colorNeutralStroke4: '#3d3d3d', | ||
| colorNeutralStroke4Hover: '#444444', | ||
| colorNeutralStroke4Pressed: '#4a4a4a', | ||
| colorNeutralStroke4Selected: '#3d3d3d', | ||
| colorNeutralForeground5: '#adadad', | ||
| colorNeutralForeground5Hover: '#ffffff', | ||
| colorNeutralForeground5Pressed: '#ffffff', | ||
| }; | ||
|
|
||
| const capLightTheme: Theme = { ...webLightTheme, ...capLightTokens }; | ||
| const capDarkTheme: Theme = { ...webDarkTheme, ...capDarkTokens }; | ||
|
|
||
| export type ThemeId = 'fluentLight' | 'fluentDark' | 'capLight' | 'capDark'; | ||
|
|
||
| type ThemeConfig = { | ||
| title: string; | ||
| theme: Theme; | ||
| styleHooks?: FluentProviderProps['customStyleHooks_unstable']; | ||
| }; | ||
|
|
||
| export const THEMES: Record<ThemeId, ThemeConfig> = { | ||
| fluentLight: { title: 'Fluent UI Light', theme: webLightTheme }, | ||
| fluentDark: { title: 'Fluent UI Dark', theme: webDarkTheme }, | ||
| capLight: { | ||
| title: 'CAP Light', | ||
| theme: capLightTheme, | ||
| styleHooks: CAP_STYLE_HOOKS, | ||
| }, | ||
| capDark: { | ||
| title: 'CAP Dark', | ||
| theme: capDarkTheme, | ||
| styleHooks: CAP_STYLE_HOOKS, | ||
| }, | ||
| }; | ||
|
|
||
| export const DEFAULT_THEME: ThemeId = 'capLight'; | ||
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.
With this configuration when switching from
fluent{Light/Dark}tocap{Light/Dark}theme, stories crashes.Fluent{Light/Dark} entries do not set any custom style hooks, so Fluent components fall back to internal noop style hooks (zero React hooks called inside). When the theme switcher selects CAP{Light/Dark}, it flips that prop (
customStyleHooks_unstable) on the same FluentProvider, so the same runs more hooks under CAP than under Fluent (and vice versa). React reconciles the same instance with a different hook count and crashes ("Rendered more/fewer hooks than expected") → white screen in the canvas.Note: on the Docs page the components still render — each example remounts inside Storybook's per-example error boundary, so the crash is swallowed visually — but the error is still thrown and logged in the browser DevTools console. The Default (component canvas) stories have no such boundary, so they crash completely with a white screen.
Fix:
Drop the fluentLight / fluentDark entries and keep only the CAP ones:
Rationale: The tokens in capLightTokens and capDarkTokens that extend webLightTheme / webDarkTheme are already part of Fluent UI core's token set in recent versions. They only need to be patched in here because the contrib package is pinned to an older
@fluentui/react-components. Once that dependency is bumped, these capLightTokens / capDarkTokens overrides become redundant and can be deleted — capLightTheme would collapse to webLightTheme (same for dark), so the stories would render identically with no manual token patching needed.