diff --git a/packages/web-components/fast-components/docs/api-report.md b/packages/web-components/fast-components/docs/api-report.md index 0eca3aa7515..632fbbc3e02 100644 --- a/packages/web-components/fast-components/docs/api-report.md +++ b/packages/web-components/fast-components/docs/api-report.md @@ -269,6 +269,8 @@ export class FASTButton extends Button { appearance: ButtonAppearance; // (undocumented) connectedCallback(): void; + // (undocumented) + defaultSlottedContentChanged(oldValue: any, newValue: any): void; } // @public diff --git a/packages/web-components/fast-components/src/button/index.ts b/packages/web-components/fast-components/src/button/index.ts index a604e67443a..1efce7a15f4 100644 --- a/packages/web-components/fast-components/src/button/index.ts +++ b/packages/web-components/fast-components/src/button/index.ts @@ -45,11 +45,27 @@ export class FASTButton extends Button { public connectedCallback() { super.connectedCallback(); - if (!this.appearance) { this.appearance = "neutral"; } } + + /** + * Applies 'icon-only' class when there is only an SVG in the default slot + * + * @public + * @remarks + */ + public defaultSlottedContentChanged(oldValue, newValue): void { + const slottedElements = this.defaultSlottedContent.filter( + x => x.nodeType === Node.ELEMENT_NODE + ); + if (slottedElements.length === 1 && slottedElements[0] instanceof SVGElement) { + this.root.classList.add("icon-only"); + } else { + this.root.classList.remove("icon-only"); + } + } } /** diff --git a/packages/web-components/fast-element/docs/api-report.md b/packages/web-components/fast-element/docs/api-report.md index 3b88384a9c1..4208ba8dee6 100644 --- a/packages/web-components/fast-element/docs/api-report.md +++ b/packages/web-components/fast-element/docs/api-report.md @@ -275,6 +275,9 @@ export interface ElementViewTemplate { // @internal export const emptyArray: readonly never[]; +// @public +export function enableArrayObservation(): void; + // @public export class ExecutionContext { get event(): Event; @@ -430,8 +433,6 @@ export function repeat(itemsBinding: Binding implements Behavior, Subscriber { constructor(location: Node, itemsBinding: Binding, isItemsBindingVolatile: boolean, templateBinding: Binding, isTemplateBindingVolatile: boolean, options: RepeatOptions); bind(source: TSource, context: ExecutionContext): void; - // Warning: (ae-forgotten-export) The symbol "Splice" needs to be exported by the entry point index.d.ts - // // @internal (undocumented) handleChange(source: any, args: Splice[]): void; unbind(): void; @@ -469,6 +470,13 @@ export class SlottedBehavior extends NodeObservationBehavior extends NodeBehaviorOptions, AssignedNodesOptions { } +// @public +export interface Splice { + addedCount: number; + index: number; + removed: any[]; +} + // @public export interface StyleTarget { adoptedStyleSheets?: CSSStyleSheet[]; diff --git a/packages/web-components/fast-foundation/docs/api-report.md b/packages/web-components/fast-foundation/docs/api-report.md index d83335ac95a..ff6b8019ce9 100644 --- a/packages/web-components/fast-foundation/docs/api-report.md +++ b/packages/web-components/fast-foundation/docs/api-report.md @@ -156,12 +156,14 @@ export class Button extends FormAssociatedButton { autofocus: boolean; // @internal (undocumented) connectedCallback(): void; + defaultSlottedContent: HTMLElement[]; formaction: string; formenctype: string; formId: string; formmethod: string; formnovalidate: boolean; formtarget: "_self" | "_blank" | "_parent" | "_top"; + root: HTMLButtonElement; type: "submit" | "reset" | "button"; } diff --git a/packages/web-components/fast-foundation/src/button/button.template.ts b/packages/web-components/fast-foundation/src/button/button.template.ts index a46f731ca5a..655d4e42a83 100644 --- a/packages/web-components/fast-foundation/src/button/button.template.ts +++ b/packages/web-components/fast-foundation/src/button/button.template.ts @@ -1,4 +1,4 @@ -import { html } from "@microsoft/fast-element"; +import { html, ref, slotted, elements } from "@microsoft/fast-element"; import { endTemplate, startTemplate } from "../patterns/start-end"; import { Button } from "./button"; @@ -42,10 +42,11 @@ export const ButtonTemplate = html diff --git a/packages/web-components/fast-foundation/src/button/button.ts b/packages/web-components/fast-foundation/src/button/button.ts index 274a883b850..2b971f11dcd 100644 --- a/packages/web-components/fast-foundation/src/button/button.ts +++ b/packages/web-components/fast-foundation/src/button/button.ts @@ -1,4 +1,4 @@ -import { attr } from "@microsoft/fast-element"; +import { attr, observable } from "@microsoft/fast-element"; import { ARIAGlobalStatesAndProperties, StartEnd } from "../patterns/index"; import { applyMixins } from "../utilities/apply-mixins"; import { FormAssociatedButton } from "./button.form-associated"; @@ -128,6 +128,16 @@ export class Button extends FormAssociatedButton { previous === "reset" && this.removeEventListener("click", this.handleFormReset); } + /** + * + * Default slotted content + * + * @public + * @remarks + */ + @observable + public defaultSlottedContent: HTMLElement[]; + /** * @internal */ @@ -168,6 +178,11 @@ export class Button extends FormAssociatedButton { private handleFormReset = () => { this.form?.reset(); }; + + /** + * References the root element + */ + public root: HTMLButtonElement; } /**