Skip to content
This repository was archived by the owner on Jul 9, 2020. It is now read-only.

Commit

Permalink
Update for compatibility with react-bootstrap 0.29+.
Browse files Browse the repository at this point in the history
  • Loading branch information
schneidmaster committed Jul 12, 2016
1 parent 1d07b4c commit 0b031ab
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 15 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

# react-bootstrap-maskedinput

[react-maskedinput](https://github.com/insin/react-maskedinput) form element that works with [react-bootstrap](https://github.com/react-bootstrap/react-bootstrap)
[react-maskedinput](https://github.com/insin/react-maskedinput) form element that works with [react-bootstrap](https://github.com/react-bootstrap/react-bootstrap).

For `react-bootstrap` < 0.29.0, use [v0.1.0](https://github.com/schneidmaster/react-bootstrap-maskedinput/releases/tag/v0.1.0). For current versions of `react-bootstrap`, use 0.2.0.

## Usage

Expand All @@ -18,7 +20,10 @@ import MaskedInput from 'react-bootstrap-maskedinput'
export class MyForm extends React.Component {
render () {
return (
<MaskedInput type='text' label='Phone Number' name='phoneNumber' mask='111-111-1111' />
<FormGroup>
<ControlLabel>Phone Number</ControlLabel>
<MaskedFormControl type='text' name='phoneNumber' placeholder='09:00' mask='11:11' />
</FormGroup>
);
}
}
Expand Down
56 changes: 47 additions & 9 deletions index.cjsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,49 @@
React = require('react')
classNames = require('classnames')
Input = require('react-bootstrap').Input
MaskedInputField = require('react-maskedinput')
{FormControl} = require('react-bootstrap')
MaskedInputField = require('react-maskedinput')
{bsClass, getClassSet} = require('react-bootstrap/lib/utils/bootstrapUtils')
FormControlFeedback = require('react-bootstrap/lib/FormControlFeedback')
FormControlStatic = require('react-bootstrap/lib/FormControlStatic')
React = require('react')
elementType = require('react-prop-types/lib/elementType')
classNames = require('classnames')

class MaskedInput extends Input
renderInput: ->
className = if @isCheckboxOrRadio() || @isFile() then '' else 'form-control'
<MaskedInputField {...@props} className={classNames(@props.className, className)} ref='input' key='input' />
propTypes =
componentClass: elementType
# Only relevant if `componentClass` is `'input'`.
type: React.PropTypes.string
# Uses `controlId` from `<FormGroup>` if not explicitly specified.
id: React.PropTypes.string

module.exports = MaskedInput
defaultProps =
componentClass: 'input'

contextTypes =
$bs_formGroup: React.PropTypes.object

class MaskedFormControl extends FormControl
render: ->
formGroup = @context.$bs_formGroup
controlId = formGroup && formGroup.controlId

{type, id, className} = @props
id ||= controlId
props = {}
props[k] = v for k, v in @props when k not in ['componentClass', 'type', 'id', 'className', 'bsClass']

classes = getClassSet(@props) unless type is 'file'

<MaskedInputField
{...@props}
type={type}
id={id}
className={classNames(className, classes)}
/>

MaskedFormControl.propTypes = propTypes
MaskedFormControl.defaultProps = defaultProps
MaskedFormControl.contextTypes = contextTypes

MaskedFormControl.Feedback = FormControlFeedback
MaskedFormControl.Static = FormControlStatic

module.exports = bsClass('form-control', MaskedFormControl)
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-bootstrap-maskedinput",
"version": "0.1.0",
"version": "0.2.0",
"description": "react-maskedinput form element that works with react-bootstrap",
"main": "index.js",
"scripts": {
Expand All @@ -25,9 +25,10 @@
"homepage": "https://github.com/schneidmaster/react-bootstrap-maskedinput#readme",
"dependencies": {
"classnames": "^2.2.3",
"react": "^0.14.6",
"react-bootstrap": "^0.28.5",
"react-maskedinput": "^3.0.0"
"react": "^15.0.0",
"react-bootstrap": ">= 0.29.0",
"react-maskedinput": "^3.0.0",
"react-prop-types": "^0.3.0"
},
"devDependencies": {
"coffee-react": "^5.0.0"
Expand Down

0 comments on commit 0b031ab

Please sign in to comment.