Skip to content

Commit

Permalink
feat(spinner): introduce a busy bar
Browse files Browse the repository at this point in the history
this is a great component to use with the useViewLoading hook above an esri.Map component
  • Loading branch information
steveoh committed Nov 6, 2024
1 parent da18794 commit 8f98ea0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
13 changes: 12 additions & 1 deletion packages/utah-design-system/src/components/Spinner.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta } from '@storybook/react';
import { Spinner as Component } from './Spinner';
import { BusyBar, Spinner as Component } from './Spinner.tsx';

const meta: Meta<typeof Component> = {
component: Component,
Expand All @@ -14,3 +14,14 @@ const meta: Meta<typeof Component> = {
export default meta;

export const Example = {};

export const BarExample = {
render: (args: { busy?: boolean }) => (
<div className="relative isolate min-w-96">
<BusyBar {...args} />
</div>
),
args: {
busy: true,
},
};
30 changes: 26 additions & 4 deletions packages/utah-design-system/src/components/Spinner.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { useProgressBar } from 'react-aria';

export const Spinner = () => {
const { progressBarProps } = useProgressBar({
isIndeterminate: true,
});

return (
<svg
{...progressBarProps}
className="h-full shrink-0 motion-safe:animate-spin"
fill="none"
role="progressbar"
aria-live="polite"
aria-hidden="false"
aria-valuetext="loading"
aria-label="Loading…"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
width="18"
Expand Down Expand Up @@ -37,3 +41,21 @@ Spinner.minDelay = async (promise: Promise<any>, ms = 2500) => {

return promise;
};

export const BusyBar = ({ busy }: { busy?: boolean }) => {
const { progressBarProps } = useProgressBar({
isIndeterminate: true,
});

if (!busy) {
return null;
}

return (
<div
{...progressBarProps}
aria-label="Loading…"
className="absolute inset-x-0 top-0 z-[1] h-2 w-full min-w-full animate-gradient-x bg-gradient-to-r from-secondary-700/90 from-30% via-accent-400/90 to-primary-800/90 to-70% transition-all duration-700 ease-in-out"
></div>
);
};

0 comments on commit 8f98ea0

Please sign in to comment.