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

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
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 @@
{
Copy link
Collaborator

@fabricteam fabricteam Nov 19, 2024

Choose a reason for hiding this comment

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

🕵🏾‍♀️ visual regressions to review in the fluentuiv8 Visual Regression Report

Callout 2 screenshots
Image Name Diff(in Pixels) Image Type
Callout.Left center.chromium.png 2616 Changed
Callout.Root.chromium.png 2309 Changed
react-charting-AreaChart 1 screenshots
Image Name Diff(in Pixels) Image Type
react-charting-AreaChart.Custom Accessibility.chromium.png 11 Changed
react-charting-LineChart 1 screenshots
Image Name Diff(in Pixels) Image Type
react-charting-LineChart.Gaps.chromium.png 1 Changed

Copy link
Collaborator

@fabricteam fabricteam Nov 19, 2024

Choose a reason for hiding this comment

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

🕵🏾‍♀️ visual regressions to review in the fluentuiv9 Visual Regression Report

Avatar Converged 1 screenshots
Image Name Diff(in Pixels) Image Type
Avatar Converged.badgeMask.chromium.png 18 Changed
Drawer 1 screenshots
Image Name Diff(in Pixels) Image Type
Drawer.Full Overlay High Contrast.chromium.png 2239 Changed

"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.0",
"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.2.2",
"vinyl": "2.2.0",
"vite": "5.4.11",
"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.0",
"eslint": "8.57.0",
"swc-loader": "^0.2.6",
"prettier": "2.8.8",
Expand Down
10 changes: 9 additions & 1 deletion packages/web-components/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,13 @@
// TODO: I think we can come up with a regex that ignores variables with __ in them
}
]
}
},
"overrides": [
{
"files": ["**/*.json"],
"rules": {
"@typescript-eslint/no-unused-expressions": "off"
}
}
]
}
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
2 changes: 1 addition & 1 deletion packages/web-components/src/tablist/tablist.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ test.describe('Tablist', () => {
const element = page.locator('fluent-tablist');
const tabs = element.locator('fluent-tab');

page.setContent(/* html */ `
await page.setContent(/* html */ `
<fluent-tablist>
<fluent-tab>Tab one</fluent-tab>
<fluent-tab>Tab two</fluent-tab>
Expand Down
77 changes: 41 additions & 36 deletions packages/web-components/src/tooltip/tooltip.stories.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { html, render, repeat } from '@microsoft/fast-element';
import { html, repeat } from '@microsoft/fast-element';
import { uniqueId } from '@microsoft/fast-web-utilities';
import { Meta, renderComponent, Story } from '../helpers.stories.js';
import { type Meta, renderComponent, type StoryObj } from '../helpers.stories.js';
import { definition } from './tooltip.definition.js';
import { Tooltip } from './tooltip.js';
import type { Tooltip } from './tooltip.js';
import { TooltipPositioningOption } from './tooltip.options.js';

type Story = StoryObj<Tooltip>;

const storyTemplate = () => {
const id = uniqueId('anchor-');

Expand Down Expand Up @@ -48,13 +50,12 @@ export default {
},
},
},
} as unknown as Meta<Tooltip>;
} as Meta<Tooltip>;

export const Default: Story<Tooltip> = args => {
return renderComponent(html`${render(args, storyTemplate)}`)(args);
};
Default.args = {
slottedContent: () => html`Really long tooltip content goes here. lorem ipsum dolor sit amet.`,
export const Default: Story = {
args: {
slottedContent: () => html`Really long tooltip content goes here. lorem ipsum dolor sit amet.`,
},
};

const iconArrowRight = (rotation = 0) => html`<svg
Expand Down Expand Up @@ -121,32 +122,36 @@ const positionTooltipTemplate = html`
<fluent-tooltip anchor="btn-${x => x.id}" positioning="${x => x.id}"> ${x => x.id} </fluent-tooltip>
`;

export const Positioning: Story<Tooltip> = renderComponent(html`
<div>
<style>
.grid {
box-sizing: border-box;
display: grid;
gap: 4px;
max-width: min-content;
grid-template-areas:
'. above-start above above-end .'
'before-top . . . after-top'
'before . . . after'
'before-bottom . . . after-bottom'
'. below-start below below-end .';
}
.grid fluent-button {
aspect-ratio: 1;
min-width: 44px;
}
</style>
<div class="grid">${repeat(x => x.storyItems, positionButtonTemplate)}</div>

${repeat(x => x.storyItems, positionTooltipTemplate)}
</div>
`).bind({});
export const Positioning: Story = {
parameters: {
layout: 'centered',
},
render: renderComponent(html`
<div>
<style>
.grid {
box-sizing: border-box;
display: grid;
gap: 4px;
max-width: min-content;
grid-template-areas:
'. above-start above above-end .'
'before-top . . . after-top'
'before . . . after'
'before-bottom . . . after-bottom'
'. below-start below below-end .';
}
.grid fluent-button {
aspect-ratio: 1;
min-width: 44px;
}
</style>
<div class="grid">${repeat(x => x.storyItems, positionButtonTemplate)}</div>

Positioning.args = {
storyItems: Object.keys(TooltipPositioningOption).map(id => ({ id })),
${repeat(x => x.storyItems, positionTooltipTemplate)}
</div>
`),
args: {
storyItems: Object.keys(TooltipPositioningOption).map(id => ({ id })),
},
};
Loading
Loading