Checkbox field
v0.0.10
v0.0.10StableComponentStatelessApache-2.0
Installation
mix mishka.ui.gen.component checkbox_field
Source
View Source
Checkbox component
Checkbox component
heex
<.checkbox_field color="base" />
<.checkbox_field color="white" />
<.checkbox_field color="primary" />
<.checkbox_field color="secondary" />
<.checkbox_field color="dark" />
<.checkbox_field color="success" />
<.checkbox_field color="warning" />
<.checkbox_field color="danger" />
<.checkbox_field color="info" />
<.checkbox_field color="light" />
<.checkbox_field color="misc" />
<.checkbox_field color="dawn" />Checkbox label class prop
Add your custom classes to checkbox labels
Checkbox label class prop
heex
<.checkbox_field label_class="your_classes" />Checkbox reverse prop
Change the order of the checkbox and label.
Checkbox reverse prop
heex
<.checkbox_field reverse />
<.checkbox_field />Checkbox checked prop
This prop sets the checkbox to checked (true).
Checkbox checked prop
heex
<.checkbox_field checked />Checkbox multiple prop
Checkbox multiple prop
heex
<.checkbox_field multiple />Checkbox Group component prop
Checkbox Group component prop
heex
<.group_checkbox id="" variation="horizontal" name="" space="large" color="danger">
<:checkbox value="10">Label of item 1 in group</:checkbox>
<:checkbox value="30">Label of item 2 in group</:checkbox>
<:checkbox value="50">Label of item 3 in group</:checkbox>
<:checkbox value="60" checked={true}>Label of item 4 in group</:checkbox>
</.group_checkbox>
<!--Default is vertical variation-->
<.group_checkbox id="" name="" space="large" color="info">
<:checkbox value="10">Label of item 1 in group</:checkbox>
<:checkbox value="30">Label of item 2 in group</:checkbox>
<:checkbox value="50">Label of item 3 in group</:checkbox>
<:checkbox value="60" checked={true}>Label of item 4 in group</:checkbox>
</.group_checkbox>checkbox_check helper
Here is a real-world example provided for you.
checkbox_check helper
heex
<.form_wrapper
for={@form}
id="user-form"
phx-change="validate"
phx-submit="save"
class="space-y-5"
>
<.input label="Full name" field={@form[:fullname]} />
<.input
field={@form[:job]}
type="select"
label="Choose your Job"
options={Ecto.Enum.values(User, :job)}
/>
<.h3>What is your hobbies?</.h3>
<.group_checkbox variation="horizontal" field={@form[:hobbies]} color="danger">
<:checkbox
value="reading"
checked={checkbox_check(:list, {:hobbies, "reading"}, @form)}
>
Reading
</:checkbox>
<:checkbox
value="programming"
checked={checkbox_check(:list, {:hobbies, "programming"}, @form)}
>
Programming
</:checkbox>
<:checkbox
value="photography"
checked={checkbox_check(:list, {:hobbies, "photography"}, @form)}
>
Photography
</:checkbox>
</.group_checkbox>
<hr />
<.toggle_field
field={@form[:accepted_terms]}
label="Terms"
checked={toggle_check(:accepted_terms, @form)}
color="primary"
phx-debounce="300"
/>
<:actions>
<.button phx-disable-with="Saving...">Save User</.button>
</:actions>
</.form_wrapper>Attributes
| Name | Type | Default | Values | Required | Description |
|---|---|---|---|---|---|
id
|
any
| — | — | No | A unique identifier is used to manage state and interaction |
class
|
any
| — | — | No | Custom CSS class for additional styling |
color
|
string
|
primary
|
basenaturalwhiteprimarysecondarydarksuccesswarningdangerinfosilvermiscdawn
| No | Determines color theme |
border
|
string
|
extra_small
| — | No | Determines border style |
rounded
|
string
|
small
|
extra_smallsmallmediumlargeextra_largefullnone
| No | Determines the border radius |
space
|
string
|
medium
|
extra_smallsmallmediumlargeextra_large
| No | Space between items |
label_class
|
string
|
block
| — | No | Custom CSS class for the label styling |
wrapper_class
|
string
| — | — | No | Custom CSS class for the wrapper |
checkbox_class
|
string
| — | — | No | Custom CSS class for the wrapper |
size
|
string
|
extra_large
|
extra_smallsmallmediumlargeextra_large
| No | Determines the overall size of the elements, including padding, font size, and other items |
ring
|
boolean
|
true
| — | No | Determines a ring border on focused input, utilities for creating outline rings with box-shadows. |
reverse
|
boolean
|
false
| — | No | Switches the order of the element and label |
checked
|
boolean
|
false
| — | No | Specifies if the element is checked by default |
error_icon
|
string
| — | — | No | Icon to be displayed alongside error messages |
label
|
string
| — | — | No | Specifies text for the label |
multiple
|
boolean
|
false
| — | No | the multiple flag for select inputs |
errors
|
list
|
[]
| — | No | List of error messages to be displayed |
name
|
any
| — | — | No | Name of input |
value
|
any
| — | — | No | Value of input |
field
|
Phoenix.HTML.FormField
| — | — | No | a form field struct retrieved from the form |
rest
|
global
| — | — | No | Global attributes can define defaults which are merged with attributes provided by the caller |
Options
Each option takes one or more of its values, separated by commas.
| Option | Values |
|---|---|
--color
|
basenaturalwhiteprimarysecondarydarksuccesswarningdangerinfosilvermiscdawn
|
--size
|
extra_smallsmallmediumlargeextra_large
|
--rounded
|
extra_smallsmallmediumlargeextra_largefullnone
|
--space
|
extra_smallsmallmediumlargeextra_large
|
--type
|
checkbox_fieldgroup_checkbox
|
--module
| A module name of your own |
What it generates
Functions
checkbox_fieldgroup_checkbox
Helpers
checkbox_check/3
Generated with it
icon
Command
mix mishka.ui.gen.component checkbox_field