JSFiddle - React, Tailwind, and code Playground
by nosir
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.js"></script>
<script src="https://fb.me/react-with-addons-15.2.0.js"></script>
<script src="https://fb.me/react-dom-15.2.0.js"></script>
<script src="https://nosir.github.io/cleave.js/dist/cleave-react.min.js"></script>
<script src="https://nosir.github.io/cleave.js/lib/cleave-phone.i18n.js"></script>
<script src="https://facebook.github.io/react/js/jsfiddle-integration-babel.js"></script>
<div id="content"></div>
CSS
* {
font-family: sans-serif;
}
.raw-values {
margin-top: 20px;
border-top: 1px dotted #AAA;
}
input {
display: block;
outline: none;
-webkit-appearance: none;
border: 1px solid #e6e6e6;
border-radius: 5px;
background-color: #fff;
line-height: 30px;
vertical-align: middle;
height: 33px;
width: 170px;
font-size: 14px;
padding: 0 8px;
margin-bottom: 10px;
}
.input-numeral {
text-align: right;
}
JavaScript 1.7
class MyComponent extends React.Component {
constructor(props, context) {
super(props, context);
this.state = {
info: 'none',
customRawValue: ''
};
this.onCustomChange = this.onCustomChange.bind(this);
this.onBlur = this.onBlur.bind(this);
this.onFocus = this.onFocus.bind(this);
}
onCustomChange(event) {
this.setState({customRawValue: event.target.rawValue});
}
onBlur(event) {
this.setState({info: 'blur triggered!'});
}
onFocus(event) {
this.setState({info: 'focus triggered!'});
}
render() {
return (
<div>
<Cleave placeholder="Custom delimiter / blocks" options={{blocks: [3,3,3], delimiter: '-'}}
onBlur={this.onBlur}
onFocus={this.onFocus}
onChange={this.onCustomChange}/>
<div className="raw-values">
<p>custom value: {this.state.customRawValue}</p>
<p>blur / focus info: {this.state.info}</p>
</div>
</div>
);
}
}
ReactDOM.render(<MyComponent/>, document.getElementById('content'));