add initial contrast theme
This commit is contained in:
1 parent
c4e13e8e1b
commit
3fa99b28de
15 files changed
+168
-20
No files matched your search
@@ -8,6 +8,7 @@ const cx = classnames.bind(s)
|
||||
export type BoxProps = {
|
||||
as?: keyof HTMLElementTagNameMap
|
||||
children?: React.ReactNode
|
||||
className?: string
|
||||
style?: React.CSSProperties
|
||||
wrap?: boolean
|
||||
align?: boolean
|
||||
@@ -22,10 +23,11 @@ export const Box: React.FC<BoxProps> = ({
|
||||
center = false,
|
||||
align = true,
|
||||
style,
|
||||
className,
|
||||
...props
|
||||
}) => {
|
||||
const newProps = {
|
||||
className: cx(s.box, { vertical, align, center, wrap }),
|
||||
className: cx(s.box, className, { vertical, align, center, wrap }),
|
||||
style,
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import s from "./panel.module.css"
|
||||
|
||||
import { Box } from "../Box"
|
||||
|
||||
export type PanelProps = {
|
||||
children?: React.ReactNode
|
||||
style?: React.CSSProperties
|
||||
}
|
||||
|
||||
export const Panel: React.FC<PanelProps> = ({
|
||||
style,
|
||||
children,
|
||||
}) => {
|
||||
return (
|
||||
<Box vertical align={false} className={`${s.panel} ${s.default}`} style={style}>
|
||||
{children}
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
.panel {
|
||||
padding: var(--size-m);
|
||||
border-radius: var(--radius);
|
||||
}
|
||||
|
||||
.default {
|
||||
background-color: white;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { useState } from "react"
|
||||
import { ThemeContext } from "./ThemeContext"
|
||||
import { ThemeType } from "./types"
|
||||
|
||||
export type ThemeProps = {
|
||||
children?: React.ReactNode
|
||||
}
|
||||
|
||||
export const Theme: React.FC<ThemeProps> = ({ children }) => {
|
||||
const [theme, setTheme] = useState<ThemeType>("default")
|
||||
|
||||
return (
|
||||
<ThemeContext.Provider value={[theme, setTheme]}>
|
||||
{children}
|
||||
</ThemeContext.Provider>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { createContext } from "react"
|
||||
import { SetTheme, ThemeType } from "./types"
|
||||
|
||||
export const ThemeContext = createContext<[ThemeType, SetTheme]>("default")
|
||||
@@ -0,0 +1,2 @@
|
||||
export type ThemeType = "default" | "contrast"
|
||||
export type SetTheme = (theme: ThemeType) => void
|
||||
@@ -0,0 +1,15 @@
|
||||
import { useContext } from "react"
|
||||
import { ThemeContext } from "./ThemeContext"
|
||||
import { SetTheme, ThemeType } from "./types"
|
||||
|
||||
export type UseThemeResult = {
|
||||
theme: ThemeType
|
||||
setTheme: SetTheme
|
||||
// toggleTheme:
|
||||
}
|
||||
|
||||
export function useTheme(): UseThemeResult {
|
||||
const [theme, setTheme] = useContext(ThemeContext)
|
||||
|
||||
return { theme, setTheme }
|
||||
}
|
||||
Reference in new issue
Block a user