UNPKG

@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.

49 lines (47 loc) 1.36 kB
'use client'; import * as React from 'react'; import { useToastRootContext } from "../root/ToastRootContext.js"; import { useButton } from "../../use-button/useButton.js"; import { useRenderElement } from "../../utils/useRenderElement.js"; /** * Performs an action when clicked. * Renders a `<button>` element. * * Documentation: [Base UI Toast](https://base-ui.com/react/components/toast) */ export const ToastAction = /*#__PURE__*/React.forwardRef(function ToastAction(componentProps, forwardedRef) { const { render, className, disabled, nativeButton = true, ...elementProps } = componentProps; const { toast } = useToastRootContext(); const computedChildren = toast.actionProps?.children ?? elementProps.children; const shouldRender = Boolean(computedChildren); const { getButtonProps, buttonRef } = useButton({ disabled, native: nativeButton }); const state = React.useMemo(() => ({ type: toast.type }), [toast.type]); const element = useRenderElement('button', componentProps, { ref: [forwardedRef, buttonRef], state, props: [elementProps, toast.actionProps, getButtonProps, { children: computedChildren }] }); if (!shouldRender) { return null; } return element; }); if (process.env.NODE_ENV !== "production") ToastAction.displayName = "ToastAction";