1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
// @ts-nocheck
import * as mod from "./list"
import { create } from "../storybook/scaffold"
const docs = `### Overview
Filterable list with keyboard navigation and optional search input.
Use within panels or popovers where keyboard navigation is expected.
### API
- Required: \`items\` and \`key\`.
- Required: \`children\` render function for items.
- Optional: \`search\`, \`filterKeys\`, \`groupBy\`, \`onSelect\`, \`onKeyEvent\`.
### Variants and states
- Optional search bar and group headers.
### Behavior
- Uses fuzzy search when \`search\` is enabled.
- Keyboard navigation via arrow keys; Enter selects.
### Accessibility
- TODO: confirm ARIA roles for list items and search input.
### Theming/tokens
- Uses \`data-component="list"\` and data slots for structure.
`
const story = create({
title: "UI/List",
mod,
args: {
items: ["One", "Two", "Three", "Four"],
key: (x: string) => x,
children: (x: string) => x,
search: true,
},
})
export default {
title: "UI/List",
id: "components-list",
component: story.meta.component,
tags: ["autodocs"],
parameters: {
docs: {
description: {
component: docs,
},
},
},
}
export const Basic = story.Basic
export const Grouped = {
render: () => {
const items = [
{ id: "a1", title: "Alpha", group: "Group A" },
{ id: "a2", title: "Bravo", group: "Group A" },
{ id: "b1", title: "Delta", group: "Group B" },
]
return (
<mod.List items={items} key={(item) => item.id} groupBy={(item) => item.group} search={true}>
{(item) => item.title}
</mod.List>
)
},
}
export const Empty = {
render: () => (
<mod.List items={[]} key={(item) => item} search={true}>
{(item) => item}
</mod.List>
),
}
export const WithAdd = {
render: () => (
<mod.List
items={["One", "Two"]}
key={(item) => item}
search={true}
add={{
render: () => (
<button type="button" data-slot="list-item">
Add item
</button>
),
}}
>
{(item) => item}
</mod.List>
),
}
export const Divider = {
render: () => (
<mod.List items={["One", "Two", "Three"]} key={(item) => item} divider={true}>
{(item) => item}
</mod.List>
),
}
export const ActiveIcon = {
render: () => (
<mod.List items={["Alpha", "Beta", "Gamma"]} key={(item) => item} activeIcon="chevron-right">
{(item) => item}
</mod.List>
),
}
export const NoSearch = {
render: () => (
<mod.List items={["One", "Two", "Three"]} key={(item) => item} search={false}>
{(item) => item}
</mod.List>
),
}
export const SearchOptions = {
render: () => (
<mod.List
items={["Apple", "Banana", "Cherry"]}
key={(item) => item}
search={{
placeholder: "Filter...",
hideIcon: true,
action: <button type="button">Action</button>,
}}
>
{(item) => item}
</mod.List>
),
}
export const ItemWrapper = {
render: () => (
<mod.List
items={["One", "Two", "Three"]}
key={(item) => item}
itemWrapper={(item, node) => (
<div style={{ border: "1px solid var(--border-weak)", "border-radius": "6px", margin: "4px 0" }}>{node}</div>
)}
>
{(item) => item}
</mod.List>
),
}
export const GroupHeader = {
render: () => {
const items = [
{ id: "a1", title: "Alpha", group: "Group A" },
{ id: "b1", title: "Beta", group: "Group B" },
]
return (
<mod.List
items={items}
key={(item) => item.id}
groupBy={(item) => item.group}
groupHeader={(group) => <strong>{group.category}</strong>}
>
{(item) => item.title}
</mod.List>
)
},
}
|