Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: [M3-8183] - Clean up loading components #10524

Merged
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tech Stories
---

Clean up loading components ([#10524](https://github.com/linode/manager/pull/10524))
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const Autocomplete = <
<>
{loading && (
<InputAdornment position="end">
<CircleProgress mini={true} />
<CircleProgress size="sm" />
</InputAdornment>
)}
{textFieldProps?.InputProps?.endAdornment}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,20 @@ describe('CircleProgress', () => {
expect(innerCircle).toBeInTheDocument();
});

it('renders a mini CircleProgress', () => {
const screen = renderWithTheme(<CircleProgress mini />);
it('renders a small CircleProgress', () => {
const screen = renderWithTheme(<CircleProgress size="sm" />);

const circleProgress = screen.getByLabelText(CONTENT_LOADING);
expect(circleProgress).toBeVisible();
expect(circleProgress).toHaveStyle('width: 40px; height: 40px;');
});

it('sets a mini CircleProgress with no padding', () => {
const screen = renderWithTheme(<CircleProgress mini noPadding />);
it('sets a small CircleProgress with no padding', () => {
const screen = renderWithTheme(<CircleProgress noPadding size="sm" />);

const circleProgress = screen.getByLabelText(CONTENT_LOADING);
expect(circleProgress).toBeVisible();
expect(circleProgress).toHaveStyle('width: 22px; height: 22px;');
});

it('sets a mini CircleProgress with a custom size', () => {
const screen = renderWithTheme(<CircleProgress mini size={25} />);

const circleProgress = screen.getByLabelText(CONTENT_LOADING);
expect(circleProgress).toBeVisible();
expect(circleProgress).toHaveStyle('width: 25px; height: 25px;');
expect(circleProgress).toHaveStyle('width: 20px; height: 20px;');
});

it('renders a CircleProgress without the inner circle', () => {
Expand Down
53 changes: 26 additions & 27 deletions packages/manager/src/components/CircleProgress/CircleProgress.tsx
hana-akamai marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,58 +1,59 @@
import _CircularProgress from '@mui/material/CircularProgress';
import { SxProps, styled } from '@mui/material/styles';
import * as React from 'react';

import { Box } from 'src/components/Box';
import {
CircularProgress,
CircularProgressProps,
} from 'src/components/CircularProgress';
import { omittedProps } from 'src/utilities/omittedProps';

interface CircleProgressProps extends CircularProgressProps {
import type { CircularProgressProps } from '@mui/material/CircularProgress';

interface CircleProgressProps extends Omit<CircularProgressProps, 'size'> {
/**
* Additional child elements to pass in
*/
children?: JSX.Element;
/**
* Displays a smaller version of the circle progress.
*/
mini?: boolean;
/**
* If true, will not show an inner circle beneath the spinning circle
*/
noInner?: boolean;
/**
* Removes the padding for `mini` circle progresses only.
* Removes the padding
*/
noPadding?: boolean;
/**
* To be primarily used with mini and noPadding. Set spinner to a custom size.
* Set spinner to a smaller custom size
hana-akamai marked this conversation as resolved.
Show resolved Hide resolved
*/
size?: number;
size?: 'md' | 'sm' | 'xs';
/**
* Additional styles to apply to the root element.
*/
sx?: SxProps;
}

const SIZE_MAP = {
md: 40,
sm: 20,
xs: 14,
};

/**
* Use for short, indeterminate activities requiring user attention.
*/
const CircleProgress = (props: CircleProgressProps) => {
const { children, mini, noInner, noPadding, size, sx, ...rest } = props;
const { children, noInner, noPadding, size, sx, ...rest } = props;

const variant =
typeof props.value === 'number' ? 'determinate' : 'indeterminate';
const value = typeof props.value === 'number' ? props.value : 0;

if (mini) {
if (size) {
hana-akamai marked this conversation as resolved.
Show resolved Hide resolved
return (
<StyledMiniCircularProgress
<StyledCustomCircularProgress
aria-label="Content is loading"
data-qa-circle-progress
data-testid="circle-progress"
noPadding={noPadding}
size={size ? size : noPadding ? 22 : 40}
size={noPadding ? SIZE_MAP[size] : SIZE_MAP[size] * 2}
tabIndex={0}
/>
);
Expand Down Expand Up @@ -116,19 +117,17 @@ const StyledTopDiv = styled('div')(({ theme }) => ({
width: 70,
}));

const StyledCircularProgress = styled(CircularProgress)<CircleProgressProps>(
({ theme }) => ({
position: 'relative',
[theme.breakpoints.down('sm')]: {
height: '72px !important',
width: '72px !important',
},
})
);
const StyledCircularProgress = styled(_CircularProgress)(({ theme }) => ({
position: 'relative',
[theme.breakpoints.down('sm')]: {
height: '72px !important',
width: '72px !important',
},
}));

const StyledMiniCircularProgress = styled(CircularProgress, {
const StyledCustomCircularProgress = styled(_CircularProgress, {
shouldForwardProp: omittedProps(['noPadding']),
})<CircleProgressProps>(({ theme, ...props }) => ({
})<{ noPadding: boolean | undefined }>(({ theme, ...props }) => ({
padding: `calc(${theme.spacing()} * 1.3)`,
...(props.noPadding && {
padding: 0,
Expand Down
17 changes: 0 additions & 17 deletions packages/manager/src/components/CircularProgress.stories.tsx

This file was deleted.

14 changes: 0 additions & 14 deletions packages/manager/src/components/CircularProgress.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const DebouncedSearchTextField = React.memo(
InputProps={{
endAdornment: isSearching ? (
<InputAdornment position="end">
<CircleProgress mini={true} />
<CircleProgress size="sm" />
</InputAdornment>
) : (
clearable &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { styled } from '@mui/material/styles';
import * as React from 'react';

import { CircularProgress } from 'src/components/CircularProgress';
import { CircleProgress } from 'src/components/CircleProgress';

export const LoadingIndicator = () => {
return <StyledCircularProgress data-testid="input-loading" size={20} />;
return <StyledCircleProgress data-testid="input-loading" size="sm" />;
};

const StyledCircularProgress = styled(CircularProgress)(() => ({
const StyledCircleProgress = styled(CircleProgress)(() => ({
position: 'relative',
right: 20,
}));

This file was deleted.

This file was deleted.

This file was deleted.

12 changes: 6 additions & 6 deletions packages/manager/src/components/LinkButton.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { Theme } from '@mui/material/styles';
import { makeStyles } from 'tss-react/mui';
import * as React from 'react';
import { makeStyles } from 'tss-react/mui';

import { CircleProgress } from 'src/components/CircleProgress';

import { Box } from './Box';
import { StyledLinkButton } from './Button/StyledLinkButton';
import { CircularProgress } from './CircularProgress';

const useStyles = makeStyles()((theme: Theme) => ({
disabled: {
color: theme.palette.text.primary,
cursor: 'default',
pointerEvents: 'none',
},
spinner: {
marginLeft: theme.spacing(),
},
}));

interface Props {
Expand Down Expand Up @@ -58,7 +56,9 @@ export const LinkButton = (props: Props) => {
return (
<Box alignItems="center" display="flex">
{Button}
<CircularProgress className={classes.spinner} size={12} />
<Box marginLeft={1}>
<CircleProgress noPadding size="xs" />
</Box>
</Box>
);
}
Expand Down
Loading
Loading