@zendeskgarden/react-theming 8.65.0 → 8.66.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -12,10 +12,12 @@ var styledComponents = require('styled-components');
12
12
  var containerFocusvisible = require('@zendeskgarden/container-focusvisible');
13
13
  var containerUtilities = require('@zendeskgarden/container-utilities');
14
14
  var polished = require('polished');
15
+ var memoize = require('lodash.memoize');
15
16
 
16
17
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
17
18
 
18
19
  var React__default = /*#__PURE__*/_interopDefault(React);
20
+ var memoize__default = /*#__PURE__*/_interopDefault(memoize);
19
21
 
20
22
  function _extends() {
21
23
  _extends = Object.assign ? Object.assign.bind() : function (target) {
@@ -249,10 +251,12 @@ const palette = {
249
251
  };
250
252
  delete palette.product;
251
253
  const shadowWidths = {
254
+ xs: '1px',
252
255
  sm: '2px',
253
256
  md: '3px'
254
257
  };
255
258
  const shadows = {
259
+ xs: color => `0 0 0 ${shadowWidths.xs} ${color}`,
256
260
  sm: color => `0 0 0 ${shadowWidths.sm} ${color}`,
257
261
  md: color => `0 0 0 ${shadowWidths.md} ${color}`,
258
262
  lg: (offsetY, blurRadius, color) => `0 ${offsetY} ${blurRadius} 0 ${color}`
@@ -364,7 +368,7 @@ const adjust = (color, expected, actual) => {
364
368
  }
365
369
  return color;
366
370
  };
367
- function getColor(hue) {
371
+ const getColor = memoize__default.default(function (hue) {
368
372
  let shade = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_SHADE;
369
373
  let theme = arguments.length > 2 ? arguments[2] : undefined;
370
374
  let transparency = arguments.length > 3 ? arguments[3] : undefined;
@@ -398,7 +402,32 @@ function getColor(hue) {
398
402
  retVal = polished.rgba(retVal, transparency);
399
403
  }
400
404
  return retVal;
401
- }
405
+ }, (hue, shade, theme, transparency) => JSON.stringify({
406
+ hue,
407
+ shade,
408
+ palette: theme?.palette,
409
+ colors: theme?.colors,
410
+ transparency
411
+ }));
412
+
413
+ const getFocusBoxShadow = _ref => {
414
+ let {
415
+ inset = false,
416
+ hue = 'primaryHue',
417
+ shade = DEFAULT_SHADE,
418
+ shadowWidth = 'md',
419
+ spacerWidth = 'xs',
420
+ theme = DEFAULT_THEME
421
+ } = _ref;
422
+ const color = getColor(hue, shade, theme);
423
+ const shadow = theme.shadows[shadowWidth](color);
424
+ if (spacerWidth === null) {
425
+ return `${inset ? 'inset' : ''} ${shadow}`;
426
+ }
427
+ return `
428
+ ${inset ? 'inset' : ''} ${theme.shadows[spacerWidth](theme.colors.background)},
429
+ ${inset ? 'inset' : ''} ${shadow}`;
430
+ };
402
431
 
403
432
  function getLineHeight(height, fontSize) {
404
433
  const [heightValue, heightUnit] = polished.getValueAndUnit(height.toString());
@@ -583,6 +612,34 @@ function menuStyles(position) {
583
612
  return styledComponents.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));
584
613
  }
585
614
 
615
+ const SELECTOR_FOCUS_VISIBLE = '&:focus-visible, &[data-garden-focus-visible="true"]';
616
+ const focusStyles = _ref => {
617
+ let {
618
+ condition = true,
619
+ selector = SELECTOR_FOCUS_VISIBLE,
620
+ shadowWidth = 'md',
621
+ spacerWidth = 'xs',
622
+ styles,
623
+ theme,
624
+ ...options
625
+ } = _ref;
626
+ const boxShadow = condition ? getFocusBoxShadow({
627
+ shadowWidth,
628
+ spacerWidth,
629
+ theme,
630
+ ...options
631
+ }) : undefined;
632
+ let outline;
633
+ let outlineOffset;
634
+ if (spacerWidth === null) {
635
+ outline = theme.shadowWidths[shadowWidth];
636
+ } else {
637
+ outline = `${polished.math(`${theme.shadowWidths[shadowWidth]} - ${theme.shadowWidths[spacerWidth]}`)} solid transparent`;
638
+ outlineOffset = theme.shadowWidths[spacerWidth];
639
+ }
640
+ return styledComponents.css(["&:focus{outline:none;}", "{outline:", ";outline-offset:", ";box-shadow:", ";", "}"], selector, outline, outlineOffset, boxShadow, styles);
641
+ };
642
+
586
643
  const ARROW_POSITION = ['top', 'top-left', 'top-right', 'right', 'right-top', 'right-bottom', 'bottom', 'bottom-left', 'bottom-right', 'left', 'left-top', 'left-bottom'];
587
644
  const MENU_POSITION = ['top', 'right', 'bottom', 'left'];
588
645
 
@@ -590,10 +647,13 @@ exports.ARRAY_ARROW_POSITION = ARROW_POSITION;
590
647
  exports.ARRAY_MENU_POSITION = MENU_POSITION;
591
648
  exports.DEFAULT_THEME = DEFAULT_THEME;
592
649
  exports.PALETTE = PALETTE;
650
+ exports.SELECTOR_FOCUS_VISIBLE = SELECTOR_FOCUS_VISIBLE;
593
651
  exports.ThemeProvider = ThemeProvider;
594
652
  exports.arrowStyles = arrowStyles;
653
+ exports.focusStyles = focusStyles;
595
654
  exports.getColor = getColor;
596
655
  exports.getDocument = getDocument;
656
+ exports.getFocusBoxShadow = getFocusBoxShadow;
597
657
  exports.getLineHeight = getLineHeight;
598
658
  exports.isRtl = isRtl;
599
659
  exports.mediaQuery = mediaQuery;
package/dist/index.esm.js CHANGED
@@ -10,6 +10,7 @@ import { ThemeProvider as ThemeProvider$1, withTheme as withTheme$1, css, keyfra
10
10
  import { useFocusVisible } from '@zendeskgarden/container-focusvisible';
11
11
  import { getControlledValue } from '@zendeskgarden/container-utilities';
12
12
  import { rgba, darken, lighten, getValueAndUnit, math } from 'polished';
13
+ import memoize from 'lodash.memoize';
13
14
 
14
15
  function _extends() {
15
16
  _extends = Object.assign ? Object.assign.bind() : function (target) {
@@ -243,10 +244,12 @@ const palette = {
243
244
  };
244
245
  delete palette.product;
245
246
  const shadowWidths = {
247
+ xs: '1px',
246
248
  sm: '2px',
247
249
  md: '3px'
248
250
  };
249
251
  const shadows = {
252
+ xs: color => `0 0 0 ${shadowWidths.xs} ${color}`,
250
253
  sm: color => `0 0 0 ${shadowWidths.sm} ${color}`,
251
254
  md: color => `0 0 0 ${shadowWidths.md} ${color}`,
252
255
  lg: (offsetY, blurRadius, color) => `0 ${offsetY} ${blurRadius} 0 ${color}`
@@ -358,7 +361,7 @@ const adjust = (color, expected, actual) => {
358
361
  }
359
362
  return color;
360
363
  };
361
- function getColor(hue) {
364
+ const getColor = memoize(function (hue) {
362
365
  let shade = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_SHADE;
363
366
  let theme = arguments.length > 2 ? arguments[2] : undefined;
364
367
  let transparency = arguments.length > 3 ? arguments[3] : undefined;
@@ -392,7 +395,32 @@ function getColor(hue) {
392
395
  retVal = rgba(retVal, transparency);
393
396
  }
394
397
  return retVal;
395
- }
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 getFocusBoxShadow = _ref => {
407
+ let {
408
+ inset = false,
409
+ hue = 'primaryHue',
410
+ shade = DEFAULT_SHADE,
411
+ shadowWidth = 'md',
412
+ spacerWidth = 'xs',
413
+ theme = DEFAULT_THEME
414
+ } = _ref;
415
+ const color = getColor(hue, shade, theme);
416
+ const shadow = theme.shadows[shadowWidth](color);
417
+ if (spacerWidth === null) {
418
+ return `${inset ? 'inset' : ''} ${shadow}`;
419
+ }
420
+ return `
421
+ ${inset ? 'inset' : ''} ${theme.shadows[spacerWidth](theme.colors.background)},
422
+ ${inset ? 'inset' : ''} ${shadow}`;
423
+ };
396
424
 
397
425
  function getLineHeight(height, fontSize) {
398
426
  const [heightValue, heightUnit] = getValueAndUnit(height.toString());
@@ -577,7 +605,35 @@ function menuStyles(position) {
577
605
  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));
578
606
  }
579
607
 
608
+ const SELECTOR_FOCUS_VISIBLE = '&:focus-visible, &[data-garden-focus-visible="true"]';
609
+ const focusStyles = _ref => {
610
+ let {
611
+ condition = true,
612
+ selector = SELECTOR_FOCUS_VISIBLE,
613
+ shadowWidth = 'md',
614
+ spacerWidth = 'xs',
615
+ styles,
616
+ theme,
617
+ ...options
618
+ } = _ref;
619
+ const boxShadow = condition ? getFocusBoxShadow({
620
+ shadowWidth,
621
+ spacerWidth,
622
+ theme,
623
+ ...options
624
+ }) : undefined;
625
+ let outline;
626
+ let outlineOffset;
627
+ if (spacerWidth === null) {
628
+ outline = theme.shadowWidths[shadowWidth];
629
+ } else {
630
+ outline = `${math(`${theme.shadowWidths[shadowWidth]} - ${theme.shadowWidths[spacerWidth]}`)} solid transparent`;
631
+ outlineOffset = theme.shadowWidths[spacerWidth];
632
+ }
633
+ return css(["&:focus{outline:none;}", "{outline:", ";outline-offset:", ";box-shadow:", ";", "}"], selector, outline, outlineOffset, boxShadow, styles);
634
+ };
635
+
580
636
  const ARROW_POSITION = ['top', 'top-left', 'top-right', 'right', 'right-top', 'right-bottom', 'bottom', 'bottom-left', 'bottom-right', 'left', 'left-top', 'left-bottom'];
581
637
  const MENU_POSITION = ['top', 'right', 'bottom', 'left'];
582
638
 
583
- export { ARROW_POSITION as ARRAY_ARROW_POSITION, MENU_POSITION as ARRAY_MENU_POSITION, DEFAULT_THEME, PALETTE, ThemeProvider, arrowStyles, getColor, getDocument, getLineHeight, isRtl, mediaQuery, menuStyles, retrieveComponentStyles, retrieveComponentStyles as retrieveTheme, useDocument, useText, useWindow, withTheme };
639
+ export { ARROW_POSITION as ARRAY_ARROW_POSITION, MENU_POSITION as ARRAY_MENU_POSITION, DEFAULT_THEME, PALETTE, SELECTOR_FOCUS_VISIBLE, ThemeProvider, arrowStyles, focusStyles, getColor, getDocument, getFocusBoxShadow, getLineHeight, isRtl, mediaQuery, menuStyles, retrieveComponentStyles, retrieveComponentStyles as retrieveTheme, useDocument, useText, useWindow, withTheme };
@@ -13,7 +13,8 @@ export { default as retrieveComponentStyles,
13
13
  default as retrieveTheme } from './utils/retrieveComponentStyles';
14
14
  export { default as withTheme } from './utils/withTheme';
15
15
  export { default as getDocument } from './utils/getDocument';
16
- export { default as getColor } from './utils/getColor';
16
+ export { getColor } from './utils/getColor';
17
+ export { getFocusBoxShadow } from './utils/getFocusBoxShadow';
17
18
  export { default as getLineHeight } from './utils/getLineHeight';
18
19
  export { default as mediaQuery } from './utils/mediaQuery';
19
20
  export { default as arrowStyles } from './utils/arrowStyles';
@@ -21,5 +22,6 @@ export { useDocument } from './utils/useDocument';
21
22
  export { useWindow } from './utils/useWindow';
22
23
  export { useText } from './utils/useText';
23
24
  export { default as menuStyles } from './utils/menuStyles';
25
+ export { focusStyles, SELECTOR_FOCUS_VISIBLE } from './utils/focusStyles';
24
26
  export { ARROW_POSITION as ARRAY_ARROW_POSITION, MENU_POSITION as ARRAY_MENU_POSITION } from './types';
25
27
  export type { IGardenTheme, IThemeProviderProps, ArrowPosition as ARROW_POSITION, MenuPosition as MENU_POSITION } from './types';
@@ -86,10 +86,12 @@ export interface IGardenTheme {
86
86
  xxxl: string;
87
87
  };
88
88
  shadowWidths: {
89
+ xs: string;
89
90
  sm: string;
90
91
  md: string;
91
92
  };
92
93
  shadows: {
94
+ xs: (color: string) => string;
93
95
  sm: (color: string) => string;
94
96
  md: (color: string) => string;
95
97
  lg: (offsetY: string, blurRadius: string, color: string) => string;
@@ -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 { CSSObject } from 'styled-components';
8
+ import { FocusBoxShadowParameters } from './getFocusBoxShadow';
9
+ export declare const SELECTOR_FOCUS_VISIBLE = "&:focus-visible, &[data-garden-focus-visible=\"true\"]";
10
+ type FocusStylesParameters = FocusBoxShadowParameters & {
11
+ condition?: boolean;
12
+ selector?: string;
13
+ styles?: CSSObject;
14
+ };
15
+ /**
16
+ * Garden standard `box-shadow` focus styling.
17
+ *
18
+ * @param {boolean} [options.condition=true] Supplies an optional condition that can be used to prevent the focus `box-shadow`
19
+ * @param {boolean} [options.inset=false] Determines whether the `box-shadow` is inset
20
+ * @param {string|Object} [options.hue='primaryHue'] Provides a theme object `palette` hue or `color` key, or any valid CSS color notation
21
+ * @param {string} [options.selector=SELECTOR_FOCUS_VISIBLE] Provides a subsitute `:focus-visible` pseudo-class CSS selector.
22
+ * @param {number} [options.shade=600] Selects a shade for the given hue
23
+ * @param {string} [options.shadowWidth='md'] Provides a theme object `shadowWidth` key for the cumulative width of the `box-shadow`
24
+ * @param {string} [options.spacerWidth='xs'] Provides a theme object `shadowWidth` for the white spacer, or `null` to remove
25
+ * @param {Object} [options.styles] Adds CSS property values to be rendered with `:focus-visible`
26
+ * @param {Object} options.theme Provides values used to resolve the desired color
27
+ *
28
+ * @returns CSS structured as follows, with `{values}` determined by the options provided:
29
+ * ```css
30
+ * :focus {
31
+ * outline: none;
32
+ * }
33
+ *
34
+ * :focus-visible,
35
+ * [data-garden-focus-visible='true'] {
36
+ * box-shadow: 0 0 0 {1px} #fff,
37
+ * 0 0 0 {3px} {blue};
38
+ * outline: {2px} solid transparent;
39
+ * outline-offset: {1px};
40
+ * // additional {styles} here...
41
+ * }
42
+ * ```
43
+ */
44
+ export declare const focusStyles: ({ condition, selector, shadowWidth, spacerWidth, styles, theme, ...options }: FocusStylesParameters) => import("styled-components").FlattenSimpleInterpolation;
45
+ export {};
@@ -4,8 +4,10 @@
4
4
  * Use of this source code is governed under the Apache License, Version 2.0
5
5
  * found at http://www.apache.org/licenses/LICENSE-2.0.
6
6
  */
7
+ /// <reference types="lodash" />
7
8
  import { DefaultTheme } from 'styled-components';
8
- type Hue = Record<number | string, string> | string;
9
+ export type Hue = Record<number | string, string> | string;
10
+ export declare const DEFAULT_SHADE = 600;
9
11
  /**
10
12
  * Get the palette color for the given hue, shade, and theme.
11
13
  *
@@ -19,8 +21,5 @@ type Hue = Record<number | string, string> | string;
19
21
  * @param {number} [shade=DEFAULT_SHADE] A hue shade.
20
22
  * @param {Object} theme Context `theme` object.
21
23
  * @param {Number} [transparency] An alpha-channel value between 0 and 1.
22
- *
23
- * @component
24
24
  */
25
- export default function getColor(hue: Hue, shade?: number, theme?: DefaultTheme, transparency?: number): string | undefined;
26
- export {};
25
+ export declare const getColor: ((hue: Hue, shade?: number, theme?: DefaultTheme, transparency?: number) => string | undefined) & import("lodash").MemoizedFunction;
@@ -0,0 +1,31 @@
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 { IGardenTheme } from '../types';
8
+ import { Hue } from './getColor';
9
+ export type FocusBoxShadowParameters = {
10
+ inset?: boolean;
11
+ hue?: Hue;
12
+ shade?: number;
13
+ shadowWidth?: 'sm' | 'md';
14
+ spacerWidth?: null | 'xs' | 'sm';
15
+ theme: IGardenTheme;
16
+ };
17
+ /**
18
+ * Get a CSS `box-shadow` property value for focus state styling. The `hue` and
19
+ * `shade` are used to determine the color of the focus ring.
20
+ *
21
+ * @param {boolean} [options.inset=false] Determines whether the `box-shadow` is inset
22
+ * @param {string|Object} [options.hue='primaryHue'] Provides a theme object `palette` hue or `color` key, or any valid CSS color notation
23
+ * @param {number} [options.shade=600] Selects a shade for the given hue
24
+ * @param {string} [options.shadowWidth='md'] Provides a theme object `shadowWidth` key for the cumulative width of the `box-shadow`
25
+ * @param {string} [options.spacerWidth='xs'] Provides a theme object `shadowWidth` for the white spacer, or `null` to remove
26
+ * @param {Object} options.theme Provides values used to resolve the desired color
27
+ *
28
+ * @returns A `box-shadow` property value for the given options. Default is a
29
+ * 3px `blue[600]` ring with a 1px white spacer overlay.
30
+ */
31
+ export declare const getFocusBoxShadow: ({ inset, hue, shade, shadowWidth, spacerWidth, theme }: FocusBoxShadowParameters) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zendeskgarden/react-theming",
3
- "version": "8.65.0",
3
+ "version": "8.66.0",
4
4
  "description": "Theming utilities and components within the Garden Design System",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Zendesk Garden <garden@zendesk.com>",
@@ -23,6 +23,7 @@
23
23
  "dependencies": {
24
24
  "@zendeskgarden/container-focusvisible": "^1.0.0",
25
25
  "@zendeskgarden/container-utilities": "^1.0.0",
26
+ "lodash.memoize": "^4.1.2",
26
27
  "polished": "^4.0.0",
27
28
  "prop-types": "^15.5.7"
28
29
  },
@@ -31,6 +32,9 @@
31
32
  "react-dom": ">=16.8.0",
32
33
  "styled-components": "^4.2.0 || ^5.0.0"
33
34
  },
35
+ "devDependencies": {
36
+ "@types/lodash.memoize": "4.1.7"
37
+ },
34
38
  "keywords": [
35
39
  "components",
36
40
  "garden",
@@ -41,5 +45,5 @@
41
45
  "access": "public"
42
46
  },
43
47
  "zendeskgarden:src": "src/index.ts",
44
- "gitHead": "b702124a0055fdb7540f0d27b34ccbc9d552fc7a"
48
+ "gitHead": "40df9b49f68b69878186a66e9c14efb00eca051f"
45
49
  }