@kalink-ui/seedly 0.24.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -1
- package/package.json +2 -2
- package/src/components/box/box.css.ts +21 -8
- package/src/components/box/box.responsive.ts +9 -0
- package/src/components/box/box.tsx +9 -3
- package/src/components/button/button.css.ts +199 -177
- package/src/components/button/button.responsive.ts +11 -0
- package/src/components/button/button.tsx +31 -10
- package/src/components/card/card.tsx +3 -1
- package/src/components/center/center.css.ts +23 -10
- package/src/components/center/center.responsive.ts +9 -0
- package/src/components/center/center.tsx +12 -3
- package/src/components/cluster/cluster.css.ts +116 -89
- package/src/components/cluster/cluster.responsive.ts +9 -0
- package/src/components/cluster/cluster.tsx +14 -3
- package/src/components/command/command-list.css.ts +24 -10
- package/src/components/command/command-list.responsive.ts +9 -0
- package/src/components/command/command-list.tsx +2 -2
- package/src/components/command/command.tsx +2 -2
- package/src/components/cover/cover.css.ts +23 -10
- package/src/components/cover/cover.responsive.ts +9 -0
- package/src/components/cover/cover.tsx +7 -3
- package/src/components/grid/grid.css.ts +21 -8
- package/src/components/grid/grid.responsive.ts +9 -0
- package/src/components/grid/grid.tsx +7 -3
- package/src/components/heading/heading.css.ts +75 -41
- package/src/components/heading/heading.responsive.ts +28 -0
- package/src/components/heading/heading.tsx +65 -53
- package/src/components/loader/loader.css.ts +31 -18
- package/src/components/loader/moon-loader.responsive.ts +9 -0
- package/src/components/loader/moon-loader.tsx +12 -3
- package/src/components/menu/menu-separator.css.ts +26 -10
- package/src/components/menu/menu-separator.responsive.ts +9 -0
- package/src/components/sheet/sheet-title.tsx +16 -1
- package/src/components/sidebar/sidebar.css.ts +21 -8
- package/src/components/sidebar/sidebar.responsive.ts +9 -0
- package/src/components/sidebar/sidebar.tsx +6 -3
- package/src/components/stack/stack.css.ts +61 -39
- package/src/components/stack/stack.responsive.ts +9 -0
- package/src/components/stack/stack.tsx +10 -3
- package/src/components/switcher/index.ts +1 -1
- package/src/components/switcher/switcher.css.ts +21 -8
- package/src/components/switcher/switcher.responsive.ts +9 -0
- package/src/components/switcher/switcher.tsx +14 -9
- package/src/components/text/text.css.ts +78 -39
- package/src/components/text/text.responsive.ts +62 -0
- package/src/components/text/text.tsx +35 -8
- package/src/styles/breakpoints.ts +25 -0
- package/src/styles/index.ts +12 -0
- package/src/styles/responsive.ts +180 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { styleVariants, type StyleRule } from '@vanilla-extract/css';
|
|
2
|
+
import { clsx } from 'clsx';
|
|
3
|
+
|
|
4
|
+
import { screen, type BreakpointKey } from './breakpoints';
|
|
5
|
+
|
|
6
|
+
export type BreakpointWithBase = 'xs' | BreakpointKey;
|
|
7
|
+
|
|
8
|
+
export type ResponsiveObject<T, B extends string> = Partial<
|
|
9
|
+
Record<Exclude<B, 'xs'>, T>
|
|
10
|
+
> & { xs?: T };
|
|
11
|
+
export type ResponsiveArray<T> = (T | null | undefined)[];
|
|
12
|
+
export type Responsive<T, B extends string = BreakpointWithBase> =
|
|
13
|
+
| T
|
|
14
|
+
| ResponsiveObject<T, B>
|
|
15
|
+
| ResponsiveArray<T>;
|
|
16
|
+
|
|
17
|
+
export function resolveResponsive<T, B extends string = BreakpointWithBase>(
|
|
18
|
+
value: Responsive<T, B> | undefined,
|
|
19
|
+
order: readonly B[],
|
|
20
|
+
): Partial<Record<B, T>> {
|
|
21
|
+
if (value == null) {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (Array.isArray(value)) {
|
|
26
|
+
const out: Partial<Record<B, T>> = {};
|
|
27
|
+
|
|
28
|
+
value.forEach((val, i) => {
|
|
29
|
+
const breakpoint = order[i] as B | undefined;
|
|
30
|
+
|
|
31
|
+
if (val != null && breakpoint) {
|
|
32
|
+
out[breakpoint] = val as T;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (typeof value === 'object') {
|
|
40
|
+
return value as Partial<Record<B, T>>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return { xs: value as T } as Partial<Record<B, T>>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface CreateResponsiveVariantsArgs<
|
|
47
|
+
VariantValues extends string | number,
|
|
48
|
+
Bps extends string,
|
|
49
|
+
> {
|
|
50
|
+
styles: Record<VariantValues, StyleRule | StyleRule[]>;
|
|
51
|
+
media: Partial<Record<Exclude<Bps, 'xs'>, string>>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function createResponsiveVariants<
|
|
55
|
+
const VariantValues extends string | number,
|
|
56
|
+
const Bps extends string,
|
|
57
|
+
>(args: CreateResponsiveVariantsArgs<VariantValues, Bps>) {
|
|
58
|
+
const { styles, media } = args;
|
|
59
|
+
|
|
60
|
+
const at = Object.fromEntries(
|
|
61
|
+
Object.entries(media).map(([bp, query]) => {
|
|
62
|
+
const styleEntries = Object.entries(styles) as [
|
|
63
|
+
VariantValues,
|
|
64
|
+
StyleRule | StyleRule[],
|
|
65
|
+
][];
|
|
66
|
+
|
|
67
|
+
const styleMap = Object.fromEntries(
|
|
68
|
+
styleEntries.map(([val, rule]) => [
|
|
69
|
+
val,
|
|
70
|
+
applyMedia(query as string, rule),
|
|
71
|
+
]),
|
|
72
|
+
) as Record<VariantValues, StyleRule | StyleRule[]>;
|
|
73
|
+
|
|
74
|
+
return [bp, styleVariants(styleMap)];
|
|
75
|
+
}),
|
|
76
|
+
) as Record<Exclude<Bps, 'xs'>, Record<VariantValues, string>>;
|
|
77
|
+
|
|
78
|
+
return at;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function applyMedia(
|
|
82
|
+
query: string,
|
|
83
|
+
rule: StyleRule | StyleRule[],
|
|
84
|
+
): StyleRule | StyleRule[] {
|
|
85
|
+
if (Array.isArray(rule)) {
|
|
86
|
+
return rule.map((r) => ({ '@media': { [query]: r } })) as StyleRule[];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return { '@media': { [query]: rule } } as StyleRule;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
type MakeResponsive<V, B extends string> = {
|
|
93
|
+
[K in keyof V]: V[K] extends string | number ? Responsive<V[K], B> : V[K];
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export interface ResponsiveRecipeArgs<V, Bps extends string> {
|
|
97
|
+
recipe: (props: V) => string;
|
|
98
|
+
at: Partial<
|
|
99
|
+
Record<keyof V, Record<Exclude<Bps, 'xs'>, Record<string, string>>>
|
|
100
|
+
>;
|
|
101
|
+
order: readonly Bps[];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function responsiveRecipe<
|
|
105
|
+
V extends Record<string, unknown>,
|
|
106
|
+
const Bps extends string,
|
|
107
|
+
>(args: ResponsiveRecipeArgs<V, Bps>) {
|
|
108
|
+
const { recipe, at, order } = args;
|
|
109
|
+
|
|
110
|
+
return (props: MakeResponsive<V, Bps> & { className?: string }) => {
|
|
111
|
+
const { className, ...rest } = props as Record<string, unknown> & {
|
|
112
|
+
className?: string;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const baseProps: Partial<V> = {};
|
|
116
|
+
|
|
117
|
+
for (const key in rest) {
|
|
118
|
+
const value = (rest as Record<string, unknown>)[key];
|
|
119
|
+
const map = resolveResponsive(value, order);
|
|
120
|
+
|
|
121
|
+
(baseProps as Record<string, unknown>)[key] =
|
|
122
|
+
(map as Record<string, unknown>)['xs'] ?? value;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const base = recipe(baseProps as V);
|
|
126
|
+
const overrides: string[] = [];
|
|
127
|
+
|
|
128
|
+
for (const key in rest) {
|
|
129
|
+
const value = (rest as Record<string, unknown>)[key];
|
|
130
|
+
const map = resolveResponsive(value, order);
|
|
131
|
+
const variantAt = (at as Record<string, unknown>)[key] as
|
|
132
|
+
| Record<string, Record<string, string>>
|
|
133
|
+
| undefined;
|
|
134
|
+
|
|
135
|
+
if (!variantAt) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
for (const bp of order) {
|
|
140
|
+
if (bp === 'xs') {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const val = (map as Partial<Record<Bps, unknown>>)[bp];
|
|
145
|
+
|
|
146
|
+
if (val == null) {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const cls = variantAt[bp as string]?.[String(val)];
|
|
151
|
+
|
|
152
|
+
if (cls) {
|
|
153
|
+
overrides.push(cls);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return clsx(base, ...overrides, className);
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Default viewport media queries (can be replaced per-component if needed)
|
|
163
|
+
export const defaultMedia = {
|
|
164
|
+
sm: screen.sm,
|
|
165
|
+
md: screen.md,
|
|
166
|
+
lg: screen.lg,
|
|
167
|
+
xl: screen.xl,
|
|
168
|
+
'2xl': screen['2xl'],
|
|
169
|
+
'3xl': screen['3xl'],
|
|
170
|
+
} as const satisfies Partial<Record<BreakpointKey, string>>;
|
|
171
|
+
|
|
172
|
+
export const defaultOrder: readonly BreakpointWithBase[] = [
|
|
173
|
+
'xs',
|
|
174
|
+
'sm',
|
|
175
|
+
'md',
|
|
176
|
+
'lg',
|
|
177
|
+
'xl',
|
|
178
|
+
'2xl',
|
|
179
|
+
'3xl',
|
|
180
|
+
] as const;
|