@latte-macchiat-io/latte-vanilla-components 0.0.543 → 0.0.545
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 +1 -1
- package/src/components/Box/styles.css.ts +3 -4
- package/src/components/Carousel/styles.css.ts +5 -5
- package/src/components/Columns/styles.css.ts +4 -3
- package/src/components/Header/styles.css.ts +2 -3
- package/src/components/Video/styles.css.ts +6 -6
- package/src/styles/mediaqueries.ts +25 -19
- package/src/styles/utils/calcResponsiveSubtract.ts +1 -1
- package/src/styles/utils/generateResponsiveMedia.ts +8 -18
- package/src/styles/BreakpointsProvider.tsx +0 -15
- package/src/styles/config.ts +0 -12
- package/src/styles/types.ts +0 -1
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { style } from '@vanilla-extract/css';
|
|
2
2
|
import { recipe, RecipeVariants } from '@vanilla-extract/recipes';
|
|
3
|
-
import { themeContract } from '@latte-macchiat-io/latte-vanilla-components';
|
|
3
|
+
import { mediaQuery, themeContract } from '@latte-macchiat-io/latte-vanilla-components';
|
|
4
4
|
|
|
5
|
-
import { queries } from '../../styles/mediaqueries';
|
|
6
5
|
import { generateResponsiveMedia } from '../../styles/utils/generateResponsiveMedia';
|
|
7
6
|
|
|
8
7
|
export const boxBase = style({
|
|
@@ -111,7 +110,7 @@ export const boxContent = recipe({
|
|
|
111
110
|
flexDirection: 'column',
|
|
112
111
|
|
|
113
112
|
'@media': {
|
|
114
|
-
[
|
|
113
|
+
[mediaQuery('md')]: {
|
|
115
114
|
flexDirection: 'row',
|
|
116
115
|
},
|
|
117
116
|
},
|
|
@@ -140,7 +139,7 @@ export const boxContent = recipe({
|
|
|
140
139
|
flexDirection: 'column-reverse',
|
|
141
140
|
|
|
142
141
|
'@media': {
|
|
143
|
-
[
|
|
142
|
+
[mediaQuery('md')]: {
|
|
144
143
|
flexDirection: 'row-reverse',
|
|
145
144
|
},
|
|
146
145
|
},
|
|
@@ -2,7 +2,7 @@ import { globalStyle, style } from '@vanilla-extract/css';
|
|
|
2
2
|
import { calc } from '@vanilla-extract/css-utils';
|
|
3
3
|
import { recipe, RecipeVariants } from '@vanilla-extract/recipes';
|
|
4
4
|
|
|
5
|
-
import { mediaQuery
|
|
5
|
+
import { mediaQuery } from '../../styles/mediaqueries';
|
|
6
6
|
import { generateResponsiveMedia } from '../../styles/utils/generateResponsiveMedia';
|
|
7
7
|
import { themeContract } from '../../theme/contract.css';
|
|
8
8
|
|
|
@@ -22,7 +22,7 @@ export const carouselRecipe = recipe(
|
|
|
22
22
|
marginRight: calc(themeContract.global.paddingRight.mobile).negate().toString(),
|
|
23
23
|
|
|
24
24
|
'@media': {
|
|
25
|
-
[
|
|
25
|
+
[mediaQuery('sm')]: {
|
|
26
26
|
marginLeft: calc(themeContract.global.paddingLeft.sm).negate().toString(),
|
|
27
27
|
marginRight: calc(themeContract.global.paddingRight.sm).negate().toString(),
|
|
28
28
|
},
|
|
@@ -30,15 +30,15 @@ export const carouselRecipe = recipe(
|
|
|
30
30
|
marginLeft: calc(themeContract.global.paddingLeft.md).negate().toString(),
|
|
31
31
|
marginRight: calc(themeContract.global.paddingRight.md).negate().toString(),
|
|
32
32
|
},
|
|
33
|
-
[
|
|
33
|
+
[mediaQuery('lg')]: {
|
|
34
34
|
marginLeft: calc(themeContract.global.paddingLeft.lg).negate().toString(),
|
|
35
35
|
marginRight: calc(themeContract.global.paddingRight.lg).negate().toString(),
|
|
36
36
|
},
|
|
37
|
-
[
|
|
37
|
+
[mediaQuery('xl')]: {
|
|
38
38
|
marginLeft: calc(themeContract.global.paddingLeft.xl).negate().toString(),
|
|
39
39
|
marginRight: calc(themeContract.global.paddingRight.xl).negate().toString(),
|
|
40
40
|
},
|
|
41
|
-
[
|
|
41
|
+
[mediaQuery('2xl')]: {
|
|
42
42
|
marginLeft: `calc((100vw - ${themeContract.maxWidth}) / -2)`,
|
|
43
43
|
marginRight: `calc((100vw - ${themeContract.maxWidth}) / -2)`,
|
|
44
44
|
},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { globalStyle, style } from '@vanilla-extract/css';
|
|
2
2
|
import { recipe, RecipeVariants } from '@vanilla-extract/recipes';
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
import { mediaQuery } from '../../styles/mediaqueries';
|
|
4
5
|
import { generateResponsiveMedia } from '../../styles/utils/generateResponsiveMedia';
|
|
5
6
|
import { themeContract } from '../../theme/contract.css';
|
|
6
7
|
|
|
@@ -14,7 +15,7 @@ export const columnsBase = style({
|
|
|
14
15
|
gap: themeContract.columns.gap,
|
|
15
16
|
}),
|
|
16
17
|
|
|
17
|
-
[
|
|
18
|
+
[mediaQuery('md')]: {
|
|
18
19
|
gridAutoFlow: 'row',
|
|
19
20
|
gridTemplateColumns: 'var(--columns)', // desktop : prend la variable CSS
|
|
20
21
|
},
|
|
@@ -40,7 +41,7 @@ export const columnsRecipe = recipe(
|
|
|
40
41
|
reverse: {
|
|
41
42
|
true: {
|
|
42
43
|
'@media': {
|
|
43
|
-
[
|
|
44
|
+
[mediaQuery('md')]: {
|
|
44
45
|
direction: 'rtl',
|
|
45
46
|
},
|
|
46
47
|
},
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { globalStyle, style } from '@vanilla-extract/css';
|
|
2
2
|
import { recipe } from '@vanilla-extract/recipes';
|
|
3
3
|
|
|
4
|
-
import { themeContract } from '../..';
|
|
5
|
-
import { queries } from '../../styles/mediaqueries';
|
|
4
|
+
import { mediaQuery, themeContract } from '../..';
|
|
6
5
|
import { generateResponsiveMedia } from '../../styles/utils/generateResponsiveMedia';
|
|
7
6
|
|
|
8
7
|
export const headerBase = style({
|
|
@@ -116,7 +115,7 @@ export const headerToggleNav = recipe(
|
|
|
116
115
|
mobileOnly: {
|
|
117
116
|
display: 'block',
|
|
118
117
|
'@media': {
|
|
119
|
-
[
|
|
118
|
+
[mediaQuery('md')]: {
|
|
120
119
|
display: 'none',
|
|
121
120
|
},
|
|
122
121
|
},
|
|
@@ -2,7 +2,7 @@ import { globalStyle, style } from '@vanilla-extract/css';
|
|
|
2
2
|
import { calc } from '@vanilla-extract/css-utils';
|
|
3
3
|
import { recipe, RecipeVariants } from '@vanilla-extract/recipes';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { mediaQuery } from '../../styles/mediaqueries';
|
|
6
6
|
import { generateResponsiveMedia } from '../../styles/utils/generateResponsiveMedia';
|
|
7
7
|
import { themeContract } from '../../theme/contract.css';
|
|
8
8
|
import { addPixelsToBreakpoints } from '../../utils/addPixelsToBreakpoints';
|
|
@@ -30,23 +30,23 @@ export const videoRecipe = recipe(
|
|
|
30
30
|
marginRight: calc(themeContract.global.paddingRight.mobile).negate().toString(),
|
|
31
31
|
|
|
32
32
|
'@media': {
|
|
33
|
-
[
|
|
33
|
+
[mediaQuery('md')]: {
|
|
34
34
|
marginLeft: calc(themeContract.global.paddingLeft.sm).negate().toString(),
|
|
35
35
|
marginRight: calc(themeContract.global.paddingRight.sm).negate().toString(),
|
|
36
36
|
},
|
|
37
|
-
[
|
|
37
|
+
[mediaQuery('md')]: {
|
|
38
38
|
marginLeft: calc(themeContract.global.paddingLeft.md).negate().toString(),
|
|
39
39
|
marginRight: calc(themeContract.global.paddingRight.md).negate().toString(),
|
|
40
40
|
},
|
|
41
|
-
[
|
|
41
|
+
[mediaQuery('lg')]: {
|
|
42
42
|
marginLeft: calc(themeContract.global.paddingLeft.lg).negate().toString(),
|
|
43
43
|
marginRight: calc(themeContract.global.paddingRight.lg).negate().toString(),
|
|
44
44
|
},
|
|
45
|
-
[
|
|
45
|
+
[mediaQuery('xl')]: {
|
|
46
46
|
marginLeft: calc(themeContract.global.paddingLeft.xl).negate().toString(),
|
|
47
47
|
marginRight: calc(themeContract.global.paddingRight.xl).negate().toString(),
|
|
48
48
|
},
|
|
49
|
-
[
|
|
49
|
+
[mediaQuery('2xl')]: {
|
|
50
50
|
marginLeft: `calc((100vw - ${themeContract.maxWidth}) / -2)`,
|
|
51
51
|
marginRight: `calc((100vw - ${themeContract.maxWidth}) / -2)`,
|
|
52
52
|
},
|
|
@@ -1,24 +1,30 @@
|
|
|
1
|
-
import { Breakpoints } from './BreakpointsProvider';
|
|
2
|
-
import { getBreakpoints } from './config';
|
|
3
|
-
|
|
4
1
|
export const defaultBreakpoints = {
|
|
5
|
-
mobile: 0,
|
|
6
|
-
sm: 640,
|
|
7
|
-
md:
|
|
8
|
-
lg: 1024,
|
|
9
|
-
xl: 1280,
|
|
10
|
-
'2xl': 1536,
|
|
2
|
+
mobile: 0, // Mobile par défaut
|
|
3
|
+
sm: 640, // Mobile large
|
|
4
|
+
md: 888, // Tablette
|
|
5
|
+
lg: 1024, // Petit laptop
|
|
6
|
+
xl: 1280, // Desktop
|
|
7
|
+
'2xl': 1536, // Grand écran
|
|
11
8
|
} as const;
|
|
12
9
|
|
|
13
|
-
export const queries = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
10
|
+
// export const queries = {
|
|
11
|
+
// mobile: `screen and (min-width: ${defaultBreakpoints.mobile}px)`,
|
|
12
|
+
// sm: `screen and (min-width: ${defaultBreakpoints.sm}px)`,
|
|
13
|
+
// md: `screen and (min-width: ${defaultBreakpoints.md}px)`,
|
|
14
|
+
// lg: `screen and (min-width: ${defaultBreakpoints.lg}px)`,
|
|
15
|
+
// xl: `screen and (min-width: ${defaultBreakpoints.xl}px)`,
|
|
16
|
+
// '2xl': `screen and (min-width: ${defaultBreakpoints['2xl']}px)`,
|
|
17
|
+
// };
|
|
18
|
+
|
|
19
|
+
export type Breakpoints = keyof typeof defaultBreakpoints;
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
let projectBreakpoints: typeof defaultBreakpoints | undefined;
|
|
23
22
|
|
|
24
|
-
export const
|
|
23
|
+
export const setProjectBreakpoints = (bp: typeof defaultBreakpoints) => {
|
|
24
|
+
projectBreakpoints = bp;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const mediaQuery = (key: Breakpoints) => {
|
|
28
|
+
const bp = projectBreakpoints ?? defaultBreakpoints;
|
|
29
|
+
return `screen and (min-width: ${bp[key]}px)`;
|
|
30
|
+
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
// utils/
|
|
2
|
-
import {
|
|
3
|
-
import { Breakpoints } from '../types';
|
|
1
|
+
// utils/generateResponsiveMedia.ts
|
|
2
|
+
import { Breakpoints, mediaQuery } from '../mediaqueries';
|
|
4
3
|
|
|
5
4
|
// A responsive value can be a string, number, or anything with a toString method
|
|
6
5
|
type ResponsiveValue = string | number | { toString(): string };
|
|
@@ -8,7 +7,7 @@ type ResponsiveValue = string | number | { toString(): string };
|
|
|
8
7
|
// Map of breakpoint keys to responsive values
|
|
9
8
|
type BreakpointMap = Partial<Record<Breakpoints, ResponsiveValue>>;
|
|
10
9
|
|
|
11
|
-
// Ordered list of breakpoints
|
|
10
|
+
// Ordered list of breakpoints
|
|
12
11
|
const BPS: Breakpoints[] = ['mobile', 'sm', 'md', 'lg', 'xl', '2xl'];
|
|
13
12
|
|
|
14
13
|
/**
|
|
@@ -24,63 +23,54 @@ export function generateResponsiveMedia(
|
|
|
24
23
|
property: string;
|
|
25
24
|
base: ResponsiveValue | BreakpointMap;
|
|
26
25
|
offset: ResponsiveValue | BreakpointMap;
|
|
27
|
-
operator?: string;
|
|
26
|
+
operator?: string;
|
|
28
27
|
}>
|
|
29
28
|
): Record<string, Record<string, string>> {
|
|
30
29
|
const result: Record<string, Record<string, string>> = {};
|
|
31
30
|
|
|
32
|
-
// Helper to convert a value to a proper CSS string
|
|
33
31
|
const toCssValue = (v: ResponsiveValue) => {
|
|
34
32
|
const s = String(v);
|
|
35
|
-
// If the value is a CSS variable, wrap it with var()
|
|
36
33
|
return s.startsWith('--') ? `var(${s})` : s;
|
|
37
34
|
};
|
|
38
35
|
|
|
39
|
-
// 1️⃣ Process normal CSS properties
|
|
40
36
|
for (const [cssProp, valOrMap] of Object.entries(props)) {
|
|
41
37
|
const isMapLike =
|
|
42
38
|
valOrMap && typeof valOrMap === 'object' && !Array.isArray(valOrMap) && Object.keys(valOrMap).some((k) => BPS.includes(k as Breakpoints));
|
|
43
39
|
|
|
44
40
|
if (isMapLike) {
|
|
45
|
-
// Responsive map provided
|
|
46
41
|
const map = valOrMap as BreakpointMap;
|
|
47
42
|
for (const bp of BPS) {
|
|
48
43
|
const token = map[bp];
|
|
49
44
|
if (token === undefined) continue;
|
|
50
|
-
const media =
|
|
45
|
+
const media = mediaQuery(bp); // <-- juste la condition, pas @media
|
|
51
46
|
if (!result[media]) result[media] = {};
|
|
52
47
|
result[media][cssProp] = toCssValue(token);
|
|
53
48
|
}
|
|
54
49
|
} else {
|
|
55
|
-
// Single value, apply to all breakpoints
|
|
56
50
|
const token = valOrMap as ResponsiveValue;
|
|
57
51
|
for (const bp of BPS) {
|
|
58
|
-
const media =
|
|
52
|
+
const media = mediaQuery(bp);
|
|
59
53
|
if (!result[media]) result[media] = {};
|
|
60
54
|
result[media][cssProp] = toCssValue(token);
|
|
61
55
|
}
|
|
62
56
|
}
|
|
63
57
|
}
|
|
64
58
|
|
|
65
|
-
// 2️⃣ Process calc() properties if provided
|
|
66
59
|
if (calcProps) {
|
|
67
60
|
for (const { property, base, offset, operator = '+' } of calcProps) {
|
|
68
61
|
for (const bp of BPS) {
|
|
69
|
-
const media =
|
|
62
|
+
const media = mediaQuery(bp);
|
|
70
63
|
|
|
71
|
-
// Safely extract the base value for the current breakpoint
|
|
72
64
|
const baseValue =
|
|
73
65
|
typeof base === 'object' && !Array.isArray(base) ? ((base as BreakpointMap)[bp] ?? Object.values(base as BreakpointMap)[0]) : base;
|
|
74
66
|
|
|
75
|
-
// Safely extract the offset value for the current breakpoint
|
|
76
67
|
const offsetValue =
|
|
77
68
|
typeof offset === 'object' && !Array.isArray(offset)
|
|
78
69
|
? ((offset as BreakpointMap)[bp] ?? Object.values(offset as BreakpointMap)[0])
|
|
79
70
|
: offset;
|
|
80
71
|
|
|
81
72
|
if (!result[media]) result[media] = {};
|
|
82
|
-
|
|
83
|
-
result[media][property] = `calc(${baseValue} ${operator} ${offsetValue})`;
|
|
73
|
+
result[media][property] = `calc(${toCssValue(baseValue)} ${operator} ${toCssValue(offsetValue)})`;
|
|
84
74
|
}
|
|
85
75
|
}
|
|
86
76
|
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import React, { createContext, ReactNode, useContext } from 'react';
|
|
2
|
-
|
|
3
|
-
export type Breakpoints = Record<string, number>;
|
|
4
|
-
|
|
5
|
-
const BreakpointsContext = createContext<Breakpoints | null>(null);
|
|
6
|
-
|
|
7
|
-
export const BreakpointsProvider = ({ breakpoints, children }: { breakpoints: Breakpoints; children: ReactNode }) => {
|
|
8
|
-
return <BreakpointsContext.Provider value={breakpoints}>{children}</BreakpointsContext.Provider>;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const useBreakpoints = (): Breakpoints => {
|
|
12
|
-
const ctx = useContext(BreakpointsContext);
|
|
13
|
-
if (!ctx) throw new Error('No BreakpointsProvider found');
|
|
14
|
-
return ctx;
|
|
15
|
-
};
|
package/src/styles/config.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Breakpoints } from './BreakpointsProvider';
|
|
2
|
-
import { defaultBreakpoints } from './mediaqueries';
|
|
3
|
-
|
|
4
|
-
let activeBreakpoints: Breakpoints = defaultBreakpoints; // ✅ IMPORTANT
|
|
5
|
-
|
|
6
|
-
export function configureBreakpoints(breakpoints: Breakpoints) {
|
|
7
|
-
activeBreakpoints = breakpoints;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function getBreakpoints(): Breakpoints {
|
|
11
|
-
return activeBreakpoints;
|
|
12
|
-
}
|
package/src/styles/types.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type Breakpoints = 'mobile' | 'sm' | 'md' | 'lg' | 'xl' | '2xl';
|