-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update the spinner * Formatting * Spinner position in link input * Use a span instead of a progress * formatting * Positioning * Try an svg instead * Revert to html + css, and simplify the animation * Back to SVG * gray 400 -> 300 * Add a comment explaining the wrapper and the shadow * update circle attributes * revert entirely to css in js * formatting * dedicated emotion elements for spinner and indicator * formatting * Number * split styles into separate file * remove aria-hidden and update role * changelog * update dasharray calc * Split track and indicator to separate SVG elements, use a SVG arc for the indicator (instead of stroke-dashoffset) * Allow Spinner to accept and forward external props * Update storybook example to show different sizes * Update README (including the removal of the screenshot) * Update spinner size from `18` to `16` px * remove extraneous comment * fix vertical alignment of spinner in link control * Vertical alignment of spinner in link control * Update Storybook example to Controls * Revert `display` and `margin` props to the same values as the previous version of the component Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com>
- Loading branch information
1 parent
5550bae
commit 65f7c31
Showing
9 changed files
with
144 additions
and
74 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,19 +1,19 @@ | ||
# Spinner | ||
|
||
Spinners notify users that their action is being processed. | ||
|
||
![Spinner component](https://wordpress.org/gutenberg/files/2019/07/spinner.png) | ||
|
||
## Best practices | ||
|
||
The spinner component should: | ||
|
||
- Signal to users that the processing of their request is underway and will soon complete. | ||
`Spinner` is a component used to notify users that their action is being processed. | ||
|
||
## Usage | ||
|
||
```jsx | ||
import { Spinner } from '@wordpress/components'; | ||
|
||
const MySpinner = () => <Spinner />; | ||
function Example() { | ||
return <Spinner />; | ||
} | ||
``` | ||
|
||
## Best practices | ||
|
||
The spinner component should: | ||
|
||
- Signal to users that the processing of their request is underway and will soon complete. |
This file contains 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,8 +1,47 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classNames from 'classnames'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { StyledSpinner } from './styles/spinner-styles'; | ||
import { StyledSpinner, SpinnerTrack, SpinnerIndicator } from './styles'; | ||
|
||
/** | ||
* @typedef OwnProps | ||
* | ||
* @property {string} [className] Class name | ||
*/ | ||
/** @typedef {import('react').ComponentPropsWithoutRef<'svg'> & OwnProps} Props */ | ||
|
||
/** | ||
* @param {Props} props | ||
* @return {JSX.Element} Element | ||
*/ | ||
export default function Spinner( { className, ...props } ) { | ||
return ( | ||
<StyledSpinner | ||
className={ classNames( 'components-spinner', className ) } | ||
viewBox="0 0 100 100" | ||
xmlns="http://www.w3.org/2000/svg" | ||
role="presentation" | ||
focusable="false" | ||
{ ...props } | ||
> | ||
{ /* Gray circular background */ } | ||
<SpinnerTrack | ||
cx="50" | ||
cy="50" | ||
r="50" | ||
vectorEffect="non-scaling-stroke" | ||
/> | ||
|
||
export default function Spinner() { | ||
return <StyledSpinner className="components-spinner" />; | ||
{ /* Theme-colored arc */ } | ||
<SpinnerIndicator | ||
d="m 50 0 a 50 50 0 0 1 50 50" | ||
vectorEffect="non-scaling-stroke" | ||
/> | ||
</StyledSpinner> | ||
); | ||
} |
This file contains 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,10 +1,43 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { css } from '@emotion/react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { useCx } from '../../utils'; | ||
import { space } from '../../ui/utils/space'; | ||
import Spinner from '../'; | ||
|
||
export default { title: 'Components/Spinner', component: Spinner }; | ||
const sizes = { | ||
default: undefined, | ||
medium: space( 20 ), | ||
large: space( 40 ), | ||
}; | ||
|
||
export default { | ||
title: 'Components/Spinner', | ||
component: Spinner, | ||
argTypes: { | ||
size: { | ||
options: Object.keys( sizes ), | ||
mapping: sizes, | ||
control: { type: 'select' }, | ||
}, | ||
}, | ||
}; | ||
|
||
const Template = ( { size } ) => { | ||
const cx = useCx(); | ||
const spinnerClassname = cx( css` | ||
width: ${ size }; | ||
height: ${ size }; | ||
` ); | ||
return <Spinner className={ spinnerClassname } />; | ||
}; | ||
|
||
export const _default = () => { | ||
return <Spinner />; | ||
export const Default = Template.bind( {} ); | ||
Default.args = { | ||
size: 'default', | ||
}; |
This file contains 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,47 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import styled from '@emotion/styled'; | ||
import { css, keyframes } from '@emotion/react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { COLORS, CONFIG } from '../utils'; | ||
|
||
const spinAnimation = keyframes` | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
`; | ||
|
||
export const StyledSpinner = styled.svg` | ||
width: ${ CONFIG.spinnerSize }px; | ||
height: ${ CONFIG.spinnerSize }px; | ||
display: inline-block; | ||
margin: 5px 11px 0; | ||
position: relative; | ||
color: var( --wp-admin-theme-color ); | ||
overflow: visible; | ||
`; | ||
|
||
const commonPathProps = css` | ||
fill: transparent; | ||
stroke-width: 1.5px; | ||
`; | ||
|
||
export const SpinnerTrack = styled.circle` | ||
${ commonPathProps }; | ||
stroke: ${ COLORS.gray[ 300 ] }; | ||
`; | ||
|
||
export const SpinnerIndicator = styled.path` | ||
${ commonPathProps }; | ||
stroke: currentColor; | ||
stroke-linecap: round; | ||
transform-origin: 50% 50%; | ||
animation: 1.4s linear infinite both ${ spinAnimation }; | ||
`; |
This file was deleted.
Oops, something went wrong.
This file contains 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