-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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(ui): Storybook - Add theme switcher & noBorder option to <Sample /> #29765
Conversation
|
||
IconMoon.displayName = 'IconMoon'; | ||
|
||
export {IconMoon}; |
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.
IconMoon
is already part of the icon set in Figma. I just copied the SVG markup from there.
size-limit report
|
}; | ||
|
||
/** Expose the selected theme to children of <Sample /> */ | ||
export const SampleThemeContext = createContext<ThemeName>('light'); |
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.
Exporting SampleThemeContext
so children of Sample />
can consume it (via useContext(SampleThemeContext)
) for their own purposes.
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.
Hmm why would children need to use this value?
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.
In the Colors page that I'm working on, there are color samples for both light and dark mode:
These color samples need to show different values based on the current theme in <Sample />
, e.g. Gray 500 shows #2B2233
in light mode and #EBE6EF
in dark mode. This means they need to know which theme (light
/dark
) has been selected, hence the theme context.
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.
Ahh... are we going to have a separate palette for dark and light modes? I think the initial plan was to have a single palette (but not sure if that's still the plan)
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.
Yes, the plan is to have separate palettes 🌈
Adding two optional props to <Sample />: - noBorder: remove border and padding around the wrapper - showThemeSwitcher: add a toggle for switching between light and dark mode. Sample now provides a local theme context to automatically update the styles of all of its children.
dc6d96f
to
680a97c
Compare
docs-ui/components/sample.tsx
Outdated
showThemeSwitcher?: boolean; | ||
noBorder?: boolean; |
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.
Might be nice to add some /** */
comments here
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.
Good point
docs-ui/components/sample.tsx
Outdated
themeObject = theme === 'light' ? lightTheme : darkTheme; | ||
} else { | ||
themeObject = useTheme(); |
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.
You probably want themeObject
to be in state, it probably works fine most of the time because you call setTheme
, but this could lead to unwanted behavior because it's not in state.
docs-ui/components/sample.tsx
Outdated
return ( | ||
<Wrap> | ||
{showThemeSwitcher && ( | ||
<ThemeSwitcher onClick={() => toggleTheme()} active={theme === 'dark'}> |
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.
<ThemeSwitcher onClick={() => toggleTheme()} active={theme === 'dark'}> | |
<ThemeSwitcher onClick={toggleTheme} active={theme === 'dark'}> |
}; | ||
|
||
/** Expose the selected theme to children of <Sample /> */ | ||
export const SampleThemeContext = createContext<ThemeName>('light'); |
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.
Hmm why would children need to use this value?
@billyvg Added a commit addressing your points above. Tell me if it looks good (esp. how I added themeObject to state)! |
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.
Codewise, looks good
}; | ||
|
||
/** Expose the selected theme to children of <Sample /> */ | ||
export const SampleThemeContext = createContext<ThemeName>('light'); |
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.
Ahh... are we going to have a separate palette for dark and light modes? I think the initial plan was to have a single palette (but not sure if that's still the plan)
setThemeName('dark'); | ||
setTheme(darkTheme); |
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.
wonder if we should have the current theme name in theme itself... (I was avoiding it so that we wouldn't have logic based on theme name, and instead push people towards using theme aliases).
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.
thought of this myself! Would definitely make this cleaner, but wasn't sure if it's worth changing theme.tsx for it.
Adding two optional props to
<Sample />
:noBorder
: remove border and padding around the sample wrappershowThemeSwitcher
: add a toggle for switching between light and dark mode. Sample now provides a local theme context to automatically update the styles of all of its children.Without

noBorder
:With

noBorder
:With


showThemeSwitcher
enabled: