alaska-field-text
Advanced tools
Comparing version 0.11.15 to 0.12.0
36
index.js
@@ -1,25 +0,18 @@ | ||
// @flow | ||
'use strict'; | ||
import { Field, utils } from 'alaska'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
export default class TextFeild extends Field { | ||
static plain = String; | ||
static dbOptions = ['trim', 'match', 'lowercase', 'uppercase', 'maxlength', 'minlength']; | ||
static viewOptions = [ | ||
'trim', 'match', 'lowercase', 'uppercase', 'maxlength', 'minlength', | ||
'addonBefore', 'addonAfter', 'placeholder', 'multiLine', 'translate' | ||
]; | ||
static defaultOptions = { | ||
cell: 'TextFieldCell', | ||
view: 'TextFieldView', | ||
filter: 'TextFieldFilter', | ||
}; | ||
var _alaska = require('alaska'); | ||
class TextFeild extends _alaska.Field { | ||
init() { | ||
if (this.match && !(this.match instanceof RegExp)) { | ||
throw new Error(`${this._model.name}.${this.path} field "match" option must be instance of RegExp`); | ||
throw new Error(`${this._model.modelName}.${this.path} field "match" option must be instance of RegExp`); | ||
} | ||
} | ||
createFilter(filter: Object): any|void { | ||
createFilter(filter) { | ||
if (filter instanceof RegExp) { | ||
@@ -46,3 +39,3 @@ return filter; | ||
} else { | ||
result = new RegExp(utils.escapeRegExp(value), 'i'); | ||
result = new RegExp(_alaska.utils.escapeRegExp(value), 'i'); | ||
} | ||
@@ -60,1 +53,10 @@ if (inverse) { | ||
} | ||
exports.default = TextFeild; | ||
TextFeild.plain = String; | ||
TextFeild.dbOptions = ['trim', 'match', 'lowercase', 'uppercase', 'maxlength', 'minlength']; | ||
TextFeild.viewOptions = ['trim', 'match', 'lowercase', 'uppercase', 'maxlength', 'minlength', 'addonBefore', 'addonAfter', 'placeholder', 'multiLine', 'translate']; | ||
TextFeild.defaultOptions = { | ||
cell: 'TextFieldCell', | ||
view: 'TextFieldView', | ||
filter: 'TextFieldFilter' | ||
}; |
{ | ||
"name": "alaska-field-text", | ||
"version": "0.11.15", | ||
"version": "0.12.0", | ||
"description": "Alaska text field", | ||
@@ -9,6 +9,7 @@ "keywords": [ | ||
], | ||
"alaska": "field", | ||
"main": "index.js", | ||
"repository": "https://github.com/maichong/alaska/tree/master/packages/alaska-field-text", | ||
"repository": "https://github.com/maichong/alaska/tree/master/src/alaska-field-text", | ||
"author": "Liang <liang@maichong.it> (https://github.com/liangxingchen)", | ||
"license": "MIT" | ||
} |
@@ -8,4 +8,3 @@ // @flow | ||
export default class TextFieldCell extends React.Component { | ||
export default class TextFieldCell extends React.Component<Alaska$view$Field$Cell$Props> { | ||
static contextTypes = { | ||
@@ -15,9 +14,3 @@ t: PropTypes.func, | ||
props: { | ||
model: Object, | ||
field: Object, | ||
value: any | ||
}; | ||
shouldComponentUpdate(props: Object) { | ||
shouldComponentUpdate(props: Alaska$view$Field$Cell$Props) { | ||
return props.value != this.props.value; | ||
@@ -30,3 +23,3 @@ } | ||
if (value && field.translate) { | ||
const t = this.context.t; | ||
const { t } = this.context; | ||
value = t(value, model.serviceId); | ||
@@ -33,0 +26,0 @@ } |
@@ -6,4 +6,10 @@ // @flow | ||
export default class TextFieldFilter extends React.Component { | ||
type State = { | ||
mode: 1 | 2, | ||
value: string, | ||
error: boolean, | ||
inverse: boolean | ||
}; | ||
export default class TextFieldFilter extends React.Component<Alaska$view$Field$Filter$Props, State> { | ||
static contextTypes = { | ||
@@ -13,21 +19,6 @@ t: PropTypes.func, | ||
props: { | ||
className: string, | ||
value: any, | ||
field: Object, | ||
onChange: Function, | ||
onClose: Function, | ||
}; | ||
state: { | ||
mode: 1 | 2; | ||
value: string; | ||
error: boolean; | ||
inverse: boolean; | ||
}; | ||
handleMode1: Function; | ||
handleMode2: Function; | ||
constructor(props: Object) { | ||
constructor(props: Alaska$view$Field$Filter$Props) { | ||
super(props); | ||
@@ -53,3 +44,3 @@ let v = props.value || {}; | ||
handleChange = (event: ReactInputEvent) => { | ||
handleChange = (event: SyntheticInputEvent<*>) => { | ||
this.setState({ value: event.target.value }); | ||
@@ -84,5 +75,7 @@ }; | ||
render() { | ||
const t = this.context.t; | ||
const { t } = this.context; | ||
let { className, field, onClose } = this.props; | ||
const { mode, value, error, inverse } = this.state; | ||
const { | ||
mode, value, error, inverse | ||
} = this.state; | ||
const buttonClassName = 'btn btn-default'; | ||
@@ -99,7 +92,9 @@ const buttonClassNameActive = buttonClassName + ' btn-success'; | ||
onClick={this.handleMode1} | ||
>{t('equal')}</a> | ||
>{t('equal')} | ||
</a> | ||
<a | ||
className={mode === 2 ? buttonClassNameActive : buttonClassName} | ||
onClick={this.handleMode2} | ||
>{t('contain')}</a> | ||
>{t('contain')} | ||
</a> | ||
</div> | ||
@@ -116,3 +111,4 @@ <input | ||
onClick={this.handleInverse} | ||
>{t('inverse')}</a> | ||
>{t('inverse')} | ||
</a> | ||
</div> | ||
@@ -119,0 +115,0 @@ <a className="btn field-filter-close" onClick={onClose}><i className="fa fa-close" /></a> |
@@ -7,4 +7,3 @@ // @flow | ||
export default class TextFieldView extends React.Component { | ||
export default class TextFieldView extends React.Component<Alaska$view$Field$View$Props> { | ||
static contextTypes = { | ||
@@ -14,18 +13,7 @@ t: PropTypes.func, | ||
props: { | ||
className: string, | ||
model: Object, | ||
field: Object, | ||
data: Object, | ||
errorText: string, | ||
disabled: boolean, | ||
value: any, | ||
onChange: Function, | ||
}; | ||
shouldComponentUpdate(props: Object): boolean { | ||
return !shallowEqualWithout(props, this.props, 'data', 'onChange', 'model', 'field'); | ||
shouldComponentUpdate(props: Alaska$view$Field$View$Props): boolean { | ||
return !shallowEqualWithout(props, this.props, 'record', 'onChange', 'model', 'field'); | ||
} | ||
handleChange = (event: ReactInputEvent) => { | ||
handleChange = (event: SyntheticInputEvent<*>) => { | ||
if (this.props.onChange) { | ||
@@ -45,4 +33,4 @@ this.props.onChange(event.target.value); | ||
} = this.props; | ||
const t = this.context.t; | ||
let help = field.help; | ||
const { t } = this.context.t; | ||
let { help } = field; | ||
className += ' text-field'; | ||
@@ -68,3 +56,4 @@ if (errorText) { | ||
onChange={this.handleChange} | ||
disabled={disabled} value={value} | ||
disabled={disabled} | ||
value={value} | ||
/>); | ||
@@ -77,3 +66,4 @@ } else { | ||
onChange={this.handleChange} | ||
value={value} disabled={disabled} | ||
value={value} | ||
disabled={disabled} | ||
/>); | ||
@@ -80,0 +70,0 @@ let addonAfter = field.addonAfter ? |
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
9349
272