|
1 | | -import type { |
2 | | - ColorBg, |
3 | | - ColorFg, |
4 | | - ColorPalette, |
5 | | - ColorStroke, |
6 | | - HorizontalSpacing, |
7 | | - Radius, |
8 | | - Unit, |
9 | | -} from "@seed-design/vars"; |
10 | | -import { vars } from "@seed-design/vars"; |
11 | | -import clsx from "clsx"; |
12 | | -import * as React from "react"; |
| 1 | +"use client"; |
13 | 2 |
|
14 | | -function handleColor(color: string | undefined) { |
15 | | - if (!color) { |
16 | | - return undefined; |
17 | | - } |
18 | | - const [type, value] = color.split("."); |
19 | | - // @ts-ignore |
20 | | - return vars.$color[type][value] ?? undefined; |
21 | | -} |
| 3 | +import { |
| 4 | + Box as SeedBox, |
| 5 | + Flex as SeedFlex, |
| 6 | + type BoxProps as SeedBoxProps, |
| 7 | + type FlexProps as SeedFlexProps, |
| 8 | +} from "@seed-design/react"; |
22 | 9 |
|
23 | | -function handleSpacing(spacing: string | undefined) { |
24 | | - if (!spacing) { |
25 | | - return undefined; |
26 | | - } |
27 | | - // @ts-ignore |
28 | | - return vars.$unit[spacing] ?? vars.$horizontalSpacing[spacing] ?? undefined; |
29 | | -} |
| 10 | +export type BoxProps = SeedBoxProps; |
30 | 11 |
|
31 | | -function handleSize(size: string | undefined) { |
32 | | - if (!size) { |
33 | | - return undefined; |
34 | | - } |
35 | | - if (size === "full") { |
36 | | - return "100%"; |
37 | | - } |
38 | | - // @ts-ignore |
39 | | - return vars.$unit[size] ?? undefined; |
40 | | -} |
| 12 | +/** |
| 13 | + * @see https://seed-design.systems/docs/components/layout/box |
| 14 | + */ |
| 15 | +export const Box = SeedBox; |
41 | 16 |
|
42 | | -export interface BoxProps extends React.HTMLAttributes<HTMLDivElement> { |
43 | | - background?: `bg.${ColorBg}` | `palette.${ColorPalette}`; |
| 17 | +export type FlexProps = SeedFlexProps; |
44 | 18 |
|
45 | | - color?: `fg.${ColorFg}` | `palette.${ColorPalette}`; |
46 | | - |
47 | | - borderColor?: `stroke.${ColorStroke}` | `palette.${ColorPalette}`; |
48 | | - |
49 | | - borderWidth?: 0 | 1 | (number & {}); |
50 | | - |
51 | | - borderTopWidth?: 0 | 1 | (number & {}); |
52 | | - |
53 | | - borderRightWidth?: 0 | 1 | (number & {}); |
54 | | - |
55 | | - borderBottomWidth?: 0 | 1 | (number & {}); |
56 | | - |
57 | | - borderLeftWidth?: 0 | 1 | (number & {}); |
58 | | - |
59 | | - borderRadius?: Radius; |
60 | | - |
61 | | - borderTopLeftRadius?: Radius; |
62 | | - |
63 | | - borderTopRightRadius?: Radius; |
64 | | - |
65 | | - borderBottomRightRadius?: Radius; |
66 | | - |
67 | | - borderBottomLeftRadius?: Radius; |
68 | | - |
69 | | - width?: Unit | "full"; |
70 | | - |
71 | | - minWidth?: Unit | "full"; |
72 | | - |
73 | | - maxWidth?: Unit | "full"; |
74 | | - |
75 | | - height?: Unit | "full"; |
76 | | - |
77 | | - minHeight?: Unit | "full"; |
78 | | - |
79 | | - maxHeight?: Unit | "full"; |
80 | | - |
81 | | - top?: 0; |
82 | | - |
83 | | - left?: 0; |
84 | | - |
85 | | - right?: 0; |
86 | | - |
87 | | - bottom?: 0; |
88 | | - |
89 | | - padding?: Unit; |
90 | | - |
91 | | - paddingX?: Unit | HorizontalSpacing; |
92 | | - |
93 | | - paddingY?: Unit; |
94 | | - |
95 | | - paddingTop?: Unit; |
96 | | - |
97 | | - paddingRight?: Unit | HorizontalSpacing; |
98 | | - |
99 | | - paddingBottom?: Unit; |
100 | | - |
101 | | - paddingLeft?: Unit | HorizontalSpacing; |
102 | | - |
103 | | - display?: "block" | "flex" | "inline" | "inlineBlock" | "none"; |
104 | | - |
105 | | - position?: "relative" | "absolute" | "fixed" | "sticky"; |
106 | | - |
107 | | - overflowX?: "visible" | "hidden" | "scroll" | "auto"; |
108 | | - |
109 | | - overflowY?: "visible" | "hidden" | "scroll" | "auto"; |
110 | | - |
111 | | - flexGrow?: 0 | 1 | (number & {}); |
112 | | - |
113 | | - flexShrink?: 0 | (number & {}); |
114 | | - |
115 | | - // Flex |
116 | | - |
117 | | - flexDirection?: "row" | "column" | "row-reverse" | "column-reverse"; |
118 | | - |
119 | | - flexWrap?: "wrap" | "nowrap"; |
120 | | - |
121 | | - justifyContent?: |
122 | | - | "flex-start" |
123 | | - | "flex-end" |
124 | | - | "center" |
125 | | - | "space-between" |
126 | | - | "space-around"; |
127 | | - |
128 | | - alignItems?: "flex-start" | "flex-end" | "center" | "stretch"; |
129 | | - |
130 | | - alignContent?: "flex-start" | "flex-end" | "center" | "stretch"; |
131 | | - |
132 | | - gap?: Unit; |
133 | | -} |
134 | | - |
135 | | -export const Box = React.forwardRef<HTMLDivElement, BoxProps>((props, ref) => { |
136 | | - const { |
137 | | - background, |
138 | | - color, |
139 | | - borderColor, |
140 | | - borderWidth, |
141 | | - borderTopWidth, |
142 | | - borderRightWidth, |
143 | | - borderBottomWidth, |
144 | | - borderLeftWidth, |
145 | | - borderRadius, |
146 | | - borderTopLeftRadius, |
147 | | - borderTopRightRadius, |
148 | | - borderBottomRightRadius, |
149 | | - borderBottomLeftRadius, |
150 | | - width, |
151 | | - minWidth, |
152 | | - maxWidth, |
153 | | - height, |
154 | | - minHeight, |
155 | | - maxHeight, |
156 | | - padding, |
157 | | - paddingX, |
158 | | - paddingY, |
159 | | - paddingTop, |
160 | | - paddingRight, |
161 | | - paddingBottom, |
162 | | - paddingLeft, |
163 | | - display, |
164 | | - position, |
165 | | - overflowX, |
166 | | - overflowY, |
167 | | - flexGrow, |
168 | | - flexShrink, |
169 | | - flexDirection, |
170 | | - flexWrap, |
171 | | - justifyContent, |
172 | | - alignItems, |
173 | | - alignContent, |
174 | | - gap, |
175 | | - className, |
176 | | - style, |
177 | | - ...nativeProps |
178 | | - } = props; |
179 | | - |
180 | | - return ( |
181 | | - <div |
182 | | - ref={ref} |
183 | | - className={clsx("seed-box", className)} |
184 | | - style={ |
185 | | - { |
186 | | - "--seed-box-background": handleColor(background), |
187 | | - "--seed-box-color": handleColor(color), |
188 | | - "--seed-box-border-color": handleColor(borderColor), |
189 | | - "--seed-box-border-width": |
190 | | - borderWidth !== undefined ? `${borderWidth}px` : undefined, |
191 | | - "--seed-box-border-top-width": |
192 | | - borderTopWidth !== undefined ? `${borderTopWidth}px` : undefined, |
193 | | - "--seed-box-border-right-width": |
194 | | - borderRightWidth !== undefined |
195 | | - ? `${borderRightWidth}px` |
196 | | - : undefined, |
197 | | - "--seed-box-border-bottom-width": |
198 | | - borderBottomWidth !== undefined |
199 | | - ? `${borderBottomWidth}px` |
200 | | - : undefined, |
201 | | - "--seed-box-border-left-width": |
202 | | - borderLeftWidth !== undefined ? `${borderLeftWidth}px` : undefined, |
203 | | - "--seed-box-border-radius": borderRadius |
204 | | - ? `var(--seed-v3-radius-${borderRadius})` |
205 | | - : undefined, |
206 | | - "--seed-box-border-top-left-radius": borderTopLeftRadius |
207 | | - ? `var(--seed-v3-radius-${borderTopLeftRadius})` |
208 | | - : undefined, |
209 | | - "--seed-box-border-top-right-radius": borderTopRightRadius |
210 | | - ? `var(--seed-v3-radius-${borderTopRightRadius})` |
211 | | - : undefined, |
212 | | - "--seed-box-border-bottom-right-radius": borderBottomRightRadius |
213 | | - ? `var(--seed-v3-radius-${borderBottomRightRadius})` |
214 | | - : undefined, |
215 | | - "--seed-box-border-bottom-left-radius": borderBottomLeftRadius |
216 | | - ? `var(--seed-v3-radius-${borderBottomLeftRadius})` |
217 | | - : undefined, |
218 | | - "--seed-box-width": handleSize(width), |
219 | | - "--seed-box-min-width": handleSize(minWidth), |
220 | | - "--seed-box-max-width": handleSize(maxWidth), |
221 | | - "--seed-box-height": handleSize(height), |
222 | | - "--seed-box-min-height": handleSize(minHeight), |
223 | | - "--seed-box-max-height": handleSize(maxHeight), |
224 | | - "--seed-box-padding": handleSpacing(padding), |
225 | | - "--seed-box-padding-x": handleSpacing(paddingX), |
226 | | - "--seed-box-padding-y": handleSpacing(paddingY), |
227 | | - "--seed-box-padding-top": handleSpacing(paddingTop), |
228 | | - "--seed-box-padding-right": handleSpacing(paddingRight), |
229 | | - "--seed-box-padding-bottom": handleSpacing(paddingBottom), |
230 | | - "--seed-box-padding-left": handleSpacing(paddingLeft), |
231 | | - "--seed-box-display": display, |
232 | | - "--seed-box-position": position, |
233 | | - "--seed-box-overflow-x": overflowX, |
234 | | - "--seed-box-overflow-y": overflowY, |
235 | | - "--seed-box-flex-grow": flexGrow, |
236 | | - "--seed-box-flex-shrink": flexShrink, |
237 | | - "--seed-box-flex-direction": flexDirection, |
238 | | - "--seed-box-flex-wrap": flexWrap, |
239 | | - "--seed-box-justify-content": justifyContent, |
240 | | - "--seed-box-align-items": alignItems, |
241 | | - "--seed-box-align-content": alignContent, |
242 | | - "--seed-box-gap": gap ? `var(--seed-v3-unit-${gap})` : undefined, |
243 | | - ...style, |
244 | | - } as React.CSSProperties |
245 | | - } |
246 | | - {...nativeProps} |
247 | | - /> |
248 | | - ); |
249 | | -}); |
250 | | - |
251 | | -export interface FlexProps extends Omit<BoxProps, "display"> { |
252 | | - /** |
253 | | - * @default "flex" |
254 | | - */ |
255 | | - display?: "flex" | "none"; |
256 | | - |
257 | | - direction?: "row" | "column" | "row-reverse" | "column-reverse"; |
258 | | - |
259 | | - wrap?: "wrap" | "nowrap"; |
260 | | -} |
261 | | - |
262 | | -export const Flex = React.forwardRef<HTMLDivElement, FlexProps>( |
263 | | - (props, ref) => { |
264 | | - const { direction, wrap, ...rest } = props; |
265 | | - |
266 | | - return ( |
267 | | - <Box |
268 | | - ref={ref} |
269 | | - display="flex" |
270 | | - flexDirection={direction} |
271 | | - flexWrap={wrap} |
272 | | - {...rest} |
273 | | - /> |
274 | | - ); |
275 | | - }, |
276 | | -); |
| 19 | +/** |
| 20 | + * @see https://seed-design.systems/docs/components/layout/flex |
| 21 | + */ |
| 22 | +export const Flex = SeedFlex; |
0 commit comments