2023-05-22 14:32:45 +02:00
import { Canvas, Meta, Story, Source, ArgTypes } from '@storybook/blocks';
2023-04-14 16:38:58 +02:00
import { Input } from "./index";
2023-05-22 11:39:11 +02:00
import * as Stories from './index.stories';
2024-03-13 15:29:18 +01:00
import * as InputPasswordStories from './InputPassword.stories';
2023-04-14 16:38:58 +02:00
2023-05-22 11:39:11 +02:00
<Meta of={Stories}/>
2023-04-14 16:38:58 +02:00
# Input
Cunningham provides a versatile Input component that you can use in your forms.
2024-03-14 17:17:30 +01:00
<Canvas of={Stories.Default} sourceState="shown"/>
2023-04-14 16:38:58 +02:00
<Source
language='ts'
dark
format={false}
2025-10-14 12:29:46 +02:00
code={`import { Input } from "@gouvfr-lasuite/cunningham-react";`}
2023-04-14 16:38:58 +02:00
/>
## States
You can use the following props to change the state of the Input component by using the `state` props.
2024-03-14 17:17:30 +01:00
<Canvas of={Stories.Default} sourceState="shown"/>
<Canvas of={Stories.Success} sourceState="shown"/>
<Canvas of={Stories.Error} sourceState="shown"/>
2023-04-14 16:38:58 +02:00
## Disabled
As a regular input, you can disable it by using the `disabled` props.
2024-03-14 17:17:30 +01:00
<Canvas of={Stories.DisabledEmpty} sourceState="shown"/>
<Canvas of={Stories.DisabledFilled} sourceState="shown"/>
2023-04-14 16:38:58 +02:00
## Icons
You can define an icon that will appear on the left side of the input by using the `icon` props.
2024-03-14 17:17:30 +01:00
<Canvas of={Stories.Icon} sourceState="shown"/>
2023-04-14 16:38:58 +02:00
You can also independently add an icon on the right side by using the `rightIcon` props.
2024-03-14 17:17:30 +01:00
<Canvas of={Stories.IconRight} sourceState="shown"/>
2023-04-14 16:38:58 +02:00
## Texts
You can define a text that will appear below the input by using the `text` props.
2024-03-14 17:17:30 +01:00
<Canvas of={Stories.WithText} sourceState="shown"/>
2023-04-14 16:38:58 +02:00
You can also independently add a text on the right side by using the `rightText` props.
2024-03-14 17:17:30 +01:00
<Canvas of={Stories.WithBothTexts} sourceState="shown"/>
2023-04-14 16:38:58 +02:00
## Width
By default, the input has a default width, like all inputs. But you can force it to take the full width of its container by using the `fullWidth` props.
2024-03-14 17:17:30 +01:00
<Canvas of={Stories.FullWidth} sourceState="shown"/>
2023-04-14 16:38:58 +02:00
## Chars Counter
You can display a counter of the number of characters entered in the input by using the `charsCounter` props. Please bare
in mind to also define `charCounterMax`.
2024-03-14 17:17:30 +01:00
<Canvas of={Stories.CharCounter} sourceState="shown"/>
2024-03-13 15:29:18 +01:00
## Password
You can also use a built-in password input that includes a button to show or hide the password.
<Canvas of={InputPasswordStories.Password} sourceState="shown"/>
2023-04-14 16:38:58 +02:00
## Controlled / Non Controlled
Like a native input, you can use the Input component in a controlled or non controlled way. You can see the example below
using the component in a controlled way.
2024-03-14 17:17:30 +01:00
<Canvas of={Stories.Controlled} sourceState="shown"/>
2023-04-14 16:38:58 +02:00
## Ref
2023-07-26 16:52:22 +02:00
You can use the `ref` props to get a reference to the input element.
2023-04-14 16:38:58 +02:00
2024-03-14 17:17:30 +01:00
<Canvas of={Stories.WithRef} sourceState="shown"/>
2023-04-14 16:38:58 +02:00
2023-07-26 16:52:22 +02:00
## Usage with react-hook-form
You can use this input with [react-hook-form](https://react-hook-form.com/docs)
2024-03-14 17:17:30 +01:00
<Canvas of={Stories.ReactHookForm} sourceState="shown"/>
2023-07-26 16:52:22 +02:00
2023-04-14 16:38:58 +02:00
## Props
You can use all the props of the native html `<input>` element props plus the following.
2023-05-22 14:32:45 +02:00
<ArgTypes of={Input} />
2023-04-14 16:38:58 +02:00
## Design tokens
2023-10-20 17:15:06 +02:00
Here are the custom design tokens defined by the input.
2023-04-14 16:38:58 +02:00
| Token | Description |
|--------------- |----------------------------- |
| font-weight | Value font weight |
| font-size | Value font size |
2023-09-06 16:19:36 +02:00
| value-color | Value color |
| value-color--disabled | Value color when disabled |
2023-04-14 16:38:58 +02:00
| border-radius | Border radius of the input |
| border-radius--hover | Border radius of the input on mouse hover |
| border-radius--focus | Border radius of the input when focused |
| border-width | Border width of the input |
| border-color | Border color of the input |
| border-color--hover | Border color of the input on mouse hover |
| border-color--focus | Border color of the input when focus |
| border-style | Border style of the input |
2023-05-22 14:53:35 +02:00
| label-color--focus | Label color when focused |
2023-04-14 16:38:58 +02:00
See also [Field](?path=/story/components-forms-field-doc--page)
## Form Example
<Canvas>
<Story id="components-forms-input--form-example"/>
</Canvas>
##
<img src="components/Forms/Input/resources/dd_1.svg"/>
##
<img src="components/Forms/Input/resources/dd_2.svg"/>
##
<img src="components/Forms/Input/resources/dd_3.svg"/>
##
<img src="components/Forms/Input/resources/dd_4.svg"/>
##
<img src="components/Forms/Input/resources/dd_5.svg"/>