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 15, 2024
1 parent 5a0f838 commit 8226377
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
14 changes: 10 additions & 4 deletions packages/css/spinner.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
.ds-spinner {
--dsc-spinner-background: var(--ds-color-surface-default);
--dsc-spinner-stroke: var(--ds-color-border-default);
--dsc-spinner-color: currentColor;

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

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

Expand Down Expand Up @@ -37,13 +40,14 @@
}

.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;
}

Expand Down Expand Up @@ -75,10 +79,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 8226377

Please sign in to comment.