Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration: Storybook #2567

Open
TazorDE opened this issue Mar 22, 2024 · 4 comments
Open

Integration: Storybook #2567

TazorDE opened this issue Mar 22, 2024 · 4 comments
Labels
feature request Request a feature or introduce and update to the project.
Milestone

Comments

@TazorDE
Copy link
Member

TazorDE commented Mar 22, 2024

Describe the feature in detail (code, mocks, or screenshots encouraged)

In order to integrate Skeletons styles into the Storybook framework several steps need to be taken to apply the styles in Storybook.

Requirements to get it working:

  • installed SvelteKit, Tailwind, Skeleton, and Storybook in a single project
  • updated the example components inserted as part of the Storybook setup to use Tailwind styles
  • had to import the global stylesheet app.pcss in .storybook > preview.ts to enable Tailwind styles
  • then switched the Button component styles to Skeleton - initially they were not working
  • setup a Storybook Decorator (a wrapping component) that included the .dark class for enabling Tailwind dark
  • added data-theme="skeleton" to the Decorator as well. This enabled Skeleton styles

@endigo9740 did a full test of the @storybook/addon-themes plugin. Unfortunately the results were mixed:

The integration guide will be based around how that pans out. If we can use the plugin, it'll be 1000x easier for most users. If not, then we may look to create a universal wrapper component (the Decorator) that implements this. For most Skeleton users they will need to be able to toggle mode/theme at will

If they stall or don't fix the plugin quickly though we'll likely consider building either a custom Decorator -or- a custom plugin that replicates the required features specifically for Skeleton's use case

(thank you @endigo9740 for doing the actual hard work so far)

What type of pull request would this be?

Docs

Provide relevant links or additional information.

@TazorDE TazorDE added the feature request Request a feature or introduce and update to the project. label Mar 22, 2024
@endigo9740 endigo9740 added this to the v3.0 (Next) milestone Mar 22, 2024
@endigo9740
Copy link
Contributor

@fattenap
Copy link

fattenap commented Apr 8, 2024

Hi, I was able to get Storybook global styles working using the following approach.

I used @storybook/addon-themes and configured withThemeByDataAttribute for switching the theme only, not for dark/light mode. Make sure to set parentSelector and point it to body. Once I did that I was able to set the global theme using the selector.

For dark mode, I used the storybook-dark-mode add-on, which you can see below I configured using darkMode: { stylePreview: true }

My config looks like this

import type { Preview, SvelteRenderer } from '@storybook/svelte';
import { withThemeByDataAttribute } from '@storybook/addon-themes';

import '../src/app.postcss';

const preview: Preview = {
    parameters: {
        darkMode: { stylePreview: true },
        controls: {
            matchers: {
                color: /(background|color)$/i,
                date: /Date$/i
            }
        }
    },
    decorators: [
        withThemeByDataAttribute<SvelteRenderer>({
            themes: {
                skeleton: 'skeleton',
                crimson: 'crimson',
                modern: 'modern'
            },
            defaultTheme: 'skeleton',
            parentSelector: 'body',
            attributeName: 'data-theme'
        })
    ]
};

export default preview;

theme-change

@endigo9740
Copy link
Contributor

@fattenap I've tested and confirmed this is working great in practice. Good find about the dark mode plugin. We'll use this instruction when generating the upcoming integration guide for Skeleton v3.

@endigo9740 endigo9740 changed the title Skeleton and Storybook integration guide Storybook (integration) Apr 11, 2024
@endigo9740
Copy link
Contributor

Note: we have more documentation incoming on this topic soon. But just noting the need for the CSF if you wish to document all Svelte components (including support for slots).

@endigo9740 endigo9740 changed the title Storybook (integration) Integration Guide: Storybook May 24, 2024
@endigo9740 endigo9740 changed the title Integration Guide: Storybook Integration: Storybook May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request a feature or introduce and update to the project.
Projects
None yet
Development

No branches or pull requests

3 participants