DXC Logo
Halstack Design System
v16.1.0

Overview

Guidelines

Foundations

Migration

Utilities

Components

Spinner

Loading spinner is a waiting indicator in the user interface to communicate users an ongoing process.

Props

NameTypeDescriptionDefault
ariaLabelstringSpecifies a string to be used as the accessible name for the component when no label is provided or the mode is set to small.'Spinner'
New
inheritColor
booleanIf true, the color is inherited from the closest parent with a defined color. This allows users to adapt the spinner to the semantic color of the use case in which it is used.false
labelstringText to be placed inside the spinner. When the component is in small mode, this label acts as an aria-label value.-
margin'xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge' | MarginSize of the margin to be applied to the component. You can pass an object with 'top', 'bottom', 'left' and 'right' properties in order to specify different margin sizes.-
mode'large' | 'small' | 'overlay' The different variants of the components.'large'
showValuebooleanIf true, the value is displayed inside the spinner.false
valuenumberThe value of the progress indicator. If it's received the component is determinate, otherwise is indeterminate.-

Examples

Basic usage

() => {
  return (
    <DxcInset space="var(--spacing-padding-xl)">
      <DxcSpinner label="Loading..." />
    </DxcInset>
  );
}

Overlay

() => {
  const [isVisible, changeIsVisible] = useState(false);
  const showModal = () => {
    changeIsVisible(true);
    fetchData().then(() => {
      changeIsVisible(false);
    });
  };
  const fetchData = () => {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve();
      }, 3000);
    });
  };

  return (
    <DxcInset space="var(--spacing-padding-xl)">
      <DxcButton label="Show Spinner for 3 seconds" onClick={showModal} />
      {isVisible && <DxcSpinner label="Loading..." mode="overlay" />}
    </DxcInset>
  );
}