import React, {forwardRef} from 'react'; import {ActionIcon, ActionIconProps, Button as MButton, ButtonProps as MButtonProps} from '@mantine/core'; import {Icon} from './Icon'; /* * Buttons. * * Roles carry meaning (Semantic UI heritage): blue = primary/download, * green = save/confirm, red = destructive, amber = retry/warning, neutral * outline = cancel. Prefer `role` over naming a color, so a theme that remaps * a color keeps the meaning. */ export type ButtonRole = 'primary' | 'save' | 'retry' | 'danger' | 'cancel'; const roleProps: Record = { primary: {color: 'blue', variant: 'filled'}, save: {color: 'green', variant: 'filled'}, retry: {color: 'yellow', variant: 'filled'}, // Danger resolves differently per theme (filled in light/dark, dashed outline in // night). The branching lives in ui.css, never in a call site. danger: {color: 'red', variant: 'filled', className: 'wrolpi-button-danger'}, cancel: {variant: 'default'}, }; export interface ButtonProps extends Omit { role?: ButtonRole; /** Semantic icon name or a Tabler component, rendered before the label. */ icon?: string | React.ComponentType; iconAfter?: string | React.ComponentType; onClick?: React.MouseEventHandler; type?: 'button' | 'submit' | 'reset'; href?: string; target?: string; } const renderIcon = (icon?: string | React.ComponentType) => { if (!icon) return undefined; return typeof icon === 'string' ? : ; } export const Button = forwardRef(( {role, icon, iconAfter, className, ...props}, ref ) => { const fromRole = role ? roleProps[role] : undefined; return }); Button.displayName = 'Button'; export interface IconButtonProps extends Omit { role?: ButtonRole; icon: string | React.ComponentType; /** Required: an icon-only button has no visible name. */ label: string; onClick?: React.MouseEventHandler; type?: 'button' | 'submit' | 'reset'; } /** A square, icon-only button. */ export const IconButton = forwardRef(( {role, icon, label, className, ...props}, ref ) => { const fromRole = role ? roleProps[role] : undefined; return {renderIcon(icon)} }); IconButton.displayName = 'IconButton'; export {ButtonGroup} from '@mantine/core';