Back to Storybook

Addon Backgrounds Options In Preview

docs/_snippets/addon-backgrounds-options-in-preview.md

10.3.65.6 KB
Original Source
js
export default {
  parameters: {
    backgrounds: {
      options: {
        // ๐Ÿ‘‡ Default options
        dark: { name: 'Dark', value: '#333' },
        light: { name: 'Light', value: '#F7F9F2' },
        // ๐Ÿ‘‡ Add your own
        maroon: { name: 'Maroon', value: '#400' },
      },
    },
  },
  initialGlobals: {
    // ๐Ÿ‘‡ Set the initial background color
    backgrounds: { value: 'light' },
  },
};
ts
// Replace your-framework with the framework you are using, e.g. react-vite, nextjs, vue3-vite, etc.
import type { Preview } from '@storybook/your-framework';

const preview: Preview = {
  parameters: {
    backgrounds: {
      options: {
        // ๐Ÿ‘‡ Default options
        dark: { name: 'Dark', value: '#333' },
        light: { name: 'Light', value: '#F7F9F2' },
        // ๐Ÿ‘‡ Add your own
        maroon: { name: 'Maroon', value: '#400' },
      },
    },
  },
  initialGlobals: {
    // ๐Ÿ‘‡ Set the initial background color
    backgrounds: { value: 'light' },
  },
};

export default preview;
ts
// Replace your-framework with the framework you are using (e.g., react-vite, nextjs, nextjs-vite)
import { definePreview } from '@storybook/your-framework';

export default definePreview({
  parameters: {
    backgrounds: {
      options: {
        // ๐Ÿ‘‡ Default options
        dark: { name: 'Dark', value: '#333' },
        light: { name: 'Light', value: '#F7F9F2' },
        // ๐Ÿ‘‡ Add your own
        maroon: { name: 'Maroon', value: '#400' },
      },
    },
  },
  initialGlobals: {
    // ๐Ÿ‘‡ Set the initial background color
    backgrounds: { value: 'light' },
  },
});
<!-- JS snippets still needed while providing both CSF 3 & Next -->
js
// Replace your-framework with the framework you are using (e.g., react-vite, nextjs, nextjs-vite)
import { definePreview } from '@storybook/your-framework';

export default definePreview({
  parameters: {
    backgrounds: {
      options: {
        // ๐Ÿ‘‡ Default options
        dark: { name: 'Dark', value: '#333' },
        light: { name: 'Light', value: '#F7F9F2' },
        // ๐Ÿ‘‡ Add your own
        maroon: { name: 'Maroon', value: '#400' },
      },
    },
  },
  initialGlobals: {
    // ๐Ÿ‘‡ Set the initial background color
    backgrounds: { value: 'light' },
  },
});
ts
import { definePreview } from '@storybook/vue3-vite';

export default definePreview({
  parameters: {
    backgrounds: {
      options: {
        // ๐Ÿ‘‡ Default options
        dark: { name: 'Dark', value: '#333' },
        light: { name: 'Light', value: '#F7F9F2' },
        // ๐Ÿ‘‡ Add your own
        maroon: { name: 'Maroon', value: '#400' },
      },
    },
  },
  initialGlobals: {
    // ๐Ÿ‘‡ Set the initial background color
    backgrounds: { value: 'light' },
  },
});
<!-- JS snippets still needed while providing both CSF 3 & Next -->
js
import { definePreview } from '@storybook/vue3-vite';

export default definePreview({
  parameters: {
    backgrounds: {
      options: {
        // ๐Ÿ‘‡ Default options
        dark: { name: 'Dark', value: '#333' },
        light: { name: 'Light', value: '#F7F9F2' },
        // ๐Ÿ‘‡ Add your own
        maroon: { name: 'Maroon', value: '#400' },
      },
    },
  },
  initialGlobals: {
    // ๐Ÿ‘‡ Set the initial background color
    backgrounds: { value: 'light' },
  },
});
ts
import { definePreview } from '@storybook/angular';

export default definePreview({
  parameters: {
    backgrounds: {
      options: {
        // ๐Ÿ‘‡ Default options
        dark: { name: 'Dark', value: '#333' },
        light: { name: 'Light', value: '#F7F9F2' },
        // ๐Ÿ‘‡ Add your own
        maroon: { name: 'Maroon', value: '#400' },
      },
    },
  },
  initialGlobals: {
    // ๐Ÿ‘‡ Set the initial background color
    backgrounds: { value: 'light' },
  },
});
ts
import { definePreview } from '@storybook/web-components-vite';

export default definePreview({
  parameters: {
    backgrounds: {
      options: {
        // ๐Ÿ‘‡ Default options
        dark: { name: 'Dark', value: '#333' },
        light: { name: 'Light', value: '#F7F9F2' },
        // ๐Ÿ‘‡ Add your own
        maroon: { name: 'Maroon', value: '#400' },
      },
    },
  },
  initialGlobals: {
    // ๐Ÿ‘‡ Set the initial background color
    backgrounds: { value: 'light' },
  },
});
<!-- JS snippets still needed while providing both CSF 3 & Next -->
js
import { definePreview } from '@storybook/web-components-vite';

export default definePreview({
  parameters: {
    backgrounds: {
      options: {
        // ๐Ÿ‘‡ Default options
        dark: { name: 'Dark', value: '#333' },
        light: { name: 'Light', value: '#F7F9F2' },
        // ๐Ÿ‘‡ Add your own
        maroon: { name: 'Maroon', value: '#400' },
      },
    },
  },
  initialGlobals: {
    // ๐Ÿ‘‡ Set the initial background color
    backgrounds: { value: 'light' },
  },
});