-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66c7a8f
commit c870003
Showing
4 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
packages/bezier-react/src/components/AlphaTokenProvider/TokenProvider.tsx
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,49 @@ | ||
'use client' | ||
|
||
import React, { useMemo } from 'react' | ||
|
||
import { tokens } from '@channel.io/bezier-tokens/alpha' | ||
|
||
import { type ThemeName } from '~/src/types/tokens' | ||
import { createContext } from '~/src/utils/react' | ||
|
||
import { | ||
type ThemeSpecificTokens, | ||
type TokenContextValue, | ||
type TokenProviderProps, | ||
} from './TokenProvider.types' | ||
|
||
const [AlphaTokenContextProvider, useAlphaTokenContext] = | ||
createContext<TokenContextValue | null>(null, 'AlphaTokenProvider') | ||
|
||
export { useAlphaTokenContext } | ||
|
||
const tokenSet: Record<ThemeName, ThemeSpecificTokens> = Object.freeze({ | ||
light: { | ||
global: tokens.global, | ||
theme: tokens.lightTheme, | ||
}, | ||
dark: { | ||
global: tokens.global, | ||
theme: tokens.darkTheme, | ||
}, | ||
}) | ||
|
||
/** | ||
* @private | ||
*/ | ||
export function TokenProvider({ themeName, children }: TokenProviderProps) { | ||
return ( | ||
<AlphaTokenContextProvider | ||
value={useMemo( | ||
() => ({ | ||
themeName, | ||
tokens: tokenSet[themeName], | ||
}), | ||
[themeName] | ||
)} | ||
> | ||
{children} | ||
</AlphaTokenContextProvider> | ||
) | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/bezier-react/src/components/AlphaTokenProvider/TokenProvider.types.ts
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,20 @@ | ||
import { | ||
type GlobalToken, | ||
type ThemeName, | ||
type ThemeToken, | ||
} from '~/src/types/alpha-tokens' | ||
|
||
export interface ThemeSpecificTokens { | ||
global: GlobalToken | ||
theme: ThemeToken | ||
} | ||
|
||
export interface TokenContextValue { | ||
themeName: ThemeName | ||
tokens: ThemeSpecificTokens | ||
} | ||
|
||
export interface TokenProviderProps { | ||
themeName: ThemeName | ||
children: React.ReactNode | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/bezier-react/src/components/AlphaTokenProvider/index.ts
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 @@ | ||
export { | ||
TokenProvider as AlphaTokenProvider, | ||
useAlphaTokenContext, | ||
} from './TokenProvider' | ||
export type { TokenProviderProps as AlphaTokenProviderProps } from './TokenProvider.types' |
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