docs/react-v9/contributing/component-implementation-guide.md
This article outlines the steps to follow to make a component for @fluentui/react-components, commonly known as 'v9.' It is the successor to the @fluentui/react (v8) and @fluentui/react-northstar (v0) libraries.
These components are more than just a convergence of the implementations of the v8 and v0 components. We're also taking the opportunity to:
Each component is released in multiple phases. This process has changed as of July 2023, and is outlined in more detail in the v9 package release cycle. In summary:
-preview suffix and is not yet published to NPM (private).-preview suffix and is published with version 0.(major).(minor|patch). Breaking changes will be marked as minor, but announced as such in changelogs.-preview9.(minor).(patch). The -preview package is marked as deprecated on NPM.Create a GitHub Issue for your component, with the label Type: Epic. This will be used to track the convergence progress on this component. This should be the source of truth and most up to date information on convergence status please keep this up to date as you make progress.
There should be a package in the fluentui repo for the component, named like react-componentname (e.g. react-button). If the package doesn't exist yet, you can create a new one.
# NOTE: execute this command from monorepo root
$ yarn create-package
Within the package, you can create a sub folder for the main, and all related components.
# NOTE: execute this command from monorepo root
$ yarn create-component
Each package should generally contain one component, and any variants. For example, react-button contains Button, MenuButton, SplitButton, and ToggleButton, which are all variants of each other. Larger pattern, molecule and organism level components will likely contain multiple related and dependent components.
Make sure that the README.md file is accurate and up to date for the component you are working on. Indicate the status as:
Before writing the spec, you should partner with Design to do research to figure out the requirements for this control, and help inform the design and implementation.
Make sure there's a specification for the visual and interaction design for this component. Work with designers to get the process started early. Consider prototyping ideas to get feedback on technical design to ensure it aligns with existing patterns in the repo. Ideally, the spec is ready by the time you're ready to start implementing the component.
The goal here is to identify important functionality/props that we should carry forward and record this comparison in an GitHub issue. It's also generally valuable as the component author that you take a deep look at what is already there are understand it.
We do this by looking at these areas:
@fluentui/react components: packages/react/src/components - Note there are some independent packages as wellpackages/fluentui/react-northstar/src/componentsThe Open UI project is working on standardizing UI component names and structures, but it is still in the early stages. If the component you're converging doesn't already have a research page on Open UI, you should do a survey of other established UI platforms and contribute it to Open UI to help with the standardization effort. This research will help inform the converged component's API, and help the Open UI effort to eventually create a standard for UI platforms.
Creating or updating an Open UI component research page is especially useful as an education and preparation tool for Fluent UI developers. You can find information on contributing here at https://open-ui.org/contribute. Fluent UI developers can participate in Open UI beyond creating or updating a component research page, but it is not required for Fluent UI development.
Create a query for open GitHub issues related to this component, and link it in the Epic issue for the component.
For example, a query for Tooltip might be is:issue is:open tooltip.
A draft implementation is optional, but you may find it useful to create one before writing the spec. This can help you try out ideas about the component's API, and uncover issues you may need to address in the spec. It is ok to publish a PR for the draft implementation before the spec has been reviewed. Keep in mind that you may need to make larger structural changes to this draft implementation based on the spec review, so you may not want to spend a significant amount of time getting everything working perfectly. Larger, more complex components will likely require multiple prototypes.
Write the spec in a file named SPEC.md in the component's folder. The spec should document your research above, and outline the proposed API, structure, and usage of the component.
The spec should include the following:
.types.ts file and use that directly as the API proposal.The reviewers will help to double check the spec, and the API is consistent with other Fluent UI controls. The review is not intended to check every aspect of the design to ensure that the control works for all use cases--you are still accountable to create a high quality design for the control.
To get a review started:
SPEC.md and .types.ts (if applicable).Once the first draft of the spec has been reviewed, you can get started on the implementation.
Requirements
You can follow examples of other converged components for the structure of the implementation, such as:
The primary public documentation for our controls is in the form of storybook stories demonstrating the various features and recommended usage of the control. The stories are in the /stories subfolder of the component package. In general, each story should cover only one feature of a control, and follow best practices for using the control. The yarn create-component command creates a single story for each component. If you're building a larger, more complex, compositional component, it may not make sense to publish a story for every component, so some may just be slightly opinionated flavors of existing v9 components. Be sure to be intentional about the story you're telling around the main component experience.
You can get started by looking at existing storybook stories:
README.md file in the component package<a id="unstable-release"></a>
Once the component is functional, it can be released as an unstable preview. This will allow both designers to review the built component and partners to try it out and give early feedback.
Tests are not required to be completed before releasing the component as unstable, but it is recommended to at least add conformance tests and some basic unit tests.
Run the following command (replace MYCOMPONENT with the appropriate package name):
yarn nx generate prepare-initial-release --project @fluentui/react-MYCOMPONENT-preview --phase=preview
Once the component has been released as unstable, you should perform additional validation and complete any tests and documentation that was not finished before.
isConformant from your components' tests.tsx file.@testing-library/react for the tests.getByRole to find elements in the rendered DOM tree, and check that their attributes are as expected.use{Component})vr-tests-react-components app, for example Button.stories.tsxuse{Component}Styles).The converged component can't be considered fully complete until it is validated in a real product. Work with a partner team to make sure that they can use it in their product.
Organize a bug bash with other Fluent UI crews. This is the last chance to verify architecture consistency across the whole library and raise awareness among all crews. The feedback should be addressed before the stable release. There should be a bug bash for each major Time Zone (e.g. one for US and one for Europe). Tip: Look for a volunteer from another Time Zone to schedule and run the bug bash for your component.
Once all validation has been completed, the component is ready for a stable release! 🎉
Use the following script to move the package to stable, replacing your-component with the appropriate package name:
yarn nx generate prepare-initial-release --project @fluentui/react-your-component-preview --phase=stable
Important: Once the component has been released as stable, it can no longer have any breaking changes before the next major release of the library.