Files
ServerKit/frontend/src/components/IconButton.jsx
T
Juan Denis 7c8519772f Add accessible form controls and field wiring
FormField now hands its control the id, aria-describedby, aria-invalid
and aria-required through context, so every settings form announces
its hint and validation without per-call wiring. IconButton gets a real
tooltip instead of title=, ProgressBar is a labelled progressbar with
tones and an indeterminate state, and Button takes `loading` without
changing width.

New controls the panel lacked: NumberField, Combobox (single, multiple,
creatable), TagInput, Calendar with DatePicker and DateRangePicker,
PinInput, Slider, RadioGroup, Stepper, TreeView, and FileDropzone with
FileUploadList. Rounding, date and file-type rules live in lib/ with
unit tests. All of them render on /style-guide/controls.
2026-10-25 23:18:24 -04:00

44 lines
1.1 KiB
React

import { Button } from '@/components/ui/button';
import { Tip } from '@/components/ui/tooltip';
import { cn } from '@/lib/utils';
/**
* Accessible icon-only button. Always provide a descriptive label; it is the
* aria-label and the tooltip (a real one, shown on hover and keyboard focus,
* unlike `title`). `title` overrides the tooltip text; `shortcut` adds a key
* hint to it.
*
* <IconButton icon={<RefreshCw size={16} />} label="Refresh" onClick={load} />
*/
export function IconButton({
icon,
label,
onClick,
variant = 'ghost',
size = 'sm',
className,
title,
shortcut,
disabled,
...props
}) {
return (
<Tip content={title || label} shortcut={shortcut}>
<Button
type="button"
variant={variant}
size="icon"
className={cn('icon-button', size === 'sm' && 'btn-sm', className)}
onClick={onClick}
disabled={disabled}
aria-label={label}
{...props}
>
{icon}
</Button>
</Tip>
);
}
export default IconButton;