Skip to content

Commit

Permalink
feat: move storybook to the root
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasguillot committed Feb 22, 2025
1 parent 6e98bc6 commit ad6665f
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 271 deletions.
7 changes: 6 additions & 1 deletion .storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
const config = {
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
stories: [
'../storybook/**/*.mdx',
'../storybook/**/*.stories.@(js|jsx|mjs|ts|tsx)',
'../src/**/*.mdx',
'../src/**/*.stories.@(js|jsx|mjs|ts|tsx)',
],
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
Expand Down
131 changes: 0 additions & 131 deletions src/newspack-ui/storyboard/README.md

This file was deleted.

84 changes: 0 additions & 84 deletions src/newspack-ui/storyboard/button/docs.mdx

This file was deleted.

42 changes: 42 additions & 0 deletions storybook/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Newspack UI Storybook

This directory contains the Storybook implementation for Newspack UI components. Storybook is a development environment for UI components, allowing you to browse a component library, view the different states of each component, and interactively develop and test components.

## Running Storybook

From the plugin root directory:

```bash
npm run storybook
```

This will open Storybook in your default browser at `http://localhost:6006`.

## Available Scripts

- `npm run storybook` - Start Storybook development server
- `npm run build-storybook` - Build static Storybook for deployment

## Troubleshooting

Common issues and solutions:

1. **Storybook fails to start**
- Check Node.js version
- Clear npm cache: `npm cache clean --force`
- Delete node_modules and reinstall: `rm -rf node_modules && npm install`

2. **Stories not appearing**
- Verify file naming follows conventions
- Check story export format
- Clear Storybook cache: `rm -rf node_modules/.cache/storybook`

3. **Styles not loading**
- Verify style imports
- Check webpack configuration
- Clear browser cache

## Resources

- [Storybook Documentation](https://storybook.js.org/docs)
- [MDX Documentation](https://mdxjs.com/docs/)
70 changes: 70 additions & 0 deletions storybook/button/docs.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Meta, Canvas } from '@storybook/blocks';
import * as ButtonStories from './index.stories';

<Meta of={ButtonStories} name="Docs" />

# Button

A button component that provides a consistent look and feel across the Newspack UI.

<Canvas of={ButtonStories.Primary} sourceState="shown" />
<Canvas of={ButtonStories.Secondary} sourceState="shown" />
<Canvas of={ButtonStories.Branded} sourceState="shown" />
<Canvas of={ButtonStories.Ghost} sourceState="shown" />
<Canvas of={ButtonStories.Outline} sourceState="shown" />
<Canvas of={ButtonStories.Destructive} sourceState="shown" />
<Canvas of={ButtonStories.IconOnly} sourceState="shown" />

## CSS Classes

- `.newspack-ui`: Root namespace for Newspack UI components
- `.newspack-ui__button`: Base button class
- `.newspack-ui__button__label`: Container for button text
- `.newspack-ui__button__glyph`: Container for button icon

### Modifiers
- `.newspack-ui__button--primary`: Main call-to-action buttons
- `.newspack-ui__button--secondary`: Supporting actions (default)
- `.newspack-ui__button--branded`: Special emphasis using brand colors
- `.newspack-ui__button--ghost`: Subtle actions that don't need strong visual emphasis
- `.newspack-ui__button--outline`: Actions that need structure but minimal visual weight
- `.newspack-ui__button--destructive`: Actions with destructive consequences
- `.newspack-ui__button--x-small`: Extra small button size
- `.newspack-ui__button--small`: Small button size
- `.newspack-ui__button--medium`: Default button size
- `.newspack-ui__button--wide`: Makes the button take full width of its container
- `.newspack-ui__button--icon`: Styles the button as an icon-only button
- `.newspack-ui__button--loading`: Shows a loading spinner and hides button content

## Usage Guidelines

### Button Variants
- `primary`: Main call-to-action buttons
- `secondary`: Supporting actions (default)
- `branded`: Special emphasis using brand colors
- `ghost`: Subtle actions that don't need strong visual emphasis
- `outline`: Actions that need structure but minimal visual weight
- `destructive`: Actions with destructive consequences

### Button Size
- `medium` (default): Suitable for most use cases
- `small`: Use in secondary interfaces or when you need slightly reduced prominence
- `x-small`: Use in compact interfaces where space is limited

### Layout Options
- Default: Button will size to its content
- `wide`: Makes the button take full width of its container
- `icon`: Styles the button as an icon-only button
- `loading`: Shows a loading spinner and hides button content

## Accessibility

1. **Keyboard Navigation**:
- Ensure buttons are focusable using Tab key
- Use Enter or Space to activate buttons
- Maintain a logical tab order

2. **ARIA Attributes**:
- Use `aria-label` for icon-only buttons
- Use `aria-disabled="true"` when disabled
- Use `aria-pressed` for toggle buttons
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import '../../style.scss';
import '../../src/newspack-ui/style.scss';

export default {
title: 'Newspack UI/Button',
Expand Down
Loading

0 comments on commit ad6665f

Please sign in to comment.