Skip to content

Commit ce9b2f5

Browse files
authored
docs: enhance story of Input and MultiInput (#896)
1 parent 7a46fd4 commit ce9b2f5

5 files changed

Lines changed: 144 additions & 20 deletions

File tree

packages/main/scripts/create-web-components-wrapper.mjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,25 @@ const CUSTOM_DESCRIPTION_REPLACE = {
5959
''
6060
);
6161
}
62+
},
63+
MultiInput: {
64+
children: (description) => {
65+
return description.replace(
66+
`<br> Example: <br><br> &lt;ui5-input show-suggestions><br> &nbsp;&nbsp;&nbsp;&nbsp;&lt;ui5-suggestion-item text="Item #1">&lt;/ui5-suggestion-item><br> &nbsp;&nbsp;&nbsp;&nbsp;&lt;ui5-suggestion-item text="Item #2">&lt;/ui5-suggestion-item><br> &lt;/ui5-input> <br> <ui5-input show-suggestions> <ui5-suggestion-item text="Item #1"></ui5-suggestion-item> <ui5-suggestion-item text="Item #2"></ui5-suggestion-item> </ui5-input> <br><br> `,
67+
''
68+
);
69+
},
70+
tokens: (description) => {
71+
return description.replace(
72+
`<br> &lt;MultiInput><br> &nbsp;&nbsp;&nbsp;&nbsp;&lt;ui5-token slot="tokens" text="Token 1">&lt;/ui5-token><br> &nbsp;&nbsp;&nbsp;&nbsp;&lt;ui5-token slot="tokens" text="Token 2">&lt;/ui5-token><br> &lt;/MultiInput> <br> <br>`,
73+
`<br />&lt;MultiInput tokens={
74+
<br />&nbsp;&nbsp;&lt;>
75+
<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;Token text="Token 1" />
76+
<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;Token text="Token 2" />
77+
<br />&nbsp;&nbsp;</>}
78+
<br />/>`
79+
);
80+
}
6281
}
6382
};
6483

packages/main/src/webComponents/Input/Input.stories.mdx

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs/blocks';
22
import { Input } from '@ui5/webcomponents-react/lib/Input';
3+
import { ListItemTypes } from '@ui5/webcomponents-react/lib/ListItemTypes';
34
import { InputType } from '@ui5/webcomponents-react/lib/InputType';
45
import { ValueState } from '@ui5/webcomponents-react/lib/ValueState';
56
import '@ui5/webcomponents-icons/dist/icons/employee.js';
7+
import '@ui5/webcomponents-icons/dist/icons/globe.js';
68
import { Icon } from '@ui5/webcomponents-react/lib/Icon';
7-
import { CSSProperties } from 'react';
89
import { SuggestionItem } from '@ui5/webcomponents-react/lib/SuggestionItem';
910
import { createSelectArgTypes } from '@shared/stories/createSelectArgTypes';
1011
import { DocsHeader } from '@shared/stories/DocsHeader';
1112
import { DocsCommonProps } from '@shared/stories/DocsCommonProps';
13+
import '@ui5/webcomponents/dist/features/InputSuggestions.js';
1214

1315
<Meta
1416
title="UI5 Web Components / Input"
@@ -44,3 +46,88 @@ import { DocsCommonProps } from '@shared/stories/DocsCommonProps';
4446
</Canvas>
4547

4648
<ArgsTable story="." />
49+
50+
<br />
51+
52+
# Stories
53+
54+
<br />
55+
56+
## Input with customizable SuggestionItem
57+
58+
The `SuggestionItem` represents the suggestion item of the `Input`
59+
60+
**Note:** `SuggestionItems` will only be displayed if the required module has been imported (`import '@ui5/webcomponents/dist/features/InputSuggestions.js';`)
61+
and the `showSuggestions` prop is set to `true`.
62+
63+
<Canvas>
64+
<Story
65+
name="with SuggestionItem"
66+
args={{
67+
description: 'description',
68+
group: false,
69+
icon: 'globe',
70+
iconEnd: false,
71+
image: '',
72+
info: 'info',
73+
infoState: ValueState.None,
74+
text: 'Customizable SuggestionItem',
75+
type: ListItemTypes.Active
76+
}}
77+
argTypes={{
78+
description: { description: `Defines the description displayed right under the item text, if such is present.` },
79+
group: {
80+
description: `Defines the item to be displayed as a group item. <br><br> <b>Note:</b> When set, the other properties, such as <code>image</code>, <code>icon</code>, <code>description</code>, etc. will be omitted and only the <code>text</code> will be displayed.`
81+
},
82+
icon: {
83+
description: `Defines the <code>icon</code> source URI. <br><br> <b>Note:</b> SAP-icons font provides numerous buil-in icons. To find all the available icons, see the <ui5-link target="_blank" href="https://openui5.hana.ondemand.com/test-resources/sap/m/demokit/iconExplorer/webapp/index.html" class="api-table-content-cell-link">Icon Explorer</ui5-link>.`
84+
},
85+
iconEnd: {
86+
description: `Defines whether the <code>icon</code> should be displayed in the beginning of the item or in the end. <br><br> <b>Note:</b> If <code>image</code> is set, the <code>icon</code> would be displayed after the <code>image</code>.`
87+
},
88+
image: {
89+
description: `Defines the <code>image</code> source URI. <br><br> <b>Note:</b> The <code>image</code> would be displayed in the beginning of the item.`
90+
},
91+
info: { description: `Defines the <code>info</code>, displayed in the end of the item.` },
92+
infoState: {
93+
description: `Defines the state of the <code>info</code>. <br><br> Available options are: <code>"None"</code> (by default), <code>"Success"</code>, <code>"Warning"</code> and <code>"Erorr"</code>.`
94+
},
95+
text: { description: `Defines the text of the <code>SuggestionItem</code>.` },
96+
type: {
97+
control: { options: ['Inactive', 'Active', 'Detail'] },
98+
description: `Defines the visual indication and behavior of the item. Available options are <code>Active</code> (by default), <code>Inactive</code> and <code>Detail</code>. <br><br> <b>Note:</b> When set to <code>Active</code>, the item will provide visual response upon press and hover, while when <code>Inactive</code> or <code>Detail</code> - will not.`
99+
},
100+
disabled: { table: { disable: true } },
101+
highlight: { table: { disable: true } },
102+
maxlength: { table: { disable: true } },
103+
name: { table: { disable: true } },
104+
placeholder: { table: { disable: true } },
105+
readonly: { table: { disable: true } },
106+
required: { table: { disable: true } },
107+
showSuggestions: { table: { disable: true } },
108+
value: { table: { disable: true } },
109+
valueState: { table: { disable: true } },
110+
children: { table: { disable: true } },
111+
valueStateMessage: { table: { disable: true } },
112+
onChange: { table: { disable: true } },
113+
onInput: { table: { disable: true } },
114+
onSubmit: { table: { disable: true } },
115+
onSuggestionItemPreview: { table: { disable: true } },
116+
onSuggestionItemSelect: { table: { disable: true } },
117+
onSuggestionScroll: { table: { disable: true } }
118+
}}
119+
>
120+
{(args) => {
121+
return (
122+
<Input showSuggestions placeholder="click here to show suggestions" style={{ width: '400px' }}>
123+
<SuggestionItem {...args} />
124+
<SuggestionItem icon="globe" text="Argentina" />
125+
<SuggestionItem icon="globe" text="Iceland" />
126+
<SuggestionItem icon="globe" text="Moldova" />
127+
</Input>
128+
);
129+
}}
130+
</Story>
131+
</Canvas>
132+
133+
<ArgsTable story="with SuggestionItem" />

packages/main/src/webComponents/Input/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export interface InputPropTypes extends Omit<WithWebComponentPropTypes, 'onChang
5454
*/
5555
valueState?: ValueState;
5656
/**
57-
* Defines the <code>Input</code> suggestion items. <br><br> Example: <br><br> &lt;Input show-suggestions><br> &nbsp;&nbsp;&nbsp;&nbsp;&lt;ui5-suggestion-item text="Item #1">&lt;/ui5-suggestion-item><br> &nbsp;&nbsp;&nbsp;&nbsp;&lt;ui5-suggestion-item text="Item #2">&lt;/ui5-suggestion-item><br> &lt;/Input> <br><br> <b>Note:</b> The suggestion would be displayed only if the <code>showSuggestions</code> property is set to <code>true</code>. <br><br> <b>Note:</b> The &lt;ui5-suggestion-item> is recommended to be used as a suggestion item. Importing the Input Suggestions Support feature: <br> <code>import "@ui5/webcomponents/dist/features/InputSuggestions.js";</code> <br> also automatically imports the &lt;ui5-suggestion-item> for your convenience.
57+
* Defines the <code>Input</code> suggestion items. <br><br> Example: <br><br> &lt;Input showSuggestions><br> &nbsp;&nbsp;&nbsp;&nbsp;&lt;SuggestionItem text="Item #1">&lt;/SuggestionItem><br> &nbsp;&nbsp;&nbsp;&nbsp;&lt;SuggestionItem text="Item #2">&lt;/SuggestionItem><br> &lt;/Input> <br><br> <b>Note:</b> The suggestion would be displayed only if the <code>showSuggestions</code> property is set to <code>true</code>. <br><br> <b>Note:</b> The &lt;SuggestionItem> is recommended to be used as a suggestion item. Importing the Input Suggestions Support feature: <br> <code>import "@ui5/webcomponents/dist/features/InputSuggestions.js";</code> <br> also automatically imports the &lt;SuggestionItem> for your convenience.
5858
*/
5959
children?: ReactNode | ReactNode[];
6060
/**

packages/main/src/webComponents/MultiInput/MultiInput.stories.mdx

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs/blocks';
22
import { MultiInput } from '@ui5/webcomponents-react/lib/MultiInput';
3-
import { Token } from '@ui5/webcomponents-react/lib/Token';
43
import { InputType } from '@ui5/webcomponents-react/lib/InputType';
54
import { ValueState } from '@ui5/webcomponents-react/lib/ValueState';
6-
import { DocsHeader } from '@shared/stories/DocsHeader';
5+
import '@ui5/webcomponents-icons/dist/icons/employee.js';
6+
import { Token } from '@ui5/webcomponents-react/lib/Token';
77
import { createSelectArgTypes } from '@shared/stories/createSelectArgTypes';
8+
import { DocsHeader } from '@shared/stories/DocsHeader';
89
import { DocsCommonProps } from '@shared/stories/DocsCommonProps';
910

1011
<Meta
1112
title="UI5 Web Components / MultiInput"
1213
component={MultiInput}
13-
subcomponents={{ MultiInput, Token }}
14+
subcomponents={{ Token }}
1415
argTypes={{
1516
...createSelectArgTypes({ type: InputType, valueState: ValueState }),
16-
tokens: null,
17-
...DocsCommonProps
17+
...DocsCommonProps,
18+
tokens: { control: { disable: true } },
19+
children: { control: { disable: true } },
20+
icon: { control: { disable: true } },
21+
valueStateMessage: { control: { disable: true } }
22+
}}
23+
args={{
24+
type: InputType.Text,
25+
valueState: ValueState.None,
26+
style: { width: '400px' },
27+
className: '',
28+
tooltip: '',
29+
slot: '',
30+
ref: null
1831
}}
1932
/>
2033

@@ -26,7 +39,6 @@ import { DocsCommonProps } from '@shared/stories/DocsCommonProps';
2639
return (
2740
<MultiInput
2841
{...args}
29-
style={{ width: '100%' }}
3042
tokens={
3143
<>
3244
<Token text="Argentina" />
@@ -50,3 +62,7 @@ import { DocsCommonProps } from '@shared/stories/DocsCommonProps';
5062
</Canvas>
5163

5264
<ArgsTable story="." />
65+
66+
## Render SuggestionItems
67+
68+
The `MultiInput` component supports rendering `SuggestionItems`. An example on how to use them can be found [here](?path=/docs/ui5-web-components-input--with-suggestion-item#input-with-customizable-suggestionitem).

packages/main/src/webComponents/MultiInput/index.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,24 @@ export interface MultiInputPropTypes extends Omit<WithWebComponentPropTypes, 'on
5858
*/
5959
valueState?: ValueState;
6060
/**
61-
* Defines the <code>MultiInput</code> tokens. <br><br> Example: <br> &lt;MultiInput><br> &nbsp;&nbsp;&nbsp;&nbsp;&lt;ui5-token slot="tokens" text="Token 1">&lt;/ui5-token><br> &nbsp;&nbsp;&nbsp;&nbsp;&lt;ui5-token slot="tokens" text="Token 2">&lt;/ui5-token><br> &lt;/MultiInput> <br> <br>
61+
* Defines the <code>MultiInput</code> tokens. <br><br> Example: <br />&lt;MultiInput tokens={
62+
<br />&nbsp;&nbsp;&lt;>
63+
<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;Token text="Token 1" />
64+
<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;Token text="Token 2" />
65+
<br />&nbsp;&nbsp;</>}
66+
<br />/>
6267
*/
6368
tokens?: ReactNode | ReactNode[];
6469
/**
65-
* Defines the <code>Input</code> suggestion items. <br><br> Example: <br><br> &lt;ui5-input show-suggestions><br> &nbsp;&nbsp;&nbsp;&nbsp;&lt;ui5-suggestion-item text="Item #1">&lt;/ui5-suggestion-item><br> &nbsp;&nbsp;&nbsp;&nbsp;&lt;ui5-suggestion-item text="Item #2">&lt;/ui5-suggestion-item><br> &lt;/ui5-input> <br> <ui5-input show-suggestions> <ui5-suggestion-item text="Item #1"></ui5-suggestion-item> <ui5-suggestion-item text="Item #2"></ui5-suggestion-item> </ui5-input> <br><br> <b>Note:</b> The suggestion would be displayed only if the <code>showSuggestions</code> property is set to <code>true</code>. <br><br> <b>Note:</b> The &lt;ui5-suggestion-item> is recommended to be used as a suggestion item. Importing the Input Suggestions Support feature: <br> <code>import "@ui5/webcomponents/dist/features/InputSuggestions.js";</code> <br> also automatically imports the &lt;ui5-suggestion-item> for your convenience.
70+
* Defines the <code>Input</code> suggestion items. <br><b>Note:</b> The suggestion would be displayed only if the <code>showSuggestions</code> property is set to <code>true</code>. <br><br> <b>Note:</b> The &lt;ui5-suggestion-item> is recommended to be used as a suggestion item. Importing the Input Suggestions Support feature: <br> <code>import "@ui5/webcomponents/dist/features/InputSuggestions.js";</code> <br> also automatically imports the &lt;ui5-suggestion-item> for your convenience.
6671
*/
6772
children?: ReactNode | ReactNode[];
6873
/**
6974
* Defines the icon to be displayed in the <code>Input</code>.
7075
*/
7176
icon?: ReactNode | ReactNode[];
7277
/**
73-
* Defines the value state message that will be displayed as pop up under the <code>Input</code>. <br><br><br/><br/>
74-
*
78+
* Defines the value state message that will be displayed as pop up under the <code>Input</code>.<br/>
7579
* <b>Note:</b> If not specified, a default text (in the respective language) will be displayed. <br> <b>Note:</b> The <code>valueStateMessage</code> would be displayed, when the <code>Input</code> is in <code>Information</code>, <code>Warning</code> or <code>Error</code> value state. <br> <b>Note:</b> If the <code>Input</code> has <code>suggestionItems</code>, the <code>valueStateMessage</code> would be displayed as part of the same popover, if used on desktop, or dialog - on phone.
7680
*/
7781
valueStateMessage?: ReactNode | ReactNode[];
@@ -82,19 +86,19 @@ export interface MultiInputPropTypes extends Omit<WithWebComponentPropTypes, 'on
8286
/**
8387
* Fired when the value help icon is pressed and F4 or ALT/OPTION + ARROW_UP/ARROW_DOWN keyboard keys are used.
8488
*/
85-
onValueHelpTrigger?: (event: CustomEvent<{}>) => void;
89+
onValueHelpTrigger?: (event: CustomEvent) => void;
8690
/**
8791
* Fired when the input operation has finished by pressing Enter or on focusout.
8892
*/
89-
onChange?: (event: CustomEvent<{}>) => void;
93+
onChange?: (event: CustomEvent) => void;
9094
/**
9195
* Fired when the value of the <code>Input</code> changes at each keystroke, and when a suggestion item has been selected.
9296
*/
93-
onInput?: (event: CustomEvent<{}>) => void;
97+
onInput?: (event: CustomEvent) => void;
9498
/**
9599
* Fired when user presses Enter key on the <code>Input</code>. <br><br> <b>Note:</b> The event is fired independent of whether there was a change before or not. If change was performed, the event is fired after the change event. The event is also fired when an item of the select list is selected by pressing Enter.
96100
*/
97-
onSubmit?: (event: CustomEvent<{}>) => void;
101+
onSubmit?: (event: CustomEvent) => void;
98102
/**
99103
* Fired when the user navigates to a suggestion item via the ARROW keys, as a preview, before the final selection.
100104
*/
@@ -110,12 +114,10 @@ export interface MultiInputPropTypes extends Omit<WithWebComponentPropTypes, 'on
110114
}
111115

112116
/**
113-
* <h3>Overview</h3>
114-
A <code>MultiInput</code> field allows the user to enter multiple values, which are displayed as <code>Token</code>.
117+
*A <code>MultiInput</code> field allows the user to enter multiple values, which are displayed as <code>Token</code>.
115118
User can choose interaction for creating tokens. Fiori Guidelines say that user should create tokens when:
116-
<ul> <li>Type a value in the input and press enter or focus out the input field (<code>change</code> event is fired)</li> <li>Select a value from the suggestion list</li> (<code>suggestion-item-select</code> event is fired)
119+
<ul> <li>Type a value in the input and press enter or focus out the input field (<code>onChange</code> event is fired)</li> <li>Select a value from the suggestion list (<code>onSuggestionItemSelect</code> event is fired)</li>
117120
</ul>
118-
119121
* <a href="https://sap.github.io/ui5-webcomponents/playground/components/MultiInput" target="_blank">UI5 Web Components Playground</a>
120122
*/
121123
const MultiInput: FC<MultiInputPropTypes> = withWebComponent<MultiInputPropTypes>(

0 commit comments

Comments
 (0)