Form elements allow you to create flexible and beautiful Form layout. Form elements are just well known List View (List and List Item React components) but with few additional components.
There are following components included:
ListInput
- list item input elementName | Type | Default | Description |
---|---|---|---|
accept | string | number | Value of input's native "accept" attribute | |
autoCapitalize | string | Value of input's native "autocapitalize" attribute | |
autoComplete | string | Value of input's native "autoComplete" attribute | |
autoCorrect | string | Value of input's native "autocorrect" attribute | |
autoFocus | boolean | Value of input's native "autofocus" attribute | |
autoSave | string | Value of input's native "autosave" attribute | |
clearButton | boolean | false | Adds input clear button |
colors | object | Object with Tailwind CSS colors classes | |
colors.bgIos | string | '' | |
colors.bgMaterial | string | 'bg-md-light-surface-variant dark:bg-md-dark-surface-variant' | |
colors.errorBorder | string | 'border-red-500' | |
colors.errorText | string | 'text-red-500' | |
colors.labelTextFocusIos | string | '' | |
colors.labelTextFocusMaterial | string | 'text-md-light-primary dark:text-md-dark-primary' | |
colors.labelTextIos | string | '' | |
colors.labelTextMaterial | string | 'text-md-light-on-surface-variant dark:text-md-dark-on-surface-variant' | |
colors.outlineBorderFocusIos | string | 'border-primary' | |
colors.outlineBorderFocusMaterial | string | 'border-md-light-primary dark:border-md-dark-primary' | |
colors.outlineBorderIos | string | 'border-black border-opacity-30 dark:border-white dark:border-opacity-30' | |
colors.outlineBorderMaterial | string | 'border-md-light-on-surface dark:border-md-dark-on-surface' | |
colors.outlineLabelBgIos | string | 'bg-ios-light-surface-1 dark:bg-ios-dark-surface-1' | |
colors.outlineLabelBgMaterial | string | 'bg-md-light-surface dark:bg-md-dark-surface' | |
component | string | 'li' | Component's HTML Element |
defaultValue | any | Input value, in case of uncontrolled component | |
disabled | boolean | Marks input as disabled | |
dropdown | boolean | false | Renders additional dropdown icon (useful to use with |
error | ReactNode | Content of the input "error" | |
floatingLabel | boolean | false | Makes floating label |
info | ReactNode | Content of the input "info" | |
input | ReactNode | Custom input element | |
inputClassName | string | Additional input styles | |
inputId | string | Input id attribute | |
inputMode | string | Value of input's native "inputmode" attribute | |
inputStyle | CSSProperties | Additional input classes | |
label | ReactNode | Label content | |
max | string | number | Value of input's native "max" attribute | |
maxLength | string | number | Value of input's native "maxlength" attribute | |
media | ReactNode | Content of the list item "media" area (e.g. icon) | |
min | string | number | Value of input's native "min" attribute | |
minLength | string | number | Value of input's native "minlength" attribute | |
multiple | boolean | Value of input's native "multiple" attribute | |
name | string | Input name | |
outline | boolean | undefined | Renders outline-style input (with border around), overwrites |
outlineIos | boolean | false | Renders outline-style input (with border around) in iOS theme |
outlineMaterial | boolean | false | Renders outline-style input (with border around) in Material theme |
pattern | string | Value of input's native "pattern" attribute | |
placeholder | string | number | Input placeholder | |
readOnly | boolean | Marks input as readonly | |
required | boolean | Marks input as required | |
size | string | number | Value of input's native "size" attribute | |
spellCheck | string | Value of input's native "spellcheck" attribute | |
step | string | number | Value of input's native "step" attribute | |
tabIndex | string | number | Value of input's native "tabindex" attribute | |
type | string | 'text' | Input type |
value | any | Input value | |
onBlur | function(e) |
| |
onChange | function(e) |
| |
onClear | function(e) |
| |
onFocus | function(e) |
| |
onInput | function(e) |
|
import React, { useState } from 'react';import {Page,Navbar,NavbarBackLink,BlockTitle,List,ListInput,} from 'konsta/react';import DemoIcon from '../components/DemoIcon';export default function FormInputsPage() {const [name, setName] = useState({ value: '', changed: false });const [demoValue, setDemoValue] = useState('');const onNameChange = (e) => {setName({ value: e.target.value, changed: true });};const onDemoValueChange = (e) => {setDemoValue(e.target.value);};const onDemoValueClear = () => {setDemoValue('');};return (<Page><Navbartitle="Form Inputs"/><BlockTitle>Default</BlockTitle><List strongIos insetIos><ListInputlabel="Name"type="text"placeholder="Your name"media={<DemoIcon />}/><ListInputlabel="Password"type="password"placeholder="Your password"media={<DemoIcon />}/><ListInputlabel="E-mail"type="email"placeholder="Your e-mail"media={<DemoIcon />}/><ListInputlabel="URL"type="url"placeholder="URL"media={<DemoIcon />}/><ListInputlabel="Phone"type="tel"placeholder="Your phone number"media={<DemoIcon />}/><ListInputlabel="Gender"type="select"dropdowndefaultValue="Male"placeholder="Please choose..."media={<DemoIcon />}><option value="Male">Male</option><option value="Female">Female</option></ListInput><ListInputlabel="Birthday"type="date"defaultValue="2014-04-30"placeholder="Please choose..."media={<DemoIcon />}/><ListInputlabel="Date time"type="datetime-local"placeholder="Please choose..."media={<DemoIcon />}/><ListInputlabel="Textarea"type="textarea"placeholder="Bio"media={<DemoIcon />}inputClassName="!h-20 resize-none"/></List><BlockTitle>Outline</BlockTitle><List strongIos insetIos><ListInputoutlinelabel="Name"type="text"placeholder="Your name"media={<DemoIcon />}/><ListInputoutlinelabel="Password"type="password"placeholder="Your password"media={<DemoIcon />}/><ListInputoutlinelabel="E-mail"type="email"placeholder="Your e-mail"media={<DemoIcon />}/><ListInputoutlinelabel="URL"type="url"placeholder="URL"media={<DemoIcon />}/><ListInputoutlinelabel="Phone"type="tel"placeholder="Your phone number"media={<DemoIcon />}/><ListInputoutlinelabel="Gender"type="select"dropdowndefaultValue="Male"placeholder="Please choose..."media={<DemoIcon />}><option value="Male">Male</option><option value="Female">Female</option></ListInput><ListInputoutlinelabel="Birthday"type="date"defaultValue="2014-04-30"placeholder="Please choose..."media={<DemoIcon />}/><ListInputoutlinelabel="Date time"type="datetime-local"placeholder="Please choose..."media={<DemoIcon />}/><ListInputoutlinelabel="Textarea"type="textarea"placeholder="Bio"media={<DemoIcon />}inputClassName="!h-20 resize-none"/></List><BlockTitle>Floating Labels</BlockTitle><List strongIos insetIos><ListInputlabel="Name"floatingLabeltype="text"placeholder="Your name"media={<DemoIcon />}/><ListInputlabel="Password"floatingLabeltype="password"placeholder="Your password"media={<DemoIcon />}/><ListInputlabel="E-mail"floatingLabeltype="email"placeholder="Your e-mail"media={<DemoIcon />}/><ListInputlabel="URL"floatingLabeltype="url"placeholder="URL"media={<DemoIcon />}/><ListInputlabel="Phone"floatingLabeltype="tel"placeholder="Your phone number"media={<DemoIcon />}/></List><BlockTitle>Outline + Floating Labels</BlockTitle><List strongIos insetIos><ListInputoutlinelabel="Name"floatingLabeltype="text"placeholder="Your name"media={<DemoIcon />}/><ListInputoutlinelabel="Password"floatingLabeltype="password"placeholder="Your password"media={<DemoIcon />}/><ListInputoutlinelabel="E-mail"floatingLabeltype="email"placeholder="Your e-mail"media={<DemoIcon />}/><ListInputoutlinelabel="URL"floatingLabeltype="url"placeholder="URL"media={<DemoIcon />}/><ListInputoutlinelabel="Phone"floatingLabeltype="tel"placeholder="Your phone number"media={<DemoIcon />}/></List><BlockTitle>Validation + Additional Info</BlockTitle><List strongIos insetIos><ListInputlabel="Name"type="text"placeholder="Your name"info="Basic string checking"value={name.value}error={name.changed && !name.value.trim() ? 'Please specify your name' : ''}media={<DemoIcon />}onChange={onNameChange}/></List><BlockTitle>Clear Button</BlockTitle><List strongIos insetIos><ListInputlabel="TV Show"type="text"placeholder="Your favorite TV show"info="Type something to see clear button"value={demoValue}clearButton={demoValue.length > 0}media={<DemoIcon />}onChange={onDemoValueChange}onClear={onDemoValueClear}/></List><BlockTitle>Icon + Input</BlockTitle><List strongIos insetIos><ListInput type="text" placeholder="Your name" media={<DemoIcon />} /><ListInputtype="password"placeholder="Your password"media={<DemoIcon />}/><ListInputtype="email"placeholder="Your e-mail"media={<DemoIcon />}/><ListInput type="url" placeholder="URL" media={<DemoIcon />} /></List><BlockTitle>Label + Input</BlockTitle><List strongIos insetIos><ListInput label="Name" type="text" placeholder="Your name" /><ListInputlabel="Password"type="password"placeholder="Your password"/><ListInput label="E-mail" type="email" placeholder="Your e-mail" /><ListInput label="URL" type="url" placeholder="URL" /></List><BlockTitle>Only Inputs</BlockTitle><List strongIos insetIos><ListInput type="text" placeholder="Your name" /><ListInput type="password" placeholder="Your password" /><ListInput type="email" placeholder="Your e-mail" /><ListInput type="url" placeholder="URL" /></List><BlockTitle>Inputs + Additional Info</BlockTitle><List strongIos insetIos><ListInputtype="text"placeholder="Your name"info="Full name please"/><ListInputtype="password"placeholder="Your password"info="8 characters minimum"/><ListInputtype="email"placeholder="Your e-mail"info="Your work e-mail address"/><ListInput type="url" placeholder="URL" info="Your website URL" /></List></Page>);}