Bin
2025-12-16 9e0b2ba2c317b1a86212f24cbae3195ad1f3dbfa
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
import type { Meta, StoryObj } from "@storybook/react";
import { useState } from "react";
import { CollapsiblePanel } from "./collapsible-panel";
import { Button } from "../button/button";
import { EmptyState } from "../empty-state/empty-state";
import { Typography } from "../typography/typography";
import { IconUserAdd } from "@humansignal/icons";
 
const meta: Meta<typeof CollapsiblePanel> = {
  component: CollapsiblePanel,
  title: "UI/CollapsiblePanel",
  argTypes: {
    variant: {
      control: "select",
      options: ["primary", "default"],
    },
    disableToggle: {
      control: "boolean",
    },
    defaultExpanded: {
      control: "boolean",
    },
  },
};
 
export default meta;
type Story = StoryObj<typeof CollapsiblePanel>;
 
/**
 * Default Collapsible Panel
 *
 * Basic panel with title and content.
 */
export const Default: Story = {
  args: {
    variant: "default",
    title: "Panel Title",
    children: (
      <div className="p-base">
        <p className="text-sm">This is the panel content that can be collapsed or expanded.</p>
      </div>
    ),
  },
};
 
/**
 * Primary Variant
 *
 * Primary colored panel - use for important selections or actions.
 */
export const Primary: Story = {
  args: {
    variant: "primary",
    title: "Select at least one member",
    children: (
      <div className="p-base">
        <p className="text-sm text-neutral-content-subtle">Selected members will appear here</p>
      </div>
    ),
  },
};
 
/**
 * With Count Badge
 *
 * Shows a count next to the title.
 */
export const WithCount: Story = {
  args: {
    variant: "primary",
    title: "members selected",
    count: 5,
    children: (
      <div className="p-base">
        <p className="text-sm">John Doe, Jane Smith, Bob Johnson, Alice Brown, Charlie Wilson</p>
      </div>
    ),
  },
};
 
/**
 * With Actions
 *
 * Panel with action buttons in the header.
 */
export const WithActions: Story = {
  args: {
    variant: "primary",
    title: "3 members selected",
    actions: (
      <Button variant="neutral" look="outlined" size="small">
        Clear Selection
      </Button>
    ),
    children: (
      <div className="p-base">
        <p className="text-sm">John Doe, Jane Smith, Bob Johnson</p>
      </div>
    ),
  },
};
 
/**
 * With Empty State
 *
 * Panel containing an EmptyState component.
 */
export const WithEmptyState: Story = {
  args: {
    variant: "primary",
    title: "No members selected",
    children: (
      <EmptyState
        className="p-widest"
        size="small"
        icon={<IconUserAdd />}
        title="Select members from below"
        description="Select members to assign them to this resource"
      />
    ),
  },
};
 
/**
 * Toggle Disabled (Cannot be Collapsed/Expanded)
 *
 * Panel with disabled toggle button - useful when threshold is exceeded.
 * The toggle button is disabled but the rest of the header (title, actions) remains interactive.
 */
export const ToggleDisabled: Story = {
  args: {
    variant: "primary",
    title: "John, Jane, Bob, Alice, Charlie +10 selected",
    disableToggle: true,
    expanded: false,
    actions: (
      <Button variant="neutral" look="outlined" size="small">
        Clear Selection
      </Button>
    ),
    children: null,
  },
};
 
/**
 * Starts Collapsed
 *
 * Panel that starts in collapsed state.
 */
export const StartsCollapsed: Story = {
  args: {
    variant: "default",
    title: "Advanced Settings",
    defaultExpanded: false,
    children: (
      <div className="p-base">
        <div className="flex flex-col gap-3">
          <div>
            <label className="text-sm font-medium mb-1 block">Setting 1</label>
            <input type="text" className="border rounded px-2 py-1 w-full" />
          </div>
          <div>
            <label className="text-sm font-medium mb-1 block">Setting 2</label>
            <input type="text" className="border rounded px-2 py-1 w-full" />
          </div>
        </div>
      </div>
    ),
  },
};
 
/**
 * Controlled State
 *
 * Panel with externally controlled expand/collapse state.
 */
export const Controlled: Story = {
  render: () => {
    const [isExpanded, setIsExpanded] = useState(true);
 
    return (
      <div className="flex flex-col gap-4">
        <div className="flex gap-2">
          <Button size="small" onClick={() => setIsExpanded(true)}>
            Expand
          </Button>
          <Button size="small" onClick={() => setIsExpanded(false)}>
            Collapse
          </Button>
          <span className="text-sm text-neutral-content-subtle self-center">
            Current state: {isExpanded ? "Expanded" : "Collapsed"}
          </span>
        </div>
        <CollapsiblePanel
          variant="default"
          title="Controlled Panel"
          expanded={isExpanded}
          onExpandedChange={setIsExpanded}
        >
          <div className="p-base">
            <p className="text-sm">This panel's state is controlled by the buttons above.</p>
          </div>
        </CollapsiblePanel>
      </div>
    );
  },
};
 
/**
 * Multiple Panels
 *
 * Multiple panels stacked together.
 */
export const MultiplePanels: Story = {
  render: () => {
    return (
      <div className="flex flex-col gap-3">
        <CollapsiblePanel variant="primary" title="Selection Panel" count={3}>
          <div className="p-base">
            <p className="text-sm">John Doe, Jane Smith, Bob Johnson</p>
          </div>
        </CollapsiblePanel>
        <CollapsiblePanel variant="default" title="Filters" defaultExpanded={false}>
          <div className="p-base">
            <p className="text-sm">Filter options would go here</p>
          </div>
        </CollapsiblePanel>
        <CollapsiblePanel variant="default" title="Settings" defaultExpanded={false}>
          <div className="p-base">
            <p className="text-sm">Settings options would go here</p>
          </div>
        </CollapsiblePanel>
      </div>
    );
  },
};
 
/**
 * Rich Content
 *
 * Panel with complex content including lists and actions.
 */
export const RichContent: Story = {
  args: {
    variant: "primary",
    title: "5 members selected",
    actions: (
      <div className="flex gap-2">
        <Button variant="negative" look="outlined" size="small">
          Remove All
        </Button>
        <Button variant="primary" size="small">
          Assign
        </Button>
      </div>
    ),
    children: (
      <div className="divide-y divide-neutral-border">
        {["John Doe", "Jane Smith", "Bob Johnson", "Alice Brown", "Charlie Wilson"].map((name) => (
          <div key={name} className="px-base py-tight flex items-center justify-between">
            <div className="flex items-center gap-2">
              <div className="h-8 w-8 rounded-full bg-primary-background flex items-center justify-center text-xs font-medium">
                {name
                  .split(" ")
                  .map((n) => n[0])
                  .join("")}
              </div>
              <span className="text-sm">{name}</span>
            </div>
            <Button size="smaller" variant="neutral" look="text">
              Remove
            </Button>
          </div>
        ))}
      </div>
    ),
  },
};
 
/**
 * Real-World: Member Selection Panel
 *
 * Complete example of a member selection panel as used in the members table.
 */
export const MemberSelectionPanel: Story = {
  render: () => {
    const [selectedCount, setSelectedCount] = useState(0);
    const [isExpanded, setIsExpanded] = useState(true);
 
    const handleClearSelection = () => {
      setSelectedCount(0);
    };
 
    const handleSelect = (count: number) => {
      setSelectedCount(count);
      setIsExpanded(true);
    };
 
    return (
      <div className="flex flex-col gap-4">
        <div className="flex gap-2">
          <Button size="small" onClick={() => handleSelect(0)}>
            Select None
          </Button>
          <Button size="small" onClick={() => handleSelect(3)}>
            Select 3
          </Button>
          <Button size="small" onClick={() => handleSelect(15)}>
            Select 15 (Threshold Exceeded)
          </Button>
        </div>
 
        <CollapsiblePanel
          variant="primary"
          title={
            selectedCount > 0
              ? `${selectedCount} member${selectedCount === 1 ? "" : "s"} selected`
              : "No members selected"
          }
          actions={
            selectedCount > 0 ? (
              <Button variant="neutral" look="outlined" size="small" onClick={handleClearSelection}>
                Clear Selection
              </Button>
            ) : undefined
          }
          expanded={selectedCount > 10 ? false : isExpanded}
          onExpandedChange={setIsExpanded}
          disableToggle={selectedCount > 10}
        >
          {selectedCount === 0 ? (
            <EmptyState
              className="p-widest"
              size="small"
              icon={<IconUserAdd />}
              title="Select members from below"
              description="Select members to assign them to this resource"
            />
          ) : selectedCount <= 10 ? (
            <div className="p-base">
              <Typography variant="body" size="small" className="text-neutral-content-subtle">
                {selectedCount} member{selectedCount === 1 ? "" : "s"} selected
              </Typography>
            </div>
          ) : (
            <div className="p-base">
              <Typography variant="body" size="small" className="text-neutral-content-subtle">
                Too many members selected to display individually. Panel cannot be collapsed.
              </Typography>
            </div>
          )}
        </CollapsiblePanel>
      </div>
    );
  },
};