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

What is your hobbies?

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>