@rahmatsaputra-my-id/react-js-library 0.0.15 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/TextInput/TextInput.types.d.ts +3 -0
- package/dist/index.es.js +46 -5
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +46 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -14,11 +14,14 @@ export interface ITextInputProps {
|
|
|
14
14
|
placeholder?: string;
|
|
15
15
|
right?: number;
|
|
16
16
|
rows?: number;
|
|
17
|
+
maxRows?: number;
|
|
17
18
|
style?: any;
|
|
18
19
|
styleLabel?: any;
|
|
19
20
|
styleTextInput?: any;
|
|
20
21
|
top?: number;
|
|
21
22
|
type?: string;
|
|
22
23
|
value?: any;
|
|
24
|
+
isInputRupiah?: boolean;
|
|
25
|
+
isInputNumber?: boolean;
|
|
23
26
|
handleOnScanQr?: (data?: string | null) => void;
|
|
24
27
|
}
|
package/dist/index.es.js
CHANGED
|
@@ -30215,12 +30215,53 @@ var styles = {
|
|
|
30215
30215
|
};
|
|
30216
30216
|
|
|
30217
30217
|
var TextInput = function (_a) {
|
|
30218
|
-
var _b = _a.borderColor, borderColor = _b === void 0 ? Colors.grey2 : _b, _c = _a.borderRadius, borderRadius = _c === void 0 ? 4 : _c, _d = _a.bottom, bottom = _d === void 0 ? 0 : _d, _e = _a.center, center = _e === void 0 ? false : _e, _f = _a.label, label = _f === void 0 ? false : _f, _g = _a.labelError, labelError = _g === void 0 ? false : _g, _h = _a.left, left = _h === void 0 ? 0 : _h, _j = _a.multiline, multiline = _j === void 0 ? false : _j, _k = _a.padding, padding = _k === void 0 ? 0 : _k, _l = _a.right, right = _l === void 0 ? 0 : _l, _m = _a.rows, rows = _m === void 0 ?
|
|
30219
|
-
var
|
|
30220
|
-
|
|
30221
|
-
var
|
|
30218
|
+
var _b = _a.borderColor, borderColor = _b === void 0 ? Colors.grey2 : _b, _c = _a.borderRadius, borderRadius = _c === void 0 ? 4 : _c, _d = _a.bottom, bottom = _d === void 0 ? 0 : _d, _e = _a.center, center = _e === void 0 ? false : _e, _f = _a.label, label = _f === void 0 ? false : _f, _g = _a.labelError, labelError = _g === void 0 ? false : _g, _h = _a.left, left = _h === void 0 ? 0 : _h, _j = _a.multiline, multiline = _j === void 0 ? false : _j, _k = _a.padding, padding = _k === void 0 ? 0 : _k, _l = _a.right, right = _l === void 0 ? 0 : _l, _m = _a.rows, rows = _m === void 0 ? 1 : _m, _o = _a.maxRows, maxRows = _o === void 0 ? 4 : _o, _p = _a.style, style = _p === void 0 ? {} : _p, _q = _a.styleLabel, styleLabel = _q === void 0 ? {} : _q, _r = _a.styleTextInput, styleTextInput = _r === void 0 ? {} : _r, _s = _a.top, top = _s === void 0 ? 0 : _s, value = _a.value, onChange = _a.onChange, handleOnScanQr = _a.handleOnScanQr, _t = _a.isInputRupiah, isInputRupiah = _t === void 0 ? false : _t, _u = _a.isInputNumber, isInputNumber = _u === void 0 ? false : _u, props = __rest(_a, ["borderColor", "borderRadius", "bottom", "center", "label", "labelError", "left", "multiline", "padding", "right", "rows", "maxRows", "style", "styleLabel", "styleTextInput", "top", "value", "onChange", "handleOnScanQr", "isInputRupiah", "isInputNumber"]);
|
|
30219
|
+
var _v = useState(false), isScannerVisible = _v[0], setIsScannerVisible = _v[1];
|
|
30220
|
+
var textAreaRef = useRef(null);
|
|
30221
|
+
var formatRupiahDisplay = function (val) {
|
|
30222
|
+
if (!val)
|
|
30223
|
+
return '';
|
|
30224
|
+
var clean = val.toString().replace(/\D/g, '');
|
|
30225
|
+
return clean.replace(/\B(?=(\d{3})+(?!\d))/g, '.');
|
|
30226
|
+
};
|
|
30227
|
+
var parseRupiahValue = function (val) { return val.toString().replace(/\D/g, ''); };
|
|
30228
|
+
var handleChange = function (event) {
|
|
30229
|
+
var _a;
|
|
30230
|
+
var inputVal = ((_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.value) || '';
|
|
30231
|
+
if (isInputNumber) {
|
|
30232
|
+
inputVal = inputVal.replace(/\D/g, '');
|
|
30233
|
+
event.target.value = inputVal;
|
|
30234
|
+
}
|
|
30235
|
+
if (multiline && textAreaRef.current) {
|
|
30236
|
+
autoResize(textAreaRef.current);
|
|
30237
|
+
}
|
|
30238
|
+
if (isInputRupiah) {
|
|
30239
|
+
var numericVal = parseRupiahValue(inputVal);
|
|
30240
|
+
var formatted = formatRupiahDisplay(numericVal);
|
|
30241
|
+
event.target.value = formatted;
|
|
30242
|
+
onChange(__assign(__assign({}, event), { target: __assign(__assign({}, event.target), { value: numericVal }) }));
|
|
30243
|
+
}
|
|
30244
|
+
else {
|
|
30245
|
+
onChange(event);
|
|
30246
|
+
}
|
|
30247
|
+
};
|
|
30248
|
+
var autoResize = function (el) {
|
|
30249
|
+
el.style.height = 'auto';
|
|
30250
|
+
var lineHeight = parseInt(window.getComputedStyle(el).lineHeight || '20', 10);
|
|
30251
|
+
var maxHeight = lineHeight * maxRows;
|
|
30252
|
+
var newHeight = Math.min(el.scrollHeight, maxHeight);
|
|
30253
|
+
el.style.height = "".concat(newHeight, "px");
|
|
30254
|
+
el.style.overflowY = el.scrollHeight > maxHeight ? 'auto' : 'hidden';
|
|
30255
|
+
};
|
|
30256
|
+
useEffect(function () {
|
|
30257
|
+
if (multiline && textAreaRef.current) {
|
|
30258
|
+
autoResize(textAreaRef.current);
|
|
30259
|
+
}
|
|
30260
|
+
}, [value, multiline]);
|
|
30261
|
+
var adjustedStyleTextInput = __assign(__assign({}, styleTextInput), { paddingRight: handleOnScanQr ? 40 : styleTextInput.paddingRight, resize: 'none' });
|
|
30222
30262
|
var stylesTextInput = __assign(__assign({ borderColor: borderColor, borderRadius: borderRadius, textAlign: center ? 'center' : 'left', paddingBottom: multiline ? 16 : 8 }, styles.textArea), adjustedStyleTextInput);
|
|
30223
|
-
|
|
30263
|
+
var inputType = isInputRupiah || isInputNumber ? 'tel' : 'text';
|
|
30264
|
+
return (jsxs(Fragment, { children: [jsxs(View, __assign({ style: styles.container }, { children: [jsxs(View, __assign({ style: __assign({ marginTop: top, marginRight: right, marginBottom: bottom, marginLeft: left, padding: padding }, style) }, { children: [label && (jsx(Text, { style: __assign(__assign({}, styles.label), styleLabel), children: label })), jsx(View, { children: multiline ? (jsx("textarea", __assign({ ref: textAreaRef, rows: rows, inputMode: isInputNumber ? 'numeric' : 'text', style: stylesTextInput, value: isInputRupiah ? formatRupiahDisplay(value) : value !== null && value !== void 0 ? value : '', onChange: handleChange }, props))) : (jsx("input", __assign({ type: inputType, inputMode: isInputNumber ? 'numeric' : 'text', style: stylesTextInput, value: isInputRupiah ? formatRupiahDisplay(value) : value !== null && value !== void 0 ? value : '', onChange: handleChange }, props))) }), labelError ? (jsx(Text, { style: styles.labelError, children: labelError })) : null] })), handleOnScanQr && (jsx(TouchableOpacity, __assign({ style: label
|
|
30224
30265
|
? styles.scanQrImageContainerWithLabel
|
|
30225
30266
|
: styles.scanQrImageContainer, onPress: function () {
|
|
30226
30267
|
handleOnScanQr();
|