UNPKG

@alice-ui/react

Version:
59 lines (56 loc) 1.65 kB
import { _Spinner } from "./chunk-IGHU64CH.mjs"; // src/button/button.tsx import { button } from "@alice-ui/theme"; import { cloneElement, forwardRef, isValidElement, useMemo } from "react"; import { Button as AriaButton } from "react-aria-components"; import { Fragment, jsx, jsxs } from "react/jsx-runtime"; function Button(props, ref) { const { variant, color, size = "md", radius, fullWidth, isLoading, spinner = /* @__PURE__ */ jsx(_Spinner, { color: "current", size: "sm", ...props.spinnerProps }), spinnerPlacement = "start", startContent: startContentProp, endContent: endContentProp, disableAnimation, className, children, ...otherProps } = props; const styles = useMemo( () => button({ size, color, variant, radius, fullWidth, disableAnimation, className }), [className, color, disableAnimation, fullWidth, radius, size, variant] ); const getIconClone = (icon) => isValidElement(icon) ? cloneElement(icon, { "aria-hidden": true, focusable: false, tabIndex: -1 }) : null; const startContent = getIconClone(startContentProp); const endContent = getIconClone(endContentProp); return /* @__PURE__ */ jsxs(AriaButton, { ref, className: styles, ...otherProps, children: [ startContent, isLoading && spinnerPlacement === "start" && /* @__PURE__ */ jsx("div", { className: "shrink-0", children: spinner }), /* @__PURE__ */ jsx(Fragment, { children }), isLoading && spinnerPlacement === "end" && spinner, endContent ] }); } var _Button = forwardRef(Button); export { _Button };