@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 CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Rolster Technology
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Rolster Technology
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -484,20 +484,41 @@ function RlsAmountComponent({ value, className, decimals, rlsTheme, symbol }) {
484
484
  }
485
485
  const RlsAmount = require$$0.memo(RlsAmountComponent);
486
486
 
487
- function RlsAreaTextComponent({ autoComplete, disabled, formControl, identifier, onBlur, onEnter, onFocus, onKeyDown, onKeyUp, onValue, placeholder, readOnly, resize, rows = 1, value }) {
487
+ const AREA_TEXT_MAX_ROWS = 8;
488
+ const AREA_TEXT_MIN_ROWS = 3;
489
+ function RlsAreaTextComponent({ autoComplete, disabled, formControl, identifier, maxLength, maxRows, minRows, onBlur, onEnter, onFocus, onKeyDown, onKeyUp, onValue, placeholder, readOnly, resize = 'vertical', value }) {
488
490
  const valueInitial = String(formControl?.value ?? value ?? '');
491
+ const rowsMin = minRows ?? AREA_TEXT_MIN_ROWS;
492
+ const rowsMax = Math.max(maxRows ?? AREA_TEXT_MAX_ROWS, rowsMin);
489
493
  const [valueArea, setValueArea] = require$$0.useState(valueInitial);
490
494
  const [focused, setFocused] = require$$0.useState(false);
491
495
  const elementRef = require$$0.useRef(null);
492
496
  const areaRef = formControl?.elementRef ?? elementRef;
493
497
  const changeIsInternal = require$$0.useRef(false);
498
+ const heightIsManual = require$$0.useRef(false);
499
+ const heightApplied = require$$0.useRef(0);
494
500
  const refreshHeight = require$$0.useCallback(() => {
495
501
  const element = areaRef.current;
496
- if (element) {
497
- element.style.height = 'auto';
498
- element.style.height = `${element.scrollHeight}px`;
502
+ if (!element || heightIsManual.current) {
503
+ return;
504
+ }
505
+ element.style.height = 'auto';
506
+ const { lineHeight, paddingBottom, paddingTop } = getComputedStyle(element);
507
+ const heightLine = parseFloat(lineHeight);
508
+ const heightContent = element.scrollHeight;
509
+ if (!heightLine) {
510
+ element.style.height = `${heightContent}px`;
511
+ heightApplied.current = heightContent;
512
+ return;
499
513
  }
500
- }, [areaRef]);
514
+ const heightPadding = parseFloat(paddingTop) + parseFloat(paddingBottom);
515
+ const heightMin = heightLine * rowsMin + heightPadding;
516
+ const heightMax = heightLine * rowsMax + heightPadding;
517
+ const height = Math.min(Math.max(heightContent, heightMin), heightMax);
518
+ element.style.height = `${height}px`;
519
+ element.style.overflowY = heightContent > heightMax ? 'auto' : 'hidden';
520
+ heightApplied.current = height;
521
+ }, [areaRef, rowsMax, rowsMin]);
501
522
  require$$0.useEffect(() => {
502
523
  if (!changeIsInternal.current) {
503
524
  const nextValue = String(formControl?.value ?? value ?? '');
@@ -510,14 +531,31 @@ function RlsAreaTextComponent({ autoComplete, disabled, formControl, identifier,
510
531
  require$$0.useEffect(() => {
511
532
  refreshHeight();
512
533
  }, [refreshHeight, valueArea]);
534
+ require$$0.useEffect(() => {
535
+ const element = areaRef.current;
536
+ if (!element ||
537
+ resize === 'none' ||
538
+ typeof ResizeObserver === 'undefined') {
539
+ return;
540
+ }
541
+ const observer = new ResizeObserver(() => {
542
+ if (heightIsManual.current || !heightApplied.current) {
543
+ return;
544
+ }
545
+ if (Math.abs(element.offsetHeight - heightApplied.current) > 1) {
546
+ heightIsManual.current = true;
547
+ element.style.overflowY = 'auto';
548
+ }
549
+ });
550
+ observer.observe(element);
551
+ return () => observer.disconnect();
552
+ }, [areaRef, resize]);
513
553
  const onChangeArea = require$$0.useCallback((event) => {
514
554
  const nextValue = event.target.value;
515
555
  changeIsInternal.current = true;
516
556
  onValue?.(nextValue);
517
557
  setValueArea(nextValue);
518
558
  formControl?.setValue(nextValue);
519
- event.target.style.height = 'auto';
520
- event.target.style.height = `${event.target.scrollHeight}px`;
521
559
  }, [formControl, onValue]);
522
560
  const onKeyDownArea = require$$0.useCallback((event) => {
523
561
  onKeyDown?.(event);
@@ -538,12 +576,14 @@ function RlsAreaTextComponent({ autoComplete, disabled, formControl, identifier,
538
576
  setFocused(() => false);
539
577
  onBlur?.();
540
578
  }, [formControl, onBlur]);
579
+ const disabledArea = formControl?.disabled || disabled;
541
580
  const className = renderClassStatus('rls-area-text', {
542
- disabled: formControl?.disabled || disabled,
581
+ disabled: disabledArea,
543
582
  focused: formControl?.focused ?? focused,
544
- readonly: readOnly
583
+ readonly: readOnly,
584
+ resizable: resize !== 'none' && !disabledArea && !readOnly
545
585
  });
546
- 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: formControl?.disabled || disabled, readOnly: readOnly, rows: rows, style: { resize }, onFocus: onFocusArea, onBlur: onBlurArea, onChange: onChangeArea, onKeyDown: onKeyDownArea, onKeyUp: onKeyUpArea, value: valueArea }), jsxRuntimeExports.jsx("span", { className: "rls-area-text__value", children: valueArea })] }));
586
+ 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 })] }));
547
587
  }
548
588
  const RlsAreaText = require$$0.memo(RlsAreaTextComponent);
549
589
 
@@ -650,8 +690,11 @@ function RlsCheckBoxControlComponent({ formControl, disabled, identifier, rlsThe
650
690
  }
651
691
  const RlsCheckBoxControl = require$$0.memo(RlsCheckBoxControlComponent);
652
692
 
653
- function RlsSkeletonComponent({ rlsTheme }) {
654
- return jsxRuntimeExports.jsx("div", { className: "rls-skeleton", "rls-theme": rlsTheme });
693
+ function RlsSkeletonComponent({ animation, rlsTheme }) {
694
+ const className = renderClassStatus('rls-skeleton', {
695
+ animation: animation !== 'shimmer' && animation
696
+ });
697
+ return jsxRuntimeExports.jsx("div", { className: className, "rls-theme": rlsTheme });
655
698
  }
656
699
  const RlsSkeleton = require$$0.memo(RlsSkeletonComponent);
657
700
 
@@ -1260,8 +1303,8 @@ function RlsRadioButtonComponent({ checked, disabled, identifier, rlsTheme, onCl
1260
1303
  }
1261
1304
  const RlsRadioButton = require$$0.memo(RlsRadioButtonComponent);
1262
1305
 
1263
- function RlsSkeletonTextComponent({ active, children, rlsTheme }) {
1264
- 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 })) }));
1306
+ function RlsSkeletonTextComponent({ active, animation, children, rlsTheme }) {
1307
+ 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 })) }));
1265
1308
  }
1266
1309
  const RlsSkeletonText = require$$0.memo(RlsSkeletonTextComponent);
1267
1310
 
@@ -1550,17 +1593,31 @@ function RlsMessageFormErrorComponent({ className, formControl }) {
1550
1593
  const RlsMessageFormError = require$$0.memo(RlsMessageFormErrorComponent);
1551
1594
 
1552
1595
  function RlsFieldAreaComponent(props) {
1553
- const { children, formControl, identifier, rlsTheme } = props;
1596
+ const { children, formControl, identifier, maxLength, rlsTheme } = props;
1597
+ const { onValue } = props;
1554
1598
  const disabled = require$$0.useMemo(() => {
1555
1599
  return formControl?.disabled || props.disabled;
1556
1600
  }, [formControl?.disabled, props.disabled]);
1601
+ const valueSource = formControl?.value ?? props.value;
1602
+ const [valueLength, setValueLength] = require$$0.useState(() => {
1603
+ return (valueSource ?? '').length;
1604
+ });
1605
+ require$$0.useEffect(() => {
1606
+ if (valueSource !== undefined) {
1607
+ setValueLength(valueSource.length);
1608
+ }
1609
+ }, [valueSource]);
1610
+ const onValueArea = require$$0.useCallback((value) => {
1611
+ setValueLength(value.length);
1612
+ onValue?.(value);
1613
+ }, [onValue]);
1557
1614
  const className = renderClassStatus('rls-field-box', {
1558
1615
  disabled,
1559
1616
  error: formControl?.wrong,
1560
1617
  focused: formControl?.focused && !disabled,
1561
1618
  readonly: props.readOnly
1562
1619
  }, 'rls-field-area');
1563
- 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 }))] }));
1620
+ 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 }))] }));
1564
1621
  }
1565
1622
  const RlsFieldArea = require$$0.memo(RlsFieldAreaComponent);
1566
1623