Skip to content

Commit

Permalink
feat: add better prop handling
Browse files Browse the repository at this point in the history
  • Loading branch information
trevor-anderson committed Feb 20, 2024
1 parent 855821c commit bfe5882
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions src/components/Stepper/StepIconContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
import { styled } from "@mui/material/styles";
import Text, { typographyClasses } from "@mui/material/Typography";
import CheckIcon from "@mui/icons-material/Check";
import DotDotDotIcon from "@mui/icons-material/MoreHoriz";
import AlertTriangleIcon from "@mui/icons-material/Warning";
import type { StepIconProps } from "@mui/material/StepIcon";

export const StepIconContainer = ({ icon, active, completed, className, error }: StepIconProps) => (
<StyledDiv ownerState={{ completed, active, error }} className={className}>
{completed ? <CheckIcon /> : active ? error ? <AlertTriangleIcon /> : icon : <Text>...</Text>}
export const StepIconContainer = ({
icon,
active,
completed,
className,
error,
...containerProps
}: StepIconContainerProps) => (
<StyledDiv ownerState={{ completed, active, error }} className={className} {...containerProps}>
{completed ? (
<CheckIcon />
) : active ? (
error ? (
<AlertTriangleIcon />
) : (
icon
)
) : (
<DotDotDotIcon style={{ transform: "translateY(1px)" }} />
)}
</StyledDiv>
);

const StyledDiv = styled("div")<StepIconOwnerState>(({ theme: { palette }, ownerState }) => ({
const StyledDiv = styled("div", {
shouldForwardProp: (propName) => propName !== "ownerState",
})<StepIconOwnerState>(({ theme: { palette }, ownerState }) => ({
width: "100%",
height: "100%",
zIndex: 1,
Expand All @@ -32,11 +51,12 @@ const StyledDiv = styled("div")<StepIconOwnerState>(({ theme: { palette }, owner

...(ownerState.error && {
backgroundImage: `linear-gradient(135deg, ${palette.error.dark} 40%, ${palette.error.light})`,
"& > svg": {
// These styles nudge the icon up a bit and ensures it doesn't visually overflow the container
transform: "translateY(-1px)",
maxWidth: "80%",
},
}),

[`& > .${typographyClasses.root}`]: {
transform: "translateY(-2px)",
},
}));

interface StepIconOwnerState {
Expand All @@ -46,3 +66,6 @@ interface StepIconOwnerState {
error?: boolean;
};
}

export type StepIconContainerProps = StepIconProps &
Omit<React.ComponentProps<typeof StyledDiv>, "ownerState" | "className" | "children">;

0 comments on commit bfe5882

Please sign in to comment.