@zendeskgarden/react-theming 8.75.1 → 8.76.0
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/dist/esm/elements/ThemeProvider.js +38 -0
- package/dist/esm/elements/palette/index.js +149 -0
- package/dist/esm/elements/theme/index.js +127 -0
- package/dist/esm/index.js +24 -0
- package/dist/esm/types/index.js +10 -0
- package/dist/esm/utils/arrowStyles.js +64 -0
- package/dist/esm/utils/focusStyles.js +43 -0
- package/dist/esm/utils/getColorV8.js +61 -0
- package/dist/esm/utils/getDocument.js +14 -0
- package/dist/esm/utils/getFocusBoxShadow.js +34 -0
- package/dist/esm/utils/getLineHeight.js +22 -0
- package/dist/esm/utils/isRtl.js +14 -0
- package/dist/esm/utils/mediaQuery.js +56 -0
- package/dist/esm/utils/menuStyles.js +49 -0
- package/dist/esm/utils/retrieveComponentStyles.js +19 -0
- package/dist/esm/utils/useDocument.js +21 -0
- package/dist/esm/utils/useText.js +29 -0
- package/dist/esm/utils/useWindow.js +21 -0
- package/dist/esm/utils/withTheme.js +13 -0
- package/dist/index.cjs.js +6 -22
- package/package.json +3 -3
- package/dist/index.esm.js +0 -648
package/dist/index.esm.js
DELETED
|
@@ -1,648 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright Zendesk, Inc.
|
|
3
|
-
*
|
|
4
|
-
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
-
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import React, { useState, useEffect, useRef, useMemo } from 'react';
|
|
9
|
-
import { ThemeProvider as ThemeProvider$1, withTheme as withTheme$1, css, keyframes } from 'styled-components';
|
|
10
|
-
import { useFocusVisible } from '@zendeskgarden/container-focusvisible';
|
|
11
|
-
import { getControlledValue } from '@zendeskgarden/container-utilities';
|
|
12
|
-
import { rgba, darken, lighten, getValueAndUnit, math } from 'polished';
|
|
13
|
-
import memoize from 'lodash.memoize';
|
|
14
|
-
|
|
15
|
-
function _extends() {
|
|
16
|
-
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
17
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
18
|
-
var source = arguments[i];
|
|
19
|
-
for (var key in source) {
|
|
20
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
21
|
-
target[key] = source[key];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return target;
|
|
26
|
-
};
|
|
27
|
-
return _extends.apply(this, arguments);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const PALETTE = {
|
|
31
|
-
black: '#000',
|
|
32
|
-
white: '#fff',
|
|
33
|
-
product: {
|
|
34
|
-
support: '#00a656',
|
|
35
|
-
message: '#37b8af',
|
|
36
|
-
explore: '#30aabc',
|
|
37
|
-
gather: '#f6c8be',
|
|
38
|
-
guide: '#eb4962',
|
|
39
|
-
connect: '#ff6224',
|
|
40
|
-
chat: '#f79a3e',
|
|
41
|
-
talk: '#efc93d',
|
|
42
|
-
sell: '#c38f00'
|
|
43
|
-
},
|
|
44
|
-
grey: {
|
|
45
|
-
100: '#f8f9f9',
|
|
46
|
-
200: '#e9ebed',
|
|
47
|
-
300: '#d8dcde',
|
|
48
|
-
400: '#c2c8cc',
|
|
49
|
-
500: '#87929d',
|
|
50
|
-
600: '#68737d',
|
|
51
|
-
700: '#49545c',
|
|
52
|
-
800: '#2f3941'
|
|
53
|
-
},
|
|
54
|
-
blue: {
|
|
55
|
-
100: '#edf7ff',
|
|
56
|
-
200: '#cee2f2',
|
|
57
|
-
300: '#adcce4',
|
|
58
|
-
400: '#5293c7',
|
|
59
|
-
500: '#337fbd',
|
|
60
|
-
600: '#1f73b7',
|
|
61
|
-
700: '#144a75',
|
|
62
|
-
800: '#0f3554'
|
|
63
|
-
},
|
|
64
|
-
red: {
|
|
65
|
-
100: '#fff0f1',
|
|
66
|
-
200: '#f5d5d8',
|
|
67
|
-
300: '#f5b5ba',
|
|
68
|
-
400: '#e35b66',
|
|
69
|
-
500: '#d93f4c',
|
|
70
|
-
600: '#cc3340',
|
|
71
|
-
700: '#8c232c',
|
|
72
|
-
800: '#681219'
|
|
73
|
-
},
|
|
74
|
-
yellow: {
|
|
75
|
-
100: '#fff7ed',
|
|
76
|
-
200: '#ffeedb',
|
|
77
|
-
300: '#fed6a8',
|
|
78
|
-
400: '#ffb057',
|
|
79
|
-
500: '#f79a3e',
|
|
80
|
-
600: '#ed8f1c',
|
|
81
|
-
700: '#ad5918',
|
|
82
|
-
800: '#703815'
|
|
83
|
-
},
|
|
84
|
-
green: {
|
|
85
|
-
100: '#edf8f4',
|
|
86
|
-
200: '#d1e8df',
|
|
87
|
-
300: '#aecfc2',
|
|
88
|
-
400: '#5eae91',
|
|
89
|
-
500: '#228f67',
|
|
90
|
-
600: '#038153',
|
|
91
|
-
700: '#186146',
|
|
92
|
-
800: '#0b3b29'
|
|
93
|
-
},
|
|
94
|
-
kale: {
|
|
95
|
-
100: '#f5fcfc',
|
|
96
|
-
200: '#daeded',
|
|
97
|
-
300: '#bdd9d7',
|
|
98
|
-
400: '#90bbbb',
|
|
99
|
-
500: '#498283',
|
|
100
|
-
600: '#17494d',
|
|
101
|
-
700: '#03363d',
|
|
102
|
-
800: '#012b30'
|
|
103
|
-
},
|
|
104
|
-
fuschia: {
|
|
105
|
-
400: '#d653c2',
|
|
106
|
-
600: '#a81897',
|
|
107
|
-
M400: '#cf62a8',
|
|
108
|
-
M600: '#a8458c'
|
|
109
|
-
},
|
|
110
|
-
pink: {
|
|
111
|
-
400: '#ec4d63',
|
|
112
|
-
600: '#d42054',
|
|
113
|
-
M400: '#d57287',
|
|
114
|
-
M600: '#b23a5d'
|
|
115
|
-
},
|
|
116
|
-
crimson: {
|
|
117
|
-
400: '#e34f32',
|
|
118
|
-
600: '#c72a1c',
|
|
119
|
-
M400: '#cc6c5b',
|
|
120
|
-
M600: '#b24a3c'
|
|
121
|
-
},
|
|
122
|
-
orange: {
|
|
123
|
-
400: '#de701d',
|
|
124
|
-
600: '#bf5000',
|
|
125
|
-
M400: '#d4772c',
|
|
126
|
-
M600: '#b35827'
|
|
127
|
-
},
|
|
128
|
-
lemon: {
|
|
129
|
-
400: '#ffd424',
|
|
130
|
-
600: '#ffbb10',
|
|
131
|
-
M400: '#e7a500',
|
|
132
|
-
M600: '#c38f00'
|
|
133
|
-
},
|
|
134
|
-
lime: {
|
|
135
|
-
400: '#43b324',
|
|
136
|
-
600: '#2e8200',
|
|
137
|
-
M400: '#519e2d',
|
|
138
|
-
M600: '#47782c'
|
|
139
|
-
},
|
|
140
|
-
mint: {
|
|
141
|
-
400: '#00a656',
|
|
142
|
-
600: '#058541',
|
|
143
|
-
M400: '#299c66',
|
|
144
|
-
M600: '#2e8057'
|
|
145
|
-
},
|
|
146
|
-
teal: {
|
|
147
|
-
400: '#02a191',
|
|
148
|
-
600: '#028079',
|
|
149
|
-
M400: '#2d9e8f',
|
|
150
|
-
M600: '#3c7873'
|
|
151
|
-
},
|
|
152
|
-
azure: {
|
|
153
|
-
400: '#3091ec',
|
|
154
|
-
600: '#1371d6',
|
|
155
|
-
M400: '#5f8dcf',
|
|
156
|
-
M600: '#3a70b2'
|
|
157
|
-
},
|
|
158
|
-
royal: {
|
|
159
|
-
400: '#5d7df5',
|
|
160
|
-
600: '#3353e2',
|
|
161
|
-
M400: '#7986d8',
|
|
162
|
-
M600: '#4b61c3'
|
|
163
|
-
},
|
|
164
|
-
purple: {
|
|
165
|
-
400: '#b552e2',
|
|
166
|
-
600: '#6a27b8',
|
|
167
|
-
M400: '#b072cc',
|
|
168
|
-
M600: '#9358b0'
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
const BASE = 4;
|
|
173
|
-
const borderRadii = {
|
|
174
|
-
sm: `${BASE / 2}px`,
|
|
175
|
-
md: `${BASE}px`
|
|
176
|
-
};
|
|
177
|
-
const borderStyles = {
|
|
178
|
-
solid: 'solid'
|
|
179
|
-
};
|
|
180
|
-
const borderWidths = {
|
|
181
|
-
sm: '1px',
|
|
182
|
-
md: '3px'
|
|
183
|
-
};
|
|
184
|
-
const borders = {
|
|
185
|
-
sm: `${borderWidths.sm} ${borderStyles.solid}`,
|
|
186
|
-
md: `${borderWidths.md} ${borderStyles.solid}`
|
|
187
|
-
};
|
|
188
|
-
const breakpoints = {
|
|
189
|
-
xs: '0px',
|
|
190
|
-
sm: `${BASE * 144}px`,
|
|
191
|
-
md: `${BASE * 192}px`,
|
|
192
|
-
lg: `${BASE * 248}px`,
|
|
193
|
-
xl: `${BASE * 300}px`
|
|
194
|
-
};
|
|
195
|
-
const colors = {
|
|
196
|
-
background: PALETTE.white,
|
|
197
|
-
foreground: PALETTE.grey[800],
|
|
198
|
-
primaryHue: 'blue',
|
|
199
|
-
dangerHue: 'red',
|
|
200
|
-
warningHue: 'yellow',
|
|
201
|
-
successHue: 'green',
|
|
202
|
-
neutralHue: 'grey',
|
|
203
|
-
chromeHue: 'kale'
|
|
204
|
-
};
|
|
205
|
-
const fonts = {
|
|
206
|
-
mono: ['SFMono-Regular' , 'Consolas' , '"Liberation Mono"' , 'Menlo', 'Courier', 'monospace'].join(','),
|
|
207
|
-
system: ['system-ui' , '-apple-system' , 'BlinkMacSystemFont' , '"Segoe UI"' , 'Roboto' , 'Oxygen-Sans' , 'Ubuntu' , 'Cantarell' , '"Helvetica Neue"', 'Arial', 'sans-serif'].join(',')
|
|
208
|
-
};
|
|
209
|
-
const fontSizes = {
|
|
210
|
-
xs: '10px',
|
|
211
|
-
sm: '12px',
|
|
212
|
-
md: '14px',
|
|
213
|
-
lg: '18px',
|
|
214
|
-
xl: '22px',
|
|
215
|
-
xxl: '26px',
|
|
216
|
-
xxxl: '36px'
|
|
217
|
-
};
|
|
218
|
-
const fontWeights = {
|
|
219
|
-
thin: 100,
|
|
220
|
-
extralight: 200,
|
|
221
|
-
light: 300,
|
|
222
|
-
regular: 400,
|
|
223
|
-
medium: 500,
|
|
224
|
-
semibold: 600,
|
|
225
|
-
bold: 700,
|
|
226
|
-
extrabold: 800,
|
|
227
|
-
black: 900
|
|
228
|
-
};
|
|
229
|
-
const iconSizes = {
|
|
230
|
-
sm: '12px',
|
|
231
|
-
md: '16px',
|
|
232
|
-
lg: '26px'
|
|
233
|
-
};
|
|
234
|
-
const lineHeights = {
|
|
235
|
-
sm: `${BASE * 4}px`,
|
|
236
|
-
md: `${BASE * 5}px`,
|
|
237
|
-
lg: `${BASE * 6}px`,
|
|
238
|
-
xl: `${BASE * 7}px`,
|
|
239
|
-
xxl: `${BASE * 8}px`,
|
|
240
|
-
xxxl: `${BASE * 11}px`
|
|
241
|
-
};
|
|
242
|
-
const palette = {
|
|
243
|
-
...PALETTE
|
|
244
|
-
};
|
|
245
|
-
delete palette.product;
|
|
246
|
-
const shadowWidths = {
|
|
247
|
-
xs: '1px',
|
|
248
|
-
sm: '2px',
|
|
249
|
-
md: '3px'
|
|
250
|
-
};
|
|
251
|
-
const shadows = {
|
|
252
|
-
xs: color => `0 0 0 ${shadowWidths.xs} ${color}`,
|
|
253
|
-
sm: color => `0 0 0 ${shadowWidths.sm} ${color}`,
|
|
254
|
-
md: color => `0 0 0 ${shadowWidths.md} ${color}`,
|
|
255
|
-
lg: (offsetY, blurRadius, color) => `0 ${offsetY} ${blurRadius} 0 ${color}`
|
|
256
|
-
};
|
|
257
|
-
const space = {
|
|
258
|
-
base: BASE,
|
|
259
|
-
xxs: `${BASE}px`,
|
|
260
|
-
xs: `${BASE * 2}px`,
|
|
261
|
-
sm: `${BASE * 3}px`,
|
|
262
|
-
md: `${BASE * 5}px`,
|
|
263
|
-
lg: `${BASE * 8}px`,
|
|
264
|
-
xl: `${BASE * 10}px`,
|
|
265
|
-
xxl: `${BASE * 12}px`
|
|
266
|
-
};
|
|
267
|
-
const DEFAULT_THEME = {
|
|
268
|
-
borders,
|
|
269
|
-
borderRadii,
|
|
270
|
-
borderStyles,
|
|
271
|
-
borderWidths,
|
|
272
|
-
breakpoints,
|
|
273
|
-
colors: {
|
|
274
|
-
base: 'light',
|
|
275
|
-
...colors
|
|
276
|
-
},
|
|
277
|
-
components: {},
|
|
278
|
-
fonts,
|
|
279
|
-
fontSizes,
|
|
280
|
-
fontWeights,
|
|
281
|
-
iconSizes,
|
|
282
|
-
lineHeights,
|
|
283
|
-
palette,
|
|
284
|
-
rtl: false,
|
|
285
|
-
shadowWidths,
|
|
286
|
-
shadows,
|
|
287
|
-
space
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
const useDocument = theme => {
|
|
291
|
-
const [controlledDocument, setControlledDocument] = useState();
|
|
292
|
-
useEffect(() => {
|
|
293
|
-
if (theme && theme.document) {
|
|
294
|
-
setControlledDocument(theme.document);
|
|
295
|
-
} else {
|
|
296
|
-
setControlledDocument(document);
|
|
297
|
-
}
|
|
298
|
-
}, [theme]);
|
|
299
|
-
return controlledDocument;
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
const ThemeProvider = _ref => {
|
|
303
|
-
let {
|
|
304
|
-
theme,
|
|
305
|
-
focusVisibleRef,
|
|
306
|
-
children,
|
|
307
|
-
...other
|
|
308
|
-
} = _ref;
|
|
309
|
-
const scopeRef = useRef(null);
|
|
310
|
-
const relativeDocument = useDocument(theme);
|
|
311
|
-
const controlledScopeRef = focusVisibleRef === null ? React.createRef() : getControlledValue(focusVisibleRef, scopeRef);
|
|
312
|
-
useFocusVisible({
|
|
313
|
-
scope: controlledScopeRef,
|
|
314
|
-
relativeDocument
|
|
315
|
-
});
|
|
316
|
-
return React.createElement(ThemeProvider$1, _extends({
|
|
317
|
-
theme: theme
|
|
318
|
-
}, other), focusVisibleRef === undefined ? React.createElement("div", {
|
|
319
|
-
ref: scopeRef
|
|
320
|
-
}, children) : children);
|
|
321
|
-
};
|
|
322
|
-
ThemeProvider.defaultProps = {
|
|
323
|
-
theme: DEFAULT_THEME
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
function isRtl() {
|
|
327
|
-
let {
|
|
328
|
-
theme
|
|
329
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
330
|
-
return Boolean(theme && theme.rtl);
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
function retrieveComponentStyles(componentId, props) {
|
|
334
|
-
const components = props.theme && props.theme.components;
|
|
335
|
-
if (!components) {
|
|
336
|
-
return undefined;
|
|
337
|
-
}
|
|
338
|
-
const componentStyles = components[componentId];
|
|
339
|
-
if (typeof componentStyles === 'function') {
|
|
340
|
-
return componentStyles(props);
|
|
341
|
-
}
|
|
342
|
-
return componentStyles;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
function withTheme(WrappedComponent) {
|
|
346
|
-
return withTheme$1(WrappedComponent);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
function getDocument() {
|
|
350
|
-
let {
|
|
351
|
-
theme
|
|
352
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
353
|
-
return theme && theme.document || document;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
const DEFAULT_SHADE = 600;
|
|
357
|
-
const adjust = (color, expected, actual) => {
|
|
358
|
-
if (expected !== actual) {
|
|
359
|
-
const amount = Math.abs(expected - actual) / 100 * 0.05;
|
|
360
|
-
return expected > actual ? darken(amount, color) : lighten(amount, color);
|
|
361
|
-
}
|
|
362
|
-
return color;
|
|
363
|
-
};
|
|
364
|
-
const getColorV8 = memoize(function (hue) {
|
|
365
|
-
let shade = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_SHADE;
|
|
366
|
-
let theme = arguments.length > 2 ? arguments[2] : undefined;
|
|
367
|
-
let transparency = arguments.length > 3 ? arguments[3] : undefined;
|
|
368
|
-
let retVal;
|
|
369
|
-
if (isNaN(shade)) {
|
|
370
|
-
return undefined;
|
|
371
|
-
}
|
|
372
|
-
const palette = theme && theme.palette ? theme.palette : DEFAULT_THEME.palette;
|
|
373
|
-
const colors = theme && theme.colors ? theme.colors : DEFAULT_THEME.colors;
|
|
374
|
-
let _hue;
|
|
375
|
-
if (typeof hue === 'string') {
|
|
376
|
-
_hue = colors[hue] || hue;
|
|
377
|
-
} else {
|
|
378
|
-
_hue = hue;
|
|
379
|
-
}
|
|
380
|
-
if (Object.prototype.hasOwnProperty.call(palette, _hue)) {
|
|
381
|
-
_hue = palette[_hue];
|
|
382
|
-
}
|
|
383
|
-
if (typeof _hue === 'object') {
|
|
384
|
-
retVal = _hue[shade];
|
|
385
|
-
if (!retVal) {
|
|
386
|
-
const _shade = Object.keys(_hue).map(hueKey => parseInt(hueKey, 10)).reduce((previous, current) => {
|
|
387
|
-
return Math.abs(current - shade) < Math.abs(previous - shade) ? current : previous;
|
|
388
|
-
});
|
|
389
|
-
retVal = adjust(_hue[_shade], shade, _shade);
|
|
390
|
-
}
|
|
391
|
-
} else {
|
|
392
|
-
retVal = adjust(_hue, shade, DEFAULT_SHADE);
|
|
393
|
-
}
|
|
394
|
-
if (transparency) {
|
|
395
|
-
retVal = rgba(retVal, transparency);
|
|
396
|
-
}
|
|
397
|
-
return retVal;
|
|
398
|
-
}, (hue, shade, theme, transparency) => JSON.stringify({
|
|
399
|
-
hue,
|
|
400
|
-
shade,
|
|
401
|
-
palette: theme?.palette,
|
|
402
|
-
colors: theme?.colors,
|
|
403
|
-
transparency
|
|
404
|
-
}));
|
|
405
|
-
|
|
406
|
-
const getFocusBoxShadow = _ref => {
|
|
407
|
-
let {
|
|
408
|
-
boxShadow,
|
|
409
|
-
inset = false,
|
|
410
|
-
hue = 'primaryHue',
|
|
411
|
-
shade = DEFAULT_SHADE,
|
|
412
|
-
shadowWidth = 'md',
|
|
413
|
-
spacerHue = 'background',
|
|
414
|
-
spacerShade = DEFAULT_SHADE,
|
|
415
|
-
spacerWidth = 'xs',
|
|
416
|
-
theme = DEFAULT_THEME
|
|
417
|
-
} = _ref;
|
|
418
|
-
const color = getColorV8(hue, shade, theme);
|
|
419
|
-
const shadow = theme.shadows[shadowWidth](color);
|
|
420
|
-
if (spacerWidth === null) {
|
|
421
|
-
return `${inset ? 'inset' : ''} ${shadow}`;
|
|
422
|
-
}
|
|
423
|
-
const spacerColor = getColorV8(spacerHue, spacerShade, theme);
|
|
424
|
-
const retVal = `
|
|
425
|
-
${inset ? 'inset' : ''} ${theme.shadows[spacerWidth](spacerColor)},
|
|
426
|
-
${inset ? 'inset' : ''} ${shadow}`;
|
|
427
|
-
return boxShadow ? `${retVal}, ${boxShadow}` : retVal;
|
|
428
|
-
};
|
|
429
|
-
|
|
430
|
-
function getLineHeight(height, fontSize) {
|
|
431
|
-
const [heightValue, heightUnit] = getValueAndUnit(height.toString());
|
|
432
|
-
const [fontSizeValue, fontSizeUnit] = getValueAndUnit(fontSize.toString());
|
|
433
|
-
const PIXELS = 'px';
|
|
434
|
-
if (heightUnit && heightUnit !== PIXELS) {
|
|
435
|
-
throw new Error(`Unexpected \`height\` with '${heightUnit}' units.`);
|
|
436
|
-
}
|
|
437
|
-
if (fontSizeUnit && fontSizeUnit !== PIXELS) {
|
|
438
|
-
throw new Error(`Unexpected \`fontSize\` with '${fontSizeUnit}' units.`);
|
|
439
|
-
}
|
|
440
|
-
return heightValue / fontSizeValue;
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
const maxWidth = (breakpoints, breakpoint) => {
|
|
444
|
-
const keys = Object.keys(breakpoints);
|
|
445
|
-
const index = keys.indexOf(breakpoint) + 1;
|
|
446
|
-
if (keys[index]) {
|
|
447
|
-
const dimension = getValueAndUnit(breakpoints[keys[index]]);
|
|
448
|
-
const value = dimension[0] - 0.02;
|
|
449
|
-
const unit = dimension[1];
|
|
450
|
-
return `${value}${unit}`;
|
|
451
|
-
}
|
|
452
|
-
return undefined;
|
|
453
|
-
};
|
|
454
|
-
function mediaQuery(query, breakpoint, theme) {
|
|
455
|
-
let retVal;
|
|
456
|
-
let min;
|
|
457
|
-
let max;
|
|
458
|
-
const breakpoints = theme && theme.breakpoints ? theme.breakpoints : DEFAULT_THEME.breakpoints;
|
|
459
|
-
if (typeof breakpoint === 'string') {
|
|
460
|
-
if (query === 'up') {
|
|
461
|
-
min = breakpoints[breakpoint];
|
|
462
|
-
} else if (query === 'down') {
|
|
463
|
-
if (breakpoint === 'xl') {
|
|
464
|
-
min = DEFAULT_THEME.breakpoints.xs;
|
|
465
|
-
} else {
|
|
466
|
-
max = maxWidth(breakpoints, breakpoint);
|
|
467
|
-
}
|
|
468
|
-
} else if (query === 'only') {
|
|
469
|
-
min = breakpoints[breakpoint];
|
|
470
|
-
max = maxWidth(breakpoints, breakpoint);
|
|
471
|
-
}
|
|
472
|
-
} else if (query === 'between') {
|
|
473
|
-
min = breakpoints[breakpoint[0]];
|
|
474
|
-
max = maxWidth(breakpoints, breakpoint[1]);
|
|
475
|
-
}
|
|
476
|
-
if (min) {
|
|
477
|
-
retVal = `@media (min-width: ${min})`;
|
|
478
|
-
if (max) {
|
|
479
|
-
retVal = `${retVal} and (max-width: ${max})`;
|
|
480
|
-
}
|
|
481
|
-
} else if (max) {
|
|
482
|
-
retVal = `@media (max-width: ${max})`;
|
|
483
|
-
} else {
|
|
484
|
-
throw new Error(`Unexpected query and breakpoint combination: '${query}', '${breakpoint}'.`);
|
|
485
|
-
}
|
|
486
|
-
return retVal;
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
const exponentialSymbols = {
|
|
490
|
-
symbols: {
|
|
491
|
-
sqrt: {
|
|
492
|
-
func: {
|
|
493
|
-
symbol: 'sqrt',
|
|
494
|
-
f: a => Math.sqrt(a),
|
|
495
|
-
notation: 'func',
|
|
496
|
-
precedence: 0,
|
|
497
|
-
rightToLeft: 0,
|
|
498
|
-
argCount: 1
|
|
499
|
-
},
|
|
500
|
-
symbol: 'sqrt',
|
|
501
|
-
regSymbol: 'sqrt\\b'
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
};
|
|
505
|
-
const animationStyles$1 = (position, modifier) => {
|
|
506
|
-
const property = position.split('-')[0];
|
|
507
|
-
const animationName = keyframes(["0%,66%{", ":2px;border:transparent;}"], property);
|
|
508
|
-
return css(["&", "::before,&", "::after{animation:0.3s ease-in-out ", ";}"], modifier, modifier, animationName);
|
|
509
|
-
};
|
|
510
|
-
const positionStyles = (position, size, inset) => {
|
|
511
|
-
const margin = math(`${size} / -2`);
|
|
512
|
-
const placement = math(`${margin} + ${inset}`);
|
|
513
|
-
let clipPath;
|
|
514
|
-
let positionCss;
|
|
515
|
-
let propertyRadius;
|
|
516
|
-
if (position.startsWith('top')) {
|
|
517
|
-
propertyRadius = 'border-bottom-right-radius';
|
|
518
|
-
clipPath = 'polygon(100% 0, 100% 1px, 1px 100%, 0 100%, 0 0)';
|
|
519
|
-
positionCss = css(["top:", ";right:", ";left:", ";margin-left:", ";"], placement, position === 'top-right' && size, position === 'top' ? '50%' : position === 'top-left' && size, position === 'top' && margin);
|
|
520
|
-
} else if (position.startsWith('right')) {
|
|
521
|
-
propertyRadius = 'border-bottom-left-radius';
|
|
522
|
-
clipPath = 'polygon(100% 0, 100% 100%, calc(100% - 1px) 100%, 0 1px, 0 0)';
|
|
523
|
-
positionCss = css(["top:", ";right:", ";bottom:", ";margin-top:", ";"], position === 'right' ? '50%' : position === 'right-top' && size, placement, position === 'right-bottom' && size, position === 'right' && margin);
|
|
524
|
-
} else if (position.startsWith('bottom')) {
|
|
525
|
-
propertyRadius = 'border-top-left-radius';
|
|
526
|
-
clipPath = 'polygon(100% 0, calc(100% - 1px) 0, 0 calc(100% - 1px), 0 100%, 100% 100%)';
|
|
527
|
-
positionCss = css(["right:", ";bottom:", ";left:", ";margin-left:", ";"], position === 'bottom-right' && size, placement, position === 'bottom' ? '50%' : position === 'bottom-left' && size, position === 'bottom' && margin);
|
|
528
|
-
} else if (position.startsWith('left')) {
|
|
529
|
-
propertyRadius = 'border-top-right-radius';
|
|
530
|
-
clipPath = 'polygon(0 100%, 100% 100%, 100% calc(100% - 1px), 1px 0, 0 0)';
|
|
531
|
-
positionCss = css(["top:", ";bottom:", ";left:", ";margin-top:", ";"], position === 'left' ? '50%' : position === 'left-top' && size, size, placement, position === 'left' && margin);
|
|
532
|
-
}
|
|
533
|
-
return css(["&::before{", ":100%;clip-path:", ";}&::before,&::after{", "}"], propertyRadius, clipPath, positionCss);
|
|
534
|
-
};
|
|
535
|
-
function arrowStyles(position) {
|
|
536
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
537
|
-
const size = options.size || '6px';
|
|
538
|
-
const inset = options.inset || '0';
|
|
539
|
-
const squareSize = math(`${size} * 2 / sqrt(2)`, exponentialSymbols);
|
|
540
|
-
return css(["position:relative;&::before{border-width:inherit;border-style:inherit;border-color:transparent;background-clip:content-box;}&::after{z-index:-1;border:inherit;box-shadow:inherit;}&::before,&::after{position:absolute;transform:rotate(45deg);background-color:inherit;box-sizing:inherit;width:", ";height:", ";content:'';}", ";", ";"], squareSize, squareSize, positionStyles(position, squareSize, inset), options.animationModifier && animationStyles$1(position, options.animationModifier));
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
const useWindow = theme => {
|
|
544
|
-
const [controlledWindow, setControlledWindow] = useState();
|
|
545
|
-
useEffect(() => {
|
|
546
|
-
if (theme && theme.window) {
|
|
547
|
-
setControlledWindow(theme.window);
|
|
548
|
-
} else {
|
|
549
|
-
setControlledWindow(window);
|
|
550
|
-
}
|
|
551
|
-
}, [theme]);
|
|
552
|
-
return controlledWindow;
|
|
553
|
-
};
|
|
554
|
-
|
|
555
|
-
const useText = function (component, props, name, text) {
|
|
556
|
-
let condition = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
557
|
-
const value = condition ? props[name] : undefined;
|
|
558
|
-
return useMemo(() => {
|
|
559
|
-
if (condition) {
|
|
560
|
-
if (name === 'children') {
|
|
561
|
-
throw new Error('Error: `children` is not a valid `useText` prop.');
|
|
562
|
-
} else if (value === null || value === '') {
|
|
563
|
-
throw new Error(component.displayName ? `Error: you must provide a valid \`${name}\` text value for <${component.displayName}>.` : `Error: you must provide a valid \`${name}\` text value.`);
|
|
564
|
-
} else if (value === undefined) {
|
|
565
|
-
if (process.env.NODE_ENV === 'development') {
|
|
566
|
-
console.warn(component.displayName ? `Warning: you did not provide a customized/translated \`${name}\` text value for <${component.displayName}>. Zendesk Garden is rendering <${component.displayName} ${name}="${text}"> by default.` : `Warning: you did not provide a customized/translated \`${name}\` text value. Zendesk Garden is rendering ${name}="${text}" by default.`);
|
|
567
|
-
}
|
|
568
|
-
return text;
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
return value;
|
|
572
|
-
}, [component.displayName, value, name, text, condition]);
|
|
573
|
-
};
|
|
574
|
-
|
|
575
|
-
const animationStyles = (position, options) => {
|
|
576
|
-
const theme = options.theme || DEFAULT_THEME;
|
|
577
|
-
let translateValue = `${theme.space.base * 5}px`;
|
|
578
|
-
let transformFunction;
|
|
579
|
-
if (position === 'top') {
|
|
580
|
-
transformFunction = 'translateY';
|
|
581
|
-
} else if (position === 'right') {
|
|
582
|
-
transformFunction = 'translateX';
|
|
583
|
-
translateValue = `-${translateValue}`;
|
|
584
|
-
} else if (position === 'bottom') {
|
|
585
|
-
transformFunction = 'translateY';
|
|
586
|
-
translateValue = `-${translateValue}`;
|
|
587
|
-
} else {
|
|
588
|
-
transformFunction = 'translateX';
|
|
589
|
-
}
|
|
590
|
-
const animationName = keyframes(["0%{transform:", "(", ");}"], transformFunction, translateValue);
|
|
591
|
-
return css(["&", " ", "{animation:0.2s cubic-bezier(0.15,0.85,0.35,1.2) ", ";}"], options.animationModifier, options.childSelector || '> *', animationName);
|
|
592
|
-
};
|
|
593
|
-
const hiddenStyles = options => {
|
|
594
|
-
const transition = 'opacity 0.2s ease-in-out, 0.2s visibility 0s linear';
|
|
595
|
-
return css(["transition:", ";visibility:hidden;opacity:0;"], options.animationModifier && transition);
|
|
596
|
-
};
|
|
597
|
-
function menuStyles(position) {
|
|
598
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
599
|
-
const theme = options.theme || DEFAULT_THEME;
|
|
600
|
-
let marginProperty;
|
|
601
|
-
if (position === 'top') {
|
|
602
|
-
marginProperty = 'margin-bottom';
|
|
603
|
-
} else if (position === 'right') {
|
|
604
|
-
marginProperty = 'margin-left';
|
|
605
|
-
} else if (position === 'bottom') {
|
|
606
|
-
marginProperty = 'margin-top';
|
|
607
|
-
} else {
|
|
608
|
-
marginProperty = 'margin-right';
|
|
609
|
-
}
|
|
610
|
-
return css(["position:absolute;z-index:", ";", ":", ";line-height:0;font-size:0.01px;& ", "{display:inline-block;position:relative;margin:0;box-sizing:border-box;border:", " ", ";border-radius:", ";box-shadow:", ";background-color:", ";cursor:default;padding:0;text-align:", ";white-space:normal;font-size:", ";font-weight:", ";direction:", ";:focus{outline:none;}}", ";", ";"], options.zIndex || 0, marginProperty, options.margin, options.childSelector || '> *', theme.borders.sm, getColorV8('neutralHue', 300, theme), theme.borderRadii.md, theme.shadows.lg(`${theme.space.base * 5}px`, `${theme.space.base * 7.5}px`, getColorV8('chromeHue', 600, theme, 0.15)), getColorV8('background', 600 , theme), theme.rtl ? 'right' : 'left', theme.fontSizes.md, theme.fontWeights.regular, theme.rtl && 'rtl', options.animationModifier && animationStyles(position, options), options.hidden && hiddenStyles(options));
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
const SELECTOR_FOCUS_VISIBLE = '&:focus-visible, &[data-garden-focus-visible="true"]';
|
|
614
|
-
const focusStyles = _ref => {
|
|
615
|
-
let {
|
|
616
|
-
condition = true,
|
|
617
|
-
selector = SELECTOR_FOCUS_VISIBLE,
|
|
618
|
-
shadowWidth = 'md',
|
|
619
|
-
spacerWidth = 'xs',
|
|
620
|
-
styles: {
|
|
621
|
-
boxShadow,
|
|
622
|
-
...styles
|
|
623
|
-
} = {},
|
|
624
|
-
theme,
|
|
625
|
-
...options
|
|
626
|
-
} = _ref;
|
|
627
|
-
const _boxShadow = condition ? getFocusBoxShadow({
|
|
628
|
-
boxShadow,
|
|
629
|
-
shadowWidth,
|
|
630
|
-
spacerWidth,
|
|
631
|
-
theme,
|
|
632
|
-
...options
|
|
633
|
-
}) : boxShadow;
|
|
634
|
-
let outline;
|
|
635
|
-
let outlineOffset;
|
|
636
|
-
if (spacerWidth === null) {
|
|
637
|
-
outline = theme.shadowWidths[shadowWidth];
|
|
638
|
-
} else {
|
|
639
|
-
outline = `${math(`${theme.shadowWidths[shadowWidth]} - ${theme.shadowWidths[spacerWidth]}`)} solid transparent`;
|
|
640
|
-
outlineOffset = theme.shadowWidths[spacerWidth];
|
|
641
|
-
}
|
|
642
|
-
return css(["&:focus{outline:none;}", "{outline:", ";outline-offset:", ";box-shadow:", ";", "}"], selector, outline, outlineOffset, _boxShadow, styles);
|
|
643
|
-
};
|
|
644
|
-
|
|
645
|
-
const ARROW_POSITION = ['top', 'top-left', 'top-right', 'right', 'right-top', 'right-bottom', 'bottom', 'bottom-left', 'bottom-right', 'left', 'left-top', 'left-bottom'];
|
|
646
|
-
const MENU_POSITION = ['top', 'right', 'bottom', 'left'];
|
|
647
|
-
|
|
648
|
-
export { ARROW_POSITION as ARRAY_ARROW_POSITION, MENU_POSITION as ARRAY_MENU_POSITION, DEFAULT_THEME, PALETTE, SELECTOR_FOCUS_VISIBLE, ThemeProvider, arrowStyles, focusStyles, getColorV8 as getColor, getColorV8, getDocument, getFocusBoxShadow, getLineHeight, isRtl, mediaQuery, menuStyles, retrieveComponentStyles, retrieveComponentStyles as retrieveTheme, useDocument, useText, useWindow, withTheme };
|