aravint-ui-button
v1.0.15
Published
A reusable, accessible Button component with support for variants, icons, loading states, and tooltip-enabled icon buttons.
Readme
@digitus-fci-oa/button
A reusable, accessible Button component with support for variants, icons, loading states, and tooltip-enabled icon buttons.
Refer to this URL for npm:
https://github.com/digitus-git/AFCI_OffAuto/tree/develop_rel_phase1/packages
Installation
npm install @digitus-fci-oa/buttonUsage
import { Button } from '@digitus-fci-oa/button';
import { Save, Trash2, X, Pencil } from 'lucide-react';
export function TestButton() {
return (
<div style={{ display: "flex", gap: "10px", padding: "20px" }}>
<Button variant="save" leftIcon={<Save size={14} />} loading={saveLoading}>
Save
</Button>
<Button variant="update" rightIcon={<Save size={14} />}>
Update
</Button>
<Button variant="delete" leftIcon={<Trash2 size={14} />}>
Delete
</Button>
<Button variant="cancel" leftIcon={<X size={14} />}>
Cancel
</Button>
{/* Icon-only button with tooltip */}
<Button
variant="update"
size="icon"
iconButton
tooltipLabel="Edit record"
>
<Pencil size={16} />
</Button>
</div>
);
}export default function Example() { const [open, setOpen] = useState(false);
const handleExport = async ( type: "xlsx" | "csv" | "pdf" ) => { console.log(type); };
return ( <ExportButton open={open} setOpen={setOpen} onExport={handleExportClick} buttonClassName=" flex items-center gap-[2px] bg-[hsla(161,94%,30%,1)] h-[30px] px-3 rounded-[8px] text-white text-xs font-medium " buttonIcon={ <> Export </> } items={{ xlsx: { label: "XLSX", icon: , iconClassName: "text-green-600", textClassName: "text-green-600", iconWidth: "w-5", iconHeight: "h-5", },
csv: {
label: "CSV",
icon: <FileText />,
iconClassName: "text-blue-600",
textClassName: "text-blue-600",
iconWidth: "w-5",
iconHeight: "h-5",
},
pdf: {
label: "PDF",
icon: <FileText />,
iconClassName: "text-red-600",
textClassName: "text-red-600",
iconWidth: "w-5",
iconHeight: "h-5",
},
}}
/>); }
---
---
## Props
| Prop | Type | Default | Description |
|----------------|-------------------|-------------|-----------------------------------------------------------------------------|
| `variant` | `string` | `"default"` | Button style: `save`, `update`, `delete`, `cancel` |
| `size` | `string` | `"default"` | Button size: `default`, `sm`, `lg`, `icon`, `xs` |
| `loading` | `boolean` | `false` | Shows a loading spinner and disables the button |
| `leftIcon` | `React.ReactNode` | `undefined` | Icon displayed to the left of the label |
| `rightIcon` | `React.ReactNode` | `undefined` | Icon displayed to the right of the label |
| `iconButton` | `boolean` | `false` | Wraps the button in a tooltip provider (use with `tooltipLabel`) |
| `tooltipLabel` | `string` | `undefined` | Tooltip text shown on hover when `iconButton` is `true` |
| `onClick` | `() => void` | `undefined` | Click handler |
| `children` | `React.ReactNode` | — | Button label text or icon content |
| `disabled` | `boolean` | `false` | Disables the button |
| `className` | `string` | `undefined` | Additional CSS classes (Tailwind supported) |
| `style` | `CSSProperties` | `undefined` | Inline styles (merged on top of variant styles) |
| `open` | `boolean` | |Controls dropdown visibility |
| `setOpen` | `Dispatch<SetStateAction<boolean>>` | Updates dropdown state |
| `onExport` | `(type) => void` | Export callback |
| `buttonLabel` | `string` | | Button label |
| `buttonIcon` | `ReactNode` | | Optional button icon |
| `items` | `Record` | | Export menu items |
| `className` | `string` | | Additional classes |
---
## Variants
| Variant | Color | Description |
|-----------|------------------|----------------------------------|
| `default` | Blue (`#3B82F6`) | General-purpose action |
| `save` | Navy (`#003B71`) | Primary save / create action |
| `update` | Navy (`#003B71`) | Edit / update action |
| `delete` | Red (`#FF6070`) | Destructive / remove action |
| `cancel` | White / bordered | Dismiss / abort action |
---
## Sizes
| Size | Height | Description |
|-----------|--------|------------------------------------|
| `default` | 40px | Standard button |
| `sm` | 36px | Compact button |
| `lg` | 44px | Large button |
| `icon` | 40×40px| Square icon-only button |
| `xs` | 20px | Extra-small button (e.g. in tables)|
---
## Icon Support
Icons can be placed on the **left** or **right** side of the button label using `leftIcon` and `rightIcon` props. Works with any icon library (e.g. [lucide-react](https://lucide.dev/)).
```tsx
import { Pencil } from 'lucide-react';
<Button variant="update" leftIcon={<Pencil size={14} />}>
Edit
</Button>Loading State
Pass loading={true} to show a spinner and automatically disable the button during async operations.
const [saving, setSaving] = useState(false);
<Button
variant="save"
loading={saving}
onClick={() => setSaving(true)}
leftIcon={<Save size={14} />}
>
Save
</Button>Supported Export Types
- XLSX
- CSV
Features
- Reusable dropdown export button
- TailwindCSS support
- Custom icons
- Controlled open state
- Lightweight and reusable
Icon Button with Tooltip
Set iconButton={true} to wrap the button in a tooltip. Pass tooltipLabel to set the tooltip text. Pair with size="icon" for a square icon-only button.
import { Trash2 } from 'lucide-react';
<Button
variant="delete"
size="icon"
iconButton
tooltipLabel="Delete record"
onClick={handleDelete}
>
<Trash2 size={16} />
</Button>Note:
tooltipLabelonly displays wheniconButtonistrue. IftooltipLabelis omitted whileiconButtonistrue, the tooltip trigger is still rendered but no tooltip content is shown.
License
MIT
