Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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/ui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

### Enhancements

- `Spinner`: Show a trackless half-circle like the `Button` loading indicator, with a `color` prop that accepts any CSS color value and defaults to weak neutral foreground ([#83775](https://github.com/WordPress/gutenberg/pull/83775)).
- `Autocomplete`, `Combobox`, `SearchableSelect`, `SearchableChipSelect`, `SearchableSelectControl`, and `SearchableChipSelectControl` add `ItemLabel` and `ItemDescription` subcomponents. Searchable selection items also accept an optional `description` string ([#83493](https://github.com/WordPress/gutenberg/pull/83493)).

### Bug Fixes
Expand Down
16 changes: 5 additions & 11 deletions packages/ui/src/spinner/spinner.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
import clsx from 'clsx';
import type { ComponentProps } from 'react';
import { forwardRef } from '@wordpress/element';
import type { SpinnerProps } from './types';
import styles from './style.module.css';

/**
* A component used to notify users that their action is being processed.
*/
export const Spinner = forwardRef< SVGSVGElement, ComponentProps< 'svg' > >(
function UnforwardedSpinner( { className, ...props }, ref ) {
export const Spinner = forwardRef< SVGSVGElement, SpinnerProps >(
function UnforwardedSpinner( { className, color, style, ...props }, ref ) {
return (
<svg
className={ clsx( styles.spinner, className ) }
style={ color === undefined ? style : { ...style, color } }
viewBox="0 0 100 100"
xmlns="http://www.w3.org/2000/svg"
role="presentation"
focusable="false"
{ ...props }
ref={ ref }
>
<circle
className={ styles.track }
cx="50"
cy="50"
r="50"
vectorEffect="non-scaling-stroke"
/>
<path
className={ styles.indicator }
d="m 50 0 a 50 50 0 0 1 50 50"
d="m 50 0 a 50 50 0 0 1 0 100"
vectorEffect="non-scaling-stroke"
/>
</svg>
Expand Down
23 changes: 23 additions & 0 deletions packages/ui/src/spinner/stories/index.story.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import type { Meta, StoryObj } from '@storybook/react-vite';
import { Stack } from '../../stack';
import { Spinner } from '../index';

const meta: Meta< typeof Spinner > = {
tags: [ 'manifest' ],
title: 'Components/@wordpress-ui/Spinner',
id: 'design-system-components-spinner',
component: Spinner,
argTypes: {
color: { control: 'text' },
},
parameters: {
componentStatus: {
status: 'recommended',
Expand All @@ -26,3 +30,22 @@ export const CustomSize: Story = {
},
},
};

export const CustomColor: Story = {
args: { color: '#d92d20' },
};

export const CurrentColor: Story = {
args: { color: 'currentColor' },
render: ( args ) => (
<Stack
direction="row"
gap="sm"
align="center"
style={ { color: '#7f32c9' } }
>
<Spinner { ...args } />
<span>Loading…</span>
</Stack>
),
};
13 changes: 3 additions & 10 deletions packages/ui/src/spinner/style.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,13 @@
overflow: visible;
opacity: 1;
background-color: transparent;
color: var(--wpds-color-foreground-content-neutral-weak);
}

.track,
.indicator {
fill: transparent;
stroke-width: 1.5px;
}

.track {
stroke: var(--wpds-color-background-track-neutral);
}

.indicator {
stroke: var(--wpds-color-background-thumb-brand);
stroke: currentColor;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on the color being set, the spinner could become invisible in forced color mode. Should we give the indicator a system-color stroke in forced-colors mode?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed:

Before After
Spinner invisible in forced-colors mode Spinner visible in forced-colors mode

stroke-width: var(--wpds-border-width-focus);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matches what is currently used in the Button spinner, but unclear if a focus ring token is appropriate for this long term.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd favor an appropriate token over maintaining appearance. --wpds-border-width-sm is 2px, so very little difference.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried the 2px version. It is kind of prominent in smaller sizes 🤔 Maybe that's fine.

CleanShot.2026-09-30.at.16-00-19.mp4
CleanShot.2026-09-30.at.16-01-19.mp4

stroke-linecap: round;
transform-origin: 50% 50%;

Expand Down
11 changes: 11 additions & 0 deletions packages/ui/src/spinner/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { ComponentProps } from 'react';

export type SpinnerProps = Omit< ComponentProps< 'svg' >, 'color' > & {
/**
* The spinner color. Accepts any CSS color value, including `currentColor`
* to inherit the surrounding text color.
*
* @default 'var(--wpds-color-foreground-content-neutral-weak)'
*/
color?: string;
};
Loading