Qwik checkbox - Flowbite
The checkbox component can be used to receive one or more selected options from the user in the form of a square box available in multiple styles, sizes, colors, and variants.
To use the range component, you need to import it from flowbite-qwik :
import { Checkbox } from "flowbite-qwik"
Checkbox example
Use this default example of a checkbox element in a checked and unchecked state.
import { component$, useSignal } from '@builder.io/qwik'
import { Checkbox } from 'flowbite-qwik'
export default component$(() => {
const val = useSignal(false)
return (
<>
<div class="p-3">
<Checkbox bind:checked={val}>Checkbox</Checkbox>
</div>
</>
)
})
Disabled state
This example can be used for the disabled state of the checkbox component by applying the disabled attribute to the input element.
import { component$, useSignal } from '@builder.io/qwik'
import { Checkbox } from 'flowbite-qwik'
export default component$(() => {
const val = useSignal(false)
return (
<>
<div class="p-3">
<Checkbox bind:checked={val} disabled>
Disable
</Checkbox>
</div>
</>
)
})
Checked state
This example can be used for the checked state of the checkbox component.
import { component$, useSignal } from '@builder.io/qwik'
import { Checkbox } from 'flowbite-qwik'
export default component$(() => {
const val = useSignal(true)
return (
<>
<div class="p-3">
<Checkbox bind:checked={val}>Checked</Checkbox>
</div>
</>
)
})
With link
Use this example if you want to add an anchor link inside the label of the checkbox component.
import { component$, useSignal } from '@builder.io/qwik'
import { Checkbox } from 'flowbite-qwik'
export default component$(() => {
const val = useSignal(false)
return (
<>
<div class="p-3">
<Checkbox bind:checked={val}>
<a href="#" class="text-blue-500 underline">
I agree with terms and conditions.
</a>
</Checkbox>
</div>
</>
)
})
On change event
This example can be used for the onchange event of the checkbox component.
import { component$, useSignal } from '@builder.io/qwik'
import { Checkbox } from 'flowbite-qwik'
export default component$(() => {
const val = useSignal(false)
return (
<>
<div class="p-3">
<Checkbox
bind:checked={val}
onChange$={(val: boolean) => {
alert(`Checkbox state changed to ${val}`)
}}
>
Change state
</Checkbox>
</div>
</>
)
})
Colors
This example can be used for the color of the checkbox component by applying the color attribute to the input element.
import { component$, useSignal } from '@builder.io/qwik'
import { Checkbox, FlowbiteTheme } from 'flowbite-qwik'
export default component$(() => {
const val = useSignal(true)
return (
<>
<div class="flex gap-3 p-3">
{(['blue', 'green', 'red', 'pink', 'purple'] as FlowbiteTheme[]).map((color) => (
<Checkbox bind:checked={val} color={color}>
{color}
</Checkbox>
))}
</div>
</>
)
})