Skip to content

Commit

Permalink
feat: add number type and number related props to TextInput
Browse files Browse the repository at this point in the history
Signed-off-by: Erik Kieckhafer <[email protected]>
  • Loading branch information
kieckhafer committed Jul 31, 2019
1 parent 3291f23 commit 868b5e6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package/src/components/Checkbox/v1/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ const StyledDiv = styled.div`
margin-bottom: ${applyTheme("Checkbox.verticalSpacing")};
`;

/* eslint-disable max-len */

/* eslint-disable quotes */
// credit https://fontawesome.com/icons/check?style=solid
const checkboxIconSVG = (props) => encodeURIComponent(`<svg aria-hidden='true' role='img' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'><path fill='${applyTheme("Checkbox.iconColor")(props)}' d='M173.898 439.404l-166.4-166.4c-9.997-9.997-9.997-26.206 0-36.204l36.203-36.204c9.997-9.998 26.207-9.998 36.204 0L192 312.69 432.095 72.596c9.997-9.997 26.207-9.997 36.204 0l36.203 36.204c9.997 9.997 9.997 26.206 0 36.204l-294.4 294.401c-9.998 9.997-26.207 9.997-36.204-.001z'></path></svg>`);
/* eslint-enable quotes */
/* eslint-enable max-len */


// Opacity: 0 hides the default input and position: absolute removes it
// from the flow so that it doesn't push the styled checkbox to the right.
Expand Down
25 changes: 23 additions & 2 deletions package/src/components/TextInput/v1/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,18 @@ class TextInput extends Component {
* Enable to make the input read only / disabled, disabled by default
*/
isReadOnly: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
/**
* Maximum value for input when type === number
*/
max: PropTypes.number,
/**
* Max amount of characters allowed in input
*/
maxLength: PropTypes.number,
/**
* Minimum value for input when type === number
*/
min: PropTypes.number,
/**
* Input name
*/
Expand Down Expand Up @@ -300,9 +308,13 @@ class TextInput extends Component {
*/
shouldTrimValue: PropTypes.bool,
/**
* The HTML input type for the text input, the input only supports "email", "password", "text", "url" defaults to "text"
* Increment value when type === number
*/
step: PropTypes.string,
/**
* The HTML input type for the text input, the input only supports "email", "number", "password", "text", "url" defaults to "text"
*/
type: PropTypes.oneOf(["email", "password", "text", "url"]),
type: PropTypes.oneOf(["email", "number", "password", "text", "url"]),
/**
* Prepopulate the input's value
*/
Expand Down Expand Up @@ -555,10 +567,13 @@ class TextInput extends Component {
id,
isOnDarkBackground,
isReadOnly,
max,
maxLength,
min,
name,
placeholder,
shouldAllowLineBreaks,
step,
type
} = this.props;
const { isButtonFocused, isInputFocused, value } = this.state;
Expand All @@ -575,13 +590,16 @@ class TextInput extends Component {
hasBeenValidated={hasBeenValidated}
id={id}
isOnDarkBackground={isOnDarkBackground}
max={max}
maxLength={maxLength}
min={min}
name={name}
onBlur={this.onInputBlur}
onChange={this.onChange}
onFocus={this.onInputFocus}
placeholder={placeholder}
readOnly={isReadOnly}
step={step}
value={value}
/>
{this.showClearButton() ? this.renderClearButton() : null}
Expand All @@ -604,14 +622,17 @@ class TextInput extends Component {
hasBeenValidated={hasBeenValidated}
id={id}
isOnDarkBackground={isOnDarkBackground}
max={max}
maxLength={maxLength}
min={min}
name={name}
onBlur={this.onInputBlur}
onChange={this.onChange}
onFocus={this.onInputFocus}
onKeyPress={this.onKeyPress}
placeholder={placeholder}
readOnly={isReadOnly}
step={step}
type={type}
value={value}
/>
Expand Down

0 comments on commit 868b5e6

Please sign in to comment.