@zendeskgarden/react-theming 9.0.0-next.1 → 9.0.0-next.10

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.
Files changed (40) hide show
  1. package/dist/esm/elements/ThemeProvider.js +24 -0
  2. package/dist/esm/elements/palette/index.js +259 -0
  3. package/dist/esm/elements/palette/v8.js +149 -0
  4. package/dist/esm/elements/theme/index.js +224 -0
  5. package/dist/esm/index.js +28 -0
  6. package/dist/esm/types/index.js +11 -0
  7. package/dist/esm/utils/StyledBaseIcon.js +22 -0
  8. package/dist/esm/utils/arrowStyles.js +64 -0
  9. package/dist/esm/utils/focusStyles.js +43 -0
  10. package/dist/esm/utils/getArrowPosition.js +35 -0
  11. package/dist/esm/utils/getCheckeredBackground.js +40 -0
  12. package/dist/esm/utils/getColor.js +153 -0
  13. package/dist/esm/utils/getColorV8.js +72 -0
  14. package/dist/esm/utils/getFloatingPlacements.js +58 -0
  15. package/dist/esm/utils/getFocusBoxShadow.js +45 -0
  16. package/dist/esm/utils/getLineHeight.js +22 -0
  17. package/dist/esm/utils/getMenuPosition.js +11 -0
  18. package/dist/esm/utils/mediaQuery.js +56 -0
  19. package/dist/esm/utils/menuStyles.js +63 -0
  20. package/dist/esm/utils/retrieveComponentStyles.js +19 -0
  21. package/dist/esm/utils/useDocument.js +21 -0
  22. package/dist/esm/utils/useText.js +29 -0
  23. package/dist/esm/utils/useWindow.js +21 -0
  24. package/dist/index.cjs.js +726 -177
  25. package/dist/typings/elements/ThemeProvider.d.ts +1 -1
  26. package/dist/typings/elements/palette/index.d.ts +134 -26
  27. package/dist/typings/elements/palette/v8.d.ts +149 -0
  28. package/dist/typings/elements/theme/index.d.ts +0 -1
  29. package/dist/typings/index.d.ts +6 -4
  30. package/dist/typings/types/index.d.ts +59 -16
  31. package/dist/typings/utils/StyledBaseIcon.d.ts +8 -0
  32. package/dist/typings/utils/focusStyles.d.ts +3 -11
  33. package/dist/typings/utils/getArrowPosition.d.ts +4 -2
  34. package/dist/typings/utils/getCheckeredBackground.d.ts +20 -0
  35. package/dist/typings/utils/getColor.d.ts +14 -9
  36. package/dist/typings/utils/getColorV8.d.ts +27 -0
  37. package/dist/typings/utils/getFocusBoxShadow.d.ts +6 -21
  38. package/dist/typings/utils/menuStyles.d.ts +2 -2
  39. package/package.json +8 -6
  40. package/dist/index.esm.js +0 -708
package/dist/index.esm.js DELETED
@@ -1,708 +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 { 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 retrieveComponentStyles(componentId, props) {
327
- const components = props.theme && props.theme.components;
328
- if (!components) {
329
- return undefined;
330
- }
331
- const componentStyles = components[componentId];
332
- if (typeof componentStyles === 'function') {
333
- return componentStyles(props);
334
- }
335
- return componentStyles;
336
- }
337
-
338
- const POSITION_MAP = {
339
- top: 'bottom',
340
- 'top-start': 'bottom-left',
341
- 'top-end': 'bottom-right',
342
- right: 'left',
343
- 'right-start': 'left-top',
344
- 'right-end': 'left-bottom',
345
- bottom: 'top',
346
- 'bottom-start': 'top-left',
347
- 'bottom-end': 'top-right',
348
- left: 'right',
349
- 'left-start': 'right-top',
350
- 'left-end': 'right-bottom'
351
- };
352
- const getArrowPosition = placement => {
353
- return POSITION_MAP[placement];
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 getColor = 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 PLACEMENT_MAP = {
407
- end: 'right',
408
- 'end-top': 'right-start',
409
- 'end-bottom': 'right-end',
410
- start: 'left',
411
- 'start-top': 'left-start',
412
- 'start-bottom': 'left-end'
413
- };
414
- const RTL_PLACEMENT_MAP = {
415
- left: 'right',
416
- 'left-start': 'right-start',
417
- 'left-end': 'right-end',
418
- 'top-start': 'top-end',
419
- 'top-end': 'top-start',
420
- right: 'left',
421
- 'right-start': 'left-start',
422
- 'right-end': 'left-end',
423
- 'bottom-start': 'bottom-end',
424
- 'bottom-end': 'bottom-start'
425
- };
426
- const toFloatingPlacement = (placement, theme) => {
427
- let retVal = PLACEMENT_MAP[placement] || placement;
428
- if (theme.rtl) {
429
- retVal = RTL_PLACEMENT_MAP[retVal] || retVal;
430
- }
431
- return retVal;
432
- };
433
- const SIDE_FALLBACKS_MAP = {
434
- top: ['top-start', 'top', 'top-end'],
435
- right: ['right-start', 'right', 'right-end'],
436
- bottom: ['bottom-start', 'bottom', 'bottom-end'],
437
- left: ['left-start', 'left', 'left-end']
438
- };
439
- const SIDE_OPPOSITE_MAP = {
440
- top: 'bottom',
441
- right: 'left',
442
- bottom: 'top',
443
- left: 'right'
444
- };
445
- const toFallbackPlacements = (primaryPlacement, theme, fallbackPlacements) => {
446
- if (Array.isArray(fallbackPlacements) && fallbackPlacements.length > 0) {
447
- return fallbackPlacements.map(fallbackPlacement => toFloatingPlacement(fallbackPlacement, theme));
448
- }
449
- const side = primaryPlacement.split('-')[0];
450
- const sameSideFallbackPlacements = [...SIDE_FALLBACKS_MAP[side]];
451
- const oppositeSideFallbackPlacements = SIDE_FALLBACKS_MAP[SIDE_OPPOSITE_MAP[side]];
452
- sameSideFallbackPlacements.splice(sameSideFallbackPlacements.indexOf(primaryPlacement), 1);
453
- return [...sameSideFallbackPlacements, ...oppositeSideFallbackPlacements];
454
- };
455
- const getFloatingPlacements = (theme, placement, fallbackPlacements) => {
456
- const floatingPlacement = toFloatingPlacement(placement, theme);
457
- const floatingFallbackPlacements = toFallbackPlacements(floatingPlacement, theme, fallbackPlacements);
458
- return [floatingPlacement, floatingFallbackPlacements];
459
- };
460
-
461
- const getFocusBoxShadow = _ref => {
462
- let {
463
- boxShadow,
464
- inset = false,
465
- hue = 'primaryHue',
466
- shade = DEFAULT_SHADE,
467
- shadowWidth = 'md',
468
- spacerHue = 'background',
469
- spacerShade = DEFAULT_SHADE,
470
- spacerWidth = 'xs',
471
- theme = DEFAULT_THEME
472
- } = _ref;
473
- const color = getColor(hue, shade, theme);
474
- const shadow = theme.shadows[shadowWidth](color);
475
- if (spacerWidth === null) {
476
- return `${inset ? 'inset' : ''} ${shadow}`;
477
- }
478
- const spacerColor = getColor(spacerHue, spacerShade, theme);
479
- const retVal = `
480
- ${inset ? 'inset' : ''} ${theme.shadows[spacerWidth](spacerColor)},
481
- ${inset ? 'inset' : ''} ${shadow}`;
482
- return boxShadow ? `${retVal}, ${boxShadow}` : retVal;
483
- };
484
-
485
- function getLineHeight(height, fontSize) {
486
- const [heightValue, heightUnit] = getValueAndUnit(height.toString());
487
- const [fontSizeValue, fontSizeUnit] = getValueAndUnit(fontSize.toString());
488
- const PIXELS = 'px';
489
- if (heightUnit && heightUnit !== PIXELS) {
490
- throw new Error(`Unexpected \`height\` with '${heightUnit}' units.`);
491
- }
492
- if (fontSizeUnit && fontSizeUnit !== PIXELS) {
493
- throw new Error(`Unexpected \`fontSize\` with '${fontSizeUnit}' units.`);
494
- }
495
- return heightValue / fontSizeValue;
496
- }
497
-
498
- const getMenuPosition = placement => {
499
- return placement.split('-')[0];
500
- };
501
-
502
- const maxWidth = (breakpoints, breakpoint) => {
503
- const keys = Object.keys(breakpoints);
504
- const index = keys.indexOf(breakpoint) + 1;
505
- if (keys[index]) {
506
- const dimension = getValueAndUnit(breakpoints[keys[index]]);
507
- const value = dimension[0] - 0.02;
508
- const unit = dimension[1];
509
- return `${value}${unit}`;
510
- }
511
- return undefined;
512
- };
513
- function mediaQuery(query, breakpoint, theme) {
514
- let retVal;
515
- let min;
516
- let max;
517
- const breakpoints = theme && theme.breakpoints ? theme.breakpoints : DEFAULT_THEME.breakpoints;
518
- if (typeof breakpoint === 'string') {
519
- if (query === 'up') {
520
- min = breakpoints[breakpoint];
521
- } else if (query === 'down') {
522
- if (breakpoint === 'xl') {
523
- min = DEFAULT_THEME.breakpoints.xs;
524
- } else {
525
- max = maxWidth(breakpoints, breakpoint);
526
- }
527
- } else if (query === 'only') {
528
- min = breakpoints[breakpoint];
529
- max = maxWidth(breakpoints, breakpoint);
530
- }
531
- } else if (query === 'between') {
532
- min = breakpoints[breakpoint[0]];
533
- max = maxWidth(breakpoints, breakpoint[1]);
534
- }
535
- if (min) {
536
- retVal = `@media (min-width: ${min})`;
537
- if (max) {
538
- retVal = `${retVal} and (max-width: ${max})`;
539
- }
540
- } else if (max) {
541
- retVal = `@media (max-width: ${max})`;
542
- } else {
543
- throw new Error(`Unexpected query and breakpoint combination: '${query}', '${breakpoint}'.`);
544
- }
545
- return retVal;
546
- }
547
-
548
- const exponentialSymbols = {
549
- symbols: {
550
- sqrt: {
551
- func: {
552
- symbol: 'sqrt',
553
- f: a => Math.sqrt(a),
554
- notation: 'func',
555
- precedence: 0,
556
- rightToLeft: 0,
557
- argCount: 1
558
- },
559
- symbol: 'sqrt',
560
- regSymbol: 'sqrt\\b'
561
- }
562
- }
563
- };
564
- const animationStyles$1 = (position, modifier) => {
565
- const property = position.split('-')[0];
566
- const animationName = keyframes(["0%,66%{", ":2px;border:transparent;}"], property);
567
- return css(["&", "::before,&", "::after{animation:0.3s ease-in-out ", ";}"], modifier, modifier, animationName);
568
- };
569
- const positionStyles = (position, size, inset) => {
570
- const margin = math(`${size} / -2`);
571
- const placement = math(`${margin} + ${inset}`);
572
- let clipPath;
573
- let positionCss;
574
- let propertyRadius;
575
- if (position.startsWith('top')) {
576
- propertyRadius = 'border-bottom-right-radius';
577
- clipPath = 'polygon(100% 0, 100% 1px, 1px 100%, 0 100%, 0 0)';
578
- positionCss = css(["top:", ";right:", ";left:", ";margin-left:", ";"], placement, position === 'top-right' && size, position === 'top' ? '50%' : position === 'top-left' && size, position === 'top' && margin);
579
- } else if (position.startsWith('right')) {
580
- propertyRadius = 'border-bottom-left-radius';
581
- clipPath = 'polygon(100% 0, 100% 100%, calc(100% - 1px) 100%, 0 1px, 0 0)';
582
- positionCss = css(["top:", ";right:", ";bottom:", ";margin-top:", ";"], position === 'right' ? '50%' : position === 'right-top' && size, placement, position === 'right-bottom' && size, position === 'right' && margin);
583
- } else if (position.startsWith('bottom')) {
584
- propertyRadius = 'border-top-left-radius';
585
- clipPath = 'polygon(100% 0, calc(100% - 1px) 0, 0 calc(100% - 1px), 0 100%, 100% 100%)';
586
- positionCss = css(["right:", ";bottom:", ";left:", ";margin-left:", ";"], position === 'bottom-right' && size, placement, position === 'bottom' ? '50%' : position === 'bottom-left' && size, position === 'bottom' && margin);
587
- } else if (position.startsWith('left')) {
588
- propertyRadius = 'border-top-right-radius';
589
- clipPath = 'polygon(0 100%, 100% 100%, 100% calc(100% - 1px), 1px 0, 0 0)';
590
- positionCss = css(["top:", ";bottom:", ";left:", ";margin-top:", ";"], position === 'left' ? '50%' : position === 'left-top' && size, size, placement, position === 'left' && margin);
591
- }
592
- return css(["&::before{", ":100%;clip-path:", ";}&::before,&::after{", "}"], propertyRadius, clipPath, positionCss);
593
- };
594
- function arrowStyles(position) {
595
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
596
- const size = options.size || '6px';
597
- const inset = options.inset || '0';
598
- const squareSize = math(`${size} * 2 / sqrt(2)`, exponentialSymbols);
599
- 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));
600
- }
601
-
602
- const useWindow = theme => {
603
- const [controlledWindow, setControlledWindow] = useState();
604
- useEffect(() => {
605
- if (theme && theme.window) {
606
- setControlledWindow(theme.window);
607
- } else {
608
- setControlledWindow(window);
609
- }
610
- }, [theme]);
611
- return controlledWindow;
612
- };
613
-
614
- const useText = function (component, props, name, text) {
615
- let condition = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
616
- const value = condition ? props[name] : undefined;
617
- return useMemo(() => {
618
- if (condition) {
619
- if (name === 'children') {
620
- throw new Error('Error: `children` is not a valid `useText` prop.');
621
- } else if (value === null || value === '') {
622
- 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.`);
623
- } else if (value === undefined) {
624
- if (process.env.NODE_ENV === 'development') {
625
- 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.`);
626
- }
627
- return text;
628
- }
629
- }
630
- return value;
631
- }, [component.displayName, value, name, text, condition]);
632
- };
633
-
634
- const animationStyles = (position, options) => {
635
- const theme = options.theme || DEFAULT_THEME;
636
- let translateValue = `${theme.space.base * 5}px`;
637
- let transformFunction;
638
- if (position === 'top') {
639
- transformFunction = 'translateY';
640
- } else if (position === 'right') {
641
- transformFunction = 'translateX';
642
- translateValue = `-${translateValue}`;
643
- } else if (position === 'bottom') {
644
- transformFunction = 'translateY';
645
- translateValue = `-${translateValue}`;
646
- } else {
647
- transformFunction = 'translateX';
648
- }
649
- const animationName = keyframes(["0%{transform:", "(", ");}"], transformFunction, translateValue);
650
- return css(["&", " ", "{animation:0.2s cubic-bezier(0.15,0.85,0.35,1.2) ", ";}"], options.animationModifier, options.childSelector || '> *', animationName);
651
- };
652
- const hiddenStyles = options => {
653
- const transition = 'opacity 0.2s ease-in-out, 0.2s visibility 0s linear';
654
- return css(["transition:", ";visibility:hidden;opacity:0;"], options.animationModifier && transition);
655
- };
656
- function menuStyles(position) {
657
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
658
- const theme = options.theme || DEFAULT_THEME;
659
- let marginProperty;
660
- if (position === 'top') {
661
- marginProperty = 'margin-bottom';
662
- } else if (position === 'right') {
663
- marginProperty = 'margin-left';
664
- } else if (position === 'bottom') {
665
- marginProperty = 'margin-top';
666
- } else {
667
- marginProperty = 'margin-right';
668
- }
669
- 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, getColor('neutralHue', 300, theme), theme.borderRadii.md, theme.shadows.lg(`${theme.space.base * 5}px`, `${theme.space.base * 7.5}px`, getColor('chromeHue', 600, theme, 0.15)), theme.colors.background, theme.rtl ? 'right' : 'left', theme.fontSizes.md, theme.fontWeights.regular, theme.rtl && 'rtl', options.animationModifier && animationStyles(position, options), options.hidden && hiddenStyles(options));
670
- }
671
-
672
- const SELECTOR_FOCUS_VISIBLE = '&:focus-visible, &[data-garden-focus-visible="true"]';
673
- const focusStyles = _ref => {
674
- let {
675
- condition = true,
676
- selector = SELECTOR_FOCUS_VISIBLE,
677
- shadowWidth = 'md',
678
- spacerWidth = 'xs',
679
- styles: {
680
- boxShadow,
681
- ...styles
682
- } = {},
683
- theme,
684
- ...options
685
- } = _ref;
686
- const _boxShadow = condition ? getFocusBoxShadow({
687
- boxShadow,
688
- shadowWidth,
689
- spacerWidth,
690
- theme,
691
- ...options
692
- }) : boxShadow;
693
- let outline;
694
- let outlineOffset;
695
- if (spacerWidth === null) {
696
- outline = theme.shadowWidths[shadowWidth];
697
- } else {
698
- outline = `${math(`${theme.shadowWidths[shadowWidth]} - ${theme.shadowWidths[spacerWidth]}`)} solid transparent`;
699
- outlineOffset = theme.shadowWidths[spacerWidth];
700
- }
701
- return css(["&:focus{outline:none;}", "{outline:", ";outline-offset:", ";box-shadow:", ";", "}"], selector, outline, outlineOffset, _boxShadow, styles);
702
- };
703
-
704
- const ARROW_POSITION = ['top', 'top-left', 'top-right', 'right', 'right-top', 'right-bottom', 'bottom', 'bottom-left', 'bottom-right', 'left', 'left-top', 'left-bottom'];
705
- const MENU_POSITION = ['top', 'right', 'bottom', 'left'];
706
- const PLACEMENT = ['top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end', 'end', 'end-top', 'end-bottom', 'start', 'start-top', 'start-bottom'];
707
-
708
- export { ARROW_POSITION as ARRAY_ARROW_POSITION, MENU_POSITION as ARRAY_MENU_POSITION, DEFAULT_THEME, PALETTE, PLACEMENT, SELECTOR_FOCUS_VISIBLE, ThemeProvider, arrowStyles, focusStyles, getArrowPosition, getColor, getFloatingPlacements, getFocusBoxShadow, getLineHeight, getMenuPosition, mediaQuery, menuStyles, retrieveComponentStyles, retrieveComponentStyles as retrieveTheme, useDocument, useText, useWindow };