Skip to content

Commit

Permalink
[ONL-8199] Migrate storybook to TS (#1833)
Browse files Browse the repository at this point in the history
* [ONL-8199] chore: Updated SB files to TS. Removed skiplink fix needed in SB v6.

* [ONL-8199] chore: Refactored stories that are not depending on vue components.

* [ONL-8199] chore: Updated SB to latest version.

* [ONL-8199] chore: Removed unused eslint directives.

* [ONL-8199] chore: Move vite config to TS. Removed unused babel config.

* [ONL-8199] pr: Addressed comments.
  • Loading branch information
mcibique authored Jan 26, 2024
1 parent 97f0471 commit e73d4bf
Show file tree
Hide file tree
Showing 34 changed files with 1,816 additions and 1,603 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ module.exports = {
},
{
files: [
'**/*.story.js',
'.storybook/**/*.{js,ts}',
'**/*.story.{js,jsx,ts,tsx}',
],
rules: {
'import/no-extraneous-dependencies': 'off',
Expand Down
16 changes: 0 additions & 16 deletions .storybook/backgrounds.js

This file was deleted.

30 changes: 30 additions & 0 deletions .storybook/backgrounds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export enum ChameleonTheme {
LIGHT = 'light',
DARK = 'dark',
LIGHT_BLUE = 'light blue',
DARK_BLUE = 'dark blue',
}

export type HslColor = string;

export interface ChameleonThemeConfig {
name: ChameleonTheme,
value: HslColor,
}

export const LIGHT_THEME = { name: ChameleonTheme.LIGHT, value: 'hsl(192.5, 10%, 100%)' }; // --ec-theme-gray-color-level-8
export const DARK_THEME = { name: ChameleonTheme.DARK, value: 'hsl(192.5, 10%, 20%)' }; // --ec-theme-gray-color-level-2
export const LIGHT_BLUE_THEME = { name: ChameleonTheme.LIGHT_BLUE, value: 'hsl(192.5, 100%, 47%)' }; // --ec-theme-key-color-level-4
export const DARK_BLUE_THEME = { name: ChameleonTheme.DARK_BLUE, value: 'hsl(192.5, 100%, 20%)' }; // --ec-theme-key-color-level-2

export function getAllBackgrounds(defaultName: ChameleonTheme) {
return {
default: defaultName,
values: [
LIGHT_THEME,
DARK_THEME,
LIGHT_BLUE_THEME,
DARK_BLUE_THEME,
],
};
}
6 changes: 5 additions & 1 deletion .storybook/main.js → .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
import type { StorybookConfig } from '@storybook/vue3-vite';

const config: StorybookConfig = {
framework: {
name: '@storybook/vue3-vite',
options: {},
Expand All @@ -20,3 +22,5 @@ module.exports = {
autodocs: true,
},
};

export default config;
6 changes: 0 additions & 6 deletions .storybook/manager-head.html

This file was deleted.

1 change: 0 additions & 1 deletion .storybook/manager.js → .storybook/manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/no-extraneous-dependencies */
import { addons } from '@storybook/addons';
import { create } from '@storybook/theming/create';

Expand Down
44 changes: 0 additions & 44 deletions .storybook/preview.js

This file was deleted.

50 changes: 50 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { withCssResources } from '@storybook/addon-cssresources';
import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport';
import type { Preview } from '@storybook/vue3';

import config from '../src/config';
import { inlineSvgSprites, SpriteName } from '../src/icons/browser';
// @ts-expect-error TS don't know how to handle vite's raw CSS import
import bwTheme from '../src/styles/themes/b-w.css?inline';
// @ts-expect-error TS don't know how to handle vite's raw CSS import
import greenTheme from '../src/styles/themes/green.css?inline';
// @ts-expect-error TS don't know how to handle vite's raw CSS import
import hotpinkTheme from '../src/styles/themes/hotpink.css?inline';
// @ts-expect-error TS don't know how to handle vite's raw CSS import
import redTheme from '../src/styles/themes/red.css?inline';
import { ChameleonTheme, getAllBackgrounds } from './backgrounds';

import '../src/styles/themes/blue.css';
import '../src/styles/main.css';

config.sensitiveClass = 'tw-filter tw-blur-4';

const preview: Preview = {
parameters: {
layout: 'fullscreen',
actions: { argTypesRegex: '^on[A-Z].*' },
backgrounds: getAllBackgrounds(ChameleonTheme.LIGHT),
viewport: { viewports: INITIAL_VIEWPORTS },
cssresources: [
{ id: 'green', code: `<style>\n${greenTheme}</style>`, hideCode: true },
{ id: 'red', code: `<style>\n${redTheme}</style>`, hideCode: true },
{ id: 'b&w', code: `<style>\n${bwTheme}</style>`, hideCode: true },
{ id: 'hotpink', code: `<style>\n${hotpinkTheme}</style>`, hideCode: true },
],
options: {
// we can't type this function, see comments in SB docs:
// https://storybook.js.org/docs/writing-stories/naming-components-and-hierarchy#sorting-stories
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
storySort: (a, b) => (a.title === b.title ? 0 : a.id.localeCompare(b.id, undefined, { numeric: true })),
},
controls: {
expanded: true,
},
},
decorators: [withCssResources],
};

inlineSvgSprites([SpriteName.ROUNDED_ICONS, SpriteName.SIMPLE_ICONS, SpriteName.CURRENCY_FLAGS], '/img');

export default preview;
4 changes: 3 additions & 1 deletion .storybook/utils.js → .storybook/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export function fixedContainerDecorator(height = '100vh') {
import type { StoryFn } from '@storybook/vue3';

export function fixedContainerDecorator(height: string = '100vh'): StoryFn {
// what is this for? an element with position: fixed always escapes the boundaries of the Docs page. See e.g.
// ec-navigation.story.js.
//
Expand Down
8 changes: 0 additions & 8 deletions babel.config.js

This file was deleted.

Loading

1 comment on commit e73d4bf

@vercel
Copy link

@vercel vercel bot commented on e73d4bf Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

chameleon – ./

chameleon-git-master-ebury.vercel.app
chameleon-dead-plane.vercel.app
chameleon-ebury.vercel.app

Please sign in to comment.