@base-ui-components/react
Version:
Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.
39 lines (38 loc) • 1.1 kB
JavaScript
'use client';
import * as React from 'react';
import { useButton } from "../use-button/useButton.js";
import { useRenderElement } from "../utils/useRenderElement.js";
/**
* A button component that can be used to trigger actions.
* Renders a `<button>` element.
*
* Documentation: [Base UI Button](https://base-ui.com/react/components/button)
*/
export const Button = /*#__PURE__*/React.forwardRef(function Button(componentProps, forwardedRef) {
const {
render,
className,
disabled: disabledProp = false,
focusableWhenDisabled = false,
nativeButton = true,
...elementProps
} = componentProps;
const disabled = Boolean(disabledProp);
const {
getButtonProps,
buttonRef
} = useButton({
disabled,
focusableWhenDisabled,
native: nativeButton
});
const state = React.useMemo(() => ({
disabled
}), [disabled]);
return useRenderElement('button', componentProps, {
state,
ref: [forwardedRef, buttonRef],
props: [elementProps, getButtonProps]
});
});
if (process.env.NODE_ENV !== "production") Button.displayName = "Button";