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

[Core] Remove context-pure mixin #3331

Merged
merged 1 commit into from
Feb 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions src/SelectField/SelectField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import TextField from '../text-field';
import DropDownMenu from '../DropDownMenu';
import getMuiTheme from '../styles/getMuiTheme';
import ContextPure from '../mixins/context-pure';

function getStyles(props) {
return {
Expand Down Expand Up @@ -142,19 +141,6 @@ const SelectField = React.createClass({
muiTheme: React.PropTypes.object,
},

mixins: [
ContextPure,
],

statics: {
getChildrenClasses() {
return [
TextField,
DropDownMenu,
];
},
},

getDefaultProps() {
return {
autoWidth: false,
Expand Down
41 changes: 10 additions & 31 deletions src/TextField/TextField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Transitions from '../styles/transitions';
import UniqueId from '../utils/unique-id';
import EnhancedTextarea from '../enhanced-textarea';
import getMuiTheme from '../styles/getMuiTheme';
import ContextPure from '../mixins/context-pure';
import TextFieldHint from './TextFieldHint';
import TextFieldLabel from './TextFieldLabel';
import TextFieldUnderline from './TextFieldUnderline';
Expand Down Expand Up @@ -186,31 +185,9 @@ const TextField = React.createClass({
},

mixins: [
ContextPure,
StylePropable,
],

statics: {
getRelevantContextKeys(muiTheme) {
const textFieldTheme = muiTheme.textField;

return {
floatingLabelColor: textFieldTheme.floatingLabelColor,
focusColor: textFieldTheme.focusColor,
textColor: textFieldTheme.textColor,
disabledTextColor: textFieldTheme.disabledTextColor,
backgroundColor: textFieldTheme.backgroundColor,
hintColor: textFieldTheme.hintColor,
errorColor: textFieldTheme.errorColor,
};
},
getChildrenClasses() {
return [
EnhancedTextarea,
];
},
},

getDefaultProps() {
return {
disabled: false,
Expand Down Expand Up @@ -268,14 +245,16 @@ const TextField = React.createClass({
getStyles() {
const props = this.props;
const {
floatingLabelColor,
focusColor,
textColor,
disabledTextColor,
backgroundColor,
hintColor,
errorColor,
} = this.constructor.getRelevantContextKeys(this.state.muiTheme);
textField: {
floatingLabelColor,
focusColor,
textColor,
disabledTextColor,
backgroundColor,
hintColor,
errorColor,
},
} = this.state.muiTheme;

const styles = {
root: {
Expand Down
13 changes: 0 additions & 13 deletions src/buttons/flat-button-label.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import ContextPure from '../mixins/context-pure';
import getMuiTheme from '../styles/getMuiTheme';

function getStyles(props, state) {
Expand Down Expand Up @@ -35,18 +34,6 @@ const FlatButtonLabel = React.createClass({
muiTheme: React.PropTypes.object,
},

mixins: [
ContextPure,
],

statics: {
getRelevantContextKeys(muiTheme) {
return {
spacingDesktopGutterLess: muiTheme.rawTheme.spacing.desktopGutterLess,
};
},
},

getInitialState() {
return {
muiTheme: this.context.muiTheme || getMuiTheme(),
Expand Down
13 changes: 0 additions & 13 deletions src/card/card-expandable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import OpenIcon from '../svg-icons/hardware/keyboard-arrow-up';
import CloseIcon from '../svg-icons/hardware/keyboard-arrow-down';
import IconButton from '../icon-button';
import getMuiTheme from '../styles/getMuiTheme';
import ContextPure from '../mixins/context-pure';

function getStyles() {
return {
Expand Down Expand Up @@ -37,18 +36,6 @@ const CardExpandable = React.createClass({
muiTheme: React.PropTypes.object,
},

mixins: [
ContextPure,
],

statics: {
getChildrenClasses() {
return [
IconButton,
];
},
},

getInitialState() {
return {
muiTheme: this.context.muiTheme || getMuiTheme(),
Expand Down
21 changes: 1 addition & 20 deletions src/date-picker/date-picker-dialog.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import ContextPure from '../mixins/context-pure';
import EventListener from 'react-event-listener';
import KeyCode from '../utils/key-code';
import Calendar from './calendar';
Expand Down Expand Up @@ -42,24 +41,6 @@ const DatePickerDialog = React.createClass({
muiTheme: React.PropTypes.object,
},

mixins: [
ContextPure,
],

statics: {
getRelevantContextKeys(muiTheme) {
return {
calendarTextColor: muiTheme.datePicker.calendarTextColor,
};
},
getChildrenClasses() {
return [
Calendar,
Dialog,
];
},
},

getDefaultProps: function() {
return {
DateTimeFormat: DateTime.DateTimeFormat,
Expand Down Expand Up @@ -148,7 +129,7 @@ const DatePickerDialog = React.createClass({

const {
calendarTextColor,
} = this.constructor.getRelevantContextKeys(this.state.muiTheme);
} = this.state.muiTheme.datePicker;

const styles = {
root: {
Expand Down
69 changes: 20 additions & 49 deletions src/flat-button.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import ContextPure from './mixins/context-pure';
import Transitions from './styles/transitions';
import Children from './utils/children';
import ColorManipulator from './utils/color-manipulator';
Expand Down Expand Up @@ -122,41 +121,10 @@ const FlatButton = React.createClass({
muiTheme: React.PropTypes.object,
},

//for passing default theme context to children
childContextTypes: {
muiTheme: React.PropTypes.object,
},

mixins: [
ContextPure,
],

statics: {
getRelevantContextKeys(muiTheme) {
const buttonTheme = muiTheme.button;
const flatButtonTheme = muiTheme.flatButton;

return {
buttonColor: flatButtonTheme.color,
buttonFilterColor: flatButtonTheme.buttonFilterColor,
buttonHeight: buttonTheme.height,
buttonMinWidth: buttonTheme.minWidth,
disabledTextColor: flatButtonTheme.disabledTextColor,
primaryTextColor: flatButtonTheme.primaryTextColor,
secondaryTextColor: flatButtonTheme.secondaryTextColor,
textColor: flatButtonTheme.textColor,
textTransform: flatButtonTheme.textTransform ? flatButtonTheme.textTransform :
(buttonTheme.textTransform ? buttonTheme.textTransform : 'uppercase'),
};
},
getChildrenClasses() {
return [
EnhancedButton,
FlatButtonLabel,
];
},
},

getDefaultProps() {
return {
disabled: false,
Expand Down Expand Up @@ -186,11 +154,10 @@ const FlatButton = React.createClass({
};
},

//to update theme inside state whenever a new theme is passed down
//from the parent / owner using context
componentWillReceiveProps(nextProps, nextContext) {
const newMuiTheme = nextContext.muiTheme ? nextContext.muiTheme : this.state.muiTheme;
this.setState({muiTheme: newMuiTheme});
this.setState({
muiTheme: nextContext.muiTheme || this.state.muiTheme,
});
},

_handleKeyboardFocus(e, isKeyboardFocused) {
Expand Down Expand Up @@ -232,17 +199,23 @@ const FlatButton = React.createClass({
} = this.props;

const {
buttonColor,
buttonHeight,
buttonMinWidth,
disabledTextColor,
buttonFilterColor,
primaryTextColor,
secondaryTextColor,
textColor,
textTransform,
} = this.constructor.getRelevantContextKeys(this.state.muiTheme);

button: {
height: buttonHeight,
minWidth: buttonMinWidth,
textTransform: buttonTextTransform,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should actually calculate this from button and flatbutton like the logic above. I feel like this isn't getting initialized properly in the transpiled code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic is the same, textTransform is being assigned to a variable called buttonTextTransform, then in line 216, if textTransform was not provided in flatButton theme, it defaults to either the buttonTextTransform or uppercase.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, Good to know 👍 👍

},
flatButton: {
buttonFilterColor,
color: buttonColor,
disabledTextColor,
fontSize,
fontWeight,
primaryTextColor,
secondaryTextColor,
textColor,
textTransform = buttonTextTransform || 'uppercase',
},
} = this.state.muiTheme;
const defaultTextColor = disabled ? disabledTextColor :
primary ? primaryTextColor :
secondary ? secondaryTextColor :
Expand All @@ -254,8 +227,6 @@ const FlatButton = React.createClass({
const buttonRippleColor = rippleColor || defaultRippleColor;
const buttonBackgroundColor = backgroundColor || buttonColor;
const hovered = (this.state.hovered || this.state.isKeyboardFocused) && !disabled;
const fontSize = this.state.muiTheme.flatButton.fontSize;
const fontWeight = this.state.muiTheme.flatButton.fontWeight;

const mergedRootStyles = Object.assign({}, {
color: defaultTextColor,
Expand Down
27 changes: 0 additions & 27 deletions src/icon-button.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import ContextPure from './mixins/context-pure';
import Transitions from './styles/transitions';
import PropTypes from './utils/prop-types';
import EnhancedButton from './enhanced-button';
Expand Down Expand Up @@ -132,36 +131,10 @@ const IconButton = React.createClass({
muiTheme: React.PropTypes.object,
},

//for passing default theme context to children
childContextTypes: {
muiTheme: React.PropTypes.object,
},

mixins: [
ContextPure,
],

statics: {
getRelevantContextKeys(muiTheme) {
const spacing = muiTheme.rawTheme.spacing;
const palette = muiTheme.rawTheme.palette;

return {
iconSize: spacing.iconSize,
textColor: palette.textColor,
disabledColor: palette.disabledColor,
};
},

getChildrenClasses() {
return [
EnhancedButton,
FontIcon,
Tooltip,
];
},
},

getDefaultProps() {
return {
disabled: false,
Expand Down
55 changes: 0 additions & 55 deletions src/mixins/context-pure.js

This file was deleted.

Loading