Skip to content

Commit 5813d36

Browse files
authored
Merge pull request #14 from ethereum/recover-chakra-theme
Sync Chakra theme files
2 parents 0cd4b4d + a112960 commit 5813d36

File tree

16 files changed

+1210
-31
lines changed

16 files changed

+1210
-31
lines changed

src/@chakra-ui/components/Alert.ts

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import {
2+
createMultiStyleConfigHelpers,
3+
SystemStyleObject,
4+
} from "@chakra-ui/react"
5+
import { alertAnatomy } from "@chakra-ui/anatomy"
6+
import { alertDefaultTheme, defineMergeStyles } from "./components.utils"
7+
import { AlertStatusType } from "@/components/Alert"
8+
9+
const STATUS_COLORS: Record<
10+
"solid" | "subtle",
11+
Record<AlertStatusType, SystemStyleObject>
12+
> = {
13+
solid: {
14+
error: {
15+
bg: "error.base",
16+
color: "error.light",
17+
},
18+
info: {
19+
bg: "body.medium",
20+
color: "background.base",
21+
},
22+
warning: {
23+
bg: "attention.base",
24+
color: "attention.light",
25+
},
26+
success: {
27+
bg: "success.base",
28+
color: "success.light",
29+
},
30+
},
31+
subtle: {
32+
error: {
33+
bg: "error.light",
34+
color: "error.base",
35+
},
36+
info: {
37+
bg: "background.highlight",
38+
color: "body.base",
39+
},
40+
warning: {
41+
bg: "attention.light",
42+
color: "gray.700",
43+
},
44+
success: {
45+
bg: "success.light",
46+
color: "success",
47+
},
48+
},
49+
}
50+
51+
const { baseStyle: alertBaseStyle } = alertDefaultTheme
52+
53+
const { defineMultiStyleConfig, definePartsStyle } =
54+
createMultiStyleConfigHelpers(alertAnatomy.keys)
55+
56+
const baseStyleContainer = defineMergeStyles(alertBaseStyle?.container, {
57+
justifyContent: "center",
58+
gap: 2,
59+
})
60+
61+
const baseStyleIcon = defineMergeStyles(alertBaseStyle?.icon, {
62+
me: 2,
63+
})
64+
65+
const baseStyle = definePartsStyle({
66+
container: baseStyleContainer,
67+
icon: baseStyleIcon,
68+
})
69+
70+
const variantSolid = definePartsStyle((props) => ({
71+
container: {
72+
...STATUS_COLORS["solid"][props.status],
73+
},
74+
}))
75+
76+
const variantSubtle = definePartsStyle((props) => ({
77+
container: {
78+
...STATUS_COLORS["subtle"][props.status],
79+
},
80+
}))
81+
82+
const variants = {
83+
solid: variantSolid,
84+
subtle: variantSubtle,
85+
}
86+
87+
export const Alert = defineMultiStyleConfig({
88+
baseStyle,
89+
variants,
90+
defaultProps: {
91+
variant: "solid",
92+
},
93+
})
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import {
2+
createMultiStyleConfigHelpers,
3+
cssVar,
4+
defineStyle,
5+
getToken,
6+
} from "@chakra-ui/react"
7+
import { avatarAnatomy } from "@chakra-ui/anatomy"
8+
import { avatarDefaultTheme, defineMergeStyles } from "./components.utils"
9+
import { pick } from "lodash"
10+
11+
const { defineMultiStyleConfig, definePartsStyle } =
12+
createMultiStyleConfigHelpers(avatarAnatomy.keys)
13+
14+
const { baseStyle: defaultBaseStyle, sizes: defaultSizes } = avatarDefaultTheme
15+
16+
const $border = cssVar("avatar-border-color", "transparent")
17+
const $mlBySize = cssVar("ml-by-size")
18+
19+
const baseStyleContainer = defineStyle((props) => {
20+
const primaryLowContrast = getToken(
21+
"colors",
22+
"primary.lowContrast"
23+
)(props.theme)
24+
25+
return defineMergeStyles(defaultBaseStyle?.(props).container, {
26+
[$border.variable]: "transparent",
27+
borderWidth: "1px",
28+
"&:hover, [data-peer]:hover ~ &": {
29+
boxShadow: `0.15em 0.15em 0 ${primaryLowContrast}`,
30+
},
31+
_focus: {
32+
outline: "4px solid",
33+
outlineColor: "primary.hover",
34+
outlineOffset: "-1px",
35+
},
36+
_active: {
37+
[$border.variable]: "colors.primary.hover",
38+
boxShadow: "none",
39+
"& img": {
40+
opacity: 0.7,
41+
},
42+
},
43+
"[role='group'] &": {
44+
[$border.variable]: "colors.background.base",
45+
_notLast: {
46+
marginLeft: $mlBySize.reference,
47+
},
48+
},
49+
})
50+
})
51+
52+
const baseStyleExessLabel = defineStyle((props) =>
53+
defineMergeStyles(defaultBaseStyle?.(props).excessLabel, {
54+
bg: "body.base",
55+
color: "background.base",
56+
ms: $mlBySize.reference,
57+
})
58+
)
59+
60+
const baseStyle = definePartsStyle((props) => ({
61+
container: baseStyleContainer(props),
62+
excessLabel: baseStyleExessLabel(props),
63+
}))
64+
65+
const USED_SIZES = ["xs", "sm", "md", "lg"] as const
66+
67+
const pickedDefaultSizes: { [k in (typeof USED_SIZES)[number]]?: object } =
68+
pick(defaultSizes, ...USED_SIZES)
69+
70+
const sizes = defineMergeStyles(pickedDefaultSizes, {
71+
xs: {
72+
group: {
73+
[$mlBySize.variable]: "space.-1",
74+
},
75+
excessLabel: {
76+
fontSize: "0.563rem",
77+
},
78+
},
79+
sm: {
80+
group: {
81+
[$mlBySize.variable]: "space.-2",
82+
},
83+
excessLabel: {
84+
fontSize: "sm",
85+
},
86+
},
87+
})
88+
89+
export const Avatar = defineMultiStyleConfig({
90+
baseStyle,
91+
// @ts-expect-error
92+
sizes,
93+
})

src/@chakra-ui/components/Badge.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { defineStyle, defineStyleConfig } from "@chakra-ui/react"
2+
import { badgeDefaultTheme, defineMergeStyles } from "./components.utils"
3+
4+
const { baseStyle: defaultBaseStyle } = badgeDefaultTheme
5+
6+
const baseStyle = defineMergeStyles(defaultBaseStyle, {
7+
borderRadius: "base",
8+
border: "1px solid",
9+
borderColor: "transparent",
10+
fontWeight: "initial",
11+
py: 1,
12+
px: 2,
13+
textTransform: "uppercase",
14+
})
15+
16+
const variantSecondary = defineStyle({
17+
borderColor: "primary100",
18+
color: "text",
19+
})
20+
21+
const variantSolid = defineStyle({
22+
color: "black300",
23+
background: "primary100",
24+
})
25+
26+
export const Badge = defineStyleConfig({
27+
baseStyle,
28+
variants: {
29+
solid: variantSolid,
30+
secondary: variantSecondary,
31+
},
32+
sizes: {
33+
sm: {
34+
py: 0,
35+
},
36+
lg: {
37+
px: 3,
38+
},
39+
},
40+
defaultProps: {
41+
variant: "solid",
42+
},
43+
})
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { createMultiStyleConfigHelpers, defineStyle } from "@chakra-ui/react"
2+
import { checkboxAnatomy } from "@chakra-ui/anatomy"
3+
import {
4+
checkboxDefaultTheme,
5+
commonInputTriggerStyles,
6+
defineMergeStyles,
7+
} from "./components.utils"
8+
9+
const { sizes: defaultSizes } = checkboxDefaultTheme
10+
11+
const { definePartsStyle, defineMultiStyleConfig } =
12+
createMultiStyleConfigHelpers(checkboxAnatomy.keys)
13+
14+
const { commonContainerProps, commonControlProps, commonLabelProps } =
15+
commonInputTriggerStyles
16+
17+
const checkboxMdSize = defaultSizes?.md
18+
19+
const baseStyleControl = defineMergeStyles(
20+
checkboxMdSize?.control,
21+
commonControlProps,
22+
{
23+
boxSize: "var(--checkbox-size)", // Comes from default theme
24+
borderRadius: "sm",
25+
}
26+
)
27+
28+
const baseStyleLabel = defineStyle({ ...commonLabelProps })
29+
30+
const baseStyleContainer = defineStyle({ ...commonContainerProps })
31+
32+
const baseStyleIcon = defineStyle({
33+
boxSize: 2,
34+
})
35+
36+
const baseStyle = definePartsStyle({
37+
container: baseStyleContainer,
38+
control: baseStyleControl,
39+
label: baseStyleLabel,
40+
icon: baseStyleIcon,
41+
})
42+
43+
export const Checkbox = defineMultiStyleConfig({
44+
baseStyle,
45+
})

src/@chakra-ui/components/Input.ts

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import { inputAnatomy } from "@chakra-ui/anatomy"
2+
import {
3+
createMultiStyleConfigHelpers,
4+
defineStyle,
5+
} from "@chakra-ui/styled-system"
6+
import { defineMergeStyles, inputDefaultTheme } from "./components.utils"
7+
8+
const { defineMultiStyleConfig, definePartsStyle } =
9+
createMultiStyleConfigHelpers(inputAnatomy.keys)
10+
11+
const baseStyle = definePartsStyle((props) => {
12+
const {
13+
focusBorderColor: fc = "primaryHover",
14+
errorBorderColor: ec = "errorOutline",
15+
} = props
16+
17+
return defineMergeStyles(
18+
inputDefaultTheme.baseStyle,
19+
inputDefaultTheme.variants?.outline(props),
20+
{
21+
field: {
22+
borderColor: "currentColor",
23+
borderRadius: "base",
24+
outline: "3px solid transparent",
25+
lineHeight: 1,
26+
_placeholder: {
27+
color: "disabled",
28+
opacity: 1,
29+
},
30+
_focusVisible: {
31+
outlineColor: fc,
32+
outlineOffset: "-1px",
33+
borderColor: "transparent",
34+
boxShadow: "none",
35+
},
36+
_hover: null, // override default
37+
_groupHover: {
38+
borderColor: "primary.hover",
39+
},
40+
_invalid: {
41+
borderColor: ec,
42+
boxShadow: "none",
43+
},
44+
_disabled: {
45+
borderColor: "disabled",
46+
opacity: 1,
47+
},
48+
"&:not(:disabled)": {
49+
_active: {
50+
bg: "background.highlight",
51+
borderColor: "primary.highContrast",
52+
},
53+
},
54+
},
55+
element: {
56+
fontSize: "2xl",
57+
transitionProperty: "common",
58+
transitionDuration: "normal",
59+
_groupHover: {
60+
color: "primary.hover",
61+
},
62+
_peerFocusVisible: {
63+
color: fc,
64+
_peerInvalid: {
65+
color: ec,
66+
},
67+
_peerDisabled: {
68+
color: "disabled",
69+
},
70+
},
71+
_peerDisabled: {
72+
color: "disabled",
73+
},
74+
"[data-peer]:not(:disabled):active ~ &": {
75+
color: "primary.dark",
76+
_dark: {
77+
color: "primary.highContrast",
78+
},
79+
},
80+
},
81+
}
82+
)
83+
})
84+
85+
const size = {
86+
md: defineStyle({
87+
h: 10.5,
88+
px: 2,
89+
}),
90+
sm: defineStyle({
91+
h: 8,
92+
px: 1,
93+
}),
94+
}
95+
96+
const sizes = {
97+
md: definePartsStyle({
98+
field: size.md,
99+
element: size.md,
100+
}),
101+
sm: definePartsStyle({
102+
field: { ...size.sm, fontSize: "sm" },
103+
element: {
104+
...size.sm,
105+
fontSize: "xl",
106+
},
107+
}),
108+
}
109+
110+
export const Input = defineMultiStyleConfig({
111+
baseStyle,
112+
sizes,
113+
defaultProps: {
114+
variant: "outline",
115+
size: "md",
116+
},
117+
})

0 commit comments

Comments
 (0)