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

Styled components with props #196

Open
morganbarrett opened this issue Mar 20, 2023 · 2 comments
Open

Styled components with props #196

morganbarrett opened this issue Mar 20, 2023 · 2 comments

Comments

@morganbarrett
Copy link

So I've been trying to get styled components to work with props and have come up empty handed.

It seems possible in MUI v5, but I'm not sure which version of MUI, SUID is based off.

I saw issue #144 where it was noted that this was not possible with MUI, but I have found a couple of instances on the docs where it has been done.

For example, on the official MUI docs:

const MyStyledButton = styled('button')((props) => ({
  backgroundColor: props.myBackgroundColor,
}));

Although this does not work in SUID, so the question is, is SUID running of an older version of MUI and if so, can it be updated to include this feature?

@juanrgm
Copy link
Member

juanrgm commented Mar 31, 2023

Could you locate in which version of MUI that improvement was introduced?

@morganbarrett
Copy link
Author

I actually found I was just importing "styled" from the wrong location. If I import it from @suid/material it worked as expected.

However TypeScript didn't like it, so this was my workaround:

import type {ParentProps} from "solid-js";

export const fromProps = 
    <Props extends object>() =>
        (props: Props & ParentProps) =>
            <div {...props} />;

and used like so:

import {styled} from "@suid/material";
import {fromProps} from "./fromProps";

const StyledDiv = styled(fromProps<{someProp: number}>())(({props}) => ({
     width: props.someProp + "px"
}));

It would be handy if this worked without the helper though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants