미리보기
코드
////////////////////////////// 사용 예시 //////////////////////////////
<StyledSwitch $width={100} $height={50} />
////////////////////////////// 스타일 컴포넌트 타입 //////////////////////////////
type StyledSwitchPropsType = {
$width: number;
$height: number;
};
////////////////////////////// 스타일 컴포넌트 정의 //////////////////////////////
const StyledSwitch = styled(Switch, { shouldForwardProp })<StyledSwitchPropsType>`
&& {
width: ${({ $width }) => $width}px;
height: ${({ $height }) => $height + $height * 0.15}px;
padding: 0px;
.MuiSwitch-switchBase {
padding: 0px;
margin: ${({ $height }) => $height * 0.075}px;
transform: translateX(0);
&.Mui-checked {
transform: translateX(${(props) => props.$width / 2 - props.$width * 0.1}px);
& + .MuiSwitch-track {
opacity: 1;
}
}
}
.MuiSwitch-thumb {
width: ${({ $width }) => $width / 2}px;
height: ${({ $height }) => $height}px;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2);
background-color: ${({ theme }) => theme.palette.background.paper};
}
.MuiSwitch-track {
border-radius: ${({ $width }) => $width / 3}px;
opacity: 0.5;
}
}
`;
'라이브러리 > MUI' 카테고리의 다른 글
[MUI] 스타일 프롭스 추가 | shouldForwardProp 사용방법 (0) | 2025.04.22 |
---|---|
[Next.js + MUI + Emotion] Received true for a non-boolean attribute $preview 오류 해결기 (0) | 2025.04.22 |
[MUI] 컴포넌트에 스타일 프롭스 추가하는 방법 (0) | 2025.04.22 |
[MUI] 캘린더 달력 한국 시간으로 변경하기 (0) | 2025.04.17 |
[MUI] <SwipeableTemporaryDrawer/> 전역 상태로 상태 관리 방법 feat.예시코드 (0) | 2025.04.15 |