Skip to content
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

feat(web-components): improve ergonomics of the fluent design system #19056

Merged
merged 5 commits into from
Jul 24, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat(web-components): improve ergonomics of the fluent design system",
"packageName": "@fluentui/web-components",
"email": "roeisenb@microsoft.com",
"dependentChangeType": "patch"
}
16 changes: 16 additions & 0 deletions packages/web-components/src/custom-elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { fluentTextField } from './text-field/index';
import { fluentTooltip } from './tooltip/index';
import { fluentTreeView } from './tree-view/index';
import { fluentTreeItem } from './tree-item/index';
import { Container } from '@microsoft/fast-foundation';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EisenbergEffect looks like the lint portion of the PR build is throwing on the import order here. This likely needs to move to the top (line 3)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On it.


export {
fluentAccordion,
Expand Down Expand Up @@ -127,4 +128,19 @@ export const allComponents = {
fluentTooltip,
fluentTreeView,
fluentTreeItem,
register(container?: Container) {
if (!container) {
// preserve backward compatibility with code that loops through
// the values of this object and calls them as funcs with no args
return;
}

for (const key in this) {
if (key === "register") {
continue;
}

this[key]().register(container);
}
},
};
12 changes: 12 additions & 0 deletions packages/web-components/src/fluent-design-system.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { DesignSystem } from "@microsoft/fast-foundation";

/**
* Provides a design system for the specified element either by returning one that was
* already created for that element or creating one.
* @param element - The element to root the design system at. By default, this is the body.
* @returns A Fluent Design System
* @public
*/
export function provideFluentDesignSystem(element?: HTMLElement): DesignSystem {
return DesignSystem.getOrCreate(element).withPrefix("fluent");
}
13 changes: 7 additions & 6 deletions packages/web-components/src/index-rollup.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// TODO: Is exporting Foundation still necessary with the updated API's?
// export * from "@microsoft/fast-element";
import { DesignSystem } from '@microsoft/fast-foundation';
import { allComponents } from './custom-elements';
import { provideFluentDesignSystem } from './fluent-design-system';

export * from './index';

/**
* TODO rename this to FluentDesignSystem when {@link @FluentDesignSystem} interface is removed.
/**
* The global Fluent Design System.
* @remarks
* Only available if the components are added through a script tag
* rather than a module/build system.
*/
export const fluentDesignSystem = DesignSystem.getOrCreate()
.withPrefix('fluent')
.register(...Object.values(allComponents).map(definition => definition()));
export const FluentDesignSystem = provideFluentDesignSystem().register(allComponents);
2 changes: 1 addition & 1 deletion packages/web-components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Export all custom element definitions.
*/
export * from './custom-elements';

export * from "./fluent-design-system";
export * from './accordion/';
export * from './anchor/';
export * from './anchored-region';
Expand Down