Skip to content
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

Implement multi theme feature based on data attributes #1756

Merged
merged 29 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6fdefea
feat: implement alpha bezier provider (wip)
sungik-choi Nov 23, 2023
3e0fa8f
feat(styles): add color-scheme style
sungik-choi Nov 23, 2023
0b4e6ea
chore(styles): add comment
sungik-choi Nov 23, 2023
1c73be3
feat(styles): add base font color style
sungik-choi Nov 23, 2023
9935160
feat(bezier-react): implement useToken hook
sungik-choi Nov 28, 2023
244f5cf
refactor(use-token): include token set
sungik-choi Nov 28, 2023
1677c2f
feat(use-tokens): add themeName value to context value and implement …
sungik-choi Nov 28, 2023
b0fc27b
feat: implement fixed theme providers
sungik-choi Nov 28, 2023
367a0c6
feat(alpha-bezier-provider): add tooltip provider
sungik-choi Nov 28, 2023
187450b
feat(alpha-bezier-provider): consider when other root elements may ex…
sungik-choi Nov 28, 2023
52bc57d
feat(alpha-bezier-provider): add feature provider
sungik-choi Nov 28, 2023
c10dc90
refactor: rename to AlphaAppProvider
sungik-choi Nov 28, 2023
58e123a
fix(styles): change html to where selector to support shadow root hos…
sungik-choi Nov 28, 2023
7975f56
fix(styles): change data selector to affect all elements
sungik-choi Nov 28, 2023
59158f4
refactor(alpha-app-provider): rename prop
sungik-choi Nov 29, 2023
0ed795c
docs(alpha-app-provider): add jsdoc
sungik-choi Nov 29, 2023
4462f81
docs: add jsdoc
sungik-choi Nov 29, 2023
4c3c887
feat(root): export modules
sungik-choi Nov 29, 2023
45606aa
chore(changeset): add changeset
sungik-choi Nov 29, 2023
dce4b9c
fix: fix typecheck error
sungik-choi Nov 29, 2023
e96e4de
fix: fix import path
sungik-choi Nov 29, 2023
c943fa1
refactor(window-provider): rm document from window provider
sungik-choi Nov 29, 2023
3c98893
feat(alpha-app-provider): apply WindowProvider and add window prop
sungik-choi Nov 29, 2023
f2090b9
feat(alpha-app-provider): change to use ThemeProvider internally
sungik-choi Nov 29, 2023
f8befb7
feat(styles): rm root color scheme
sungik-choi Nov 29, 2023
f2faf6b
feat: back to the root element
sungik-choi Nov 29, 2023
9776221
feat(theme-provider): apply the changed design token structure
sungik-choi Nov 30, 2023
257b8d9
refactor(theme-provider): add Provider suffix
sungik-choi Dec 1, 2023
d89ea83
refactor(alpha-app-provider): change callback fn name
sungik-choi Dec 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/bezier-react/src/hooks/useToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { type tokens } from '@channel.io/bezier-tokens'
yangwooseong marked this conversation as resolved.
Show resolved Hide resolved

import { createContext } from '~/src/utils/reactUtils'

type Tokens = typeof tokens
type GlobalTokens = Tokens['global']
type SemanticTokens = Omit<Tokens, 'global'>

export type TokenContextValue = GlobalTokens & SemanticTokens[keyof SemanticTokens]

const [TokenContextProvider, useTokenContext] = createContext<TokenContextValue | null>(null, 'ThemeContext')

function useToken() {
return useTokenContext('useToken')
}

export {
/** For internal use only.
* @private
*/
TokenContextProvider,
}

export default useToken
31 changes: 8 additions & 23 deletions packages/bezier-react/src/providers/AlphaBezierProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import React, {
useEffect,
useMemo,
} from 'react'
import React, { useEffect } from 'react'

import { tokens } from '@channel.io/bezier-tokens'

import { document } from '~/src//utils/domUtils'
import { createContext } from '~/src/utils/reactUtils'
import { TokenContextProvider } from '~/src/hooks/useToken'
import { document } from '~/src/utils/domUtils'

// TODO: Change theme name constant to import from bezier-tokens
type ThemeName = 'light' | 'dark'
export type ThemeName = 'light' | 'dark'

const tokenSet = {
const tokenSet = Object.freeze({
light: {
...tokens.global,
...tokens.lightTheme,
Expand All @@ -20,15 +17,7 @@ const tokenSet = {
...tokens.global,
...tokens.darkTheme,
},
} as const

interface ThemeContextValue {
themeName: ThemeName
tokens: typeof tokenSet[ThemeName]
}

const [ThemeContextProvider] =
createContext<ThemeContextValue | null>(null, 'ThemeContext')
} as const)

interface AlphaBezierProviderProps {
themeName?: ThemeName
Expand All @@ -49,13 +38,9 @@ function AlphaBezierProvider({
}, [themeName])

return (
<ThemeContextProvider value={useMemo(() => ({
themeName,
tokens: tokenSet[themeName],
}), [themeName])}
>
<TokenContextProvider value={tokenSet[themeName]}>
{ children }
</ThemeContextProvider>
</TokenContextProvider>
)
}

Expand Down