7.8 KiB
7.8 KiB
Button
Styled button with full DaisyUI support and reactive states.
Tag
Button
Props
| Prop | Type | Default | Description |
|---|---|---|---|
class |
string |
'' |
Additional CSS classes (DaisyUI + Tailwind) |
disabled |
boolean | Signal<boolean> |
false |
Disabled state |
loading |
boolean | Signal<boolean> |
false |
Shows loading spinner |
badge |
string | Signal<string> |
- |
Badge text displayed on corner |
badgeClass |
string |
'badge-secondary' |
Badge styling classes |
tooltip |
string | Signal<string> |
- |
Tooltip text on hover |
icon |
string | VNode | Signal |
- |
Icon displayed before text |
onclick |
function |
- |
Click event handler |
type |
string |
'button' |
Native button type |
Live Examples
Basic Button
Live Demo
const BasicDemo = () => {
return Button({ class: "btn btn-primary" }, "Click Me");
};
$mount(BasicDemo, "#demo-basic");
With Loading State
Live Demo
const LoadingDemo = () => {
const isSaving = $(false);
return Button(
{
class: "btn btn-success",
loading: isSaving,
onclick: async () => {
isSaving(true);
await new Promise((resolve) => setTimeout(resolve, 2000));
isSaving(false);
},
},
"Save Changes",
);
};
$mount(LoadingDemo, "#demo-loading");
With Badge
Live Demo
const BadgeDemo = () => {
return Button(
{
class: "btn btn-outline",
badge: "3",
badgeClass: "badge-accent",
},
"Notifications",
);
};
$mount(BadgeDemo, "#demo-badge");
With Tooltip
Live Demo
const TooltipDemo = () => {
return Button(
{
class: "btn btn-ghost",
tooltip: "Delete item",
},
"Delete",
);
};
$mount(TooltipDemo, "#demo-tooltip");
Disabled State
Live Demo
const DisabledDemo = () => {
const isDisabled = $(true);
return Button(
{
class: "btn btn-primary",
disabled: isDisabled,
},
"Submit",
);
};
$mount(DisabledDemo, "#demo-disabled");
All Variants
Live Demo
const VariantsDemo = () => {
return Div({ class: "flex flex-wrap gap-2 justify-center" }, [
Button({ class: "btn btn-primary" }, "Primary"),
Button({ class: "btn btn-secondary" }, "Secondary"),
Button({ class: "btn btn-accent" }, "Accent"),
Button({ class: "btn btn-ghost" }, "Ghost"),
Button({ class: "btn btn-outline" }, "Outline"),
]);
};
$mount(VariantsDemo, "#demo-variants");