UNPKG

@cerberus-design/react

Version:

The Cerberus Design React component library.

35 lines (30 loc) 1.33 kB
'use strict'; Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const jsxRuntime = require('react/jsx-runtime'); const React = require('react'); const jsx = require('styled-system/jsx'); const show = require('../show/show.cjs'); const spinner = require('../spinner/spinner.cjs'); const primitives = require('./primitives.cjs'); const ButtonContext = React.createContext({ pending: false }); function Button(props) { const { pending = false, ...nativeProps } = props; const value = React.useMemo(() => ({ pending }), [pending]); return /* @__PURE__ */ jsxRuntime.jsx(ButtonContext.Provider, { value, children: /* @__PURE__ */ jsxRuntime.jsx( primitives.ButtonRoot, { ...nativeProps, "data-scope": "button", "data-part": "root", disabled: pending || props.disabled } ) }); } function ButtonIcon(props) { const { pending } = React.useContext(ButtonContext); return /* @__PURE__ */ jsxRuntime.jsx(show.Show, { when: pending, fallback: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: props.children }), children: /* @__PURE__ */ jsxRuntime.jsx(jsx.Box, { "data-scope": "button", "data-part": "button-spinner", w: "4", children: /* @__PURE__ */ jsxRuntime.jsx(spinner.Spinner, {}) }) }); } exports.Button = Button; exports.ButtonIcon = ButtonIcon;