フォーム要素を使用すると、柔軟で美しいフォームレイアウトを作成できます。 フォーム要素は、よく知られているリストビュー(リスト および リストアイテム Svelteコンポーネント)ですが、いくつかの追加コンポーネントがあります。
以下のコンポーネントが含まれています
ListInput
- リストアイテム入力要素名前 | タイプ | デフォルト | 説明 |
---|---|---|---|
accept | 文字列 | 数値 | 入力のネイティブ "accept" 属性の値 | |
autocapitalize | 文字列 | 入力のネイティブ "autocapitalize" 属性の値 | |
autocomplete | 文字列 | 入力のネイティブ "autoComplete" 属性の値 | |
autocorrect | 文字列 | 入力のネイティブ "autocorrect" 属性の値 | |
autofocus | ブール値 | 入力のネイティブ "autofocus" 属性の値 | |
autosave | 文字列 | 入力のネイティブ "autosave" 属性の値 | |
clearButton | ブール値 | false | 入力クリアボタンを追加します |
colors | オブジェクト | Tailwind CSS カラー クラスを持つオブジェクト | |
colors.bgIos | 文字列 | '' | |
colors.bgMaterial | 文字列 | 'bg-md-light-surface-variant dark:bg-md-dark-surface-variant' | |
colors.errorBorder | 文字列 | 'border-red-500' | |
colors.errorText | 文字列 | 'text-red-500' | |
colors.labelTextFocusIos | 文字列 | '' | |
colors.labelTextFocusMaterial | 文字列 | 'text-md-light-primary dark:text-md-dark-primary' | |
colors.labelTextIos | 文字列 | '' | |
colors.labelTextMaterial | 文字列 | 'text-md-light-on-surface-variant dark:text-md-dark-on-surface-variant' | |
colors.outlineBorderFocusIos | 文字列 | 'border-primary' | |
colors.outlineBorderFocusMaterial | 文字列 | 'border-md-light-primary dark:border-md-dark-primary' | |
colors.outlineBorderIos | 文字列 | 'border-black border-opacity-30 dark:border-white dark:border-opacity-30' | |
colors.outlineBorderMaterial | 文字列 | 'border-md-light-on-surface dark:border-md-dark-on-surface' | |
colors.outlineLabelBgIos | 文字列 | 'bg-ios-light-surface-1 dark:bg-ios-dark-surface-1' | |
colors.outlineLabelBgMaterial | 文字列 | 'bg-md-light-surface dark:bg-md-dark-surface' | |
component | 文字列 | 'li' | コンポーネントのHTML要素 |
disabled | ブール値 | 入力を無効としてマークします | |
dropdown | ブール値 | false | 追加のドロップダウンアイコンを表示します( |
error | 文字列 | 入力の "error" の内容 | |
floatingLabel | ブール値 | false | フローティングラベルを作成します |
info | 文字列 | 入力の "info" の内容 | |
inputClass | 文字列 | 追加の入力スタイル | |
inputId | 文字列 | 入力ID属性 | |
inputmode | 文字列 | 入力のネイティブ "inputmode" 属性の値 | |
inputStyle | CSSProperties | 追加の入力クラス | |
label | 文字列 | ラベルの内容 | |
max | 文字列 | 数値 | 入力のネイティブ "max" 属性の値 | |
maxlength | 文字列 | 数値 | 入力のネイティブ "maxlength" 属性の値 | |
min | 文字列 | 数値 | 入力のネイティブ "min" 属性の値 | |
minlength | 文字列 | 数値 | 入力のネイティブ "minlength" 属性の値 | |
multiple | ブール値 | 入力のネイティブ "multiple" 属性の値 | |
name | 文字列 | 入力名 | |
outline | ブール値 | 未定義 | アウトラインスタイルの入力(周囲に枠線がある)をレンダリングし、 |
outlineIos | ブール値 | false | iOSテーマでアウトラインスタイルの入力(周囲に枠線がある)をレンダリングします |
outlineMaterial | ブール値 | false | マテリアルテーマでアウトラインスタイルの入力(周囲に枠線がある)をレンダリングします |
pattern | 文字列 | 入力のネイティブ "pattern" 属性の値 | |
placeholder | 文字列 | 数値 | 入力プレースホルダー | |
readonly | ブール値 | 入力を読み取り専用としてマークします | |
required | ブール値 | 入力を必須としてマークします | |
size | 文字列 | 数値 | 入力のネイティブ "size" 属性の値 | |
spellcheck | 文字列 | 入力のネイティブ "spellcheck" 属性の値 | |
step | 文字列 | 数値 | 入力のネイティブ "step" 属性の値 | |
tabindex | 文字列 | 数値 | 入力のネイティブ "tabindex" 属性の値 | |
type | 文字列 | 'text' | 入力タイプ |
value | 任意 | 入力値 | |
onBlur | function(e) |
| |
onChange | function(e) |
| |
onClear | function(e) |
| |
onFocus | function(e) |
| |
onInput | function(e) |
|
名前 | 説明 |
---|---|
error | 入力の "error" の内容 |
info | 入力の "info" の内容 |
input | カスタム入力要素 |
label | ラベルの内容 |
media | リストアイテムの "media" エリアの内容(例:アイコン) |
<script>import {Page,Navbar,NavbarBackLink,BlockTitle,List,ListInput,} from 'konsta/svelte';import DemoIcon from '../components/DemoIcon.svelte';let name = { value: '', changed: false };let demoValue = '';const onNameChange = (e) => {name = { value: e.target.value, changed: true };};const onDemoValueChange = (e) => {demoValue = e.target.value;};const onDemoValueClear = () => {demoValue = '';};</script><Page><Navbar title="Form Inputs" /><BlockTitle>Default</BlockTitle><List strongIos insetIos><ListInput label="Name" type="text" placeholder="Your name"><DemoIcon slot="media" /></ListInput><ListInput label="Password" type="password" placeholder="Your password"><DemoIcon slot="media" /></ListInput><ListInput label="E-mail" type="email" placeholder="Your e-mail"><DemoIcon slot="media" /></ListInput><ListInput label="URL" type="url" placeholder="URL"><DemoIcon slot="media" /></ListInput><ListInput label="Phone" type="tel" placeholder="Your phone number"><DemoIcon slot="media" /></ListInput><ListInputlabel="Gender"type="select"dropdowndefaultValue="Male"placeholder="Please choose..."><DemoIcon slot="media" /><option value="Male">Male</option><option value="Female">Female</option></ListInput><ListInputlabel="Birthday"type="date"defaultValue="2014-04-30"placeholder="Please choose..."><DemoIcon slot="media" /></ListInput><ListInputlabel="Date time"type="datetime-local"placeholder="Please choose..."><DemoIcon slot="media" /></ListInput><ListInputlabel="Textarea"type="textarea"placeholder="Bio"inputClass="!h-20 resize-none"><DemoIcon slot="media" /></ListInput></List><BlockTitle>Outline</BlockTitle><List strongIos insetIos><ListInput outline label="Name" type="text" placeholder="Your name"><DemoIcon slot="media" /></ListInput><ListInputoutlinelabel="Password"type="password"placeholder="Your password"><DemoIcon slot="media" /></ListInput><ListInput outline label="E-mail" type="email" placeholder="Your e-mail"><DemoIcon slot="media" /></ListInput><ListInput outline label="URL" type="url" placeholder="URL"><DemoIcon slot="media" /></ListInput><ListInput outline label="Phone" type="tel" placeholder="Your phone number"><DemoIcon slot="media" /></ListInput><ListInputoutlinelabel="Gender"type="select"dropdowndefaultValue="Male"placeholder="Please choose..."><DemoIcon slot="media" /><option value="Male">Male</option><option value="Female">Female</option></ListInput><ListInputoutlinelabel="Birthday"type="date"defaultValue="2014-04-30"placeholder="Please choose..."><DemoIcon slot="media" /></ListInput><ListInputoutlinelabel="Date time"type="datetime-local"placeholder="Please choose..."><DemoIcon slot="media" /></ListInput><ListInputoutlinelabel="Textarea"type="textarea"placeholder="Bio"inputClass="!h-20 resize-none"><DemoIcon slot="media" /></ListInput></List><BlockTitle>Floating Labels</BlockTitle><List strongIos insetIos><ListInput label="Name" floatingLabel type="text" placeholder="Your name"><DemoIcon slot="media" /></ListInput><ListInputlabel="Password"floatingLabeltype="password"placeholder="Your password"><DemoIcon slot="media" /></ListInput><ListInputlabel="E-mail"floatingLabeltype="email"placeholder="Your e-mail"><DemoIcon slot="media" /></ListInput><ListInput label="URL" floatingLabel type="url" placeholder="URL"><DemoIcon slot="media" /></ListInput><ListInputlabel="Phone"floatingLabeltype="tel"placeholder="Your phone number"><DemoIcon slot="media" /></ListInput></List><BlockTitle>Outline + Floating Labels</BlockTitle><List strongIos insetIos><ListInputoutlinelabel="Name"floatingLabeltype="text"placeholder="Your name"><DemoIcon slot="media" /></ListInput><ListInputoutlinelabel="Password"floatingLabeltype="password"placeholder="Your password"><DemoIcon slot="media" /></ListInput><ListInputoutlinelabel="E-mail"floatingLabeltype="email"placeholder="Your e-mail"><DemoIcon slot="media" /></ListInput><ListInput outline label="URL" floatingLabel type="url" placeholder="URL"><DemoIcon slot="media" /></ListInput><ListInputoutlinelabel="Phone"floatingLabeltype="tel"placeholder="Your phone number"><DemoIcon slot="media" /></ListInput></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': ''}onInput={onNameChange}><DemoIcon slot="media" /></ListInput></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}onInput={onDemoValueChange}onClear={onDemoValueClear}><DemoIcon slot="media" /></ListInput></List><BlockTitle>Icon + Input</BlockTitle><List strongIos insetIos><ListInput type="text" placeholder="Your name"><DemoIcon slot="media" /></ListInput><ListInput type="password" placeholder="Your password"><DemoIcon slot="media" /></ListInput><ListInput type="email" placeholder="Your e-mail"><DemoIcon slot="media" /></ListInput><ListInput type="url" placeholder="URL"><DemoIcon slot="media" /></ListInput></List><BlockTitle>Label + Input</BlockTitle><List strongIos insetIos><ListInput label="Name" type="text" placeholder="Your name" /><ListInput label="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><ListInput type="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>