-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from omnifed/56-docs-add-usetheme-reference
56 docs add usetheme reference
- Loading branch information
Showing
22 changed files
with
787 additions
and
521 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
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
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 @@ | ||
declare module 'color-space' |
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
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
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
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 |
---|---|---|
@@ -1,22 +1,25 @@ | ||
import type { PropsWithChildren } from 'react' | ||
import { cx } from '@/styled-system/css' | ||
import { container } from '@/styled-system/patterns' | ||
import { markdown } from '../styles/markdown' | ||
import { | ||
PageLayout, | ||
PageMainContent, | ||
PageSideNav, | ||
PageSections, | ||
} from '../components/PageLayout' | ||
import SideNav, { type NavList } from '../components/SideNav' | ||
import sideNavData from './side-nav.json' | ||
|
||
interface ReactProps {} | ||
|
||
export default function ReactLayout(props: PropsWithChildren<ReactProps>) { | ||
return ( | ||
<div | ||
className={cx( | ||
container({ | ||
pt: '12', | ||
}), | ||
markdown, | ||
)} | ||
> | ||
<header>Nav sidebar</header> | ||
{props.children} | ||
</div> | ||
<PageLayout> | ||
<PageSideNav> | ||
<SideNav navList={sideNavData as NavList} /> | ||
</PageSideNav> | ||
|
||
<PageMainContent>{props.children}</PageMainContent> | ||
|
||
<PageSections>On this page</PageSections> | ||
</PageLayout> | ||
) | ||
} |
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
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
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,41 @@ | ||
[ | ||
{ | ||
"id": "1", | ||
"label": "Overview", | ||
"type": "heading" | ||
}, | ||
{ | ||
"id": "1:a", | ||
"label": "Installation", | ||
"route": "/react", | ||
"type": "route" | ||
}, | ||
{ | ||
"id": "2", | ||
"label": "Components", | ||
"type": "heading" | ||
}, | ||
{ | ||
"id": "2:a", | ||
"label": "Button", | ||
"route": "/react/button", | ||
"type": "route" | ||
}, | ||
{ | ||
"id": "3", | ||
"label": "Hooks", | ||
"type": "heading" | ||
}, | ||
{ | ||
"id": "3:a", | ||
"label": "useTheme", | ||
"route": "/react/use-theme", | ||
"type": "route" | ||
}, | ||
{ | ||
"id": "3:b", | ||
"label": "useThemeContext", | ||
"route": "/react/use-theme-context", | ||
"type": "route" | ||
} | ||
] |
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,96 @@ | ||
import { Admonition } from '@/app/components/Admonition' | ||
|
||
# useThemeContext | ||
|
||
The `useThemeContext` hook allows you to access or modify the theme and mode properties of the Cerberus Design System in multiple components. | ||
|
||
```ts showLineNumbers=false | ||
type DefaultThemes = 'cerberus' | ||
type ColorModes = 'light' | 'dark' | ||
|
||
define function useThemeContext( | ||
defaultTheme: DefaultThemes = 'cerberus', | ||
defaultColorMode: ColorModes = 'light', | ||
): { | ||
theme: DefaultThemes | ||
mode: ColorModes | ||
updateTheme: (theme: DefaultThemes) => void | ||
updateMode: (mode: ColorModes) => void | ||
} | ||
``` | ||
|
||
<Admonition | ||
heading="When to use" | ||
description="This hook is ideal for when you need to access or modify the theme or mode properties of the Cerberus Design System in multiple components." | ||
/> | ||
|
||
## Usage | ||
|
||
To use the `useThemeContext` hook, you need to wrap the component using the hook with the Cerberus `ThemeProvider` component. | ||
|
||
```tsx title="nav.tsx" {4} | ||
import { ThemeProvider, useThemeContext } from '@cerberus-design/react' | ||
|
||
function Nav() { | ||
const { theme, mode, udpateTheme, updateMode } = useThemeContext() | ||
|
||
function handleSetTheme(theme: string) { | ||
updateTheme('party-town') | ||
} | ||
|
||
function handleToggleMode() { | ||
updateMode((prev) => (prev === 'light' ? 'dark' : 'light')) | ||
} | ||
|
||
return ( | ||
<nav> | ||
<button onClick={handleSetTheme} type="button"> | ||
update theme to party-town | ||
</button> | ||
<button onClick={handleToggleMode} type="button"> | ||
toggle mode | ||
</button> | ||
</nav> | ||
) | ||
} | ||
``` | ||
|
||
```tsx title="header.tsx" {4} | ||
import { ThemeProvider, useThemeContext } from '@cerberus-design/react' | ||
|
||
function Header() { | ||
const { mode } = useThemeContext() | ||
|
||
return ( | ||
<h1> | ||
{mode === 'light' ? 'Hey, friend!' : 'I wear my sunglasses at night.'} | ||
</h1> | ||
) | ||
} | ||
``` | ||
|
||
```tsx title="layout.tsx" {7} | ||
import { ThemeProvider } from '@cerberus-design/react' | ||
import Header from './header' | ||
import Nav from './nav' | ||
|
||
function Layout() { | ||
return ( | ||
<ThemeProvider> | ||
<Nav /> | ||
<Header /> | ||
</ThemeProvider> | ||
) | ||
} | ||
``` | ||
|
||
<Admonition | ||
heading="When not to use" | ||
description="When you need to access or modify the theme or mode proprties in a single component, consider using the `useTheme` hook instead." | ||
/> | ||
|
||
## API | ||
|
||
### Arguments | ||
|
||
The `useThemeContext` hook accepts the same arguments as the [useTheme hook](/react/use-theme). |
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,5 @@ | ||
import UseThemeDoc from './doc.mdx' | ||
|
||
export default function UseThemePage() { | ||
return <UseThemeDoc /> | ||
} |
Oops, something went wrong.