-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(theme): add theme for light & dark theme usage
- Loading branch information
Showing
3 changed files
with
76 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
- Typography | ||
- Size | ||
- Spacing | ||
- Light & Dark Theme | ||
- Components: '*' | ||
- Patterns: | ||
- Drag and drop | ||
|
44 changes: 44 additions & 0 deletions
44
packages/site-demo/content/product/foundations/light-dark-theme/index.mdx
This file contains 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,44 @@ | ||
import { ThemeProvider, Button, Chip, Flag, useTheme } from '@lumx/react'; | ||
|
||
# Light & Dark Theme | ||
|
||
By default, all component use a `light` theme that can be used on a light background. | ||
Some components provide an alternative `dark` theme that can be used to adapt to dark backgrounds. | ||
|
||
This theme is not synced to the user's preferred color scheme, it **must be activated manually**. | ||
|
||
## Activate via prop | ||
|
||
On the supported components, use the `theme` prop to activate the desired theme. | ||
|
||
<DemoBlock orientation="horizontal" backgroundColor={{ color: 'dark', variant: 'N' }} alwaysShowCode> | ||
<Button theme="dark">Dark Button</Button> | ||
<Chip theme="dark">Dark Chip</Chip> | ||
</DemoBlock> | ||
|
||
## Activate via context | ||
|
||
Use the `ThemeProvider` component to apply the desired theme to all of its children. | ||
|
||
<DemoBlock orientation="horizontal" backgroundColor={{ color: 'dark', variant: 'N' }} alwaysShowCode> | ||
<ThemeProvider value="dark"> | ||
<Button>Dark Button</Button> | ||
<Chip>Dark Chip</Chip> | ||
</ThemeProvider> | ||
</DemoBlock> | ||
|
||
Please note **some exceptions** to the theme context propagation: | ||
- The `Popover` ignores the theme context for now because most children that we put inside do not support the `dark` theme (List & ListItem) | ||
- The components `Popover`, `Lightbox` and `Dialog` all stop the propagation of the theme context and reset the theme because their children won't appear on the same background from where they are called | ||
|
||
Use the `useTheme()` hook to get the theme from the current theme context when you need to adapt within your custom component. | ||
|
||
<DemoBlock orientation="horizontal" backgroundColor={{ color: 'dark', variant: 'N' }}> | ||
{() => { | ||
function MyComponent() { | ||
const theme = useTheme(); | ||
return <Flag theme={theme} label={`Current theme: ${theme}`} />; | ||
} | ||
return <ThemeProvider value="dark"><MyComponent /></ThemeProvider>; | ||
}} | ||
</DemoBlock> |
This file contains 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