UNPKG

@front-ui/button

Version:

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

65 lines (62 loc) 1.7 kB
"use client"; // src/button.tsx import { forwardRef, useRef } from "react"; import { button } from "@front-ui/theme"; import { useRipple } from "@front-ui/use-ripple"; import { mergeRefs, mergeEvents } from "@front-ui/react-utils"; import { useButton, useFocusRing } from "react-aria"; import { jsx, jsxs } from "react/jsx-runtime"; var Button = forwardRef((props, ref) => { const { startContent, endContent, rippleProps, className, color, fullWidth, isDisabled, rounded, size, variant, isIconOnly } = props; const { base, focusVisible } = button({ className, color, fullWidth, isDisabled, rounded, size, variant, isIconOnly }); const innerRef = useRef(null); const [rippleRef, rippleEvent] = useRipple(rippleProps); const { buttonProps } = useButton(props, innerRef); const { focusProps, isFocusVisible, isFocused } = useFocusRing(); return /* @__PURE__ */ jsxs( "button", { ...buttonProps, ref: mergeRefs(ref, rippleRef, innerRef), ...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__ */ jsx("span", { "data-visible": isFocusVisible && isFocused, className: focusVisible() }) ] } ); }); Button.displayName = "front-ui.Button"; var button_default = Button; export { button_default };