Skip to content

Commit

Permalink
Added new TextField component. Fixes #183
Browse files Browse the repository at this point in the history
  • Loading branch information
Hai Nguyen committed Jan 21, 2015
1 parent a64a399 commit b607a57
Show file tree
Hide file tree
Showing 12 changed files with 736 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/src/app/app-routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var Sliders = require('./components/pages/components/sliders.jsx');
var Snackbar = require('./components/pages/components/snackbar.jsx');
var Switches = require('./components/pages/components/switches.jsx');
var Tabs = require('./components/pages/components/tabs.jsx');
var TextFields = require('./components/pages/components/text-fields.jsx');
var Toolbars = require('./components/pages/components/toolbars.jsx');


Expand Down Expand Up @@ -66,6 +67,7 @@ var AppRoutes = (
<Route name="switches" handler={Switches} />
<Route name="snackbar" handler={Snackbar} />
<Route name="tabs" handler={Tabs} />
<Route name="text-fields" handler={TextFields} />
<Route name="toolbars" handler={Toolbars} />
<Redirect from="/components" to="buttons" />
</Route>
Expand Down
3 changes: 2 additions & 1 deletion docs/src/app/components/pages/components.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ var Components = React.createClass({
{ route: 'sliders', text: 'Sliders'},
{ route: 'switches', text: 'Switches'},
{ route: 'snackbar', text: 'Snackbar'},
{ route: 'tabs', text:'Tabs'},
{ route: 'tabs', text: 'Tabs'},
{ route: 'text-fields', text: 'Text Fields'},
{ route: 'toolbars', text: 'Toolbars'},
];

Expand Down
258 changes: 258 additions & 0 deletions docs/src/app/components/pages/components/text-fields.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
var React = require('react');
var mui = require('mui');
var TextField = mui.TextField;
var ComponentDoc = require('../../component-doc.jsx');

var TextFieldsPage = React.createClass({

getInitialState: function() {
return {
errorText: 'This field is required.',
error2Text: 'This field must be numeric.',
floatingErrorText: 'This field is required.',
floatingError2Text: 'This field must be numeric.'
};
},

render: function() {

var code =
'//Single Line Text Fields\n' +
'<TextField\n' +
' hintText="Hint Text" />\n' +
'<TextField\n' +
' hintText="Hint Text"\n' +
' defaultValue="Default Value" />\n' +
'<TextField\n' +
' hintText="Hint Text"\n' +
' value="Prop Value" />\n' +
'<TextField\n' +
' hintText="Hint Text (MultiLine)"\n' +
' multiLine={true} />\n' +
'<TextField\n' +
' hintText="Hint Text"\n' +
' errorText={this.state.errorText}\n' +
' onChange={this._handleErrorInputChange} />\n' +
'<TextField\n' +
' hintText="Hint Text"\n' +
' errorText={this.state.error2Text}\n' +
' onChange={this._handleError2InputChange}\n' +
' defaultValue="abc" />\n' +
'<TextField\n' +
' hintText="Disabled Hint Text"\n' +
' disabled={true} />\n' +
'<TextField\n' +
' hintText="Disabled Hint Text"\n' +
' disabled={true}\n' +
' defaultValue="Disabled With Value" />\n\n' +

'//Multi Line Text Fields\n' +
'<TextField\n' +
' hintText="Floating Label Hint Text"\n' +
' floatingLabels={true} />\n' +
'<TextField\n' +
' hintText="Floating Label Hint Text"\n' +
' floatingLabels={true}\n' +
' defaultValue="Default Value" />\n' +
'<TextField\n' +
' hintText="Floating Label Hint Text"\n' +
' floatingLabels={true}\n' +
' value="Prop Value" />\n' +
'<TextField\n' +
' hintText="Floating Label Hint Text (MultiLine)"\n' +
' floatingLabels={true} multiLine={true} />\n' +
'<TextField\n' +
' hintText="Floating Label Hint Text"\n' +
' errorText={this.state.floatingErrorText}\n' +
' floatingLabels={true}\n' +
' onChange={this._handleFloatingErrorInputChange} />\n' +
'<TextField\n' +
' hintText="Floating Label Hint Text"\n' +
' errorText={this.state.floatingError2Text}\n' +
' floatingLabels={true} defaultValue="abc"\n' +
' onChange={this._handleFloating2ErrorInputChange} />\n' +
'<TextField\n' +
' hintText="Floating Label Disabled Hint Text"\n' +
' disabled={true}\n' +
' floatingLabels={true} />\n' +
'<TextField\n' +
' hintText="Floating Label Disabled Hint Text"\n' +
' disabled={true}\n' +
' floatingLabels={true}\n' +
' defaultValue="Disabled With Value" />';

var componentInfo = [
{
name: 'Props',
infoArray: [
{
name: 'errorText',
type: 'string',
header: 'optional',
desc: 'The error text string to display.'
},
{
name: 'floatingLabels',
type: 'bool',
header: 'default: false',
desc: 'If true, hint text labels will float above the input box.'
},
{
name: 'hintText',
type: 'string',
header: 'optional',
desc: 'The hint text string to display.'
},
{
name: 'multiLine',
type: 'bool',
header: 'default: false',
desc: 'If true, a textarea element will be rendered. The textarea also grows and shrinks according to the number of lines.'
}
]
},
{
name: 'Methods',
infoArray: [
{
name: 'blur',
header: 'TextField.blur()',
desc: 'Removes focus on the input element.'
},
{
name: 'clearValue',
header: 'TextField.clearValue()',
desc: 'Clears the value on the input element.'
},
{
name: 'focus',
header: 'TextField.focus()',
desc: 'Sets the focus on the input element.'
},
{
name: 'getValue',
header: 'TextField.getValue()',
desc: 'Returns the value of the input.'
},
{
name: 'setErrorText',
header: 'TextField.setErrorText(newErrorText)',
desc: 'Sets the error text on the input element.'
},
{
name: 'setValue',
header: 'TextField.setValue(newValue)',
desc: 'Sets the value of the input element.'
}
]
}
];

return (
<ComponentDoc
name="Text Field"
code={code}
componentInfo={componentInfo}>

<div className="text-field-example">
<div className="text-field-example-group text-field-example-single-line">
<TextField
hintText="Hint Text" /><br/>
<TextField
hintText="Hint Text"
defaultValue="Default Value" /><br/>
<TextField
hintText="Hint Text"
value="Prop Value" /><br/>
<TextField
hintText="Hint Text (MultiLine)"
multiLine={true} /><br/>
<TextField
hintText="Hint Text"
errorText={this.state.errorText}
onChange={this._handleErrorInputChange} /><br/>
<TextField
hintText="Hint Text"
errorText={this.state.error2Text}
onChange={this._handleError2InputChange}
defaultValue="abc" /><br/>
<TextField
hintText="Disabled Hint Text"
disabled={true} /><br/>
<TextField
hintText="Disabled Hint Text"
disabled={true}
defaultValue="Disabled With Value" /><br/>
</div>

<div className="text-field-example-group">
<TextField
hintText="Floating Label Hint Text"
floatingLabels={true} /><br/>
<TextField
hintText="Floating Label Hint Text"
floatingLabels={true}
defaultValue="Default Value" /><br/>
<TextField
hintText="Floating Label Hint Text"
floatingLabels={true}
value="Prop Value" /><br/>
<TextField
hintText="Floating Label Hint Text (MultiLine)"
floatingLabels={true} multiLine={true} /><br/>
<TextField
hintText="Floating Label Hint Text"
errorText={this.state.floatingErrorText}
floatingLabels={true}
onChange={this._handleFloatingErrorInputChange} /><br/>
<TextField
hintText="Floating Label Hint Text"
errorText={this.state.floatingError2Text}
floatingLabels={true} defaultValue="abc"
onChange={this._handleFloating2ErrorInputChange} /><br/>
<TextField
hintText="Floating Label Disabled Hint Text"
disabled={true}
floatingLabels={true} /><br/>
<TextField
hintText="Floating Label Disabled Hint Text"
disabled={true}
floatingLabels={true}
defaultValue="Disabled With Value" /><br/>
</div>
</div>
</ComponentDoc>
);
},

_handleErrorInputChange: function(e) {
this.setState({
errorText: e.target.value ? '' : 'This field is required.'
});
},

_handleError2InputChange: function(e) {
var value = e.target.value;
var isNumeric = !isNaN(parseFloat(value)) && isFinite(value);
this.setState({
error2Text: isNumeric ? '' : 'This field must be numeric.'
});
},

_handleFloatingErrorInputChange: function(e) {
this.setState({
floatingErrorText: e.target.value ? '' : 'This field is required.'
});
},

_handleFloating2ErrorInputChange: function(e) {
var value = e.target.value;
var isNumeric = !isNaN(parseFloat(value)) && isFinite(value);
this.setState({
floatingError2Text: isNumeric ? '' : 'This field must be numeric.'
});
}

});

module.exports = TextFieldsPage;
1 change: 1 addition & 0 deletions docs/src/less/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
@import "pages/components/component-doc.less";
@import "pages/components/buttons.less";
@import "pages/components/switches.less";
@import "pages/components/text-fields.less";
@import "pages/components/icon.less";
@import "pages/components/paper.less";

Expand Down
20 changes: 20 additions & 0 deletions docs/src/less/pages/components/text-fields.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.text-field-example {

.clearfix();

.text-field-example-group {
width: 100%;
float: left;
margin-bottom: 32px;

@media @device-large {
width: 50%;
}
}

.text-field-example-single-line {
.mui-text-field {
margin-top: 24px;
}
}
}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = {
Tabs: require('./js/tabs/tabs.jsx'),
Toggle: require('./js/toggle.jsx'),
Snackbar: require('./js/snackbar.jsx'),

TextField: require('./js/text-field.jsx'),
Toolbar: require('./js/toolbar.jsx'),
ToolbarGroup: require('./js/toolbar-group.jsx'),
Tooltip: require('./js/tooltip.jsx'),
Expand Down
Loading

0 comments on commit b607a57

Please sign in to comment.