Skip to content
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

Spinner: Convert component to TypeScript #41540

Merged
merged 13 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Internal

- `Spinner`: Convert to TypeScript and update storybook ([#41540](https://github.com/WordPress/gutenberg/pull/41540/)).
- `InputControl`: Add tests and update to use `@testing-library/user-event` ([#41421](https://github.com/WordPress/gutenberg/pull/41421)).

## 19.13.0 (2022-06-15)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@
* External dependencies
*/
import classNames from 'classnames';
import type { ForwardedRef } from 'react';

/**
* Internal dependencies
*/
import { StyledSpinner, SpinnerTrack, SpinnerIndicator } from './styles';
import type { WordPressComponentProps } from '../ui/context';

/**
* @typedef OwnProps
*
* @property {string} [className] Class name
* WordPress dependencies
*/
/** @typedef {import('react').ComponentPropsWithoutRef<'svg'> & OwnProps} Props */
import { forwardRef } from '@wordpress/element';

/**
* @param {Props} props
* @return {JSX.Element} Element
*/
export default function Spinner( { className, ...props } ) {
export function UnforwardedSpinner(
{ className, ...props }: WordPressComponentProps< {}, 'svg', false >,
forwardedRef: ForwardedRef< any >
) {
return (
<StyledSpinner
className={ classNames( 'components-spinner', className ) }
Expand All @@ -28,6 +27,7 @@ export default function Spinner( { className, ...props } ) {
role="presentation"
focusable="false"
{ ...props }
ref={ forwardedRef }
>
{ /* Gray circular background */ }
<SpinnerTrack
Expand All @@ -45,3 +45,17 @@ export default function Spinner( { className, ...props } ) {
</StyledSpinner>
);
}
/**
* `Spinner` is a component used to notify users that their action is being processed.
*
* @example
* ```js
* import { Spinner } from '@wordpress/components';
*
* function Example() {
* return <Spinner />;
* }
* ```
*/
export const Spinner = forwardRef( UnforwardedSpinner );
export default Spinner;
43 changes: 0 additions & 43 deletions packages/components/src/spinner/stories/index.js

This file was deleted.

32 changes: 32 additions & 0 deletions packages/components/src/spinner/stories/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* External dependencies
*/
import type { ComponentStory, ComponentMeta } from '@storybook/react';

/**
* Internal dependencies
*/
import Spinner from '../';
import { space } from '../../ui/utils/space';

const meta: ComponentMeta< typeof Spinner > = {
title: 'Components/Spinner',
component: Spinner,
parameters: {
controls: {
expanded: true,
},
docs: { source: { state: 'open' } },
},
};
export default meta;

const Template: ComponentStory< typeof Spinner > = ( args ) => {
return <Spinner { ...args } />;
};

export const Default: ComponentStory< typeof Spinner > = Template.bind( {} );

// The Spinner can be resized to any size, but the stroke width will remain unchanged.
export const CustomSize: ComponentStory< typeof Spinner > = Template.bind( {} );
CustomSize.args = { style: { width: space( 20 ), height: space( 20 ) } };
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ exports[`PostPublishPanel should render the spinner if the post is being saved 1
<div
className="editor-post-publish-panel__content"
>
<Spinner />
<ForwardRef(UnforwardedSpinner) />
</div>
<div
className="editor-post-publish-panel__footer"
Expand Down