@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@latte-macchiat-io/latte-vanilla-components",
3
- "version": "0.0.543",
3
+ "version": "0.0.545",
4
4
  "description": "Beautiful components for amazing projects, with a touch of Vanilla 🥤",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -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
- [queries.md]: {
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
- [queries.md]: {
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, queries } from '../../styles/mediaqueries';
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
- [queries.sm]: {
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
- [queries.lg]: {
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
- [queries.xl]: {
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
- [queries['2xl']]: {
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
- import { queries } from '../../styles/mediaqueries';
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
- [queries.md]: {
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
- [queries.md]: {
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
- [queries.md]: {
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 { queries } from '../../styles/mediaqueries';
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
- [queries.sm]: {
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
- [queries.md]: {
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
- [queries.lg]: {
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
- [queries.xl]: {
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
- [queries['2xl']]: {
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: 768,
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
- mobile: `screen and (min-width: ${defaultBreakpoints.mobile}px)`,
15
- sm: `screen and (min-width: ${defaultBreakpoints.sm}px)`,
16
- md: `screen and (min-width: ${defaultBreakpoints.md}px)`,
17
- lg: `screen and (min-width: ${defaultBreakpoints.lg}px)`,
18
- xl: `screen and (min-width: ${defaultBreakpoints.xl}px)`,
19
- '2xl': `screen and (min-width: ${defaultBreakpoints['2xl']}px)`,
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
- export type BreakpointKey = keyof typeof defaultBreakpoints;
21
+ let projectBreakpoints: typeof defaultBreakpoints | undefined;
23
22
 
24
- export const mediaQuery = (key: BreakpointKey) => `screen and (min-width: ${defaultBreakpoints[key]}px)`;
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,4 +1,4 @@
1
- import { Breakpoints } from '../types';
1
+ import { Breakpoints } from '../mediaqueries';
2
2
 
3
3
  // A responsive value can be a string, number, or anything with a toString method
4
4
  type ResponsiveValue = string | number | { toString(): string };
@@ -1,6 +1,5 @@
1
- // utils/generateResponsive.ts
2
- import { queries } from '../mediaqueries';
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 to iterate over
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; // + - * / etc.
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 = queries[bp as keyof typeof queries];
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 = queries[bp as keyof typeof queries];
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 = queries[bp as keyof typeof queries];
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
- // Build the calc() CSS value
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
- };
@@ -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
- }
@@ -1 +0,0 @@
1
- export type Breakpoints = 'mobile' | 'sm' | 'md' | 'lg' | 'xl' | '2xl';