@zendeskgarden/react-theming 9.0.0-next.7 → 9.0.0-next.9

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 (34) 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 +372 -262
  25. package/dist/typings/elements/palette/index.d.ts +0 -24
  26. package/dist/typings/index.d.ts +3 -1
  27. package/dist/typings/types/index.d.ts +43 -1
  28. package/dist/typings/utils/StyledBaseIcon.d.ts +8 -0
  29. package/dist/typings/utils/focusStyles.d.ts +1 -8
  30. package/dist/typings/utils/getCheckeredBackground.d.ts +20 -0
  31. package/dist/typings/utils/getColor.d.ts +3 -24
  32. package/dist/typings/utils/getFocusBoxShadow.d.ts +6 -20
  33. package/package.json +3 -3
  34. package/dist/index.esm.js +0 -1145
@@ -0,0 +1,22 @@
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
+ import styled from 'styled-components';
8
+ import React, { Children } from 'react';
9
+
10
+ const StyledBaseIcon = styled(_ref => {
11
+ let {
12
+ children,
13
+ theme,
14
+ ...props
15
+ } = _ref;
16
+ return React.cloneElement(Children.only(children), props);
17
+ }).withConfig({
18
+ displayName: "StyledBaseIcon",
19
+ componentId: "sc-1moykgb-0"
20
+ })([""]);
21
+
22
+ export { StyledBaseIcon };
@@ -0,0 +1,64 @@
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
+ import { css, keyframes } from 'styled-components';
8
+ import { math } from 'polished';
9
+
10
+ const exponentialSymbols = {
11
+ symbols: {
12
+ sqrt: {
13
+ func: {
14
+ symbol: 'sqrt',
15
+ f: a => Math.sqrt(a),
16
+ notation: 'func',
17
+ precedence: 0,
18
+ rightToLeft: 0,
19
+ argCount: 1
20
+ },
21
+ symbol: 'sqrt',
22
+ regSymbol: 'sqrt\\b'
23
+ }
24
+ }
25
+ };
26
+ const animationStyles = (position, modifier) => {
27
+ const property = position.split('-')[0];
28
+ const animationName = keyframes(["0%,66%{", ":2px;border:transparent;}"], property);
29
+ return css(["&", "::before,&", "::after{animation:0.3s ease-in-out ", ";}"], modifier, modifier, animationName);
30
+ };
31
+ const positionStyles = (position, size, inset) => {
32
+ const margin = math(`${size} / -2`);
33
+ const placement = math(`${margin} + ${inset}`);
34
+ let clipPath;
35
+ let positionCss;
36
+ let propertyRadius;
37
+ if (position.startsWith('top')) {
38
+ propertyRadius = 'border-bottom-right-radius';
39
+ clipPath = 'polygon(100% 0, 100% 1px, 1px 100%, 0 100%, 0 0)';
40
+ positionCss = css(["top:", ";right:", ";left:", ";margin-left:", ";"], placement, position === 'top-right' && size, position === 'top' ? '50%' : position === 'top-left' && size, position === 'top' && margin);
41
+ } else if (position.startsWith('right')) {
42
+ propertyRadius = 'border-bottom-left-radius';
43
+ clipPath = 'polygon(100% 0, 100% 100%, calc(100% - 1px) 100%, 0 1px, 0 0)';
44
+ positionCss = css(["top:", ";right:", ";bottom:", ";margin-top:", ";"], position === 'right' ? '50%' : position === 'right-top' && size, placement, position === 'right-bottom' && size, position === 'right' && margin);
45
+ } else if (position.startsWith('bottom')) {
46
+ propertyRadius = 'border-top-left-radius';
47
+ clipPath = 'polygon(100% 0, calc(100% - 1px) 0, 0 calc(100% - 1px), 0 100%, 100% 100%)';
48
+ positionCss = css(["right:", ";bottom:", ";left:", ";margin-left:", ";"], position === 'bottom-right' && size, placement, position === 'bottom' ? '50%' : position === 'bottom-left' && size, position === 'bottom' && margin);
49
+ } else if (position.startsWith('left')) {
50
+ propertyRadius = 'border-top-right-radius';
51
+ clipPath = 'polygon(0 100%, 100% 100%, 100% calc(100% - 1px), 1px 0, 0 0)';
52
+ positionCss = css(["top:", ";bottom:", ";left:", ";margin-top:", ";"], position === 'left' ? '50%' : position === 'left-top' && size, size, placement, position === 'left' && margin);
53
+ }
54
+ return css(["&::before{", ":100%;clip-path:", ";}&::before,&::after{", "}"], propertyRadius, clipPath, positionCss);
55
+ };
56
+ function arrowStyles(position) {
57
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
58
+ const size = options.size || '6px';
59
+ const inset = options.inset || '0';
60
+ const squareSize = math(`${size} * 2 / sqrt(2)`, exponentialSymbols);
61
+ 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(position, options.animationModifier));
62
+ }
63
+
64
+ export { arrowStyles as default, exponentialSymbols };
@@ -0,0 +1,43 @@
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
+ import { css } from 'styled-components';
8
+ import { math } from 'polished';
9
+ import { getFocusBoxShadow } from './getFocusBoxShadow.js';
10
+
11
+ const SELECTOR_FOCUS_VISIBLE = '&:focus-visible';
12
+ const focusStyles = _ref => {
13
+ let {
14
+ condition = true,
15
+ selector = SELECTOR_FOCUS_VISIBLE,
16
+ shadowWidth = 'md',
17
+ spacerWidth = 'xs',
18
+ styles: {
19
+ boxShadow,
20
+ ...styles
21
+ } = {},
22
+ theme,
23
+ ...options
24
+ } = _ref;
25
+ const _boxShadow = condition ? getFocusBoxShadow({
26
+ boxShadow,
27
+ shadowWidth,
28
+ spacerWidth,
29
+ theme,
30
+ ...options
31
+ }) : boxShadow;
32
+ let outline;
33
+ let outlineOffset;
34
+ if (spacerWidth === null) {
35
+ outline = theme.shadowWidths[shadowWidth];
36
+ } else {
37
+ outline = `${math(`${theme.shadowWidths[shadowWidth]} - ${theme.shadowWidths[spacerWidth]}`)} solid transparent`;
38
+ outlineOffset = theme.shadowWidths[spacerWidth];
39
+ }
40
+ return css(["&:focus{outline:none;}", "{outline:", ";outline-offset:", ";box-shadow:", ";", "}"], selector, outline, outlineOffset, _boxShadow, styles);
41
+ };
42
+
43
+ export { SELECTOR_FOCUS_VISIBLE, focusStyles };
@@ -0,0 +1,35 @@
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
+ const POSITION_MAP = {
8
+ top: 'bottom',
9
+ 'top-start': 'bottom-left',
10
+ 'top-end': 'bottom-right',
11
+ right: 'left',
12
+ 'right-start': 'left-top',
13
+ 'right-end': 'left-bottom',
14
+ bottom: 'top',
15
+ 'bottom-start': 'top-left',
16
+ 'bottom-end': 'top-right',
17
+ left: 'right',
18
+ 'left-start': 'right-top',
19
+ 'left-end': 'right-bottom'
20
+ };
21
+ const RTL_POSITION_MAP = {
22
+ 'bottom-left': 'bottom-right',
23
+ 'bottom-right': 'bottom-left',
24
+ 'top-left': 'top-right',
25
+ 'top-right': 'top-left'
26
+ };
27
+ const getArrowPosition = (theme, placement) => {
28
+ let retVal = POSITION_MAP[placement];
29
+ if (theme.rtl) {
30
+ retVal = RTL_POSITION_MAP[retVal] || retVal;
31
+ }
32
+ return retVal;
33
+ };
34
+
35
+ export { POSITION_MAP, RTL_POSITION_MAP, getArrowPosition };
@@ -0,0 +1,40 @@
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
+ import { getColor } from './getColor.js';
8
+
9
+ const getCheckeredBackground = _ref => {
10
+ let {
11
+ theme,
12
+ size,
13
+ overlay,
14
+ positionY = 0,
15
+ repeat = 'repeat'
16
+ } = _ref;
17
+ const color = getColor({
18
+ theme,
19
+ variable: 'border.default'
20
+ });
21
+ const dimensions = `${size}px ${size}px`;
22
+ const positionX1 = theme.rtl ? '100%' : '0';
23
+ const positionX2 = theme.rtl ? `calc(100% - ${size / 2}px)` : `${size / 2}px`;
24
+ const position1 = `${positionX1} ${positionY}px`;
25
+ const position2 = `${positionX2} ${size / 2 + positionY}px`;
26
+ const position3 = `${positionX2} ${positionY}px`;
27
+ const position4 = `${positionX1} ${size / -2 + positionY}px`;
28
+ let retVal = `
29
+ linear-gradient(45deg, ${color} 25%, transparent 25%) ${position1} / ${dimensions} ${repeat},
30
+ linear-gradient(45deg, transparent 75%, ${color} 75%) ${position2} / ${dimensions} ${repeat},
31
+ linear-gradient(135deg, ${color} 25%, transparent 25%) ${position3} / ${dimensions} ${repeat},
32
+ linear-gradient(135deg, transparent 75%, ${color} 75%) ${position4} / ${dimensions} ${repeat}
33
+ `;
34
+ if (overlay) {
35
+ retVal = overlay.startsWith('linear-gradient') ? `${overlay}, ${retVal}` : `linear-gradient(${overlay}, ${overlay}), ${retVal}`;
36
+ }
37
+ return retVal;
38
+ };
39
+
40
+ export { getCheckeredBackground };
@@ -0,0 +1,153 @@
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
+ import { valid, scale } from 'chroma-js';
8
+ import { rgba, darken, lighten } from 'polished';
9
+ import get from 'lodash.get';
10
+ import memoize from 'lodash.memoize';
11
+ import DEFAULT_THEME from '../elements/theme/index.js';
12
+ import PALETTE from '../elements/palette/index.js';
13
+
14
+ const PALETTE_SIZE = Object.keys(PALETTE.blue).length;
15
+ const adjust = (color, expected, actual) => {
16
+ if (expected !== actual) {
17
+ const amount = Math.abs(expected - actual) / 100 * 0.05;
18
+ return expected > actual ? darken(amount, color) : lighten(amount, color);
19
+ }
20
+ return color;
21
+ };
22
+ const toShade = (shade, offset, scheme) => {
23
+ let _shade;
24
+ if (shade === undefined) {
25
+ _shade = scheme === 'dark' ? 500 : 700;
26
+ } else {
27
+ _shade = parseInt(shade.toString(), 10);
28
+ if (isNaN(_shade)) {
29
+ throw new TypeError(`Error: unexpected '${typeof shade}' type for color shade "${shade}"`);
30
+ }
31
+ }
32
+ return _shade + (offset || 0);
33
+ };
34
+ const toHex = (hue, shade, offset, scheme) => {
35
+ const _shade = toShade(shade, offset, scheme);
36
+ let retVal = hue[_shade];
37
+ if (!retVal) {
38
+ const closestShade = Object.keys(hue).map(hueShade => parseInt(hueShade, 10)).reduce((previous, current) => {
39
+ return Math.abs(current - _shade) < Math.abs(previous - _shade) ? current : previous;
40
+ });
41
+ retVal = adjust(hue[closestShade], _shade, closestShade);
42
+ }
43
+ return retVal;
44
+ };
45
+ const toColor = (colors, palette, opacity, scheme, hue, shade, offset, transparency) => {
46
+ let retVal;
47
+ let _hue = colors[hue] || hue;
48
+ if (Object.hasOwn(palette, _hue)) {
49
+ _hue = palette[_hue];
50
+ }
51
+ if (typeof _hue === 'object') {
52
+ retVal = toHex(_hue, shade, offset, scheme);
53
+ } else if (_hue === 'transparent' || valid(_hue)) {
54
+ if (shade === undefined) {
55
+ retVal = _hue;
56
+ } else {
57
+ const _colors = scale([PALETTE.white, _hue, PALETTE.black]).correctLightness().colors(PALETTE_SIZE + 2);
58
+ _hue = _colors.reduce((_retVal, color, index) => {
59
+ if (index > 0 && index <= PALETTE_SIZE) {
60
+ _retVal[index * 100] = color;
61
+ }
62
+ return _retVal;
63
+ }, {});
64
+ retVal = toHex(_hue, shade, offset, scheme);
65
+ }
66
+ }
67
+ if (retVal && transparency) {
68
+ const alpha = transparency > 1 ? opacity[transparency] : transparency;
69
+ if (alpha === undefined) {
70
+ throw new Error('Error: invalid `transparency` parameter');
71
+ }
72
+ retVal = rgba(retVal, alpha);
73
+ }
74
+ return retVal;
75
+ };
76
+ const toProperty = (object, path) => {
77
+ const retVal = get(object, path);
78
+ if (typeof retVal === 'string') {
79
+ return retVal;
80
+ } else if (retVal === undefined) {
81
+ throw new ReferenceError(`Error: color variable '${path}' is not defined`);
82
+ } else {
83
+ throw new TypeError(`Error: unexpected '${typeof retVal}' type for color variable "${path}"`);
84
+ }
85
+ };
86
+ const getColor = memoize(_ref => {
87
+ let {
88
+ dark,
89
+ hue,
90
+ light,
91
+ offset,
92
+ shade,
93
+ theme,
94
+ transparency,
95
+ variable
96
+ } = _ref;
97
+ let retVal;
98
+ const palette = theme.palette && Object.keys(theme.palette).length > 0 ? theme.palette : DEFAULT_THEME.palette;
99
+ const {
100
+ base,
101
+ variables,
102
+ ...colors
103
+ } = theme.colors && Object.keys(theme.colors).length > 0 ? theme.colors : DEFAULT_THEME.colors;
104
+ const scheme = base === 'dark' ? 'dark' : 'light';
105
+ const mode = scheme === 'dark' ? dark : light;
106
+ let _hue = mode?.hue || hue;
107
+ let _shade = mode?.shade === undefined ? shade : mode.shade;
108
+ const _offset = mode?.offset === undefined ? offset : mode.offset;
109
+ const _transparency = mode?.transparency === undefined ? transparency : mode.transparency;
110
+ if (variable) {
111
+ const _variables = variables?.[scheme] ? variables[scheme] : DEFAULT_THEME.colors.variables[scheme];
112
+ const property = toProperty(_variables, variable);
113
+ const [key, value] = property.split(/\.(?<value>.*)/u);
114
+ if (key === 'palette') {
115
+ _hue = toProperty(palette, value);
116
+ } else {
117
+ _hue = key;
118
+ _shade = parseInt(value, 10);
119
+ }
120
+ }
121
+ if (_hue) {
122
+ const opacity = theme.opacity && Object.keys(theme.opacity).length > 0 ? theme.opacity : DEFAULT_THEME.opacity;
123
+ retVal = toColor(colors, palette, opacity, scheme, _hue, _shade, _offset, _transparency);
124
+ }
125
+ if (retVal === undefined) {
126
+ throw new Error('Error: invalid `getColor` parameters');
127
+ }
128
+ return retVal;
129
+ }, _ref2 => {
130
+ let {
131
+ dark,
132
+ hue,
133
+ light,
134
+ offset,
135
+ shade,
136
+ theme,
137
+ transparency,
138
+ variable
139
+ } = _ref2;
140
+ return JSON.stringify({
141
+ dark,
142
+ hue,
143
+ light,
144
+ offset,
145
+ shade,
146
+ colors: theme.colors,
147
+ palette: theme.palette,
148
+ transparency,
149
+ variable
150
+ });
151
+ });
152
+
153
+ export { getColor };
@@ -0,0 +1,72 @@
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
+ import DEFAULT_THEME from '../elements/theme/index.js';
8
+ import PALETTE_V8 from '../elements/palette/v8.js';
9
+ import { rgba, darken, lighten } from 'polished';
10
+ import memoize from 'lodash.memoize';
11
+
12
+ const DEFAULT_SHADE = 600;
13
+ const adjust = (color, expected, actual) => {
14
+ if (expected !== actual) {
15
+ const amount = Math.abs(expected - actual) / 100 * 0.05;
16
+ return expected > actual ? darken(amount, color) : lighten(amount, color);
17
+ }
18
+ return color;
19
+ };
20
+ const getColorV8 = memoize(function (hue) {
21
+ let shade = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_SHADE;
22
+ let theme = arguments.length > 2 ? arguments[2] : undefined;
23
+ let transparency = arguments.length > 3 ? arguments[3] : undefined;
24
+ let retVal;
25
+ if (isNaN(shade)) {
26
+ return undefined;
27
+ }
28
+ const palette = {
29
+ background: PALETTE_V8.white,
30
+ foreground: PALETTE_V8.grey[800],
31
+ ...(theme && theme.palette ? {
32
+ ...theme.palette,
33
+ ...PALETTE_V8
34
+ } : {
35
+ ...DEFAULT_THEME.palette,
36
+ ...PALETTE_V8
37
+ })
38
+ };
39
+ const colors = theme && theme.colors ? theme.colors : DEFAULT_THEME.colors;
40
+ let _hue;
41
+ if (typeof hue === 'string') {
42
+ _hue = colors[hue] || hue;
43
+ } else {
44
+ _hue = hue;
45
+ }
46
+ if (Object.prototype.hasOwnProperty.call(palette, _hue)) {
47
+ _hue = palette[_hue];
48
+ }
49
+ if (typeof _hue === 'object') {
50
+ retVal = _hue[shade];
51
+ if (!retVal) {
52
+ const _shade = Object.keys(_hue).map(hueKey => parseInt(hueKey, 10)).reduce((previous, current) => {
53
+ return Math.abs(current - shade) < Math.abs(previous - shade) ? current : previous;
54
+ });
55
+ retVal = adjust(_hue[_shade], shade, _shade);
56
+ }
57
+ } else {
58
+ retVal = adjust(_hue, shade, DEFAULT_SHADE);
59
+ }
60
+ if (transparency) {
61
+ retVal = rgba(retVal, transparency);
62
+ }
63
+ return retVal;
64
+ }, (hue, shade, theme, transparency) => JSON.stringify({
65
+ hue,
66
+ shade,
67
+ palette: theme?.palette,
68
+ colors: theme?.colors,
69
+ transparency
70
+ }));
71
+
72
+ export { DEFAULT_SHADE, getColorV8 };
@@ -0,0 +1,58 @@
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
+ const PLACEMENT_MAP = {
8
+ end: 'right',
9
+ 'end-top': 'right-start',
10
+ 'end-bottom': 'right-end',
11
+ start: 'left',
12
+ 'start-top': 'left-start',
13
+ 'start-bottom': 'left-end'
14
+ };
15
+ const RTL_PLACEMENT_MAP = {
16
+ left: 'right',
17
+ 'left-start': 'right-start',
18
+ 'left-end': 'right-end',
19
+ right: 'left',
20
+ 'right-start': 'left-start',
21
+ 'right-end': 'left-end'
22
+ };
23
+ const toFloatingPlacement = (placement, theme) => {
24
+ let retVal = PLACEMENT_MAP[placement] || placement;
25
+ if (theme.rtl) {
26
+ retVal = RTL_PLACEMENT_MAP[retVal] || retVal;
27
+ }
28
+ return retVal;
29
+ };
30
+ const SIDE_FALLBACKS_MAP = {
31
+ top: ['top-start', 'top', 'top-end'],
32
+ right: ['right-start', 'right', 'right-end'],
33
+ bottom: ['bottom-start', 'bottom', 'bottom-end'],
34
+ left: ['left-start', 'left', 'left-end']
35
+ };
36
+ const SIDE_OPPOSITE_MAP = {
37
+ top: 'bottom',
38
+ right: 'left',
39
+ bottom: 'top',
40
+ left: 'right'
41
+ };
42
+ const toFallbackPlacements = (primaryPlacement, theme, fallbackPlacements) => {
43
+ if (Array.isArray(fallbackPlacements) && fallbackPlacements.length > 0) {
44
+ return fallbackPlacements.map(fallbackPlacement => toFloatingPlacement(fallbackPlacement, theme));
45
+ }
46
+ const side = primaryPlacement.split('-')[0];
47
+ const sameSideFallbackPlacements = [...SIDE_FALLBACKS_MAP[side]];
48
+ const oppositeSideFallbackPlacements = SIDE_FALLBACKS_MAP[SIDE_OPPOSITE_MAP[side]];
49
+ sameSideFallbackPlacements.splice(sameSideFallbackPlacements.indexOf(primaryPlacement), 1);
50
+ return [...sameSideFallbackPlacements, ...oppositeSideFallbackPlacements];
51
+ };
52
+ const getFloatingPlacements = (theme, placement, fallbackPlacements) => {
53
+ const floatingPlacement = toFloatingPlacement(placement, theme);
54
+ const floatingFallbackPlacements = toFallbackPlacements(floatingPlacement, theme, fallbackPlacements);
55
+ return [floatingPlacement, floatingFallbackPlacements];
56
+ };
57
+
58
+ export { PLACEMENT_MAP, RTL_PLACEMENT_MAP, getFloatingPlacements };
@@ -0,0 +1,45 @@
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
+ import DEFAULT_THEME from '../elements/theme/index.js';
8
+ import { getColorV8 } from './getColorV8.js';
9
+ import { getColor } from './getColor.js';
10
+
11
+ const getFocusBoxShadow = _ref => {
12
+ let {
13
+ boxShadow,
14
+ inset = false,
15
+ color = {
16
+ variable: 'border.primaryEmphasis'
17
+ },
18
+ shadowWidth = 'md',
19
+ spacerColor = {
20
+ variable: 'background.default'
21
+ },
22
+ spacerWidth = 'xs',
23
+ theme = DEFAULT_THEME,
24
+ ...args
25
+ } = _ref;
26
+ const _args = args;
27
+ const _color = _args.hue ? getColorV8(_args.hue, _args.shade, theme) : getColor({
28
+ ...color,
29
+ theme
30
+ });
31
+ const shadow = theme.shadows[shadowWidth](_color);
32
+ if (spacerWidth === null) {
33
+ return `${inset ? 'inset' : ''} ${shadow}`;
34
+ }
35
+ const _spacerColor = _args.spacerHue ? getColorV8(_args.spacerHue, _args.spacerShade, theme) : getColor({
36
+ ...spacerColor,
37
+ theme
38
+ });
39
+ const retVal = `
40
+ ${inset ? 'inset' : ''} ${theme.shadows[spacerWidth](_spacerColor)},
41
+ ${inset ? 'inset' : ''} ${shadow}`;
42
+ return boxShadow ? `${retVal}, ${boxShadow}` : retVal;
43
+ };
44
+
45
+ export { getFocusBoxShadow };
@@ -0,0 +1,22 @@
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
+ import { getValueAndUnit } from 'polished';
8
+
9
+ function getLineHeight(height, fontSize) {
10
+ const [heightValue, heightUnit] = getValueAndUnit(height.toString());
11
+ const [fontSizeValue, fontSizeUnit] = getValueAndUnit(fontSize.toString());
12
+ const PIXELS = 'px';
13
+ if (heightUnit && heightUnit !== PIXELS) {
14
+ throw new Error(`Unexpected \`height\` with '${heightUnit}' units.`);
15
+ }
16
+ if (fontSizeUnit && fontSizeUnit !== PIXELS) {
17
+ throw new Error(`Unexpected \`fontSize\` with '${fontSizeUnit}' units.`);
18
+ }
19
+ return heightValue / fontSizeValue;
20
+ }
21
+
22
+ export { getLineHeight as default };
@@ -0,0 +1,11 @@
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
+ const getMenuPosition = placement => {
8
+ return placement.split('-')[0];
9
+ };
10
+
11
+ export { getMenuPosition };
@@ -0,0 +1,56 @@
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
+ import DEFAULT_THEME from '../elements/theme/index.js';
8
+ import { getValueAndUnit } from 'polished';
9
+
10
+ const maxWidth = (breakpoints, breakpoint) => {
11
+ const keys = Object.keys(breakpoints);
12
+ const index = keys.indexOf(breakpoint) + 1;
13
+ if (keys[index]) {
14
+ const dimension = getValueAndUnit(breakpoints[keys[index]]);
15
+ const value = dimension[0] - 0.02;
16
+ const unit = dimension[1];
17
+ return `${value}${unit}`;
18
+ }
19
+ return undefined;
20
+ };
21
+ function mediaQuery(query, breakpoint, theme) {
22
+ let retVal;
23
+ let min;
24
+ let max;
25
+ const breakpoints = theme && theme.breakpoints ? theme.breakpoints : DEFAULT_THEME.breakpoints;
26
+ if (typeof breakpoint === 'string') {
27
+ if (query === 'up') {
28
+ min = breakpoints[breakpoint];
29
+ } else if (query === 'down') {
30
+ if (breakpoint === 'xl') {
31
+ min = DEFAULT_THEME.breakpoints.xs;
32
+ } else {
33
+ max = maxWidth(breakpoints, breakpoint);
34
+ }
35
+ } else if (query === 'only') {
36
+ min = breakpoints[breakpoint];
37
+ max = maxWidth(breakpoints, breakpoint);
38
+ }
39
+ } else if (query === 'between') {
40
+ min = breakpoints[breakpoint[0]];
41
+ max = maxWidth(breakpoints, breakpoint[1]);
42
+ }
43
+ if (min) {
44
+ retVal = `@media (min-width: ${min})`;
45
+ if (max) {
46
+ retVal = `${retVal} and (max-width: ${max})`;
47
+ }
48
+ } else if (max) {
49
+ retVal = `@media (max-width: ${max})`;
50
+ } else {
51
+ throw new Error(`Unexpected query and breakpoint combination: '${query}', '${breakpoint}'.`);
52
+ }
53
+ return retVal;
54
+ }
55
+
56
+ export { mediaQuery as default };