import { Story, Meta, html } from '@open-wc/demoing-storybook'; import { loadDefaultFeedbackMessages, MaxLength } from '@lion/validate'; import { localize } from '@lion/localize'; import '../lion-input.js'; # Input `lion-input` component is a webcomponent that enhances the functionality of the native `` element. {html` `} ```html ``` ## Features - Based on [field](?path=/docs/forms-system-overview--page) - Extra visual elements can be added via `slots` - **label**: can also be provided via the `label` attribute, but the slot can be used to change the `html` and `CSS` of the label. For example add an `u-sr-only` class to the label to make it visually hidden. A label is always needed for accessibility reasons. - **help-text**: a helper text shown below the label to give extra clarification. - **prefix**: does not have an active use case yet, but the option is in place. - **suffix**: can be used for addons to the input like a calculator, datepicker or addressbook. In these cases a button with an icon is used. - **before**: does not have an active use case yet, but the option is in place. - **after**: can be used to show a currency or percentage. - Delegates attributes like `type`, `disabled`, `placeholder` and `read-only` to the native input. - Can make us of [validation](?path=/docs/forms-validation-overview--page) ## How to use ### Installation ```sh npm i --save @lion/input ``` ```js import '@lion/input/lion-input.js'; ``` ## Examples ### Label Can be provided via the `label` attribute, but the slot can be used to change the `html` and `CSS` of the label. For example add an `u-sr-only` class to the label to make it (partially) visually hidden. A label is always needed for accessibility reasons. {html` `} ```html ``` ### Help-text A helper text shown below the label to give extra clarification. Just like the `label`, a `help-text` can be provided via the `help-text` attribute, a slot can be used to change the `html` and `CSS` of the help-text. For example add an anchor with further explanation. {html`
Help text using html
`}
```html
Help text using html
``` ### Prefilled {html` `} ```html ``` ### Read only `readonly` attribute will be delegated to the native `` to make it read-only. This field **will still be included** in the parent fieldset or form's `serializedValue`. {html` `} ```html ``` ### Disabled `disabled` attribute will be delegated to the native `` to make it disabled. This field **will not be included** in the parent fieldset or form's `serializedValue`. {html` `} ```html ``` ### Prefix > Prefix slot does not have an active use case yet. {html`
[prefix]
`}
```html
[prefix]
``` ### Suffix The suffix can be used for addons to the input like a calculator, datepicker or addressbook. In these cases a button with an icon is used. {html`
[suffix]
`}
```html
[suffix]
``` ### Before > Before slot does not have an active use case yet. {html`
[before]
`}
```html
[before]
``` ### After {html`
EUR
%
`}
```html
EUR
%
``` ## Using validation The input can be used with [validation](?path=/docs/forms-validation-overview--page). On certain conditions, a feedback message can be shown if the input value is invalid. You can change the locale with the buttons below the field. Our default validators come with default translations already. {() => { loadDefaultFeedbackMessages(); return html` `; }} ```html ```