-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Scaffolding Nav component #28824
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
Scaffolding Nav component #28824
Changes from 3 commits
5d9c04f
1f6441d
049800c
e2a8b94
83d55e2
6255fe7
ce61309
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "presets": ["@griffel"], | ||
| "plugins": ["annotate-pure-calls", "@babel/transform-react-pure-annotations"] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "extends": ["plugin:@fluentui/eslint-plugin/react"], | ||
| "root": true | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| .storybook/ | ||
| .vscode/ | ||
| bundle-size/ | ||
| config/ | ||
| coverage/ | ||
| docs/ | ||
| etc/ | ||
| node_modules/ | ||
| src/ | ||
| stories/ | ||
| dist/types/ | ||
| temp/ | ||
| __fixtures__ | ||
| __mocks__ | ||
| __tests__ | ||
|
|
||
| *.api.json | ||
| *.log | ||
| *.spec.* | ||
| *.cy.* | ||
| *.test.* | ||
| *.yml | ||
|
|
||
| # config files | ||
| *config.* | ||
| *rc.* | ||
| .editorconfig | ||
| .eslint* | ||
| .git* | ||
| .prettierignore |
| 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, '../stories/**/*.stories.mdx', '../stories/**/index.stories.@(ts|tsx)'], | ||
| addons: [...rootMain.addons], | ||
| webpackFinal: (config, options) => { | ||
| const localConfig = { ...rootMain.webpackFinal(config, options) }; | ||
|
|
||
| // add your own webpack tweaks if needed | ||
|
|
||
| return localConfig; | ||
| }, | ||
| }); |
| 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 }; |
| 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", "storybook__addons"] | ||
| }, | ||
| "include": ["../stories/**/*.stories.ts", "../stories/**/*.stories.tsx", "*.js"] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| @fluentui/react-nav | ||
|
|
||
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # @fluentui/react-nav | ||
|
|
||
| **React Nav components for [Fluent UI React](https://react.fluentui.dev/)** | ||
|
|
||
| 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. |
| 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.v-next.json" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /** Jest test setup file. */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # @fluentui/react-nav 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) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| ## API Report File for "@fluentui/react-nav" | ||
|
|
||
| > 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 * as React_2 from 'react'; | ||
| import type { Slot } from '@fluentui/react-utilities'; | ||
| import type { SlotClassNames } from '@fluentui/react-utilities'; | ||
|
|
||
| // @public | ||
| export const Nav: ForwardRefComponent<NavProps>; | ||
|
|
||
| // @public (undocumented) | ||
| export const navClassNames: SlotClassNames<NavSlots>; | ||
|
|
||
| // @public | ||
| export type NavProps = ComponentProps<NavSlots> & {}; | ||
|
|
||
| // @public (undocumented) | ||
| export type NavSlots = { | ||
| root: Slot<'div'>; | ||
| }; | ||
|
|
||
| // @public | ||
| export type NavState = ComponentState<NavSlots>; | ||
|
|
||
| // @public | ||
| export const renderNav_unstable: (state: NavState) => JSX.Element; | ||
|
|
||
| // @public | ||
| export const useNav_unstable: (props: NavProps, ref: React_2.Ref<HTMLElement>) => NavState; | ||
|
|
||
| // @public | ||
| export const useNavStyles_unstable: (state: NavState) => NavState; | ||
|
|
||
| // (No @packageDocumentation comment for this package) | ||
|
|
||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // @ts-check | ||
|
|
||
| /** | ||
| * @type {import('@jest/types').Config.InitialOptions} | ||
| */ | ||
| module.exports = { | ||
| displayName: 'react-nav', | ||
| 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: ['@griffel/jest-serializer'], | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { preset } from '@fluentui/scripts-tasks'; | ||
|
|
||
| preset(); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,61 @@ | ||||||
| { | ||||||
| "name": "@fluentui/react-nav", | ||||||
| "version": "9.0.0-alpha.0", | ||||||
| "private": true, | ||||||
| "description": "A react component that provides affordances for top level app navigation", | ||||||
| "main": "lib-commonjs/index.js", | ||||||
| "module": "lib/index.js", | ||||||
| "typings": "./dist/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", | ||||||
| "test": "jest --passWithNoTests", | ||||||
| "type-check": "tsc -b tsconfig.json", | ||||||
| "generate-api": "tsc -p ./tsconfig.lib.json --emitDeclarationOnly && just-scripts api-extractor", | ||||||
| "storybook": "start-storybook", | ||||||
| "start": "yarn storybook" | ||||||
| }, | ||||||
| "devDependencies": { | ||||||
| "@fluentui/eslint-plugin": "*", | ||||||
| "@fluentui/react-conformance": "*", | ||||||
| "@fluentui/react-conformance-griffel": "9.0.0-beta.19", | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dependencies on fluentui packages should use version
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep - added by the script |
||||||
| "@fluentui/scripts-api-extractor": "*", | ||||||
| "@fluentui/scripts-tasks": "*" | ||||||
| }, | ||||||
| "dependencies": { | ||||||
| "@fluentui/react-theme": "^9.1.5", | ||||||
| "@fluentui/react-utilities": "^9.7.0", | ||||||
| "@griffel/react": "^1.5.2", | ||||||
| "tslib": "^2.1.0" | ||||||
| }, | ||||||
| "peerDependencies": { | ||||||
| "@types/react": ">=16.8.0 <19.0.0", | ||||||
| "@types/react-dom": ">=16.8.0 <19.0.0", | ||||||
| "react": ">=16.8.0 <19.0.0", | ||||||
| "react-dom": ">=16.8.0 <19.0.0" | ||||||
| }, | ||||||
| "beachball": { | ||||||
| "disallowedChangeTypes": [ | ||||||
| "major", | ||||||
| "minor", | ||||||
| "patch" | ||||||
| ] | ||||||
| }, | ||||||
| "exports": { | ||||||
| ".": { | ||||||
| "types": "./dist/index.d.ts", | ||||||
| "import": "./lib/index.js", | ||||||
| "require": "./lib-commonjs/index.js" | ||||||
| }, | ||||||
| "./package.json": "./package.json" | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './components/Nav/index'; |
| 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 { Nav } from './Nav'; | ||
| import { isConformant } from '../../testing/isConformant'; | ||
|
|
||
| describe('Nav', () => { | ||
| isConformant({ | ||
| Component: Nav, | ||
| displayName: 'Nav', | ||
| }); | ||
|
|
||
| // TODO add more tests here, and create visual regression tests in /apps/vr-tests | ||
|
|
||
| it('renders a default state', () => { | ||
| const result = render(<Nav>Default Nav</Nav>); | ||
| expect(result.container).toMatchSnapshot(); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import * as React from 'react'; | ||
| import { useNav_unstable } from './useNav'; | ||
| import { renderNav_unstable } from './renderNav'; | ||
| import { useNavStyles_unstable } from './useNavStyles'; | ||
| import type { NavProps } from './Nav.types'; | ||
| import type { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
|
|
||
| /** | ||
| * Nav component - TODO: add more docs | ||
| */ | ||
| export const Nav: ForwardRefComponent<NavProps> = React.forwardRef((props, ref) => { | ||
| const state = useNav_unstable(props, ref); | ||
|
|
||
| useNavStyles_unstable(state); | ||
| return renderNav_unstable(state); | ||
| }); | ||
|
|
||
| Nav.displayName = 'Nav'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; | ||
|
|
||
| export type NavSlots = { | ||
| root: Slot<'div'>; | ||
| }; | ||
|
|
||
| /** | ||
| * Nav Props | ||
| */ | ||
| export type NavProps = ComponentProps<NavSlots> & {}; | ||
|
|
||
| /** | ||
| * State used in rendering Nav | ||
| */ | ||
| export type NavState = ComponentState<NavSlots>; | ||
| // TODO: Remove semicolon from previous line, uncomment next line, and provide union of props to pick from NavProps. | ||
| // & Required<Pick<NavProps, 'propName'>> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`Nav renders a default state 1`] = ` | ||
| <div> | ||
| <div | ||
| class="fui-Nav" | ||
| > | ||
| Default Nav | ||
| </div> | ||
| </div> | ||
| `; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export * from './Nav'; | ||
| export * from './Nav.types'; | ||
| export * from './renderNav'; | ||
| export * from './useNav'; | ||
| export * from './useNavStyles'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import * as React from 'react'; | ||
| import { getSlots } from '@fluentui/react-utilities'; | ||
| import type { NavState, NavSlots } from './Nav.types'; | ||
|
|
||
| /** | ||
| * Render the final JSX of Nav | ||
| */ | ||
| export const renderNav_unstable = (state: NavState) => { | ||
| const { slots, slotProps } = getSlots<NavSlots>(state); | ||
|
|
||
| // TODO Add additional slots in the appropriate place | ||
| return <slots.root {...slotProps.root} />; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be
@fluentui/react-nav-previewand start at version0.0.0, according to https://github.com/microsoft/fluentui/wiki/new-release-process---v9-packages.The create-package script should have added
-previewautomatically, based on the changes in #28474. Did that not happen?cc @Hotell
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct - I just gave it the name 'react-nav'