How to use reakit-system - 10 common examples

To help you get started, we’ve selected a few reakit-system 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-playground / src / PlaygroundPreview.tsx View on Github external
export function PlaygroundPreview({
  code,
  modules,
  update,
  componentName,
  ...htmlProps
}: PlaygroundPreviewOptions & PlaygroundPreviewHTMLProps) {
  const options = useOptions(
    "PlaygroundPreview",
    { code, modules, componentName },
    htmlProps
  );

  const ref = React.useRef(null);
  const { id: prefix } = useId({ baseId: "preview" });
  const [error, setError] = React.useState(null);

  const handleError = React.useCallback((e: Error) => {
    setError(e);
    console.error(e); // eslint-disable-line no-console
  }, []);

  const [rendered, setRendered] = React.useState(() => {
    try {
github reakit / reakit / packages / reakit / src / Menu / Menu.tsx View on Github external
usePopover
} from "../Popover/Popover";
import { MenuBarOptions, MenuBarHTMLProps, useMenuBar } from "./MenuBar";
import { useMenuState, MenuStateReturn } from "./MenuState";
import { MenuContext, MenuContextType } from "./__utils/MenuContext";

export type MenuOptions = Omit &
  Pick &
  Pick, "first" | "last"> &
  MenuBarOptions;

export type MenuHTMLProps = PopoverHTMLProps & MenuBarHTMLProps;

export type MenuProps = MenuOptions & MenuHTMLProps;

export const useMenu = createHook({
  name: "Menu",
  compose: [useMenuBar, usePopover],
  useState: useMenuState,

  useOptions(options) {
    const parent = React.useContext(MenuContext);
    const parentIsMenuBar = parent && parent.role === "menubar";

    return {
      unstable_autoFocusOnShow: !parent,
      unstable_autoFocusOnHide: !parentIsMenuBar,
      modal: false,
      ...options,
      // will be handled differently from usePopover/useDialog
      hideOnEsc: false
    };
github reakit / reakit / packages / reakit / src / Tabbable / Tabbable.ts View on Github external
element.tagName === "A" ||
    element.tagName === "AUDIO" ||
    element.tagName === "VIDEO"
  );
}

// https://twitter.com/diegohaz/status/1176998102139572225
function isUserAgent(string: string) {
  if (typeof window === "undefined") return false;
  return window.navigator.userAgent.indexOf(string) !== -1;
}

const isSafariOrFirefoxOnMac =
  isUserAgent("Mac") && (isUserAgent("Safari") || isUserAgent("Firefox"));

export const useTabbable = createHook({
  name: "Tabbable",
  compose: useBox,
  keys: [
    "disabled",
    "focusable",
    "unstable_clickOnEnter",
    "unstable_clickOnSpace"
  ],

  useOptions(
    { unstable_clickOnEnter = true, unstable_clickOnSpace = true, ...options },
    { disabled }
  ) {
    return {
      disabled,
      unstable_clickOnEnter,
github reakit / reakit / packages / reakit / src / Id / Id.tsx View on Github external
import { unstable_IdStateReturn, unstable_useIdState } from "./IdState";
import { unstable_IdContext } from "./IdProvider";

export type unstable_IdOptions = BoxOptions &
  Pick, "baseId" | "unstable_idCountRef"> & {
    /**
     * Same as the HTML attribute.
     */
    id?: string;
  };

export type unstable_IdHTMLProps = BoxHTMLProps;

export type unstable_IdProps = unstable_IdOptions & unstable_IdHTMLProps;

export const unstable_useId = createHook<
  unstable_IdOptions,
  unstable_IdHTMLProps
>({
  name: "Id",
  compose: useBox,
  useState: unstable_useIdState,
  keys: ["id"],

  useOptions(options, htmlProps) {
    const generateId = React.useContext(unstable_IdContext);

    const [suffix] = React.useState(() => {
      // This comes from useIdState
      if (options.unstable_idCountRef) {
        options.unstable_idCountRef.current += 1;
        return `-${options.unstable_idCountRef.current}`;
github reakit / reakit / packages / reakit-playground / src / PlaygroundPreview.tsx View on Github external
return () => clearTimeout(timer);
  }, [
    options.code,
    options.modules,
    options.componentName,
    renderChildren,
    handleError,
    unmount
  ]);

  React.useEffect(() => {
    // Ensure that we unmount the React component when the effect is destroyed.
    return () => unmount();
  }, [unmount]);

  htmlProps = useProps("PlaygroundPreview", options, htmlProps);

  return (
    
      <div>
        {error &amp;&amp; }
        <div>{renderChildren(rendered)}</div>
      </div>
    
  );
}
github reakit / reakit / packages / website / src / components / Anchor.ts View on Github external
useProps(_, htmlProps) {
    const color = usePalette("link");
    const anchor = css`
      color: ${color};
      font-weight: 500;
      text-decoration: none;

      &:hover {
        text-decoration: underline;
      }
    `;
    return { ...htmlProps, className: cx(anchor, htmlProps.className) };
  }
});

const Anchor = createComponent({
  as: "a",
  useHook: useAnchor,

  useCreateElement(type, { href, ...props }, children) {
    if (href && /^\/(?!\/)/.test(href)) {
      return useCreateElement(Link, { to: href, ...props }, children);
    }
    return useCreateElement(type, { href, ...props }, children);
  }
});

export default Anchor;
github reakit / reakit / packages / website / src / components / Anchor.ts View on Github external
useCreateElement(type, { href, ...props }, children) {
    if (href && /^\/(?!\/)/.test(href)) {
      return useCreateElement(Link, { to: href, ...props }, children);
    }
    return useCreateElement(type, { href, ...props }, children);
  }
});
github reakit / reakit / packages / website / src / components / Anchor.ts View on Github external
useCreateElement(type, { href, ...props }, children) {
    if (href && /^\/(?!\/)/.test(href)) {
      return useCreateElement(Link, { to: href, ...props }, children);
    }
    return useCreateElement(type, { href, ...props }, children);
  }
});
github reakit / reakit / packages / reakit / src / Tab / TabList.tsx View on Github external
export const useTabList = createHook({
  name: "TabList",
  compose: unstable_useIdGroup,
  useState: useTabState,

  useProps(options, htmlProps) {
    return {
      role: "tablist",
      "aria-orientation": options.orientation,
      ...htmlProps
    };
  }
});

export const TabList = createComponent({
  as: "div",
  useHook: useTabList,
  useCreateElement: (type, props, children) =&gt; {
    warning(
      !props["aria-label"] &amp;&amp; !props["aria-labelledby"],
      "[reakit/TabList]",
      "You should provide either `aria-label` or `aria-labelledby` props.",
      "See https://reakit.io/docs/tab"
    );
    return useCreateElement(type, props, children);
  }
});
github reakit / reakit / packages / reakit / src / Menu / MenuSeparator.ts View on Github external
MenuSeparatorOptions,
  MenuSeparatorHTMLProps
>({
  name: "MenuSeparator",
  compose: useSeparator,
  useState: useMenuState,

  useOptions({ orientation = "vertical", ...options }) {
    return {
      orientation: orientation === "vertical" ? "horizontal" : "vertical",
      ...options
    };
  }
});

export const MenuSeparator = createComponent({
  as: "hr",
  useHook: useMenuSeparator
});