Skip to content

Commit 224c531

Browse files
author
NgocNhi123
committed
use jsdoc
1 parent 242df89 commit 224c531

10 files changed

+272
-355
lines changed

src/docs/components/dialog.stories.tsx

+36-47
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ export const Primary: StoryObj<typeof Dialog> = {
2020
render: () => <div>None</div>,
2121
};
2222

23+
/**
24+
* Dialog is a [controlled][1], [declarative][3] component:
25+
* you should have a boolean [state][2] for whether the dialog should be visible or not,
26+
* and conditionally render a dialog based on that state.
27+
*
28+
* A dialog will call its `onEsc` function when the user press the "Esc" key or click on the backdrop.
29+
* It's common to set your state to `false` here to "close" the dialog.
30+
*
31+
* [1]: https://reactjs.org/docs/forms.html#controlled-components
32+
* [2]: https://reactjs.org/docs/hooks-state.html
33+
* [3]: https://reactjs.org/docs/refs-and-the-dom.html#when-to-use-refs
34+
*/
2335
export const Basic: StoryObj = {
2436
render: () => {
2537
const [visible, setVisible] = useState(false);
@@ -34,22 +46,15 @@ export const Basic: StoryObj = {
3446
},
3547
};
3648

37-
Utils.story(Basic, {
38-
desc: `
39-
Dialog is a [controlled][1], [declarative][3] component: you should have a
40-
boolean [state][2] for whether the dialog should be visible or not, and
41-
conditionally render a dialog based on that state.
42-
43-
A dialog will call its \`onEsc\` function when the user press the "Esc" key or
44-
click on the backdrop. It's common to set your state to \`false\` here to
45-
"close" the dialog.
46-
47-
[1]: https://reactjs.org/docs/forms.html#controlled-components
48-
[2]: https://reactjs.org/docs/hooks-state.html
49-
[3]: https://reactjs.org/docs/refs-and-the-dom.html#when-to-use-refs
50-
`,
51-
});
52-
49+
/**
50+
* Out of the box, dialogs render their children as-is, without even a padding,
51+
* to allow maximum customization.
52+
* Therefore, the Dialog component has supporting components to give you common dialog layout:
53+
*
54+
* - `Dialog.Body` wraps its children inside a padding.
55+
* - `Dialog.Footer` places its children horizontally, with gaps, aligned to end.
56+
* - `Dialog.Title` makes its children bold and larger, like a title.
57+
*/
5358
export const Layout: StoryObj = {
5459
render: () => {
5560
const [visible, setVisible] = useState(false);
@@ -75,18 +80,21 @@ export const Layout: StoryObj = {
7580
},
7681
};
7782

78-
Utils.story(Layout, {
79-
desc: `
80-
Out of the box, dialogs render their children as-is, without even a padding,
81-
to allow maximum customization. Therefore, the Dialog component has supporting
82-
components to give you common dialog layout:
83-
84-
- \`Dialog.Body\` wraps its children inside a padding.
85-
- \`Dialog.Footer\` places its children horizontally, with gaps, aligned to end.
86-
- \`Dialog.Title\` makes its children bold and larger, like a title.
87-
`,
88-
});
89-
83+
/**
84+
* The Dialog component has some utility methods as alternatives to the browser's built-in dialogs:
85+
*
86+
* - `Dialog.alert` for [`window.alert`][1]
87+
* - `Dialog.confirm` for [`window.confirm`][2]
88+
* - `Dialog.prompt` for [`window.prompt`][3]
89+
*
90+
* They accept the same parameters as their built-in counterparts,
91+
* but return async results and thus do not block the main flow.
92+
* They are implemented using Moai's components.
93+
*
94+
* [1]: https://developer.mozilla.org/en-US/docs/Web/API/Window/alert
95+
* [2]: https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm
96+
* [3]: https://developer.mozilla.org/en-US/docs/Web/API/Window/prompt
97+
*/
9098
export const Utilities: StoryObj = {
9199
render: () => (
92100
<Button
@@ -99,22 +107,3 @@ export const Utilities: StoryObj = {
99107
/>
100108
),
101109
};
102-
103-
Utils.story(Utilities, {
104-
desc: `
105-
The Dialog component has some utility methods as alternatives to the browser's
106-
built-in dialogs:
107-
108-
- \`Dialog.alert\` for [\`window.alert\`][1]
109-
- \`Dialog.confirm\` for [\`window.confirm\`][2]
110-
- \`Dialog.prompt\` for [\`window.prompt\`][3]
111-
112-
They accept the same parameters as their built-in counterparts, but return
113-
async results and thus do not block the main flow. They are implemented using
114-
Moai's components.
115-
116-
[1]: https://developer.mozilla.org/en-US/docs/Web/API/Window/alert
117-
[2]: https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm
118-
[3]: https://developer.mozilla.org/en-US/docs/Web/API/Window/prompt
119-
`,
120-
});

src/docs/components/icon.stories.tsx

+39-54
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,30 @@ export const Primary: StoryObj<typeof Icon> = {
3636
),
3737
};
3838

39+
/**
40+
* The recommended way to use the Icon component is to import an icon from the [react-icons][1] package
41+
* and pass it to the `icon` prop.
42+
* All icons in the package can be used with Moai out of the box.
43+
*
44+
* ~~~ts
45+
*
46+
* import { FaHome } from "react-icons/fa";
47+
* ~~~
48+
*
49+
* [1]: https://react-icons.github.io/react-icons/
50+
*/
3951
export const Basic: StoryObj = {
4052
render: () => <Icon component={FaHome} />,
4153
};
4254

43-
Utils.story(Basic, {
44-
desc: `
45-
The recommended way to use the Icon component is to import an icon from the
46-
[react-icons][1] package and pass it to the \`icon\` prop. All icons in the
47-
package can be used with Moai out of the box.
48-
49-
~~~ts
50-
51-
import { FaHome } from "react-icons/fa";
52-
~~~
53-
54-
[1]: https://react-icons.github.io/react-icons/
55-
`,
56-
});
57-
55+
/**
56+
* To make layout more predictable, icons are rendered as [block elements][1] by default.
57+
* However, for icons that are parts of texts, they should be rendered as [inline elements][2].
58+
* This is done by setting the `display` prop to `inline`.
59+
*
60+
* [1]: https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
61+
* [2]: https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements
62+
*/
5863
export const Display: StoryObj = {
5964
render: () => (
6065
<p>
@@ -65,18 +70,15 @@ export const Display: StoryObj = {
6570
),
6671
};
6772

68-
Utils.story(Display, {
69-
desc: `
70-
To make layout more predictable, icons are rendered as [block elements][1] by
71-
default. However, for icons that are parts of texts, they should be rendered as
72-
[inline elements][2]. This is done by setting the \`display\` prop to
73-
\`inline\`.
74-
75-
[1]: https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
76-
[2]: https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements
77-
`,
78-
});
79-
73+
/**
74+
* SVG icons usually use the [`currentcolor`][1] keyword for their colors.
75+
* This means to set the color of an icon, you should set the [text color][2] of its container.
76+
* Moai has a [`text`][3] utility that provides predefined, accessible colors for icons.
77+
*
78+
* [1]: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#currentcolor_keyword
79+
* [2]: https://developer.mozilla.org/en-US/docs/Web/CSS/color
80+
* [3]: /docs/patterns-color-text--page
81+
*/
8082
export const Color: StoryObj = {
8183
render: () => (
8284
<div className={text.highlightWeak}>
@@ -85,19 +87,16 @@ export const Color: StoryObj = {
8587
),
8688
};
8789

88-
Utils.story(Color, {
89-
desc: `
90-
SVG icons usually use the [\`currentcolor\`][1] keyword for their colors. This
91-
means to set the color of an icon, you should set the [text color][2] of its
92-
container. Moai has a [\`text\`][3] utility that provides predefined,
93-
accessible colors for icons.
94-
95-
[1]: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#currentcolor_keyword
96-
[2]: https://developer.mozilla.org/en-US/docs/Web/CSS/color
97-
[3]: /docs/patterns-color-text--page
98-
`,
99-
});
100-
90+
/**
91+
* Technically, the `component` prop expects a [function component][1] that returns an SVG element.
92+
* You can use it to display your own custom icons (e.g. logos, product icons).
93+
* With tools like [React SVGR][3], you can even create your own icon sets to use with Moai.
94+
* See the [Advanced section][2] in the Icon Pattern guide for detail.
95+
*
96+
* [1]: https://reactjs.org/docs/components-and-props.html#function-and-class-components
97+
* [2]: /docs/patterns-icon--advanced
98+
* [3]: https://react-svgr.com
99+
*/
101100
export const Advanced: StoryObj = {
102101
render: () => {
103102
// In practice, this should be defined outside of your component, or even
@@ -111,17 +110,3 @@ export const Advanced: StoryObj = {
111110
return <Icon component={Line} />;
112111
},
113112
};
114-
115-
Utils.story(Advanced, {
116-
desc: `
117-
Technically, the \`component\` prop expects a [function component][1] that
118-
returns an SVG element. You can use it to display your own custom icons (e.g.
119-
logos, product icons). With tools like [React SVGR][3], you can even create
120-
your own icon sets to use with Moai. See the [Advanced section][2] in the Icon
121-
Pattern guide for detail.
122-
123-
[1]: https://reactjs.org/docs/components-and-props.html#function-and-class-components
124-
[2]: /docs/patterns-icon--advanced
125-
[3]: https://react-svgr.com
126-
`,
127-
});

src/docs/components/input.stories.tsx

+49-61
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,26 @@ export const Primary: StoryObj<typeof Input> = {
3737
),
3838
};
3939

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+
*/
4060
export const Basic: StoryObj = {
4161
render: () => {
4262
const [text, setText] = useState<string>("Hello");
@@ -49,29 +69,17 @@ export const Basic: StoryObj = {
4969
},
5070
};
5171

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+
*/
7583
export const Suggestion: StoryObj = {
7684
render: () => (
7785
<div style={{ width: 200 }}>
@@ -83,20 +91,17 @@ export const Suggestion: StoryObj = {
8391
),
8492
};
8593

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+
*/
100105
export const Form: StoryObj = {
101106
render: () => (
102107
// "Fm" is the Formik's namespace
@@ -114,20 +119,13 @@ export const Form: StoryObj = {
114119
),
115120
};
116121

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+
*/
131129
export const Icon: StoryObj = {
132130
render: () => (
133131
// The icon is imported from the "react-icons" external library, like
@@ -141,13 +139,3 @@ export const Icon: StoryObj = {
141139
</div>
142140
),
143141
};
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

Comments
 (0)