@zendeskgarden/react-theming 9.0.0-next.2 → 9.0.0-next.20

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 +240 -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 +45 -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 +245 -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 +70 -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 +838 -198
  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 +61 -16
  31. package/dist/typings/utils/StyledBaseIcon.d.ts +8 -0
  32. package/dist/typings/utils/arrowStyles.d.ts +0 -16
  33. package/dist/typings/utils/focusStyles.d.ts +3 -11
  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 +1 -1
  39. package/package.json +8 -7
  40. package/dist/index.esm.js +0 -714
@@ -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,70 @@
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 colorStyles = theme => {
30
+ const backgroundColor = getColor({
31
+ theme,
32
+ variable: 'background.raised'
33
+ });
34
+ const borderColor = getColor({
35
+ theme,
36
+ variable: 'border.default'
37
+ });
38
+ const boxShadowColor = getColor({
39
+ variable: 'shadow.medium',
40
+ theme
41
+ });
42
+ const boxShadowBlurRadius = `${theme.space.base * (theme.colors.base === 'dark' ? 5 : 6)}px`;
43
+ const boxShadowOffsetY = `${theme.space.base * (theme.colors.base === 'dark' ? 4 : 5)}px`;
44
+ const foregroundColor = getColor({
45
+ theme,
46
+ variable: 'foreground.default'
47
+ });
48
+ return css(["border-color:", ";box-shadow:", ";background-color:", ";color:", ";"], borderColor, theme.shadows.lg(boxShadowOffsetY, boxShadowBlurRadius, boxShadowColor), backgroundColor, foregroundColor);
49
+ };
50
+ const hiddenStyles = options => {
51
+ const transition = 'opacity 0.2s ease-in-out, 0.2s visibility 0s linear';
52
+ return css(["transition:", ";visibility:hidden;opacity:0;"], options.animationModifier && transition);
53
+ };
54
+ function menuStyles(position) {
55
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
56
+ const theme = options.theme || DEFAULT_THEME;
57
+ let marginProperty;
58
+ if (position === 'top') {
59
+ marginProperty = 'margin-bottom';
60
+ } else if (position === 'right') {
61
+ marginProperty = 'margin-left';
62
+ } else if (position === 'bottom') {
63
+ marginProperty = 'margin-top';
64
+ } else {
65
+ marginProperty = 'margin-right';
66
+ }
67
+ return css(["position:absolute;z-index:", ";", ":", ";line-height:0;font-size:0.01px;color-scheme:only ", ";& ", "{display:inline-block;position:relative;margin:0;box-sizing:border-box;border:", ";border-radius:", ";cursor:default;padding:0;text-align:", ";white-space:normal;font-size:", ";font-weight:", ";direction:", ";", ";:focus{outline:none;}}", ";", ";"], options.zIndex || 0, marginProperty, options.margin, p => p.theme.colors.base, options.childSelector || '> *', theme.borders.sm, theme.borderRadii.md, theme.rtl ? 'right' : 'left', theme.fontSizes.md, theme.fontWeights.regular, theme.rtl && 'rtl', colorStyles(theme), options.animationModifier && animationStyles(position, options), options.hidden && hiddenStyles(options));
68
+ }
69
+
70
+ 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 };
@@ -0,0 +1,29 @@
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 { useMemo } from 'react';
8
+
9
+ const useText = function (component, props, name, text) {
10
+ let condition = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
11
+ const value = condition ? props[name] : undefined;
12
+ return useMemo(() => {
13
+ if (condition) {
14
+ if (name === 'children') {
15
+ throw new Error('Error: `children` is not a valid `useText` prop.');
16
+ } else if (value === null || value === '') {
17
+ 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.`);
18
+ } else if (value === undefined) {
19
+ if (process.env.NODE_ENV === 'development') {
20
+ 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.`);
21
+ }
22
+ return text;
23
+ }
24
+ }
25
+ return value;
26
+ }, [component.displayName, value, name, text, condition]);
27
+ };
28
+
29
+ export { useText };
@@ -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 useWindow = theme => {
10
+ const [controlledWindow, setControlledWindow] = useState();
11
+ useEffect(() => {
12
+ if (theme && theme.window) {
13
+ setControlledWindow(theme.window);
14
+ } else {
15
+ setControlledWindow(window);
16
+ }
17
+ }, [theme]);
18
+ return controlledWindow;
19
+ };
20
+
21
+ export { useWindow };