diff --git a/apps/docs/tsconfig.json b/apps/docs/tsconfig.json index 6d7945c687..c3547825e0 100644 --- a/apps/docs/tsconfig.json +++ b/apps/docs/tsconfig.json @@ -6,6 +6,7 @@ "strict": true, "noImplicitOverride": true, "noImplicitReturns": true, + "noUnusedLocals": true, "noFallthroughCasesInSwitch": true, "esModuleInterop": true, "resolveJsonModule": true diff --git a/libs/components/cem.config.mjs b/libs/components/cem.config.mjs index 201fa46763..2a31ccbfc5 100644 --- a/libs/components/cem.config.mjs +++ b/libs/components/cem.config.mjs @@ -9,6 +9,7 @@ export default { /** Globs to analyze */ globs: [ 'libs/components/src/lib/**/*.ts', + 'libs/components/src/shared/foundation/**/*.ts', 'libs/components/src/shared/date-picker/date-picker-base.ts', ], /** Globs to exclude */ diff --git a/libs/components/src/lib/breadcrumb-item/breadcrumb-item.ts b/libs/components/src/lib/breadcrumb-item/breadcrumb-item.ts index 0fb3097ac7..a779e532e0 100644 --- a/libs/components/src/lib/breadcrumb-item/breadcrumb-item.ts +++ b/libs/components/src/lib/breadcrumb-item/breadcrumb-item.ts @@ -1,6 +1,6 @@ import { attr, observable } from '@microsoft/fast-element'; import { applyMixins, FoundationElement } from '@microsoft/fast-foundation'; -import { Anchor } from '../../shared/patterns/anchor'; +import { Anchor } from '../../shared/foundation/anchor/anchor'; /** * @public diff --git a/libs/components/src/lib/fab/fab.ts b/libs/components/src/lib/fab/fab.ts index 9be09b5d0a..f04a177f19 100644 --- a/libs/components/src/lib/fab/fab.ts +++ b/libs/components/src/lib/fab/fab.ts @@ -1,9 +1,6 @@ -import { - applyMixins, - Button as FoundationButton, -} from '@microsoft/fast-foundation'; import { attr } from '@microsoft/fast-element'; - +import { applyMixins } from '@microsoft/fast-foundation'; +import { FoundationButton } from '../../shared/foundation/button'; import type { Connotation, Size } from '../enums.js'; import { AffixIconWithTrailing } from '../../shared/patterns/affix'; diff --git a/libs/components/src/shared/patterns/anchor.ts b/libs/components/src/shared/foundation/anchor/anchor.ts similarity index 97% rename from libs/components/src/shared/patterns/anchor.ts rename to libs/components/src/shared/foundation/anchor/anchor.ts index 6f844eec7c..e572151c4a 100644 --- a/libs/components/src/shared/patterns/anchor.ts +++ b/libs/components/src/shared/foundation/anchor/anchor.ts @@ -1,6 +1,6 @@ import { attr } from '@microsoft/fast-element'; import { applyMixins } from '@microsoft/fast-foundation'; -import { ARIAGlobalStatesAndProperties } from './aria-global'; +import { ARIAGlobalStatesAndProperties } from '../patterns/aria-global'; /** * Based largely on the {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a | element }. diff --git a/libs/components/src/shared/foundation/button/REAME.md b/libs/components/src/shared/foundation/button/REAME.md new file mode 100644 index 0000000000..e59aeb1702 --- /dev/null +++ b/libs/components/src/shared/foundation/button/REAME.md @@ -0,0 +1,142 @@ +--- +id: button +title: fast-button +sidebar_label: button +custom_edit_url: https://github.com/microsoft/fast/edit/master/packages/web-components/fast-foundation/src/button/README.md +description: fast-button is a web component implementation of a button element. +--- + +As defined by the [W3C](https://w3c.github.io/aria-practices/#button): + +> A button is a widget that enables users to trigger an action or event, such as submitting a form, opening a dialog, canceling an action, or performing a delete operation. + +`fast-button` is a web component implementation of an [HTML button element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button). The `fast-components` button supports several visual appearances (accent, lightweight, neutral, outline, stealth). + +## Setup + +```ts +import { + provideFASTDesignSystem, + fastButton, +} from '@microsoft/fast-components'; + +provideFASTDesignSystem().register(fastButton()); +``` + +## Usage + +```html live +Submit +``` + +## Create your own design + +```ts +import { Button, buttonTemplate as template } from '@microsoft/fast-foundation'; +import { buttonStyles as styles } from './my-button.styles'; + +export const myButton = Button.compose({ + baseName: 'button', + template, + styles, + shadowOptions: { + delegatesFocus: true, + }, +}); +``` + +:::note +This component is built with the expectation that focus is delegated to the button element rendered into the shadow DOM. +::: + +## API + +### class: `Button` + +#### Superclass + +| Name | Module | Package | +| ---------------------- | ------------------------------------- | ------- | +| `FormAssociatedButton` | /src/button/button.form-associated.js | | + +#### Fields + +| Name | Privacy | Type | Default | Description | Inherited From | +| ----------------------- | ------- | -------------------------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------- | +| `autofocus` | public | `boolean` | | Determines if the element should receive document focus on page load. | | +| `formId` | public | `string` | | The id of a form to associate the element to. | | +| `formaction` | public | `string` | | See [` +`; diff --git a/libs/components/src/shared/foundation/button/button.ts b/libs/components/src/shared/foundation/button/button.ts new file mode 100644 index 0000000000..40a3fc4cb6 --- /dev/null +++ b/libs/components/src/shared/foundation/button/button.ts @@ -0,0 +1,271 @@ +/* eslint-disable @typescript-eslint/explicit-member-accessibility */ +import { attr } from '@microsoft/fast-element'; +import { applyMixins } from '@microsoft/fast-foundation'; +import type { FoundationElementDefinition } from '@microsoft/fast-foundation'; +import { ARIAGlobalStatesAndProperties } from '../patterns/index'; +import { FormAssociatedButton } from './button.form-associated'; + +/** + * Button configuration options + * @public + */ +export type ButtonOptions = FoundationElementDefinition; + +/** + * A Button Custom HTML Element. + * Based largely on the {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button |