@zendeskgarden/react-theming 8.64.0 → 8.65.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
@@ -513,21 +513,36 @@ function arrowStyles(position) {
513
513
  return styledComponents.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$1(position, options.animationModifier));
514
514
  }
515
515
 
516
- const useText = (component, props, name, text) => {
517
- const value = props[name];
516
+ const useWindow = theme => {
517
+ const [controlledWindow, setControlledWindow] = React.useState();
518
+ React.useEffect(() => {
519
+ if (theme && theme.window) {
520
+ setControlledWindow(theme.window);
521
+ } else {
522
+ setControlledWindow(window);
523
+ }
524
+ }, [theme]);
525
+ return controlledWindow;
526
+ };
527
+
528
+ const useText = function (component, props, name, text) {
529
+ let condition = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
530
+ const value = condition ? props[name] : undefined;
518
531
  return React.useMemo(() => {
519
- if (name === 'children') {
520
- throw new Error('Error: `children` is not a valid `getText` prop.');
521
- } else if (value === null || value === '') {
522
- 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.`);
523
- } else if (value === undefined) {
524
- if (process.env.NODE_ENV === 'development') {
525
- 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.`);
532
+ if (condition) {
533
+ if (name === 'children') {
534
+ throw new Error('Error: `children` is not a valid `useText` prop.');
535
+ } else if (value === null || value === '') {
536
+ 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.`);
537
+ } else if (value === undefined) {
538
+ if (process.env.NODE_ENV === 'development') {
539
+ 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.`);
540
+ }
541
+ return text;
526
542
  }
527
- return text;
528
543
  }
529
544
  return value;
530
- }, [component.displayName, value, name, text]);
545
+ }, [component.displayName, value, name, text, condition]);
531
546
  };
532
547
 
533
548
  const animationStyles = (position, options) => {
@@ -587,4 +602,5 @@ exports.retrieveComponentStyles = retrieveComponentStyles;
587
602
  exports.retrieveTheme = retrieveComponentStyles;
588
603
  exports.useDocument = useDocument;
589
604
  exports.useText = useText;
605
+ exports.useWindow = useWindow;
590
606
  exports.withTheme = withTheme;
package/dist/index.esm.js CHANGED
@@ -507,21 +507,36 @@ function arrowStyles(position) {
507
507
  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$1(position, options.animationModifier));
508
508
  }
509
509
 
510
- const useText = (component, props, name, text) => {
511
- const value = props[name];
510
+ const useWindow = theme => {
511
+ const [controlledWindow, setControlledWindow] = useState();
512
+ useEffect(() => {
513
+ if (theme && theme.window) {
514
+ setControlledWindow(theme.window);
515
+ } else {
516
+ setControlledWindow(window);
517
+ }
518
+ }, [theme]);
519
+ return controlledWindow;
520
+ };
521
+
522
+ const useText = function (component, props, name, text) {
523
+ let condition = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
524
+ const value = condition ? props[name] : undefined;
512
525
  return useMemo(() => {
513
- if (name === 'children') {
514
- throw new Error('Error: `children` is not a valid `getText` prop.');
515
- } else if (value === null || value === '') {
516
- 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.`);
517
- } else if (value === undefined) {
518
- if (process.env.NODE_ENV === 'development') {
519
- 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.`);
526
+ if (condition) {
527
+ if (name === 'children') {
528
+ throw new Error('Error: `children` is not a valid `useText` prop.');
529
+ } else if (value === null || value === '') {
530
+ 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.`);
531
+ } else if (value === undefined) {
532
+ if (process.env.NODE_ENV === 'development') {
533
+ 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.`);
534
+ }
535
+ return text;
520
536
  }
521
- return text;
522
537
  }
523
538
  return value;
524
- }, [component.displayName, value, name, text]);
539
+ }, [component.displayName, value, name, text, condition]);
525
540
  };
526
541
 
527
542
  const animationStyles = (position, options) => {
@@ -565,4 +580,4 @@ function menuStyles(position) {
565
580
  const ARROW_POSITION = ['top', 'top-left', 'top-right', 'right', 'right-top', 'right-bottom', 'bottom', 'bottom-left', 'bottom-right', 'left', 'left-top', 'left-bottom'];
566
581
  const MENU_POSITION = ['top', 'right', 'bottom', 'left'];
567
582
 
568
- 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, withTheme };
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 };
@@ -18,6 +18,7 @@ export { default as getLineHeight } from './utils/getLineHeight';
18
18
  export { default as mediaQuery } from './utils/mediaQuery';
19
19
  export { default as arrowStyles } from './utils/arrowStyles';
20
20
  export { useDocument } from './utils/useDocument';
21
+ export { useWindow } from './utils/useWindow';
21
22
  export { useText } from './utils/useText';
22
23
  export { default as menuStyles } from './utils/menuStyles';
23
24
  export { ARROW_POSITION as ARRAY_ARROW_POSITION, MENU_POSITION as ARRAY_MENU_POSITION } from './types';
@@ -13,6 +13,7 @@ type Hue = Record<number | string, string> | string;
13
13
  export interface IGardenTheme {
14
14
  rtl: boolean;
15
15
  document?: any;
16
+ window?: any;
16
17
  borders: {
17
18
  sm: string;
18
19
  md: string;
@@ -14,5 +14,6 @@ import { FC } from 'react';
14
14
  * @param props The component props to check for `name`
15
15
  * @param name The name of the component prop to set default text on
16
16
  * @param text The default text to apply if the value of `props[name]` is undefined
17
+ * @param condition An optional condition that can be used to prevent evaluation
17
18
  */
18
- export declare const useText: (component: Pick<FC, 'displayName'>, props: Record<string, any>, name: string, text: string) => string;
19
+ export declare const useText: (component: Pick<FC, 'displayName'>, props: Record<string, any>, name: string, text: string, condition?: boolean) => string | undefined;
@@ -0,0 +1,8 @@
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 { DefaultTheme } from 'styled-components';
8
+ export declare const useWindow: (theme?: Partial<DefaultTheme>) => Window | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zendeskgarden/react-theming",
3
- "version": "8.64.0",
3
+ "version": "8.65.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>",
@@ -41,5 +41,5 @@
41
41
  "access": "public"
42
42
  },
43
43
  "zendeskgarden:src": "src/index.ts",
44
- "gitHead": "c0cfa3666c7a2e72ec8a9e0af8d530bb3312da86"
44
+ "gitHead": "b702124a0055fdb7540f0d27b34ccbc9d552fc7a"
45
45
  }