@latte-macchiat-io/latte-vanilla-components 0.0.323 → 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,8 +5,10 @@ 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';
|
11
|
+
import { mergeResponsiveMedias } from '../../utils/mergeResponsiveMedias';
|
10
12
|
|
11
13
|
export const carouselRecipe = recipe(
|
12
14
|
{
|
@@ -184,12 +186,19 @@ export const carouselBullets = style({
|
|
184
186
|
position: 'absolute',
|
185
187
|
justifyContent: 'center',
|
186
188
|
|
187
|
-
'@media':
|
188
|
-
|
189
|
+
'@media': generateResponsive(
|
190
|
+
{
|
189
191
|
gap: themeContract.carousel.bullet.gap,
|
190
|
-
}
|
191
|
-
|
192
|
-
|
192
|
+
},
|
193
|
+
[
|
194
|
+
{
|
195
|
+
property: 'top',
|
196
|
+
base: '100%',
|
197
|
+
offset: themeContract.carousel.bullet.positionVerticalOffset,
|
198
|
+
operator: '+',
|
199
|
+
},
|
200
|
+
]
|
201
|
+
),
|
193
202
|
});
|
194
203
|
|
195
204
|
export const carouselBullet = style(
|
@@ -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
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
/**
|
2
|
+
* Fusionne plusieurs objets responsive générés pour Vanilla Extract
|
3
|
+
* sans écraser les valeurs existantes des mêmes breakpoints.
|
4
|
+
*
|
5
|
+
* Exemple :
|
6
|
+
* mergeResponsiveMedias(a, b) => combine les clés communes
|
7
|
+
*/
|
8
|
+
export function mergeResponsiveMedias(...mediaObjects: Record<string, Record<string, string>>[]): Record<string, Record<string, string>> {
|
9
|
+
const merged: Record<string, Record<string, string>> = {};
|
10
|
+
|
11
|
+
for (const obj of mediaObjects) {
|
12
|
+
for (const [query, styles] of Object.entries(obj)) {
|
13
|
+
merged[query] = {
|
14
|
+
...(merged[query] || {}),
|
15
|
+
...styles,
|
16
|
+
};
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
return merged;
|
21
|
+
}
|