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 all 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"
}
18 changes: 12 additions & 6 deletions packages/web-components/docs/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ import { CheckboxOptions } from '@microsoft/fast-foundation';
import { Combobox as Combobox_2 } from '@microsoft/fast-foundation';
import { ComboboxOptions } from '@microsoft/fast-foundation';
import { Constructable } from '@microsoft/fast-element';
import type { Container } from '@microsoft/fast-foundation';
import { CSSDesignToken } from '@microsoft/fast-foundation';
import { CSSDirective } from '@microsoft/fast-element';
import { DataGrid } from '@microsoft/fast-foundation';
import { DataGridCell } from '@microsoft/fast-foundation';
import { DataGridRow } from '@microsoft/fast-foundation';
import { DesignSystem } from '@microsoft/fast-foundation';
import { DesignToken } from '@microsoft/fast-foundation';
import { Dialog } from '@microsoft/fast-foundation';
import { Direction } from '@microsoft/fast-web-utilities';
Expand Down Expand Up @@ -201,6 +203,7 @@ export const allComponents: {
fluentTooltip: (overrideDefinition?: OverrideFoundationElementDefinition<FoundationElementDefinition> | undefined) => FoundationElementRegistry<FoundationElementDefinition, Tooltip>;
fluentTreeView: (overrideDefinition?: OverrideFoundationElementDefinition<FoundationElementDefinition> | undefined) => FoundationElementRegistry<FoundationElementDefinition, TreeView>;
fluentTreeItem: (overrideDefinition?: OverrideFoundationElementDefinition<TreeItemOptions> | undefined) => FoundationElementRegistry<TreeItemOptions, Constructable<FoundationElement>>;
register(container?: Container | undefined): void;
};

// Warning: (ae-internal-missing-underscore) The name "ambientShadow" should be prefixed with an underscore because the declaration is marked as @internal
Expand Down Expand Up @@ -1099,6 +1102,9 @@ export const progressRingStyles: (context: ElementDefinitionContext, definition:
// @public
export const progressStyles: (context: ElementDefinitionContext, definition: ProgressOptions) => ElementStyles;

// @public
export function provideFluentDesignSystem(element?: HTMLElement): DesignSystem;

export { Radio }

export { RadioGroup }
Expand Down Expand Up @@ -1322,12 +1328,12 @@ export const typeRampPlus6LineHeight: CSSDesignToken<string>;

// Warnings were encountered during analysis:
//
// dist/dts/custom-elements.d.ts:47:5 - (ae-incompatible-release-tags) The symbol "fluentAnchor" is marked as @public, but its signature references "Anchor" which is marked as @internal
// dist/dts/custom-elements.d.ts:49:5 - (ae-incompatible-release-tags) The symbol "fluentBadge" is marked as @public, but its signature references "Badge" which is marked as @internal
// dist/dts/custom-elements.d.ts:52:5 - (ae-incompatible-release-tags) The symbol "fluentButton" is marked as @public, but its signature references "Button" which is marked as @internal
// dist/dts/custom-elements.d.ts:89:5 - (ae-incompatible-release-tags) The symbol "fluentTextArea" is marked as @public, but its signature references "TextArea" which is marked as @internal
// dist/dts/custom-elements.d.ts:90:5 - (ae-incompatible-release-tags) The symbol "fluentTextField" is marked as @public, but its signature references "TextField" which is marked as @internal
// dist/dts/custom-elements.d.ts:91:5 - (ae-incompatible-release-tags) The symbol "fluentTooltip" is marked as @public, but its signature references "Tooltip" which is marked as @internal
// dist/dts/custom-elements.d.ts:48:5 - (ae-incompatible-release-tags) The symbol "fluentAnchor" is marked as @public, but its signature references "Anchor" which is marked as @internal
// dist/dts/custom-elements.d.ts:50:5 - (ae-incompatible-release-tags) The symbol "fluentBadge" is marked as @public, but its signature references "Badge" which is marked as @internal
// dist/dts/custom-elements.d.ts:53:5 - (ae-incompatible-release-tags) The symbol "fluentButton" is marked as @public, but its signature references "Button" which is marked as @internal
// dist/dts/custom-elements.d.ts:90:5 - (ae-incompatible-release-tags) The symbol "fluentTextArea" is marked as @public, but its signature references "TextArea" which is marked as @internal
// dist/dts/custom-elements.d.ts:91:5 - (ae-incompatible-release-tags) The symbol "fluentTextField" is marked as @public, but its signature references "TextField" which is marked as @internal
// dist/dts/custom-elements.d.ts:92:5 - (ae-incompatible-release-tags) The symbol "fluentTooltip" is marked as @public, but its signature references "Tooltip" which is marked as @internal

// (No @packageDocumentation comment for this package)

Expand Down
16 changes: 16 additions & 0 deletions packages/web-components/src/custom-elements.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* Export all custom element definitions
*/
import type { Container } from '@microsoft/fast-foundation';
import { fluentAccordion, fluentAccordionItem } from './accordion/index';
import { fluentAnchor } from './anchor/index';
import { fluentAnchoredRegion } from './anchored-region/index';
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