Skip to content

Commit

Permalink
fix(plasma-core): add default uniqId for Spinner
Browse files Browse the repository at this point in the history
  • Loading branch information
kayman233 committed Apr 25, 2023
1 parent e240bd9 commit ff10511
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,17 @@ describe('plasma-core: Spinner', () => {
);
cy.matchImageSnapshot();
});

it('many colors', () => {
mount(
<CypressTestDecorator>
<Spin size={32} color="green" />
<PadMe />
<Spin size={32} color="blue" />
<PadMe />
<Spin size={32} color="red" />
</CypressTestDecorator>,
);
cy.matchImageSnapshot();
});
});
7 changes: 5 additions & 2 deletions packages/plasma-core/src/components/Spinner/Spinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import styled, { keyframes, css } from 'styled-components';

import { accent } from '../../tokens';
import { useUniqId } from '../../hooks';

import { SpinnerSvg } from './SpinnerSvg';

Expand Down Expand Up @@ -48,11 +49,13 @@ const sizeFormatting = (size: number | string, deviceScale = 1): string => {
*/
export const Spinner: React.FC<SpinnerProps> = (props) => {
const { id, size = 56, color = accent, deviceScale, ...rest } = props;
const uniqId = useUniqId();
const innerId = id || uniqId;
const currentSize = sizeFormatting(size, deviceScale);

return (
<StyledRoot id={id} $size={currentSize} {...rest}>
<SpinnerSvg id={id} width={size} height={size} color={color} />
<StyledRoot id={innerId} $size={currentSize} {...rest}>
<SpinnerSvg id={innerId} width={size} height={size} color={color} />
</StyledRoot>
);
};

0 comments on commit ff10511

Please sign in to comment.