Skip to content

Commit 9124977

Browse files
committed
add Search subcomponents and example
1 parent 9c123ff commit 9124977

File tree

2 files changed

+137
-4
lines changed

2 files changed

+137
-4
lines changed

packages/main/src/webComponents/Search/Search.mdx

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
import { ControlsWithNote, DocsHeader, Footer } from '@sb/components';
2-
import { Canvas, Meta } from '@storybook/addon-docs/blocks';
1+
import { ArgTypesWithNote, ControlsWithNote, DocsHeader, Footer } from '@sb/components';
2+
import { Canvas, Description, Meta } from '@storybook/addon-docs/blocks';
33
import * as ComponentStories from './Search.stories';
4+
import { SearchItem } from '../SearchItem/index.js';
5+
import { SearchItemGroup } from '../SearchItemGroup/index.js';
6+
import { SearchItemShowMore } from '../SearchItemShowMore/index.js';
7+
import { SearchMessageArea } from '../SearchMessageArea/index.js';
8+
import { SearchScope } from '../SearchScope/index.js';
49

510
<Meta of={ComponentStories} />
611

@@ -35,7 +40,7 @@ const scopeData = [
3540
{ name: 'Log work', scope: 'apps' },
3641
{ name: 'Manage Products', scope: 'apps' },
3742
{ name: 'Mobile Phones', scope: 'products' },
38-
{ name: 'Tablet', scope: 'products' }
43+
{ name: 'Tablet', scope: 'products' },
3944
];
4045

4146
function SearchComponent(props) {
@@ -50,7 +55,7 @@ function SearchComponent(props) {
5055
setFilterData(
5156
scopeData.filter((item) => {
5257
return item.scope === scope.text.toLowerCase();
53-
})
58+
}),
5459
);
5560
}
5661
};
@@ -67,4 +72,79 @@ function SearchComponent(props) {
6772

6873
</details>
6974

75+
### Search with `SearchShowMore` Item
76+
77+
Search with Grouped Suggestions and Show More (N) Item
78+
79+
<Canvas of={ComponentStories.ShowMoreItem} />
80+
81+
<details>
82+
<summary>Show static code</summary>
83+
84+
```tsx
85+
const allItems = [
86+
{ text: 'Search Item 1', icon: historyIcon },
87+
{ text: 'Search Item 2', icon: searchIcon },
88+
{ text: 'Search Item 3', icon: historyIcon },
89+
{ text: 'Search Item 4', icon: historyIcon },
90+
{ text: 'Search Item 5', icon: searchIcon },
91+
{ text: 'Search Item 6', icon: globeIcon },
92+
];
93+
const visibleItems = allItems.slice(0, 3);
94+
const hiddenItems = allItems.slice(3);
95+
96+
export function ShowMoreItem() {
97+
const [showHiddenItems, setShowHiddenItems] = useState(false);
98+
99+
return (
100+
<Search showClearIcon={true} placeholder="Placeholder">
101+
<SearchItemGroup headerText="Group Header 1">
102+
{visibleItems.map((item) => (
103+
<SearchItem key={item.text} text={item.text} icon={item.icon} />
104+
))}
105+
{!showHiddenItems && (
106+
<SearchItemShowMore itemsToShowCount={hiddenItems.length} onClick={() => setShowHiddenItems(true)} />
107+
)}
108+
{showHiddenItems && hiddenItems.map((item) => <SearchItem key={item.text} text={item.text} icon={item.icon} />)}
109+
</SearchItemGroup>
110+
111+
<SearchItemGroup headerText="Group Header 2">
112+
<SearchItem text="Search Item 1" icon={historyIcon} />
113+
<SearchItem text="Search Item 2" icon={historyIcon} />
114+
<SearchItem text="Search Item 3" icon={globeIcon} />
115+
</SearchItemGroup>
116+
</Search>
117+
);
118+
}
119+
```
120+
121+
</details>
122+
123+
## Subcomponents
124+
125+
### SearchItem
126+
127+
<Description of={SearchItem} />
128+
<ArgTypesWithNote metaOf={ComponentStories} of={SearchItem} />
129+
130+
### SearchItemGroup
131+
132+
<Description of={SearchItemGroup} />
133+
<ArgTypesWithNote metaOf={ComponentStories} of={SearchItemGroup} />
134+
135+
### SearchItemShowMore
136+
137+
<Description of={SearchItemShowMore} />
138+
<ArgTypesWithNote metaOf={ComponentStories} of={SearchItemShowMore} />
139+
140+
### SearchMessageArea
141+
142+
<Description of={SearchMessageArea} />
143+
<ArgTypesWithNote metaOf={ComponentStories} of={SearchMessageArea} />
144+
145+
### SearchScope
146+
147+
<Description of={SearchScope} />
148+
<ArgTypesWithNote metaOf={ComponentStories} of={SearchScope} />
149+
70150
<Footer />

packages/main/src/webComponents/Search/Search.stories.tsx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import type { Meta, StoryObj } from '@storybook/react-vite';
2+
import globeIcon from '@ui5/webcomponents-icons/dist/globe.js';
3+
import historyIcon from '@ui5/webcomponents-icons/dist/history.js';
4+
import searchIcon from '@ui5/webcomponents-icons/dist/search.js';
25
import { useState } from 'react';
36
import { SearchItem } from '../SearchItem/index.js';
7+
import { SearchItemGroup } from '../SearchItemGroup/index.js';
8+
import { SearchItemShowMore } from '../SearchItemShowMore/index.js';
49
import { SearchScope } from '../SearchScope/index.js';
510
import { Search } from './index.js';
611
import type { SearchPropTypes } from './index.js';
@@ -70,3 +75,51 @@ export const WithScopeAndItems: Story = {
7075
);
7176
},
7277
};
78+
79+
const allItems = [
80+
{ text: 'Search Item 1', icon: historyIcon },
81+
{ text: 'Search Item 2', icon: searchIcon },
82+
{ text: 'Search Item 3', icon: historyIcon },
83+
{ text: 'Search Item 4', icon: historyIcon },
84+
{ text: 'Search Item 5', icon: searchIcon },
85+
{ text: 'Search Item 6', icon: globeIcon },
86+
];
87+
const visibleItems = allItems.slice(0, 3);
88+
const hiddenItems = allItems.slice(3);
89+
90+
export const ShowMoreItem: Story = {
91+
args: {
92+
showClearIcon: true,
93+
placeholder: 'Placeholder',
94+
},
95+
render(args) {
96+
const [showHiddenItems, setShowHiddenItems] = useState(false);
97+
98+
return (
99+
<Search {...args}>
100+
<SearchItemGroup headerText="Group Header 1">
101+
{visibleItems.map((item) => {
102+
return <SearchItem key={item.text} text={item.text} icon={item.icon} />;
103+
})}
104+
{!showHiddenItems && (
105+
<SearchItemShowMore
106+
itemsToShowCount={hiddenItems.length}
107+
onClick={() => {
108+
setShowHiddenItems(true);
109+
}}
110+
/>
111+
)}
112+
{showHiddenItems &&
113+
hiddenItems.map((item) => {
114+
return <SearchItem key={item.text} text={item.text} icon={item.icon} />;
115+
})}
116+
</SearchItemGroup>
117+
<SearchItemGroup headerText="Group Header 2">
118+
<SearchItem text="Search Item 1" icon={historyIcon} />
119+
<SearchItem text="Search Item 2" icon={historyIcon} />
120+
<SearchItem text="Search Item 3" icon={globeIcon} />
121+
</SearchItemGroup>
122+
</Search>
123+
);
124+
},
125+
};

0 commit comments

Comments
 (0)