Get notified about new features and updates.
package showcase
import (
"github.com/templui/templui/components/card"
"github.com/templui/templui/components/checkbox"
"github.com/templui/templui/components/label"
)
templ CheckboxDefault() {
<div class="flex flex-col gap-6">
<!-- Basic checkbox with label -->
<div class="flex items-center gap-3">
@checkbox.Checkbox(checkbox.Props{
ID: "terms",
Name: "agreements",
Value: "terms",
})
@label.Label(label.Props{
For: "terms",
}) {
Accept terms and conditions
}
</div>
<!-- Checkbox with description -->
<div class="flex items-start gap-3">
@checkbox.Checkbox(checkbox.Props{
ID: "newsletter",
Name: "agreements",
Value: "newsletter",
Checked: true,
})
<div class="grid gap-2">
@label.Label(label.Props{
For: "newsletter",
}) {
Subscribe to newsletter
}
<p class="text-muted-foreground text-sm">
Get notified about new features and updates.
</p>
</div>
</div>
<!-- Disabled checkbox -->
<div class="flex items-center gap-3">
@checkbox.Checkbox(checkbox.Props{
ID: "cookies",
Name: "agreements",
Value: "cookies",
Disabled: true,
})
@label.Label(label.Props{
For: "cookies",
}) {
Use essential cookies only
}
</div>
<!-- Checkbox in a card container -->
@label.Label(label.Props{
For: "premium",
Class: "block cursor-pointer",
}) {
@card.Card(card.Props{
Class: "hover:border-primary/50 has-[:checked]:ring-1 has-[:checked]:ring-primary has-[:checked]:border-primary transition-all",
}) {
@card.Content(card.ContentProps{
Class: "p-3 flex items-start gap-3",
}) {
@checkbox.Checkbox(checkbox.Props{
ID: "premium",
Name: "agreements",
Value: "premium",
})
<div class="grid gap-1.5">
<p class="text-sm leading-none font-medium">
Enable premium features
</p>
<p class="text-muted-foreground text-sm">
Unlock advanced functionality and priority support.
</p>
</div>
}
}
}
</div>
}
Installation
templui add labelLoad the script once in your layout:
<head>
@label.Script()
</head>import "github.com/templui/templui/components/label"Load the script once in your layout:
<head>
@label.Script()
</head>Usage
The Label component enhances the following form controls:
API Reference
Required parameter
Hover for description
Label
Accessible label component for associating text with form controls.
| Name | Type | Default |
|---|---|---|
Unique identifier for the label element. | | - |
Additional CSS classes to apply to the label. | | - |
Additional HTML attributes to apply to the label element. | | - |
ID of the form control this label is associated with (for attribute). | | - |
Error message that changes the label styling to indicate validation errors. | | - |