-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TextField] added characterCount attribute
- Loading branch information
1 parent
9e0b348
commit 3936295
Showing
2 changed files
with
128 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React from 'react'; | ||
const propTypes = { | ||
/** | ||
* True if current count exceeds maximum count. | ||
*/ | ||
countError: React.PropTypes.bool, | ||
|
||
/** | ||
* Current number of character in the Textfield. | ||
*/ | ||
currentChar: React.PropTypes.number, | ||
|
||
/** | ||
* Override the inline-styles of the error element. | ||
*/ | ||
errorStyle: React.PropTypes.object, | ||
|
||
/** | ||
* Maximum number of character in the Textfield. | ||
*/ | ||
maxChar: React.PropTypes.number, | ||
|
||
/** | ||
* @ignore | ||
* The material-ui theme applied to this component. | ||
*/ | ||
muiTheme: React.PropTypes.object.isRequired, | ||
|
||
/** | ||
* Override the inline-styles of the root element. | ||
*/ | ||
style: React.PropTypes.object, | ||
}; | ||
|
||
const defaultProps = { | ||
}; | ||
|
||
const TextCharCount = (props) => { | ||
const { | ||
countError, | ||
currentChar, | ||
maxChar, | ||
muiTheme, | ||
style, | ||
errorStyle, | ||
} = props; | ||
|
||
const { | ||
prepareStyles, | ||
textField: { | ||
hintColor, | ||
errorColor, | ||
}, | ||
} = muiTheme; | ||
|
||
const styles = { | ||
root: { | ||
position: 'relative', | ||
color: hintColor, | ||
float: 'right', | ||
fontSize: '12px', | ||
bottom: 8, | ||
}, | ||
error: { | ||
color: errorColor, | ||
}, | ||
}; | ||
|
||
let regularStyle = Object.assign({}, styles.root, style); | ||
if (countError) regularStyle = Object.assign({}, styles.root, styles.error, errorStyle); | ||
|
||
return ( | ||
<div style={prepareStyles(regularStyle)}> | ||
{currentChar}/{maxChar} | ||
</div> | ||
); | ||
}; | ||
|
||
TextCharCount.propTypes = propTypes; | ||
TextCharCount.defaultProps = defaultProps; | ||
|
||
export default TextCharCount; |
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