-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[Badge] Support other theme colors #9455
Comments
Forbidding using any color is really bad. It limits using this library. I not always need pure colors, I need gradients too. I even can't use color from official palettes. |
Exactly, I checked their code on AppBar.js, RaisedButton.js, etc. and discovered they use "backgroundColor" as the CSS property to set the primary and accent color to the background. Since gradient won't work with background-color, the .js code probably can be changed to just "background"... My theming is as below (and this won't work): const muiTheme = getMuiTheme({
...
raisedButton:{
primaryColor: 'linear-gradient(to top right, #1D3475, #060D1F)',
secondaryColor: 'linear-gradient(to top right, #ffaf4b,#ff920a)',
},
appBar: {
color: 'linear-gradient(to top right, #1D3475, #060D1F)',
},
...
}); |
@lunarmoon26, I think at the moment import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from 'material-ui/styles';
import Badge from 'material-ui/Badge';
import MailIcon from 'material-ui-icons/Mail';
const styles = theme => ({
badge: {
margin: `0 ${theme.spacing.unit * 2}px`,
background: `radial-gradient(circle at center, red 0, blue, green 100%)`
},
});
function SimpleBadge({classes}) {
return (
<Badge classes={{badge: classes.badge}} badgeContent={4} color="primary">
<MailIcon />
</Badge>
);
}
SimpleBadge.propTypes = {
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(SimpleBadge); |
lunarmoon26 You can also apply it globally https://material-ui.com/customization/overrides#4-global-theme-variation (like you were trying to do, but you missed a step). @oliviertassinari Any reason for us not to change all instances of |
@mbrookes |
i.e. you can override |
We now support primary / secondary / error. I don't think that we should add more color to the component. Instead, I think that we should look into providing a |
Is there currently any way to have a import { Badge, withStyles } from 'material-ui';
const RedBadge = withStyles(() => ({ badge: { backgroundColor: '#F00' } }))(Badge);
// Or even a bit more dynamically
const createColoredBadge = (color) =>
withStyles(() => ({ badge: { backgroundColor: color } }))(Badge);
const GreenBadge = createColoredBadge('#0F0');
const BlueBadge = createColoredBadge('#00F'); But I'd still have to define a new component for every color of badge I want. Is there some way I can create a <ColoredBadge bgColor={color}/> |
@simonbw , to be able to do that you need a library that provides a HOC that allow props in your style as Something like |
@oliviertassinari I think this can be closed now that |
In case anyone comes across this and wants to change the color, here's how to use makeStyles from @material-ui/styles to change the color:
|
Man @patorjk you are the best. you have saved my head. |
Expected Behavior
When supplying the
color
attribute, you should be able to use any of the colors supplied in the theme.paletteCurrent Behavior
Only:
default/primary/accent
are supported.Your Environment
The text was updated successfully, but these errors were encountered: