@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/esm/elements/ThemeProvider.js +24 -0
- package/dist/esm/elements/palette/index.js +283 -0
- package/dist/esm/elements/palette/v8.js +149 -0
- package/dist/esm/elements/theme/index.js +209 -0
- package/dist/esm/index.js +26 -0
- package/dist/esm/types/index.js +11 -0
- package/dist/esm/utils/arrowStyles.js +64 -0
- package/dist/esm/utils/focusStyles.js +43 -0
- package/dist/esm/utils/getArrowPosition.js +35 -0
- package/dist/esm/utils/getColor.js +148 -0
- package/dist/esm/utils/getColorV8.js +72 -0
- package/dist/esm/utils/getFloatingPlacements.js +58 -0
- package/dist/esm/utils/getFocusBoxShadow.js +45 -0
- package/dist/esm/utils/getLineHeight.js +22 -0
- package/dist/esm/utils/getMenuPosition.js +11 -0
- package/dist/esm/utils/mediaQuery.js +56 -0
- package/dist/esm/utils/menuStyles.js +63 -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/index.cjs.js +121 -66
- package/dist/typings/elements/ThemeProvider.d.ts +3 -3
- package/dist/typings/index.d.ts +1 -1
- package/dist/typings/types/index.d.ts +35 -9
- package/dist/typings/utils/focusStyles.d.ts +3 -11
- package/dist/typings/utils/getColor.d.ts +1 -22
- package/dist/typings/utils/getFocusBoxShadow.d.ts +6 -20
- package/package.json +3 -5
- package/dist/index.esm.js +0 -1158
|
@@ -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,148 @@
|
|
|
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, 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
|
+
retVal = rgba(retVal, transparency);
|
|
69
|
+
}
|
|
70
|
+
return retVal;
|
|
71
|
+
};
|
|
72
|
+
const toProperty = (object, path) => {
|
|
73
|
+
const retVal = get(object, path);
|
|
74
|
+
if (typeof retVal === 'string') {
|
|
75
|
+
return retVal;
|
|
76
|
+
} else if (retVal === undefined) {
|
|
77
|
+
throw new ReferenceError(`Error: color variable '${path}' is not defined`);
|
|
78
|
+
} else {
|
|
79
|
+
throw new TypeError(`Error: unexpected '${typeof retVal}' type for color variable "${path}"`);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const getColor = memoize(_ref => {
|
|
83
|
+
let {
|
|
84
|
+
dark,
|
|
85
|
+
hue,
|
|
86
|
+
light,
|
|
87
|
+
offset,
|
|
88
|
+
shade,
|
|
89
|
+
theme,
|
|
90
|
+
transparency,
|
|
91
|
+
variable
|
|
92
|
+
} = _ref;
|
|
93
|
+
let retVal;
|
|
94
|
+
const palette = theme.palette && Object.keys(theme.palette).length > 0 ? theme.palette : DEFAULT_THEME.palette;
|
|
95
|
+
const {
|
|
96
|
+
base,
|
|
97
|
+
variables,
|
|
98
|
+
...colors
|
|
99
|
+
} = theme.colors && Object.keys(theme.colors).length > 0 ? theme.colors : DEFAULT_THEME.colors;
|
|
100
|
+
const scheme = base === 'dark' ? 'dark' : 'light';
|
|
101
|
+
const mode = scheme === 'dark' ? dark : light;
|
|
102
|
+
let _hue = mode?.hue || hue;
|
|
103
|
+
let _shade = mode?.shade === undefined ? shade : mode.shade;
|
|
104
|
+
const _offset = mode?.offset === undefined ? offset : mode.offset;
|
|
105
|
+
const _transparency = mode?.transparency === undefined ? transparency : mode.transparency;
|
|
106
|
+
if (variable) {
|
|
107
|
+
const _variables = variables?.[scheme] ? variables[scheme] : DEFAULT_THEME.colors.variables[scheme];
|
|
108
|
+
const property = toProperty(_variables, variable);
|
|
109
|
+
const [key, value] = property.split(/\.(?<value>.*)/u);
|
|
110
|
+
if (key === 'palette') {
|
|
111
|
+
_hue = toProperty(palette, value);
|
|
112
|
+
} else {
|
|
113
|
+
_hue = key;
|
|
114
|
+
_shade = parseInt(value, 10);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (_hue) {
|
|
118
|
+
retVal = toColor(colors, palette, scheme, _hue, _shade, _offset, _transparency);
|
|
119
|
+
}
|
|
120
|
+
if (retVal === undefined) {
|
|
121
|
+
throw new Error('Error: invalid `getColor` parameters');
|
|
122
|
+
}
|
|
123
|
+
return retVal;
|
|
124
|
+
}, _ref2 => {
|
|
125
|
+
let {
|
|
126
|
+
dark,
|
|
127
|
+
hue,
|
|
128
|
+
light,
|
|
129
|
+
offset,
|
|
130
|
+
shade,
|
|
131
|
+
theme,
|
|
132
|
+
transparency,
|
|
133
|
+
variable
|
|
134
|
+
} = _ref2;
|
|
135
|
+
return JSON.stringify({
|
|
136
|
+
dark,
|
|
137
|
+
hue,
|
|
138
|
+
light,
|
|
139
|
+
offset,
|
|
140
|
+
shade,
|
|
141
|
+
colors: theme.colors,
|
|
142
|
+
palette: theme.palette,
|
|
143
|
+
transparency,
|
|
144
|
+
variable
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
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 };
|
|
@@ -0,0 +1,63 @@
|
|
|
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 DEFAULT_THEME from '../elements/theme/index.js';
|
|
9
|
+
import { getColor } from './getColor.js';
|
|
10
|
+
|
|
11
|
+
const animationStyles = (position, options) => {
|
|
12
|
+
const theme = options.theme || DEFAULT_THEME;
|
|
13
|
+
let translateValue = `${theme.space.base * 5}px`;
|
|
14
|
+
let transformFunction;
|
|
15
|
+
if (position === 'top') {
|
|
16
|
+
transformFunction = 'translateY';
|
|
17
|
+
} else if (position === 'right') {
|
|
18
|
+
transformFunction = 'translateX';
|
|
19
|
+
translateValue = `-${translateValue}`;
|
|
20
|
+
} else if (position === 'bottom') {
|
|
21
|
+
transformFunction = 'translateY';
|
|
22
|
+
translateValue = `-${translateValue}`;
|
|
23
|
+
} else {
|
|
24
|
+
transformFunction = 'translateX';
|
|
25
|
+
}
|
|
26
|
+
const animationName = keyframes(["0%{transform:", "(", ");}"], transformFunction, translateValue);
|
|
27
|
+
return css(["&", " ", "{animation:0.2s cubic-bezier(0.15,0.85,0.35,1.2) ", ";}"], options.animationModifier, options.childSelector || '> *', animationName);
|
|
28
|
+
};
|
|
29
|
+
const hiddenStyles = options => {
|
|
30
|
+
const transition = 'opacity 0.2s ease-in-out, 0.2s visibility 0s linear';
|
|
31
|
+
return css(["transition:", ";visibility:hidden;opacity:0;"], options.animationModifier && transition);
|
|
32
|
+
};
|
|
33
|
+
function menuStyles(position) {
|
|
34
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
35
|
+
const theme = options.theme || DEFAULT_THEME;
|
|
36
|
+
let marginProperty;
|
|
37
|
+
if (position === 'top') {
|
|
38
|
+
marginProperty = 'margin-bottom';
|
|
39
|
+
} else if (position === 'right') {
|
|
40
|
+
marginProperty = 'margin-left';
|
|
41
|
+
} else if (position === 'bottom') {
|
|
42
|
+
marginProperty = 'margin-top';
|
|
43
|
+
} else {
|
|
44
|
+
marginProperty = 'margin-right';
|
|
45
|
+
}
|
|
46
|
+
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;color:", ";font-size:", ";font-weight:", ";direction:", ";:focus{outline:none;}}", ";", ";"], options.zIndex || 0, marginProperty, options.margin, options.childSelector || '> *', theme.borders.sm, getColor({
|
|
47
|
+
theme,
|
|
48
|
+
variable: 'border.default'
|
|
49
|
+
}), theme.borderRadii.md, theme.shadows.lg(`${theme.space.base * 5}px`, `${theme.space.base * 7.5}px`, getColor({
|
|
50
|
+
theme,
|
|
51
|
+
hue: 'chromeHue',
|
|
52
|
+
shade: 600,
|
|
53
|
+
transparency: 0.15
|
|
54
|
+
})), getColor({
|
|
55
|
+
theme,
|
|
56
|
+
variable: 'background.raised'
|
|
57
|
+
}), theme.rtl ? 'right' : 'left', getColor({
|
|
58
|
+
theme,
|
|
59
|
+
variable: 'foreground.default'
|
|
60
|
+
}), theme.fontSizes.md, theme.fontWeights.regular, theme.rtl && 'rtl', options.animationModifier && animationStyles(position, options), options.hidden && hiddenStyles(options));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { menuStyles as default };
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
function retrieveComponentStyles(componentId, props) {
|
|
8
|
+
const components = props.theme && props.theme.components;
|
|
9
|
+
if (!components) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
const componentStyles = components[componentId];
|
|
13
|
+
if (typeof componentStyles === 'function') {
|
|
14
|
+
return componentStyles(props);
|
|
15
|
+
}
|
|
16
|
+
return componentStyles;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { retrieveComponentStyles as default };
|
|
@@ -0,0 +1,21 @@
|
|
|
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 { useState, useEffect } from 'react';
|
|
8
|
+
|
|
9
|
+
const useDocument = theme => {
|
|
10
|
+
const [controlledDocument, setControlledDocument] = useState();
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (theme && theme.document) {
|
|
13
|
+
setControlledDocument(theme.document);
|
|
14
|
+
} else {
|
|
15
|
+
setControlledDocument(document);
|
|
16
|
+
}
|
|
17
|
+
}, [theme]);
|
|
18
|
+
return controlledDocument;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { useDocument };
|