Buttons
Button and link components
The project provides Button and ButtonLink components with built-in support for icons, loading states, and internationalization.
Basic Usage
import { Button, ButtonLink } from "@/components/ui/button";
<Button onClick={handleClick}>
Click Me
</Button>
<ButtonLink href="/about">
About Us
</ButtonLink>Button Variants
| Variant | Use Case |
|---|---|
default | Standard actions |
destructive | Delete or dangerous actions |
outline | Secondary actions |
secondary | Alternative styling |
ghost | Subtle actions, toolbar buttons |
link | Text-style links |
<Button variant="default">Save</Button>
<Button variant="destructive">Delete</Button>
<Button variant="outline">Cancel</Button>
<Button variant="ghost">Skip</Button>With Icons
Use the icon prop to add an icon from the icon registry:
<Button icon="save" variant="primary">
Save Changes
</Button>
<Button icon="trash" variant="destructive">
Delete
</Button>
<Button icon="download" variant="outline">
Export
</Button>The icon is automatically positioned before the text content.
Loading State
Set loading={true} to show a spinner and disable the button:
<Button
loading={isDeleting}
variant="destructive"
icon="trash"
>
Delete
</Button>When loading, the button:
- Shows a spinner icon
- Becomes disabled
- Maintains its dimensions
Internationalized Button Text
Use i18nButtonKey to automatically load translated button text:
<Button
i18nButtonKey="save"
icon="save"
onClick={handleSave}
/>
<Button
i18nButtonKey="delete"
icon="trash"
variant="destructive"
/>This loads text from messages/dictionaries/{locale}/buttons.json:
{
"save": "Save Changes",
"delete": "Delete",
"cancel": "Cancel"
}When using i18nButtonKey, you don't need to provide children content—the text is loaded automatically.
ButtonLink
For navigation, use ButtonLink with the same API:
import { PageAbout } from "@/routes";
<ButtonLink href={PageAbout()}>
About Us
</ButtonLink>
<ButtonLink
href={PageDashboard()}
variant="primary"
icon="arrowRight"
>
Go to Dashboard
</ButtonLink>Combined Example
<Button
variant="primary"
icon="save"
i18nButtonKey="save"
loading={isSaving}
onClick={handleSave}
/>This button will:
- Show "Save Changes" text (from translations)
- Display a save icon (when not loading)
- Show spinner when
isSavingis true - Call
handleSaveon click
Best Practices
- Use i18nButtonKey - Prefer
i18nButtonKeyover hardcoded text for consistency - Add icons for clarity - Icons help users understand button actions quickly
- Use appropriate variants - Match the variant to the action severity (destructive for delete, etc.)
- Handle loading states - Always show loading state during async operations