Skip to content

Commit

Permalink
feat(spinner): add extra small size for spinner
Browse files Browse the repository at this point in the history
  • Loading branch information
anuradha9712 authored and innosatyam committed Nov 12, 2024
1 parent 4d5267b commit 16ab49f
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 33 deletions.
4 changes: 3 additions & 1 deletion core/components/atoms/button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ const ButtonElement = React.forwardRef<HTMLButtonElement, ButtonProps>((props, r
[`Button-regularIcon--${iconAlign}`]: children && iconAlign && size === 'regular' && !expanded,
});

const spinnerSize = size === 'large' && children ? 'small' : 'xsmall';

return (
<button
data-test="DesignSystem-Button"
Expand All @@ -153,7 +155,7 @@ const ButtonElement = React.forwardRef<HTMLButtonElement, ButtonProps>((props, r
{loading ? (
<>
<Spinner
size="small"
size={spinnerSize}
appearance={appearance === 'basic' || appearance === 'transparent' ? 'secondary' : 'white'}
data-test="DesignSystem-Button--Spinner"
className="Button-spinner"
Expand Down
2 changes: 1 addition & 1 deletion core/components/atoms/button/__stories__/Loading.story.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { Button } from '@/index';

export const LoaderInButton = () => <Button appearance="primary" loading={true} aria-label="loading" />;
export const LoaderInButton = () => <Button loading={true} aria-label="loading" />;

export default {
title: 'Components/Button/Button/Loader In Button',
Expand Down
37 changes: 37 additions & 0 deletions core/components/atoms/button/__tests__/Button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,43 @@ describe('Button component with icon', () => {
expect(getByTestId('DesignSystem-Button--Spinner')).toHaveClass('Button-spinner');
});

it('Should have Spinner--xsmall class when loading state for button size=tiny', () => {
const { getByTestId } = render(
<Button loading={true} size="tiny">
Button
</Button>
);
expect(getByTestId('DesignSystem-Button--Spinner')).toHaveClass('Spinner--xsmall');
});

it('Should have Spinner--xsmall class when loading state for button size=regular', () => {
const { getByTestId } = render(
<Button loading={true} size="regular">
Button
</Button>
);
expect(getByTestId('DesignSystem-Button--Spinner')).toHaveClass('Spinner--xsmall');
});

it('Should have Spinner--small class when loading state for button size=large', () => {
const { getByTestId } = render(
<Button loading={true} size="large">
Button
</Button>
);
expect(getByTestId('DesignSystem-Button--Spinner')).toHaveClass('Spinner--small');
});

it('Should have Spinner--xsmall class when loading state for icon button', () => {
const { getByTestId } = render(<Button loading={true} icon="places" />);
expect(getByTestId('DesignSystem-Button--Spinner')).toHaveClass('Spinner--xsmall');
});

it('Should have Spinner--xsmall class when loading state for large icon button', () => {
const { getByTestId } = render(<Button loading={true} icon="places" size="large" />);
expect(getByTestId('DesignSystem-Button--Spinner')).toHaveClass('Spinner--xsmall');
});

it('Should have no Button-spinner class when no loading state', () => {
const { getByTestId } = render(<Button loading={false}>Button</Button>);
expect(getByTestId('DesignSystem-Button')).not.toHaveClass('Button-spinner');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ exports[`Button component
tabindex="0"
>
<svg
class="Spinner Spinner--small Button-spinner"
class="Spinner Spinner--xsmall Button-spinner"
data-test="DesignSystem-Button--Spinner"
viewBox="0 0 50 50"
>
Expand All @@ -84,7 +84,7 @@ exports[`Button component
fill="none"
r="20"
stroke-miterlimit="10"
stroke-width="4"
stroke-width="8"
/>
</svg>
<span
Expand Down Expand Up @@ -191,7 +191,7 @@ exports[`Button component
tabindex="0"
>
<svg
class="Spinner Spinner--small Button-spinner"
class="Spinner Spinner--xsmall Button-spinner"
data-test="DesignSystem-Button--Spinner"
viewBox="0 0 50 50"
>
Expand All @@ -202,7 +202,7 @@ exports[`Button component
fill="none"
r="20"
stroke-miterlimit="10"
stroke-width="4"
stroke-width="8"
/>
</svg>
<span
Expand Down Expand Up @@ -309,7 +309,7 @@ exports[`Button component
tabindex="0"
>
<svg
class="Spinner Spinner--small Button-spinner"
class="Spinner Spinner--xsmall Button-spinner"
data-test="DesignSystem-Button--Spinner"
viewBox="0 0 50 50"
>
Expand All @@ -320,7 +320,7 @@ exports[`Button component
fill="none"
r="20"
stroke-miterlimit="10"
stroke-width="4"
stroke-width="8"
/>
</svg>
<span
Expand Down Expand Up @@ -427,7 +427,7 @@ exports[`Button component
tabindex="0"
>
<svg
class="Spinner Spinner--small Button-spinner"
class="Spinner Spinner--xsmall Button-spinner"
data-test="DesignSystem-Button--Spinner"
viewBox="0 0 50 50"
>
Expand All @@ -438,7 +438,7 @@ exports[`Button component
fill="none"
r="20"
stroke-miterlimit="10"
stroke-width="4"
stroke-width="8"
/>
</svg>
<span
Expand Down Expand Up @@ -904,7 +904,7 @@ exports[`Button component with no children
tabindex="0"
>
<svg
class="Spinner Spinner--small Button-spinner"
class="Spinner Spinner--xsmall Button-spinner"
data-test="DesignSystem-Button--Spinner"
viewBox="0 0 50 50"
>
Expand All @@ -915,7 +915,7 @@ exports[`Button component with no children
fill="none"
r="20"
stroke-miterlimit="10"
stroke-width="4"
stroke-width="8"
/>
</svg>
<span
Expand All @@ -939,7 +939,7 @@ exports[`Button component with no children
tabindex="0"
>
<svg
class="Spinner Spinner--small Button-spinner"
class="Spinner Spinner--xsmall Button-spinner"
data-test="DesignSystem-Button--Spinner"
viewBox="0 0 50 50"
>
Expand All @@ -950,7 +950,7 @@ exports[`Button component with no children
fill="none"
r="20"
stroke-miterlimit="10"
stroke-width="4"
stroke-width="8"
/>
</svg>
<span
Expand All @@ -974,7 +974,7 @@ exports[`Button component with no children
tabindex="0"
>
<svg
class="Spinner Spinner--small Button-spinner"
class="Spinner Spinner--xsmall Button-spinner"
data-test="DesignSystem-Button--Spinner"
viewBox="0 0 50 50"
>
Expand All @@ -985,7 +985,7 @@ exports[`Button component with no children
fill="none"
r="20"
stroke-miterlimit="10"
stroke-width="4"
stroke-width="8"
/>
</svg>
<span
Expand All @@ -1009,7 +1009,7 @@ exports[`Button component with no children
tabindex="0"
>
<svg
class="Spinner Spinner--small Button-spinner"
class="Spinner Spinner--xsmall Button-spinner"
data-test="DesignSystem-Button--Spinner"
viewBox="0 0 50 50"
>
Expand All @@ -1020,7 +1020,7 @@ exports[`Button component with no children
fill="none"
r="20"
stroke-miterlimit="10"
stroke-width="4"
stroke-width="8"
/>
</svg>
<span
Expand Down
13 changes: 11 additions & 2 deletions core/components/atoms/spinner/Spinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import classNames from 'classnames';
import { BaseProps, extractBaseProps } from '@/utils/types';

export type SpinnerAppearance = 'primary' | 'secondary' | 'white';
export type SpinnerSize = 'small' | 'medium' | 'large';
export type SpinnerSize = 'xsmall' | 'small' | 'medium' | 'large';

export interface SpinnerProps extends BaseProps {
/**
Expand All @@ -30,6 +30,7 @@ export const Spinner = (props: SpinnerProps) => {
},
className
);

const circleClasses = classNames({
Circle: true,
[`Circle--${appearance}`]: appearance,
Expand All @@ -38,13 +39,21 @@ export const Spinner = (props: SpinnerProps) => {
const svgProps = {
viewBox: '0 0 50 50',
};

const strokeWidthMapping = {
xsmall: 8,
small: 6,
medium: 4,
large: 4,
};

const circleProps = {
cx: 25,
cy: 25,
r: 20,
fill: 'none',
strokeMiterlimit: '10',
strokeWidth: '4',
strokeWidth: strokeWidthMapping[size],
};

return (
Expand Down
2 changes: 1 addition & 1 deletion core/components/atoms/spinner/__stories__/Size.story.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Spinner, Text } from '@/index';

// CSF format story
export const size = () => {
const sizes = ['small', 'medium', 'large'];
const sizes = ['xsmall', 'small', 'medium', 'large'];
return (
<div className="d-flex">
{sizes.map((SpinnerSize, ind) => {
Expand Down
2 changes: 1 addition & 1 deletion core/components/atoms/spinner/__tests__/Spinner.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Spinner, { SpinnerProps as Props } from '../Spinner';
import { testHelper, filterUndefined, valueHelper, testMessageHelper } from '@/utils/testHelper';

const appearance = ['primary', 'secondary', 'white'];
const size = ['small', 'medium', 'large'];
const size = ['xsmall', 'small', 'medium', 'large'];

describe('Spinner component', () => {
const mapper = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,30 @@ exports[`Spinner component
fill="none"
r="20"
stroke-miterlimit="10"
stroke-width="4"
stroke-width="6"
/>
</svg>
</div>
</body>
`;

exports[`Spinner component
size: "xsmall"
1`] = `
<body>
<div>
<svg
class="Spinner Spinner--xsmall"
viewBox="0 0 50 50"
>
<circle
class="Circle Circle--primary"
cx="25"
cy="25"
fill="none"
r="20"
stroke-miterlimit="10"
stroke-width="8"
/>
</svg>
</div>
Expand Down
10 changes: 0 additions & 10 deletions css/src/components/button.css
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,6 @@
z-index: 1;
}

.Button--tiny .Spinner--small {
height: var(--font-size-s);
width: var(--font-size-s);
}

.Button--large .Spinner--small {
height: var(--font-size-l);
width: var(--font-size-l);
}

.Button--selected {
background: var(--primary-lightest);
color: var(--primary-dark);
Expand Down
5 changes: 5 additions & 0 deletions css/src/components/spinner.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
animation: rotate 2s linear infinite;
}

.Spinner--xsmall {
height: var(--spacing-l);
width: var(--spacing-l);
}

.Spinner--small {
height: var(--spacing-2);
width: var(--spacing-2);
Expand Down

0 comments on commit 16ab49f

Please sign in to comment.