Checkbox Card
Selectable card component that combines a checkbox with rich content for option selection.
TailwindCSS
package showcase
import "github.com/axzilla/templui/components"
import "github.com/axzilla/templui/icons"
templ CheckboxCardDefault() {
<div class="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
@components.CheckboxCard(components.CheckboxCardProps{
ID: "feature-analytics",
},
) {
@components.CheckboxCardHeader() {
<div class="flex items-center gap-2">
<div class="text-primary">
@icons.ChartBar(icons.IconProps{Size: 20})
</div>
<h3>Analytics</h3>
</div>
}
@components.CheckboxCardDescription() {
Real-time data analytics and reporting tools
}
@components.CheckboxCardFooter() {
@radioCardPriceFooter("$5/month")
}
}
@components.CheckboxCard(components.CheckboxCardProps{
ID: "feature-storage",
},
) {
@components.CheckboxCardHeader() {
<div class="flex items-center gap-2">
<div class="text-primary">
@icons.Cloud(icons.IconProps{Size: 20})
</div>
<h3>Cloud Storage</h3>
</div>
}
@components.CheckboxCardDescription() {
Secure file storage with 100GB capacity
}
@components.CheckboxCardFooter() {
@radioCardPriceFooter("$3/month")
}
}
@components.CheckboxCard(components.CheckboxCardProps{
ID: "feature-api",
Disabled: true,
}) {
@components.CheckboxCardHeader() {
<div class="flex items-center gap-2">
<div class="text-primary">
@icons.Code(icons.IconProps{Size: 20})
</div>
<h3>API Access</h3>
</div>
}
@components.CheckboxCardDescription() {
Full access to our developer API endpoints
}
@components.CheckboxCardFooter() {
@radioCardPriceFooter("$8/month")
}
}
</div>
}
package components
import "github.com/axzilla/templui/utils"
type CheckboxCardProps struct {
ID string
Class string
Attributes templ.Attributes
Checked bool
Disabled bool
Required bool
Name string
Value string
}
type CheckboxCardHeaderProps struct {
ID string
Class string
Attributes templ.Attributes
}
type CheckboxCardDescriptionProps struct {
ID string
Class string
Attributes templ.Attributes
}
type CheckboxCardFooterProps struct {
ID string
Class string
Attributes templ.Attributes
}
templ CheckboxCard(props ...CheckboxCardProps) {
{{ var p CheckboxCardProps }}
if len(props) > 0 {
{{ p = props[0] }}
}
if p.ID == "" {
{{ p.ID = utils.RandomID() }}
}
{{ inputId := p.ID + "-input" }}
<div
if p.ID != "" {
id={ p.ID }
}
class={
utils.TwMerge(
"relative",
utils.If(p.Disabled, "opacity-60"),
p.Class,
),
}
{ p.Attributes... }
>
<input
type="checkbox"
id={ inputId }
if p.Name != "" {
name={ p.Name }
}
if p.Value != "" {
value={ p.Value }
}
checked?={ p.Checked }
disabled?={ p.Disabled }
required?={ p.Required }
class="peer sr-only"
/>
<label
for={ inputId }
class={
utils.TwMerge(
"block w-full rounded-lg border overflow-hidden h-full",
"bg-card text-card-foreground p-4 flex flex-col",
"cursor-pointer",
"hover:border-primary/50",
"peer-checked:ring-1 peer-checked:ring-primary peer-checked:border-primary",
utils.If(p.Disabled, "cursor-not-allowed"),
"transition-all duration-200",
p.Class,
),
}
>
{ children... }
</label>
</div>
}
templ CheckboxCardHeader(props ...CheckboxCardHeaderProps) {
{{ var p CheckboxCardHeaderProps }}
if len(props) > 0 {
{{ p = props[0] }}
}
<div
if p.ID != "" {
id={ p.ID }
}
class={
utils.TwMerge(
"flex items-center justify-between mb-2",
p.Class,
),
}
{ p.Attributes... }
>
{ children... }
</div>
}
templ CheckboxCardDescription(props ...CheckboxCardDescriptionProps) {
{{ var p CheckboxCardDescriptionProps }}
if len(props) > 0 {
{{ p = props[0] }}
}
<p
if p.ID != "" {
id={ p.ID }
}
class={
utils.TwMerge(
"text-sm text-muted-foreground",
p.Class,
),
}
{ p.Attributes... }
>
{ children... }
</p>
}
templ CheckboxCardFooter(props ...CheckboxCardFooterProps) {
{{ var p CheckboxCardFooterProps }}
if len(props) > 0 {
{{ p = props[0] }}
}
<div
if p.ID != "" {
id={ p.ID }
}
class={
utils.TwMerge(
"mt-auto pt-4 w-full",
p.Class,
),
}
{ p.Attributes... }
>
{ children... }
</div>
}
Usage
@components.CheckboxCard(components.CheckboxCardProps{...})