import * as React from 'react'; import { Button, tailwind } from '@tesseract-design/web-base'; const { tw } = tailwind; const ActionButtonDerivedElementComponent = 'button' as const; /** * Derived HTML element of the {@link ActionButton} component. */ export type ActionButtonDerivedElement = HTMLElementTagNameMap[ typeof ActionButtonDerivedElementComponent ]; /** * Props of the {@link ActionButton} component. */ export interface ActionButtonProps extends Omit, 'type' | 'size'> { /** * Type of the component. */ type?: Button.Type; /** * Variant of the component. */ variant?: Button.Variant; /** * Should the component occupy the whole width of its parent? */ block?: boolean; /** * Complementary content of the component. */ subtext?: React.ReactNode; /** * Short complementary content displayed at the edge of the component. */ badge?: React.ReactNode; /** * Is this component part of a menu? */ menuItem?: boolean; /** * Size of the component. */ size?: Button.Size; /** * Should the component's content use minimal space? */ compact?: boolean; /** * Graphical representation of the component. */ icon?: React.ReactNode; /** * Should the graphical representation of the component be placed after the children? */ iconAfterChildren?: boolean; } /** * Component for performing an action upon activation (e.g. when clicked). * * This component functions as a regular button. */ export const ActionButton = React.forwardRef(( { type = 'button' as const, variant = 'bare' as const, subtext, badge, menuItem = false as const, children, size = 'medium' as const, compact = false as const, className, block = false as const, icon, iconAfterChildren = false as const, ...etcProps }, forwardedRef, ) => ( {icon && ( {icon} )} {(children || subtext) && ( {children && ( {children} )} {subtext && ( <> {' - '} {subtext} )} )} {badge && ( <> {' - '} {badge} )} {menuItem && ( )} )); ActionButton.displayName = 'ActionButton' as const; ActionButton.defaultProps = { type: 'button' as const, variant: 'bare' as const, block: false as const, subtext: undefined, badge: undefined, menuItem: false as const, size: 'medium' as const, compact: false as const, icon: undefined, iconAfterChildren: false as const, };