How to use the @paprika/helpers/lib/extractChildren function in @paprika/helpers

To help you get started, we’ve selected a few @paprika/helpers 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 acl-services / paprika / packages / DropdownMenu / src / DropdownMenu.js View on Github external
setRenderConfirmation(null);
    }

    if (triggerRef.current) triggerRef.current.focus();
  };

  const handleOpenMenu = () => {
    setIsOpen(true);
    // https://github.com/acl-services/paprika/issues/316
    // Todo Should focus the first item via an onAfterOpen event callback in popover
    setTimeout(() => {
      focusAndSetIndex(0);
    }, 250);
  };

  const extractedChildren = extractChildren(children, ["DropdownMenu.Trigger"]);

  const dropdownLastItemIndex =
    React.Children.toArray(
      extractedChildren.children.filter(
        child =>
          child.type &&
          (child.type.displayName === "DropdownMenu.Item" || child.type.displayName === "DropdownMenu.LinkItem")
      )
    ).length - 1;

  const onKeyDown = (event, currentIndex) => {
    if (event.key === "ArrowDown") {
      const indexToFocus = currentIndex === dropdownLastItemIndex ? 0 : currentIndex + 1;
      focusAndSetIndex(indexToFocus);
    } else if (event.key === "ArrowUp") {
      const indexToFocus = currentIndex === 0 ? dropdownLastItemIndex : currentIndex - 1;
github acl-services / paprika / packages / Takeover / src / Takeover.js View on Github external
const Takeover = props => {
  const { isOpen, onClose, onAfterClose, onAfterOpen, ...moreProps } = props;

  function handleTransitionEnter(node) {
    // https://github.com/reactjs/react-transition-group/blob/6dbadb594c7c2a2f15bc47afc6b4374cfd73c7c0/src/CSSTransition.js#L44
    // eslint-disable-next-line no-unused-expressions
    node.scrollTop;
  }

  const {
    "Takeover.FocusTrap": focusTrapExtracted,
    "Takeover.Header": headerExtracted,
    "Takeover.Content": contentExtracted,
    children,
  } = extractChildren(moreProps.children, ["Takeover.FocusTrap", "Takeover.Header", "Takeover.Content"]);

  const extendedFocusTrapOptions = focusTrapExtracted ? focusTrapExtracted.props : {};

  const focusTrapOptions = {
    fallbackFocus: () => document.createElement("div"),
    ...extendedFocusTrapOptions,
  };

  function handleEscKey(event) {
    if (event.key === "Escape") {
      event.stopPropagation();

      onClose();
    }
  }
github acl-services / paprika / packages / FormElement / src / FormElement.js View on Github external
function FormElement(props) {
  const {
    children,
    hasOptionalLabel,
    hasRequiredLabel,
    id,
    isDisabled,
    isInline,
    isLabelVisuallyHidden,
    isReadOnly,
    label,
    size,
    ...moreProps
  } = props;

  const extractedChildren = extractChildren(children, [
    "FormElement.Description",
    "FormElement.Error",
    "FormElement.Help",
    "FormElement.Instructions",
  ]);
  const ariaDescriptionId = React.useRef(uuidv4()).current;
  const ariaErrorId = React.useRef(uuidv4()).current;
  const ariaInstructionsId = React.useRef(uuidv4()).current;
  const hasError = !!extractedChildren["FormElement.Error"] && !!extractedChildren["FormElement.Error"].props.children;
  const uniqueInputId = React.useRef(uuidv4()).current;
  const inputId = isNil(id) || id === "" ? uniqueInputId : id;
  const refLabel = React.useRef(null);

  function renderFooter() {
    if (hasError) {
      return (
github acl-services / paprika / packages / Modal / src / Modal.js View on Github external
const Modal = props => {
  const { isOpen, onClose, onAfterClose, onAfterOpen, size, a11yText, ...moreProps } = props;

  const {
    "Modal.Overlay": overlayExtracted,
    "Modal.Header": headerExtracted,
    "Modal.Content": contentExtracted,
    "Modal.Footer": footerExtracted,
    children,
  } = extractChildren(moreProps.children, ["Modal.Overlay", "Modal.Header", "Modal.Content", "Modal.Footer"]);

  const { extractedFocusLockOptions, ...overlayProps } = overlayExtracted ? overlayExtracted.props : {};

  const focusLockOptions = {
    as: styled.FocusLock,
    lockProps: { size },
    ...(extractedFocusLockOptions || {}),
  };

  const ariaLabel = a11yText || (headerExtracted ? headerExtracted.props.children : null);

  return (