-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Initial Spinner Implementation #22207
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
Changes from all commits
38c4714
19e3cf0
de37957
6eb6961
4cdfb16
d54a4e5
a873578
98d93a7
a604688
0608aa6
1675276
0941f0a
64fa166
02fedb7
e5f8a74
cce0d5a
68f30dd
c94bb18
17a6bca
f58a8b4
a83054e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import * as React from 'react'; | ||
|
|
||
| export const DefaultSvg = () => ( | ||
| <svg role="progressbar" className="fui-Spinner__Progressbar"> | ||
| <circle className="fui-Spinner__Track" /> | ||
| <circle className="fui-Spinner__Tail" /> | ||
| </svg> | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,55 @@ | ||
| import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; | ||
| import { Label } from '@fluentui/react-label'; | ||
|
|
||
| export type SpinnerSlots = { | ||
| root: Slot<'div'>; | ||
| /** | ||
| * The root of the Spinner. | ||
| * The root slot receives the `className` and `style` specified directly on the `<Spinner>`. | ||
| */ | ||
| root: NonNullable<Slot<'div'>>; | ||
| /** | ||
| * The slot for the animated svg. | ||
| * The spinner slot receives the `className` and `style` that handles the spinning animation. | ||
| * An svg is also rendered as a child of this slot | ||
| */ | ||
| spinner?: Slot<'span'>; | ||
| /** | ||
| * The label of the Slider. | ||
| * The label slot receives the styling related to the text associated with the Spinner. | ||
| */ | ||
| label?: Slot<typeof Label>; | ||
| }; | ||
|
|
||
| type SpinnerCommons = { | ||
| // TODO Add things shared between props and state here | ||
| /** | ||
| * The appearance of the Spinner. | ||
| * @default 'primary' | ||
| */ | ||
| appearance?: 'primary' | 'inverted'; | ||
|
|
||
| /** | ||
| * Where the label is positioned relative to the Spinner | ||
| * @default 'after' | ||
| */ | ||
| labelPosition?: 'above' | 'below' | 'before' | 'after'; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. above and below feel positional - like top and bottom. Consider only before and after and then a separate property about horizontal or vertical layout.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was discussed in the Spec PR to keep it this way to align with react-positioning: #21336 (comment) |
||
|
|
||
| /** | ||
| * The size of the spinner. | ||
| * @default 'medium' | ||
| */ | ||
| size?: 'tiny' | 'extra-small' | 'small' | 'medium' | 'large' | 'extra-large' | 'huge'; | ||
|
|
||
| /** | ||
| * The status of the Spinner. | ||
| * @default 'active' | ||
| */ | ||
| status?: 'active' | 'inactive'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is |
||
| }; | ||
|
|
||
| /** | ||
| * Spinner Props | ||
| */ | ||
| export type SpinnerProps = ComponentProps<SpinnerSlots> & SpinnerCommons; | ||
| export type SpinnerProps = Omit<ComponentProps<SpinnerSlots>, 'size'> & Partial<SpinnerCommons>; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is better to have commons have the required/optional based on its usage with SpinnerProps. Then have SpinnerState make required/optional changes. This way a caller reading the code doesn't have to do mental gymnastics to figure out what is required/option in props. |
||
|
|
||
| /** | ||
| * State used in rendering Spinner | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import * as React from 'react'; | ||
| import { getNativeElementProps, resolveShorthand } from '@fluentui/react-utilities'; | ||
| import type { SpinnerProps, SpinnerState } from './Spinner.types'; | ||
| import { Label } from '@fluentui/react-label'; | ||
| import { DefaultSvg } from './DefaultSvg'; | ||
|
|
||
| /** | ||
| * Create the state required to render Spinner. | ||
| * | ||
| * The returned state can be modified with hooks such as useSpinnerStyles_unstable, | ||
| * before being passed to renderSpinner_unstable. | ||
| * | ||
| * @param props - props from this instance of Spinner | ||
| * @param ref - reference to root HTMLElement of Spinner | ||
| */ | ||
| export const useSpinner_unstable = (props: SpinnerProps, ref: React.Ref<HTMLElement>): SpinnerState => { | ||
| // Props | ||
| const { appearance = 'primary', labelPosition = 'after', size = 'medium', status = 'active' } = props; | ||
|
|
||
| const state: SpinnerState = { | ||
| appearance, | ||
| labelPosition, | ||
| size, | ||
| status, | ||
| components: { | ||
| root: 'div', | ||
| spinner: 'span', | ||
| label: Label, | ||
| }, | ||
| root: getNativeElementProps('div', { ref, ...props }, ['size']), | ||
| spinner: resolveShorthand(props.spinner, { | ||
| required: true, | ||
| defaultProps: { | ||
| children: <DefaultSvg />, | ||
| }, | ||
| }), | ||
| label: resolveShorthand(props.label, { | ||
| required: false, | ||
| }), | ||
| }; | ||
| return state; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding the it('renders') test maybe with and without the label.