|
1 | 1 | import { clsx, type ClassValue } from "clsx"; |
2 | 2 | import { twMerge } from "tailwind-merge"; |
| 3 | +import type { CSSProperties, DynamicResolver } from "./dynamic"; |
3 | 4 |
|
4 | | -type CSSProperties = Record<string, string | number>; |
5 | | - |
6 | | -type DynamicResolverResult = |
7 | | - | string |
8 | | - | { className?: string; style?: CSSProperties }; |
9 | | - |
10 | | -type DynamicResolver<T = any> = (value: T) => DynamicResolverResult; |
11 | | - |
12 | | -type PxProp = |
13 | | - | "width" |
14 | | - | "height" |
15 | | - | "minWidth" |
16 | | - | "maxWidth" |
17 | | - | "minHeight" |
18 | | - | "maxHeight" |
19 | | - | "top" |
20 | | - | "right" |
21 | | - | "bottom" |
22 | | - | "left"; |
23 | | - |
24 | | -type NumProp = "zIndex" | "flexGrow" | "flexShrink" | "order"; |
25 | | - |
26 | | -type VarUnit = "px" | "%" | "deg" | "ms"; |
27 | | - |
28 | | -function px(prop: PxProp): DynamicResolver<number | string> { |
29 | | - return (value: number | string): DynamicResolverResult => { |
30 | | - if (typeof value === "number") { |
31 | | - return { style: { [prop]: `${value}px` } }; |
32 | | - } |
33 | | - return value; |
34 | | - }; |
35 | | -} |
36 | | - |
37 | | -function num(prop: NumProp): DynamicResolver<number | string> { |
38 | | - return (value: number | string): DynamicResolverResult => { |
39 | | - if (typeof value === "number") { |
40 | | - return { style: { [prop]: value } }; |
41 | | - } |
42 | | - return value; |
43 | | - }; |
44 | | -} |
45 | | - |
46 | | -function opacity(): DynamicResolver<number | string> { |
47 | | - return (value: number | string): DynamicResolverResult => { |
48 | | - if (typeof value === "number") { |
49 | | - return { style: { opacity: value } }; |
50 | | - } |
51 | | - return value; |
52 | | - }; |
53 | | -} |
54 | | - |
55 | | -function cssVar( |
56 | | - name: `--${string}`, |
57 | | - options?: { unit?: VarUnit }, |
58 | | -): DynamicResolver<number | string> { |
59 | | - return (value: number | string): DynamicResolverResult => { |
60 | | - if (typeof value === "number") { |
61 | | - if (options?.unit) { |
62 | | - return { style: { [name]: `${value}${options.unit}` } }; |
63 | | - } |
64 | | - return { style: { [name]: String(value) } }; |
65 | | - } |
66 | | - return { style: { [name]: value } }; |
67 | | - }; |
68 | | -} |
69 | | - |
70 | | -export const dynamic = { |
71 | | - px, |
72 | | - num, |
73 | | - opacity, |
74 | | - var: cssVar, |
75 | | -}; |
| 5 | +export { dynamic, type CSSProperties, type DynamicResolver } from "./dynamic"; |
76 | 6 |
|
77 | 7 | type SlotAwareObject = { |
78 | 8 | root?: ClassValue; |
|
0 commit comments