Skip to content
Merged
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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ packages/react-components/react-breadcrumb/stories @microsoft/cxe-prg
packages/react-components/react-drawer/library @microsoft/cxe-prg @mainframev
packages/react-components/react-drawer/stories @microsoft/cxe-prg @mainframev
packages/react-components/react-storybook-addon-export-to-sandbox @microsoft/fluentui-react-build
packages/react-components/react-storybook-addon-playground @microsoft/fluentui-react-build
packages/react-components/babel-preset-storybook-full-source @microsoft/fluentui-react-build
packages/react-components/react-jsx-runtime @microsoft/teams-prg
packages/react-components/react-toast/library @microsoft/teams-prg
Expand Down
1 change: 1 addition & 0 deletions apps/public-docsite-v9-headless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@fluentui/react-headless-components-preview": "*",
"@fluentui/react-storybook-addon": "*",
"@fluentui/react-storybook-addon-export-to-sandbox": "*",
"@fluentui/react-storybook-addon-playground": "*",
"react": "19.2.0",
"react-dom": "19.2.0",
"tslib": "^2.1.0"
Expand Down
16 changes: 14 additions & 2 deletions apps/public-docsite-v9-headless/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,27 @@
"build-storybook": {
"dependsOn": [
{
"projects": ["react-storybook-addon", "react-storybook-addon-export-to-sandbox", "storybook-llms-extractor"],
"projects": [
"react-headless-components-preview",
"react-storybook-addon",
"react-storybook-addon-export-to-sandbox",
"react-storybook-addon-playground",
"storybook-llms-extractor"
],
"target": "build"
}
]
},
"build-storybook:docsite": {
"dependsOn": [
{
"projects": ["react-storybook-addon", "react-storybook-addon-export-to-sandbox", "storybook-llms-extractor"],
"projects": [
"react-headless-components-preview",
"react-storybook-addon",
"react-storybook-addon-export-to-sandbox",
"react-storybook-addon-playground",
"storybook-llms-extractor"
],
"target": "build"
}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "patch",
"comment": "fix: ignore buttons added by the playground addon when locating the Show code toggle",
"packageName": "@fluentui/react-storybook-addon-export-to-sandbox",
"email": "dmytrokirpa@microsoft.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "patch",
"comment": "feat: add @fluentui/react-storybook-addon-playground package scaffold",
"packageName": "@fluentui/react-storybook-addon-playground",
"email": "dmytrokirpa@microsoft.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module '*.css';
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,55 @@ const {
processBabelLoaderOptions,
} = require('@fluentui/scripts-storybook');
const { registerCssModuleRules } = require('./css-modules-webpack');
const headlessPackageJson = require('../../library/package.json');

const repoRoot = path.resolve(__dirname, '../../../../..');
const tsConfigPath = path.resolve(repoRoot, 'tsconfig.base.json');
const HEADLESS_PACKAGE_NAME = '@fluentui/react-headless-components-preview';

/**
* Headless Storybook replaces the root sandbox addon with a CSS-modules-aware one, and registers
* the playground here only (not on the shared v9 Storybook).
*
* @param {string | { name?: string }} addon
*/
function isNotExportToSandboxAddon(addon) {
function isNotRootSandboxOrPlaygroundAddon(addon) {
const name = typeof addon === 'string' ? addon : addon?.name ?? '';
return !name.includes('react-storybook-addon-export-to-sandbox');
return (
!name.includes('react-storybook-addon-export-to-sandbox') && !name.includes('react-storybook-addon-playground')
);
}

/**
* Maps every published subpath of the headless package (plus react-icons) into the playground allowlist.
* Skips `.` — the barrel is empty, and Storybook only has a tsconfig path for `package/*` (source),
* not the package root (built `lib/index.js`, which CI `build-storybook` does not produce).
*
* @returns {Record<string, string>}
*/
function getHeadlessPlaygroundModules() {
/** @type {Record<string, string>} */
const modules = {
'@fluentui/react-icons': '@fluentui/react-icons',
};

for (const exportPath of Object.keys(headlessPackageJson.exports ?? {})) {
if (exportPath === '.' || exportPath === './package.json') {
continue;
}

const specifier = `${HEADLESS_PACKAGE_NAME}${exportPath.slice(1)}`;
modules[specifier] = specifier;
}

return modules;
}

module.exports = /** @type {Omit<import('../../../../../.storybook/main'), 'typescript'|'babel'>} */ ({
...rootMain,
stories: [...rootMain.stories, '../src/**/*.mdx', '../src/**/index.stories.@(ts|tsx)'],
addons: [
...rootMain.addons.filter(isNotExportToSandboxAddon),
...rootMain.addons.filter(isNotRootSandboxOrPlaygroundAddon),
loadWorkspaceAddon('@fluentui/react-storybook-addon-export-to-sandbox', {
tsConfigPath,
/** @type {import('../../../react-storybook-addon-export-to-sandbox/src/index').PresetConfig} */
Expand All @@ -37,6 +69,15 @@ module.exports = /** @type {Omit<import('../../../../../.storybook/main'), 'type
},
},
}),
/** {@link file://./../../../react-storybook-addon-playground/package.json} */
loadWorkspaceAddon('@fluentui/react-storybook-addon-playground', {
tsConfigPath,
/** @type {import('../../../react-storybook-addon-playground/src/index').PresetConfig} */
options: {
modules: getHeadlessPlaygroundModules(),
setup: path.resolve(__dirname, './playground.setup.tsx'),
},
}),
],
webpackFinal: (config, options) => {
const localConfig = /** @type {any} */ ({ ...rootMain.webpackFinal(config, options) });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import * as React from 'react';
import { polyfillBodyAndObserve } from '@microsoft/focusgroup-polyfill/shadowless';
import { Provider } from '@fluentui/react-headless-components-preview/provider';
import { definePlaygroundSetup } from '@fluentui/react-storybook-addon-playground/setup';

import './tokens.css';

polyfillBodyAndObserve();

type HeadlessPlaygroundTheme = 'light' | 'dark';

const defaultCode = `import * as React from 'react';
import { Button } from '@fluentui/react-headless-components-preview/button';

export default () => {
const [count, setCount] = React.useState(0);

return (
<Button
onClick={() => setCount(count + 1)}
style={{
height: 32,
padding: '0 14px',
border: 0,
borderRadius: 999,
background: 'var(--accent)',
color: 'var(--accent-contrast)',
cursor: 'pointer',
}}
>
Clicked {count} times
</Button>
);
};
`;

export default definePlaygroundSetup<HeadlessPlaygroundTheme>({
title: 'Fluent UI Playground',
subtitle: 'Headless',
defaultCode,
themes: [
{ id: 'light', label: 'Light', value: 'light', dark: false },
{ id: 'dark', label: 'Dark', value: 'dark', dark: true },
],
render: ({ Component, theme }) => (
<Provider>
<div data-theme={theme ?? 'light'} style={{ minHeight: '100%', background: 'var(--bg)', color: 'var(--text)' }}>
<Component />
</div>
</Provider>
),
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { polyfillBodyAndObserve } from '@microsoft/focusgroup-polyfill/shadowless';
import '../../../react-storybook-addon-playground/src/styles.css';

import * as rootPreview from '../../../../../.storybook/preview';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"moduleResolution": "bundler",
"types": ["static-assets", "environment"]
},
"include": ["*.js"]
"include": ["*.js", "*.tsx", "*.d.ts"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,23 @@
"projectType": "library",
"sourceRoot": "packages/react-components/react-headless-components-preview/stories/src",
"tags": ["vNext", "platform:web", "type:stories", "react-headless"],
"implicitDependencies": []
"implicitDependencies": [],
"targets": {
"storybook": {
"dependsOn": [
{
"projects": ["react-headless-components-preview", "react-storybook-addon-playground"],
"target": "build"
}
]
},
"build-storybook": {
"dependsOn": [
{
"projects": ["react-headless-components-preview", "react-storybook-addon-playground"],
"target": "build"
}
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ export function prepareSandboxContainers(context: StoryContext) {
}

return Array.from(rootElements).map(rootElement => {
// Exclude buttons added by this addon and by @fluentui/react-storybook-addon-playground
const showCodeButton = rootElement.querySelector(
'.docblock-code-toggle:not(.with-code-sandbox-button):not(.with-open-in-new-tab-button)',
'.docblock-code-toggle:not(.with-code-sandbox-button):not(.with-open-in-new-tab-button):not(.with-open-in-playground-button)',
);
const container = showCodeButton?.parentElement;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["annotate-pure-calls", "@babel/transform-react-pure-annotations"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"exclude": [
"/testing",
"/**/*.cy.ts",
"/**/*.cy.tsx",
"/**/*.spec.ts",
"/**/*.spec.tsx",
"/**/*.test.ts",
"/**/*.test.tsx",
"/**/src/playground/**"
],
"jsc": {
"baseUrl": ".",
"parser": {
"syntax": "typescript",
"tsx": true,
"decorators": false,
"dynamicImport": false
},
"externalHelpers": true,
"transform": {
"react": {
"runtime": "classic",
"useSpread": true
},
"optimizer": {
"simplify": true
}
},
"target": "es2019"
},
"minify": false,
"sourceMaps": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@fluentui/react-storybook-addon-playground

Copyright (c) Microsoft Corporation

All rights reserved.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note: Usage of the fonts and icons referenced in Fluent UI React is subject to the terms listed at https://aka.ms/fluentui-assets-license
Loading
Loading