Skip to content

Commit

Permalink
Merge pull request #481 from mmrtnz/css-in-js
Browse files Browse the repository at this point in the history
Merge with master
  • Loading branch information
mmrtnz committed Mar 30, 2015
2 parents 24db37b + 54b61d7 commit 089ff9b
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 26 deletions.
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "material-ui-docs",
"version": "0.6.1",
"version": "0.7.2",
"description": "Documentation site for material-ui",
"repository": {
"type": "git",
Expand Down
4 changes: 1 addition & 3 deletions docs/src/app/components/app-left-nav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ class AppLeftNav extends React.Component {

for (var i = menuItems.length - 1; i >= 0; i--) {
currentItem = menuItems[i];
if (currentItem.route && this.context.router.isActive(currentItem.route)) {
return i;
}
if (currentItem.route && this.context.router.isActive(currentItem.route)) return i;
}
}

Expand Down
4 changes: 2 additions & 2 deletions docs/src/app/components/pages/components/dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ class DialogPage extends React.Component {
},
{
name: 'title',
type: 'string',
type: 'node',
header: 'optional',
desc: 'The title string to display on the dialog.'
desc: 'The title to display on the dialog. Could be number, string, element or an array containing these types.'
}
]
},
Expand Down
4 changes: 2 additions & 2 deletions docs/src/app/components/pages/components/tabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ class TabsPage extends React.Component {
'</Tabs> \n' +
'\n' +
'_onActive: function(tab){ \n' +
' this.transitionTo(tab.props.route); \n' +
' this.context.router.transitionTo(tab.props.route); \n' +
'}';

var desc = 'Refs cannont be set on individual Tab components as cloneWithProps is being ' +
var desc = 'Refs cannot be set on individual Tab components as cloneWithProps is being ' +
'used to extend the individual tab components under the hood. However, ' +
'refs can be passed to the Tabs container and to any element or component within the template. ' +
'If you need to access a tab directly - you can do so with the first argument of onActive or ' +
Expand Down
4 changes: 1 addition & 3 deletions docs/src/app/components/pages/page-with-nav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ class PageWithNav extends React.Component {

for (var i = menuItems.length - 1; i >= 0; i--) {
currentItem = menuItems[i];
if (currentItem.route && this.context.router.isActive(currentItem.route)) {
return i;
}
if (currentItem.route && this.context.router.isActive(currentItem.route)) return i;
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"homepage": "http://material-ui.com/",
"dependencies": {
"react-classset": "0.0.2",
"classnames": "^1.2.0",
"react-draggable2": "^0.5.1"
},
"peerDependencies": {
Expand Down
18 changes: 14 additions & 4 deletions src/js/dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var Dialog = React.createClass({
mixins: [StylePropable],

propTypes: {
title: React.PropTypes.string
title: React.PropTypes.node
},

/** Styles */
Expand All @@ -28,21 +28,31 @@ var Dialog = React.createClass({
render: function() {
var {
className,
title,
...other
} = this.props;

var title;
if (this.props.title) {
// If the title is a string, wrap in an h3 tag.
// If not, just use it as a node.
title = toString.call(this.props.title) === '[object String]' ?
<h3 style={this.title()}>{this.props.title}</h3> :
this.props.title;
}

return (
<DialogWindow
{...other}
ref="dialogWindow"
className={className}
style={this.props.style}>

<h3 style={this.title()}>{this.props.title}</h3>
{title}

<div ref="dialogContent" style={this.content()}>
{this.props.children}
</div>

</DialogWindow>
);
},
Expand Down
143 changes: 143 additions & 0 deletions src/js/input.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
var React = require('react');
var Classable = require('./mixins/classable');
var ClassNames = require('classnames');

var Input = React.createClass({

propTypes: {
multiline: React.PropTypes.bool,
inlinePlaceholder: React.PropTypes.bool,
rows: React.PropTypes.number,
inputStyle: React.PropTypes.string,
error: React.PropTypes.string,
description: React.PropTypes.string,
placeholder: React.PropTypes.string,
type: React.PropTypes.string,
onChange: React.PropTypes.func
},

mixins: [Classable],

getInitialState: function() {
return {
value: this.props.defaultValue,
rows: this.props.rows
};
},

getDefaultProps: function() {
return {
multiline: false,
type: "text"
};
},

componentDidMount: function() {
if (process.NODE_ENV !== 'production') {
console.warn('Input has been deprecated. Please use TextField instead. See http://material-ui.com/#/components/text-fields');
}
},

render: function() {
var classes = this.getClasses('mui-input', {
'mui-floating': this.props.inputStyle === 'floating',
'mui-text': this.props.type === 'text',
'mui-error': this.props.error || false,
'mui-disabled': !!this.props.disabled,
});
var placeholder = this.props.inlinePlaceholder ? this.props.placeholder : "";
var inputIsNotEmpty = !!this.state.value;
var inputClassName = ClassNames({
'mui-is-not-empty': inputIsNotEmpty
});
var textareaClassName = ClassNames({
'mui-input-textarea': true,
'mui-is-not-empty': inputIsNotEmpty
});
var inputElement = this.props.multiline ?
this.props.valueLink ?
<textarea {...this.props} ref="input"
className={textareaClassName}
placeholder={placeholder}
rows={this.state.rows} /> :
<textarea {...this.props} ref="input"
value={this.state.value}
className={textareaClassName}
placeholder={placeholder}
rows={this.state.rows}
onChange={this._onTextAreaChange} /> :
this.props.valueLink ?
<input {...this.props} ref="input"
className={inputClassName}
placeholder={placeholder} /> :
<input {...this.props} ref="input"
className={inputClassName}
value={this.state.value}
placeholder={placeholder}
onChange={this._onInputChange} />;
var placeholderSpan = this.props.inlinePlaceholder ? null :
<span className="mui-input-placeholder" onClick={this._onPlaceholderClick}>
{this.props.placeholder}
</span>;

return (
<div ref={this.props.ref} className={classes}>
{inputElement}
{placeholderSpan}
<span className="mui-input-highlight"></span>
<span className="mui-input-bar"></span>
<span className="mui-input-description">{this.props.description}</span>
<span className="mui-input-error">{this.props.error}</span>
</div>
);
},

getValue: function() {
return this.state.value;
},

setValue: function(txt) {
this.setState({value: txt});
},

clearValue: function() {
this.setValue('');
},

blur: function() {
if(this.isMounted()) this.refs.input.getDOMNode().blur();
},

focus: function() {
if (this.isMounted()) this.refs.input.getDOMNode().focus();
},

_onInputChange: function(e) {
var value = e.target.value;
this.setState({value: value});
if (this.props.onChange) this.props.onChange(e, value);
},

_onPlaceholderClick: function(e) {
this.focus();
},

_onTextAreaChange: function(e) {
this._onInputChange(e);
this._onLineBreak(e);
},

_onLineBreak: function(e) {
var value = e.target.value;
var lines = value.split('\n').length;

if (lines > this.state.rows) {
if (this.state.rows !== 20) {
this.setState({ rows: ((this.state.rows) + 1)});
}
}
}

});

module.exports = Input;
23 changes: 18 additions & 5 deletions src/js/menu/menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var NestedMenuItem = React.createClass({
},

componentClickAway: function() {
this.setState({ open: false });
this._closeNestedMenu();
},

componentDidMount: function() {
Expand Down Expand Up @@ -69,10 +69,11 @@ var NestedMenuItem = React.createClass({
} = this.props;

return (
<div style={styles}>
<div style={styles} onMouseEnter={this._openNestedMenu} onMouseLeave={this._closeNestedMenu}>
<MenuItem
index={index}
style={menuItemStyle}
disabled={this.props.disabled}
iconRightStyle={iconCustomArrowDropRight}
iconRightClassName="muidocs-icon-custom-arrow-drop-right"
onClick={this._onParentItemClick}>
Expand All @@ -95,19 +96,31 @@ var NestedMenuItem = React.createClass({
var nestedMenu = this.refs.nestedMenu.getDOMNode();
nestedMenu.style.left = el.offsetWidth + 'px';
},

_openNestedMenu: function() {
if (!this.props.disabled) this.setState({ open: true });
},

_closeNestedMenu: function() {
this.setState({ open: false });
},

_toggleNestedMenu: function() {
if (!this.props.disabled) this.setState({ open: !this.state.open });
},

_onParentItemClick: function() {
if (!this.props.disabled) this.setState({ open: !this.state.open });
this._toggleNestedMenu();
},

_onMenuItemClick: function(e, index, menuItem) {
if (this.props.onItemClick) this.props.onItemClick(e, index, menuItem);
this.setState({ open: false });
this._closeNestedMenu();
},

_onMenuItemTap: function(e, index, menuItem) {
if (this.props.onItemTap) this.props.onItemTap(e, index, menuItem);
this.setState({ open: false });
this._closeNestedMenu();
}

});
Expand Down
8 changes: 4 additions & 4 deletions src/js/mixins/classable.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var React = require('react');
var classSet = require('react-classset');
var classNames = require('classnames');

module.exports = {

Expand All @@ -15,16 +15,16 @@ module.exports = {

//Add in initial classes
if (typeof initialClasses === 'object') {
classString += ' ' + classSet(initialClasses);
classString += ' ' + classNames(initialClasses);
} else {
classString += ' ' + initialClasses;
}

//Add in additional classes
if (additionalClassObj) classString += ' ' + classSet(additionalClassObj);
if (additionalClassObj) classString += ' ' + classNames(additionalClassObj);

//Convert the class string into an object and run it through the class set
return classSet(this.getClassSet(classString));
return classNames(this.getClassSet(classString));
},

getClassSet: function(classString) {
Expand Down
2 changes: 1 addition & 1 deletion src/js/mixins/dom-idable.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {

getDomId: function() {
return 'dom_id' + this._rootNodeID.replace(/\./g, '_');
return 'dom_id' + this._reactInternalInstance._rootNodeID.replace(/\./g, '_');
}

}

0 comments on commit 089ff9b

Please sign in to comment.