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

chore(web-components): Switch Storybook framework from html-webpack5 to html-vite #33298

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
radium-v marked this conversation as resolved.
Show resolved Hide resolved
radium-v marked this conversation as resolved.
Show resolved Hide resolved
"type": "none",
"comment": "switch storybook framework from html-webpack5 to html-vite",
"packageName": "@fluentui/web-components",
"email": "[email protected]",
"dependentChangeType": "none"
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"@storybook/react": "7.6.20",
"@storybook/react-webpack5": "7.6.20",
"@storybook/theming": "7.6.20",
"@storybook/html-vite": "7.6.20",
"@swc/cli": "0.3.14",
"@swc/core": "1.5.7",
"@swc/helpers": "0.5.1",
Expand Down Expand Up @@ -224,7 +225,7 @@
"enquirer": "2.3.6",
"enzyme": "3.10.0",
"enzyme-to-json": "3.6.2",
"esbuild": "0.20.1",
"esbuild": "0.24.2",
"esbuild-loader": "4.1.0",
"eslint": "8.57.0",
"eslint-config-airbnb": "18.2.1",
Expand Down Expand Up @@ -342,6 +343,7 @@
"tslib": "2.6.3",
"typescript": "5.3.3",
"vinyl": "2.2.0",
"vite": "6.0.5",
"webpack": "5.94.0",
"webpack-bundle-analyzer": "4.10.1",
"webpack-cli": "5.1.4",
Expand Down Expand Up @@ -374,7 +376,7 @@
},
"resolutions": {
"@types/jest-axe/axe-core": "4.7.2",
"esbuild": "0.20.1",
"esbuild": "0.24.2",
"eslint": "8.57.0",
"swc-loader": "^0.2.6",
"prettier": "2.8.8",
Expand Down
88 changes: 0 additions & 88 deletions packages/web-components/.storybook/main.cjs

This file was deleted.

27 changes: 27 additions & 0 deletions packages/web-components/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { StorybookConfig } from '@storybook/html-vite';

export default {
// helpers.stories.ts is a file that contains helper functions for stories,
// and should not be treated as a story itself.
stories: ['../src/**/!(helpers)*.stories.@(ts|mdx)'],
staticDirs: ['../public'],
core: {
disableTelemetry: true,
disableWhatsNewNotifications: true,
},
framework: '@storybook/html-vite',
addons: [
{
name: '@storybook/addon-essentials',
options: {
backgrounds: false,
viewport: false,
toolbars: false,
actions: true,
},
},
],
docs: {
autodocs: true,
},
} satisfies StorybookConfig;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { addons } from '@storybook/manager-api';
import webcomponentsTheme from './theme.mjs';
import webcomponentsTheme from './theme.js';

addons.setConfig({
previewTabs: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
/// <reference types="vite/client" />

import { teamsDarkTheme, teamsLightTheme, webDarkTheme, webLightTheme } from '@fluentui/tokens';
import type { StoryContext } from '@storybook/html';
import * as prettier from 'prettier';
import prettierPluginHTML from 'prettier/parser-html.js';
import { setTheme } from '../src/theme/set-theme.js';
import webcomponentsTheme from './theme.mjs';

import '../src/index-rollup.js';
import './docs-root.css';
import webcomponentsTheme from './theme.js';

// Import all component definitions. This is a vite-specific feature:
// https://vitejs.dev/guide/features.html#glob-import
const modules = import.meta.glob(['../src/**/define.ts']);
for (const path in modules) {
modules[path]();
}

const FAST_EXPRESSION_COMMENTS = /<!--((fast-\w+)\{.*\}\2)?-->/g; // Matches comments that contain FAST expressions

Expand All @@ -16,8 +24,8 @@ const themes = {
'teams-dark': teamsDarkTheme,
};

function changeTheme(/** @type {Event} */ e) {
setTheme(themes[/** @type {keyof themes} */ (/** @type {HTMLInputElement}*/ (e.target).value)]);
function changeTheme(e: Event) {
setTheme(themes[(e.target as HTMLSelectElement).value as keyof typeof themes]);
}

// This is needed in Playwright.
Expand All @@ -43,7 +51,7 @@ export const parameters = {
source: {
// To get around the inability to change Prettier options in the source addon, this transform function
// imports the standalone Prettier and uses it to format the source with the desired options.
transform(/** @type {string} */ src, /** @type {import('@storybook/html').StoryContext} */ storyContext) {
transform(src: string, storyContext: StoryContext) {
if (!src) {
const fragment = storyContext.originalStoryFn(storyContext.allArgs, storyContext);
if (!(fragment instanceof DocumentFragment) && !(fragment instanceof HTMLElement)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default create({

// Typography
fontBase:
'"Segoe UI", "Segoe UI Web (West European)", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;',
'"Segoe UI", "Segoe UI Web (West European)", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;',
fontCode: 'monospace',

// Text colors
Expand All @@ -32,4 +32,3 @@ export default create({
inputTextColor: 'black',
inputBorderRadius: 4,
});

3 changes: 1 addition & 2 deletions packages/web-components/.storybook/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"noEmit": true,
"types": ["node"]
"noEmit": true
},
"include": ["*", "../public", "../src/**/*.stories.*"]
}
2 changes: 0 additions & 2 deletions packages/web-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@
"devDependencies": {
"@microsoft/fast-element": "2.0.0",
"@tensile-perf/web-components": "~0.2.0",
"@storybook/html": "7.6.20",
"@storybook/html-webpack5": "7.6.20",
"chromedriver": "^125.0.0"
},
"dependencies": {
Expand Down
24 changes: 12 additions & 12 deletions packages/web-components/src/menu/menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test.describe('Menu', () => {
const element = page.locator('fluent-menu');
const menuList = element.locator('fluent-menu-list');

page.setContent(/* html */ `
await page.setContent(/* html */ `
<fluent-menu>
<fluent-menu-button appearance="primary" slot="trigger">Toggle Menu</fluent-menu-button>
<fluent-menu-list>
Expand All @@ -40,7 +40,7 @@ test.describe('Menu', () => {
const menuButton = element.locator('fluent-menu-button');
const menuList = element.locator('fluent-menu-list');

page.setContent(/* html */ `
await page.setContent(/* html */ `
<fluent-menu>
<fluent-menu-button appearance="primary" slot="trigger">Toggle Menu</fluent-menu-button>
<fluent-menu-list>
Expand All @@ -62,7 +62,7 @@ test.describe('Menu', () => {
const menuButton = element.locator('fluent-menu-button');
const menuList = element.locator('fluent-menu-list');

page.setContent(/* html */ `
await page.setContent(/* html */ `
<fluent-menu>
<fluent-menu-button appearance="primary" slot="trigger">Toggle Menu</fluent-menu-button>
<fluent-menu-list>
Expand All @@ -89,7 +89,7 @@ test.describe('Menu', () => {
const menuList = element.locator('fluent-menu-list');
const menuItems = menuList.locator('fluent-menu-item');

page.setContent(/* html */ `
await page.setContent(/* html */ `
<fluent-menu>
<fluent-menu-button appearance="primary" slot="trigger">Toggle Menu</fluent-menu-button>
<fluent-menu-list>
Expand All @@ -116,7 +116,7 @@ test.describe('Menu', () => {
const menuList = element.locator('fluent-menu-list');
const menuItems = menuList.locator('fluent-menu-item');

page.setContent(/* html */ `
await page.setContent(/* html */ `
<fluent-menu>
<fluent-menu-button appearance="primary" slot="trigger">Toggle Menu</fluent-menu-button>
<fluent-menu-list>
Expand Down Expand Up @@ -144,7 +144,7 @@ test.describe('Menu', () => {
const menuButton = element.locator('fluent-menu-button');
const menuList = element.locator('fluent-menu-list');

page.setContent(/* html */ `
await page.setContent(/* html */ `
<fluent-menu>
<fluent-menu-button appearance="primary" slot="trigger">Toggle Menu</fluent-menu-button>
<fluent-menu-list>
Expand All @@ -170,7 +170,7 @@ test.describe('Menu', () => {
const menuButton = element.locator('fluent-menu-button');
const menuList = element.locator('fluent-menu-list');

page.setContent(/* html */ `
await page.setContent(/* html */ `
<fluent-menu>
<fluent-menu-button appearance="primary" slot="trigger">Toggle Menu</fluent-menu-button>
<fluent-menu-list>
Expand All @@ -197,7 +197,7 @@ test.describe('Menu', () => {
const menuList = element.locator('fluent-menu-list');
const menuItems = menuList.locator('fluent-menu-item');

page.setContent(/* html */ `
await page.setContent(/* html */ `
<fluent-menu>
<fluent-menu-button appearance="primary" slot="trigger">Toggle Menu</fluent-menu-button>
<fluent-menu-list>
Expand Down Expand Up @@ -225,7 +225,7 @@ test.describe('Menu', () => {
const menuButton = element.locator('fluent-menu-button');
const menuList = element.locator('fluent-menu-list');

page.setContent(/* html */ `
await page.setContent(/* html */ `
<fluent-menu>
<fluent-menu-button appearance="primary" slot="trigger">Toggle Menu</fluent-menu-button>
<fluent-menu-list>
Expand Down Expand Up @@ -261,7 +261,7 @@ test.describe('Menu', () => {
const menuButton = element.locator('fluent-menu-button');
const menuList = element.locator('fluent-menu-list');

page.setContent(/* html */ `
await page.setContent(/* html */ `
<fluent-menu>
<fluent-menu-button appearance="primary" slot="trigger">Toggle Menu</fluent-menu-button>
<fluent-menu-list>
Expand Down Expand Up @@ -296,7 +296,7 @@ test.describe('Menu', () => {
const menuList = element.locator('fluent-menu-list');
const menuItems = menuList.locator('fluent-menu-item');

page.setContent(/* html */ `
await page.setContent(/* html */ `
<fluent-menu>
<fluent-menu-button appearance="primary" slot="trigger">Toggle Menu</fluent-menu-button>
<fluent-menu-list>
Expand Down Expand Up @@ -348,7 +348,7 @@ test.describe('Menu', () => {
const element = page.locator('fluent-menu');
const menuButton = element.locator('fluent-menu-button');

page.setContent(/* html */ `
await page.setContent(/* html */ `
<fluent-menu>
<fluent-menu-button appearance="primary" slot="trigger" icon-only></fluent-menu-button>
<fluent-button appearance="primary" slot="primary-action">Primary Action</fluent-menu-button>
Expand Down
Loading
Loading