UNPKG

@front-ui/button

Version:

A button allows a user to perform an action, with mouse, touch, and keyboard interactions.

84 lines (82 loc) 2.82 kB
"use client"; "use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/button.tsx var button_exports = {}; __export(button_exports, { default: () => button_default }); module.exports = __toCommonJS(button_exports); var import_react = require("react"); var import_theme = require("@front-ui/theme"); var import_use_ripple = require("@front-ui/use-ripple"); var import_react_utils = require("@front-ui/react-utils"); var import_react_aria = require("react-aria"); var import_jsx_runtime = require("react/jsx-runtime"); var Button = (0, import_react.forwardRef)((props, ref) => { const { startContent, endContent, rippleProps, className, color, fullWidth, isDisabled, rounded, size, variant, isIconOnly } = props; const { base, focusVisible } = (0, import_theme.button)({ className, color, fullWidth, isDisabled, rounded, size, variant, isIconOnly }); const innerRef = (0, import_react.useRef)(null); const [rippleRef, rippleEvent] = (0, import_use_ripple.useRipple)(rippleProps); const { buttonProps } = (0, import_react_aria.useButton)(props, innerRef); const { focusProps, isFocusVisible, isFocused } = (0, import_react_aria.useFocusRing)(); return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( "button", { ...buttonProps, ref: (0, import_react_utils.mergeRefs)(ref, rippleRef, innerRef), ...(0, import_react_utils.mergeEvents)( { onPointerDown: rippleEvent }, { onPointerDown: buttonProps.onPointerDown }, { onFocus: focusProps.onFocus, onBlur: focusProps.onBlur }, { onFocus: buttonProps.onFocus, onBlur: buttonProps.onBlur } ), className: base(), children: [ !isIconOnly ? startContent : null, props.children, !isIconOnly ? endContent : null, /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { "data-visible": isFocusVisible && isFocused, className: focusVisible() }) ] } ); }); Button.displayName = "front-ui.Button"; var button_default = Button;