/* ! * (c) Copyright 2026 Palantir Technologies Inc. All rights reserved. */ import type { Meta, StoryObj } from "@storybook/react-vite"; import { storybookLayoutDecorator, StoryLabel } from "@storybook-common"; import { expect, waitFor } from "storybook/test"; import { Flex } from "@blueprintjs/labs"; import { Elevation } from "../../common"; import { Button } from "../button/buttons"; import { Section } from "./section"; import { SectionCard } from "./sectionCard"; const meta: Meta = { title: "Core/Section", component: Section, decorators: [storybookLayoutDecorator], parameters: { layout: "centered", }, tags: ["autodocs"], args: { title: "Section title", elevation: Elevation.ZERO, compact: false, collapsible: false, }, argTypes: { elevation: { control: "select", options: [Elevation.ZERO, Elevation.ONE], }, compact: { control: "boolean", }, collapsible: { control: "boolean", }, icon: { control: "text", }, subtitle: { control: "text", }, }, } satisfies Meta; export default meta; type Story = StoryObj; /** * A basic section with a title and some content. */ export const Default: Story = { args: { title: "Section title", children: Section content goes here., }, }; /** * Use the `elevation` prop to control the visual depth of the section. * Section supports `Elevation.ZERO` and `Elevation.ONE`. */ export const ElevationExample: Story = { name: "Elevation", argTypes: { elevation: { table: { disable: true } }, }, render: args => (
Content with zero elevation.
Content with elevation one.
), }; /** * Use the `compact` prop to render a section with reduced padding. */ export const CompactExample: Story = { name: "Compact", argTypes: { compact: { table: { disable: true } }, }, render: args => (
Default padding.
Compact padding.
), }; /** * Use the `icon` prop to render an icon in the section header, * and `subtitle` to display additional context below the title. */ export const IconExample: Story = { name: "Icon & Subtitle", argTypes: { icon: { table: { disable: true } }, subtitle: { table: { disable: true } }, title: { table: { disable: true } }, }, render: args => (
Section with an icon.
Section with a subtitle.
Section with both icon and subtitle.
), }; /** * Use the `rightElement` prop to render an element on the right side of the section header. * This is commonly used for action buttons. */ export const RightElementExample: Story = { name: "Right Element", argTypes: { rightElement: { table: { disable: true } }, }, render: args => (
}> Section with a right element action button.
), }; /** * Interactive playground with all props toggleable via Storybook controls. */ export const Playground: Story = { args: { title: "Playground section", icon: "folder-open", subtitle: "Explore section props", elevation: Elevation.ONE, children: Section content goes here., }, }; /** * Use the `collapsible` prop to make the section's contents collapsible. * Clicking the section header toggles between expanded and collapsed states. */ export const Collapsible: Story = { args: { title: "Collapsible section", collapsible: true, children: This section's content can be toggled by clicking the header., }, argTypes: { collapsible: { table: { disable: true } }, }, play: async ({ canvas, userEvent, step }) => { const header = canvas.getByText("Collapsible section").closest(".bp6-section-header")!; const section = header.closest(".bp6-section")!; const collapseBody = section.querySelector(".bp6-collapse-body")!; const caret = canvas.getByRole("button", { name: /collapse section|expand section/ }); await step("Section starts expanded with content visible", async () => { await expect(canvas.getByText(/content can be toggled/)).toBeVisible(); await expect(collapseBody).toHaveAttribute("aria-hidden", "false"); await expect(caret).toHaveAttribute("aria-expanded", "false"); }); await step("Click header to collapse the section", async () => { await userEvent.click(header); await waitFor(() => expect(collapseBody).toHaveAttribute("aria-hidden", "true")); await expect(section).toHaveClass("bp6-section-collapsed"); await expect(collapseBody).toHaveAttribute("aria-hidden", "true"); await expect(caret).toHaveAttribute("aria-expanded", "true"); }); await step("Click header again to re-expand the section", async () => { await userEvent.click(header); await waitFor(() => expect(collapseBody).toHaveAttribute("aria-hidden", "false")); await expect(canvas.getByText(/content can be toggled/)).toBeVisible(); await expect(section).not.toHaveClass("bp6-section-collapsed"); await expect(caret).toHaveAttribute("aria-expanded", "false"); }); }, };