diff --git a/change/@fluentui-react-button-1b2e69bc-f82f-49a8-a211-b843e3bef591.json b/change/@fluentui-react-button-1b2e69bc-f82f-49a8-a211-b843e3bef591.json new file mode 100644 index 00000000000000..7798f21e352731 --- /dev/null +++ b/change/@fluentui-react-button-1b2e69bc-f82f-49a8-a211-b843e3bef591.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Button: Migrate to new dx", + "packageName": "@fluentui/react-button", + "email": "tristan.watanabe@gmail.com", + "dependentChangeType": "patch" +} diff --git a/change/@fluentui-react-examples-28ae56c7-be37-496c-a550-ccfd1b3180c6.json b/change/@fluentui-react-examples-28ae56c7-be37-496c-a550-ccfd1b3180c6.json new file mode 100644 index 00000000000000..eaa823b99844a7 --- /dev/null +++ b/change/@fluentui-react-examples-28ae56c7-be37-496c-a550-ccfd1b3180c6.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "Button: Migrate to new dx", + "packageName": "@fluentui/react-examples", + "email": "tristan.watanabe@gmail.com", + "dependentChangeType": "patch" +} diff --git a/jest.config.js b/jest.config.js index f8e81fbc426d0f..383b2a34ced9a6 100644 --- a/jest.config.js +++ b/jest.config.js @@ -25,6 +25,7 @@ module.exports = { '/packages/react-utilities', '/packages/react-theme', '/packages/react-badge', + '/packages/react-button', '/packages/keyboard-keys', '/packages/react-slider', '/packages/make-styles-webpack-loader', diff --git a/nx.json b/nx.json index 4c7ba658614432..35f0c511ed029c 100644 --- a/nx.json +++ b/nx.json @@ -77,7 +77,7 @@ "@fluentui/react-accordion": { "tags": ["vNext"], "implicitDependencies": [] }, "@fluentui/react-avatar": { "tags": ["vNext", "platform:web"], "implicitDependencies": [] }, "@fluentui/react-badge": { "tags": ["vNext", "platform:web"], "implicitDependencies": [] }, - "@fluentui/react-button": { "implicitDependencies": [] }, + "@fluentui/react-button": { "tags": ["vNext", "platform:web"], "implicitDependencies": [] }, "@fluentui/react-card": { "implicitDependencies": [] }, "@fluentui/react-cards": { "implicitDependencies": [] }, "@fluentui/react-charting": { "implicitDependencies": [] }, diff --git a/packages/react-button/.storybook/main.js b/packages/react-button/.storybook/main.js new file mode 100644 index 00000000000000..f47245f2d07f01 --- /dev/null +++ b/packages/react-button/.storybook/main.js @@ -0,0 +1,11 @@ +const rootMain = require('../../../.storybook/main'); + +module.exports = /** @type {Pick} */ ({ + stories: [...rootMain.stories, '../src/**/*.stories.mdx', '../src/**/*.stories.@(ts|tsx)'], + addons: [...rootMain.addons], + webpackFinal: (config, options) => { + const localConfig = { ...rootMain.webpackFinal(config, options) }; + + return localConfig; + }, +}); diff --git a/packages/react-button/.storybook/preview.js b/packages/react-button/.storybook/preview.js new file mode 100644 index 00000000000000..b52409294c3304 --- /dev/null +++ b/packages/react-button/.storybook/preview.js @@ -0,0 +1,3 @@ +import * as rootPreview from '../../../.storybook/preview'; + +export const decorators = [...rootPreview.decorators]; diff --git a/packages/react-button/.storybook/tsconfig.json b/packages/react-button/.storybook/tsconfig.json new file mode 100644 index 00000000000000..3bd9adcd2ee05e --- /dev/null +++ b/packages/react-button/.storybook/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "allowJs": true, + "checkJs": true + }, + "exclude": ["../**/*.test.ts", "../**/*.test.js", "../**/*.test.tsx", "../**/*.test.jsx"], + "include": ["../src/**/*", "*.js"] +} diff --git a/packages/react-button/config/api-extractor.local.json b/packages/react-button/config/api-extractor.local.json new file mode 100644 index 00000000000000..c2ea401c1c3685 --- /dev/null +++ b/packages/react-button/config/api-extractor.local.json @@ -0,0 +1,5 @@ +{ + "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", + "extends": "./api-extractor.json", + "mainEntryPointFilePath": "/dist//src/index.d.ts" +} diff --git a/packages/react-button/jest.config.js b/packages/react-button/jest.config.js index c2a9e205df8e6d..4a890cb7c1bc1e 100644 --- a/packages/react-button/jest.config.js +++ b/packages/react-button/jest.config.js @@ -1,9 +1,21 @@ -const { createConfig } = require('@fluentui/scripts/jest/jest-resources'); -const path = require('path'); +// @ts-check -const config = createConfig({ - setupFiles: [path.resolve(path.join(__dirname, 'config', 'tests.js'))], +/** + * @type {jest.InitialOptions} + */ +module.exports = { + displayName: 'react-button', + preset: '../../jest.preset.js', + globals: { + 'ts-jest': { + tsConfig: '/tsconfig.json', + diagnostics: false, + }, + }, + transform: { + '^.+\\.tsx?$': 'ts-jest', + }, + coverageDirectory: './coverage', + setupFilesAfterEnv: ['./config/tests.js'], snapshotSerializers: ['@fluentui/jest-serializer-make-styles'], -}); - -module.exports = config; +}; diff --git a/packages/react-button/package.json b/packages/react-button/package.json index 51379bbd43a625..46c24c138a09fb 100644 --- a/packages/react-button/package.json +++ b/packages/react-button/package.json @@ -17,10 +17,11 @@ "code-style": "just-scripts code-style", "just": "just-scripts", "lint": "just-scripts lint", - "start": "just-scripts dev:storybook", - "start-test": "just-scripts jest-watch", - "test": "just-scripts test", - "update-snapshots": "just-scripts jest -u" + "start": "yarn storybook", + "test": "jest", + "docs": "api-extractor run --config=config/api-extractor.local.json --local", + "build:local": "tsc -p . --module esnext --emitDeclarationOnly && node ../../scripts/typescript/normalize-import --output dist/packages/react-button/src && yarn docs", + "storybook": "start-storybook" }, "devDependencies": { "@fluentui/a11y-testing": "^0.1.0", diff --git a/packages/react-examples/src/react-button/Button/Button.stories.tsx b/packages/react-button/src/Button.stories.tsx similarity index 65% rename from packages/react-examples/src/react-button/Button/Button.stories.tsx rename to packages/react-button/src/Button.stories.tsx index ce064f21541a7a..d1c6754cf9e7d8 100644 --- a/packages/react-examples/src/react-button/Button/Button.stories.tsx +++ b/packages/react-button/src/Button.stories.tsx @@ -1,7 +1,8 @@ import * as React from 'react'; -import { Button, ButtonProps } from '@fluentui/react-button'; -import { Playground } from '../Playground'; -import { PlaygroundProps, PropDefinition } from '../Playground.types'; +import { Button, ButtonProps } from './Button'; +import { Playground } from './Playground.stories'; +import { PlaygroundProps } from './Playground.types.stories'; +import { buttonBaseProps } from './buttonBaseProps.stories'; // TODO: this is here while waiting for react-icons to merge const SVGIcon = () => ( @@ -101,29 +102,6 @@ export const Disabled = () => ( ); -type ExampleProps = { iconOnly?: string }; - -export const buttonBaseProps: PropDefinition[] = [ - { propName: 'block', propType: 'boolean' }, - { propName: 'circular', propType: 'boolean' }, - { propName: 'content', propType: 'string', defaultValue: 'This is a button', dependsOnProps: ['~iconOnly'] }, - { propName: 'disabled', propType: 'boolean', dependsOnProps: ['~disabledFocusable'] }, - { propName: 'disabledFocusable', propType: 'boolean', dependsOnProps: ['~disabled'] }, - { propName: 'icon', propType: 'boolean' }, - { propName: 'iconOnly', propType: 'boolean', dependsOnProps: ['icon'] }, - { - propName: 'iconPosition', - propType: ['before', 'after'], - defaultValue: 'before', - dependsOnProps: ['icon', '~iconOnly'], - }, - { propName: 'outline', propType: 'boolean', dependsOnProps: ['~primary', '~subtle', '~transparent'] }, - { propName: 'primary', propType: 'boolean', dependsOnProps: ['~outline', '~subtle', '~transparent'] }, - { propName: 'size', propType: ['small', 'medium', 'large'], defaultValue: 'medium' }, - { propName: 'subtle', propType: 'boolean', dependsOnProps: ['~outline', '~primary', '~transparent'] }, - { propName: 'transparent', propType: 'boolean', dependsOnProps: ['~outline', '~primary', '~subtle'] }, -]; - const buttonProps: PlaygroundProps['sections'] = [ { sectionName: 'Button props', propList: buttonBaseProps }, ]; @@ -133,3 +111,8 @@ export const ButtonPlayground = () => (