import type { Meta, StoryObj } from "@storybook/react-vite"; import { within, expect } from "storybook/test"; import { Box } from "./box"; import "./box.scss"; const meta: Meta = { title: "FP.React Components/Layout/Box", component: Box, tags: ["autodocs", "beta", "layout"], parameters: { docs: { description: { component: ` # Box - Layout Primitive A fundamental container primitive for spacing and sizing control. Provides comprehensive control over padding, margin, width, and border radius using a unified spacing scale. ## Features - **Unified Spacing Scale**: Fluid responsive spacing using CSS clamp() - **Logical Properties**: padding-inline/padding-block for i18n support - **Polymorphic**: Render as any semantic HTML element - **CSS Custom Properties**: Runtime theming - **Type-Safe**: Full TypeScript support - **Zero Runtime**: Utility classes compiled at build time [View Full Documentation →](https://github.com/anthropics/fpkit/blob/main/packages/fpkit/src/components/box/README.mdx) `, }, }, }, }; export default meta; type Story = StoryObj; /** * Default Box component with medium padding. * Demonstrates basic usage as a container with padding. */ export const Default: Story = { args: { padding: "md", children: "Default Box with medium padding", }, play: async ({ canvasElement, step }) => { const canvas = within(canvasElement); await step("Box renders correctly", async () => { const box = canvas.getByText("Default Box with medium padding"); expect(box).toBeInTheDocument(); expect(box).toHaveClass("box-padding-md"); }); }, }; /** * Box with different padding sizes. * Demonstrates the unified spacing scale from xs to xl. */ export const PaddingSizes: Story = { render: () => (
Padding XS (4-8px) Padding SM (8-12px) Padding MD (12-18px) Padding LG (16-24px) Padding XL (24-32px)
), }; /** * Box with asymmetric padding using logical properties. * Demonstrates paddingInline and paddingBlock for different horizontal/vertical padding. */ export const AsymmetricPadding: Story = { args: { paddingInline: "xl", paddingBlock: "sm", styles: { backgroundColor: "#e8f4f8", border: "2px dashed #0066cc" }, children: "Wide horizontal padding, narrow vertical padding", }, }; /** * Box with margin spacing. * Demonstrates margin control with the spacing scale. */ export const WithMargin: Story = { render: () => (
Box with large margin on all sides
), }; /** * Box with different width options. * Demonstrates width control: auto, full, fit, and max. */ export const WidthVariants: Story = { render: () => (
Width: auto (default, natural width) Width: full (100% width) Width: fit (fits content) Width: max (max-content)
), }; /** * Box with maximum width constraints. * Useful for readable text widths and centered containers. */ export const MaxWidthVariants: Story = { render: () => (
Max Width XS (480px) - Great for mobile layouts Max Width SM (640px) - Good for narrow content Max Width MD (768px) - Tablet-friendly width Max Width Container (1200px) - Standard page container
), }; /** * Centered container pattern. * Common pattern for page layouts with max-width and auto margins. */ export const CenteredContainer: Story = { args: { padding: "lg", maxWidth: "container", styles: { marginInline: "auto", backgroundColor: "#f8f9fa" }, children: ( <>

Centered Container

This is a common pattern for page layouts. The container has a max width of 1200px and is centered using marginInline: auto.

), }, }; /** * Box with border radius options. * Demonstrates rounded corners from subtle to fully rounded. */ export const BorderRadiusVariants: Story = { render: () => (
Radius XS (2px) - Subtle rounding Radius SM (4px) - Small rounding Radius MD (6px) - Medium rounding Radius LG (8px) - Large rounding Radius XL (12px) - Extra large rounding Radius Full (9999px) - Fully rounded pill
), }; /** * Card-like Box component. * Demonstrates creating a card with padding, radius, and shadow. */ export const CardLike: Story = { args: { padding: "lg", radius: "md", as: "article", styles: { backgroundColor: "#fff", boxShadow: "0 1px 3px rgba(0,0,0,0.1)", border: "1px solid #e0e0e0", }, children: ( <>

Card Title

This Box is styled to look like a card with padding, border radius, and a subtle shadow. It uses semantic HTML (article) for better accessibility.

), }, }; /** * Semantic HTML variations. * Demonstrates polymorphic rendering with different HTML elements. */ export const SemanticVariants: Story = { render: () => (
<div> - Generic container (default) <section> - Thematic grouping <article> - Self-contained content <aside> - Tangentially related content <main> - Primary page content <header> - Page/section header <footer> - Page/section footer
), }; /** * Composition example. * Demonstrates nesting Box components for complex layouts. */ export const Composition: Story = { render: () => (

Outer Container

Nested Box 1

Boxes can be nested to create complex layouts.

Nested Box 2

Each Box is independent with its own spacing and styling.

), }; /** * CSS Custom Property Override. * Demonstrates theming by overriding CSS custom properties. */ export const CustomProperties: Story = { args: { padding: "lg", radius: "md", styles: { // Override spacing and radius via CSS variables "--spacing-lg": "2rem", "--box-radius-md": "1rem", backgroundColor: "#e8f4f8", border: "2px solid #0066cc", } as React.CSSProperties, children: ( <>

Custom CSS Properties

This Box overrides --spacing-lg and --box-radius-md to demonstrate theming via CSS custom properties.

), }, }; /** * Responsive full-width section. * Common pattern for full-width hero or section layouts. */ export const FullWidthSection: Story = { args: { as: "section", width: "full", paddingBlock: "xl", paddingInline: "lg", styles: { backgroundColor: "#0066cc", color: "#fff", }, children: ( <>

Full-Width Hero Section

This pattern is common for hero sections or full-width content areas. Uses paddingBlock and paddingInline for responsive spacing.

), }, };