@zendeskgarden/react-theming 9.0.0-next.6 → 9.0.0-next.8

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/index.esm.js DELETED
@@ -1,1158 +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, css, keyframes } from 'styled-components';
10
- import { useFocusVisible } from '@zendeskgarden/container-focusvisible';
11
- import { getControlledValue } from '@zendeskgarden/container-utilities';
12
- import { valid, scale } from 'chroma-js';
13
- import { rgba, darken, lighten, getValueAndUnit, math } from 'polished';
14
- import get from 'lodash.get';
15
- import memoize from 'lodash.memoize';
16
-
17
- function _extends() {
18
- _extends = Object.assign ? Object.assign.bind() : function (target) {
19
- for (var i = 1; i < arguments.length; i++) {
20
- var source = arguments[i];
21
- for (var key in source) {
22
- if (Object.prototype.hasOwnProperty.call(source, key)) {
23
- target[key] = source[key];
24
- }
25
- }
26
- }
27
- return target;
28
- };
29
- return _extends.apply(this, arguments);
30
- }
31
-
32
- const PALETTE = {
33
- black: '#000',
34
- white: '#fff',
35
- product: {
36
- support: '#00a656',
37
- message: '#37b8af',
38
- explore: '#30aabc',
39
- gather: '#f6c8be',
40
- guide: '#eb4962',
41
- connect: '#ff6224',
42
- chat: '#f79a3e',
43
- talk: '#efc93d',
44
- sell: '#c38f00'
45
- },
46
- grey: {
47
- 100: '#f4f6f6',
48
- 200: '#e4e7e9',
49
- 300: '#c7cdd0',
50
- 400: '#afb7bd',
51
- 500: '#88929d',
52
- 600: '#7f8a95',
53
- 700: '#65707a',
54
- 800: '#4b565f',
55
- 900: '#2e373f',
56
- 1000: '#1e252a',
57
- 1100: '#171b1f',
58
- 1200: '#101316'
59
- },
60
- blue: {
61
- 100: '#edf7ff',
62
- 200: '#d9eaf7',
63
- 300: '#b3d0e7',
64
- 400: '#92bbdb',
65
- 500: '#5896c9',
66
- 600: '#4b8ec5',
67
- 700: '#1f73b7',
68
- 800: '#18578b',
69
- 900: '#103859',
70
- 1000: '#0b253b',
71
- 1100: '#081c2d',
72
- 1200: '#061420'
73
- },
74
- red: {
75
- 100: '#fff2f3',
76
- 200: '#fde1e3',
77
- 300: '#f5bfc4',
78
- 400: '#f2a0a6',
79
- 500: '#e76973',
80
- 600: '#e35c67',
81
- 700: '#cd3642',
82
- 800: '#9d2933',
83
- 900: '#6c1219',
84
- 1000: '#431418',
85
- 1100: '#2d1315',
86
- 1200: '#1b1011'
87
- },
88
- yellow: {
89
- 100: '#fff3e4',
90
- 200: '#ffe2c2',
91
- 300: '#ffc079',
92
- 400: '#fba246',
93
- 500: '#d87916',
94
- 600: '#ce7117',
95
- 700: '#ac5918',
96
- 800: '#874114',
97
- 900: '#512d17',
98
- 1000: '#312016',
99
- 1100: '#221913',
100
- 1200: '#17120f'
101
- },
102
- green: {
103
- 100: '#eef8f4',
104
- 200: '#d7ede4',
105
- 300: '#b4d3c6',
106
- 400: '#91bfae',
107
- 500: '#3fa17e',
108
- 600: '#329974',
109
- 700: '#037f52',
110
- 800: '#186045',
111
- 900: '#0b3e2b',
112
- 1000: '#0c291e',
113
- 1100: '#0b1e17',
114
- 1200: '#0a1511'
115
- },
116
- kale: {
117
- 100: '#ecf9f9',
118
- 200: '#d8ebeb',
119
- 300: '#b3d2d0',
120
- 400: '#94bebd',
121
- 500: '#5e9b9c',
122
- 600: '#579394',
123
- 700: '#40787a',
124
- 800: '#275c5f',
125
- 900: '#0a3c42',
126
- 1000: '#02282d',
127
- 1100: '#041e22',
128
- 1200: '#061517'
129
- },
130
- fuschia: {
131
- 100: '#fbf3f8',
132
- 200: '#f6e2ef',
133
- 300: '#ecc0dc',
134
- 400: '#e3a2cc',
135
- 500: '#d36faf',
136
- 600: '#cf63a8',
137
- 700: '#b34496',
138
- 800: '#971688',
139
- 900: '#640e59',
140
- 1000: '#430a3d',
141
- 1100: '#34072f',
142
- 1200: '#260523',
143
- M400: '#cf62a8',
144
- M600: '#a8458c'
145
- },
146
- pink: {
147
- 100: '#fcf4f5',
148
- 200: '#f7e3e8',
149
- 300: '#edc1ca',
150
- 400: '#e4a5b3',
151
- 500: '#d57388',
152
- 600: '#e35b72',
153
- 700: '#d62054',
154
- 800: '#94304e',
155
- 900: '#611f32',
156
- 1000: '#401522',
157
- 1100: '#31101a',
158
- 1200: '#230b12',
159
- M400: '#d57287',
160
- M600: '#b23a5d'
161
- },
162
- crimson: {
163
- 100: '#fbf4f3',
164
- 200: '#f6e4e1',
165
- 300: '#eac3bc',
166
- 400: '#e1a89e',
167
- 500: '#d1796a',
168
- 600: '#cd6e5d',
169
- 700: '#be4938',
170
- 800: '#a32217',
171
- 900: '#6b160f',
172
- 1000: '#480f0a',
173
- 1100: '#370c08',
174
- 1200: '#280806',
175
- M400: '#cc6c5b',
176
- M600: '#b24a3c'
177
- },
178
- orange: {
179
- 100: '#fdf3ed',
180
- 200: '#f9e3d3',
181
- 300: '#f2c39f',
182
- 400: '#eda671',
183
- 500: '#e2721e',
184
- 600: '#d26e20',
185
- 700: '#af5626',
186
- 800: '#85421d',
187
- 900: '#562b13',
188
- 1000: '#3a1c0d',
189
- 1100: '#2c150a',
190
- 1200: '#1f0f07',
191
- M400: '#d4772c',
192
- M600: '#b35827'
193
- },
194
- lemon: {
195
- 100: '#fff6cf',
196
- 200: '#ffe682',
197
- 300: '#ffc417',
198
- 400: '#eda900',
199
- 500: '#ba8900',
200
- 600: '#b08100',
201
- 700: '#8f6900',
202
- 800: '#6d5000',
203
- 900: '#463300',
204
- 1000: '#2f2200',
205
- 1100: '#231a00',
206
- 1200: '#191200',
207
- M400: '#e7a500',
208
- M600: '#c38f00'
209
- },
210
- lime: {
211
- 100: '#ebfae6',
212
- 200: '#c9f2bd',
213
- 300: '#88e270',
214
- 400: '#4ecf2a',
215
- 500: '#4da42a',
216
- 600: '#489b20',
217
- 700: '#3d7e19',
218
- 800: '#385f23',
219
- 900: '#243c16',
220
- 1000: '#18280f',
221
- 1100: '#121e0b',
222
- 1200: '#0d1508',
223
- M400: '#519e2d',
224
- M600: '#47782c'
225
- },
226
- mint: {
227
- 100: '#d6ffeb',
228
- 200: '#83ffc3',
229
- 300: '#00ea79',
230
- 400: '#00d16d',
231
- 500: '#00a756',
232
- 600: '#279b65',
233
- 700: '#2d7d55',
234
- 800: '#225f41',
235
- 900: '#163d2a',
236
- 1000: '#0f291c',
237
- 1100: '#0b1e15',
238
- 1200: '#08150f',
239
- M400: '#299c66',
240
- M600: '#2e8057'
241
- },
242
- teal: {
243
- 100: '#d6fefa',
244
- 200: '#70fdef',
245
- 300: '#03e5ce',
246
- 400: '#03ccb8',
247
- 500: '#02a392',
248
- 600: '#1f998b',
249
- 700: '#367a74',
250
- 800: '#2e5c59',
251
- 900: '#1e3b39',
252
- 1000: '#142726',
253
- 1100: '#0f1d1c',
254
- 1200: '#0a1514',
255
- M400: '#2d9e8f',
256
- M600: '#3c7873'
257
- },
258
- azure: {
259
- 100: '#f0f7fe',
260
- 200: '#d7eafb',
261
- 300: '#a8d1f7',
262
- 400: '#7fbbf3',
263
- 500: '#3795ed',
264
- 600: '#598ad0',
265
- 700: '#2770c4',
266
- 800: '#2c5689',
267
- 900: '#1d3758',
268
- 1000: '#13253a',
269
- 1100: '#0e1b2c',
270
- 1200: '#0a131f',
271
- M400: '#5f8dcf',
272
- M600: '#3a70b2'
273
- },
274
- royal: {
275
- 100: '#f5f6fc',
276
- 200: '#e3e6f7',
277
- 300: '#c5cbee',
278
- 400: '#abb3e7',
279
- 500: '#7f8cda',
280
- 600: '#7182e1',
281
- 700: '#4d67d3',
282
- 800: '#1f40d8',
283
- 900: '#142a8d',
284
- 1000: '#0e1c5f',
285
- 1100: '#0a1548',
286
- 1200: '#070f34',
287
- M400: '#7986d8',
288
- M600: '#4b61c3'
289
- },
290
- purple: {
291
- 100: '#f9f4fb',
292
- 200: '#efe3f5',
293
- 300: '#ddc3e9',
294
- 400: '#cea8e0',
295
- 500: '#b57acf',
296
- 600: '#b16ecf',
297
- 700: '#9256b1',
298
- 800: '#722eb8',
299
- 900: '#491b7f',
300
- 1000: '#311256',
301
- 1100: '#250e41',
302
- 1200: '#1b0a2e',
303
- M400: '#b072cc',
304
- M600: '#9358b0'
305
- }
306
- };
307
-
308
- const BASE = 4;
309
- const borderRadii = {
310
- sm: `${BASE / 2}px`,
311
- md: `${BASE}px`
312
- };
313
- const borderStyles = {
314
- solid: 'solid'
315
- };
316
- const borderWidths = {
317
- sm: '1px',
318
- md: '3px'
319
- };
320
- const borders = {
321
- sm: `${borderWidths.sm} ${borderStyles.solid}`,
322
- md: `${borderWidths.md} ${borderStyles.solid}`
323
- };
324
- const breakpoints = {
325
- xs: '0px',
326
- sm: `${BASE * 144}px`,
327
- md: `${BASE * 192}px`,
328
- lg: `${BASE * 248}px`,
329
- xl: `${BASE * 300}px`
330
- };
331
- const colors = {
332
- primaryHue: 'blue',
333
- dangerHue: 'red',
334
- warningHue: 'yellow',
335
- successHue: 'green',
336
- neutralHue: 'grey',
337
- chromeHue: 'kale',
338
- variables: {
339
- dark: {
340
- background: {
341
- default: 'neutralHue.1100'
342
- },
343
- border: {
344
- default: 'neutralHue.700'
345
- },
346
- foreground: {
347
- default: 'neutralHue.300'
348
- }
349
- },
350
- light: {
351
- background: {
352
- default: 'palette.white'
353
- },
354
- border: {
355
- default: 'neutralHue.400'
356
- },
357
- foreground: {
358
- default: 'neutralHue.900'
359
- }
360
- }
361
- }
362
- };
363
- const fonts = {
364
- mono: ['SFMono-Regular' , 'Consolas' , '"Liberation Mono"' , 'Menlo', 'Courier', 'monospace'].join(','),
365
- system: ['system-ui' , '-apple-system' , 'BlinkMacSystemFont' , '"Segoe UI"' , 'Roboto' , 'Oxygen-Sans' , 'Ubuntu' , 'Cantarell' , '"Helvetica Neue"', 'Arial', 'sans-serif'].join(',')
366
- };
367
- const fontSizes = {
368
- xs: '10px',
369
- sm: '12px',
370
- md: '14px',
371
- lg: '18px',
372
- xl: '22px',
373
- xxl: '26px',
374
- xxxl: '36px'
375
- };
376
- const fontWeights = {
377
- thin: 100,
378
- extralight: 200,
379
- light: 300,
380
- regular: 400,
381
- medium: 500,
382
- semibold: 600,
383
- bold: 700,
384
- extrabold: 800,
385
- black: 900
386
- };
387
- const iconSizes = {
388
- sm: '12px',
389
- md: '16px',
390
- lg: '26px'
391
- };
392
- const lineHeights = {
393
- sm: `${BASE * 4}px`,
394
- md: `${BASE * 5}px`,
395
- lg: `${BASE * 6}px`,
396
- xl: `${BASE * 7}px`,
397
- xxl: `${BASE * 8}px`,
398
- xxxl: `${BASE * 11}px`
399
- };
400
- const palette = {
401
- ...PALETTE
402
- };
403
- delete palette.product;
404
- const shadowWidths = {
405
- xs: '1px',
406
- sm: '2px',
407
- md: '3px'
408
- };
409
- const shadows = {
410
- xs: color => `0 0 0 ${shadowWidths.xs} ${color}`,
411
- sm: color => `0 0 0 ${shadowWidths.sm} ${color}`,
412
- md: color => `0 0 0 ${shadowWidths.md} ${color}`,
413
- lg: (offsetY, blurRadius, color) => `0 ${offsetY} ${blurRadius} 0 ${color}`
414
- };
415
- const space = {
416
- base: BASE,
417
- xxs: `${BASE}px`,
418
- xs: `${BASE * 2}px`,
419
- sm: `${BASE * 3}px`,
420
- md: `${BASE * 5}px`,
421
- lg: `${BASE * 8}px`,
422
- xl: `${BASE * 10}px`,
423
- xxl: `${BASE * 12}px`
424
- };
425
- const DEFAULT_THEME = {
426
- borders,
427
- borderRadii,
428
- borderStyles,
429
- borderWidths,
430
- breakpoints,
431
- colors: {
432
- base: 'light',
433
- ...colors
434
- },
435
- components: {},
436
- fonts,
437
- fontSizes,
438
- fontWeights,
439
- iconSizes,
440
- lineHeights,
441
- palette,
442
- rtl: false,
443
- shadowWidths,
444
- shadows,
445
- space
446
- };
447
-
448
- const useDocument = theme => {
449
- const [controlledDocument, setControlledDocument] = useState();
450
- useEffect(() => {
451
- if (theme && theme.document) {
452
- setControlledDocument(theme.document);
453
- } else {
454
- setControlledDocument(document);
455
- }
456
- }, [theme]);
457
- return controlledDocument;
458
- };
459
-
460
- const ThemeProvider = _ref => {
461
- let {
462
- theme,
463
- focusVisibleRef,
464
- children,
465
- ...other
466
- } = _ref;
467
- const scopeRef = useRef(null);
468
- const relativeDocument = useDocument(theme);
469
- const controlledScopeRef = focusVisibleRef === null ? React.createRef() : getControlledValue(focusVisibleRef, scopeRef);
470
- useFocusVisible({
471
- scope: controlledScopeRef,
472
- relativeDocument
473
- });
474
- return React.createElement(ThemeProvider$1, _extends({
475
- theme: theme
476
- }, other), focusVisibleRef === undefined ? React.createElement("div", {
477
- ref: scopeRef
478
- }, children) : children);
479
- };
480
- ThemeProvider.defaultProps = {
481
- theme: DEFAULT_THEME
482
- };
483
-
484
- const PALETTE_V8 = {
485
- black: '#000',
486
- white: '#fff',
487
- product: {
488
- support: '#00a656',
489
- message: '#37b8af',
490
- explore: '#30aabc',
491
- gather: '#f6c8be',
492
- guide: '#eb4962',
493
- connect: '#ff6224',
494
- chat: '#f79a3e',
495
- talk: '#efc93d',
496
- sell: '#c38f00'
497
- },
498
- grey: {
499
- 100: '#f8f9f9',
500
- 200: '#e9ebed',
501
- 300: '#d8dcde',
502
- 400: '#c2c8cc',
503
- 500: '#87929d',
504
- 600: '#68737d',
505
- 700: '#49545c',
506
- 800: '#2f3941'
507
- },
508
- blue: {
509
- 100: '#edf7ff',
510
- 200: '#cee2f2',
511
- 300: '#adcce4',
512
- 400: '#5293c7',
513
- 500: '#337fbd',
514
- 600: '#1f73b7',
515
- 700: '#144a75',
516
- 800: '#0f3554'
517
- },
518
- red: {
519
- 100: '#fff0f1',
520
- 200: '#f5d5d8',
521
- 300: '#f5b5ba',
522
- 400: '#e35b66',
523
- 500: '#d93f4c',
524
- 600: '#cc3340',
525
- 700: '#8c232c',
526
- 800: '#681219'
527
- },
528
- yellow: {
529
- 100: '#fff7ed',
530
- 200: '#ffeedb',
531
- 300: '#fed6a8',
532
- 400: '#ffb057',
533
- 500: '#f79a3e',
534
- 600: '#ed8f1c',
535
- 700: '#ad5918',
536
- 800: '#703815'
537
- },
538
- green: {
539
- 100: '#edf8f4',
540
- 200: '#d1e8df',
541
- 300: '#aecfc2',
542
- 400: '#5eae91',
543
- 500: '#228f67',
544
- 600: '#038153',
545
- 700: '#186146',
546
- 800: '#0b3b29'
547
- },
548
- kale: {
549
- 100: '#f5fcfc',
550
- 200: '#daeded',
551
- 300: '#bdd9d7',
552
- 400: '#90bbbb',
553
- 500: '#498283',
554
- 600: '#17494d',
555
- 700: '#03363d',
556
- 800: '#012b30'
557
- },
558
- fuschia: {
559
- 400: '#d653c2',
560
- 600: '#a81897',
561
- M400: '#cf62a8',
562
- M600: '#a8458c'
563
- },
564
- pink: {
565
- 400: '#ec4d63',
566
- 600: '#d42054',
567
- M400: '#d57287',
568
- M600: '#b23a5d'
569
- },
570
- crimson: {
571
- 400: '#e34f32',
572
- 600: '#c72a1c',
573
- M400: '#cc6c5b',
574
- M600: '#b24a3c'
575
- },
576
- orange: {
577
- 400: '#de701d',
578
- 600: '#bf5000',
579
- M400: '#d4772c',
580
- M600: '#b35827'
581
- },
582
- lemon: {
583
- 400: '#ffd424',
584
- 600: '#ffbb10',
585
- M400: '#e7a500',
586
- M600: '#c38f00'
587
- },
588
- lime: {
589
- 400: '#43b324',
590
- 600: '#2e8200',
591
- M400: '#519e2d',
592
- M600: '#47782c'
593
- },
594
- mint: {
595
- 400: '#00a656',
596
- 600: '#058541',
597
- M400: '#299c66',
598
- M600: '#2e8057'
599
- },
600
- teal: {
601
- 400: '#02a191',
602
- 600: '#028079',
603
- M400: '#2d9e8f',
604
- M600: '#3c7873'
605
- },
606
- azure: {
607
- 400: '#3091ec',
608
- 600: '#1371d6',
609
- M400: '#5f8dcf',
610
- M600: '#3a70b2'
611
- },
612
- royal: {
613
- 400: '#5d7df5',
614
- 600: '#3353e2',
615
- M400: '#7986d8',
616
- M600: '#4b61c3'
617
- },
618
- purple: {
619
- 400: '#b552e2',
620
- 600: '#6a27b8',
621
- M400: '#b072cc',
622
- M600: '#9358b0'
623
- }
624
- };
625
-
626
- function retrieveComponentStyles(componentId, props) {
627
- const components = props.theme && props.theme.components;
628
- if (!components) {
629
- return undefined;
630
- }
631
- const componentStyles = components[componentId];
632
- if (typeof componentStyles === 'function') {
633
- return componentStyles(props);
634
- }
635
- return componentStyles;
636
- }
637
-
638
- const POSITION_MAP = {
639
- top: 'bottom',
640
- 'top-start': 'bottom-left',
641
- 'top-end': 'bottom-right',
642
- right: 'left',
643
- 'right-start': 'left-top',
644
- 'right-end': 'left-bottom',
645
- bottom: 'top',
646
- 'bottom-start': 'top-left',
647
- 'bottom-end': 'top-right',
648
- left: 'right',
649
- 'left-start': 'right-top',
650
- 'left-end': 'right-bottom'
651
- };
652
- const RTL_POSITION_MAP = {
653
- 'bottom-left': 'bottom-right',
654
- 'bottom-right': 'bottom-left',
655
- 'top-left': 'top-right',
656
- 'top-right': 'top-left'
657
- };
658
- const getArrowPosition = (theme, placement) => {
659
- let retVal = POSITION_MAP[placement];
660
- if (theme.rtl) {
661
- retVal = RTL_POSITION_MAP[retVal] || retVal;
662
- }
663
- return retVal;
664
- };
665
-
666
- const PALETTE_SIZE = Object.keys(PALETTE.blue).length;
667
- const adjust$1 = (color, expected, actual) => {
668
- if (expected !== actual) {
669
- const amount = Math.abs(expected - actual) / 100 * 0.05;
670
- return expected > actual ? darken(amount, color) : lighten(amount, color);
671
- }
672
- return color;
673
- };
674
- const toShade = (shade, offset, scheme) => {
675
- let _shade;
676
- if (shade === undefined) {
677
- _shade = scheme === 'dark' ? 500 : 700;
678
- } else {
679
- _shade = parseInt(shade.toString(), 10);
680
- if (isNaN(_shade)) {
681
- throw new TypeError(`Error: unexpected '${typeof shade}' type for color shade "${shade}"`);
682
- }
683
- }
684
- return _shade + (offset || 0);
685
- };
686
- const toHex = (hue, shade, offset, scheme) => {
687
- const _shade = toShade(shade, offset, scheme);
688
- let retVal = hue[_shade];
689
- if (!retVal) {
690
- const closestShade = Object.keys(hue).map(hueShade => parseInt(hueShade, 10)).reduce((previous, current) => {
691
- return Math.abs(current - _shade) < Math.abs(previous - _shade) ? current : previous;
692
- });
693
- retVal = adjust$1(hue[closestShade], _shade, closestShade);
694
- }
695
- return retVal;
696
- };
697
- const toColor = (colors, palette, scheme, hue, shade, offset, transparency) => {
698
- let retVal;
699
- let _hue = colors[hue] || hue;
700
- if (Object.hasOwn(palette, _hue)) {
701
- _hue = palette[_hue];
702
- }
703
- if (typeof _hue === 'object') {
704
- retVal = toHex(_hue, shade, offset, scheme);
705
- } else if (valid(_hue)) {
706
- if (shade === undefined) {
707
- retVal = _hue;
708
- } else {
709
- const _colors = scale([PALETTE.white, _hue, PALETTE.black]).correctLightness().colors(PALETTE_SIZE + 2);
710
- _hue = _colors.reduce((_retVal, color, index) => {
711
- if (index > 0 && index <= PALETTE_SIZE) {
712
- _retVal[index * 100] = color;
713
- }
714
- return _retVal;
715
- }, {});
716
- retVal = toHex(_hue, shade, offset, scheme);
717
- }
718
- }
719
- if (retVal && transparency) {
720
- retVal = rgba(retVal, transparency);
721
- }
722
- return retVal;
723
- };
724
- const toProperty = (object, path) => {
725
- const retVal = get(object, path);
726
- if (typeof retVal === 'string') {
727
- return retVal;
728
- } else if (retVal === undefined) {
729
- throw new ReferenceError(`Error: color variable '${path}' is not defined`);
730
- } else {
731
- throw new TypeError(`Error: unexpected '${typeof retVal}' type for color variable "${path}"`);
732
- }
733
- };
734
- const getColor = memoize(_ref => {
735
- let {
736
- dark,
737
- hue,
738
- light,
739
- offset,
740
- shade,
741
- theme,
742
- transparency,
743
- variable
744
- } = _ref;
745
- let retVal;
746
- const palette = theme.palette && Object.keys(theme.palette).length > 0 ? theme.palette : DEFAULT_THEME.palette;
747
- const {
748
- base,
749
- variables,
750
- ...colors
751
- } = theme.colors && Object.keys(theme.colors).length > 0 ? theme.colors : DEFAULT_THEME.colors;
752
- const scheme = base === 'dark' ? 'dark' : 'light';
753
- const mode = scheme === 'dark' ? dark : light;
754
- let _hue = mode?.hue || hue;
755
- let _shade = mode?.shade === undefined ? shade : mode.shade;
756
- const _offset = mode?.offset === undefined ? offset : mode.offset;
757
- const _transparency = mode?.transparency === undefined ? transparency : mode.transparency;
758
- if (variable) {
759
- const _variables = variables?.[scheme] ? variables[scheme] : DEFAULT_THEME.colors.variables[scheme];
760
- const property = toProperty(_variables, variable);
761
- const [key, value] = property.split(/\.(?<value>.*)/u);
762
- if (key === 'palette') {
763
- _hue = toProperty(palette, value);
764
- } else {
765
- _hue = key;
766
- _shade = parseInt(value, 10);
767
- }
768
- }
769
- if (_hue) {
770
- retVal = toColor(colors, palette, scheme, _hue, _shade, _offset, _transparency);
771
- }
772
- if (retVal === undefined) {
773
- throw new Error('Error: invalid `getColor` parameters');
774
- }
775
- return retVal;
776
- }, _ref2 => {
777
- let {
778
- dark,
779
- hue,
780
- light,
781
- offset,
782
- shade,
783
- theme,
784
- transparency,
785
- variable
786
- } = _ref2;
787
- return JSON.stringify({
788
- dark,
789
- hue,
790
- light,
791
- offset,
792
- shade,
793
- colors: theme.colors,
794
- palette: theme.palette,
795
- transparency,
796
- variable
797
- });
798
- });
799
-
800
- const DEFAULT_SHADE = 600;
801
- const adjust = (color, expected, actual) => {
802
- if (expected !== actual) {
803
- const amount = Math.abs(expected - actual) / 100 * 0.05;
804
- return expected > actual ? darken(amount, color) : lighten(amount, color);
805
- }
806
- return color;
807
- };
808
- const getColorV8 = memoize(function (hue) {
809
- let shade = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_SHADE;
810
- let theme = arguments.length > 2 ? arguments[2] : undefined;
811
- let transparency = arguments.length > 3 ? arguments[3] : undefined;
812
- let retVal;
813
- if (isNaN(shade)) {
814
- return undefined;
815
- }
816
- const palette = {
817
- background: PALETTE_V8.white,
818
- foreground: PALETTE_V8.grey[800],
819
- ...(theme && theme.palette ? {
820
- ...theme.palette,
821
- ...PALETTE_V8
822
- } : {
823
- ...DEFAULT_THEME.palette,
824
- ...PALETTE_V8
825
- })
826
- };
827
- const colors = theme && theme.colors ? theme.colors : DEFAULT_THEME.colors;
828
- let _hue;
829
- if (typeof hue === 'string') {
830
- _hue = colors[hue] || hue;
831
- } else {
832
- _hue = hue;
833
- }
834
- if (Object.prototype.hasOwnProperty.call(palette, _hue)) {
835
- _hue = palette[_hue];
836
- }
837
- if (typeof _hue === 'object') {
838
- retVal = _hue[shade];
839
- if (!retVal) {
840
- const _shade = Object.keys(_hue).map(hueKey => parseInt(hueKey, 10)).reduce((previous, current) => {
841
- return Math.abs(current - shade) < Math.abs(previous - shade) ? current : previous;
842
- });
843
- retVal = adjust(_hue[_shade], shade, _shade);
844
- }
845
- } else {
846
- retVal = adjust(_hue, shade, DEFAULT_SHADE);
847
- }
848
- if (transparency) {
849
- retVal = rgba(retVal, transparency);
850
- }
851
- return retVal;
852
- }, (hue, shade, theme, transparency) => JSON.stringify({
853
- hue,
854
- shade,
855
- palette: theme?.palette,
856
- colors: theme?.colors,
857
- transparency
858
- }));
859
-
860
- const PLACEMENT_MAP = {
861
- end: 'right',
862
- 'end-top': 'right-start',
863
- 'end-bottom': 'right-end',
864
- start: 'left',
865
- 'start-top': 'left-start',
866
- 'start-bottom': 'left-end'
867
- };
868
- const RTL_PLACEMENT_MAP = {
869
- left: 'right',
870
- 'left-start': 'right-start',
871
- 'left-end': 'right-end',
872
- right: 'left',
873
- 'right-start': 'left-start',
874
- 'right-end': 'left-end'
875
- };
876
- const toFloatingPlacement = (placement, theme) => {
877
- let retVal = PLACEMENT_MAP[placement] || placement;
878
- if (theme.rtl) {
879
- retVal = RTL_PLACEMENT_MAP[retVal] || retVal;
880
- }
881
- return retVal;
882
- };
883
- const SIDE_FALLBACKS_MAP = {
884
- top: ['top-start', 'top', 'top-end'],
885
- right: ['right-start', 'right', 'right-end'],
886
- bottom: ['bottom-start', 'bottom', 'bottom-end'],
887
- left: ['left-start', 'left', 'left-end']
888
- };
889
- const SIDE_OPPOSITE_MAP = {
890
- top: 'bottom',
891
- right: 'left',
892
- bottom: 'top',
893
- left: 'right'
894
- };
895
- const toFallbackPlacements = (primaryPlacement, theme, fallbackPlacements) => {
896
- if (Array.isArray(fallbackPlacements) && fallbackPlacements.length > 0) {
897
- return fallbackPlacements.map(fallbackPlacement => toFloatingPlacement(fallbackPlacement, theme));
898
- }
899
- const side = primaryPlacement.split('-')[0];
900
- const sameSideFallbackPlacements = [...SIDE_FALLBACKS_MAP[side]];
901
- const oppositeSideFallbackPlacements = SIDE_FALLBACKS_MAP[SIDE_OPPOSITE_MAP[side]];
902
- sameSideFallbackPlacements.splice(sameSideFallbackPlacements.indexOf(primaryPlacement), 1);
903
- return [...sameSideFallbackPlacements, ...oppositeSideFallbackPlacements];
904
- };
905
- const getFloatingPlacements = (theme, placement, fallbackPlacements) => {
906
- const floatingPlacement = toFloatingPlacement(placement, theme);
907
- const floatingFallbackPlacements = toFallbackPlacements(floatingPlacement, theme, fallbackPlacements);
908
- return [floatingPlacement, floatingFallbackPlacements];
909
- };
910
-
911
- const getFocusBoxShadow = _ref => {
912
- let {
913
- boxShadow,
914
- inset = false,
915
- hue = 'primaryHue',
916
- shade = DEFAULT_SHADE,
917
- shadowWidth = 'md',
918
- spacerHue = 'background',
919
- spacerShade = DEFAULT_SHADE,
920
- spacerWidth = 'xs',
921
- theme = DEFAULT_THEME
922
- } = _ref;
923
- const color = getColorV8(hue, shade, theme);
924
- const shadow = theme.shadows[shadowWidth](color);
925
- if (spacerWidth === null) {
926
- return `${inset ? 'inset' : ''} ${shadow}`;
927
- }
928
- const spacerColor = getColorV8(spacerHue, spacerShade, theme);
929
- const retVal = `
930
- ${inset ? 'inset' : ''} ${theme.shadows[spacerWidth](spacerColor)},
931
- ${inset ? 'inset' : ''} ${shadow}`;
932
- return boxShadow ? `${retVal}, ${boxShadow}` : retVal;
933
- };
934
-
935
- function getLineHeight(height, fontSize) {
936
- const [heightValue, heightUnit] = getValueAndUnit(height.toString());
937
- const [fontSizeValue, fontSizeUnit] = getValueAndUnit(fontSize.toString());
938
- const PIXELS = 'px';
939
- if (heightUnit && heightUnit !== PIXELS) {
940
- throw new Error(`Unexpected \`height\` with '${heightUnit}' units.`);
941
- }
942
- if (fontSizeUnit && fontSizeUnit !== PIXELS) {
943
- throw new Error(`Unexpected \`fontSize\` with '${fontSizeUnit}' units.`);
944
- }
945
- return heightValue / fontSizeValue;
946
- }
947
-
948
- const getMenuPosition = placement => {
949
- return placement.split('-')[0];
950
- };
951
-
952
- const maxWidth = (breakpoints, breakpoint) => {
953
- const keys = Object.keys(breakpoints);
954
- const index = keys.indexOf(breakpoint) + 1;
955
- if (keys[index]) {
956
- const dimension = getValueAndUnit(breakpoints[keys[index]]);
957
- const value = dimension[0] - 0.02;
958
- const unit = dimension[1];
959
- return `${value}${unit}`;
960
- }
961
- return undefined;
962
- };
963
- function mediaQuery(query, breakpoint, theme) {
964
- let retVal;
965
- let min;
966
- let max;
967
- const breakpoints = theme && theme.breakpoints ? theme.breakpoints : DEFAULT_THEME.breakpoints;
968
- if (typeof breakpoint === 'string') {
969
- if (query === 'up') {
970
- min = breakpoints[breakpoint];
971
- } else if (query === 'down') {
972
- if (breakpoint === 'xl') {
973
- min = DEFAULT_THEME.breakpoints.xs;
974
- } else {
975
- max = maxWidth(breakpoints, breakpoint);
976
- }
977
- } else if (query === 'only') {
978
- min = breakpoints[breakpoint];
979
- max = maxWidth(breakpoints, breakpoint);
980
- }
981
- } else if (query === 'between') {
982
- min = breakpoints[breakpoint[0]];
983
- max = maxWidth(breakpoints, breakpoint[1]);
984
- }
985
- if (min) {
986
- retVal = `@media (min-width: ${min})`;
987
- if (max) {
988
- retVal = `${retVal} and (max-width: ${max})`;
989
- }
990
- } else if (max) {
991
- retVal = `@media (max-width: ${max})`;
992
- } else {
993
- throw new Error(`Unexpected query and breakpoint combination: '${query}', '${breakpoint}'.`);
994
- }
995
- return retVal;
996
- }
997
-
998
- const exponentialSymbols = {
999
- symbols: {
1000
- sqrt: {
1001
- func: {
1002
- symbol: 'sqrt',
1003
- f: a => Math.sqrt(a),
1004
- notation: 'func',
1005
- precedence: 0,
1006
- rightToLeft: 0,
1007
- argCount: 1
1008
- },
1009
- symbol: 'sqrt',
1010
- regSymbol: 'sqrt\\b'
1011
- }
1012
- }
1013
- };
1014
- const animationStyles$1 = (position, modifier) => {
1015
- const property = position.split('-')[0];
1016
- const animationName = keyframes(["0%,66%{", ":2px;border:transparent;}"], property);
1017
- return css(["&", "::before,&", "::after{animation:0.3s ease-in-out ", ";}"], modifier, modifier, animationName);
1018
- };
1019
- const positionStyles = (position, size, inset) => {
1020
- const margin = math(`${size} / -2`);
1021
- const placement = math(`${margin} + ${inset}`);
1022
- let clipPath;
1023
- let positionCss;
1024
- let propertyRadius;
1025
- if (position.startsWith('top')) {
1026
- propertyRadius = 'border-bottom-right-radius';
1027
- clipPath = 'polygon(100% 0, 100% 1px, 1px 100%, 0 100%, 0 0)';
1028
- positionCss = css(["top:", ";right:", ";left:", ";margin-left:", ";"], placement, position === 'top-right' && size, position === 'top' ? '50%' : position === 'top-left' && size, position === 'top' && margin);
1029
- } else if (position.startsWith('right')) {
1030
- propertyRadius = 'border-bottom-left-radius';
1031
- clipPath = 'polygon(100% 0, 100% 100%, calc(100% - 1px) 100%, 0 1px, 0 0)';
1032
- positionCss = css(["top:", ";right:", ";bottom:", ";margin-top:", ";"], position === 'right' ? '50%' : position === 'right-top' && size, placement, position === 'right-bottom' && size, position === 'right' && margin);
1033
- } else if (position.startsWith('bottom')) {
1034
- propertyRadius = 'border-top-left-radius';
1035
- clipPath = 'polygon(100% 0, calc(100% - 1px) 0, 0 calc(100% - 1px), 0 100%, 100% 100%)';
1036
- positionCss = css(["right:", ";bottom:", ";left:", ";margin-left:", ";"], position === 'bottom-right' && size, placement, position === 'bottom' ? '50%' : position === 'bottom-left' && size, position === 'bottom' && margin);
1037
- } else if (position.startsWith('left')) {
1038
- propertyRadius = 'border-top-right-radius';
1039
- clipPath = 'polygon(0 100%, 100% 100%, 100% calc(100% - 1px), 1px 0, 0 0)';
1040
- positionCss = css(["top:", ";bottom:", ";left:", ";margin-top:", ";"], position === 'left' ? '50%' : position === 'left-top' && size, size, placement, position === 'left' && margin);
1041
- }
1042
- return css(["&::before{", ":100%;clip-path:", ";}&::before,&::after{", "}"], propertyRadius, clipPath, positionCss);
1043
- };
1044
- function arrowStyles(position) {
1045
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1046
- const size = options.size || '6px';
1047
- const inset = options.inset || '0';
1048
- const squareSize = math(`${size} * 2 / sqrt(2)`, exponentialSymbols);
1049
- 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));
1050
- }
1051
-
1052
- const useWindow = theme => {
1053
- const [controlledWindow, setControlledWindow] = useState();
1054
- useEffect(() => {
1055
- if (theme && theme.window) {
1056
- setControlledWindow(theme.window);
1057
- } else {
1058
- setControlledWindow(window);
1059
- }
1060
- }, [theme]);
1061
- return controlledWindow;
1062
- };
1063
-
1064
- const useText = function (component, props, name, text) {
1065
- let condition = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
1066
- const value = condition ? props[name] : undefined;
1067
- return useMemo(() => {
1068
- if (condition) {
1069
- if (name === 'children') {
1070
- throw new Error('Error: `children` is not a valid `useText` prop.');
1071
- } else if (value === null || value === '') {
1072
- 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.`);
1073
- } else if (value === undefined) {
1074
- if (process.env.NODE_ENV === 'development') {
1075
- 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.`);
1076
- }
1077
- return text;
1078
- }
1079
- }
1080
- return value;
1081
- }, [component.displayName, value, name, text, condition]);
1082
- };
1083
-
1084
- const animationStyles = (position, options) => {
1085
- const theme = options.theme || DEFAULT_THEME;
1086
- let translateValue = `${theme.space.base * 5}px`;
1087
- let transformFunction;
1088
- if (position === 'top') {
1089
- transformFunction = 'translateY';
1090
- } else if (position === 'right') {
1091
- transformFunction = 'translateX';
1092
- translateValue = `-${translateValue}`;
1093
- } else if (position === 'bottom') {
1094
- transformFunction = 'translateY';
1095
- translateValue = `-${translateValue}`;
1096
- } else {
1097
- transformFunction = 'translateX';
1098
- }
1099
- const animationName = keyframes(["0%{transform:", "(", ");}"], transformFunction, translateValue);
1100
- return css(["&", " ", "{animation:0.2s cubic-bezier(0.15,0.85,0.35,1.2) ", ";}"], options.animationModifier, options.childSelector || '> *', animationName);
1101
- };
1102
- const hiddenStyles = options => {
1103
- const transition = 'opacity 0.2s ease-in-out, 0.2s visibility 0s linear';
1104
- return css(["transition:", ";visibility:hidden;opacity:0;"], options.animationModifier && transition);
1105
- };
1106
- function menuStyles(position) {
1107
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1108
- const theme = options.theme || DEFAULT_THEME;
1109
- let marginProperty;
1110
- if (position === 'top') {
1111
- marginProperty = 'margin-bottom';
1112
- } else if (position === 'right') {
1113
- marginProperty = 'margin-left';
1114
- } else if (position === 'bottom') {
1115
- marginProperty = 'margin-top';
1116
- } else {
1117
- marginProperty = 'margin-right';
1118
- }
1119
- 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));
1120
- }
1121
-
1122
- const SELECTOR_FOCUS_VISIBLE = '&:focus-visible, &[data-garden-focus-visible="true"]';
1123
- const focusStyles = _ref => {
1124
- let {
1125
- condition = true,
1126
- selector = SELECTOR_FOCUS_VISIBLE,
1127
- shadowWidth = 'md',
1128
- spacerWidth = 'xs',
1129
- styles: {
1130
- boxShadow,
1131
- ...styles
1132
- } = {},
1133
- theme,
1134
- ...options
1135
- } = _ref;
1136
- const _boxShadow = condition ? getFocusBoxShadow({
1137
- boxShadow,
1138
- shadowWidth,
1139
- spacerWidth,
1140
- theme,
1141
- ...options
1142
- }) : boxShadow;
1143
- let outline;
1144
- let outlineOffset;
1145
- if (spacerWidth === null) {
1146
- outline = theme.shadowWidths[shadowWidth];
1147
- } else {
1148
- outline = `${math(`${theme.shadowWidths[shadowWidth]} - ${theme.shadowWidths[spacerWidth]}`)} solid transparent`;
1149
- outlineOffset = theme.shadowWidths[spacerWidth];
1150
- }
1151
- return css(["&:focus{outline:none;}", "{outline:", ";outline-offset:", ";box-shadow:", ";", "}"], selector, outline, outlineOffset, _boxShadow, styles);
1152
- };
1153
-
1154
- const ARROW_POSITION = ['top', 'top-left', 'top-right', 'right', 'right-top', 'right-bottom', 'bottom', 'bottom-left', 'bottom-right', 'left', 'left-top', 'left-bottom'];
1155
- const MENU_POSITION = ['top', 'right', 'bottom', 'left'];
1156
- const PLACEMENT = ['top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end', 'end', 'end-top', 'end-bottom', 'start', 'start-top', 'start-bottom'];
1157
-
1158
- export { ARROW_POSITION, DEFAULT_THEME, MENU_POSITION, PALETTE, PALETTE_V8, PLACEMENT, SELECTOR_FOCUS_VISIBLE, ThemeProvider, arrowStyles, focusStyles, getArrowPosition, getColor, getColorV8, getFloatingPlacements, getFocusBoxShadow, getLineHeight, getMenuPosition, mediaQuery, menuStyles, retrieveComponentStyles, useDocument, useText, useWindow };