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

[material-ui][Stepper] Add classes .Mui-active for MuiStep-root #42301

Closed
PunkFleet opened this issue May 19, 2024 · 1 comment
Closed

[material-ui][Stepper] Add classes .Mui-active for MuiStep-root #42301

PunkFleet opened this issue May 19, 2024 · 1 comment
Labels
component: stepper This is the name of the generic UI component, not the React module!

Comments

@PunkFleet
Copy link

PunkFleet commented May 19, 2024

Summary

This is custom style, i add a rounded background color for MuiStep-root, but i found there not classes .Mui-active

Examples

image

'use client';
import styled from "@emotion/styled";
import { Step, StepConnector, StepIconProps, StepLabel, Stepper, stepClasses, stepConnectorClasses, stepLabelClasses, stepperClasses } from "@mui/material";
import CheckCircleIcon from '@mui/icons-material/CheckCircle';
import ReceiptIcon from '@mui/icons-material/Receipt';
import PaymentIcon from '@mui/icons-material/Payment';
import RedeemIcon from '@mui/icons-material/Redeem';

const steps = ['Billing Information', 'Payment Information', 'Order Confirmation'];

export default function Page({ }) {
    return (
        <CustomStepper  activeStep={1} connector={<Connector />}>
            {steps.map((label) => (
                <Step key={label} >
                    <CustomStepLabel StepIconComponent={StepIcon}>{label}</CustomStepLabel>
                </Step>
            ))}
        </CustomStepper>
    )
}
const CustomStepper = styled(Stepper)(() => ({
    [`& .${stepClasses.root}`]: {
        [`&.${stepLabelClasses.completed}`]: {
            backgroundColor: '#e1d5ff',
            padding: 8,
            border: '1px solid #e1d5ff',
            borderRadius: 20,
        },
        padding: 8,
        backgroundColor: 'rgb(245 245 245 /.8)',
        border: '1px solid rgb(245 245 245 /.8)',
        borderRadius: 20,
    }
}))
const CustomStepLabel = styled(StepLabel)(({ theme }) => ({
    [`& .${stepLabelClasses.label}`]: {
        [`&.${stepLabelClasses.completed}`]: {
            color: "#784af4"
        },
        [`&.${stepLabelClasses.active}`]: {
            color: "#784af4",
        },

        color: "gray",
        padding: 1,
    }
}));
const Connector = styled(StepConnector)(() => ({
    [`&.${stepConnectorClasses.alternativeLabel}`]: {
        top: 10,
        left: 'calc(-50% + 16px)',
        right: 'calc(50% + 16px)',
    },
    [`&.${stepConnectorClasses.active}`]: {
        [`& .${stepConnectorClasses.line}`]: {
            borderColor: '#784af4',
        },
    },
    [`&.${stepConnectorClasses.completed}`]: {
        [`& .${stepConnectorClasses.line}`]: {
            borderColor: '#784af4',
        },
    },
    [`& .${stepConnectorClasses.line}`]: {
        borderColor: '#eaeaf0',
        borderTopWidth: 3,
        borderRadius: 1,
    },
}));
const StepIconRoot = styled('div')<{ ownerState: { active?: boolean, completed?: boolean } }>(
    ({ ownerState }) => ({
        color: 'gray',
        display: 'flex',
        height: 22,
        alignItems: 'center',
        ...(ownerState.active && {
            color: '#784af4',
        }),
        ...(ownerState.completed && {
            color: '#784af4',
        }),
    }),
);

function StepIcon(props: StepIconProps) {
    const { active, completed, className } = props;
    const icons: { [index: string]: React.ReactElement } = {
        1: <ReceiptIcon />,
        2: <PaymentIcon />,
        3: <RedeemIcon />,
    };
    return (
        <StepIconRoot ownerState={{ completed, active }} className={className}>
            {completed ? (
                <CheckCircleIcon />
            ) : icons[String(props.icon)]
            }
        </StepIconRoot>
    );
}

Motivation

No response

Search keywords: stepper Mui-active MuiStep-root

@PunkFleet PunkFleet added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label May 19, 2024
@PunkFleet PunkFleet changed the title [Stepper] Add classes .Mui-active for MuiStep-root [material-ui][Stepper] Add classes .Mui-active for MuiStep-root May 20, 2024
@PunkFleet
Copy link
Author

The class categories here look a bit confusing, and I accomplished the desired effect by specifying subclasses

<Stepper activeStep={0} connector={<Connector />}>
            {steps.map((label) => (
                <CustomStep key={label}>
                    <StepLabel StepIconComponent={StepIcon}>{label}</StepLabel>
                </CustomStep>
            ))}
        </Stepper>
        //........
const CustomStep = styled(Step)(({ theme }) => ({
    [`&.Mui-completed .${stepLabelClasses.root}`]: {
        backgroundColor: "#e1d5ff",
        borderRadius: 20,
        padding: 8,
        color: "#784af4",
    },
    [`& .${stepLabelClasses.root}`]: {
        backgroundColor: "#784af4",
        borderRadius: 20,
        padding: 8,

        color: "gray",
        [`&.${stepLabelClasses.disabled}`]: {
            backgroundColor: "rgb(0 0 0 /.3)",
            borderRadius: 20,
            padding: 8,
            color: "gray",
        },
    },
    [`& .${stepLabelClasses.label}`]: {
        [`&.${stepLabelClasses.completed}`]: {
            color: "#784af4",
            fontWeight: 600,
        },
        [`&.${stepLabelClasses.active}`]: {
            color: "white",
            fontWeight: 600,
        },
        [`&.${stepLabelClasses.disabled}`]: {
            color: "white",
            fontWeight: 600,
        },
        color: "gray",
        padding: 1,
        fontWeight: 600,
    },
}));

@github-actions github-actions bot removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label May 20, 2024
@zannager zannager added the component: stepper This is the name of the generic UI component, not the React module! label May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: stepper This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests

2 participants