Skip to content

Commit d160f43

Browse files
mm-wangclaude
andauthored
[core] Add Storybook stories for Collapse (#7943)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 553e3c0 commit d160f43

1 file changed

Lines changed: 125 additions & 0 deletions

File tree

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
* (c) Copyright 2026 Palantir Technologies Inc. All rights reserved.
3+
*/
4+
5+
import type { Meta, StoryObj } from "@storybook/react-vite";
6+
import { useCallback } from "react";
7+
import { useArgs } from "storybook/preview-api";
8+
9+
import { Button } from "../button/buttons";
10+
import { Code, H4 } from "../html/html";
11+
12+
import { Collapse } from "./collapse";
13+
14+
const sampleContent = (
15+
<div style={{ padding: 12, background: "var(--pt-app-background-color)", border: "1px solid var(--gray3)" }}>
16+
<p style={{ margin: 0 }}>
17+
This is an example of collapsible content. It can contain any valid React elements, including paragraphs,
18+
lists, forms, or other components.
19+
</p>
20+
</div>
21+
);
22+
23+
const meta: Meta<typeof Collapse> = {
24+
title: "Core/Collapse",
25+
component: Collapse,
26+
decorators: [
27+
Story => (
28+
<div style={{ display: "flex", flexDirection: "column", gap: 8, minWidth: "400px", maxWidth: "500px" }}>
29+
<Story />
30+
</div>
31+
),
32+
],
33+
parameters: {
34+
layout: "centered",
35+
},
36+
tags: ["autodocs"],
37+
args: {
38+
isOpen: false,
39+
keepChildrenMounted: false,
40+
transitionDuration: 200,
41+
},
42+
argTypes: {
43+
isOpen: {
44+
control: "boolean",
45+
},
46+
keepChildrenMounted: {
47+
control: "boolean",
48+
},
49+
transitionDuration: {
50+
control: "number",
51+
},
52+
component: {
53+
control: "text",
54+
},
55+
},
56+
} satisfies Meta<typeof Collapse>;
57+
58+
export default meta;
59+
type Story = StoryObj<typeof meta>;
60+
61+
/**
62+
* A basic collapse that reveals and hides content with a smooth sliding animation.
63+
* Use the `isOpen` control to toggle visibility.
64+
*/
65+
export const Default: Story = {
66+
args: {
67+
isOpen: true,
68+
},
69+
argTypes: {
70+
component: { table: { disable: true } },
71+
},
72+
render: function RenderDefault(args) {
73+
const [, updateArgs] = useArgs();
74+
const handleToggle = useCallback(() => updateArgs({ isOpen: !args.isOpen }), [args.isOpen, updateArgs]);
75+
76+
return (
77+
<div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
78+
<Button text={args.isOpen ? "Hide content" : "Show content"} onClick={handleToggle} />
79+
<Collapse {...args}>{sampleContent}</Collapse>
80+
</div>
81+
);
82+
},
83+
};
84+
85+
/**
86+
* Interactive playground with all props toggleable via Storybook controls.
87+
*/
88+
export const Playground: Story = {
89+
args: {
90+
isOpen: false,
91+
},
92+
argTypes: {
93+
component: { table: { disable: true } },
94+
},
95+
render: function RenderPlayground(args) {
96+
const [, updateArgs] = useArgs();
97+
const handleToggle = useCallback(() => updateArgs({ isOpen: !args.isOpen }), [args.isOpen, updateArgs]);
98+
99+
return (
100+
<div style={{ display: "flex", flexDirection: "column", gap: 8, minWidth: 400 }}>
101+
<Button text={args.isOpen ? "Collapse" : "Expand"} onClick={handleToggle} icon="exchange" />
102+
<Collapse {...args}>
103+
<div
104+
style={{
105+
padding: 16,
106+
background: "var(--pt-app-background-color)",
107+
border: "1px solid var(--gray3)",
108+
borderRadius: 4,
109+
}}
110+
>
111+
<H4 style={{ marginTop: 0 }}>Collapsible Content</H4>
112+
<p>
113+
This content is revealed and hidden with a smooth sliding animation. Toggle the controls in
114+
the Storybook panel to adjust the component behavior.
115+
</p>
116+
<p style={{ marginBottom: 0 }}>
117+
Try adjusting <Code>transitionDuration</Code> and <Code>keepChildrenMounted</Code> to see
118+
their effects.
119+
</p>
120+
</div>
121+
</Collapse>
122+
</div>
123+
);
124+
},
125+
};

0 commit comments

Comments
 (0)