Skip to content

Commit

Permalink
fix(css,react): smoother spinner animation using opacity
Browse files Browse the repository at this point in the history
  • Loading branch information
unekinn committed Nov 18, 2024
1 parent 58ecb78 commit a158a39
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
19 changes: 15 additions & 4 deletions packages/css/spinner.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.ds-spinner {
--dsc-spinner-background: var(--ds-color-surface-default);
--dsc-spinner-stroke: var(--ds-color-border-default);
--dsc-spinner-color: currentColor;

--dsc-spinner-animation-duration: 2s;

Expand Down Expand Up @@ -37,14 +36,24 @@
}

.ds-spinner__background {
stroke: var(--dsc-spinner-background);
stroke: var(--dsc-spinner-color);
opacity: 20%;
}

.ds-spinner__circle {
animation: ds-spinner-stroke-animation ease-in-out infinite var(--dsc-spinner-animation-duration);
stroke-dasharray: 1px, 200px;
stroke: var(--dsc-spinner-stroke);
stroke: var(--dsc-spinner-color);
transform-origin: center;
opacity: 75%;
}

&[data-color] {
--dsc-spinner-color: var(--ds-color-border-default);

.ds-spinner__circle {
opacity: 100%;
}
}

/* Prefers reduced motion needs longer animation,
Expand Down Expand Up @@ -75,10 +84,12 @@ but don't remove it since it is not decorative.
50% {
stroke-dasharray: 100px, 200px;
stroke-dashoffset: -15px;
transform: rotate(0deg);
}

100% {
stroke-dasharray: 1px, 200px;
stroke-dashoffset: -120px;
transform: rotate(15deg);
}
}
8 changes: 4 additions & 4 deletions packages/react/src/components/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,15 @@ export const TextAndIcon: StoryFn<typeof Button> = () => (
</>
);

export const Loading: StoryFn<typeof Button> = () => (
export const Loading: StoryFn<typeof Button> = (args) => (
<>
<Button variant='primary' loading>
<Button {...args} variant='primary' loading>
Laster...
</Button>
<Button variant='secondary' loading>
<Button {...args} variant='secondary' loading>
Laster...
</Button>
<Button variant='tertiary' loading>
<Button {...args} variant='tertiary' loading>
Laster...
</Button>
</>
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/loaders/Spinner/Spinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type SpinnerProps = {
*/
'data-size'?: '2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl';
/**
* The color of the spinner. If left unspecified, the color is inherited from the nearest ancestor with data-color.
* The color of the spinner. If left unspecified, the current text color (`currentColor`) is used.
*/
'data-color'?: Color;
} & ComponentPropsWithoutRef<'svg'> &
Expand Down

0 comments on commit a158a39

Please sign in to comment.