Forms
v0.0.10
mix mishka.ui.gen.component form_wrapper
The form components are the fields a form is built from: text, email, password, number, telephone, URL, search and textarea fields, date and time, color, file upload, a native select and a combobox, checkboxes, radio buttons, toggles, range sliders and fieldsets, plus the form wrapper on this page, which holds them with one shared look. Each of them has a page of its own:
- Checkbox Card ComponentStateless Checkbox cards for Phoenix LiveView forms: icon, title and description per card, grid columns, five variants, an optional checkbox and form error display.
- Checkbox field ComponentStateless Phoenix LiveView checkbox_field and group_checkbox with color themes, sizes, reverse layout and errors, plus checkbox_check to read checked state from params.
- Color field ComponentStateless Phoenix LiveView color picker field built on the native color input, with label, description and errors. Takes a hex value; the circle prop rounds the swatch.
- Combobox ComponentStatelessJS Phoenix LiveView combobox that filters options as you type, with multiple selection, grouped options, keyboard navigation and a scroll area for long lists.
- Date time field ComponentStateless Phoenix LiveView date and time input on the browser's native picker. Types are date, datetime-local, time, week and month, with floating labels and errors.
- Email field ComponentStateless Phoenix LiveView email input using type email. The multiple attribute takes several addresses; floating labels, six variants and icons in start and end slots.
- Fieldset ComponentStateless Phoenix LiveView fieldset groups related controls under an optional legend via the native fieldset element, which helps screen readers. Color and variant props.
- File field ComponentStateless Phoenix LiveView file upload input with an optional drag and drop dropzone: progress bars in file mode, thumbnails in image mode, multiple files and errors.
- Input field ComponentStateless Phoenix LiveView input for text, email, number, date and other types, plus select, textarea and checkbox. Kept for backward compatibility; use dedicated fields.
- Native select ComponentStateless Phoenix LiveView native select, a styled wrapper around the browser's select. Options come from a slot, can be selected or disabled, and multiple is a prop.
- Number field ComponentStateless Phoenix LiveView number input with floating labels, descriptions and errors. The controls prop sets the browser's spinner arrows to default, fixed or hidden.
- Password field ComponentStatelessJS-module Phoenix LiveView password input with a show_password option that toggles the text visible, plus floating labels, start and end slots, color themes and errors.
- Radio Card ComponentStateless Radio cards for picking one option from a grid, each with icon, title and description. Five variants and Phoenix LiveView form field integration.
- Radio field ComponentStateless Radio buttons for Phoenix forms with color themes, sizes, a checked state and a reverse layout, plus a group_radio component for sets of related options.
- Range field ComponentStateless Phoenix LiveView range slider with color themes, sizes, and min, max and step values. Range value slots place start, middle and end labels such as prices.
- Search field ComponentStateless Phoenix LiveView search field with an optional search_button, floating labels, a description, and start and end slots. Renders the browser's search input type.
- Telephone Field ComponentStateless Phoenix LiveView telephone input on type tel, with pattern and inputmode for phone formats. Put a country code select or an icon in the start slot.
- Text field ComponentStateless Phoenix LiveView single-line text input with inner or outer floating labels, six variants, five sizes, descriptions, errors, and start and end content slots.
- Textarea field ComponentStateless Phoenix LiveView textarea with floating labels, sizes, a rows prop and error messages. Set disable_resize to lock the size; start and end slots add content.
- Toggle field ComponentStateless Phoenix LiveView toggle switch with color themes, sizes from extra_small to extra_large, a rounded prop for the corner radius, and form field errors.
- URL Field ComponentStateless Phoenix LiveView URL input using type url so browsers check the address format. Includes floating labels, descriptions, error messages and start and end slots.
Overview of the Phoenix and LiveView Form Component
The Mishka Chelekom form component is a Phoenix LiveView component that allows developers to create consistent and customizable forms using various input types, including text, number, email, telephone, and textarea fields. Each of these input types shares the same design and style, ensuring a unified and polished look across the form.
Overview of the Phoenix and LiveView Form Component
This Phoenix LiveView form component supports uniform styling for all form elements, including input fields, floating labels, and validation messages, providing a seamless user experience. Its responsive and flexible design makes it easy to apply across different input types while maintaining a consistent and professional appearance.
Base Variant
Base Variant
<.text_field label="Text field" placeholder="Mishka chelekom input" />
<.email_field label="Email field" placeholder="Mishka chelekom input" />Outline Variant
The outline style of the Mishka Chelekom forms features a border. Using a single setting, you can choose from various color variants to suit your design needs.
Outline Variant
<.text_field variant="outline" color="silver" />
<.text_field variant="outline" color="natural" />
<.text_field variant="outline" color="primary" />
<.text_field variant="outline" color="secondary" />
<.text_field variant="outline" color="success" />
<.text_field variant="outline" color="warning" />
<.text_field variant="outline" color="danger" />
<.text_field variant="outline" color="info" />
<.text_field variant="outline" color="misc" />
<.text_field variant="outline" color="dawn" />Default Variant
The default style of the Mishka Chelekom forms applies a solid background and border that change based on user interaction, making it perfect for delivering important notifications. With just a single setting, you can select from a range of color options, ensuring easy customization to match various design styles.
Default Variant
<.text_field variant="default" color="white" />
<.text_field variant="default" color="natural" />
<.email_field variant="default" color="primary" />
<.textarea_field variant="default" color="secondary" />
<.text_field variant="default" color="dark" />
<.text_field variant="default" color="success" />
<.textarea_field variant="default" color="warning" />
<.tel_field variant="default" color="danger" />
<.text_field variant="default" color="info" />
<.text_field variant="default" color="silver" />
<.email_field variant="default" color="misc" />
<.tel_field variant="default" color="dawn" />Shadow Variant
The shadow variant of the Mishka Chelekom forms is similar to the default variant, but it also includes a subtle shadow along with a border and white background in light mode.
Shadow Variant
<.text_field variant="shadow" color="primary" />
<.textarea_field variant="shadow" color="secondary" />
<.text_field variant="shadow" color="natural" />
<.text_field variant="shadow" color="success" />
<.number_field variant="shadow" color="warning" />
<.text_field variant="shadow" color="danger" />
<.email_field variant="shadow" color="info" />
<.tel_field variant="shadow" color="silver" />
<.text_field variant="shadow" color="misc" />
<.text_field variant="shadow" color="dawn" />bordered Variant
The Bordered variant of the Mishka Chelekom form has lighter background and a border. Bordered variant have also white and dark colors which are the same colors in the dark and light mode.
bordered Variant
<.text_field variant="bordered" color="white" />
<.text_field variant="bordered" color="primary" />
<.textarea_field variant="bordered" color="secondary" />
<.tel_field variant="bordered" color="dark" />
<.text_field variant="bordered" color="success" />
<.email_field variant="bordered" color="warning" />
<.text_field variant="bordered" color="danger" />
<.text_field variant="bordered" color="info" />
<.text_field variant="bordered" color="silver" />
<.number_field variant="bordered" color="misc" />
<.text_field variant="bordered" color="dawn" />Transparent Variant
The transparent variant of the Mishka Chelekom forms is similar to the default variant, but without border and background color.
Transparent Variant
<.text_field variant="transparent" color="primary" />
<.email_field variant="transparent" color="secondary" />
<.text_field variant="transparent" color="natural" />
<.text_field variant="transparent" color="success" />
<.text_field variant="transparent" color="warning" />
<.number_field variant="transparent" color="danger" />
<.text_field variant="transparent" color="info" />
<.number_field variant="transparent" color="silver" />
<.tel_field variant="transparent" color="misc" />
<.textarea_field variant="transparent" color="dawn" />Rounded prop in Phoenix LiveView form Component
The rounded prop offers values like extra_small, small, medium, large, and extra_large. These values control the border radius of the form fields, allowing for different levels of rounding from subtle to more pronounced corners, depending on the design needs.
Rounded prop in Phoenix LiveView form Component
<.text_field rounded="extra_small" />
<.text_field rounded="small" />
<.email_field rounded="medium" />
<.text_field rounded="large" />
<.url_field rounded="extra_large" />
<.number_field rounded="full" />Border prop
The border prop offers values like extra_small, small, medium, large, and extra_large.
Border prop
<.text_field border="extra_small" />
<.email_field border="small" />
<.text_field border="medium" />
<.number_field border="large" />
<.text_field border="extra_large" />Size prop
The size prop offers values such as extra_small, small, medium, large, and extra_large. These values control both the icon size and input height size within the forms.
Size prop
<.url_field size="extra_small" />
<.text_field size="small" />
<.email_field size="medium" />
<.email_field size="large" />
<.tel_field size="extra_large" />Space prop
The space prop offers values such as extra_small, small, medium, large, and extra_large. These values control the vertical spacing between elements within the form labelas and descriptions and input.
Space prop
<.text_field space="extra_small" />
<.text_field space="small" />
<.text_field space="medium" />
<.text_field space="large" />
<.text_field space="extra_large" />Ring prop
The ring attribute is a boolean option, with a default value of true, that controls whether a ring border is applied to an input field when it is focused. This attribute allows you to add a visually distinct outline around focused form fields using utilities like box-shadows to create the ring effect. When set to true, the outline is applied automatically upon focus, improving user interaction and focus.
Ring prop
<.text_field ring />Floating prop
The floating attribute is a string that determines the floating label behavior for an input field, with options for none, inner, and outer. By default, no floating label is applied (none), but if set to inner, the label appears inside the input wrapper and transitions upward when focused or filled. The outer option places the label on the border of the input, creating a transparent floating effect around the field. These options allow for flexible label positioning, enhancing the user's interaction with form fields.
Floating prop
<.text_field floating="none" />
<.text_field floating="inner" />
<.text_field floating="outer" />Error icon prop
The error_icon attribute is a string that specifies an icon to be displayed alongside error messages in a form field. By default, this attribute is set to nil, meaning no icon is shown unless specified. You can choose any icon from the Hero Icons library to enhance the visual feedback when an error occurs, helping users quickly identify and address form issues. This customization adds an extra layer of clarity and improves user experience by associating an icon with error states.
Error icon prop
<!--you can use any hero-icons icon -->
<.text_field error_icon="hero-shield-exclamation" />Label prop
The label prop is a string that defines the text displayed as the label for an input field.
Label prop
<.text_field label="field_label" />Description prop
The description prop is a string that provides a small, helpful text displayed below the label. This description offers additional context or guidance for users about the input field, clarifying its purpose or instructions on what to enter.
Description prop
<.text_field description="field_description" />
<.number_field description="field_description" />
<.url_field description="field_description" />
<.email_field description="field_description" />
<.textarea_field description="field_description" />Name prop
The name prop represents the name attribute for an input field, serving as a key identifier when submitting form data. It links the input value to a specific field name in the form, allowing the backend or processing scripts to correctly handle the submitted information. The name prop is essential for form submissions, ensuring that data entered by the user is captured and processed accurately. Each input field should have a unique name to avoid conflicts and ensure the proper handling of form data.
Name prop
<.text_field name="field_name" />
<.email_field name="field_name" />
<.number_field name="field_name" />Value prop
The value attribute represents the data or content associated with the input field. It is flexible, accepting any type of value, such as strings, numbers, or other data types. The value attribute is essential for both capturing user input and pre-populating form fields with existing data. It allows the input to hold and display a specific value, ensuring that the input's state can be managed dynamically or passed along during form submissions.
Value prop
<.text_field value="field_value" />
<.text_field value="" />Errors prop
The errors attribute is a list that holds error messages related to an input field. By default, it is an empty list, but when validation fails or other issues arise, you can populate this list with relevant error messages. These messages will be displayed to inform users of any issues with their input, providing clear feedback on how to correct the problem. The errors attribute enhances the form's user experience by ensuring that users receive immediate, understandable error notifications, helping them to complete the form accurately.
Errors prop
<.text_field errors={["Invalid email"]} />start and end section slots
The errors attribute is a list that holds error messages related to an input field. By default, it is an empty list, but when validation fails or other issues arise, you can populate this list with relevant error messages. These messages will be displayed to inform users of any issues with their input, providing clear feedback on how to correct the problem. The errors attribute enhances the form's user experience by ensuring that users receive immediate, understandable error notifications, helping them to complete the form accurately.
start and end section slots
<.tel_field>
<:start_section>
+31
</:start_section>
</.tel_field>
<.tel_field>
<:start_section>
<.icon name="hero-user" class="your_classes" />
</:start_section>
</.tel_field>
<.email_field>
<:start_section>
<.icon name="hero-envelope" class="your_classes" />
</:start_section>
</.email_field>Form wrapper component
The form_wrapper component in Phoenix LiveView is used to wrap form elements and manage form data. It has two key attributes that enhance its functionality. The for attribute is optional and represents the data structure that the form will bind to, allowing the form to be populated with existing data or updated dynamically. The as attribute allows you to group all form inputs under a specific server-side parameter, making it easier to handle the form data on submission. These attributes provide flexibility in how form data is structured and managed in LiveView applications.
Form wrapper component
<.form_wrapper for={@form}>
<div class="grid lg:grid-cols-2 gap-2">
<.text_field
name="name1"
value=""
space="small"
color="silver"
label="Name"
placeholder="Enter your name"
/>
<.text_field
name="name1"
value=""
space="small"
color="silver"
label="Family"
placeholder="Enter your family"
/>
<.email_field
name="name1"
value=""
space="small"
color="silver"
label="Email"
placeholder="Enter your email"
/>
</div>
</.form_wrapper>Attributes
| Name | Type | Default | Values | Required | Description |
|---|---|---|---|---|---|
id
|
string
| — | — | No | A unique identifier is used to manage state and interaction |
class
|
any
| — | — | No | Custom CSS class for additional styling |
color
|
string
|
natural
|
naturalwhitedarkprimarysecondarysuccesswarningdangerinfomiscdawnsilver
| No | Determines color theme |
variant
|
string
|
base
|
defaultoutlineborderedshadowtransparentbase
| No | Determines the style |
border
|
string
|
extra_small
| — | No | Determines border style |
rounded
|
string
| — |
extra_smallsmallmediumlargeextra_largefullnone
| No | Determines the border radius |
padding
|
string
| — |
extra_smallsmallmediumlargeextra_large
| No | Determines padding for items |
space
|
string
| — |
extra_smallsmallmediumlargeextra_large
| No | Space between items |
form_wrapper_class
|
string
| — | — | No | Custom classes form wrapper |
action_wrapper_class
|
string
| — | — | No | Custom classes action wrapper |
size
|
string
| — |
extra_smallsmallmediumlargeextra_large
| No | Determines the overall size of the elements, including padding, font size, and other items |
for
|
any
| — | — | No | the data structure for the form |
as
|
any
| — | — | No | the server side parameter to collect all input under |
rest
|
global
| — | — | No | Global attributes can define defaults which are merged with attributes provided by the caller |
Slots
| Name | Required | Description |
|---|---|---|
inner_block
| Yes | Inner block that renders HEEx content |
actions
| No | the slot for form actions, such as a submit button |
Options
Each option takes one or more of its values, separated by commas.
| Option | Values |
|---|---|
--variant
|
defaultoutlineborderedshadowtransparentbase
|
--color
|
naturalwhitedarkprimarysecondarysuccesswarningdangerinfomiscdawnsilver
|
--size
|
extra_smallsmallmediumlargeextra_large
|
--space
|
extra_smallsmallmediumlargeextra_large
|
--rounded
|
extra_smallsmallmediumlargeextra_largefullnone
|
--padding
|
extra_smallsmallmediumlargeextra_large
|
--module
| A module name of your own |
What it generates
mix mishka.ui.gen.component form_wrapper