From 13029a4394590a4c4b86068c2786b7ba763ecf5c Mon Sep 17 00:00:00 2001 From: Dhruv Bhanushali Date: Thu, 28 Oct 2021 16:24:45 +0400 Subject: [PATCH] Create an `InputField` component --- src/components/InputField/InputField.vue | 82 ++++++++++++ .../InputField/meta/InputField.stories.mdx | 120 ++++++++++++++++++ 2 files changed, 202 insertions(+) create mode 100644 src/components/InputField/InputField.vue create mode 100644 src/components/InputField/meta/InputField.stories.mdx diff --git a/src/components/InputField/InputField.vue b/src/components/InputField/InputField.vue new file mode 100644 index 0000000000..105a974b06 --- /dev/null +++ b/src/components/InputField/InputField.vue @@ -0,0 +1,82 @@ + + + diff --git a/src/components/InputField/meta/InputField.stories.mdx b/src/components/InputField/meta/InputField.stories.mdx new file mode 100644 index 0000000000..d781a2279c --- /dev/null +++ b/src/components/InputField/meta/InputField.stories.mdx @@ -0,0 +1,120 @@ +import { + ArgsTable, + Canvas, + Description, + Meta, + Story, +} from '@storybook/addon-docs' + +import InputField from '~/components/InputField/InputField.vue' + + + +export const Template = (args, { argTypes }) => ({ + template: ` + + Extra info + + `, + components: { InputField }, + props: Object.keys(argTypes), +}) + +# Input field + + + + + +The component emits an `input` event with the new contents of the field whenever +the field receives an input. + + + + {Template.bind({})} + + + +The recommended way to use it is with `v-model` mapping to a `String`. + +export const vModelTemplate = () => ({ + template: ` +
+ + {{ text.length }} + + {{ text }} +
+ `, + components: { InputField }, + data() { + return { + text: 'Hello, World!', + } + }, +}) + + + {vModelTemplate.bind({})} + + +The component is a transparent wrapper over `` so all attributes of the +input element can be applied to it, e.g. `placeholder`. It is recommended not to +change the type as the field is specifically designed for text. + + + + {Template.bind({})} + + + +For a11y, it is recommended that the input field be associated with a label. The +approach for this is to set the `inputId` prop and use the ID as the `for` +attribute of a `