@@ -37,6 +37,26 @@ export const Primary: StoryObj<typeof Input> = {
37
37
) ,
38
38
} ;
39
39
40
+ /**
41
+ * Input should be used as a [controlled][1] component.
42
+ * You should have a [state][2] to store the text value,
43
+ * and give its control to an Input via its `value` and `setValue` props.
44
+ * At the moment, these props work with `string` values only.
45
+ *
46
+ * To have good accessibility, ensure that your inputs have their matching labels.
47
+ * You can do it in many ways: wrap the input inside a `label`,
48
+ * or explicitly [link][3] it to one (like in the example below),
49
+ * or via the `aria-label` and `aria-labelledby` props.
50
+ *
51
+ * Note that Moai's inputs don't have the [confusing][4] default width.
52
+ * Instead, inputs always fill 100% of their container width.
53
+ * This means you should control the width of an input via its container.
54
+ *
55
+ * [1]: https://reactjs.org/docs/forms.html#controlled-components
56
+ * [2]: https://reactjs.org/docs/hooks-state.html
57
+ * [3]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label#attr-for
58
+ * [4]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-size
59
+ */
40
60
export const Basic : StoryObj = {
41
61
render : ( ) => {
42
62
const [ text , setText ] = useState < string > ( "Hello" ) ;
@@ -49,29 +69,17 @@ export const Basic: StoryObj = {
49
69
} ,
50
70
} ;
51
71
52
- Utils . story ( Basic , {
53
- desc : `
54
- Input should be used as a [controlled][1] component. You should have a
55
- [state][2] to store the text value, and give its control to an Input via its
56
- \`value\` and \`setValue\` props. At the moment, these props work with
57
- \`string\` values only.
58
-
59
- To have good accessibility, ensure that your inputs have their matching labels.
60
- You can do it in many ways: wrap the input inside a \`label\`, or explicitly
61
- [link][3] it to one (like in the example below), or via the \`aria-label\` and
62
- \`aria-labelledby\` props.
63
-
64
- Note that Moai's inputs don't have the [confusing][4] default width. Instead,
65
- inputs always fill 100% of their container width. This means you should control
66
- the width of an input via its container.
67
-
68
- [1]: https://reactjs.org/docs/forms.html#controlled-components
69
- [2]: https://reactjs.org/docs/hooks-state.html
70
- [3]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label#attr-for
71
- [4]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-size
72
- ` ,
73
- } ) ;
74
-
72
+ /**
73
+ * Input follows the [standard approach][1] to support suggestion.
74
+ * You should define your suggestion as a `datalist` element,
75
+ * then give its `id` to an input via the `list` prop.
76
+ *
77
+ * As a convenient shortcut, you can also define your suggestion directly via the `list` prop
78
+ * and Input will create the `datalist` element for you.
79
+ * You'll still need an explicit `id` for the list:
80
+ *
81
+ * [1]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/datalist
82
+ */
75
83
export const Suggestion : StoryObj = {
76
84
render : ( ) => (
77
85
< div style = { { width : 200 } } >
@@ -83,20 +91,17 @@ export const Suggestion: StoryObj = {
83
91
) ,
84
92
} ;
85
93
86
- Utils . story ( Suggestion , {
87
- desc : `
88
- Input follows the [standard approach][1] to support suggestion. You should
89
- define your suggestion as a \`datalist\` element, then give its \`id\` to an
90
- input via the \`list\` prop.
91
-
92
- As a convenient shortcut, you can also define your suggestion directly via the
93
- \`list\` prop and Input will create the \`datalist\` element for you. You'll
94
- still need an explicit \`id\` for the list:
95
-
96
- [1]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/datalist
97
- ` ,
98
- } ) ;
99
-
94
+ /**
95
+ * Input supports both [controlled][1] and [uncontrolled][2] usages,
96
+ * making it easy to use them with form builders like [Formik][3] and [React Hook Form][4], right out of the box.
97
+ * See our [Form guide][5] to learn more.
98
+ *
99
+ * [1]: https://reactjs.org/docs/forms.html#controlled-components
100
+ * [2]: https://reactjs.org/docs/uncontrolled-components.html
101
+ * [3]: https://formik.org
102
+ * [4]: https://react-hook-form.com
103
+ * [5]: /docs/guides-icons--primary
104
+ */
100
105
export const Form : StoryObj = {
101
106
render : ( ) => (
102
107
// "Fm" is the Formik's namespace
@@ -114,20 +119,13 @@ export const Form: StoryObj = {
114
119
) ,
115
120
} ;
116
121
117
- Utils . story ( Form , {
118
- desc : `
119
- Input supports both [controlled][1] and [uncontrolled][2] usages, making it
120
- easy to use them with form builders like [Formik][3] and [React Hook Form][4],
121
- right out of the box. See our [Form guide][5] to learn more.
122
-
123
- [1]: https://reactjs.org/docs/forms.html#controlled-components
124
- [2]: https://reactjs.org/docs/uncontrolled-components.html
125
- [3]: https://formik.org
126
- [4]: https://react-hook-form.com
127
- [5]: /docs/guides-icons--primary
128
- ` ,
129
- } ) ;
130
-
122
+ /**
123
+ * An input can have an icon defined via the `icon` prop.
124
+ * This follows our [Icon standard][1], which supports all SVG icons.
125
+ * See the [Icon guide][1] to learn more.
126
+ *
127
+ * [1]: /docs/guides-icons--primary
128
+ */
131
129
export const Icon : StoryObj = {
132
130
render : ( ) => (
133
131
// The icon is imported from the "react-icons" external library, like
@@ -141,13 +139,3 @@ export const Icon: StoryObj = {
141
139
</ div >
142
140
) ,
143
141
} ;
144
-
145
- Utils . story ( Icon , {
146
- desc : `
147
- An input can have an icon defined via the \`icon\` prop. This follows our [Icon
148
- standard][1], which supports all SVG icons. See the [Icon guide][1] to learn
149
- more.
150
-
151
- [1]: /docs/guides-icons--primary
152
- ` ,
153
- } ) ;
0 commit comments