Preloader Graphic
A visual element that shows an operation is in progress.
Playground
Size Variant
The Preloader comes in a variety of sizes:
<><BasicPreloader visuallyHiddenLabel="Loading" sizeVariant="large" /><BasicPreloader visuallyHiddenLabel="Loading" sizeVariant="extra-large" /></>
<asideclass="preloader-graphic preloader-graphic-large"aria-live="polite"role="status"><span class="preloader-graphic-inner"></span><span class="visually-hidden">Loading...</span></aside><asideclass="preloader-graphic preloader-graphic-extra-large"aria-live="polite"role="status"><span class="preloader-graphic-inner"></span><span class="visually-hidden">Loading...</span></aside>
Inline
If you need to render a loader inline with some text, you can use the "inline" option.
Please look at this animation Loading...while you are waiting.
<p>Please look at this animation<BasicPreloader visuallyHiddenLabel="Loading..." inline />while you are waiting.</p>
<p>Please look at this animation<!-- note: the inline version uses a <span> tag instead of <aside> --><spanclass="preloader-graphic preloader-graphic-inline"aria-live="polite"role="status"><span class="preloader-graphic-inner"></span><span class="visually-hidden">Loading...</span></span>while you are waiting.</p>
Centered
The "centered" option centers the Preloader Graphic within its container.
Button Loader
Sometimes when a button is clicked, the user needs to wait for a little bit while things are processing. In order to indicate that some sort of processing is taking place, you can render a Preloader
inside of a TextButton
.
When a Preloader
is rendered inside of a TextButton
, it gets a new look that's specifically designed for buttons.
() => {const [isPlacingOrder, setIsPlacingOrder] = React.useState(false)return (<TextButtononClick={() => {setIsPlacingOrder(true)// reset the button after a few seconds for demo purposessetTimeout(() => {setIsPlacingOrder(false)}, 2000)}}>{isPlacingOrder && <BasicPreloader />}{isPlacingOrder ? 'Placing order' : 'Place order'}</TextButton>)}
Skeleton screen
Skeleton screens are a form of loader, separate from the Preloader Graphic component. They show the page's UI and layout, but with a blank, shimmering content that tells the user that the content is still loading.
You can build skeleton screens using the Background Color feature, and choosing the "loading-shimmer" color. This will give the shimmering "skeleton screen" background to the component that has the Background Color on it.
<><Box backgroundColor="loading-shimmer" mb="8" style={{ height: 30 }}></Box><StandardTile skin="product"><StandardTileImage backgroundColor="loading-shimmer"></StandardTileImage><StandardTileContents><StandardTileName>Tile name</StandardTileName><StandardTileDescription>Tile description</StandardTileDescription></StandardTileContents></StandardTile></>
Components
Preloader
Prop | Type | Default | Description |
---|---|---|---|
sizeVariant | "standard" | "large" | "extra-large" | standard | The visual style of the Loader |
inline | boolean | Whether or not the Loader should be rendered inline with other elements | |
centered | boolean | Whether or not the Loader should be horizontally centered within its container |
All other props are forwarded to the element specified in thecomponent
prop(default: <div/>
)
PreloaderInner
PreloaderInner
has no props of its own
All props are forwarded to the element specified in thecomponent
prop(default: <div/>
)
React
If you need more control over the individual elements of the BasicPreloader
, you can use the composition-API to customize each individual component
.
Convenience Components
The React BasicPreloader
component is a convenience component created by combining basic components together, so if you find that it isn't exactly what you need, you can easily compose your own version!
Prop | Type | Default | Description |
---|---|---|---|
sizeVariant | "standard" | "large" | "extra-large" | "standard" | The visual style of the Loader |
inline | boolean | false | Whether or not the Loader should be rendered inline with other elements |
centered | boolean | false | Whether or not the Loader should be horizontally centered within its container |
visuallyHiddenLabel | string | A localized string which will be visually-hidden, but will be read aloud by screen-readers |
It is based on the Preloader
and PreloaderInner
components. The visuallyHiddenLabel
is placed inside of a VisuallyHidden
, and the rest of the props are forwarded to the Preloader
.
What's Under the Hood?
<Preloader {...otherProps}><PreloaderInner /><VisuallyHidden>{visuallyHiddenLabel}</VisuallyHidden></Preloader>
Guidelines
Developer Guidelines
While the Visage package also includes a preloader .GIF for legacy reasons, we recommend using it only when absolutely necessary (e.g. there's no other choice but to do the preloader as a background image). The Preloader Graphic component is preferable because it loads faster than the .GIF, and has crisper edges (because it uses vector graphics).
Accessibility Guidelines
To support accessibility, the component needs visually hidden text inside it that describes what is happening (e.g. "Loading..."). In React, the
visuallyHiddenLabel
forBasicPreloader
takes care of this.