Skip to content

Commit

Permalink
Export forwarded component, add example & use forwardRef from wp/element
Browse files Browse the repository at this point in the history
  • Loading branch information
opr committed Jun 16, 2022
1 parent 4ee97a0 commit df3885f
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions packages/components/src/spinner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@
* External dependencies
*/
import classNames from 'classnames';
import type { ForwardedRef } from 'react';

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

export function Spinner(
/**
* WordPress dependencies
*/
import { forwardRef } from '@wordpress/element';

export function UnforwardedSpinner(
{ className, ...props }: WordPressComponentProps< {}, 'svg', false >,
forwardedRef: React.ForwardedRef< any >
forwardedRef: ForwardedRef< any >
) {
return (
<StyledSpinner
Expand Down Expand Up @@ -39,7 +45,17 @@ export function Spinner(
</StyledSpinner>
);
}

const ConnectedSpinner = contextConnect( Spinner, 'Spinner' );

export default ConnectedSpinner;
/**
* `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;

0 comments on commit df3885f

Please sign in to comment.