nuke-input
Version:
输入框
125 lines (112 loc) • 2.89 kB
Markdown
# Input Demo
* order: 4
单行文本 md 定制
---
```js
/** @jsx createElement */
import { createElement, Component, render } from 'rax';
import View from 'nuke-view';
import Text from 'nuke-text';
import Input from 'nuke-input';
import Page from 'nuke-page';
import Button from 'nuke-button';
import { isWeb, appInfo } from 'nuke-env';
import { StyleProvider } from 'nuke-theme-provider';
const isAndroid = true;
let md = {
Core: {
'color-brand1-1': '#00BBD3',
'color-brand1-6': '#1A9CB7',
'color-brand1-9': '#0096A6',
'color-error-3': '#D50000',
'color-line1-1': '#DADADA',
'color-line1-2': '#E0E0E0',
'color-text1-1': '#9E9E9E',
['font-size-title']: 40,
['font-size-subhead']: 32,
['font-size-body-3']: 28,
['font-size-body-2']: 28,
['font-size-body-1']: 28,
['font-size-caption']: 24,
['font-size-footnote']: 20
},
Input: {
'md-placeholder-height': 50,
'md-help-margin-top': 16,
'md-input-height': 50,
'md-placeholder-font-size': 28,
'md-input-margin-bottom': 0
}
};
let App = class NukeDemoIndex extends Component {
constructor() {
super();
this.state = {
content: '',
max: 10,
placeholderText: 'Please enter account number'
};
this.validateCreditCard = this.validateCreditCard.bind(this);
// this.checkLengthOnInput = this.checkLengthOnInput.bind(this);
// this.change = this.change.bind(this);
// this.onIconPress = this.onIconPress.bind(this);
}
validateCreditCard(e) {
let newValue = this.cc_format(e.value);
if (newValue !== e.value) {
this.setState({
cardNumber: newValue
});
} else {
}
}
cc_format(value) {
var v = value.replace(/\s+/g, '').replace(/[^0-9]/gi, '');
var matches = v.match(/\d{4,16}/g);
var match = (matches && matches[0]) || '';
var parts = [];
var len = match.length;
for (var i = 0; i < len; i += 4) {
parts.push(match.substring(i, i + 4));
}
if (parts.length) {
return parts.join(' ');
} else {
return value;
}
}
handleClear = (value) => {
alert('handleClear: ' + value);
}
handleChange = (value) => {
alert('handleChange: ' + value);
return true;
}
render() {
return (
<Page title="single md">
<Page.Intro main="cardnumber" />
<View style={styles.demoBlock}>
<Input
ref="myinput"
maxLength={this.state.max}
placeholder={this.state.placeholderText}
style={{ height: 60, marginBottom: '20rem' }}
id="first"
hasClear={true}
onClear={this.handleClear}
onChange={this.handleChange}
/>
</View>
</Page>
);
}
};
const styles = {
demoBlock: {
marginLeft: 40,
marginRight: 40
}
};
render(<App />);
```