mui / material-ui

Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.
https://mui.com/material-ui/
MIT License
93.51k stars 32.19k forks source link

Convenient method to append className #12606

Closed ackvf closed 6 years ago

ackvf commented 6 years ago

Current Behavior

To append a classname, classNames() or string concatenation must be used explicitly.

<Icon className={classNames(classes.icon, 'fa fa-plus-circle')} />
<Icon className={classNames(classes.icon, 'fa fa-plus-circle')} color="primary"/>
<Icon className={classNames(classes.icon, 'fa fa-plus-circle')} color="secondary"/>

This forces repetitivness and uglifies the code.

Expected Behavior & Example

Proposed improvement is to allow custom classes in the theme object:

const styles = theme => ({
   icon: {
    className: 'fa fa-plus-circle',
    // ...
  },
});

Usage

<Icon className={classes.icon} />
<Icon className={classes.icon} color="primary"/>
<Icon className={classes.icon} color="secondary"/>

classes.icon here represents ${classes.icon} ${classes.icon.className} under the hood.

oliviertassinari commented 6 years ago

@ackvf https://github.com/cssinjs/jss-compose can help.