@zendeskgarden/react-theming 9.0.0-next.7 → 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.
@@ -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 };
package/dist/index.cjs.js CHANGED
@@ -1,10 +1,9 @@
1
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
-
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
+ */
8
7
  'use strict';
9
8
 
10
9
  var React = require('react');
@@ -20,21 +19,6 @@ var React__default = /*#__PURE__*/_interopDefault(React);
20
19
  var get__default = /*#__PURE__*/_interopDefault(get);
21
20
  var memoize__default = /*#__PURE__*/_interopDefault(memoize);
22
21
 
23
- function _extends() {
24
- _extends = Object.assign ? Object.assign.bind() : function (target) {
25
- for (var i = 1; i < arguments.length; i++) {
26
- var source = arguments[i];
27
- for (var key in source) {
28
- if (Object.prototype.hasOwnProperty.call(source, key)) {
29
- target[key] = source[key];
30
- }
31
- }
32
- }
33
- return target;
34
- };
35
- return _extends.apply(this, arguments);
36
- }
37
-
38
22
  const PALETTE = {
39
23
  black: '#000',
40
24
  white: '#fff',
@@ -344,24 +328,84 @@ const colors = {
344
328
  variables: {
345
329
  dark: {
346
330
  background: {
347
- default: 'neutralHue.1100'
331
+ default: 'neutralHue.1100',
332
+ raised: 'neutralHue.1000',
333
+ recessed: 'neutralHue.1200',
334
+ subtle: 'neutralHue.1000',
335
+ emphasis: 'neutralHue.600',
336
+ primary: 'primaryHue.900',
337
+ success: 'successHue.1000',
338
+ warning: 'warningHue.1000',
339
+ danger: 'dangerHue.1000',
340
+ primaryEmphasis: 'primaryHue.600',
341
+ successEmphasis: 'successHue.600',
342
+ warningEmphasis: 'warningHue.600',
343
+ dangerEmphasis: 'dangerHue.600'
348
344
  },
349
345
  border: {
350
- default: 'neutralHue.700'
346
+ default: 'neutralHue.800',
347
+ emphasis: 'neutralHue.600',
348
+ subtle: 'neutralHue.900',
349
+ success: 'successHue.800',
350
+ warning: 'warningHue.800',
351
+ danger: 'dangerHue.800',
352
+ primaryEmphasis: 'primaryHue.600',
353
+ successEmphasis: 'successHue.600',
354
+ warningEmphasis: 'warningHue.600',
355
+ dangerEmphasis: 'dangerHue.600'
351
356
  },
352
357
  foreground: {
353
- default: 'neutralHue.300'
358
+ default: 'neutralHue.300',
359
+ subtle: 'neutralHue.500',
360
+ onEmphasis: 'neutralHue.1100',
361
+ primary: 'primaryHue.600',
362
+ success: 'successHue.400',
363
+ warning: 'warningHue.400',
364
+ danger: 'dangerHue.400',
365
+ successEmphasis: 'successHue.300',
366
+ warningEmphasis: 'warningHue.300',
367
+ dangerEmphasis: 'dangerHue.300'
354
368
  }
355
369
  },
356
370
  light: {
357
371
  background: {
358
- default: 'palette.white'
372
+ default: 'palette.white',
373
+ raised: 'palette.white',
374
+ recessed: 'neutralHue.100',
375
+ subtle: 'neutralHue.100',
376
+ emphasis: 'neutralHue.700',
377
+ primary: 'primaryHue.100',
378
+ success: 'successHue.100',
379
+ warning: 'warningHue.100',
380
+ danger: 'dangerHue.100',
381
+ primaryEmphasis: 'primaryHue.700',
382
+ successEmphasis: 'successHue.700',
383
+ warningEmphasis: 'warningHue.700',
384
+ dangerEmphasis: 'dangerHue.700'
359
385
  },
360
386
  border: {
361
- default: 'neutralHue.400'
387
+ default: 'neutralHue.300',
388
+ emphasis: 'neutralHue.600',
389
+ subtle: 'neutralHue.200',
390
+ success: 'successHue.300',
391
+ warning: 'warningHue.300',
392
+ danger: 'dangerHue.300',
393
+ primaryEmphasis: 'primaryHue.700',
394
+ successEmphasis: 'successHue.700',
395
+ warningEmphasis: 'warningHue.700',
396
+ dangerEmphasis: 'dangerHue.700'
362
397
  },
363
398
  foreground: {
364
- default: 'neutralHue.900'
399
+ default: 'neutralHue.900',
400
+ subtle: 'neutralHue.700',
401
+ onEmphasis: 'palette.white',
402
+ primary: 'primaryHue.700',
403
+ success: 'successHue.700',
404
+ warning: 'warningHue.700',
405
+ danger: 'dangerHue.700',
406
+ successEmphasis: 'successHue.900',
407
+ warningEmphasis: 'warningHue.900',
408
+ dangerEmphasis: 'dangerHue.900'
365
409
  }
366
410
  }
367
411
  }
@@ -456,7 +500,7 @@ const ThemeProvider = _ref => {
456
500
  theme,
457
501
  ...other
458
502
  } = _ref;
459
- return React__default.default.createElement(styledComponents.ThemeProvider, _extends({
503
+ return React__default.default.createElement(styledComponents.ThemeProvider, Object.assign({
460
504
  theme: theme
461
505
  }, other));
462
506
  };
@@ -685,7 +729,7 @@ const toColor = (colors, palette, scheme, hue, shade, offset, transparency) => {
685
729
  }
686
730
  if (typeof _hue === 'object') {
687
731
  retVal = toHex(_hue, shade, offset, scheme);
688
- } else if (chromaJs.valid(_hue)) {
732
+ } else if (_hue === 'transparent' || chromaJs.valid(_hue)) {
689
733
  if (shade === undefined) {
690
734
  retVal = _hue;
691
735
  } else {
@@ -895,22 +939,32 @@ const getFocusBoxShadow = _ref => {
895
939
  let {
896
940
  boxShadow,
897
941
  inset = false,
898
- hue = 'primaryHue',
899
- shade = DEFAULT_SHADE,
942
+ color = {
943
+ variable: 'border.primaryEmphasis'
944
+ },
900
945
  shadowWidth = 'md',
901
- spacerHue = 'background',
902
- spacerShade = DEFAULT_SHADE,
946
+ spacerColor = {
947
+ variable: 'background.default'
948
+ },
903
949
  spacerWidth = 'xs',
904
- theme = DEFAULT_THEME
950
+ theme = DEFAULT_THEME,
951
+ ...args
905
952
  } = _ref;
906
- const color = getColorV8(hue, shade, theme);
907
- const shadow = theme.shadows[shadowWidth](color);
953
+ const _args = args;
954
+ const _color = _args.hue ? getColorV8(_args.hue, _args.shade, theme) : getColor({
955
+ ...color,
956
+ theme
957
+ });
958
+ const shadow = theme.shadows[shadowWidth](_color);
908
959
  if (spacerWidth === null) {
909
960
  return `${inset ? 'inset' : ''} ${shadow}`;
910
961
  }
911
- const spacerColor = getColorV8(spacerHue, spacerShade, theme);
962
+ const _spacerColor = _args.spacerHue ? getColorV8(_args.spacerHue, _args.spacerShade, theme) : getColor({
963
+ ...spacerColor,
964
+ theme
965
+ });
912
966
  const retVal = `
913
- ${inset ? 'inset' : ''} ${theme.shadows[spacerWidth](spacerColor)},
967
+ ${inset ? 'inset' : ''} ${theme.shadows[spacerWidth](_spacerColor)},
914
968
  ${inset ? 'inset' : ''} ${shadow}`;
915
969
  return boxShadow ? `${retVal}, ${boxShadow}` : retVal;
916
970
  };
@@ -1111,7 +1165,21 @@ function menuStyles(position) {
1111
1165
  } else {
1112
1166
  marginProperty = 'margin-right';
1113
1167
  }
1114
- 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, getColorV8('neutralHue', 300, theme), theme.borderRadii.md, theme.shadows.lg(`${theme.space.base * 5}px`, `${theme.space.base * 7.5}px`, getColorV8('chromeHue', 600, theme, 0.15)), getColorV8('background', 600 , theme), theme.rtl ? 'right' : 'left', theme.fontSizes.md, theme.fontWeights.regular, theme.rtl && 'rtl', options.animationModifier && animationStyles(position, options), options.hidden && hiddenStyles(options));
1168
+ 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;color:", ";font-size:", ";font-weight:", ";direction:", ";:focus{outline:none;}}", ";", ";"], options.zIndex || 0, marginProperty, options.margin, options.childSelector || '> *', theme.borders.sm, getColor({
1169
+ theme,
1170
+ variable: 'border.default'
1171
+ }), theme.borderRadii.md, theme.shadows.lg(`${theme.space.base * 5}px`, `${theme.space.base * 7.5}px`, getColor({
1172
+ theme,
1173
+ hue: 'chromeHue',
1174
+ shade: 600,
1175
+ transparency: 0.15
1176
+ })), getColor({
1177
+ theme,
1178
+ variable: 'background.raised'
1179
+ }), theme.rtl ? 'right' : 'left', getColor({
1180
+ theme,
1181
+ variable: 'foreground.default'
1182
+ }), theme.fontSizes.md, theme.fontWeights.regular, theme.rtl && 'rtl', options.animationModifier && animationStyles(position, options), options.hidden && hiddenStyles(options));
1115
1183
  }
1116
1184
 
1117
1185
  const SELECTOR_FOCUS_VISIBLE = '&:focus-visible';
@@ -23,4 +23,4 @@ export { useWindow } from './utils/useWindow';
23
23
  export { useText } from './utils/useText';
24
24
  export { default as menuStyles } from './utils/menuStyles';
25
25
  export { focusStyles, SELECTOR_FOCUS_VISIBLE } from './utils/focusStyles';
26
- export { ARROW_POSITION, MENU_POSITION, PLACEMENT, type IGardenTheme, type IThemeProviderProps, type ArrowPosition, type MenuPosition, type Placement } from './types';
26
+ export { ARROW_POSITION, MENU_POSITION, PLACEMENT, type IGardenTheme, type IThemeProviderProps, type ArrowPosition, type ColorParameters, type FocusBoxShadowParameters, type FocusStylesParameters, type MenuPosition, type Placement } from './types';
@@ -4,13 +4,47 @@
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
- import { ThemeProviderProps } from 'styled-components';
7
+ import { CSSObject, ThemeProviderProps } from 'styled-components';
8
8
  export declare const ARROW_POSITION: readonly ["top", "top-left", "top-right", "right", "right-top", "right-bottom", "bottom", "bottom-left", "bottom-right", "left", "left-top", "left-bottom"];
9
9
  export type ArrowPosition = (typeof ARROW_POSITION)[number];
10
10
  export declare const MENU_POSITION: readonly ["top", "right", "bottom", "left"];
11
11
  export type MenuPosition = (typeof MENU_POSITION)[number];
12
12
  export declare const PLACEMENT: readonly ["top", "top-start", "top-end", "bottom", "bottom-start", "bottom-end", "end", "end-top", "end-bottom", "start", "start-top", "start-bottom"];
13
13
  export type Placement = (typeof PLACEMENT)[number];
14
+ export type ColorParameters = {
15
+ dark?: {
16
+ hue?: string;
17
+ offset?: number;
18
+ shade?: number;
19
+ transparency?: number;
20
+ };
21
+ hue?: string;
22
+ light?: {
23
+ hue?: string;
24
+ offset?: number;
25
+ shade?: number;
26
+ transparency?: number;
27
+ };
28
+ offset?: number;
29
+ shade?: number;
30
+ theme: IGardenTheme;
31
+ transparency?: number;
32
+ variable?: string;
33
+ };
34
+ export type FocusStylesParameters = FocusBoxShadowParameters & {
35
+ condition?: boolean;
36
+ selector?: string;
37
+ styles?: CSSObject;
38
+ };
39
+ export type FocusBoxShadowParameters = {
40
+ boxShadow?: string;
41
+ inset?: boolean;
42
+ color?: Omit<ColorParameters, 'theme'>;
43
+ shadowWidth?: 'sm' | 'md';
44
+ spacerColor?: Omit<ColorParameters, 'theme'>;
45
+ spacerWidth?: null | 'xs' | 'sm';
46
+ theme: IGardenTheme;
47
+ };
14
48
  export type Hue = Record<number | string, string> | string;
15
49
  export interface IGardenTheme {
16
50
  rtl: boolean;
@@ -4,14 +4,8 @@
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
- import { CSSObject } from 'styled-components';
8
- import { FocusBoxShadowParameters } from './getFocusBoxShadow';
7
+ import { FocusStylesParameters } from '../types';
9
8
  export declare const SELECTOR_FOCUS_VISIBLE = "&:focus-visible";
10
- type FocusStylesParameters = FocusBoxShadowParameters & {
11
- condition?: boolean;
12
- selector?: string;
13
- styles?: CSSObject;
14
- };
15
9
  /**
16
10
  * Garden standard `box-shadow` focus styling.
17
11
  *
@@ -43,4 +37,3 @@ type FocusStylesParameters = FocusBoxShadowParameters & {
43
37
  * ```
44
38
  */
45
39
  export declare const focusStyles: ({ condition, selector, shadowWidth, spacerWidth, styles: { boxShadow, ...styles }, theme, ...options }: FocusStylesParameters) => import("styled-components").FlattenSimpleInterpolation;
46
- export {};
@@ -5,27 +5,7 @@
5
5
  * found at http://www.apache.org/licenses/LICENSE-2.0.
6
6
  */
7
7
  /// <reference types="lodash" />
8
- import { IGardenTheme } from '../types';
9
- type ColorParameters = {
10
- dark?: {
11
- hue?: string;
12
- offset?: number;
13
- shade?: number;
14
- transparency?: number;
15
- };
16
- hue?: string;
17
- light?: {
18
- hue?: string;
19
- offset?: number;
20
- shade?: number;
21
- transparency?: number;
22
- };
23
- offset?: number;
24
- shade?: number;
25
- theme: IGardenTheme;
26
- transparency?: number;
27
- variable?: string;
28
- };
8
+ import { ColorParameters } from '../types';
29
9
  /**
30
10
  * Get a color value from the theme. Variable lookup takes precedence, followed
31
11
  * by `dark` and `light` object values. If none of these are provided, `hue`,
@@ -48,4 +28,3 @@ type ColorParameters = {
48
28
  * @param {number} [options.transparency] An alpha-channel value between 0 and 1
49
29
  */
50
30
  export declare const getColor: (({ dark, hue, light, offset, shade, theme, transparency, variable }: ColorParameters) => string) & import("lodash").MemoizedFunction;
51
- export {};
@@ -4,33 +4,19 @@
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
- import { Hue, IGardenTheme } from '../types';
8
- export type FocusBoxShadowParameters = {
9
- boxShadow?: string;
10
- inset?: boolean;
11
- hue?: Hue;
12
- shade?: number;
13
- shadowWidth?: 'sm' | 'md';
14
- spacerHue?: Hue;
15
- spacerShade?: number;
16
- spacerWidth?: null | 'xs' | 'sm';
17
- theme: IGardenTheme;
18
- };
7
+ import { FocusBoxShadowParameters } from '../types';
19
8
  /**
20
- * Get a CSS `box-shadow` property value for focus state styling. The `hue` and
21
- * `shade` are used to determine the color of the focus ring.
9
+ * Get a CSS `box-shadow` property value for focus state styling.
22
10
  *
23
11
  * @param {string} [options.boxShadow] Provides an existing `box-shadow` (a drop shadow, for example) to be retained along with the focus ring
24
12
  * @param {boolean} [options.inset=false] Determines whether the `box-shadow` is inset
25
- * @param {string|Object} [options.hue='primaryHue'] Provides a theme object `palette` hue or `color` key, or any valid CSS color notation
26
- * @param {number} [options.shade=600] Selects a shade for the given `hue`
13
+ * @param {Object} [options.color={ variable: 'border.primaryEmphasis' }] Provides an object with `getColor` parameters used to determine the focus ring color
27
14
  * @param {string} [options.shadowWidth='md'] Provides a theme object `shadowWidth` key for the cumulative width of the `box-shadow`
28
- * @param {string|Object} [options.spacerHue='background'] Provides a theme object `palette` hue or `color` key, or any valid CSS color notation
29
- * @param {number} [options.spacerShade=600] Selects a shade for the given `spacerHue`
15
+ * @param {Object} [options.spacerColor={ variable: 'background.default' }] Provides an object with `getColor` parameters used to determine the spacer color
30
16
  * @param {string} [options.spacerWidth='xs'] Provides a theme object `shadowWidth` for the white spacer, or `null` to remove
31
17
  * @param {Object} options.theme Provides values used to resolve the desired color
32
18
  *
33
19
  * @returns A `box-shadow` property value for the given options. Default is a
34
- * 3px `blue[600]` ring with a 1px white spacer overlay.
20
+ * 3px blue ring with a 1px spacer overlay that matches the background.
35
21
  */
36
- export declare const getFocusBoxShadow: ({ boxShadow, inset, hue, shade, shadowWidth, spacerHue, spacerShade, spacerWidth, theme }: FocusBoxShadowParameters) => string;
22
+ export declare const getFocusBoxShadow: ({ boxShadow, inset, color, shadowWidth, spacerColor, spacerWidth, theme, ...args }: FocusBoxShadowParameters) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zendeskgarden/react-theming",
3
- "version": "9.0.0-next.7",
3
+ "version": "9.0.0-next.8",
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>",
@@ -10,7 +10,7 @@
10
10
  "url": "https://github.com/zendeskgarden/react-components/issues"
11
11
  },
12
12
  "main": "dist/index.cjs.js",
13
- "module": "dist/index.esm.js",
13
+ "module": "dist/esm/index.js",
14
14
  "files": [
15
15
  "dist"
16
16
  ],
@@ -48,5 +48,5 @@
48
48
  "access": "public"
49
49
  },
50
50
  "zendeskgarden:src": "src/index.ts",
51
- "gitHead": "50a2b45b2e237a490a6d460818d33498b92479ec"
51
+ "gitHead": "a3d6534843d5a4f5cb60b52bc67264f3230f2da0"
52
52
  }