How to use the reakit-utils/useSealedState.useSealedState function in reakit-utils

To help you get started, we’ve selected a few reakit-utils 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 reakit / reakit / packages / reakit / src / Hidden / HiddenState.ts View on Github external
export function useHiddenState(
  initialState: SealedInitialState = {}
): HiddenStateReturn {
  const {
    unstable_animated: animated = false,
    visible: sealedVisible = false,
    unstable_isMounted: initialIsMounted = false,
    ...sealed
  } = useSealedState(initialState);

  const id = unstable_useIdState(sealed);

  const [visible, setVisible] = React.useState(sealedVisible);
  const [animating, setAnimating] = React.useState(false);
  const [isMounted, setIsMounted] = React.useState(initialIsMounted);
  const lastVisible = useLastValue(visible);

  if (
    animated &&
    !animating &&
    lastVisible.current != null &&
    lastVisible.current !== visible
  ) {
    // Sets animating to true when when visible changes
    setAnimating(true);
github reakit / reakit / packages / reakit / src / Id / IdState.ts View on Github external
export function unstable_useIdState(
  initialState: SealedInitialState = {}
): unstable_IdStateReturn {
  const { baseId: initialBaseId } = useSealedState(initialState);
  const generateId = React.useContext(unstable_IdContext);
  const idCountRef = React.useRef(0);
  const [baseId, setBaseId] = React.useState(
    () => initialBaseId || generateId()
  );

  return {
    baseId,
    unstable_setBaseId: setBaseId,
    unstable_idCountRef: idCountRef
  };
}
github reakit / reakit / packages / reakit / src / Tooltip / TooltipState.ts View on Github external
export function useTooltipState(
  initialState: SealedInitialState = {}
): TooltipStateReturn {
  const {
    placement = "top",
    unstable_boundariesElement = "window",
    ...sealed
  } = useSealedState(initialState);
  return usePopoverState({ ...sealed, placement, unstable_boundariesElement });
}
github reakit / reakit / packages / reakit / src / Checkbox / CheckboxState.ts View on Github external
export function useCheckboxState(
  initialState: SealedInitialState = {}
): CheckboxStateReturn {
  const { state: initialValue = false } = useSealedState(initialState);
  const [state, setState] = React.useState(initialValue);
  return {
    state,
    setState
  };
}
github reakit / reakit / packages / reakit / src / Tab / TabState.ts View on Github external
export function useTabState(
  initialState: SealedInitialState = {}
): TabStateReturn {
  const {
    selectedId: sealedSelectedId = null,
    loop = true,
    manual = false,
    ...sealed
  } = useSealedState(initialState);

  const [selectedId, select] = React.useState(sealedSelectedId);
  const rover = useRoverState({
    loop,
    currentId: selectedId,
    ...sealed
  });

  return {
    ...rover,
    selectedId,
    manual,
    select
  };
}
github reakit / reakit / packages / reakit / src / Toolbar / ToolbarState.ts View on Github external
export function useToolbarState(
  initialState: SealedInitialState = {}
): ToolbarStateReturn {
  const { orientation = "horizontal", ...sealed } = useSealedState(
    initialState
  );
  return useRoverState({ orientation, ...sealed });
}
github reakit / reakit / packages / reakit / src / Menu / MenuBarState.ts View on Github external
export function useMenuBarState(
  initialState: SealedInitialState = {}
): MenuBarStateReturn {
  const {
    orientation = "horizontal",
    unstable_values: initialValues = {},
    ...sealed
  } = useSealedState(initialState);

  const [values, setValues] = React.useState(initialValues);
  const rover = useRoverState({ ...sealed, orientation });

  return {
    ...rover,
    unstable_values: values,
    unstable_setValue: React.useCallback((name, value) => {
      setValues(vals => ({
        ...vals,
        [name]: typeof value === "function" ? value(vals) : value
      }));
    }, [])
  };
}
github reakit / reakit / packages / reakit / src / Menu / MenuState.ts View on Github external
export function useMenuState(
  initialState: SealedInitialState = {}
): MenuStateReturn {
  const {
    orientation = "vertical",
    unstable_gutter: initialGutter = 0,
    ...sealed
  } = useSealedState(initialState);

  const parent = React.useContext(MenuContext);

  const placement =
    sealed.placement ||
    (parent && parent.orientation === "vertical"
      ? "right-start"
      : "bottom-start");

  const menuBar = useMenuBarState({ ...sealed, orientation });
  const popover = usePopoverState({
    ...sealed,
    placement,
    unstable_gutter: initialGutter
  });
github reakit / reakit / packages / reakit / src / Popover / PopoverState.ts View on Github external
export function usePopoverState(
  initialState: SealedInitialState = {}
): PopoverStateReturn {
  const {
    gutter = 12,
    placement: sealedPlacement = "bottom",
    unstable_flip: flip = true,
    unstable_shift: shift = true,
    unstable_inner: inner = false,
    unstable_preventOverflow: preventOverflow = true,
    unstable_boundariesElement: boundariesElement = "scrollParent",
    unstable_fixed: fixed = false,
    ...sealed
  } = useSealedState(initialState);

  const popper = React.useRef(null);
  const referenceRef = React.useRef(null);
  const popoverRef = React.useRef(null);
  const arrowRef = React.useRef(null);

  const [originalPlacement, place] = React.useState(sealedPlacement);
  const [placement, setPlacement] = React.useState(sealedPlacement);
  const [popoverStyles, setPopoverStyles] = React.useState(
    {}
  );
  const [arrowStyles, setArrowStyles] = React.useState({});

  const dialog = useDialogState(sealed);

  const scheduleUpdate = React.useCallback(() => {
github reakit / reakit / packages / reakit / src / Radio / RadioState.ts View on Github external
export function useRadioState(
  initialState: SealedInitialState = {}
): RadioStateReturn {
  const { state: initialCurrentValue, loop = true, ...sealed } = useSealedState(
    initialState
  );

  const [state, setState] = React.useState(initialCurrentValue);

  const rover = useRoverState({ ...sealed, loop });

  return {
    ...rover,
    state,
    setState
  };
}