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

Passing multiple style props to a child component #306

Open
gaurav5430 opened this issue Sep 5, 2021 · 1 comment
Open

Passing multiple style props to a child component #306

gaurav5430 opened this issue Sep 5, 2021 · 1 comment

Comments

@gaurav5430
Copy link

gaurav5430 commented Sep 5, 2021

I have a child component, which accepts multiple props for styles, one for the container, and other for one of the internal elements. Generally, I would just name them something like className and elementClassName, and get different css classes from the parent in each of the props. With react-css-modules though, since the default rule only allows converting styleName to className, I can not pass different local classes in multiple props, as i can only have 1 styleName prop.

One of the way around this seems to be to use named imports instead of anonymous imports and then pass styles.containerClass in className and styles.elementClass in elementClassName prop. This does not require using the styleName prop at all.

import styles from './some.css';

...
...
<Component className={styles.containerClass} elementClassName={styles.elementClass} />

...
...

This seems alright, and the other existing styleName in the file do not break, still work alright and do not need to be changed to styles.soemthing, but it is slightly confusing that the named import is being only used at one place, and at the rest of the places the anonymous string value in styleName still works fine.

Is there another preferred / prescribed approach to handle the above scenario?

@gaurav5430
Copy link
Author

Oh, going through the readme, stumbled across the Custom attribute mapping.
Would the Custom attribute mapping / attributeNames map help with this?

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

No branches or pull requests

1 participant