@latte-macchiat-io/latte-vanilla-components 0.0.175 → 0.0.177
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 +12 -23
- package/src/assets/styles/default-theme.ts +312 -0
- package/src/components/Button/stories.ts +127 -0
- package/src/components/Columns/stories.ts +35 -0
- package/src/components/Icon/path.ts +36 -0
- package/src/components/Icon/stories.ts +29 -0
- package/src/components/Main/stories.ts +33 -0
- package/src/components/Section/stories.ts +64 -0
- package/{dist/types/index.d.ts → src/index.ts} +38 -0
- package/src/styles/mediaqueries.ts +17 -0
- package/src/theme/baseThemeValues.ts +160 -0
- package/src/theme/index.ts +6 -0
- package/src/theme/utils.ts +76 -0
- package/src/types/theme.ts +295 -0
- package/src/types/withClassName.ts +3 -0
- package/src/utils/cookie.ts +24 -0
- package/src/utils/deep-merge-objects.ts +15 -0
- package/src/utils/use-breakpoint-key.ts +30 -0
- package/src/utils/use-window-size.ts +37 -0
- package/dist/components/Actions/Actions.css.ts +0 -113
- package/dist/components/Button/Button.css.ts +0 -119
- package/dist/components/Carousel/Carousel.css.ts +0 -179
- package/dist/components/Columns/Columns.css.ts +0 -185
- package/dist/components/ConsentCookie/ConsentCookie.css.ts +0 -167
- package/dist/components/Footer/Footer.css.ts +0 -108
- package/dist/components/Form/Form.css.ts +0 -64
- package/dist/components/Form/Row/Row.css.ts +0 -70
- package/dist/components/Form/TextField/Input/Input.css.ts +0 -106
- package/dist/components/Form/TextField/Label/Label.css.ts +0 -58
- package/dist/components/Form/TextField/TextField.css.ts +0 -139
- package/dist/components/Form/TextField/Textarea/Textarea.css.ts +0 -121
- package/dist/components/Header/Header.css.ts +0 -111
- package/dist/components/Header/HeaderOverlay/styles.css.ts +0 -33
- package/dist/components/Header/ToggleNav/styles.css.ts +0 -40
- package/dist/components/Icon/Icon.css.ts +0 -102
- package/dist/components/KeyNumber/KeyNumber.css.ts +0 -158
- package/dist/components/LanguageSwitcher/LanguageSwitcher.css.ts +0 -120
- package/dist/components/Logo/Logo.css.ts +0 -98
- package/dist/components/Main/Main.css.ts +0 -62
- package/dist/components/Modal/Modal.css.ts +0 -203
- package/dist/components/Nav/Nav.css.ts +0 -123
- package/dist/components/NavLegal/NavLegal.css.ts +0 -121
- package/dist/components/NavSocial/NavSocial.css.ts +0 -121
- package/dist/components/Section/Section.css.ts +0 -101
- package/dist/components/Video/Video.css.ts +0 -210
- package/dist/components/VideoFullWidth/VideoFullWidth.css.ts +0 -50
- package/dist/index.cjs.js +0 -2
- package/dist/index.es.js +0 -6813
- package/dist/styles/sprinkles.css.ts +0 -84
- package/dist/theme/contract.css.ts +0 -83
- package/dist/types/components/Actions/Actions.css.d.ts +0 -74
- package/dist/types/components/Actions/Actions.d.ts +0 -7
- package/dist/types/components/Actions/export.d.ts +0 -0
- package/dist/types/components/Actions/stories.d.ts +0 -0
- package/dist/types/components/Button/Button.css.d.ts +0 -65
- package/dist/types/components/Button/Button.d.ts +0 -8
- package/dist/types/components/Button/export.d.ts +0 -0
- package/dist/types/components/Button/stories.d.ts +0 -0
- package/dist/types/components/Carousel/Carousel.css.d.ts +0 -33
- package/dist/types/components/Carousel/Carousel.d.ts +0 -15
- package/dist/types/components/Carousel/export.d.ts +0 -0
- package/dist/types/components/Columns/Columns.css.d.ts +0 -104
- package/dist/types/components/Columns/Columns.d.ts +0 -8
- package/dist/types/components/Columns/export.d.ts +0 -0
- package/dist/types/components/Columns/stories.d.ts +0 -0
- package/dist/types/components/ConsentCookie/ConsentCookie.css.d.ts +0 -15
- package/dist/types/components/ConsentCookie/ConsentCookie.d.ts +0 -17
- package/dist/types/components/ConsentCookie/export.d.ts +0 -0
- package/dist/types/components/ConsentCookie/stories.d.ts +0 -0
- package/dist/types/components/Footer/Footer.css.d.ts +0 -50
- package/dist/types/components/Footer/Footer.d.ts +0 -7
- package/dist/types/components/Footer/export.d.ts +0 -0
- package/dist/types/components/Footer/stories.d.ts +0 -6
- package/dist/types/components/Form/Form.css.d.ts +0 -46
- package/dist/types/components/Form/Form.d.ts +0 -7
- package/dist/types/components/Form/Row/Row.css.d.ts +0 -51
- package/dist/types/components/Form/Row/Row.d.ts +0 -9
- package/dist/types/components/Form/Row/index.d.ts +0 -0
- package/dist/types/components/Form/Row/stories.d.ts +0 -0
- package/dist/types/components/Form/TextField/Input/Input.css.d.ts +0 -32
- package/dist/types/components/Form/TextField/Input/Input.d.ts +0 -10
- package/dist/types/components/Form/TextField/Input/export.d.ts +0 -0
- package/dist/types/components/Form/TextField/Label/Label.css.d.ts +0 -23
- package/dist/types/components/Form/TextField/Label/Label.d.ts +0 -9
- package/dist/types/components/Form/TextField/Label/export.d.ts +0 -0
- package/dist/types/components/Form/TextField/TextField.css.d.ts +0 -19
- package/dist/types/components/Form/TextField/TextField.d.ts +0 -21
- package/dist/types/components/Form/TextField/Textarea/Textarea.css.d.ts +0 -56
- package/dist/types/components/Form/TextField/Textarea/Textarea.d.ts +0 -8
- package/dist/types/components/Form/TextField/Textarea/export.d.ts +0 -0
- package/dist/types/components/Form/TextField/Textarea/stories.d.ts +0 -0
- package/dist/types/components/Form/TextField/export.d.ts +0 -0
- package/dist/types/components/Form/export.d.ts +0 -0
- package/dist/types/components/Header/Header.css.d.ts +0 -36
- package/dist/types/components/Header/Header.d.ts +0 -11
- package/dist/types/components/Header/HeaderOverlay/index.d.ts +0 -7
- package/dist/types/components/Header/HeaderOverlay/styles.css.d.ts +0 -5
- package/dist/types/components/Header/ToggleNav/index.d.ts +0 -9
- package/dist/types/components/Header/ToggleNav/styles.css.d.ts +0 -5
- package/dist/types/components/Header/export.d.ts +0 -0
- package/dist/types/components/Header/stories.d.ts +0 -6
- package/dist/types/components/Icon/Icon.css.d.ts +0 -45
- package/dist/types/components/Icon/Icon.d.ts +0 -12
- package/dist/types/components/Icon/export.d.ts +0 -0
- package/dist/types/components/Icon/path.d.ts +0 -19
- package/dist/types/components/Icon/stories.d.ts +0 -0
- package/dist/types/components/KeyNumber/KeyNumber.css.d.ts +0 -40
- package/dist/types/components/KeyNumber/KeyNumber.d.ts +0 -15
- package/dist/types/components/KeyNumber/export.d.ts +0 -0
- package/dist/types/components/LanguageSwitcher/LanguageSwitcher.css.d.ts +0 -18
- package/dist/types/components/LanguageSwitcher/LanguageSwitcher.d.ts +0 -16
- package/dist/types/components/LanguageSwitcher/export.d.ts +0 -0
- package/dist/types/components/Logo/Logo.css.d.ts +0 -54
- package/dist/types/components/Logo/Logo.d.ts +0 -8
- package/dist/types/components/Logo/export.d.ts +0 -0
- package/dist/types/components/Logo/stories.d.ts +0 -6
- package/dist/types/components/Main/Main.css.d.ts +0 -32
- package/dist/types/components/Main/Main.d.ts +0 -7
- package/dist/types/components/Main/export.d.ts +0 -0
- package/dist/types/components/Main/stories.d.ts +0 -0
- package/dist/types/components/Modal/Modal.css.d.ts +0 -82
- package/dist/types/components/Modal/Modal.d.ts +0 -15
- package/dist/types/components/Modal/export.d.ts +0 -0
- package/dist/types/components/Modal/types.d.ts +0 -5
- package/dist/types/components/Nav/Nav.css.d.ts +0 -52
- package/dist/types/components/Nav/Nav.d.ts +0 -7
- package/dist/types/components/Nav/export.d.ts +0 -0
- package/dist/types/components/Nav/stories.d.ts +0 -6
- package/dist/types/components/NavLegal/NavLegal.css.d.ts +0 -57
- package/dist/types/components/NavLegal/NavLegal.d.ts +0 -7
- package/dist/types/components/NavLegal/export.d.ts +0 -0
- package/dist/types/components/NavLegal/stories.d.ts +0 -6
- package/dist/types/components/NavLegal/types.d.ts +0 -1
- package/dist/types/components/NavSocial/NavSocial.css.d.ts +0 -30
- package/dist/types/components/NavSocial/NavSocial.d.ts +0 -15
- package/dist/types/components/NavSocial/export.d.ts +0 -0
- package/dist/types/components/NavSocial/stories.d.ts +0 -0
- package/dist/types/components/NavSocial/types.d.ts +0 -1
- package/dist/types/components/Section/Section.css.d.ts +0 -60
- package/dist/types/components/Section/Section.d.ts +0 -7
- package/dist/types/components/Section/export.d.ts +0 -0
- package/dist/types/components/Section/stories.d.ts +0 -0
- package/dist/types/components/ToRemove/ToRemove.d.ts +0 -1
- package/dist/types/components/Video/Video.css.d.ts +0 -43
- package/dist/types/components/Video/Video.d.ts +0 -17
- package/dist/types/components/Video/export.d.ts +0 -0
- package/dist/types/components/VideoFullWidth/VideoFullWidth.css.d.ts +0 -18
- package/dist/types/components/VideoFullWidth/VideoFullWidth.d.ts +0 -14
- package/dist/types/components/VideoFullWidth/export.d.ts +0 -0
- package/dist/types/utils/cookie.d.ts +0 -2
- package/dist/types/utils/deep-merge-objects.d.ts +0 -2
- package/dist/types/utils/theme.css.d.ts +0 -173
- package/dist/types/utils/use-breakpoint-key.d.ts +0 -1
- package/dist/types/utils/use-window-size.d.ts +0 -5
- package/dist/utils/theme.css.ts +0 -129
@@ -0,0 +1,295 @@
|
|
1
|
+
export interface Theme {
|
2
|
+
global: {
|
3
|
+
maxWidth: number;
|
4
|
+
paddingLeft: number[];
|
5
|
+
paddingRight: number[];
|
6
|
+
|
7
|
+
brandFont: string;
|
8
|
+
defaultFont: string;
|
9
|
+
};
|
10
|
+
|
11
|
+
colors: {
|
12
|
+
defaultText: string;
|
13
|
+
defaultLightText: string;
|
14
|
+
defaultTitle: string;
|
15
|
+
defaultLink: string;
|
16
|
+
defaultIcon: string;
|
17
|
+
};
|
18
|
+
|
19
|
+
backgroundColors: {
|
20
|
+
modal: string;
|
21
|
+
modalOverlay: string;
|
22
|
+
cookieConsent: string;
|
23
|
+
};
|
24
|
+
|
25
|
+
borders: {
|
26
|
+
hr: string;
|
27
|
+
cookieConsent: string;
|
28
|
+
};
|
29
|
+
|
30
|
+
borderRadius: {
|
31
|
+
modal: number;
|
32
|
+
input: number;
|
33
|
+
cookieConsent: number;
|
34
|
+
};
|
35
|
+
|
36
|
+
widthSizes: {
|
37
|
+
modal: number;
|
38
|
+
cookieConsent: number;
|
39
|
+
};
|
40
|
+
|
41
|
+
transitions: {
|
42
|
+
global: string;
|
43
|
+
};
|
44
|
+
|
45
|
+
actions: {
|
46
|
+
gap: number[];
|
47
|
+
paddingTop: number[];
|
48
|
+
paddingBottom: number[];
|
49
|
+
};
|
50
|
+
|
51
|
+
button: {
|
52
|
+
minWidth: number;
|
53
|
+
fontWeight: number;
|
54
|
+
letterSpacing: number;
|
55
|
+
color: {
|
56
|
+
primary: string;
|
57
|
+
secondary: string;
|
58
|
+
disabled: string;
|
59
|
+
};
|
60
|
+
backgroundColor: {
|
61
|
+
primary: string;
|
62
|
+
secondary: string;
|
63
|
+
disabled: string;
|
64
|
+
};
|
65
|
+
border: {
|
66
|
+
width: number;
|
67
|
+
style: string;
|
68
|
+
color: {
|
69
|
+
primary: string;
|
70
|
+
secondary: string;
|
71
|
+
disabled: string;
|
72
|
+
};
|
73
|
+
};
|
74
|
+
borderRadius: number;
|
75
|
+
paddingTop: {
|
76
|
+
small: number[];
|
77
|
+
medium: number[];
|
78
|
+
large: number[];
|
79
|
+
};
|
80
|
+
paddingBottom: {
|
81
|
+
small: number[];
|
82
|
+
medium: number[];
|
83
|
+
large: number[];
|
84
|
+
};
|
85
|
+
paddingRight: {
|
86
|
+
small: number[];
|
87
|
+
medium: number[];
|
88
|
+
large: number[];
|
89
|
+
};
|
90
|
+
paddingLeft: {
|
91
|
+
small: number[];
|
92
|
+
medium: number[];
|
93
|
+
large: number[];
|
94
|
+
};
|
95
|
+
transition: string;
|
96
|
+
};
|
97
|
+
|
98
|
+
keyNumber: {
|
99
|
+
paddingBottom: number[];
|
100
|
+
};
|
101
|
+
|
102
|
+
columns: {
|
103
|
+
gap: number;
|
104
|
+
};
|
105
|
+
|
106
|
+
form: {
|
107
|
+
width: number;
|
108
|
+
backgroundColor: string;
|
109
|
+
padding: [string | number, string | number];
|
110
|
+
|
111
|
+
row: {
|
112
|
+
gap: [string | number, string | number];
|
113
|
+
padding: [string | number, string | number];
|
114
|
+
};
|
115
|
+
|
116
|
+
label: {
|
117
|
+
font: string;
|
118
|
+
color: string;
|
119
|
+
fontWeight: number;
|
120
|
+
paddingBottom: number;
|
121
|
+
};
|
122
|
+
|
123
|
+
input: {
|
124
|
+
font: string;
|
125
|
+
color: string;
|
126
|
+
border: string;
|
127
|
+
padding: number[];
|
128
|
+
borderRadius: number;
|
129
|
+
backgroundColor: string;
|
130
|
+
placeholder: {
|
131
|
+
color: string;
|
132
|
+
opacity: number;
|
133
|
+
};
|
134
|
+
};
|
135
|
+
|
136
|
+
textarea: {
|
137
|
+
font: string;
|
138
|
+
color: string;
|
139
|
+
border: string;
|
140
|
+
padding: number[];
|
141
|
+
borderRadius: number;
|
142
|
+
backgroundColor: string;
|
143
|
+
placeholder: {
|
144
|
+
color: string;
|
145
|
+
opacity: number;
|
146
|
+
};
|
147
|
+
};
|
148
|
+
|
149
|
+
error: {
|
150
|
+
color: string;
|
151
|
+
};
|
152
|
+
};
|
153
|
+
|
154
|
+
header: {
|
155
|
+
gap: number[];
|
156
|
+
height: number[];
|
157
|
+
backgroundColor: string;
|
158
|
+
|
159
|
+
paddingTop: number[];
|
160
|
+
paddingLeft: number[];
|
161
|
+
paddingRight: number[];
|
162
|
+
paddingBottom: number[];
|
163
|
+
|
164
|
+
overlayGap: number[];
|
165
|
+
overlayBackgroundColor: string;
|
166
|
+
|
167
|
+
toggleNavColor: string;
|
168
|
+
toggleNavOpenColor: string;
|
169
|
+
toggleNavBorderRadius: number;
|
170
|
+
};
|
171
|
+
|
172
|
+
main: {
|
173
|
+
minHeight: string;
|
174
|
+
backgroundColor: string;
|
175
|
+
};
|
176
|
+
|
177
|
+
section: {
|
178
|
+
paddingTop: number[];
|
179
|
+
paddingBottom: number[];
|
180
|
+
};
|
181
|
+
|
182
|
+
footer: {
|
183
|
+
gap: number[];
|
184
|
+
height: number[];
|
185
|
+
backgroundColor: string;
|
186
|
+
|
187
|
+
paddingTop: number[];
|
188
|
+
paddingBottom: number[];
|
189
|
+
};
|
190
|
+
|
191
|
+
modal: {
|
192
|
+
border: string;
|
193
|
+
width: number[];
|
194
|
+
borderRadius: number;
|
195
|
+
backgroundColor: string;
|
196
|
+
|
197
|
+
overlayBlur: number;
|
198
|
+
overlayOpacity: number;
|
199
|
+
overlayBackgroundColor: string;
|
200
|
+
|
201
|
+
paddingTop: number[];
|
202
|
+
paddingLeft: number[];
|
203
|
+
paddingRight: number[];
|
204
|
+
paddingBottom: number[];
|
205
|
+
};
|
206
|
+
|
207
|
+
languageSwitcher: {
|
208
|
+
color: string;
|
209
|
+
border: string;
|
210
|
+
width: number[];
|
211
|
+
borderRadius: number;
|
212
|
+
backgroundColor: string;
|
213
|
+
|
214
|
+
paddingTop: number[];
|
215
|
+
paddingLeft: number[];
|
216
|
+
paddingRight: number[];
|
217
|
+
paddingBottom: number[];
|
218
|
+
};
|
219
|
+
|
220
|
+
carousel: {
|
221
|
+
gap: number[];
|
222
|
+
bullet: {
|
223
|
+
width: number[];
|
224
|
+
height: number[];
|
225
|
+
borderRadius: number;
|
226
|
+
backgroundColor: string;
|
227
|
+
};
|
228
|
+
};
|
229
|
+
|
230
|
+
video: {
|
231
|
+
playButton: {
|
232
|
+
color: string;
|
233
|
+
border: string;
|
234
|
+
width: number[];
|
235
|
+
height: number[];
|
236
|
+
borderRadius: number;
|
237
|
+
backgroundColor: string;
|
238
|
+
};
|
239
|
+
pauseButton: {
|
240
|
+
color: string;
|
241
|
+
border: string;
|
242
|
+
width: number[];
|
243
|
+
height: number[];
|
244
|
+
borderRadius: number;
|
245
|
+
backgroundColor: string;
|
246
|
+
};
|
247
|
+
soundButton: {
|
248
|
+
color: string;
|
249
|
+
border: string;
|
250
|
+
width: number[];
|
251
|
+
height: number[];
|
252
|
+
borderRadius: number;
|
253
|
+
backgroundColor: string;
|
254
|
+
};
|
255
|
+
closeButton: {
|
256
|
+
color: string;
|
257
|
+
border: string;
|
258
|
+
width: number[];
|
259
|
+
height: number[];
|
260
|
+
borderRadius: number;
|
261
|
+
backgroundColor: string;
|
262
|
+
};
|
263
|
+
};
|
264
|
+
|
265
|
+
consentCookie: {
|
266
|
+
borders: number;
|
267
|
+
width: number[];
|
268
|
+
borderRadius: number;
|
269
|
+
backgroundColor: string;
|
270
|
+
|
271
|
+
overlayBlur: number;
|
272
|
+
overlayOpacity: number;
|
273
|
+
overlayBackgroundColor: string;
|
274
|
+
|
275
|
+
paddingTop: number[];
|
276
|
+
paddingLeft: number[];
|
277
|
+
paddingRight: number[];
|
278
|
+
paddingBottom: number[];
|
279
|
+
|
280
|
+
actionsGap: number;
|
281
|
+
actionsPaddingTop: number[];
|
282
|
+
};
|
283
|
+
|
284
|
+
nav: {
|
285
|
+
gap: number[];
|
286
|
+
};
|
287
|
+
|
288
|
+
navSocial: {
|
289
|
+
gap: number[];
|
290
|
+
};
|
291
|
+
|
292
|
+
navLegal: {
|
293
|
+
gap: number[];
|
294
|
+
};
|
295
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
// https://www.w3schools.com/js/js_cookies.asp
|
2
|
+
|
3
|
+
export function getCookie(name: string) {
|
4
|
+
const fullName = name + '=';
|
5
|
+
const decodedCookie = decodeURIComponent(document.cookie);
|
6
|
+
const ca = decodedCookie.split(';');
|
7
|
+
for (let i = 0; i < ca.length; i++) {
|
8
|
+
let c = ca[i];
|
9
|
+
while (c.charAt(0) == ' ') {
|
10
|
+
c = c.substring(1);
|
11
|
+
}
|
12
|
+
if (c.indexOf(fullName) == 0) {
|
13
|
+
return c.substring(fullName.length, c.length);
|
14
|
+
}
|
15
|
+
}
|
16
|
+
return '';
|
17
|
+
}
|
18
|
+
|
19
|
+
export function setCookie(name: string, value: string, expirationInDays: number) {
|
20
|
+
const d = new Date();
|
21
|
+
d.setTime(d.getTime() + expirationInDays * 24 * 60 * 60 * 1000);
|
22
|
+
const expires = 'expires=' + d.toUTCString();
|
23
|
+
document.cookie = name + '=' + value + ';' + expires + ';path=/';
|
24
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2
|
+
const deepMergeObjects = (obj1: any, obj2: any) => {
|
3
|
+
for (const key in obj2) {
|
4
|
+
if (obj2.hasOwnProperty(key)) {
|
5
|
+
if (obj2[key] instanceof Object && obj1[key] instanceof Object) {
|
6
|
+
obj1[key] = deepMergeObjects(obj1[key], obj2[key]);
|
7
|
+
} else {
|
8
|
+
obj1[key] = obj2[key];
|
9
|
+
}
|
10
|
+
}
|
11
|
+
}
|
12
|
+
return obj1;
|
13
|
+
};
|
14
|
+
|
15
|
+
export default deepMergeObjects;
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { useEffect, useState } from 'react';
|
2
|
+
|
3
|
+
import { breakpoints } from '../assets/styles/mediaqueries';
|
4
|
+
|
5
|
+
type BreakpointKey = keyof typeof breakpoints;
|
6
|
+
|
7
|
+
export function useBreakpointKey(): number {
|
8
|
+
const [breakpoint, setBreakpoint] = useState<BreakpointKey>('mobile');
|
9
|
+
|
10
|
+
useEffect(() => {
|
11
|
+
function handleResize() {
|
12
|
+
const width = window.innerWidth;
|
13
|
+
|
14
|
+
if (width >= breakpoints['2xl']) setBreakpoint('2xl');
|
15
|
+
else if (width >= breakpoints.xl) setBreakpoint('xl');
|
16
|
+
else if (width >= breakpoints.lg) setBreakpoint('lg');
|
17
|
+
else if (width >= breakpoints.md) setBreakpoint('md');
|
18
|
+
else if (width >= breakpoints.sm) setBreakpoint('sm');
|
19
|
+
else setBreakpoint('mobile');
|
20
|
+
}
|
21
|
+
|
22
|
+
handleResize(); // init au mount
|
23
|
+
window.addEventListener('resize', handleResize);
|
24
|
+
return () => window.removeEventListener('resize', handleResize);
|
25
|
+
}, []);
|
26
|
+
|
27
|
+
// Map Breakpoint → Index numérique
|
28
|
+
const order: BreakpointKey[] = ['mobile', 'sm', 'md', 'lg', 'xl', '2xl'];
|
29
|
+
return order.indexOf(breakpoint);
|
30
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import { useEffect, useState } from 'react';
|
2
|
+
|
3
|
+
function useWindowSize() {
|
4
|
+
// Initialize state with undefined width/height so server and client renders match
|
5
|
+
// Learn more here: https://joshwcomeau.com/react/the-perils-of-rehydration/
|
6
|
+
const [windowSize, setWindowSize] = useState<{
|
7
|
+
width: undefined | number;
|
8
|
+
height: undefined | number;
|
9
|
+
}>({
|
10
|
+
width: undefined,
|
11
|
+
height: undefined,
|
12
|
+
});
|
13
|
+
|
14
|
+
useEffect(() => {
|
15
|
+
// only execute all the code below in client side
|
16
|
+
// Handler to call on window resize
|
17
|
+
function handleResize() {
|
18
|
+
// Set window width/height to state
|
19
|
+
setWindowSize({
|
20
|
+
width: window.innerWidth,
|
21
|
+
height: window.innerHeight,
|
22
|
+
});
|
23
|
+
}
|
24
|
+
|
25
|
+
// Add event listener
|
26
|
+
window.addEventListener('resize', handleResize);
|
27
|
+
|
28
|
+
// Call handler right away so state gets updated with initial window size
|
29
|
+
handleResize();
|
30
|
+
|
31
|
+
// Remove event listener on cleanup
|
32
|
+
return () => window.removeEventListener('resize', handleResize);
|
33
|
+
}, []); // Empty array ensures that effect is only run on mount
|
34
|
+
return windowSize;
|
35
|
+
}
|
36
|
+
|
37
|
+
export default useWindowSize;
|
@@ -1,113 +0,0 @@
|
|
1
|
-
import { style } from '@vanilla-extract/css';
|
2
|
-
import { recipe, RecipeVariants } from '@vanilla-extract/recipes';
|
3
|
-
import { themeContract } from '../../theme';
|
4
|
-
import { queries } from '../../styles/mediaqueries';
|
5
|
-
|
6
|
-
const actionsBase = style({
|
7
|
-
display: 'flex',
|
8
|
-
flexWrap: 'wrap',
|
9
|
-
|
10
|
-
gap: themeContract.space.sm,
|
11
|
-
paddingTop: themeContract.space.sm,
|
12
|
-
width: '100%',
|
13
|
-
|
14
|
-
'@media': {
|
15
|
-
[queries.lg]: {
|
16
|
-
gap: themeContract.space.md,
|
17
|
-
paddingTop: themeContract.space.md,
|
18
|
-
},
|
19
|
-
},
|
20
|
-
});
|
21
|
-
|
22
|
-
export const actionsRecipe = recipe({
|
23
|
-
base: actionsBase,
|
24
|
-
|
25
|
-
variants: {
|
26
|
-
align: {
|
27
|
-
left: {
|
28
|
-
justifyContent: 'flex-start',
|
29
|
-
alignItems: 'flex-start',
|
30
|
-
},
|
31
|
-
center: {
|
32
|
-
justifyContent: 'center',
|
33
|
-
alignItems: 'center',
|
34
|
-
},
|
35
|
-
right: {
|
36
|
-
justifyContent: 'flex-end',
|
37
|
-
alignItems: 'flex-end',
|
38
|
-
},
|
39
|
-
},
|
40
|
-
direction: {
|
41
|
-
row: {
|
42
|
-
flexDirection: 'row',
|
43
|
-
},
|
44
|
-
column: {
|
45
|
-
flexDirection: 'column',
|
46
|
-
},
|
47
|
-
'row-reverse': {
|
48
|
-
flexDirection: 'row-reverse',
|
49
|
-
},
|
50
|
-
'column-reverse': {
|
51
|
-
flexDirection: 'column-reverse',
|
52
|
-
},
|
53
|
-
},
|
54
|
-
spacing: {
|
55
|
-
none: {
|
56
|
-
gap: '0',
|
57
|
-
paddingTop: '0',
|
58
|
-
},
|
59
|
-
xs: {
|
60
|
-
gap: themeContract.space.xs,
|
61
|
-
paddingTop: themeContract.space.xs,
|
62
|
-
},
|
63
|
-
sm: {
|
64
|
-
gap: themeContract.space.sm,
|
65
|
-
paddingTop: themeContract.space.sm,
|
66
|
-
},
|
67
|
-
md: {
|
68
|
-
gap: themeContract.space.md,
|
69
|
-
paddingTop: themeContract.space.md,
|
70
|
-
},
|
71
|
-
lg: {
|
72
|
-
gap: themeContract.space.lg,
|
73
|
-
paddingTop: themeContract.space.lg,
|
74
|
-
},
|
75
|
-
xl: {
|
76
|
-
gap: themeContract.space.xl,
|
77
|
-
paddingTop: themeContract.space.xl,
|
78
|
-
},
|
79
|
-
},
|
80
|
-
wrap: {
|
81
|
-
true: {
|
82
|
-
flexWrap: 'wrap',
|
83
|
-
},
|
84
|
-
false: {
|
85
|
-
flexWrap: 'nowrap',
|
86
|
-
},
|
87
|
-
},
|
88
|
-
fullWidth: {
|
89
|
-
true: {
|
90
|
-
width: '100%',
|
91
|
-
|
92
|
-
// selectors: {
|
93
|
-
// '& > *': {
|
94
|
-
// flex: '1',
|
95
|
-
// },
|
96
|
-
// },
|
97
|
-
},
|
98
|
-
false: {
|
99
|
-
width: 'auto',
|
100
|
-
},
|
101
|
-
},
|
102
|
-
},
|
103
|
-
|
104
|
-
defaultVariants: {
|
105
|
-
align: 'left',
|
106
|
-
direction: 'row',
|
107
|
-
spacing: 'sm',
|
108
|
-
wrap: true,
|
109
|
-
fullWidth: false,
|
110
|
-
},
|
111
|
-
});
|
112
|
-
|
113
|
-
export type ActionsVariants = RecipeVariants<typeof actionsRecipe>;
|
@@ -1,119 +0,0 @@
|
|
1
|
-
import { recipe, RecipeVariants } from '@vanilla-extract/recipes';
|
2
|
-
import { themeContract } from '../../theme';
|
3
|
-
|
4
|
-
export const buttonRecipe = recipe({
|
5
|
-
base: {
|
6
|
-
display: 'inline-flex',
|
7
|
-
alignItems: 'center',
|
8
|
-
justifyContent: 'center',
|
9
|
-
padding: themeContract.space.md,
|
10
|
-
borderRadius: themeContract.radii.md,
|
11
|
-
border: 'none',
|
12
|
-
cursor: 'pointer',
|
13
|
-
fontFamily: themeContract.fonts.body,
|
14
|
-
fontSize: themeContract.fontSizes.md,
|
15
|
-
fontWeight: '500',
|
16
|
-
lineHeight: themeContract.lineHeights.tight,
|
17
|
-
textDecoration: 'none',
|
18
|
-
transition: 'all 0.2s ease-in-out',
|
19
|
-
outline: 'none',
|
20
|
-
|
21
|
-
':hover': {
|
22
|
-
transform: 'translateY(-1px)',
|
23
|
-
boxShadow: themeContract.shadows.md,
|
24
|
-
},
|
25
|
-
|
26
|
-
':active': {
|
27
|
-
transform: 'translateY(0)',
|
28
|
-
},
|
29
|
-
|
30
|
-
':focus-visible': {
|
31
|
-
outline: '2px solid',
|
32
|
-
outlineColor: themeContract.colors.primary,
|
33
|
-
outlineOffset: '2px',
|
34
|
-
},
|
35
|
-
|
36
|
-
':disabled': {
|
37
|
-
opacity: '0.5',
|
38
|
-
cursor: 'not-allowed',
|
39
|
-
transform: 'none',
|
40
|
-
boxShadow: 'none',
|
41
|
-
},
|
42
|
-
},
|
43
|
-
|
44
|
-
variants: {
|
45
|
-
variant: {
|
46
|
-
primary: {
|
47
|
-
backgroundColor: themeContract.colors.primary,
|
48
|
-
color: themeContract.colors.background,
|
49
|
-
|
50
|
-
':hover': {
|
51
|
-
backgroundColor: themeContract.colors.accent,
|
52
|
-
},
|
53
|
-
},
|
54
|
-
secondary: {
|
55
|
-
backgroundColor: themeContract.colors.secondary,
|
56
|
-
color: themeContract.colors.text,
|
57
|
-
|
58
|
-
':hover': {
|
59
|
-
backgroundColor: themeContract.colors.surface,
|
60
|
-
},
|
61
|
-
},
|
62
|
-
outline: {
|
63
|
-
backgroundColor: 'transparent',
|
64
|
-
color: themeContract.colors.text,
|
65
|
-
border: `1px solid ${themeContract.colors.border}`,
|
66
|
-
|
67
|
-
':hover': {
|
68
|
-
backgroundColor: themeContract.colors.surface,
|
69
|
-
borderColor: themeContract.colors.primary,
|
70
|
-
},
|
71
|
-
},
|
72
|
-
ghost: {
|
73
|
-
backgroundColor: 'transparent',
|
74
|
-
color: themeContract.colors.text,
|
75
|
-
|
76
|
-
':hover': {
|
77
|
-
backgroundColor: themeContract.colors.surface,
|
78
|
-
},
|
79
|
-
},
|
80
|
-
danger: {
|
81
|
-
backgroundColor: themeContract.colors.error,
|
82
|
-
color: themeContract.colors.background,
|
83
|
-
|
84
|
-
':hover': {
|
85
|
-
opacity: '0.9',
|
86
|
-
},
|
87
|
-
},
|
88
|
-
},
|
89
|
-
size: {
|
90
|
-
sm: {
|
91
|
-
padding: `${themeContract.space.xs} ${themeContract.space.sm}`,
|
92
|
-
fontSize: themeContract.fontSizes.sm,
|
93
|
-
borderRadius: themeContract.radii.sm,
|
94
|
-
},
|
95
|
-
md: {
|
96
|
-
padding: `${themeContract.space.sm} ${themeContract.space.md}`,
|
97
|
-
fontSize: themeContract.fontSizes.md,
|
98
|
-
borderRadius: themeContract.radii.md,
|
99
|
-
},
|
100
|
-
lg: {
|
101
|
-
padding: `${themeContract.space.md} ${themeContract.space.lg}`,
|
102
|
-
fontSize: themeContract.fontSizes.lg,
|
103
|
-
borderRadius: themeContract.radii.lg,
|
104
|
-
},
|
105
|
-
},
|
106
|
-
fullWidth: {
|
107
|
-
true: {
|
108
|
-
width: '100%',
|
109
|
-
},
|
110
|
-
},
|
111
|
-
},
|
112
|
-
|
113
|
-
defaultVariants: {
|
114
|
-
variant: 'primary',
|
115
|
-
size: 'md',
|
116
|
-
},
|
117
|
-
});
|
118
|
-
|
119
|
-
export type ButtonVariants = RecipeVariants<typeof buttonRecipe>;
|