diff --git a/docs/src/app/components/code-example/code-example.jsx b/docs/src/app/components/code-example/code-example.jsx index 7475511b0d5a27..7f3690ecfd38a3 100644 --- a/docs/src/app/components/code-example/code-example.jsx +++ b/docs/src/app/components/code-example/code-example.jsx @@ -6,14 +6,22 @@ var React = require('react'), class CodeExample extends React.Component { render() { + var borderColor = this.context.theme.palette.borderColor; var style = { - color: this.context.theme.palette.textColor + label: { + color: borderColor + }, + block: { + borderRight: 'solid 1px ' + borderColor, + borderBottom: 'solid 1px ' + borderColor, + borderRadius: '0 0 2px 0' + } }; return ( -
example
-
+
example
+
{this.props.children}
{this.props.code} diff --git a/docs/src/app/components/pages/home.jsx b/docs/src/app/components/pages/home.jsx index 2f1b645fe0320e..2df9de0d9ece25 100644 --- a/docs/src/app/components/pages/home.jsx +++ b/docs/src/app/components/pages/home.jsx @@ -18,10 +18,10 @@ class HomePage extends React.Component { color: ThemeManager.palette.primary1Color, }, githubStyle: { - margin: '16px 32px 0px 8px', + margin: '16px 32px 0px 8px' }, demoStyle: { - margin: '16px 32px 0px 32px', + margin: '16px 32px 0px 32px' }, } } @@ -40,8 +40,20 @@ class HomePage extends React.Component { Components that Implement Google's Material Design - - + +
diff --git a/docs/src/less/main.less b/docs/src/less/main.less index ef6bf51f9a3c38..7e225314b0516f 100644 --- a/docs/src/less/main.less +++ b/docs/src/less/main.less @@ -91,10 +91,7 @@ body, h1, h2, h3, h4, h5, h6 { text-transform: uppercase; color: rgba(0, 0, 0, 0.26); // minBlack; padding: 8px; - border-right: solid 1px @border-color; - border-bottom: solid 1px @border-color; margin-bottom: 0; - border-radius: 0 0 2px 0; } .example-block, diff --git a/src/app-bar.jsx b/src/app-bar.jsx index c85f2038b8b3b6..a71276bc34ebd8 100644 --- a/src/app-bar.jsx +++ b/src/app-bar.jsx @@ -32,52 +32,6 @@ var AppBar = React.createClass({ } }, - /** Styles */ - - _main: function() { - return this.mergeAndPrefix({ - zIndex: 5, - width: '100%', - minHeight: this.getSpacing().desktopKeylineIncrement, - backgroundColor: this.getThemeVariables().color, - }); - }, - - _title: function() { - return { - float: 'left', - paddingTop: 0, - letterSpacing: 0, - fontSize: '24px', - fontWeight: Typography.fontWeightNormal, - color: this.getThemeVariables().textColor, - lineHeight: this.getSpacing().desktopKeylineIncrement + 'px', - }; - }, - - _iconButton: function() { - var iconButtonSize = this.context.theme.component.button.iconButtonSize; - return { - style: { - marginTop: (this.getThemeVariables().height - iconButtonSize) / 2, - float: 'left', - marginRight: 8, - marginLeft: -16, - }, - iconStyle: { - fill: this.getThemeVariables().textColor, - color: this.getThemeVariables().textColor, - } - } - }, - - _paper: function() { - return { - paddingLeft: this.getSpacing().desktopGutter, - paddingRight: this.getSpacing().desktopGutter, - }; - }, - componentDidMount: function() { if (process.NODE_ENV !== 'production' && (this.props.iconElementLeft && this.props.iconClassNameLeft)) { @@ -95,40 +49,79 @@ var AppBar = React.createClass({ return this.context.theme.component.appBar; }, + getStyles: function(){ + var iconButtonSize = this.context.theme.component.button.iconButtonSize; + var styles = { + root: { + zIndex: 5, + width: '100%', + minHeight: this.getSpacing().desktopKeylineIncrement, + backgroundColor: this.getThemeVariables().color + }, + title: { + float: 'left', + paddingTop: 0, + letterSpacing: 0, + fontSize: '24px', + fontWeight: Typography.fontWeightNormal, + color: this.getThemeVariables().textColor, + lineHeight: this.getSpacing().desktopKeylineIncrement + 'px' + }, + iconButton: { + style: { + marginTop: (this.getThemeVariables().height - iconButtonSize) / 2, + float: 'left', + marginRight: 8, + marginLeft: -16 + }, + iconStyle: { + fill: this.getThemeVariables().textColor, + color: this.getThemeVariables().textColor + } + }, + paper: { + paddingLeft: this.getSpacing().desktopGutter, + paddingRight: this.getSpacing().desktopGutter + } + }; + return styles; + }, + render: function() { var { onTouchTap, ...other } = this.props; + var styles = this.getStyles(); var title, menuElementLeft, menuElementRight; - var iconRightStyle = this.mergeAndPrefix(this._iconButton().style, { + var iconRightStyle = this.mergeAndPrefix(styles.iconButton.style, { float: 'right', marginRight: -16, - marginLeft: 8, + marginLeft: 8 }); if (this.props.title) { // If the title is a string, wrap in an h1 tag. // If not, just use it as a node. title = Object.prototype.toString.call(this.props.title) === '[object String]' ? -

{this.props.title}

: +

{this.props.title}

: this.props.title; } if (this.props.showMenuIconButton) { if (this.props.iconElementLeft) { menuElementLeft = ( -
+
{this.props.iconElementLeft}
); } else { - var child = (this.props.iconClassNameLeft) ? '' : ; + var child = (this.props.iconClassNameLeft) ? '' : ; menuElementLeft = ( {child} @@ -146,7 +139,7 @@ var AppBar = React.createClass({ menuElementRight = ( @@ -155,10 +148,15 @@ var AppBar = React.createClass({ } return ( - - {menuElementLeft} - {title} - {menuElementRight} + + {menuElementLeft} + {title} + {menuElementRight} ); }, diff --git a/src/checkbox.jsx b/src/checkbox.jsx index 92bb19c44a505d..252074097beb6c 100644 --- a/src/checkbox.jsx +++ b/src/checkbox.jsx @@ -31,60 +31,72 @@ var Checkbox = React.createClass({ return this.context.theme.component.checkbox; }, + getStyles: function() { + var checkboxSize = 24; + var styles = { + icon: { + height: checkboxSize, + width: checkboxSize, + }, + check: { + positiion: 'absolute', + opacity: 0, + transform: 'scale(0)', + transitionOrigin: '50% 50%', + transition: Transitions.easeOut('450ms', 'opacity', '0ms') + ', ' + + Transitions.easeOut('0ms', 'transform', '450ms'), + fill: this.getTheme().checkedColor + }, + box: { + position: 'absolute', + opacity: 1, + fill: this.getTheme().boxColor, + transition: Transitions.easeOut('2s', null, '200ms') + }, + checkWhenSwitched: { + opacity: 1, + transform: 'scale(1)', + transition: Transitions.easeOut('0ms', 'opacity', '0ms') + ', ' + + Transitions.easeOut('800ms', 'transform', '0ms') + }, + boxWhenSwitched: { + transition: Transitions.easeOut('100ms', null, '0ms'), + fill: this.getTheme().checkedColor + }, + checkWhenDisabled: { + fill: this.getTheme().disabledColor + }, + boxWhenDisabled: { + fill: this.getTheme().disabledColor + } + }; + return styles; + }, + render: function() { var { onCheck, ...other } = this.props; - var checkboxSize = 24; - - var iconStyles = { - height: checkboxSize, - width: checkboxSize, - } - - var checkStyles = { - positiion: 'absolute', - opacity: 0, - transform: 'scale(0)', - transitionOrigin: '50% 50%', - transition: Transitions.easeOut('450ms', 'opacity', '0ms') + ', ' + - Transitions.easeOut('0ms', 'transform', '450ms'), - fill: this.getTheme().checkedColor - } - - var boxStyles = { - position: 'absolute', - opacity: 1, - fill: this.getTheme().boxColor, - transition: Transitions.easeOut('2s', null, '200ms') - } - - if (this.state.switched) { - checkStyles = this.mergeStyles(checkStyles, { - opacity: 1, - transform: 'scale(1)', - transition: Transitions.easeOut('0ms', 'opacity', '0ms') + ', ' + - Transitions.easeOut('800ms', 'transform', '0ms') - }); - boxStyles = this.mergeStyles(boxStyles, { - transition: Transitions.easeOut('100ms', null, '0ms'), - fill: this.getTheme().checkedColor - }); - } - - if (this.props.disabled) { - checkStyles.fill = this.getTheme().disabledColor; - boxStyles.fill = this.getTheme().disabledColor; - } - - if (this.state.switched && this.props.disabled) boxStyles.opacity = 0; + var styles = this.getStyles(); var checkboxElement = (
- - + +
); @@ -93,7 +105,7 @@ var Checkbox = React.createClass({ inputType: "checkbox", switched: this.state.switched, switchElement: checkboxElement, - iconStyle: iconStyles, + iconStyle: styles.icon, onSwitch: this._handleCheck, onParentShouldUpdate: this._handleStateChange, defaultSwitched: this.props.defaultChecked, diff --git a/src/date-picker/calendar.jsx b/src/date-picker/calendar.jsx index 2929cac86b03bf..7aea4178f77733 100644 --- a/src/date-picker/calendar.jsx +++ b/src/date-picker/calendar.jsx @@ -60,7 +60,6 @@ var Calendar = React.createClass({ root: { fontSize: '12px' }, - calendarContainer: { width: isLandscape ? '280px' : '100%', height: weekCount === 5 ? '268px' : @@ -68,13 +67,11 @@ var Calendar = React.createClass({ float: isLandscape ? 'right' : 'none', transition: Transitions.easeOut('150ms', 'height') }, - dateDisplay: { width: isLandscape ? '280px' : '100%', height: '100%', float: isLandscape ? 'left' : 'none' }, - weekTitle: { padding: '0 14px', lineHeight: '12px', @@ -83,7 +80,6 @@ var Calendar = React.createClass({ fontWeight: '500', margin: 0 }, - weekTitleDay: { listStyle: 'none', float: 'left', diff --git a/src/date-picker/date-display.jsx b/src/date-picker/date-display.jsx index 971fcf589af3ba..20a140023e7933 100644 --- a/src/date-picker/date-display.jsx +++ b/src/date-picker/date-display.jsx @@ -139,7 +139,7 @@ var DateDisplay = React.createClass({ }; return ( -
+
+
+
{this.props.children} diff --git a/src/drop-down-icon.jsx b/src/drop-down-icon.jsx index 208e482cf7cdd4..41f99d50de8e56 100644 --- a/src/drop-down-icon.jsx +++ b/src/drop-down-icon.jsx @@ -37,41 +37,36 @@ var DropDownIcon = React.createClass({ this.setState({ open: false }); }, - /** Styles */ - - _main: function() { + getStyles: function() { var iconWidth = 48; - return this.mergeAndPrefix({ - display: 'inline-block', - width: iconWidth + 'px !important', - position: 'relative', - height: Spacing.desktopToolbarHeight, - fontSize: Spacing.desktopDropDownMenuFontSize, - cursor: 'pointer' - }); - }, - - _menu: function() { - - return { - transition: Transitions.easeOut(), - right: '-14px !important', - top: '9px !important', - opacity: (this.props.open) ? 1 : 0, - } - }, - - _menuItem: function() { // similair to drop down menu's menu item styles - return { - paddingRight: (Spacing.iconSize + (Spacing.desktopGutterLess*2)), - height: Spacing.desktopDropDownMenuItemHeight, - lineHeight: Spacing.desktopDropDownMenuItemHeight + 'px', - } + var styles = { + root: { + display: 'inline-block', + width: iconWidth + 'px !important', + position: 'relative', + height: Spacing.desktopToolbarHeight, + fontSize: Spacing.desktopDropDownMenuFontSize, + cursor: 'pointer' + }, + menu: { + transition: Transitions.easeOut(), + right: '-14px !important', + top: '9px !important', + opacity: (this.props.open) ? 1 : 0 + }, + menuItem: { // similair to drop down menu's menu item styles + paddingRight: (Spacing.iconSize + (Spacing.desktopGutterLess*2)), + height: Spacing.desktopDropDownMenuItemHeight, + lineHeight: Spacing.desktopDropDownMenuItemHeight + 'px' + } + }; + return styles; }, render: function() { + var styles = this.getStyles(); return ( -
+
diff --git a/src/drop-down-menu.jsx b/src/drop-down-menu.jsx index 4f56c5335d160b..98d1c51a3a59de 100644 --- a/src/drop-down-menu.jsx +++ b/src/drop-down-menu.jsx @@ -56,115 +56,11 @@ var DropDownMenu = React.createClass({ }, componentWillReceiveProps: function(nextProps) { - if (props.hasOwnProperty('selectedIndex')) { + if (nextProps.hasOwnProperty('selectedIndex')) { this._setSelectedIndex(nextProps); } }, - /** Styles */ - _main: function() { - var style = { - transition: Transitions.easeOut(), - position: 'relative', - display: 'inline-block', - height: this.getSpacing().desktopToolbarHeight, - fontSize: this.getSpacing().desktopDropDownMenuFontSize - }; - - if (this.state.open) style.opacity = 1; - - return this.mergeAndPrefix(style); - }, - - _control: function() { - var style = { - cursor: 'pointer', - position: 'static', - height: '100%', - }; - - if (this.props.styleControl) this.mergeAndPrefix(style, this.props.styleControl); - - return style; - }, - - _controlBg: function() { - var style = { - transition: Transitions.easeOut(), - backgroundColor: this.context.theme.component.menu.backgroundColor, - height: '100%', - width: '100%', - opacity: (this.state.open) ? 0 : - (this.state.isHovered) ? 1 : 0, - }; - - if (this.props.styleControlBg) style = this.mergeAndPrefix(style, this.props.styleControlBg); - - return style; - }, - - _icon: function() { - var style = { - position: 'absolute', - top: ((this.getSpacing().desktopToolbarHeight - 24) / 2), - right: this.getSpacing().desktopGutterLess, - fill: this.context.theme.component.dropDownMenu.accentColor, - }; - - if (this.props.styleIcon) style = this.mergeAndPrefix(style, this.props.styleIcon); - - return style; - }, - - _label: function() { - var style = { - transition: Transitions.easeOut(), - lineHeight: this.getSpacing().desktopToolbarHeight + 'px', - position: 'absolute', - paddingLeft: this.getSpacing().desktopGutter, - top: 0, - opacity: 1, - color: this.getTextColor() - }; - - if (this.state.open) { - style = this.mergeAndPrefix(style, { - opacity: 0, - top: this.getSpacing().desktopToolbarHeight / 2, - }); - } - - if (this.props.styleLabel) style = this.mergeAndPrefix(style, this.props.styleLabel); - - return style; - }, - - _underline: function() { - var style = { - borderTop: 'solid 1px ' + this.context.theme.component.dropDownMenu.accentColor, - margin: '0 ' + this.getSpacing().desktopGutter + 'px', - }; - - if (this.props.styleUnderline) style =this.mergeAndPrefix(style, this.props.styleUnderline); - - return style; - }, - - _menuItem: function() { - var style = { - paddingRight: this.getSpacing().iconSize + - this.getSpacing().desktopGutterLess + - this.getSpacing().desktopGutterMini, - height: this.getSpacing().desktopDropDownMenuItemHeight, - lineHeight: this.getSpacing().desktopDropDownMenuItemHeight + 'px', - whiteSpace: 'nowrap', - }; - - if (this.props.styleMenuItem) style = this.mergeAndPrefix(style, this.props.styleMenuItem); - - return style; - }, - getSpacing: function() { return this.context.theme.spacing; }, @@ -173,21 +69,88 @@ var DropDownMenu = React.createClass({ return this.context.theme.palette.textColor; }, + getStyles: function(){ + var accentColor = this.context.theme.component.dropDownMenu.accentColor; + var backgroundColor = this.context.theme.component.menu.backgroundColor; + var styles = { + root: { + transition: Transitions.easeOut(), + position: 'relative', + display: 'inline-block', + height: this.getSpacing().desktopToolbarHeight, + fontSize: this.getSpacing().desktopDropDownMenuFontSize + }, + control: { + cursor: 'pointer', + position: 'static', + height: '100%' + }, + controlBg: { + transition: Transitions.easeOut(), + backgroundColor: backgroundColor, + height: '100%', + width: '100%', + opacity: (this.state.open) ? 0 : + (this.state.isHovered) ? 1 : 0 + }, + icon: { + position: 'absolute', + top: ((this.getSpacing().desktopToolbarHeight - 24) / 2), + right: this.getSpacing().desktopGutterLess, + fill: this.context.theme.component.dropDownMenu.accentColor + }, + label: { + transition: Transitions.easeOut(), + lineHeight: this.getSpacing().desktopToolbarHeight + 'px', + position: 'absolute', + paddingLeft: this.getSpacing().desktopGutter, + top: 0, + opacity: 1, + color: this.getTextColor() + }, + underline: { + borderTop: 'solid 1px ' + accentColor, + margin: '0 ' + this.getSpacing().desktopGutter + 'px' + }, + menuItem: { + paddingRight: this.getSpacing().iconSize + + this.getSpacing().desktopGutterLess + + this.getSpacing().desktopGutterMini, + height: this.getSpacing().desktopDropDownMenuItemHeight, + lineHeight: this.getSpacing().desktopDropDownMenuItemHeight + 'px', + whiteSpace: 'nowrap' + }, + rootWhenOpen: { + opacity: 1 + }, + labelWhenOpen: { + opacity: 0, + top: this.getSpacing().desktopToolbarHeight / 2 + } + }; + return styles; + }, + render: function() { + var styles = this.getStyles(); return (
- - - -
+ onMouseOver={this._handleMouseOver} + className={this.props.className} + style={this.mergeAndPrefix( + styles.root, + this.state.open && styles.rootWhenOpen, + this.props.style)} > + + + +
{this.props.menuItems[this.state.selectedIndex].text}
- -
+ +
diff --git a/src/enhanced-button.jsx b/src/enhanced-button.jsx index 5995404d765f0e..fcfa90761a90f2 100644 --- a/src/enhanced-button.jsx +++ b/src/enhanced-button.jsx @@ -57,33 +57,29 @@ var EnhancedButton = React.createClass({ } }, - /** Styles */ - _main: function() { - var style = { - border: 10, - background: 'none', - boxSizing: 'border-box', - font: 'inherit', - fontFamily: this.context.theme.contentFontFamily, - WebkitTapHighlightColor: 'rgba(0, 0, 0, 0)', - WebkitApperance: 'button' - }; - - if (this.props.linkButton) { - style = this.mergeAndPrefix({ + getStyles: function() { + var styles = { + root: { + border: 10, + background: 'none', + boxSizing: 'border-box', + font: 'inherit', + fontFamily: this.context.theme.contentFontFamily, + WebkitTapHighlightColor: 'rgba(0, 0, 0, 0)', + WebkitApperance: 'button' + }, + rootWhenLinkButton: { display: 'inline-block', cursor: (this.props.disabled) ? 'default' : 'pointer', - textDecoration: 'none', - }, style); - } - - if (this.props.disabled) style.cursor = 'default'; - - - return this.mergeAndPrefix(style); + textDecoration: 'none' + }, + rootWhenDisabled: { + cursor: 'default' + } + }; + return styles; }, - render: function() { var { centerRipple, @@ -98,6 +94,13 @@ var EnhancedButton = React.createClass({ onTouchTap, ...other } = this.props; + var styles = this.mergeAndPrefix( + this.getStyles().root, + this.props.linkButton && this.getStyles().rootWhenLinkButton, + this.props.disabled && this.getStyles().rootWhenDisabled, + this.props.style + ); + var touchRipple = ( ); var buttonProps = { - style: this._main(), + style: styles, disabled: disabled, onBlur: this._handleBlur, onFocus: this._handleFocus, diff --git a/src/enhanced-switch.jsx b/src/enhanced-switch.jsx index 28f71a188a4e13..a77f56c3bea608 100644 --- a/src/enhanced-switch.jsx +++ b/src/enhanced-switch.jsx @@ -46,20 +46,21 @@ var EnhancedSwitch = React.createClass({ getInitialState: function() { return { - isKeyboardFocused: false + isKeyboardFocused: false, + parentWidth: 100, }; }, getEvenWidth: function(){ return ( parseInt(window - .getComputedStyle(this.getDOMNode()) + .getComputedStyle(React.findDOMNode(this.refs.root)) .getPropertyValue('width'), 10) ); }, componentDidMount: function() { - var inputNode = this.refs.checkbox.getDOMNode(); + var inputNode = React.findDOMNode(this.refs.checkbox); if (!this.props.switched || this.props.switched == undefined || inputNode.checked != this.props.switched) this.props.onParentShouldUpdate(inputNode.checked); @@ -91,39 +92,19 @@ var EnhancedSwitch = React.createClass({ return this.context.theme.palette; }, - render: function() { - var { - type, - name, - value, - label, - onSwitch, - defaultSwitched, - onBlur, - onFocus, - onMouseUp, - onMouseDown, - onMouseOut, - onTouchStart, - onTouchEnd, - disableTouchRipple, - disableFocusRipple, - ...other - } = this.props; - + getStyles: function() { var switchWidth = 60 - Spacing.desktopGutterLess; var labelWidth = this.state.parentWidth - 60; - - var styles = this.mergeStyles({ + var styles = { + root: { position: 'relative', cursor: this.props.disabled ? 'default' : 'pointer', overflow: 'visible', display: 'table', height: 'auto', - width: '100%', - }); - - var inputStyles = { + width: '100%' + }, + input: { position: 'absolute', cursor: this.props.disabled ? 'default' : 'pointer', pointerEvents: 'all', @@ -133,10 +114,17 @@ var EnhancedSwitch = React.createClass({ zIndex: 2, left: 0, boxSizing: 'border-box', - padding: 0, - }; - - var wrapStyles = this.mergeStyles({ + padding: 0 + }, + label: { + float: 'left', + position: 'relative', + display: 'table-column', + width: labelWidth, + lineHeight: '24px', + color: this.getTheme().textColor + }, + wrap: { transition: Transitions.easeOut(), float: 'left', position: 'relative', @@ -146,16 +134,43 @@ var EnhancedSwitch = React.createClass({ Spacing.desktopGutterLess : 0, marginLeft: (this.props.labelPosition == 'left') ? Spacing.desktopGutterLess : 0 - }, this.props.iconStyle); + }, + ripple: { + height: '200%', + width: '200%', + top: '-12', + left: '-12' + } + }; + return styles; + }, - var labelStyles = { - float: 'left', - position: 'relative', - display: 'table-column', - width: labelWidth, - lineHeight: '24px', - color: this.getTheme().textColor - } + render: function() { + var { + type, + name, + value, + label, + onSwitch, + defaultSwitched, + onBlur, + onFocus, + onMouseUp, + onMouseDown, + onMouseOut, + onTouchStart, + onTouchEnd, + disableTouchRipple, + disableFocusRipple, + ...other + } = this.props; + + var styles = this.getStyles(); + + styles.root.cursor = styles.root.input = this.props.disabled ? 'default' : 'pointer'; + + var wrapStyles = this.mergeAndPrefix(styles.wrap, this.props.iconStyle); + var rippleStyle = this.mergeAndPrefix(styles.ripple, this.props.rippleStyle); if (this.props.thumbStyle) { wrapStyles.marginLeft /= 2; @@ -165,7 +180,7 @@ var EnhancedSwitch = React.createClass({ var inputId = this.props.id || UniqueId.generate(); var labelElement = this.props.label ? ( -