Skip to content

Commit

Permalink
feat: generated react-dialog package (#20954)
Browse files Browse the repository at this point in the history
* feat: generated react-dialog package

* chore: run package migration

* fix: radio-dialog conformance

* docs: update react-dialog api docs
  • Loading branch information
varholak-peter authored Jan 3, 2022
1 parent 4035bf3 commit 25864f8
Show file tree
Hide file tree
Showing 39 changed files with 562 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ packages/react-button/ @microsoft/cxe-red @dzearing @khmakoto
packages/react-card/ @microsoft/cxe-prg
packages/react-checkbox/ @microsoft/cxe-red @khmakoto
packages/react-components/ @microsoft/teams-prg @microsoft/cxe-prg @microsoft/cxe-red
packages/react-dialog/ @microsoft/cxe-prg
packages/react-divider/ @microsoft/cxe-red @geoffcoxmsft
packages/react-focus/ @microsoft/cxe-red @khmakoto
packages/react-image/ @microsoft/cxe-prg
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ module.exports = {
'<rootDir>/packages/react-radio',
'<rootDir>/packages/react-spinbutton',
'<rootDir>/packages/react-tabs',
'<rootDir>/packages/react-dialog',
],
};
4 changes: 4 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@
"@fluentui/react-date-time": {
"implicitDependencies": []
},
"@fluentui/react-dialog": {
"tags": ["vNext", "platform:web"],
"implicitDependencies": []
},
"@fluentui/react-divider": {
"tags": ["vNext", "platform:web"],
"implicitDependencies": []
Expand Down
3 changes: 3 additions & 0 deletions packages/react-dialog/.babelrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["module:@fluentui/babel-make-styles", "annotate-pure-calls", "@babel/transform-react-pure-annotations"]
}
4 changes: 4 additions & 0 deletions packages/react-dialog/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": ["plugin:@fluentui/eslint-plugin/react"],
"root": true
}
28 changes: 28 additions & 0 deletions packages/react-dialog/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.storybook/
.vscode/
bundle-size/
config/
coverage/
e2e/
etc/
node_modules/
src/
temp/
__fixtures__
__mocks__
__tests__

*.api.json
*.log
*.spec.*
*.stories.*
*.test.*
*.yml

# config files
*config.*
*rc.*
.editorconfig
.eslint*
.git*
.prettierignore
14 changes: 14 additions & 0 deletions packages/react-dialog/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const rootMain = require('../../../.storybook/main');

module.exports = /** @type {Omit<import('../../../.storybook/main'), 'typescript'|'babel'>} */ ({
...rootMain,
stories: [...rootMain.stories, '../src/**/*.stories.mdx', '../src/**/*.stories.@(ts|tsx)'],
addons: [...rootMain.addons],
webpackFinal: (config, options) => {
const localConfig = { ...rootMain.webpackFinal(config, options) };

// add your own webpack tweaks if needed

return localConfig;
},
});
7 changes: 7 additions & 0 deletions packages/react-dialog/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as rootPreview from '../../../.storybook/preview';

/** @type {typeof rootPreview.decorators} */
export const decorators = [...rootPreview.decorators];

/** @type {typeof rootPreview.parameters} */
export const parameters = { ...rootPreview.parameters };
10 changes: 10 additions & 0 deletions packages/react-dialog/.storybook/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "",
"allowJs": true,
"checkJs": true,
"types": ["static-assets", "environment", "inline-style-expand-shorthand", "storybook__addons"]
},
"include": ["../src/**/*.stories.ts", "../src/**/*.stories.tsx", "*.js"]
}
15 changes: 15 additions & 0 deletions packages/react-dialog/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@fluentui/react-dialog

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
5 changes: 5 additions & 0 deletions packages/react-dialog/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @fluentui/react-dialog

**React Dialog components for [Fluent UI React](https://developer.microsoft.com/en-us/fluentui)**

These are not production-ready components and **should never be used in product**. This space is useful for testing new components whose APIs might change before final release.
63 changes: 63 additions & 0 deletions packages/react-dialog/Spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# @fluentui/react-dialog Spec

## Background

_Description and use cases of this component_

## Prior Art

_Include background research done for this component_

- _Link to Open UI research_
- _Link to comparison of v7 and v0_
- _Link to GitHub epic issue for the converged component_

## Sample Code

_Provide some representative example code that uses the proposed API for the component_

## Variants

_Describe visual or functional variants of this control, if applicable. For example, a slider could have a 2D variant._

## API

_List the **Props** and **Slots** proposed for the component. Ideally this would just be a link to the component's `.types.ts` file_

## Structure

- _**Public**_
- _**Internal**_
- _**DOM** - how the component will be rendered as HTML elements_

## Migration

_Describe what will need to be done to upgrade from the existing implementations:_

- _Migration from v8_
- _Migration from v0_

## Behaviors

_Explain how the component will behave in use, including:_

- _Component States_
- _Interaction_
- _Keyboard_
- _Cursor_
- _Touch_
- _Screen readers_

## Accessibility

Base accessibility information is included in the design document. After the spec is filled and review, outcomes from it need to be communicated to design and incorporated in the design document.

- Decide whether to use **native element** or folow **ARIA** and provide reasons
- Identify the **[ARIA](https://www.w3.org/TR/wai-aria-practices-1.2/) pattern** and, if the component is listed there, follow its specification as possible.
- Identify accessibility **variants**, the `role` ([ARIA roles](https://www.w3.org/TR/wai-aria-1.1/#role_definitions)) of the component, its `slots` and `aria-*` props.
- Describe the **keyboard navigation**: Tab Oder and Arrow Key Navigation. Describe any other keyboard **shortcuts** used
- Specify texts for **state change announcements** - [ARIA live regions
](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions) (number of available items in dropdown, error messages, confirmations, ...)
- Identify UI parts that appear on **hover or focus** and specify keyboard and screen reader interaction with them
- List cases when **focus** needs to be **trapped** in sections of the UI (for dialogs and popups or for hierarchical navigation)
- List cases when **focus** needs to be **moved programatically** (if parts of the UI are appearing/disappearing or other cases)
4 changes: 4 additions & 0 deletions packages/react-dialog/config/api-extractor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"extends": "@fluentui/scripts/api-extractor/api-extractor.common.json"
}
5 changes: 5 additions & 0 deletions packages/react-dialog/config/api-extractor.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"extends": "./api-extractor.json",
"mainEntryPointFilePath": "<projectFolder>/dist/packages/<unscopedPackageName>/src/index.d.ts"
}
7 changes: 7 additions & 0 deletions packages/react-dialog/config/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** Jest test setup file. */

const { configure } = require('enzyme');
const Adapter = require('enzyme-adapter-react-16');

// Configure enzyme.
configure({ adapter: new Adapter() });
47 changes: 47 additions & 0 deletions packages/react-dialog/etc/react-dialog.api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
## API Report File for "@fluentui/react-dialog"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts

import type { ComponentProps } from '@fluentui/react-utilities';
import type { ComponentState } from '@fluentui/react-utilities';
import type { ForwardRefComponent } from '@fluentui/react-utilities';
import type { IntrinsicShorthandProps } from '@fluentui/react-utilities';
import * as React_2 from 'react';

// @public
export const Dialog: ForwardRefComponent<DialogProps>;

// @public (undocumented)
export const dialogClassName = "fui-Dialog";

// @public (undocumented)
export type DialogCommons = {};

// @public
export type DialogProps = ComponentProps<DialogSlots> & DialogCommons;

// @public
export const dialogShorthandProps: (keyof DialogSlots)[];

// @public (undocumented)
export type DialogSlots = {
root: IntrinsicShorthandProps<'div'>;
};

// @public
export type DialogState = ComponentState<DialogSlots> & DialogCommons;

// @public
export const renderDialog: (state: DialogState) => JSX.Element;

// @public
export const useDialog: (props: DialogProps, ref: React_2.Ref<HTMLElement>) => DialogState;

// @public
export const useDialogStyles: (state: DialogState) => DialogState;

// (No @packageDocumentation comment for this package)

```
21 changes: 21 additions & 0 deletions packages/react-dialog/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// @ts-check

/**
* @type {jest.InitialOptions}
*/
module.exports = {
displayName: 'react-dialog',
preset: '../../jest.preset.js',
globals: {
'ts-jest': {
tsConfig: '<rootDir>/tsconfig.spec.json',
diagnostics: false,
},
},
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
coverageDirectory: './coverage',
setupFilesAfterEnv: ['./config/tests.js'],
snapshotSerializers: ['@fluentui/jest-serializer-make-styles'],
};
3 changes: 3 additions & 0 deletions packages/react-dialog/just.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { preset } from '@fluentui/scripts';

preset();
64 changes: 64 additions & 0 deletions packages/react-dialog/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"name": "@fluentui/react-dialog",
"version": "9.0.0-beta.5",
"private": true,
"description": "Dialog component for Fluent UI React",
"main": "lib-commonjs/index.js",
"module": "lib/index.js",
"typings": "lib/index.d.ts",
"sideEffects": false,
"repository": {
"type": "git",
"url": "https://github.com/microsoft/fluentui"
},
"license": "MIT",
"scripts": {
"build": "just-scripts build",
"clean": "just-scripts clean",
"code-style": "just-scripts code-style",
"just": "just-scripts",
"lint": "just-scripts lint",
"start": "yarn storybook",
"test": "jest --passWithNoTests",
"docs": "api-extractor run --config=config/api-extractor.local.json --local",
"build:local": "tsc -p ./tsconfig.lib.json --module esnext --emitDeclarationOnly && node ../../scripts/typescript/normalize-import --output ./dist/packages/react-dialog/src && yarn docs",
"storybook": "start-storybook",
"type-check": "tsc -b tsconfig.json"
},
"devDependencies": {
"@fluentui/babel-make-styles": "9.0.0-beta.4",
"@fluentui/eslint-plugin": "*",
"@fluentui/jest-serializer-make-styles": "9.0.0-beta.4",
"@fluentui/react-conformance": "*",
"@fluentui/react-conformance-make-styles": "9.0.0-beta.4",
"@fluentui/scripts": "^1.0.0",
"@types/enzyme": "3.10.3",
"@types/enzyme-adapter-react-16": "1.0.3",
"@types/react": "16.9.42",
"@types/react-dom": "16.9.10",
"@types/react-test-renderer": "^16.0.0",
"enzyme": "~3.10.0",
"enzyme-adapter-react-16": "^1.15.0",
"react": "16.8.6",
"react-dom": "16.8.6",
"react-test-renderer": "^16.3.0"
},
"dependencies": {
"@fluentui/react-make-styles": "9.0.0-beta.4",
"@fluentui/react-utilities": "9.0.0-beta.4",
"tslib": "^2.1.0"
},
"peerDependencies": {
"@types/react": ">=16.8.0 <18.0.0",
"@types/react-dom": ">=16.8.0 <18.0.0",
"react": ">=16.8.0 <18.0.0",
"react-dom": ">=16.8.0 <18.0.0"
},
"beachball": {
"disallowedChangeTypes": [
"major",
"minor",
"patch"
]
}
}
1 change: 1 addition & 0 deletions packages/react-dialog/src/Dialog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './components/Dialog/index';
15 changes: 15 additions & 0 deletions packages/react-dialog/src/common/isConformant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { isConformant as baseIsConformant } from '@fluentui/react-conformance';
import type { IsConformantOptions, TestObject } from '@fluentui/react-conformance';
import makeStylesTests from '@fluentui/react-conformance-make-styles';

export function isConformant<TProps = {}>(
testInfo: Omit<IsConformantOptions<TProps>, 'componentPath'> & { componentPath?: string },
) {
const defaultOptions: Partial<IsConformantOptions<TProps>> = {
asPropHandlesRef: true,
componentPath: module!.parent!.filename.replace('.test', ''),
extraTests: makeStylesTests as TestObject<TProps>,
};

baseIsConformant(defaultOptions, testInfo);
}
18 changes: 18 additions & 0 deletions packages/react-dialog/src/components/Dialog/Dialog.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as React from 'react';
import { render } from '@testing-library/react';
import { Dialog } from './Dialog';
import { isConformant } from '../../common/isConformant';

describe('Dialog', () => {
isConformant({
Component: Dialog,
displayName: 'Dialog',
});

// TODO add more tests here, and create visual regression tests in /apps/vr-tests

it('renders a default state', () => {
const result = render(<Dialog>Default Dialog</Dialog>);
expect(result.container).toMatchSnapshot();
});
});
18 changes: 18 additions & 0 deletions packages/react-dialog/src/components/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as React from 'react';
import { useDialog } from './useDialog';
import { renderDialog } from './renderDialog';
import { useDialogStyles } from './useDialogStyles';
import type { DialogProps } from './Dialog.types';
import type { ForwardRefComponent } from '@fluentui/react-utilities';

/**
* A Dialog is an elevated Card triggered by a user’s action.
*/
export const Dialog: ForwardRefComponent<DialogProps> = React.forwardRef((props, ref) => {
const state = useDialog(props, ref);

useDialogStyles(state);
return renderDialog(state);
});

Dialog.displayName = 'Dialog';
Loading

0 comments on commit 25864f8

Please sign in to comment.