Back to Kibana

@kbn/content-management-storybook

src/platform/packages/shared/content-management/kbn-content-management-storybook/README.md

9.4.06.8 KB
Original Source

@kbn/content-management-storybook

Centralized Storybook configuration for the Content Management component ecosystem.

Table of Contents

Overview

This package provides a shared Storybook configuration for all packages under src/platform/packages/shared/content-management/. It enables developers to build and test UI components in isolation without requiring a running Kibana backend.

The Storybook aggregates stories from sibling packages including:

  • content_editor - Inline content editing components.
  • content_insights - Activity and view tracking UI.
  • favorites - Favorite/star functionality.
  • table_list_view / table_list_view_table - Content listing tables.
  • tabbed_table_list_view - Tabbed content navigation.
  • user_profiles - Creator/updater display components.
  • access_control - Permission and sharing UI.

Quick Start

Run the Content Management Storybook:

bash
yarn storybook content_management

Build a static Storybook site:

bash
yarn storybook --site content_management

Usage

Writing Stories

Create stories in sibling packages using the Component Story Format (CSF). Stories are automatically discovered from any *.stories.tsx or *.mdx file within the content-management/ directory tree.

tsx
// Example: table_list_view_table/src/components/tag_badge.stories.tsx
import type { Meta, StoryObj } from '@storybook/react';

import { TagBadge } from './tag_badge';

const meta: Meta<typeof TagBadge> = {
  title: 'Content Management/Tags/Tag Badge',
  component: TagBadge,
};

export default meta;
type Story = StoryObj<typeof TagBadge>;

export const Default: Story = {};

export const WithCustomProps: Story = {
  args: {
    color: '#FF5733',
    label: 'Production',
  },
};

Using Mock Data

This package re-exports mock data from @kbn/content-list-mock-data for use in stories. Here's a complete example:

tsx
import type { Meta, StoryObj } from '@storybook/react';
import { mockFindDashboards, MOCK_TAGS } from '@kbn/content-management-storybook';

import { ContentList } from './content_list';

const meta: Meta<typeof ContentList> = {
  title: 'Content Management/Content List/ContentList',
  component: ContentList,
};

export default meta;
type Story = StoryObj<typeof ContentList>;

export const Default: Story = {
  args: {
    findItems: mockFindDashboards,
    tags: MOCK_TAGS,
  },
};

export const WithVisualizationData: Story = {
  args: {
    findItems: mockFindVisualizations,
    tags: MOCK_TAGS,
  },
};

For advanced mock data usage (custom findItems, user profiles, status sorting), see the @kbn/content-list-mock-data README.

Architecture

Stories are discovered from sibling packages via the main.ts configuration:

src/platform/packages/shared/content-management/
├── kbn-content-management-storybook/   # This package (Storybook config)
│   ├── main.ts                         # Story discovery: ../**/*.stories.+(tsx|mdx)
│   ├── preview.ts                      # Global decorators and parameters
│   ├── manager.ts                      # UI branding and panel config
│   └── index.ts                        # Re-exports for story imports
│
├── table_list_view_table/
│   └── src/
│       └── components/
│           └── *.stories.tsx           # ← Stories here are auto-discovered
│
├── content_editor/
│   └── src/
│       └── components/
│           └── *.stories.tsx           # ← Stories here are auto-discovered
│
└── ... (other sibling packages)

Configuration Files

FilePurpose
main.tsExtends @kbn/storybook default config. Enables react-docgen-typescript for automatic prop table generation.
preview.tsSets global Storybook parameters. Injects jest-mock for stories requiring mock functions.
manager.tsCustomizes the Storybook UI with Content Management branding and default panel settings.
constants.tsCentralized TITLE and URL constants for branding.

API

Configuration Exports

ExportTypeDescription
TITLEstringStorybook title: 'Content Management Storybook'.
URLstringGitHub URL for the content-management directory.

Mock Data Re-exports

All exports from @kbn/content-list-mock-data are available from this package:

ExportDescription
mockFindDashboardsPre-configured findItems for dashboard content.
mockFindMapsPre-configured findItems for map content.
mockFindFilesPre-configured findItems for file content.
mockFindVisualizationsPre-configured findItems for visualization content.
MOCK_DASHBOARDSArray of 8 dashboard mock items.
MOCK_VISUALIZATIONSArray of 8 visualization mock items.
MOCK_MAPSArray of 5 map mock items.
MOCK_FILESArray of 6 file mock items.
MOCK_TAGSArray of 8 tag items.
MOCK_USER_PROFILESArray of user profile objects.
mockUserProfileServicesMock getUserProfile and bulkGetUserProfiles implementations.
createMockFindItemsFactory for custom findItems implementations.
createSimpleMockFindItemsSimplified factory with optional delay.

For complete type definitions and advanced usage, see the @kbn/content-list-mock-data API documentation.

Troubleshooting

Jest Mock Availability

The preview.ts file injects jest-mock onto window.jest to support stories that use Jest mock functions. This is a workaround because Storybook runs in a browser environment where Jest is not available.

If you encounter errors like jest is not defined in your story, ensure your story file imports mocks from this package or @kbn/content-list-mock-data rather than calling jest.fn() directly.

tsx
// ❌ Won't work in Storybook
const mockFn = jest.fn();

// ✅ Use the injected jest-mock
import jest from 'jest-mock';
const mockFn = jest.fn();

// ✅ Or use pre-built mocks from this package
import { mockFindDashboards } from '@kbn/content-management-storybook';

Stories Not Appearing

If your stories don't appear in Storybook:

  1. Ensure the file ends with .stories.tsx or .mdx.
  2. Verify the file is within the content-management/ directory tree.
  3. Check that the story has a valid default export with meta configuration.
  4. Restart the Storybook dev server after adding new story files.