Skip to content

Commit

Permalink
refactor: [M3-8183] - Clean up loading components (#10524)
Browse files Browse the repository at this point in the history
## Description 📝
We have a lot of loading components that are all basically just variations of CircleProgress. This PR cleans up those components.

I also moved the overage pricing tooltip text position in the Object Storage Create Bucket drawer to the top so that the tooltip doesn't block the CTA buttons

## How to test 🧪
### Verification steps
(How to verify changes)
- Check the affected loading spinners throughout the app
  • Loading branch information
hana-akamai authored Jun 5, 2024
1 parent d52ad40 commit a0c4520
Show file tree
Hide file tree
Showing 50 changed files with 122 additions and 320 deletions.
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 @@ -15,40 +15,21 @@ describe('CircleProgress', () => {
const circle = screen.getByTestId('circle-progress');
expect(circle).toBeInTheDocument();
expect(circle).toHaveStyle('width: 124px; height: 124px;');
const innerCircle = screen.getByTestId('inner-circle-progress');
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;');
});

it('renders a CircleProgress without the inner circle', () => {
const screen = renderWithTheme(<CircleProgress noInner />);

const circleProgress = screen.getByLabelText(CONTENT_LOADING);
expect(circleProgress).toBeVisible();
const innerCircle = screen.queryByTestId('inner-circle-progress');
expect(innerCircle).not.toBeInTheDocument();
expect(circleProgress).toHaveStyle('width: 20px; height: 20px;');
});
});
90 changes: 34 additions & 56 deletions packages/manager/src/components/CircleProgress/CircleProgress.tsx
Original file line number Diff line number Diff line change
@@ -1,58 +1,63 @@
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.
* Sets the size of the spinner
* @default "lg"
*/
size?: number;
size?: 'lg' | 'md' | 'sm' | 'xs';
/**
* Additional styles to apply to the root element.
*/
sx?: SxProps;
}

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

/**
* Use for short, indeterminate activities requiring user attention.
* Use for short, indeterminate activities requiring user attention. Defaults to large.
*
* sizes:
* xs = 14
* md = 20
* md = 40
* lg = 124
*/
const CircleProgress = (props: CircleProgressProps) => {
const { children, mini, noInner, noPadding, size, sx, ...rest } = props;
const { children, 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) {
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 All @@ -63,16 +68,11 @@ const CircleProgress = (props: CircleProgressProps) => {
{children !== undefined && (
<Box sx={{ marginTop: 4, position: 'absolute' }}>{children}</Box>
)}
{noInner !== true && (
<StyledTopWrapperDiv data-testid="inner-circle-progress">
<StyledTopDiv />
</StyledTopWrapperDiv>
)}
<StyledCircularProgress
{...rest}
data-qa-circle-progress={value}
data-testid="circle-progress"
size={124}
size={SIZE_MAP['lg']}
thickness={2}
value={value}
variant={variant}
Expand All @@ -96,39 +96,17 @@ const StyledRootDiv = styled('div')(({ theme }) => ({
width: '100%',
}));

const StyledTopWrapperDiv = styled('div')(({}) => ({
alignItems: 'center',
display: 'flex',
height: '100%',
justifyContent: 'center',
position: 'absolute',
width: '100%',
}));

const StyledTopDiv = styled('div')(({ theme }) => ({
border: '1px solid #999',
borderRadius: '50%',
height: 70,
[theme.breakpoints.up('sm')]: {
height: 120,
width: 120,
const StyledCircularProgress = styled(_CircularProgress)(({ theme }) => ({
position: 'relative',
[theme.breakpoints.down('sm')]: {
height: '72px !important',
width: '72px !important',
},
width: 70,
}));

const StyledCircularProgress = styled(CircularProgress)<CircleProgressProps>(
({ 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.

Loading

0 comments on commit a0c4520

Please sign in to comment.