Skip to content

Commit

Permalink
feat: create circular progress indicator (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fran McDade authored and Fran McDade committed Jun 6, 2024
1 parent d430305 commit 8016af1
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import styled from "@emotion/styled";

export const ProgressPositioner = styled.div`
display: flex;
position: relative; /* positions track */
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {
CircularProgress as MCircularProgress,
CircularProgressProps as MCircularProgressProps,
} from "@mui/material";
import React, { ElementType } from "react";
import { ProgressPositioner } from "./circularProgress.styles";
import { CircularProgressTrack } from "./components/CircularProgressTrack/circularProgressTrack";

export interface CircularProgressProps extends MCircularProgressProps {
className?: string;
Track?: ElementType<CircularProgressProps>;
}

export const CircularProgress = ({
className,
value,
Track = CircularProgressTrack,
...props /* Spread props to allow for CircularProgress specific props e.g. "disableShrink". */
}: CircularProgressProps): JSX.Element => {
return (
<ProgressPositioner className={className}>
<Track {...props} />
<MCircularProgress value={value} {...props} />
</ProgressPositioner>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import styled from "@emotion/styled";
import { CircularProgress as MCircularProgress } from "@mui/material";
import {
alertLight,
infoLight,
smokeLight,
successLight,
warningLight,
} from "../../../../../../../styles/common/mixins/colors";

export const CircularProgress = styled(MCircularProgress)`
color: ${smokeLight};
left: 0;
position: absolute;
top: 0;
z-index: 0;
&.MuiCircularProgress-colorAlert {
color: ${alertLight};
}
&.MuiCircularProgress-colorInfo {
color: ${infoLight};
}
&.MuiCircularProgress-colorSuccess {
color: ${successLight};
}
&.MuiCircularProgress-colorWarning {
color: ${warningLight};
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { CircularProgressProps as MCircularProgressProps } from "@mui/material";
import React, { Fragment } from "react";
import { CircularProgress } from "./circularProgressTrack.styles";

export interface CircularProgressTrackProps extends MCircularProgressProps {
className?: string;
track?: boolean;
}

export const CircularProgressTrack = ({
className,
track = true,
value = 100,
...props /* Spread props to allow for CircularProgress specific props e.g. "disableShrink". */
}: CircularProgressTrackProps): JSX.Element => {
return (
<Fragment>
{track && (
<CircularProgress className={className} value={value} {...props} />
)}
</Fragment>
);
};
12 changes: 6 additions & 6 deletions src/styles/common/mixins/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { CommonColors, PaletteColor } from "@mui/material/styles/createPalette";
import { ThemeProps } from "../../../theme/theme";

// Alert
export const alertLight = ({ theme }: ThemeProps): PaletteColor["light"] =>
theme.palette.alert.light;
export const alertLightest = ({
theme,
}: ThemeProps): PaletteColor["lightest"] => theme.palette.alert.lightest;
Expand All @@ -13,8 +15,6 @@ export const errorMain = ({ theme }: ThemeProps): PaletteColor["main"] =>
theme.palette.error.main;

// Info
export const infoDark = ({ theme }: ThemeProps): PaletteColor["dark"] =>
theme.palette.info.dark;
export const infoLight = ({ theme }: ThemeProps): PaletteColor["light"] =>
theme.palette.info.light;
export const infoLightest = ({ theme }: ThemeProps): PaletteColor["lightest"] =>
Expand All @@ -23,12 +23,8 @@ export const infoMain = ({ theme }: ThemeProps): PaletteColor["main"] =>
theme.palette.info.main;

// Ink
export const inkDark = ({ theme }: ThemeProps): PaletteColor["dark"] =>
theme.palette.ink.dark;
export const inkLight = ({ theme }: ThemeProps): PaletteColor["light"] =>
theme.palette.ink.light;
export const inkLightest = ({ theme }: ThemeProps): PaletteColor["lightest"] =>
theme.palette.ink.lightest;
export const inkMain = ({ theme }: ThemeProps): PaletteColor["main"] =>
theme.palette.ink.main;

Expand All @@ -50,13 +46,17 @@ export const smokeMain = ({ theme }: ThemeProps): PaletteColor["main"] =>
theme.palette.smoke.main;

// Success
export const successLight = ({ theme }: ThemeProps): PaletteColor["light"] =>
theme.palette.success.light;
export const successLightest = ({
theme,
}: ThemeProps): PaletteColor["lightest"] => theme.palette.success.lightest;
export const successMain = ({ theme }: ThemeProps): PaletteColor["main"] =>
theme.palette.success.main;

// Warning
export const warningLight = ({ theme }: ThemeProps): PaletteColor["light"] =>
theme.palette.warning.light;
export const warningLightest = ({
theme,
}: ThemeProps): PaletteColor["lightest"] => theme.palette.warning.lightest;
Expand Down
27 changes: 27 additions & 0 deletions src/theme/common/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,33 @@ export const MuiChip = (theme: Theme): Components["MuiChip"] => {
};
};

/**
* MuiCircularProgress Component
* @param theme - Theme.
* @returns MuiCircularProgress component theme styles.
*/
export const MuiCircularProgress = (
theme: Theme
): Components["MuiCircularProgress"] => {
return {
styleOverrides: {
circle: {
strokeLinecap: "round",
},
},
variants: [
{
props: {
color: "alert",
},
style: {
backgroundColor: theme.palette.alert.main,
},
},
],
};
};

/**
* MuiCssBaseline Component
* @param theme - Theme.
Expand Down
1 change: 1 addition & 0 deletions src/theme/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export function createAppTheme(customOptions?: ThemeOptions): Theme {
MuiCard: C.MuiCard,
MuiCheckbox: C.MuiCheckbox(theme),
MuiChip: C.MuiChip(theme),
MuiCircularProgress: C.MuiCircularProgress(theme),
MuiCssBaseline: C.MuiCssBaseline(theme),
MuiDialog: C.MuiDialog(theme),
MuiDialogActions: C.MuiDialogActions,
Expand Down
10 changes: 10 additions & 0 deletions types/data-explorer-ui.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {} from "@mui/material/Alert";
import type {} from "@mui/material/Button";
import type {} from "@mui/material/Checkbox";
import type {} from "@mui/material/Chip";
import type {} from "@mui/material/CircularProgress";
import type {} from "@mui/material/IconButton";
import type {} from "@mui/material/Paper";
import type {} from "@mui/material/styles";
Expand Down Expand Up @@ -54,6 +55,15 @@ declare module "@mui/material/Button" {
}
}

/**
* CircularProgress prop options.
*/
declare module "@mui/material/CircularProgress" {
interface CircularProgressPropsColorOverrides {
alert: true;
}
}

/**
* Checkbox prop options.
*/
Expand Down

0 comments on commit 8016af1

Please sign in to comment.