-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Adds basic implementation of Spinner component #26392
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
Merged
procload
merged 18 commits into
microsoft:web-components-v3
from
procload:users/procload/add-spinner-as-new-component
Feb 14, 2023
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6ff34d5
Adds basic implementation of Spinner component
procload c61e79a
Adds inverted Story to Spinner
procload dbae4d7
Cleans up some typos
procload 6f8fd64
Resolves merge conflict
procload ae1d8e9
Generates API report
procload 284913c
Adds change file
procload 880130a
Removes kebab-case for key in Spinner in favor of camelCase; Adds spi…
procload ee8b57a
Address feedback in PR
procload 3b57680
Minor typo cleanup
procload 401f694
Rebuilds
procload 33bddab
Merge branch 'web-components-v3' into users/procload/add-spinner-as-n…
procload fc74a37
Adds new API Report
procload 8c32938
Rejiggers Spinner option order
procload 77def8d
Updates ValuesOf in Spinner options to use the new FAST helper
procload 1928395
Adds API report
procload 6e4a6da
Removes stray type line
procload d698710
Bumps API report
procload 2735193
Merge branch 'web-components-v3' into users/procload/add-spinner-as-n…
procload File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-web-components-b6b8fdad-d432-4c23-871e-ff051099582f.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "prerelease", | ||
| "comment": "Adds Spinner as a web component", | ||
| "packageName": "@fluentui/web-components", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "patch" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| export * from './badge/index.js'; | ||
| export * from './counter-badge/index.js'; | ||
| export * from './progress-bar/index.js'; | ||
| export * from './spinner/index.js'; | ||
| export * from './text/index.js'; | ||
|
|
||
| export * from './theme/index.js'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import { FluentDesignSystem } from '../fluent-design-system.js'; | ||
| import { definition } from './spinner.definition.js'; | ||
|
|
||
| definition.define(FluentDesignSystem.registry); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export * from './spinner.js'; | ||
| export * from './spinner.options.js'; | ||
| export { template as SpinnerTemplate } from './spinner.template.js'; | ||
| export { styles as SpinnerStyles } from './spinner.styles.js'; | ||
| export { definition as SpinnerDefinition } from './spinner.definition.js'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { FluentDesignSystem } from '../fluent-design-system.js'; | ||
| import { Spinner } from './spinner.js'; | ||
| import { styles } from './spinner.styles.js'; | ||
| import { template } from './spinner.template.js'; | ||
|
|
||
| /** | ||
| * The Fluent Spinner Element. Implements {@link @microsoft/fast-foundation#ProgressRing }, | ||
| * {@link @microsoft/fast-foundation#progress-ringTemplate} | ||
| * | ||
| * | ||
| * @public | ||
| * @remarks | ||
| * HTML Element: \<fluent-spinner\> | ||
| */ | ||
| export const definition = Spinner.compose({ | ||
| name: `${FluentDesignSystem.prefix}-spinner`, | ||
| template, | ||
| styles, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { ValuesOf } from '@microsoft/fast-foundation'; | ||
|
|
||
| /** | ||
| * SpinnerAppearance constants | ||
| * @public | ||
| */ | ||
| export const SpinnerAppearance = { | ||
| primary: 'primary', | ||
| inverted: 'inverted', | ||
| } as const; | ||
|
|
||
| /** | ||
| * A Spinner's appearance can be either primary or inverted | ||
| * @public | ||
| */ | ||
| export type SpinnerAppearance = ValuesOf<typeof SpinnerAppearance>; | ||
|
|
||
| /** | ||
| * SpinnerSize constants | ||
| * @public | ||
| */ | ||
| export const SpinnerSize = { | ||
| tiny: 'tiny', | ||
| extraSmall: 'extra-small', | ||
| small: 'small', | ||
| medium: 'medium', | ||
| large: 'large', | ||
| extraLarge: 'extra-large', | ||
| huge: 'huge', | ||
| } as const; | ||
|
|
||
| /** | ||
| * A Spinner's size can be either small, tiny, extra-small, medium, large, extra-large, or huge | ||
| * @public | ||
| */ | ||
| export type SpinnerSize = ValuesOf<typeof SpinnerSize>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { html } from '@microsoft/fast-element'; | ||
| import type { Args, Meta } from '@storybook/html'; | ||
| import { renderComponent } from '../__test__/helpers.js'; | ||
| import { SpinnerAppearance, SpinnerSize } from './spinner.options.js'; | ||
| import './define.js'; | ||
|
|
||
| type SpinnerStoryArgs = Args; | ||
| type SpinnerStoryMeta = Meta<SpinnerStoryArgs>; | ||
|
|
||
| const storyTemplate = html<SpinnerStoryArgs>` | ||
| <fluent-spinner appearance=${x => x.appearance} size=${x => x.size}></fluent-spinner> | ||
| `; | ||
|
|
||
| export default { | ||
| title: 'Components/Spinner', | ||
| argTypes: { | ||
| appearance: { | ||
| description: 'The appearance of the spinner', | ||
| table: { | ||
| defaultValue: { summary: 'primary' }, | ||
| }, | ||
| control: { | ||
| type: 'select', | ||
| options: Object.values(SpinnerAppearance), | ||
| }, | ||
| defaultValue: 'primary', | ||
| }, | ||
| size: { | ||
| description: 'The size of the spinner', | ||
| table: { | ||
| defaultValue: { summary: 'medium' }, | ||
| }, | ||
| control: { | ||
| type: 'select', | ||
| options: Object.values(SpinnerSize), | ||
| }, | ||
| defaultValue: 'medium', | ||
| }, | ||
| }, | ||
| parameters: { | ||
| status: { | ||
| type: 'experimental', | ||
| }, | ||
| }, | ||
| } as SpinnerStoryMeta; | ||
|
|
||
| export const Spinner = renderComponent(storyTemplate).bind({}); | ||
|
|
||
| export const SpinnerInverted = renderComponent(html<SpinnerStoryArgs>` | ||
| <div style="background-color: #0f6cbd; padding: 20px;"> | ||
| <fluent-spinner appearance="inverted" size="medium"></fluent-spinner> | ||
| </div> | ||
| `); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import { css } from '@microsoft/fast-element'; | ||
| import { display } from '@microsoft/fast-foundation'; | ||
| import { colorBrandStroke1, colorBrandStroke2, colorNeutralStrokeOnBrand2 } from '../theme/design-tokens.js'; | ||
|
|
||
| export const styles = css` | ||
| ${display('flex')} | ||
|
|
||
| :host { | ||
| display: flex; | ||
| align-items: center; | ||
| height: 32px; | ||
| width: 32px; | ||
| } | ||
| :host([size='tiny']) { | ||
| height: 20px; | ||
| width: 20px; | ||
| } | ||
| :host([size='extra-small']) { | ||
| height: 24px; | ||
| width: 24px; | ||
| } | ||
| :host([size='small']) { | ||
| height: 28px; | ||
| width: 28px; | ||
| } | ||
| :host([size='large']) { | ||
| height: 36px; | ||
| width: 36px; | ||
| } | ||
| :host([size='extra-large']) { | ||
| height: 40px; | ||
| width: 40px; | ||
| } | ||
| :host([size='huge']) { | ||
| height: 44px; | ||
| width: 44px; | ||
| } | ||
| .progress { | ||
| height: 100%; | ||
| width: 100%; | ||
| } | ||
|
|
||
| .background { | ||
| fill: none; | ||
| stroke: ${colorBrandStroke2}; | ||
| stroke-width: 1.5px; | ||
| } | ||
|
|
||
| :host([appearance='inverted']) .background { | ||
| stroke: rgba(255, 255, 255, 0.2); | ||
| } | ||
|
|
||
| .determinate { | ||
| stroke: ${colorBrandStroke1}; | ||
| fill: none; | ||
| stroke-width: 1.5px; | ||
| stroke-linecap: round; | ||
| transform-origin: 50% 50%; | ||
| transform: rotate(-90deg); | ||
| transition: all 0.2s ease-in-out; | ||
| } | ||
|
|
||
| :host([appearance='inverted']) .determinite { | ||
| stroke: ${colorNeutralStrokeOnBrand2}; | ||
| } | ||
|
|
||
| .indeterminate-indicator-1 { | ||
| stroke: ${colorBrandStroke1}; | ||
| fill: none; | ||
| stroke-width: 1.5px; | ||
| stroke-linecap: round; | ||
| transform-origin: 50% 50%; | ||
| transform: rotate(-90deg); | ||
| transition: all 0.2s ease-in-out; | ||
| animation: spin-infinite 3s cubic-bezier(0.53, 0.21, 0.29, 0.67) infinite; | ||
| } | ||
|
|
||
| :host([appearance='inverted']) .indeterminate-indicator-1 { | ||
| stroke: ${colorNeutralStrokeOnBrand2}; | ||
| } | ||
|
|
||
| @keyframes spin-infinite { | ||
| 0% { | ||
| stroke-dasharray: 0.01px 43.97px; | ||
| transform: rotate(0deg); | ||
| } | ||
| 50% { | ||
| stroke-dasharray: 21.99px 21.99px; | ||
| transform: rotate(450deg); | ||
| } | ||
| 100% { | ||
| stroke-dasharray: 0.01px 43.97px; | ||
| transform: rotate(1080deg); | ||
| } | ||
| } | ||
| `; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import type { ElementViewTemplate } from '@microsoft/fast-element'; | ||
| import { progressRingTemplate } from '@microsoft/fast-foundation'; | ||
| import { Spinner } from './spinner.js'; | ||
|
|
||
| export const template: ElementViewTemplate<Spinner> = progressRingTemplate({ | ||
| indeterminateIndicator: ` | ||
| <svg class="progress" part="progress" viewBox="0 0 16 16"> | ||
| <circle | ||
| class="background" | ||
| part="background" | ||
| cx="8px" | ||
| cy="8px" | ||
| r="7px" | ||
| ></circle> | ||
| <circle | ||
| class="indeterminate-indicator-1" | ||
| part="indeterminate-indicator-1" | ||
| cx="8px" | ||
| cy="8px" | ||
| r="7px" | ||
| ></circle> | ||
| </svg> | ||
| `, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { attr } from '@microsoft/fast-element'; | ||
| import { FASTProgressRing } from '@microsoft/fast-foundation'; | ||
| import type { SpinnerAppearance, SpinnerSize } from './spinner.options.js'; | ||
|
|
||
| /** | ||
| * The base class used for constructing a fluent-spinner custom element | ||
| * @public | ||
| */ | ||
| export class Spinner extends FASTProgressRing { | ||
| /** | ||
| * The size of the spinner | ||
| * | ||
| * @public | ||
| * @default 'medium' | ||
| * @remarks | ||
| * HTML Attribute: size | ||
| */ | ||
| @attr | ||
| public size: SpinnerSize; | ||
|
|
||
| /** | ||
| * The appearance of the spinner | ||
| * @public | ||
| * @default 'primary' | ||
| * @remarks | ||
procload marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * HTML Attribute: appearance | ||
| */ | ||
| @attr | ||
| public appearance: SpinnerAppearance; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.