@addev-be/ui 0.8.9 → 0.8.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@addev-be/ui",
3
- "version": "0.8.9",
3
+ "version": "0.8.12",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "watch": "tsc -b --watch",
@@ -91,6 +91,7 @@ export const FilterValuesScrollerContainer = styled.div.attrs({
91
91
 
92
92
  input[type='checkbox'] {
93
93
  margin-right: var(--space-1);
94
+ flex-shrink: 0;
94
95
  }
95
96
  }
96
97
  `;
@@ -0,0 +1,41 @@
1
+ import {
2
+ DetailedHTMLProps,
3
+ TextareaHTMLAttributes,
4
+ useEffect,
5
+ useState,
6
+ } from 'react';
7
+
8
+ type TextAreaProps = DetailedHTMLProps<
9
+ TextareaHTMLAttributes<HTMLTextAreaElement>,
10
+ HTMLTextAreaElement
11
+ >;
12
+ type AutoTextAreaProps = TextAreaProps & {
13
+ minRows?: number;
14
+ maxRows?: number;
15
+ canGrow?: boolean;
16
+ canShrink?: boolean;
17
+ };
18
+
19
+ export const AutoTextArea = ({
20
+ className,
21
+ canGrow = true,
22
+ canShrink = true,
23
+ minRows = 1,
24
+ maxRows = 10,
25
+ value,
26
+ ...props
27
+ }: AutoTextAreaProps) => {
28
+ const [rows, setRows] = useState(minRows);
29
+
30
+ useEffect(() => {
31
+ const linesCount = String(value).split('\n').length;
32
+ const rowsCount = Math.min(maxRows, Math.max(minRows, linesCount));
33
+ if ((canGrow && rowsCount > rows) || (canShrink && rowsCount < rows)) {
34
+ setRows(rowsCount);
35
+ }
36
+ }, [canGrow, canShrink, maxRows, minRows, rows, value]);
37
+
38
+ return (
39
+ <textarea {...props} className={className} rows={rows} value={value} />
40
+ );
41
+ };
@@ -1,3 +1,4 @@
1
+ export * from './AutoTextArea';
1
2
  export * from './Button';
2
3
  export * from './Select';
3
4
  export * from './IconButton';