@latte-macchiat-io/latte-vanilla-components 0.0.324 → 0.0.325
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/package.json
CHANGED
@@ -5,6 +5,7 @@ import { recipe, RecipeVariants } from '@vanilla-extract/recipes';
|
|
5
5
|
import { queries } from '../../styles/mediaqueries';
|
6
6
|
import { themeContract } from '../../theme/contract.css';
|
7
7
|
|
8
|
+
import { generateResponsive } from '../../utils/generateResponsive';
|
8
9
|
import { generateResponsiveMedia } from '../../utils/generateResponsiveMedia';
|
9
10
|
import { generateResponsiveMediaCalc } from '../../utils/generateResponsiveMediaCalc';
|
10
11
|
import { mergeResponsiveMedias } from '../../utils/mergeResponsiveMedias';
|
@@ -185,11 +186,18 @@ export const carouselBullets = style({
|
|
185
186
|
position: 'absolute',
|
186
187
|
justifyContent: 'center',
|
187
188
|
|
188
|
-
'@media':
|
189
|
-
|
189
|
+
'@media': generateResponsive(
|
190
|
+
{
|
190
191
|
gap: themeContract.carousel.bullet.gap,
|
191
|
-
}
|
192
|
-
|
192
|
+
},
|
193
|
+
[
|
194
|
+
{
|
195
|
+
property: 'top',
|
196
|
+
base: '100%',
|
197
|
+
offset: themeContract.carousel.bullet.positionVerticalOffset,
|
198
|
+
operator: '+',
|
199
|
+
},
|
200
|
+
]
|
193
201
|
),
|
194
202
|
});
|
195
203
|
|
@@ -0,0 +1,69 @@
|
|
1
|
+
import { queries } from '../styles/mediaqueries';
|
2
|
+
|
3
|
+
type BreakpointKey = 'mobile' | 'sm' | 'md' | 'lg' | 'xl' | '2xl';
|
4
|
+
type ResponsiveValue = string | number | { toString(): string };
|
5
|
+
type BreakpointMap = Partial<Record<BreakpointKey, ResponsiveValue>>;
|
6
|
+
|
7
|
+
const BPS: BreakpointKey[] = ['mobile', 'sm', 'md', 'lg', 'xl', '2xl'];
|
8
|
+
|
9
|
+
/**
|
10
|
+
* Generate fully responsive CSS object for Vanilla Extract
|
11
|
+
*
|
12
|
+
* @param props - normal CSS properties (string/number or responsive map)
|
13
|
+
* @param calcProps - optional array of calc() rules
|
14
|
+
* @returns object ready for `@media` in Vanilla Extract
|
15
|
+
*/
|
16
|
+
export function generateResponsive(
|
17
|
+
props: Record<string, ResponsiveValue | BreakpointMap>,
|
18
|
+
calcProps?: Array<{
|
19
|
+
property: string;
|
20
|
+
base: ResponsiveValue | BreakpointMap;
|
21
|
+
offset: ResponsiveValue | BreakpointMap;
|
22
|
+
operator?: string; // + - * / ...
|
23
|
+
}>
|
24
|
+
): Record<string, Record<string, string>> {
|
25
|
+
const result: Record<string, Record<string, string>> = {};
|
26
|
+
|
27
|
+
const toCssValue = (v: ResponsiveValue) => {
|
28
|
+
const s = String(v);
|
29
|
+
return s.startsWith('--') ? `var(${s})` : s;
|
30
|
+
};
|
31
|
+
|
32
|
+
// 1️⃣ Normal props
|
33
|
+
for (const [cssProp, valOrMap] of Object.entries(props)) {
|
34
|
+
const isMapLike =
|
35
|
+
valOrMap && typeof valOrMap === 'object' && !Array.isArray(valOrMap) && Object.keys(valOrMap).some((k) => BPS.includes(k as BreakpointKey));
|
36
|
+
|
37
|
+
if (isMapLike) {
|
38
|
+
const map = valOrMap as BreakpointMap;
|
39
|
+
for (const bp of BPS) {
|
40
|
+
const token = map[bp];
|
41
|
+
if (token === undefined) continue;
|
42
|
+
const media = queries[bp as keyof typeof queries];
|
43
|
+
if (!result[media]) result[media] = {};
|
44
|
+
result[media][cssProp] = toCssValue(token);
|
45
|
+
}
|
46
|
+
} else {
|
47
|
+
for (const bp of BPS) {
|
48
|
+
const media = queries[bp as keyof typeof queries];
|
49
|
+
if (!result[media]) result[media] = {};
|
50
|
+
result[media][cssProp] = toCssValue(valOrMap as ResponsiveValue);
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
// 2️⃣ Calc props
|
56
|
+
if (calcProps) {
|
57
|
+
for (const { property, base, offset, operator = '+' } of calcProps) {
|
58
|
+
for (const bp of BPS) {
|
59
|
+
const media = queries[bp as keyof typeof queries];
|
60
|
+
const baseValue = typeof base === 'string' ? base : (base[bp] ?? Object.values(base)[0]);
|
61
|
+
const offsetValue = typeof offset === 'string' ? offset : (offset[bp] ?? Object.values(offset)[0]);
|
62
|
+
if (!result[media]) result[media] = {};
|
63
|
+
result[media][property] = `calc(${baseValue} ${operator} ${offsetValue})`;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
return result;
|
69
|
+
}
|