How to use @zendeskgarden/react-utilities - 10 common examples

To help you get started, we’ve selected a few @zendeskgarden/react-utilities examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zendeskgarden / react-components / packages / toggles / src / elements / Toggle.js View on Github external
{Children.map(children, child => {
          if (!isValidElement(child)) {
            return child;
          }

          if (hasType(child, Label)) {
            const { onMouseUp, ...otherChildProps } = child.props;

            return cloneElement(
              child,
              getLabelProps({
                focused: keyboardFocused,
                // Apply keyboard-only focus event
                onMouseUp: composeEventHandlers(onMouseUp, onFocusMouseDown),
                ...otherChildProps
              })
            );
          }

          if (hasType(child, Hint)) {
            return cloneElement(child, getHintProps(child.props));
          }
github zendeskgarden / react-components / packages / menus / src / elements / Menu.js View on Github external
const { textValue, disabled, children: childChildren } = child.props;
              const key = child.key;

              /**
               * Children with the `disabled` prop are not selectable
               */
              if (disabled) {
                return child;
              }

              if (
                hasType(child, AddItem) ||
                hasType(child, Item) ||
                hasType(child, MediaItem) ||
                hasType(child, NextItem) ||
                hasType(child, PreviousItem)
              ) {
                /**
                 * Automatically apply `textValue` if children is a string
                 */
                const childrenTextValue =
                  typeof childChildren === 'string' ? childChildren : undefined;

                let itemPropMapper = getItemProps;

                if (hasType(child, NextItem)) {
                  itemPropMapper = getNextItemProps;
                } else if (hasType(child, PreviousItem)) {
                  itemPropMapper = getPreviousItemProps;
                }
github zendeskgarden / react-components / packages / menus / src / elements / Menu.js View on Github external
const { textValue, disabled, children: childChildren } = child.props;
              const key = child.key;

              /**
               * Children with the `disabled` prop are not selectable
               */
              if (disabled) {
                return child;
              }

              if (
                hasType(child, AddItem) ||
                hasType(child, Item) ||
                hasType(child, MediaItem) ||
                hasType(child, NextItem) ||
                hasType(child, PreviousItem)
              ) {
                /**
                 * Automatically apply `textValue` if children is a string
                 */
                const childrenTextValue =
                  typeof childChildren === 'string' ? childChildren : undefined;

                let itemPropMapper = getItemProps;

                if (hasType(child, NextItem)) {
                  itemPropMapper = getNextItemProps;
                } else if (hasType(child, PreviousItem)) {
                  itemPropMapper = getPreviousItemProps;
                }

                return cloneElement(
github zendeskgarden / react-components / packages / menus / src / elements / Menu.js View on Github external
if (
                hasType(child, AddItem) ||
                hasType(child, Item) ||
                hasType(child, MediaItem) ||
                hasType(child, NextItem) ||
                hasType(child, PreviousItem)
              ) {
                /**
                 * Automatically apply `textValue` if children is a string
                 */
                const childrenTextValue =
                  typeof childChildren === 'string' ? childChildren : undefined;

                let itemPropMapper = getItemProps;

                if (hasType(child, NextItem)) {
                  itemPropMapper = getNextItemProps;
                } else if (hasType(child, PreviousItem)) {
                  itemPropMapper = getPreviousItemProps;
                }

                return cloneElement(
                  child,
                  itemPropMapper({
                    key,
                    textValue: textValue || childrenTextValue,
                    focused: focusedKey === key,
                    children: childChildren,
                    ...child.props
                  })
                );
              }
github zendeskgarden / react-components / packages / ranges / src / elements / RangeField.js View on Github external
{Children.map(children, child => {
              if (!isValidElement(child)) {
                return child;
              }

              if (hasType(child, Label)) {
                return cloneElement(child, getLabelProps(child.props));
              }

              if (hasType(child, Range) || hasType(child, MultiThumbRange)) {
                return cloneElement(child, getInputProps(child.props, { isDescribed }));
              }

              if (hasType(child, Hint)) {
                return cloneElement(child, getHintProps(child.props));
              }

              return child;
            })}
github zendeskgarden / react-components / packages / textfields / src / elements / TextField.js View on Github external
{Children.map(children, child => {
            if (!isValidElement(child)) {
              return child;
            }

            if (hasType(child, Label)) {
              return cloneElement(child, getLabelProps(child.props));
            }

            if (hasType(child, Input) || hasType(child, Textarea)) {
              return cloneElement(child, getInputProps(child.props, { isDescribed }));
            }

            if (hasType(child, Hint)) {
              return cloneElement(child, getHintProps(child.props));
            }

            return child;
          })}
github zendeskgarden / react-components / packages / select / src / elements / SelectField.js View on Github external
{Children.map(children, child => {
              if (!isValidElement(child)) {
                return child;
              }

              if (hasType(child, Label)) {
                return cloneElement(child, getFieldLabelProps(this.getLabelProps(child.props)));
              }

              if (hasType(child, Hint)) {
                return cloneElement(child, getHintProps(child.props));
              }

              if (hasType(child, Select)) {
                return cloneElement(child, getFieldInputProps(this.getInputProps(child.props)));
              }

              return child;
            })}
github zendeskgarden / react-components / packages / select / src / elements / Select.js View on Github external
Children.forEach(options, option => {
      const { textValue, disabled, children: childChildren } = option.props;
      const key = option.key;

      if (disabled) {
        return;
      }

      if (
        hasType(option, AddItem) ||
        hasType(option, Item) ||
        hasType(option, MediaItem) ||
        hasType(option, NextItem) ||
        hasType(option, PreviousItem)
      ) {
        /**
         * Use children as textValue if none is provided
         */
        let optionTextValue = textValue;

        if (optionTextValue === undefined) {
          optionTextValue = typeof childChildren === 'string' ? childChildren : undefined;
        }

        /**
         * Create model to allow keyboard selection without opening dropdown
github zendeskgarden / react-components / packages / modals / src / elements / Modal.js View on Github external
{Children.map(children, child => {
            if (!isValidElement(child)) {
              return child;
            }

            if (hasType(child, Header)) {
              return cloneElement(child, getTitleProps(child.props));
            }

            if (hasType(child, Body)) {
              return cloneElement(child, getContentProps(child.props));
            }

            if (hasType(child, Close)) {
              return cloneElement(child, getCloseProps(child.props));
            }

            return child;
          })}
github zendeskgarden / react-components / packages / menus / src / elements / Menu.js View on Github external
}

              const { textValue, disabled, children: childChildren } = child.props;
              const key = child.key;

              /**
               * Children with the `disabled` prop are not selectable
               */
              if (disabled) {
                return child;
              }

              if (
                hasType(child, AddItem) ||
                hasType(child, Item) ||
                hasType(child, MediaItem) ||
                hasType(child, NextItem) ||
                hasType(child, PreviousItem)
              ) {
                /**
                 * Automatically apply `textValue` if children is a string
                 */
                const childrenTextValue =
                  typeof childChildren === 'string' ? childChildren : undefined;

                let itemPropMapper = getItemProps;

                if (hasType(child, NextItem)) {
                  itemPropMapper = getNextItemProps;
                } else if (hasType(child, PreviousItem)) {
                  itemPropMapper = getPreviousItemProps;
                }

@zendeskgarden/react-utilities

Components relating to utilities in the Garden Design System

Apache-2.0
Latest version published 26 days ago

Package Health Score

81 / 100
Full package analysis