-
Notifications
You must be signed in to change notification settings - Fork 21
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
7bc0210
commit ba82748
Showing
84 changed files
with
1,326 additions
and
969 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
16 changes: 16 additions & 0 deletions
16
components/src/components/atoms/Button/utils/getValidatedColor.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,16 @@ | ||
import { BaseColour, validateBaseColour } from '@/src/tokens/color3' | ||
|
||
export type Color = BaseColour | ||
|
||
export type WithColor = { color: Color } | ||
|
||
export const getValidatedColor = ( | ||
color?: Color, | ||
fallback = '$textPrimary', | ||
): string => { | ||
if (!color) return fallback | ||
const matches = color.match('^(.*?)(Primary|Secondary)?$') | ||
const baseColor = matches?.[1] || 'accent' | ||
const validatedColor = validateBaseColour(baseColor, 'accent') | ||
return `$${validatedColor}Primary` | ||
} |
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
38 changes: 38 additions & 0 deletions
38
components/src/components/atoms/ThemeProvider/ThemeProvider.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,38 @@ | ||
import * as React from 'react' | ||
|
||
type Mode = 'dark' | 'light' | ||
|
||
type ThemeContextValue = { | ||
mode: Mode | ||
setMode: (mode: Mode) => void | ||
} | ||
|
||
const ThemeContext = React.createContext<ThemeContextValue | null>(null) | ||
|
||
type Props = { | ||
defaultMode?: Mode | ||
} | ||
export const ThemeProvider = ({ | ||
defaultMode = 'light', | ||
children, | ||
}: React.PropsWithChildren<Props>) => { | ||
const [mode, setMode] = React.useState<Mode>(defaultMode) | ||
|
||
const value = React.useMemo(() => ({ mode, setMode }), [mode]) | ||
|
||
React.useEffect(() => { | ||
const root = document.querySelector(':root') | ||
if (root) { | ||
root.setAttribute('data-theme', mode) | ||
} | ||
}, [mode]) | ||
return <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider> | ||
} | ||
|
||
export const useTheme = () => { | ||
const context = React.useContext(ThemeContext) | ||
if (context === null) { | ||
throw new Error('useTheme must be used within a ThemeProvider') | ||
} | ||
return context | ||
} |
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 @@ | ||
export { ThemeProvider, useTheme } from './ThemeProvider' |
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
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
21 changes: 21 additions & 0 deletions
21
components/src/components/molecules/ThemeToggle/ThemeToggle.test.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,21 @@ | ||
import * as React from 'react' | ||
|
||
import { ThemeProvider } from 'styled-components' | ||
|
||
import { cleanup, render } from '@/test' | ||
|
||
import { lightTheme } from '@/src/tokens' | ||
|
||
import { ThemeToggle } from './ThemeToggle' | ||
|
||
describe('<CurrencyToggle />', () => { | ||
afterEach(cleanup) | ||
|
||
it('renders', () => { | ||
render( | ||
<ThemeProvider theme={lightTheme}> | ||
<ThemeToggle /> | ||
</ThemeProvider>, | ||
) | ||
}) | ||
}) |
Oops, something went wrong.