Garden Design System React Components

repository·main·Indexed 22 days ago

https://github.com/zendeskgarden/react-components

A collection of React components for Zendesk's Garden design system, distributed as individual scoped npm packages. It features a three-tier Container-View-Element architecture and requires a ThemeProvider from @zendeskgarden/react-theming for styling and design tokens. Available components include accordions, buttons, modals, tables, and more.

Tokens
19.6K
Snippets
51
Records
166
Agent score
67%

What's inside @zendeskgarden/react-components

  1. Understand the Garden package structure

    main

    All Garden packages follow a standardized directory structure to separate concerns between demos, logic, and styling. A typical package (e.g., /packages/test) contains:

    • demo/: Visual component demos generated via Storybook.
    • src/: The core component source code and spec tests.
      • elements/: High-abstraction components that wrap interaction behavior and visual styling.
      • styled/: View-level styled-components containing theme-based CSS.
      • index.ts: The public-facing component exports for the package.
    • package.json: Configuration for the package as it would be published to the registry.
    • README.md: Essential package description, installation, and usage instructions.
  2. Define Story argTypes and parameters

    main

    To ensure proper categorization in Storybook, use argTypes and parameters effectively.

    argTypes

    Categorize props into two acceptable categories:

    1. Subcomponent: All subcomponent props (including children) should be specified under the associated subcomponent name.
    2. "Story": Ancillary controls needed to stress the full flexibility of the component.

    Use argTypes to rename props with subcomponent notation for clarity:

    argTypes={{
      hasHint: { name: Hint, table: { category: 'Story' } }
    }}

    parameters

    Use parameters to link to Figma designs. This helps developers see the intended design for a specific story state.

    args

    Storybook provides main component props as args. For Garden boolean props that default to true, you must explicitly specify them in args to match the default behavior.

  3. Understand Garden component versioning

    main

    Garden components are published under the @zendeskgarden npm namespace and follow semantic versioning (SemVer).

    Key versioning behaviors:

    • Patch versions: Bug fixes.
    • Minor versions: New features.
    • Major versions: Breaking changes.
    • Release Cadence: Fixes are released upon approval, features are released weekly, and breaking changes are released once per quarter.
    • Fixed Mode: Garden uses a fixed (common major) versioning strategy. While you can upgrade individual packages independently, it is best practice to keep all Garden dependencies up-to-date to ensure compatibility.
  4. What are Patterns in Garden demos?

    main

    A Pattern is a demo story that demonstrates how a component works in conjunction with other Garden components or external libraries.

    Patterns may violate the 'isolation' best practice because they focus on layout and behavior that supercede a single component. They are often used for visual testing or to demonstrate complex interactions.

    Important: Patterns are intended to be short-lived. Developers should move successful patterns to the official documentation website and remove them from Storybook to ensure the website remains the single source of truth.

  5. Improve tree-shaking in Garden React Components

    main
    Starting from version v8.76.0, the package preserves its module structure. This change is designed to improve tree-shaking efficiency, allowing bundlers to more effectively remove unused code from your final application bundle when using the @zendeskgarden/react-components package.
  6. TypeScript naming and structure conventions in Garden

    main

    Garden follows specific TypeScript standards for interfaces, types, and constants to ensure compatibility with generated API documentation and code reuse. When contributing or extending components, follow these naming and structural rules:

    Naming Conventions

    • Interfaces: Use the IComponentXxxProps convention (e.g., IButtonProps).
    • Types: Use CamelCase.
    • Array Constants: Use UPPER_CASE.

    Structural Rules

    • Exported Element Component Interfaces: Must reside in the src/types folder.
    • Non-shared Interfaces: Interfaces for internal use (like view or context) should live next to the components they type, not in src/types.
    • Constants: Define array constants using as const (e.g., export const COLORS = ['red', 'blue'] as const).
    • Type Derivation: Define types by reusing these constants where possible using typeof ARRAY[number].
    • Enums: Do not use JavaScript enum. Use union types derived from constants instead.
    • View Components: View component interfaces (IStyledXxxProps) and context interfaces should be defined in terms of the exported element component interface using TypeScript utility types.
  7. How to consume types without explicit type exports

    main

    Garden does not explicitly export type definitions. Instead, consumers should reuse types by accessing them through the publicly exported interface using indexed access types. This ensures a single source of truth for component properties.

    For example, if you need to reference a specific property type from a component's props, use the following pattern:

    // Instead of importing a specific type, use the interface's property
    type ButtonSize = IButtonProps['size'];
    type ButtonSize = IButtonProps['size'];
  8. Understand the Garden Container-View-Element architecture

    main

    Garden components are built using a three-tier architecture to separate concerns:

    1. Container components: No-UI components that manage complex logic like accessibility, keyboard interactions, and RTL (Right-to-Left) awareness. They expose this logic via React hooks or render props.
    2. View components: Responsible for visual rendering using styled-components. They should extend semantic HTML elements and follow strict CSS ordering rules.
    3. Element components: High-abstraction wrappers that combine Container logic and View styling. These are the public-facing components used by consumers.

    To ensure new components follow these rules, use the npm run new command to generate starter code.