@latte-macchiat-io/latte-vanilla-components 0.0.327 → 0.0.328
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,7 +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 {
|
8
|
+
import { generateResponsiveMedia } from '../../utils/generateResponsiveMedia';
|
9
9
|
|
10
10
|
export const carouselRecipe = recipe(
|
11
11
|
{
|
@@ -95,7 +95,7 @@ export const carouselNav = recipe(
|
|
95
95
|
pointerEvents: 'none',
|
96
96
|
justifyContent: 'flex-end',
|
97
97
|
|
98
|
-
'@media':
|
98
|
+
'@media': generateResponsiveMedia({
|
99
99
|
gap: themeContract.carousel.nav.gap,
|
100
100
|
}),
|
101
101
|
},
|
@@ -117,7 +117,7 @@ export const carouselNav = recipe(
|
|
117
117
|
|
118
118
|
navPositionVertical: {
|
119
119
|
top: {
|
120
|
-
'@media':
|
120
|
+
'@media': generateResponsiveMedia(
|
121
121
|
{}, // pas de props "normales" ici
|
122
122
|
[
|
123
123
|
{
|
@@ -134,7 +134,7 @@ export const carouselNav = recipe(
|
|
134
134
|
transform: 'translate(0%, -50%)',
|
135
135
|
},
|
136
136
|
bottom: {
|
137
|
-
'@media':
|
137
|
+
'@media': generateResponsiveMedia(
|
138
138
|
{}, // pas de props "normales" ici non plus
|
139
139
|
[
|
140
140
|
{
|
@@ -182,7 +182,7 @@ export const carouselNavButton = style(
|
|
182
182
|
pointerEvents: 'none',
|
183
183
|
},
|
184
184
|
|
185
|
-
'@media':
|
185
|
+
'@media': generateResponsiveMedia({
|
186
186
|
width: themeContract.carousel.nav.width,
|
187
187
|
height: themeContract.carousel.nav.height,
|
188
188
|
}),
|
@@ -199,7 +199,7 @@ export const carouselBullets = style({
|
|
199
199
|
position: 'absolute',
|
200
200
|
justifyContent: 'center',
|
201
201
|
|
202
|
-
'@media':
|
202
|
+
'@media': generateResponsiveMedia(
|
203
203
|
{
|
204
204
|
gap: themeContract.carousel.bullet.gap,
|
205
205
|
},
|
@@ -227,7 +227,7 @@ export const carouselBullet = style(
|
|
227
227
|
transform: 'scale(1.2)',
|
228
228
|
},
|
229
229
|
|
230
|
-
'@media':
|
230
|
+
'@media': generateResponsiveMedia({
|
231
231
|
width: themeContract.carousel.bullet.width,
|
232
232
|
height: themeContract.carousel.bullet.height,
|
233
233
|
}),
|
@@ -1,46 +1,50 @@
|
|
1
|
-
// utils/
|
1
|
+
// utils/generateResponsive.ts
|
2
2
|
import { queries } from '../styles/mediaqueries';
|
3
3
|
|
4
|
-
|
5
|
-
* Breakpoint keys you support (should match your queries object).
|
6
|
-
*/
|
4
|
+
// Define the supported breakpoint keys
|
7
5
|
type BreakpointKey = 'mobile' | 'sm' | 'md' | 'lg' | 'xl' | '2xl';
|
8
|
-
const BPS: BreakpointKey[] = ['mobile', 'sm', 'md', 'lg', 'xl', '2xl'];
|
9
6
|
|
10
|
-
|
11
|
-
* Responsive values can be a plain string/number or anything with a toString().
|
12
|
-
*/
|
7
|
+
// A responsive value can be a string, number, or anything with a toString method
|
13
8
|
type ResponsiveValue = string | number | { toString(): string };
|
9
|
+
|
10
|
+
// Map of breakpoint keys to responsive values
|
14
11
|
type BreakpointMap = Partial<Record<BreakpointKey, ResponsiveValue>>;
|
15
12
|
|
13
|
+
// Ordered list of breakpoints to iterate over
|
14
|
+
const BPS: BreakpointKey[] = ['mobile', 'sm', 'md', 'lg', 'xl', '2xl'];
|
15
|
+
|
16
16
|
/**
|
17
|
-
*
|
17
|
+
* Generates a fully responsive CSS object for Vanilla Extract
|
18
18
|
*
|
19
|
-
*
|
20
|
-
*
|
21
|
-
*
|
22
|
-
* padding: '20px'
|
23
|
-
* })
|
24
|
-
*
|
25
|
-
* => {
|
26
|
-
* '@media (min-width:...)': { width: '50%', padding: '20px' },
|
27
|
-
* ...
|
28
|
-
* }
|
19
|
+
* @param props - normal CSS properties, either a single value or responsive map
|
20
|
+
* @param calcProps - optional array of calc() rules for dynamic calculations
|
21
|
+
* @returns an object ready to use under `@media` in Vanilla Extract
|
29
22
|
*/
|
30
|
-
export function generateResponsiveMedia(
|
23
|
+
export function generateResponsiveMedia(
|
24
|
+
props: Record<string, ResponsiveValue | BreakpointMap>,
|
25
|
+
calcProps?: Array<{
|
26
|
+
property: string;
|
27
|
+
base: ResponsiveValue | BreakpointMap;
|
28
|
+
offset: ResponsiveValue | BreakpointMap;
|
29
|
+
operator?: string; // + - * / etc.
|
30
|
+
}>
|
31
|
+
): Record<string, Record<string, string>> {
|
31
32
|
const result: Record<string, Record<string, string>> = {};
|
32
33
|
|
34
|
+
// Helper to convert a value to a proper CSS string
|
33
35
|
const toCssValue = (v: ResponsiveValue) => {
|
34
36
|
const s = String(v);
|
35
|
-
//
|
37
|
+
// If the value is a CSS variable, wrap it with var()
|
36
38
|
return s.startsWith('--') ? `var(${s})` : s;
|
37
39
|
};
|
38
40
|
|
39
|
-
|
41
|
+
// 1️⃣ Process normal CSS properties
|
42
|
+
for (const [cssProp, valOrMap] of Object.entries(props)) {
|
40
43
|
const isMapLike =
|
41
44
|
valOrMap && typeof valOrMap === 'object' && !Array.isArray(valOrMap) && Object.keys(valOrMap).some((k) => BPS.includes(k as BreakpointKey));
|
42
45
|
|
43
46
|
if (isMapLike) {
|
47
|
+
// Responsive map provided
|
44
48
|
const map = valOrMap as BreakpointMap;
|
45
49
|
for (const bp of BPS) {
|
46
50
|
const token = map[bp];
|
@@ -50,7 +54,7 @@ export function generateResponsiveMedia(properties: Record<string, ResponsiveVal
|
|
50
54
|
result[media][cssProp] = toCssValue(token);
|
51
55
|
}
|
52
56
|
} else {
|
53
|
-
//
|
57
|
+
// Single value, apply to all breakpoints
|
54
58
|
const token = valOrMap as ResponsiveValue;
|
55
59
|
for (const bp of BPS) {
|
56
60
|
const media = queries[bp as keyof typeof queries];
|
@@ -60,6 +64,29 @@ export function generateResponsiveMedia(properties: Record<string, ResponsiveVal
|
|
60
64
|
}
|
61
65
|
}
|
62
66
|
|
67
|
+
// 2️⃣ Process calc() properties if provided
|
68
|
+
if (calcProps) {
|
69
|
+
for (const { property, base, offset, operator = '+' } of calcProps) {
|
70
|
+
for (const bp of BPS) {
|
71
|
+
const media = queries[bp as keyof typeof queries];
|
72
|
+
|
73
|
+
// Safely extract the base value for the current breakpoint
|
74
|
+
const baseValue =
|
75
|
+
typeof base === 'object' && !Array.isArray(base) ? ((base as BreakpointMap)[bp] ?? Object.values(base as BreakpointMap)[0]) : base;
|
76
|
+
|
77
|
+
// Safely extract the offset value for the current breakpoint
|
78
|
+
const offsetValue =
|
79
|
+
typeof offset === 'object' && !Array.isArray(offset)
|
80
|
+
? ((offset as BreakpointMap)[bp] ?? Object.values(offset as BreakpointMap)[0])
|
81
|
+
: offset;
|
82
|
+
|
83
|
+
if (!result[media]) result[media] = {};
|
84
|
+
// Build the calc() CSS value
|
85
|
+
result[media][property] = `calc(${baseValue} ${operator} ${offsetValue})`;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
63
90
|
return result;
|
64
91
|
}
|
65
92
|
|
@@ -1,91 +0,0 @@
|
|
1
|
-
// utils/generateResponsive.ts
|
2
|
-
import { queries } from '../styles/mediaqueries';
|
3
|
-
|
4
|
-
// Define the supported breakpoint keys
|
5
|
-
type BreakpointKey = 'mobile' | 'sm' | 'md' | 'lg' | 'xl' | '2xl';
|
6
|
-
|
7
|
-
// A responsive value can be a string, number, or anything with a toString method
|
8
|
-
type ResponsiveValue = string | number | { toString(): string };
|
9
|
-
|
10
|
-
// Map of breakpoint keys to responsive values
|
11
|
-
type BreakpointMap = Partial<Record<BreakpointKey, ResponsiveValue>>;
|
12
|
-
|
13
|
-
// Ordered list of breakpoints to iterate over
|
14
|
-
const BPS: BreakpointKey[] = ['mobile', 'sm', 'md', 'lg', 'xl', '2xl'];
|
15
|
-
|
16
|
-
/**
|
17
|
-
* Generates a fully responsive CSS object for Vanilla Extract
|
18
|
-
*
|
19
|
-
* @param props - normal CSS properties, either a single value or responsive map
|
20
|
-
* @param calcProps - optional array of calc() rules for dynamic calculations
|
21
|
-
* @returns an object ready to use under `@media` in Vanilla Extract
|
22
|
-
*/
|
23
|
-
export function generateResponsive(
|
24
|
-
props: Record<string, ResponsiveValue | BreakpointMap>,
|
25
|
-
calcProps?: Array<{
|
26
|
-
property: string;
|
27
|
-
base: ResponsiveValue | BreakpointMap;
|
28
|
-
offset: ResponsiveValue | BreakpointMap;
|
29
|
-
operator?: string; // + - * / etc.
|
30
|
-
}>
|
31
|
-
): Record<string, Record<string, string>> {
|
32
|
-
const result: Record<string, Record<string, string>> = {};
|
33
|
-
|
34
|
-
// Helper to convert a value to a proper CSS string
|
35
|
-
const toCssValue = (v: ResponsiveValue) => {
|
36
|
-
const s = String(v);
|
37
|
-
// If the value is a CSS variable, wrap it with var()
|
38
|
-
return s.startsWith('--') ? `var(${s})` : s;
|
39
|
-
};
|
40
|
-
|
41
|
-
// 1️⃣ Process normal CSS properties
|
42
|
-
for (const [cssProp, valOrMap] of Object.entries(props)) {
|
43
|
-
const isMapLike =
|
44
|
-
valOrMap && typeof valOrMap === 'object' && !Array.isArray(valOrMap) && Object.keys(valOrMap).some((k) => BPS.includes(k as BreakpointKey));
|
45
|
-
|
46
|
-
if (isMapLike) {
|
47
|
-
// Responsive map provided
|
48
|
-
const map = valOrMap as BreakpointMap;
|
49
|
-
for (const bp of BPS) {
|
50
|
-
const token = map[bp];
|
51
|
-
if (token === undefined) continue;
|
52
|
-
const media = queries[bp as keyof typeof queries];
|
53
|
-
if (!result[media]) result[media] = {};
|
54
|
-
result[media][cssProp] = toCssValue(token);
|
55
|
-
}
|
56
|
-
} else {
|
57
|
-
// Single value, apply to all breakpoints
|
58
|
-
const token = valOrMap as ResponsiveValue;
|
59
|
-
for (const bp of BPS) {
|
60
|
-
const media = queries[bp as keyof typeof queries];
|
61
|
-
if (!result[media]) result[media] = {};
|
62
|
-
result[media][cssProp] = toCssValue(token);
|
63
|
-
}
|
64
|
-
}
|
65
|
-
}
|
66
|
-
|
67
|
-
// 2️⃣ Process calc() properties if provided
|
68
|
-
if (calcProps) {
|
69
|
-
for (const { property, base, offset, operator = '+' } of calcProps) {
|
70
|
-
for (const bp of BPS) {
|
71
|
-
const media = queries[bp as keyof typeof queries];
|
72
|
-
|
73
|
-
// Safely extract the base value for the current breakpoint
|
74
|
-
const baseValue =
|
75
|
-
typeof base === 'object' && !Array.isArray(base) ? ((base as BreakpointMap)[bp] ?? Object.values(base as BreakpointMap)[0]) : base;
|
76
|
-
|
77
|
-
// Safely extract the offset value for the current breakpoint
|
78
|
-
const offsetValue =
|
79
|
-
typeof offset === 'object' && !Array.isArray(offset)
|
80
|
-
? ((offset as BreakpointMap)[bp] ?? Object.values(offset as BreakpointMap)[0])
|
81
|
-
: offset;
|
82
|
-
|
83
|
-
if (!result[media]) result[media] = {};
|
84
|
-
// Build the calc() CSS value
|
85
|
-
result[media][property] = `calc(${baseValue} ${operator} ${offsetValue})`;
|
86
|
-
}
|
87
|
-
}
|
88
|
-
}
|
89
|
-
|
90
|
-
return result;
|
91
|
-
}
|