Comparing version 0.0.19 to 0.0.20
/*! | ||
* Eyzy v0.0.19 | ||
* Eyzy v0.0.20 | ||
* (c) 2022 amsik | ||
@@ -192,3 +192,2 @@ * Released under the MIT License. | ||
var className = props.className, width = props.width, required = props.required, fit = props.fit, type = props.type, style = props.style, error = props.error, helpText = props.helpText, label = props.label, onPressEnter = props.onPressEnter, onPressEsc = props.onPressEsc, onKeyDown = props.onKeyDown, onChange = props.onChange, rest = __rest(props, ["className", "width", "required", "fit", "type", "style", "error", "helpText", "label", "onPressEnter", "onPressEsc", "onKeyDown", "onChange"]); | ||
var _a = React.useState(props.value || props.defaultValue || ''), value = _a[0], setValue = _a[1]; | ||
var handleChange = function (e) { | ||
@@ -199,11 +198,3 @@ var val = e.target.value; | ||
} | ||
else { | ||
setValue(val); | ||
} | ||
}; | ||
React.useEffect(function () { | ||
if (onChange) { // controlled | ||
setValue(props.value || ''); | ||
} | ||
}, [props.value]); | ||
var handleKeyDown = function (e) { | ||
@@ -229,10 +220,6 @@ if (onPressEnter && isEnter(e)) { | ||
React__default.createElement(FocusRing, null, | ||
React__default.createElement(ElementType, __assign({}, rest, { ref: ref, value: value, type: type || 'text', className: classNames, style: elemStyle, onChange: handleChange, onKeyDown: handleKeyDown }))))); | ||
React__default.createElement(ElementType, __assign({}, rest, { ref: ref, type: type || 'text', className: classNames, style: elemStyle, onChange: handleChange, onKeyDown: handleKeyDown }))))); | ||
} | ||
var BaseInput$1 = React.forwardRef(BaseInput); | ||
var Input = React.forwardRef(BaseInput); | ||
var Input = React__default.memo(function Input(props) { | ||
return (React__default.createElement(BaseInput$1, __assign({}, props))); | ||
}); | ||
var TextArea = React__default.memo(function TextArea(props) { | ||
@@ -260,3 +247,3 @@ var textAreaRef = React.useRef(); | ||
}, [autoHeight]); | ||
return (React__default.createElement(BaseInput$1, __assign({}, rest, { className: classNames, ref: textAreaRef, type: "textarea" }))); | ||
return (React__default.createElement(Input, __assign({}, rest, { className: classNames, ref: textAreaRef, type: "textarea" }))); | ||
}); | ||
@@ -266,45 +253,21 @@ | ||
var INT_RE = /\-?\d+/; | ||
var FLOAT_RE = /^\-?\d*\.?\d*$/; | ||
var precessValue = function (v, isInt) { | ||
var val = v | ||
.replace(/,/g, '.') | ||
.replace(/\-+/g, '-'); | ||
if (val === '-') { | ||
return val; | ||
var INT_MATCH = /^-?(\d)+/; | ||
var processValue = function (v, isInt) { | ||
var _a; | ||
if (v === '-') { | ||
return '-'; | ||
} | ||
if (val) { | ||
if (isInt) { | ||
if (!INT_RE.test(val)) { | ||
return null; | ||
} | ||
} | ||
else { | ||
if (!FLOAT_RE.test(val)) { | ||
return null; | ||
} | ||
} | ||
if (isInt) { | ||
return ((_a = v.match(INT_MATCH)) === null || _a === void 0 ? void 0 : _a[0]) || ''; | ||
} | ||
else { | ||
return ''; | ||
if (!isFinite(v)) { | ||
v = parseFloat(v); | ||
} | ||
return isFinite(val) | ||
? val | ||
: isFinite(v) ? v : ''; | ||
return v; | ||
}; | ||
var NumberInput = React__default.memo(function NumberInput(props) { | ||
var _a = React.useState(precessValue(props.value || props.defaultValue || '')), value = _a[0], setValue = _a[1]; | ||
var handleChange = function (value, e) { | ||
var val = precessValue(value, props.isInt); | ||
if (val === null) { | ||
return; | ||
} | ||
if (props.onChange) { | ||
props.onChange(value, e); | ||
} | ||
setValue(val); | ||
}; | ||
// всетаки сделать onchange(value: string | Number, ORIGINAL_EVENT as 2th argument) | ||
// тут useEffect ([defaultValue and value]) | ||
return (React__default.createElement(BaseInput$1, __assign({}, props, { type: isMob() ? 'number' : 'text', value: value, onChange: handleChange }))); | ||
var value = undefined !== props.value | ||
? processValue(props.value, props.isInt) | ||
: ''; | ||
return (React__default.createElement(Input, __assign({}, props, { type: isMob() ? 'number' : 'text', value: value || '' }))); | ||
}); | ||
@@ -311,0 +274,0 @@ |
/*! | ||
* Eyzy v0.0.19 | ||
* Eyzy v0.0.20 | ||
* (c) 2022 amsik | ||
@@ -186,3 +186,2 @@ * Released under the MIT License. | ||
var className = props.className, width = props.width, required = props.required, fit = props.fit, type = props.type, style = props.style, error = props.error, helpText = props.helpText, label = props.label, onPressEnter = props.onPressEnter, onPressEsc = props.onPressEsc, onKeyDown = props.onKeyDown, onChange = props.onChange, rest = __rest(props, ["className", "width", "required", "fit", "type", "style", "error", "helpText", "label", "onPressEnter", "onPressEsc", "onKeyDown", "onChange"]); | ||
var _a = useState(props.value || props.defaultValue || ''), value = _a[0], setValue = _a[1]; | ||
var handleChange = function (e) { | ||
@@ -193,11 +192,3 @@ var val = e.target.value; | ||
} | ||
else { | ||
setValue(val); | ||
} | ||
}; | ||
useEffect(function () { | ||
if (onChange) { // controlled | ||
setValue(props.value || ''); | ||
} | ||
}, [props.value]); | ||
var handleKeyDown = function (e) { | ||
@@ -223,10 +214,6 @@ if (onPressEnter && isEnter(e)) { | ||
React.createElement(FocusRing, null, | ||
React.createElement(ElementType, __assign({}, rest, { ref: ref, value: value, type: type || 'text', className: classNames, style: elemStyle, onChange: handleChange, onKeyDown: handleKeyDown }))))); | ||
React.createElement(ElementType, __assign({}, rest, { ref: ref, type: type || 'text', className: classNames, style: elemStyle, onChange: handleChange, onKeyDown: handleKeyDown }))))); | ||
} | ||
var BaseInput$1 = forwardRef(BaseInput); | ||
var Input = forwardRef(BaseInput); | ||
var Input = React.memo(function Input(props) { | ||
return (React.createElement(BaseInput$1, __assign({}, props))); | ||
}); | ||
var TextArea = React.memo(function TextArea(props) { | ||
@@ -254,3 +241,3 @@ var textAreaRef = useRef(); | ||
}, [autoHeight]); | ||
return (React.createElement(BaseInput$1, __assign({}, rest, { className: classNames, ref: textAreaRef, type: "textarea" }))); | ||
return (React.createElement(Input, __assign({}, rest, { className: classNames, ref: textAreaRef, type: "textarea" }))); | ||
}); | ||
@@ -260,45 +247,21 @@ | ||
var INT_RE = /\-?\d+/; | ||
var FLOAT_RE = /^\-?\d*\.?\d*$/; | ||
var precessValue = function (v, isInt) { | ||
var val = v | ||
.replace(/,/g, '.') | ||
.replace(/\-+/g, '-'); | ||
if (val === '-') { | ||
return val; | ||
var INT_MATCH = /^-?(\d)+/; | ||
var processValue = function (v, isInt) { | ||
var _a; | ||
if (v === '-') { | ||
return '-'; | ||
} | ||
if (val) { | ||
if (isInt) { | ||
if (!INT_RE.test(val)) { | ||
return null; | ||
} | ||
} | ||
else { | ||
if (!FLOAT_RE.test(val)) { | ||
return null; | ||
} | ||
} | ||
if (isInt) { | ||
return ((_a = v.match(INT_MATCH)) === null || _a === void 0 ? void 0 : _a[0]) || ''; | ||
} | ||
else { | ||
return ''; | ||
if (!isFinite(v)) { | ||
v = parseFloat(v); | ||
} | ||
return isFinite(val) | ||
? val | ||
: isFinite(v) ? v : ''; | ||
return v; | ||
}; | ||
var NumberInput = React.memo(function NumberInput(props) { | ||
var _a = useState(precessValue(props.value || props.defaultValue || '')), value = _a[0], setValue = _a[1]; | ||
var handleChange = function (value, e) { | ||
var val = precessValue(value, props.isInt); | ||
if (val === null) { | ||
return; | ||
} | ||
if (props.onChange) { | ||
props.onChange(value, e); | ||
} | ||
setValue(val); | ||
}; | ||
// всетаки сделать onchange(value: string | Number, ORIGINAL_EVENT as 2th argument) | ||
// тут useEffect ([defaultValue and value]) | ||
return (React.createElement(BaseInput$1, __assign({}, props, { type: isMob() ? 'number' : 'text', value: value, onChange: handleChange }))); | ||
var value = undefined !== props.value | ||
? processValue(props.value, props.isInt) | ||
: ''; | ||
return (React.createElement(Input, __assign({}, props, { type: isMob() ? 'number' : 'text', value: value || '' }))); | ||
}); | ||
@@ -305,0 +268,0 @@ |
{ | ||
"name": "eyzy", | ||
"version": "0.0.19", | ||
"version": "0.0.20", | ||
"author": "Kostiantyn", | ||
@@ -5,0 +5,0 @@ "description": "React UI Toolkit", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
169762
1705