@rolster/react-components 19.8.21 → 19.8.22
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/LICENSE +21 -21
- package/dist/cjs/index.cjs +73 -16
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/es/index.mjs +73 -16
- package/dist/es/index.mjs.map +1 -1
- package/dist/esm/components/atoms/AreaText/AreaText.d.ts +4 -2
- package/dist/esm/components/atoms/AreaText/AreaText.js +50 -10
- package/dist/esm/components/atoms/AreaText/AreaText.js.map +1 -1
- package/dist/esm/components/atoms/Skeleton/Skeleton.d.ts +5 -1
- package/dist/esm/components/atoms/Skeleton/Skeleton.js +6 -2
- package/dist/esm/components/atoms/Skeleton/Skeleton.js.map +1 -1
- package/dist/esm/components/atoms/SkeletonText/SkeletonText.d.ts +3 -1
- package/dist/esm/components/atoms/SkeletonText/SkeletonText.js +2 -2
- package/dist/esm/components/atoms/SkeletonText/SkeletonText.js.map +1 -1
- package/dist/esm/components/molecules/FieldArea/FieldArea.d.ts +1 -0
- package/dist/esm/components/molecules/FieldArea/FieldArea.js +17 -3
- package/dist/esm/components/molecules/FieldArea/FieldArea.js.map +1 -1
- package/package.json +2 -2
- package/readme.md +392 -2
package/dist/es/index.mjs
CHANGED
|
@@ -482,20 +482,41 @@ function RlsAmountComponent({ value, className, decimals, rlsTheme, symbol }) {
|
|
|
482
482
|
}
|
|
483
483
|
const RlsAmount = memo(RlsAmountComponent);
|
|
484
484
|
|
|
485
|
-
|
|
485
|
+
const AREA_TEXT_MAX_ROWS = 8;
|
|
486
|
+
const AREA_TEXT_MIN_ROWS = 3;
|
|
487
|
+
function RlsAreaTextComponent({ autoComplete, disabled, formControl, identifier, maxLength, maxRows, minRows, onBlur, onEnter, onFocus, onKeyDown, onKeyUp, onValue, placeholder, readOnly, resize = 'vertical', value }) {
|
|
486
488
|
const valueInitial = String(formControl?.value ?? value ?? '');
|
|
489
|
+
const rowsMin = minRows ?? AREA_TEXT_MIN_ROWS;
|
|
490
|
+
const rowsMax = Math.max(maxRows ?? AREA_TEXT_MAX_ROWS, rowsMin);
|
|
487
491
|
const [valueArea, setValueArea] = useState(valueInitial);
|
|
488
492
|
const [focused, setFocused] = useState(false);
|
|
489
493
|
const elementRef = useRef(null);
|
|
490
494
|
const areaRef = formControl?.elementRef ?? elementRef;
|
|
491
495
|
const changeIsInternal = useRef(false);
|
|
496
|
+
const heightIsManual = useRef(false);
|
|
497
|
+
const heightApplied = useRef(0);
|
|
492
498
|
const refreshHeight = useCallback(() => {
|
|
493
499
|
const element = areaRef.current;
|
|
494
|
-
if (element) {
|
|
495
|
-
|
|
496
|
-
|
|
500
|
+
if (!element || heightIsManual.current) {
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
element.style.height = 'auto';
|
|
504
|
+
const { lineHeight, paddingBottom, paddingTop } = getComputedStyle(element);
|
|
505
|
+
const heightLine = parseFloat(lineHeight);
|
|
506
|
+
const heightContent = element.scrollHeight;
|
|
507
|
+
if (!heightLine) {
|
|
508
|
+
element.style.height = `${heightContent}px`;
|
|
509
|
+
heightApplied.current = heightContent;
|
|
510
|
+
return;
|
|
497
511
|
}
|
|
498
|
-
|
|
512
|
+
const heightPadding = parseFloat(paddingTop) + parseFloat(paddingBottom);
|
|
513
|
+
const heightMin = heightLine * rowsMin + heightPadding;
|
|
514
|
+
const heightMax = heightLine * rowsMax + heightPadding;
|
|
515
|
+
const height = Math.min(Math.max(heightContent, heightMin), heightMax);
|
|
516
|
+
element.style.height = `${height}px`;
|
|
517
|
+
element.style.overflowY = heightContent > heightMax ? 'auto' : 'hidden';
|
|
518
|
+
heightApplied.current = height;
|
|
519
|
+
}, [areaRef, rowsMax, rowsMin]);
|
|
499
520
|
useEffect(() => {
|
|
500
521
|
if (!changeIsInternal.current) {
|
|
501
522
|
const nextValue = String(formControl?.value ?? value ?? '');
|
|
@@ -508,14 +529,31 @@ function RlsAreaTextComponent({ autoComplete, disabled, formControl, identifier,
|
|
|
508
529
|
useEffect(() => {
|
|
509
530
|
refreshHeight();
|
|
510
531
|
}, [refreshHeight, valueArea]);
|
|
532
|
+
useEffect(() => {
|
|
533
|
+
const element = areaRef.current;
|
|
534
|
+
if (!element ||
|
|
535
|
+
resize === 'none' ||
|
|
536
|
+
typeof ResizeObserver === 'undefined') {
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
const observer = new ResizeObserver(() => {
|
|
540
|
+
if (heightIsManual.current || !heightApplied.current) {
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
if (Math.abs(element.offsetHeight - heightApplied.current) > 1) {
|
|
544
|
+
heightIsManual.current = true;
|
|
545
|
+
element.style.overflowY = 'auto';
|
|
546
|
+
}
|
|
547
|
+
});
|
|
548
|
+
observer.observe(element);
|
|
549
|
+
return () => observer.disconnect();
|
|
550
|
+
}, [areaRef, resize]);
|
|
511
551
|
const onChangeArea = useCallback((event) => {
|
|
512
552
|
const nextValue = event.target.value;
|
|
513
553
|
changeIsInternal.current = true;
|
|
514
554
|
onValue?.(nextValue);
|
|
515
555
|
setValueArea(nextValue);
|
|
516
556
|
formControl?.setValue(nextValue);
|
|
517
|
-
event.target.style.height = 'auto';
|
|
518
|
-
event.target.style.height = `${event.target.scrollHeight}px`;
|
|
519
557
|
}, [formControl, onValue]);
|
|
520
558
|
const onKeyDownArea = useCallback((event) => {
|
|
521
559
|
onKeyDown?.(event);
|
|
@@ -536,12 +574,14 @@ function RlsAreaTextComponent({ autoComplete, disabled, formControl, identifier,
|
|
|
536
574
|
setFocused(() => false);
|
|
537
575
|
onBlur?.();
|
|
538
576
|
}, [formControl, onBlur]);
|
|
577
|
+
const disabledArea = formControl?.disabled || disabled;
|
|
539
578
|
const className = renderClassStatus('rls-area-text', {
|
|
540
|
-
disabled:
|
|
579
|
+
disabled: disabledArea,
|
|
541
580
|
focused: formControl?.focused ?? focused,
|
|
542
|
-
readonly: readOnly
|
|
581
|
+
readonly: readOnly,
|
|
582
|
+
resizable: resize !== 'none' && !disabledArea && !readOnly
|
|
543
583
|
});
|
|
544
|
-
return (jsxRuntimeExports.jsxs("div", { id: identifier, className: className, children: [jsxRuntimeExports.jsx("textarea", { ref: areaRef, className: "rls-area-text__component", autoComplete: autoComplete ?? 'off', placeholder: placeholder, disabled:
|
|
584
|
+
return (jsxRuntimeExports.jsxs("div", { id: identifier, className: className, children: [jsxRuntimeExports.jsx("textarea", { ref: areaRef, className: "rls-area-text__component", autoComplete: autoComplete ?? 'off', placeholder: placeholder, disabled: disabledArea, readOnly: readOnly, maxLength: maxLength, rows: rowsMin, style: { resize }, onFocus: onFocusArea, onBlur: onBlurArea, onChange: onChangeArea, onKeyDown: onKeyDownArea, onKeyUp: onKeyUpArea, value: valueArea }), jsxRuntimeExports.jsx("span", { className: "rls-area-text__value", "aria-hidden": "true", children: valueArea })] }));
|
|
545
585
|
}
|
|
546
586
|
const RlsAreaText = memo(RlsAreaTextComponent);
|
|
547
587
|
|
|
@@ -648,8 +688,11 @@ function RlsCheckBoxControlComponent({ formControl, disabled, identifier, rlsThe
|
|
|
648
688
|
}
|
|
649
689
|
const RlsCheckBoxControl = memo(RlsCheckBoxControlComponent);
|
|
650
690
|
|
|
651
|
-
function RlsSkeletonComponent({ rlsTheme }) {
|
|
652
|
-
|
|
691
|
+
function RlsSkeletonComponent({ animation, rlsTheme }) {
|
|
692
|
+
const className = renderClassStatus('rls-skeleton', {
|
|
693
|
+
animation: animation !== 'shimmer' && animation
|
|
694
|
+
});
|
|
695
|
+
return jsxRuntimeExports.jsx("div", { className: className, "rls-theme": rlsTheme });
|
|
653
696
|
}
|
|
654
697
|
const RlsSkeleton = memo(RlsSkeletonComponent);
|
|
655
698
|
|
|
@@ -1258,8 +1301,8 @@ function RlsRadioButtonComponent({ checked, disabled, identifier, rlsTheme, onCl
|
|
|
1258
1301
|
}
|
|
1259
1302
|
const RlsRadioButton = memo(RlsRadioButtonComponent);
|
|
1260
1303
|
|
|
1261
|
-
function RlsSkeletonTextComponent({ active, children, rlsTheme }) {
|
|
1262
|
-
return (jsxRuntimeExports.jsx("div", { className: "rls-skeleton-text", "rls-theme": rlsTheme, children: active ? (jsxRuntimeExports.jsx(RlsSkeleton, {})) : (jsxRuntimeExports.jsx("div", { className: "rls-skeleton-text__value", children: children })) }));
|
|
1304
|
+
function RlsSkeletonTextComponent({ active, animation, children, rlsTheme }) {
|
|
1305
|
+
return (jsxRuntimeExports.jsx("div", { className: "rls-skeleton-text", "rls-theme": rlsTheme, children: active ? (jsxRuntimeExports.jsx(RlsSkeleton, { animation: animation })) : (jsxRuntimeExports.jsx("div", { className: "rls-skeleton-text__value", children: children })) }));
|
|
1263
1306
|
}
|
|
1264
1307
|
const RlsSkeletonText = memo(RlsSkeletonTextComponent);
|
|
1265
1308
|
|
|
@@ -1548,17 +1591,31 @@ function RlsMessageFormErrorComponent({ className, formControl }) {
|
|
|
1548
1591
|
const RlsMessageFormError = memo(RlsMessageFormErrorComponent);
|
|
1549
1592
|
|
|
1550
1593
|
function RlsFieldAreaComponent(props) {
|
|
1551
|
-
const { children, formControl, identifier, rlsTheme } = props;
|
|
1594
|
+
const { children, formControl, identifier, maxLength, rlsTheme } = props;
|
|
1595
|
+
const { onValue } = props;
|
|
1552
1596
|
const disabled = useMemo(() => {
|
|
1553
1597
|
return formControl?.disabled || props.disabled;
|
|
1554
1598
|
}, [formControl?.disabled, props.disabled]);
|
|
1599
|
+
const valueSource = formControl?.value ?? props.value;
|
|
1600
|
+
const [valueLength, setValueLength] = useState(() => {
|
|
1601
|
+
return (valueSource ?? '').length;
|
|
1602
|
+
});
|
|
1603
|
+
useEffect(() => {
|
|
1604
|
+
if (valueSource !== undefined) {
|
|
1605
|
+
setValueLength(valueSource.length);
|
|
1606
|
+
}
|
|
1607
|
+
}, [valueSource]);
|
|
1608
|
+
const onValueArea = useCallback((value) => {
|
|
1609
|
+
setValueLength(value.length);
|
|
1610
|
+
onValue?.(value);
|
|
1611
|
+
}, [onValue]);
|
|
1555
1612
|
const className = renderClassStatus('rls-field-box', {
|
|
1556
1613
|
disabled,
|
|
1557
1614
|
error: formControl?.wrong,
|
|
1558
1615
|
focused: formControl?.focused && !disabled,
|
|
1559
1616
|
readonly: props.readOnly
|
|
1560
1617
|
}, 'rls-field-area');
|
|
1561
|
-
return (jsxRuntimeExports.jsxs("div", { id: identifier, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsx("div", { className: "rls-field-box__body", children: jsxRuntimeExports.jsx(RlsAreaText, { ...props }) }) }), !props.msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl }))] }));
|
|
1618
|
+
return (jsxRuntimeExports.jsxs("div", { id: identifier, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsx("div", { className: "rls-field-box__body", children: jsxRuntimeExports.jsx(RlsAreaText, { ...props, onValue: onValueArea }) }) }), props.counter && (jsxRuntimeExports.jsx("span", { className: "rls-field-box__helper rls-field-area__counter", children: maxLength ? `${valueLength} / ${maxLength}` : valueLength })), !props.msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl }))] }));
|
|
1562
1619
|
}
|
|
1563
1620
|
const RlsFieldArea = memo(RlsFieldAreaComponent);
|
|
1564
1621
|
|