UNPKG

@cerberus-design/react

Version:

The Cerberus Design React component library.

36 lines (34 loc) 1.08 kB
import { Spinner } from "./chunk-QUOJS5LL.js"; import { ButtonRoot } from "./chunk-YZG7BNVB.js"; import { Show } from "./chunk-NUXMADXV.js"; // src/components/button/button.tsx import { createContext, useContext, useMemo } from "react"; import { Box } from "styled-system/jsx"; import { Fragment, jsx } from "react/jsx-runtime"; var ButtonContext = createContext({ pending: false }); function Button(props) { const { pending = false, ...nativeProps } = props; const value = useMemo(() => ({ pending }), [pending]); return /* @__PURE__ */ jsx(ButtonContext.Provider, { value, children: /* @__PURE__ */ jsx(ButtonRoot, { ...nativeProps, disabled: pending || nativeProps.disabled }) }); } function ButtonIcon(props) { const { pending } = useContext(ButtonContext); return /* @__PURE__ */ jsx(Show, { when: pending, fallback: /* @__PURE__ */ jsx(Fragment, { children: props.children }), children: /* @__PURE__ */ jsx(Box, { w: "4", children: /* @__PURE__ */ jsx(Spinner, {}) }) }); } export { Button, ButtonIcon }; //# sourceMappingURL=chunk-JIEN2PM7.js.map