-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
285 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
var text_validator = /^([a-z]+(-| )?)+$/i; | ||
var text_error_message = 'Invalid Name'; | ||
|
||
var password_validator = /^(?=.*\d)(?=.*[a-zA-Z])(?!.*[\W_\x7B-\xFF]).{6,15}$/; | ||
var password_error_message = 'Password must be 6-20 characters including at least 1 upper or lower alpha, and 1 digit.'; | ||
|
||
var email_validator = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; | ||
var email_error_message = 'Invalid Email'; | ||
|
||
var example = ( | ||
<div> | ||
<UIToolkit.Input | ||
type='text' | ||
name='sample_text' | ||
id='sample_text' | ||
label='Name: ' | ||
placeholder='Full Name' | ||
validator={text_validator} | ||
errorMessage={text_error_message} | ||
/> | ||
<UIToolkit.Input | ||
type='email' | ||
name='sample_email' | ||
id='sample_email' | ||
label='Email Address: ' | ||
placeholder='me@email.com' | ||
validator={email_validator} | ||
errorMessage={email_error_message} | ||
/> | ||
<UIToolkit.Input | ||
type='password' | ||
name='sample_password' | ||
id='sample_password' | ||
label='Password: ' | ||
placeholder='Enter a Password' | ||
validator={password_validator} | ||
errorMessage={password_error_message} | ||
/> | ||
</div> | ||
|
||
); | ||
|
||
React.render(example, mountNode); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** @jsx React.DOM */ | ||
|
||
var InputView = require('../code/views/inputView.jsx'); | ||
|
||
describe('InputComponent', function() { | ||
|
||
it('should render text input', function() { | ||
var input = TestUtils.renderIntoDocument( | ||
<InputView type="text" /> | ||
); | ||
|
||
var renderedInput = TestUtils.findRenderedDOMComponentWithClass(input, 'component-input'); | ||
assert.isDefined(renderedInput); | ||
|
||
}); | ||
|
||
it('should render password input', function() { | ||
var input = TestUtils.renderIntoDocument( | ||
<InputView type="password" /> | ||
); | ||
|
||
var renderedInput = TestUtils.findRenderedDOMComponentWithClass(input, 'component-input'); | ||
assert.isDefined(renderedInput); | ||
|
||
}); | ||
|
||
it('should render email input', function() { | ||
var input = TestUtils.renderIntoDocument( | ||
<InputView type="email" /> | ||
); | ||
|
||
var renderedInput = TestUtils.findRenderedDOMComponentWithClass(input, 'component-input'); | ||
assert.isDefined(renderedInput); | ||
|
||
}); | ||
|
||
it('should render input with label', function() { | ||
var input = TestUtils.renderIntoDocument( | ||
<InputView type="text" label="Full Name" /> | ||
); | ||
|
||
var renderedInput = TestUtils.findRenderedDOMComponentWithClass(input, 'input-group-label'); | ||
assert.isDefined(renderedInput); | ||
|
||
}); | ||
|
||
it('should render input as disabled', function() { | ||
var input = TestUtils.renderIntoDocument( | ||
<InputView type="text" disabled /> | ||
); | ||
|
||
var renderedInput = TestUtils.findRenderedDOMComponentWithClass(input, 'component-input-field'); | ||
assert.equal(renderedInput.getDOMNode().getAttribute('disabled'), ''); | ||
|
||
}); | ||
|
||
it('should render input as readonly', function() { | ||
var input = TestUtils.renderIntoDocument( | ||
<InputView type="text" readOnly /> | ||
); | ||
|
||
var renderedInput = TestUtils.findRenderedDOMComponentWithClass(input, 'component-input-field'); | ||
assert.equal(renderedInput.getDOMNode().getAttribute('readonly'), ''); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./views/inputView.jsx'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
var React = require('react'); | ||
var classNames = require('classnames'); | ||
|
||
module.exports = function (component){ | ||
|
||
var classes = classNames('input-group', { | ||
'component-input': true, | ||
'input-group-error': component.state.error || false, | ||
'input-group-disabled': component.props.disabled || false | ||
}); | ||
|
||
// the form label | ||
var label; | ||
|
||
if (component.props.label){ | ||
label = ( <label className="component-input-label input-group-label" htmlFor={component.props.id}>{component.props.label}</label > ); | ||
} | ||
|
||
/** | ||
* Create the span element used for containing messages | ||
* related to the element. | ||
*/ | ||
var span; | ||
|
||
if (component.state.error) | ||
{ | ||
span = ( <span className="input-group-span component-input-error">{component.state.error}</span> ); | ||
} | ||
|
||
return ( | ||
<div className={classes} ref={component.props.ref}> | ||
{label} | ||
<input | ||
className="input-group-field component-input-field" | ||
type={component.props.type} | ||
valid={component.state.valid} | ||
name={component.props.name} | ||
id={component.props.id} | ||
placeholder={component.props.placeholder} | ||
onChange={component.changeHandler} | ||
defaultValue={component.props.defaultValue} | ||
disabled={component.props.disabled} | ||
readOnly={component.props.readOnly} | ||
required={component.props.required} | ||
/> | ||
{span} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
var React = require('react'); | ||
|
||
module.exports = React.createClass({ | ||
|
||
propTypes: { | ||
label: React.PropTypes.string, | ||
type: React.PropTypes.oneOf(['text', 'password', 'email']), | ||
placeholder: React.PropTypes.string, | ||
defaultValue: React.PropTypes.string, | ||
name: React.PropTypes.string, | ||
id: React.PropTypes.string, | ||
error: React.PropTypes.string, | ||
disabled: React.PropTypes.bool, | ||
readOnly: React.PropTypes.bool, | ||
required: React.PropTypes.bool, | ||
valid: React.PropTypes.bool, | ||
errorMessage: React.PropTypes.string, | ||
onChange: React.PropTypes.func | ||
}, | ||
|
||
getInitialState: function() { | ||
return { | ||
value: this.props.defaultValue || '', | ||
error: null, | ||
valid: true | ||
} | ||
}, | ||
|
||
getDefaultProps: function() { | ||
return { | ||
type: 'text', | ||
disabled: false, | ||
readOnly: false, | ||
required: false, | ||
onChange: this.changeHandler, | ||
errorMessage: null | ||
} | ||
}, | ||
|
||
changeHandler: function(e) { | ||
|
||
var is_valid = true; | ||
|
||
if(typeof this.props.validator !== 'undefined'){ | ||
is_valid = this.props.validator.test(e.target.value); | ||
} | ||
|
||
if( !is_valid){ | ||
this.setState({ error : this.props.errorMessage }); | ||
} | ||
|
||
this.setState({ valid : is_valid }); | ||
}, | ||
|
||
render: function() { | ||
return require('../templates/inputTemplate.jsx')(this); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./code/index'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
if [ -z "$VARIANT" ]; then VARIANT=''; fi | ||
if [ -z "$TEMPLATE_LANG" ]; then TEMPLATE_LANG='en'; fi | ||
|
||
echo "Building package for demo. Variant: '$VARIANT', language: '$TEMPLATE_LANG'." | ||
|
||
browserify -t [ redirectify --dir "$VARIANT" ] -t reactify dev/example.jsx -o dev/ui-component-email.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
if [ -z "$VARIANT" ]; then VARIANT=''; fi | ||
if [ -z "$TEMPLATE_LANG" ]; then TEMPLATE_LANG='en'; fi | ||
|
||
echo "Building package for demo. Variant: '$VARIANT', language: '$TEMPLATE_LANG'." | ||
|
||
browserify -t [ redirectify --dir "$VARIANT" ] -t reactify index.js --standalone ui-component-email > dist/ui-component-email-standalone.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters