-
Notifications
You must be signed in to change notification settings - Fork 25
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
11 changed files
with
351 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"lerna": "2.0.0-rc.5", | ||
"lerna": "2.0.0", | ||
"version": "0.0.10", | ||
"packages": [ | ||
"packages/*" | ||
|
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,70 @@ | ||
###### Default textfield: | ||
|
||
<TextField/> | ||
|
||
###### TextField with header above: | ||
|
||
<TextField header="This is a TextField"/> | ||
|
||
###### Small textfield: | ||
|
||
<TextField small/> | ||
|
||
###### Medium textfield: | ||
|
||
<TextField medium/> | ||
|
||
###### Large textfield: | ||
|
||
<TextField large/> | ||
|
||
###### Placeholder text: | ||
|
||
<TextField placeholder="Enter product details here..."/> | ||
|
||
###### HTML5 types texfields (default: "text"): | ||
|
||
<div> | ||
<TextField type="email" header="Email"/> | ||
<TextField type="password" header="Password"/> | ||
</div> | ||
|
||
###### Default or app controlled value: | ||
|
||
<TextField value="textfield value here"/> | ||
|
||
###### Disabled textfield: | ||
|
||
<TextField disabled/> | ||
|
||
###### Required validation: | ||
|
||
<TextField required header="Email Address"/> | ||
|
||
###### Maximum length validation: | ||
|
||
<TextField maxLength={20}/> | ||
|
||
###### Custom validation: | ||
|
||
<TextField | ||
errorText="Only numbers are allowed." | ||
validator={ (value) => { return /^\d+$/.test(value) } } | ||
header="Only numbers allowed"/> | ||
|
||
###### Input Mask: | ||
|
||
<div> | ||
<TextField | ||
placeholder="(54) 111-1111" | ||
mask="(54) 111-1111" | ||
header="Phone"/> | ||
<TextField | ||
placeholder="ABC 1234" | ||
mask="AAA 1111" | ||
header="Lincese Plate"/> | ||
</div> | ||
|
||
###### onChange handler: | ||
|
||
<TextField onChange={ () => { alert('onChange executed!'); } }/> |
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,211 @@ | ||
import React, { cloneElement } from "react"; | ||
import PropTypes from "prop-types"; | ||
import { InputCore } from "../Input"; | ||
import cx from "classnames"; | ||
|
||
class TextField extends React.PureComponent { | ||
constructor(props) { | ||
super(props); | ||
// Initial state | ||
this.state = { | ||
"value": props.value || "", | ||
"remaining": props.maxLength, | ||
"active": false, | ||
"valid": true | ||
}; | ||
} | ||
|
||
_handleChange = event => { | ||
event.persist(); | ||
let value = event.target.value; | ||
|
||
if (this.props.maxLength) { | ||
// Keep difference between maxlength and input value in state for count | ||
this.setState({ "remaining": this.props.maxLength - value.length }); | ||
} | ||
|
||
// Set valid state depending on InputCore state | ||
this.setState({ "valid": this.inputRef.state.isValid }); | ||
|
||
if (this.props.onChange) { | ||
// Execute app code | ||
this.props.onChange(event); | ||
} | ||
}; | ||
|
||
_handleFocus = event => { | ||
this.setState({ "active": true }); | ||
}; | ||
|
||
_handleBlur = event => { | ||
this.setState({ "active": false }); | ||
}; | ||
|
||
render() { | ||
const { | ||
name, | ||
type, | ||
header, | ||
placeholder, | ||
maxLength, | ||
small, | ||
medium, | ||
large, | ||
required, | ||
validator, | ||
errorText, | ||
mask, | ||
disabled, | ||
hidden | ||
} = this.props; | ||
|
||
let textFieldHeader = | ||
header && | ||
<div styleName={cx("header")}> | ||
<span styleName={cx("headerFont")}>{header}</span> | ||
{required && <span styleName={"error_text"}> *</span>} | ||
</div>; | ||
|
||
let wrapperClasses = cx( | ||
{ | ||
hidden, | ||
small, | ||
medium, | ||
large | ||
}, | ||
"textfieldWrapper" | ||
); | ||
|
||
let textFieldClasses = cx( | ||
{ | ||
disabled, | ||
"active": this.state.active, | ||
"invalid": !this.state.valid | ||
}, | ||
"textfield" | ||
); | ||
|
||
return ( | ||
<div | ||
styleName={wrapperClasses} | ||
onFocus={this._handleFocus} | ||
onBlur={this._handleBlur} | ||
> | ||
{textFieldHeader} | ||
<InputCore | ||
type={type} | ||
name={name} | ||
placeholder={placeholder} | ||
value={this.state.value} | ||
maxLength={maxLength} | ||
styleName={textFieldClasses} | ||
onChange={this._handleChange} | ||
required={required} | ||
validator={validator} | ||
errorText={errorText} | ||
mask={mask} | ||
disabled={disabled} | ||
hidden={hidden} | ||
ref={node => this.inputRef = node} | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
TextField.PropTypes = { | ||
/** | ||
* Define a custom css class name. | ||
* @examples 'textfield', 'textfield-elem' | ||
*/ | ||
"className": PropTypes.string, | ||
/** | ||
* Define a name for the text input. | ||
* @examples '<TextField name="test"/>' | ||
*/ | ||
"name": PropTypes.string, | ||
/** | ||
* Define a type for the text input. Default is "text". | ||
* @examples '<TextField type="password"/>' | ||
*/ | ||
"type": PropTypes.string, | ||
/** | ||
* Define a default value for the text input. | ||
* @examples '<TextField value="Textfield value here"/>' | ||
*/ | ||
"value": PropTypes.string, | ||
/** | ||
* Defines a small sized text input. | ||
* @examples '<TextField small/>' | ||
*/ | ||
"small": PropTypes.bool, | ||
/** | ||
* Define a title or header to be displayed above the textfield. | ||
* @examples '<TextField header="test"/>' | ||
*/ | ||
"header": PropTypes.string, | ||
/** | ||
* Defines a medium sized text input. | ||
* @examples '<TextField medium/>' | ||
*/ | ||
"medium": PropTypes.bool, | ||
/** | ||
* Defines a large sized text input. | ||
* @examples '<TextField large/>' | ||
*/ | ||
"large": PropTypes.bool, | ||
/** | ||
* Sets a maximum character length that will be validated onChange. | ||
* @examples '<TextField maxLenght={25}/>' | ||
*/ | ||
"maxLength": PropTypes.number, | ||
/** | ||
* Sets a handler function to be executed and validate against. If it returns any falsy value, validation error will trigger. | ||
* @examples '<TextField validator={this.customValidator}/>' | ||
*/ | ||
"validator": PropTypes.func, | ||
/** | ||
* Defines the error text to be shown when custom validation occurs. | ||
* @examples '<TextField errorText="Custom error message."/>' | ||
*/ | ||
"errorText": PropTypes.string, | ||
/** | ||
* Sets a mask for the input field. | ||
* @examples '<TextField mask="AAA 11111"/>' | ||
*/ | ||
"mask": PropTypes.string, | ||
/** | ||
* Defines placeholder text. | ||
* @examples '<TextField placeholder="test input"/>' | ||
*/ | ||
"placeholder": PropTypes.string, | ||
/** | ||
* Sets a handler function to be executed when onChange event occurs (at input element). | ||
* @examples <TextField onChange={this.customOnChangeFunc}/> | ||
*/ | ||
"onChange": PropTypes.func, | ||
/** | ||
* Sets the field as required. Will be validated onChange. | ||
* @examples '<TextField required/>' | ||
*/ | ||
"required": PropTypes.bool, | ||
/** | ||
* Determines if the text input is disabled. | ||
* @examples '<TextField disabled/>' | ||
*/ | ||
"disabled": PropTypes.bool, | ||
/** | ||
* Determines if the text input is hidden. | ||
* @examples '<TextField hidden/>' | ||
*/ | ||
"hidden": PropTypes.bool | ||
}; | ||
|
||
TextField.defaultProps = { | ||
"className": "", | ||
"type": "text", | ||
"disabled": false, | ||
"hidden": false | ||
}; | ||
|
||
export default TextField; |
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,2 @@ | ||
import { default as TextFieldCore } from "./TextField"; | ||
export { TextFieldCore }; |
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,2 @@ | ||
import * as TextFieldStyle from "./textfield.css"; | ||
export { TextFieldStyle }; |
58 changes: 58 additions & 0 deletions
58
packages/react-atlas-default-theme/src/TextField/textfield.css
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 @@ | ||
.textfield { | ||
composes: primary-gray-border from '../styles.css'; | ||
width: 100%; | ||
padding: 5px; | ||
} | ||
|
||
.textfieldWrapper { | ||
width: 99%; | ||
composes: default-font from '../styles.css'; | ||
} | ||
|
||
.header { | ||
padding: 10px 0 5px 0; | ||
} | ||
|
||
.headerFont { | ||
composes: header-font from '../styles.css'; | ||
} | ||
|
||
.small { | ||
width: 30%; | ||
} | ||
|
||
.medium { | ||
width: 60%; | ||
} | ||
|
||
.large { | ||
width: 90%; | ||
} | ||
|
||
.active { | ||
composes: text-input-active from '../styles.css'; | ||
} | ||
|
||
.invalid { | ||
composes: text-input-invalid from '../styles.css'; | ||
} | ||
|
||
.invalid + span { | ||
color: #bd0a33; | ||
} | ||
|
||
.disabled { | ||
composes: cursor-not-allowed from '../styles.css'; | ||
pointer-events: none; | ||
background-color: #ccc; | ||
} | ||
|
||
.hidden { | ||
display: none; | ||
visibility: hidden; | ||
} | ||
|
||
.error_text { | ||
composes: header-font from '../styles.css'; | ||
color: #BD0A33; | ||
} |
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