babel-plugin-react-css-modules icon indicating copy to clipboard operation
babel-plugin-react-css-modules copied to clipboard

Plugin doesn't resolve classnames in function

Open shrihari-balasubramani opened this issue 6 years ago • 2 comments

Plugin doesn't resolve the styles in the following scenario.

import styles from './TYTextButton.css'
import classnames from 'classnames'

const renderText = (text, textClassName) => <Typography className={classnames(styles.text, textClassName)}>{text}</Typography>

I tried work arounds and came out with this approach https://github.com/shrihari-balasubramani/babel-plugin-react-css-modules/commit/a6e5849fee18c0376eb704ea012d7a0892ce0bfb

Please let me know if any better approach exists for this. Else I can raise a PR here .

shrihari-balasubramani avatar Feb 19 '19 06:02 shrihari-balasubramani

@shrihari-balasubramani maybe you're looking for named reference?

Something like

import classnames from 'classnames';
import foo from './foo1.css';

// Imports "a" CSS module from ./foo1.css.
<div styleName={classnames('foo.a')}></div>;

AlbertLucianto avatar Feb 21 '19 10:02 AlbertLucianto

@AlbertLucianto no. I also need to pass the style object to the child component as a prop.

shrihari-balasubramani avatar Feb 21 '19 10:02 shrihari-balasubramani