File tree Expand file tree Collapse file tree 4 files changed +77
-0
lines changed
packages/bezier-react/src
components/AlphaTokenProvider Expand file tree Collapse file tree 4 files changed +77
-0
lines changed Original file line number Diff line number Diff line change
1
+ 'use client'
2
+
3
+ import React , { useMemo } from 'react'
4
+
5
+ import { tokens } from '@channel.io/bezier-tokens/alpha'
6
+
7
+ import { type ThemeName } from '~/src/types/tokens'
8
+ import { createContext } from '~/src/utils/react'
9
+
10
+ import {
11
+ type ThemeSpecificTokens ,
12
+ type TokenContextValue ,
13
+ type TokenProviderProps ,
14
+ } from './TokenProvider.types'
15
+
16
+ const [ AlphaTokenContextProvider , useAlphaTokenContext ] =
17
+ createContext < TokenContextValue | null > ( null , 'AlphaTokenProvider' )
18
+
19
+ export { useAlphaTokenContext }
20
+
21
+ const tokenSet : Record < ThemeName , ThemeSpecificTokens > = Object . freeze ( {
22
+ light : {
23
+ global : tokens . global ,
24
+ theme : tokens . lightTheme ,
25
+ } ,
26
+ dark : {
27
+ global : tokens . global ,
28
+ theme : tokens . darkTheme ,
29
+ } ,
30
+ } )
31
+
32
+ /**
33
+ * @private
34
+ */
35
+ export function TokenProvider ( { themeName, children } : TokenProviderProps ) {
36
+ return (
37
+ < AlphaTokenContextProvider
38
+ value = { useMemo (
39
+ ( ) => ( {
40
+ themeName,
41
+ tokens : tokenSet [ themeName ] ,
42
+ } ) ,
43
+ [ themeName ]
44
+ ) }
45
+ >
46
+ { children }
47
+ </ AlphaTokenContextProvider >
48
+ )
49
+ }
Original file line number Diff line number Diff line change
1
+ import {
2
+ type GlobalToken ,
3
+ type ThemeName ,
4
+ type ThemeToken ,
5
+ } from '~/src/types/alpha-tokens'
6
+
7
+ export interface ThemeSpecificTokens {
8
+ global : GlobalToken
9
+ theme : ThemeToken
10
+ }
11
+
12
+ export interface TokenContextValue {
13
+ themeName : ThemeName
14
+ tokens : ThemeSpecificTokens
15
+ }
16
+
17
+ export interface TokenProviderProps {
18
+ themeName : ThemeName
19
+ children : React . ReactNode
20
+ }
Original file line number Diff line number Diff line change
1
+ export {
2
+ TokenProvider as AlphaTokenProvider ,
3
+ useAlphaTokenContext ,
4
+ } from './TokenProvider'
5
+ export type { TokenProviderProps as AlphaTokenProviderProps } from './TokenProvider.types'
Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ import {
10
10
export type ThemeName = 'light' | 'dark'
11
11
12
12
export type GlobalToken = typeof tokens . global
13
+ /**
14
+ * FIXME: Separate functional and semantic tokens?
15
+ */
13
16
export type ThemeToken = typeof tokens . lightTheme | typeof tokens . darkTheme
14
17
15
18
// NOTE: (@ed) Do not remove alpha- prefix to match CSS variable names
You can’t perform that action at this time.
0 commit comments