Skip to content

Commit

Permalink
Fix a number of unthemeable elements.
Browse files Browse the repository at this point in the history
Replace hard-coded color values with colors derived from either text or
canvas color.

Closes #3135
  • Loading branch information
pdf committed Feb 6, 2016
1 parent 2867e20 commit 69335df
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 49 deletions.
4 changes: 3 additions & 1 deletion src/Subheader/Subheader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ let Subheader = (props) => {
prepareStyles,
} = muiTheme;

const theme = muiTheme.subheader;

const styles = {
root: {
boxSizing: 'border-box',
color: Typography.textLightBlack,
color: theme.color,
fontSize: 14,
fontWeight: Typography.fontWeightMedium,
lineHeight: '48px',
Expand Down
13 changes: 6 additions & 7 deletions src/avatar.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import StylePropable from './mixins/style-propable';
import Colors from './styles/colors';
import getMuiTheme from './styles/getMuiTheme';

const Avatar = React.createClass({
Expand Down Expand Up @@ -60,8 +59,6 @@ const Avatar = React.createClass({

getDefaultProps() {
return {
backgroundColor: Colors.grey400,
color: Colors.white,
size: 40,
};
},
Expand All @@ -86,6 +83,8 @@ const Avatar = React.createClass({
},

render() {
const theme = this.state.muiTheme.avatar;

let {
backgroundColor,
color,
Expand All @@ -108,7 +107,7 @@ const Avatar = React.createClass({
};

if (src) {
const borderColor = this.state.muiTheme.avatar.borderColor;
const borderColor = theme.borderColor;

if (borderColor) {
styles.root = this.mergeStyles(styles.root, {
Expand All @@ -128,19 +127,19 @@ const Avatar = React.createClass({
);
} else {
styles.root = this.mergeStyles(styles.root, {
backgroundColor: backgroundColor,
backgroundColor: backgroundColor || theme.backgroundColor,
textAlign: 'center',
lineHeight: size + 'px',
fontSize: size / 2 + 4,
color: color,
color: color || theme.color,
});

const styleIcon = {
margin: 8,
};

const iconElement = icon ? React.cloneElement(icon, {
color: color,
color: color || theme.color,
style: this.mergeStyles(styleIcon, icon.props.style),
}) : null;

Expand Down
8 changes: 4 additions & 4 deletions src/card/card-header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ const CardHeader = React.createClass({

getDefaultProps() {
return {
titleColor: Styles.Colors.darkBlack,
subtitleColor: Styles.Colors.lightBlack,
avatar: null,
};
},
Expand All @@ -67,6 +65,8 @@ const CardHeader = React.createClass({
},

getStyles() {
const theme = this.state.muiTheme.card;

return {
root: {
height: 72,
Expand All @@ -83,12 +83,12 @@ const CardHeader = React.createClass({
marginRight: 16,
},
title: {
color: this.props.titleColor,
color: this.props.titleColor || theme.titleColor,
display: 'block',
fontSize: 15,
},
subtitle: {
color: this.props.subtitleColor,
color: this.props.subtitleColor || theme.subtitleColor,
display: 'block',
fontSize: 14,
},
Expand Down
14 changes: 4 additions & 10 deletions src/card/card-title.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import Styles from '../styles';
import StylePropable from '../mixins/style-propable';
import getMuiTheme from '../styles/getMuiTheme';

Expand Down Expand Up @@ -36,13 +35,6 @@ const CardTitle = React.createClass({
StylePropable,
],

getDefaultProps() {
return {
titleColor: Styles.Colors.darkBlack,
subtitleColor: Styles.Colors.lightBlack,
};
},

getInitialState() {
return {
muiTheme: this.context.muiTheme || getMuiTheme(),
Expand All @@ -65,20 +57,22 @@ const CardTitle = React.createClass({
},

getStyles() {
const theme = this.state.muiTheme.card;

return {
root: {
padding: 16,
position: 'relative',
},
title: {
fontSize: 24,
color: this.props.titleColor,
color: this.props.titleColor || theme.titleColor,
display: 'block',
lineHeight: '36px',
},
subtitle: {
fontSize: 14,
color: this.props.subtitleColor,
color: this.props.subtitleColor || theme.subtitleColor,
display: 'block',
},
};
Expand Down
2 changes: 0 additions & 2 deletions src/floating-action-button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import ReactDOM from 'react-dom';
import StylePropable from './mixins/style-propable';
import Transitions from './styles/transitions';
import Colors from './styles/colors';
import ColorManipulator from './utils/color-manipulator';
import EnhancedButton from './enhanced-button';
import FontIcon from './font-icon';
Expand Down Expand Up @@ -122,7 +121,6 @@ const FloatingActionButton = React.createClass({
getDefaultProps() {
return {
disabled: false,
disabledColor: Colors.grey300,
mini: false,
secondary: false,
};
Expand Down
2 changes: 0 additions & 2 deletions src/ripples/circle-ripple.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import PureRenderMixin from 'react-addons-pure-render-mixin';
import StylePropable from '../mixins/style-propable';
import autoPrefix from '../styles/auto-prefix';
import Transitions from '../styles/transitions';
import Colors from '../styles/colors';

const CircleRipple = React.createClass({

Expand All @@ -31,7 +30,6 @@ const CircleRipple = React.createClass({

getDefaultProps() {
return {
color: Colors.darkBlack,
opacity: 0.16,
};
},
Expand Down
11 changes: 3 additions & 8 deletions src/ripples/focus-ripple.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import ReactDOM from 'react-dom';
import PureRenderMixin from 'react-addons-pure-render-mixin';
import StylePropable from '../mixins/style-propable';
import autoPrefix from '../styles/auto-prefix';
import Colors from '../styles/colors';
import Transitions from '../styles/transitions';
import ScaleInTransitionGroup from '../transition-groups/scale-in';

Expand Down Expand Up @@ -34,12 +33,6 @@ const FocusRipple = React.createClass({
StylePropable,
],

getDefaultProps() {
return {
color: Colors.darkBlack,
};
},

componentDidMount() {
if (this.props.show) {
this._setRippleSize();
Expand All @@ -57,6 +50,8 @@ const FocusRipple = React.createClass({
},

_getRippleElement(props) {
const theme = this.props.muiTheme.ripple;

const {
color,
innerStyle,
Expand All @@ -69,7 +64,7 @@ const FocusRipple = React.createClass({
width: '100%',
borderRadius: '50%',
opacity: opacity ? opacity : 0.16,
backgroundColor: color,
backgroundColor: color || theme.color,
transition: Transitions.easeOut(pulsateDuration + 'ms', 'transform', null, Transitions.easeInOutFunction),
}, innerStyle);

Expand Down
4 changes: 3 additions & 1 deletion src/ripples/touch-ripple.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const TouchRipple = React.createClass({
},

start(e, isRippleTouchGenerated) {
const theme = this.props.muiTheme.ripple;

if (this._ignoreNextMouseDown && !isRippleTouchGenerated) {
this._ignoreNextMouseDown = false;
return;
Expand All @@ -72,7 +74,7 @@ const TouchRipple = React.createClass({
key={this.state.nextKey}
muiTheme={this.props.muiTheme}
style={!this.props.centerRipple ? this._getRippleStyle(e) : {}}
color={this.props.color}
color={this.props.color || theme.color}
opacity={this.props.opacity}
touchGenerated={isRippleTouchGenerated}
/>
Expand Down
29 changes: 24 additions & 5 deletions src/styles/getMuiTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ export default function getMuiTheme(baseTheme, muiTheme) {
height: spacing.desktopKeylineIncrement,
},
avatar: {
borderColor: 'rgba(0, 0, 0, 0.08)',
color: palette.canvasColor,
backgroundColor: ColorManipulator.luminance(palette.canvasColor) > 0.5 ?
ColorManipulator.darken(palette.canvasColor, 0.26) :
ColorManipulator.lighten(palette.canvasColor, 1.26, 1.0),
borderColor: ColorManipulator.fade(palette.textColor, 0.08),
},
badge: {
color: palette.alternateTextColor,
Expand All @@ -46,6 +50,10 @@ export default function getMuiTheme(baseTheme, muiTheme) {
minWidth: 88,
iconButtonSize: spacing.iconSize * 2,
},
card: {
titleColor: ColorManipulator.fade(palette.textColor, 0.87),
subtitleColor: ColorManipulator.fade(palette.textColor, 0.54),
},
cardText: {
textColor: palette.textColor,
},
Expand Down Expand Up @@ -83,6 +91,9 @@ export default function getMuiTheme(baseTheme, muiTheme) {
secondaryColor: palette.primary1Color,
secondaryIconColor: palette.alternateTextColor,
disabledTextColor: palette.disabledColor,
disabledColor: ColorManipulator.luminance(palette.canvasColor) > 0.5 ?
ColorManipulator.darken(palette.canvasColor, 0.12) :
ColorManipulator.lighten(palette.canvasColor, 1.12, 1.0),
},
gridTile: {
textColor: Colors.white,
Expand All @@ -104,7 +115,7 @@ export default function getMuiTheme(baseTheme, muiTheme) {
menuItem: {
dataHeight: 32,
height: 48,
hoverColor: 'rgba(0, 0, 0, .035)',
hoverColor: ColorManipulator.fade(palette.textColor, 0.035),
padding: spacing.desktopGutter,
selectedTextColor: palette.accent1Color,
},
Expand Down Expand Up @@ -150,6 +161,9 @@ export default function getMuiTheme(baseTheme, muiTheme) {
strokeColor: palette.borderColor,
loadingStrokeColor: palette.primary1Color,
},
ripple: {
color: ColorManipulator.fade(palette.textColor, 0.87),
},
slider: {
trackSize: 2,
trackColor: palette.primary3Color,
Expand All @@ -167,6 +181,9 @@ export default function getMuiTheme(baseTheme, muiTheme) {
backgroundColor: palette.textColor,
actionColor: palette.accent1Color,
},
subheader: {
color: ColorManipulator.fade(palette.textColor, 0.54),
},
table: {
backgroundColor: palette.canvasColor,
},
Expand Down Expand Up @@ -217,12 +234,14 @@ export default function getMuiTheme(baseTheme, muiTheme) {
trackRequiredColor: ColorManipulator.fade(palette.primary1Color, 0.5),
},
toolbar: {
color: ColorManipulator.fade(palette.textColor, 0.54),
hoverColor: ColorManipulator.fade(palette.textColor, 0.87),
backgroundColor: ColorManipulator.darken(palette.accent2Color, 0.05),
height: 56,
titleFontSize: 20,
iconColor: 'rgba(0, 0, 0, .40)',
separatorColor: 'rgba(0, 0, 0, .175)',
menuHoverColor: 'rgba(0, 0, 0, .10)',
iconColor: ColorManipulator.fade(palette.textColor, 0.4),
separatorColor: ColorManipulator.fade(palette.textColor, 0.175),
menuHoverColor: ColorManipulator.fade(palette.textColor, 0.1),
},
tabs: {
backgroundColor: palette.primary1Color,
Expand Down
5 changes: 2 additions & 3 deletions src/toolbar/toolbar-group.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import Colors from '../styles/colors';
import getMuiTheme from '../styles/getMuiTheme';

function getStyles(props, state) {
Expand Down Expand Up @@ -28,7 +27,7 @@ function getStyles(props, state) {
dropDownMenu: {
root: {
float: 'left',
color: Colors.lightBlack, // removes hover color change, we want to keep it
color: toolbar.color, // removes hover color change, we want to keep it
display: 'inline-block',
marginRight: baseTheme.spacing.desktopGutter,
},
Expand All @@ -54,7 +53,7 @@ function getStyles(props, state) {
paddingLeft: baseTheme.spacing.desktopGutter,
},
hover: {
color: Colors.darkBlack,
color: toolbar.hoverColor,
},
},
span: {
Expand Down
12 changes: 6 additions & 6 deletions src/utils/color-manipulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default {
*
* Formula: http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
*/
_luminance(color) {
luminance(color) {
color = this._decomposeColor(color);

if (color.type.indexOf('rgb') > -1) {
Expand Down Expand Up @@ -97,8 +97,8 @@ export default {
return this._convertColorToString(color, amount);
},

// Desaturates rgb and sets opacity to 0.15
lighten(color, amount) {
// Desaturates rgb and sets opacity (defaults to 0.15)
lighten(color, amount, opacity = '0.15') {
color = this._decomposeColor(color);

if (color.type.indexOf('hsl') > -1) {
Expand All @@ -113,7 +113,7 @@ export default {

if (color.type.indexOf('a') <= -1) color.type += 'a';

return this._convertColorToString(color, '0.15');
return this._convertColorToString(color, opacity);
},

darken(color, amount) {
Expand All @@ -137,8 +137,8 @@ export default {
//
// Formula: http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef
contrastRatio(background, foreground) {
let lumA = this._luminance(background);
let lumB = this._luminance(foreground);
let lumA = this.luminance(background);
let lumB = this.luminance(foreground);

if (lumA >= lumB) {
return ((lumA + 0.05) / (lumB + 0.05)).toFixed(2);
Expand Down

0 comments on commit 69335df

Please sign in to comment.