-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Solution for composition? #2
Comments
Sorry for late reply @awdyson , type Props ={
size: "big" | "small";
};
const { useClassNames } = createUseClassNames<Props & { color: "red" | "blue" }>()(
(theme, { size, color }) => ({
link: {
...
'&:hover': {
extend: 'activeLink', // JSS solution
},
},
activeLink: {
// Here you have access to "size" from Props and "color" from internal state
},
}));
function MyComponent(props: Props){
const [ color, setColor ] = useState<"red" | "blue">("red");
const { classNames } = useClassNames({ ...props, color });
//...
} Best regard |
Sorry, I should have been more clear. I'm looking to share styling between classes, within the context of a single So, to rework the example above: const helper = (theme, props) => ({
// shared style that relies on theme and/or props
});
const { useClassNames } = createUseClassNames<Props>()((theme, props) => ({
link: {
// other styles
'&:hover': helper(theme, props),
},
activeLink: helper(theme, props),
})); Hopefully this makes sense. |
@awdyson This is actually a very good point, we need to support that. |
I will, soon, implement something like that: const { classes, getLinkCss } = makeStyles<Props>()(
(theme, props) => ({
"link": {
// other styles
"&:hover": {
//style specific to hover link
},
},
"activeLink": {
...getLinkCss(theme, props)["&:hover"],
//style specific to activeLink
}
})
);
//getLinkCss can be exported for reuse outside of the file.
export { getLinkCss }; We'll get correct typing of There will be some voodoo involved to prevent infinite recursion behind the seen but it will be transparent to the user. |
In the end I figured out that there is no need for a dedicated API. |
Haven't been able to work on this project in a while, so I'm catching up on a lot of updates. Your solution looks great -- and is the sort of thing I couldn't do well in JSS+MUI for a reason I can't remember. |
Any way we can reuse styles that rely on props/state?
The text was updated successfully, but these errors were encountered: