react-ui89 0.19.0 → 0.19.2
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/esm/index.js +38 -22
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/react-utils.d.ts +7 -0
- package/dist/esm/timeout.d.ts +4 -0
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -134,7 +134,7 @@ function Ui89Button({ theme = Ui89Theme.primary, size = "normal", block, onClick
|
|
|
134
134
|
if (href) {
|
|
135
135
|
return (React__default.createElement("span", { className: styles$f.container },
|
|
136
136
|
React__default.createElement(HoverShadow, null,
|
|
137
|
-
React__default.createElement("a", { className: buttonClass
|
|
137
|
+
React__default.createElement("a", { className: `${resetStyles.a} ${buttonClass}`, role: "button", href: href, onClick: onAnchorClick },
|
|
138
138
|
React__default.createElement("span", { className: styles$f.click }),
|
|
139
139
|
React__default.createElement("div", { className: styles$f.buttonContent }, children)))));
|
|
140
140
|
}
|
|
@@ -303,14 +303,20 @@ function throttledTimeout() {
|
|
|
303
303
|
Timeout.set(id, () => callback(), delay);
|
|
304
304
|
}
|
|
305
305
|
},
|
|
306
|
+
/**
|
|
307
|
+
* If there is a call that has been scheduled, remove it from the queue.
|
|
308
|
+
*/
|
|
309
|
+
abort() {
|
|
310
|
+
Timeout.clear(id, true);
|
|
311
|
+
},
|
|
306
312
|
};
|
|
307
313
|
}
|
|
308
314
|
|
|
309
315
|
const THROTTLE_DELAY = 200;
|
|
310
316
|
function Ui89InputText({ value, placeholder, autoTrim = true, onChange, onTyping, onFocus, onBlur, }) {
|
|
311
317
|
const inputRef = useRef(null);
|
|
312
|
-
const [isTyping, setIsTyping] = useState(false);
|
|
313
318
|
const [intermediateValue, setIntermediateValue] = useState(value);
|
|
319
|
+
const [isTyping, setIsTyping] = useState(false);
|
|
314
320
|
const onChangeThrottled = useMemo(() => throttledTimeout(), []);
|
|
315
321
|
useEffect(() => {
|
|
316
322
|
if (inputRef.current === null) {
|
|
@@ -326,6 +332,8 @@ function Ui89InputText({ value, placeholder, autoTrim = true, onChange, onTyping
|
|
|
326
332
|
}
|
|
327
333
|
};
|
|
328
334
|
inputRef.current.onblur = () => {
|
|
335
|
+
onChangeThrottled.abort();
|
|
336
|
+
update();
|
|
329
337
|
setIsTyping(false);
|
|
330
338
|
if (onTyping) {
|
|
331
339
|
onTyping(false);
|
|
@@ -336,31 +344,40 @@ function Ui89InputText({ value, placeholder, autoTrim = true, onChange, onTyping
|
|
|
336
344
|
};
|
|
337
345
|
}, [inputRef.current, onBlur, onFocus]);
|
|
338
346
|
useEffect(() => {
|
|
339
|
-
if (isTyping === null) {
|
|
340
|
-
return;
|
|
341
|
-
}
|
|
342
347
|
if (!isTyping) {
|
|
343
|
-
// Lets show the user what
|
|
344
|
-
|
|
348
|
+
// Lets show the user what the actual value is.
|
|
349
|
+
onChangeThrottled.call(THROTTLE_DELAY, () => {
|
|
350
|
+
setIntermediateValue(value);
|
|
351
|
+
});
|
|
345
352
|
}
|
|
346
|
-
}, [
|
|
353
|
+
}, [value]);
|
|
347
354
|
function implOnChange(e) {
|
|
355
|
+
setIntermediateValue(e.target.value);
|
|
356
|
+
onChangeThrottled.call(THROTTLE_DELAY, update);
|
|
357
|
+
}
|
|
358
|
+
function update() {
|
|
348
359
|
if (!onChange) {
|
|
349
360
|
return;
|
|
350
361
|
}
|
|
351
|
-
|
|
352
|
-
|
|
362
|
+
if (inputRef.current === null) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
// We get the current value straight from the element because this function
|
|
366
|
+
// may have been queued.
|
|
367
|
+
let newVal = inputRef.current.value;
|
|
353
368
|
if (autoTrim) {
|
|
354
369
|
// Must trim after setting intermediate value. Do not want to disturb
|
|
355
370
|
// user.
|
|
356
371
|
newVal = newVal.replace(/\s+/g, " ").trim();
|
|
357
372
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
373
|
+
if (newVal === value) {
|
|
374
|
+
// Same value.
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
onChange(newVal);
|
|
361
378
|
}
|
|
362
379
|
return (React__default.createElement("div", null,
|
|
363
|
-
React__default.createElement("input", { ref: inputRef, className: `${inputBoxStyles.inputBox} ${typoStyles.special}`, type: "text",
|
|
380
|
+
React__default.createElement("input", { ref: inputRef, value: intermediateValue, className: `${inputBoxStyles.inputBox} ${typoStyles.special}`, type: "text", onChange: implOnChange, placeholder: placeholder })));
|
|
364
381
|
}
|
|
365
382
|
|
|
366
383
|
function stringRemoveAllWhitespace(str) {
|
|
@@ -390,10 +407,8 @@ function Ui89InputTextNumber({
|
|
|
390
407
|
* The value that is emitted when the input is emptied.
|
|
391
408
|
*/
|
|
392
409
|
emptyValue = null, value, min, max, onChange, precision, }) {
|
|
410
|
+
const [isTyping, setIsTyping] = useState(false);
|
|
393
411
|
const [intermediateValue, setIntermediateValue] = useState(displayText(value, emptyValue));
|
|
394
|
-
useEffect(() => {
|
|
395
|
-
setIntermediateValue(displayText(value, emptyValue));
|
|
396
|
-
}, [value]);
|
|
397
412
|
function implOnChange(value) {
|
|
398
413
|
if (onChange === undefined) {
|
|
399
414
|
return;
|
|
@@ -421,11 +436,12 @@ emptyValue = null, value, min, max, onChange, precision, }) {
|
|
|
421
436
|
}
|
|
422
437
|
onChange(value);
|
|
423
438
|
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
439
|
+
useEffect(() => {
|
|
440
|
+
if (!isTyping) {
|
|
441
|
+
setIntermediateValue(displayText(value, emptyValue));
|
|
442
|
+
}
|
|
443
|
+
}, [isTyping, value]);
|
|
444
|
+
return (React__default.createElement(Ui89InputText, { value: intermediateValue, onChange: implOnChange, onTyping: setIsTyping }));
|
|
429
445
|
}
|
|
430
446
|
|
|
431
447
|
var styles$a = {"menuBar":"Ui89MenuBar-module_menuBar__IlnEP","menuBarItem":"Ui89MenuBar-module_menuBarItem__UVFg2"};
|