import type { Meta, StoryObj } from "@storybook/react"; import { ExpandableText } from "./ExpandableText"; // Wrapper component for consistent story styling const StoryWrapper: React.FC<{ children: React.ReactNode }> = ({ children, }) => (
{children}
); const meta: Meta = { title: "Components/ExpandableText", component: ExpandableText, parameters: { layout: "padded", }, tags: ["autodocs"], argTypes: { maxLines: { control: { type: "number", min: 1, max: 10 }, description: "Maximum number of lines to show when collapsed", }, breakpoint: { control: { type: "select" }, options: [undefined, "xs", "sm", "md", "lg", "xl"], description: "Breakpoint at which truncation should be applied", }, showText: { control: { type: "text" }, description: "Text for the expand trigger", }, hideText: { control: { type: "text" }, description: "Text for the collapse trigger", }, }, }; export default meta; type Story = StoryObj; const longText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt."; const shortText = "This is a short text that probably won't need truncation on most screens."; const mediumText = "This is a medium length text that might be collapsed on smaller screens or with lower line limits. It contains enough content to demonstrate the truncation behavior effectively."; export const Default: Story = { args: { text: longText, maxLines: 3, showText: "Read more", hideText: "Read less", }, render: args => ( ), }; export const ShortText: Story = { args: { text: shortText, maxLines: 3, showText: "Read more", hideText: "Read less", }, render: args => ( ), }; export const SingleLine: Story = { args: { text: longText, maxLines: 1, showText: "Show more", hideText: "Show less", }, render: args => ( ), }; export const FiveLines: Story = { args: { text: longText, maxLines: 5, showText: "Read more", hideText: "Read less", }, render: args => ( ), }; export const CustomLabels: Story = { args: { text: longText, maxLines: 3, showText: "View full description", hideText: "Show summary", }, render: args => ( ), }; export const WithBreakpoint: Story = { args: { text: longText, maxLines: 3, breakpoint: "sm", showText: "Read more", hideText: "Read less", }, render: args => ( ), parameters: { docs: { description: { story: "This example only applies truncation on small screens and below. On larger screens, the full text is shown without truncation controls.", }, }, }, }; export const MediumText: Story = { args: { text: mediumText, maxLines: 2, showText: "Read more", hideText: "Read less", }, render: args => ( ), }; export const WithCustomTextProps: Story = { args: { text: longText, maxLines: 3, showText: "Read more", hideText: "Read less", textProps: { variant: "small", elementType: "p", }, }, render: args => ( ), }; export const WithOnToggleCallback: Story = { args: { text: longText, maxLines: 3, showText: "Read more", hideText: "Read less", onToggle: (expanded: boolean) => { console.log("Expandable text expanded:", expanded); }, }, render: args => ( ), parameters: { docs: { description: { story: "Check the browser console to see the onToggle callback in action.", }, }, }, };