Last active
June 7, 2022 12:14
-
-
Save onmotion/d8e0b28878b95723b0de2f444b4feafe to your computer and use it in GitHub Desktop.
MUI TS styled component add props
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const CssTextField = styled(TextField, { | |
shouldForwardProp: (prop) => prop !== "resize", | |
})<{ resize?: boolean }>(({ theme, resize }) => { | |
console.log({ resize }); | |
return { | |
root: { | |
"& label.Mui-focused": { | |
color: theme.palette.primary.light, | |
}, | |
}, | |
}; | |
}); | |
const StyledComp = styled("div", { | |
shouldForwardProp: (prop) => prop !== "color" && prop !== 'myProp', | |
})<{ myProp?: boolean; color?: string }>(({ theme, myProp, color }) => ({ | |
backgroundColor: myProp ? "aliceblue" : "red", | |
color, | |
padding: theme.spacing(1) | |
})); | |
<StyledComp myProp color="red" /> // typed safe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment