UNPKG

@arolariu/components

Version:

🎨 70+ beautiful, accessible React components built on Base UI. TypeScript-first, CSS Modules styling, tree-shakeable, SSR-ready. Perfect for modern web apps, design systems & rapid prototyping. Zero config, maximum flexibility! ⚡

79 lines (78 loc) • 2.99 kB
"use client"; import { mergeProps } from "@base-ui/react/merge-props"; import { useRender } from "@base-ui/react/use-render"; import { cn } from "../../lib/utilities.js"; import button_module from "./button.module.js"; import * as __rspack_external_react from "react"; const variantStyles = { default: button_module["default"], destructive: button_module.destructive, outline: button_module.outline, secondary: button_module.secondary, ghost: button_module.ghost, link: button_module.link }; const sizeStyles = { default: button_module.sizeDefault, sm: button_module.sizeSm, lg: button_module.sizeLg, icon: button_module.sizeIcon }; function buttonVariants({ variant = "default", size = "default", className } = {}) { return cn(button_module.button, variantStyles[variant], sizeStyles[size], className); } function isIntrinsicButtonElement(renderProp) { return /*#__PURE__*/ __rspack_external_react.isValidElement(renderProp) && "string" == typeof renderProp.type && "button" === renderProp.type; } function createNonNativeInteractionProps(disabled) { return { "aria-disabled": disabled || void 0, role: "button", tabIndex: disabled ? -1 : void 0, onClick (event) { if (!disabled) return; event.preventDefault(); if ("preventBaseUIHandler" in event && "function" == typeof event.preventBaseUIHandler) event.preventBaseUIHandler(); }, onKeyDown (event) { if (!disabled || "Enter" !== event.key && " " !== event.key) return; event.preventDefault(); if ("preventBaseUIHandler" in event && "function" == typeof event.preventBaseUIHandler) event.preventBaseUIHandler(); } }; } const Button = /*#__PURE__*/ __rspack_external_react.forwardRef((props, ref)=>{ const { render, asChild = false, variant = "default", size = "default", disabled = false, className, children, ...otherProps } = props; const state = { variant, size, disabled }; const composedClassName = buttonVariants({ variant, size, className }); const renderProp = asChild && /*#__PURE__*/ __rspack_external_react.isValidElement(children) ? children : render; const shouldRenderNativeButton = !renderProp || isIntrinsicButtonElement(renderProp); const typeProps = shouldRenderNativeButton ? { type: "button" } : {}; const interactionProps = shouldRenderNativeButton ? { disabled } : createNonNativeInteractionProps(disabled); return useRender({ defaultTagName: "button", ref, render: renderProp, state, props: mergeProps({ className: composedClassName }, typeProps, otherProps, interactionProps, { children: renderProp ? void 0 : children }) }); }); Button.displayName = "Button"; export { Button, buttonVariants }; //# sourceMappingURL=button.js.map