@devtron-labs/devtron-fe-common-lib 0.0.18 → 0.0.19

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.
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import { ResizableTextareaProps } from './Types';
3
+ export declare const ResizableTextarea: React.FC<ResizableTextareaProps>;
@@ -338,4 +338,19 @@ export interface UseSearchString {
338
338
  [key: string]: string;
339
339
  };
340
340
  }
341
+ export interface ResizableTextareaProps {
342
+ minHeight?: number;
343
+ maxHeight?: number;
344
+ value?: string;
345
+ onChange?: (e: any) => void;
346
+ onBlur?: (e: any) => void;
347
+ onFocus?: (e: any) => void;
348
+ className?: string;
349
+ placeholder?: string;
350
+ lineHeight?: number;
351
+ padding?: number;
352
+ disabled?: boolean;
353
+ name?: string;
354
+ dataTestId?: string;
355
+ }
341
356
  export {};
@@ -34,3 +34,4 @@ export * from './Policy.Types';
34
34
  export { default as DeleteComponent } from './DeleteComponentModal/DeleteComponent';
35
35
  export * from './ImageTags';
36
36
  export * from './ImageTags.Types';
37
+ export * from './ResizableTextarea';
package/dist/index.js CHANGED
@@ -23307,6 +23307,41 @@ var AddImageButton = function (_a) {
23307
23307
  return (jsxRuntime.jsx("div", __assign({ className: "add-tag-button flex pt-12 pr-12", "data-testid": "add-tags-button", onClick: handleClick }, { children: jsxRuntime.jsxs("div", __assign({ className: "lh-16 flex" }, { children: [jsxRuntime.jsx(SvgIcAdd, { className: "icon-dim-16 cn-6" }), jsxRuntime.jsx("span", __assign({ className: "cn-7" }, { children: "Add tags/comment" }))] })) })));
23308
23308
  };
23309
23309
 
23310
+ var ResizableTextarea = function (_a) {
23311
+ var minHeight = _a.minHeight, maxHeight = _a.maxHeight, value = _a.value, _b = _a.onChange, onChange = _b === void 0 ? null : _b, _c = _a.onBlur, onBlur = _c === void 0 ? null : _c, _d = _a.onFocus, onFocus = _d === void 0 ? null : _d, _e = _a.className, className = _e === void 0 ? '' : _e, _f = _a.placeholder, placeholder = _f === void 0 ? 'Enter your text here..' : _f, _g = _a.lineHeight, lineHeight = _g === void 0 ? 14 : _g, _h = _a.padding, padding = _h === void 0 ? 12 : _h, _j = _a.disabled, disabled = _j === void 0 ? false : _j, dataTestId = _a.dataTestId, props = __rest(_a, ["minHeight", "maxHeight", "value", "onChange", "onBlur", "onFocus", "className", "placeholder", "lineHeight", "padding", "disabled", "dataTestId"]);
23312
+ var _k = __read(React.useState(''), 2), text = _k[0], setText = _k[1];
23313
+ var _textRef = React.useRef(null);
23314
+ React.useEffect(function () {
23315
+ setText(value);
23316
+ }, [value]);
23317
+ function handleChange(e) {
23318
+ e.persist();
23319
+ setText(e.target.value);
23320
+ if (typeof onChange === 'function')
23321
+ onChange(e);
23322
+ }
23323
+ function handleBlur(e) {
23324
+ if (typeof onBlur === 'function')
23325
+ onBlur(e);
23326
+ }
23327
+ function handleFocus(e) {
23328
+ if (typeof onFocus === 'function')
23329
+ onFocus(e);
23330
+ }
23331
+ useThrottledEffect(function () {
23332
+ _textRef.current.style.height = 'auto';
23333
+ var nextHeight = _textRef.current.scrollHeight;
23334
+ if (minHeight && nextHeight < minHeight) {
23335
+ nextHeight = minHeight;
23336
+ }
23337
+ if (maxHeight && nextHeight > maxHeight) {
23338
+ nextHeight = maxHeight;
23339
+ }
23340
+ _textRef.current.style.height = nextHeight + 2 + 'px';
23341
+ }, 500, [text]);
23342
+ return (jsxRuntime.jsx("textarea", __assign({ "data-testid": dataTestId, ref: function (el) { return (_textRef.current = el); }, value: text, placeholder: placeholder, className: "dc__resizable-textarea ".concat(className), onChange: handleChange, onBlur: handleBlur, onFocus: handleFocus, style: { lineHeight: "".concat(lineHeight, "px"), padding: "".concat(padding, "px") }, spellCheck: false, disabled: disabled }, props)));
23343
+ };
23344
+
23310
23345
  exports.BreadCrumb = BreadCrumb;
23311
23346
  exports.BreadcrumbStore = Store;
23312
23347
  exports.BuildStageVariable = BuildStageVariable;
@@ -23353,6 +23388,7 @@ exports.RadioGroupItem = RadioGroupItem;
23353
23388
  exports.Reload = Reload;
23354
23389
  exports.RequestTimeout = RequestTimeout;
23355
23390
  exports.ResizableTagTextArea = ResizableTagTextArea;
23391
+ exports.ResizableTextarea = ResizableTextarea;
23356
23392
  exports.ScanVulnerabilitiesTable = ScanVulnerabilitiesTable;
23357
23393
  exports.ServerError = ServerError;
23358
23394
  exports.ServerErrors = ServerErrors;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devtron-labs/devtron-fe-common-lib",
3
- "version": "0.0.18",
3
+ "version": "0.0.19",
4
4
  "description": "Supporting common component library",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -0,0 +1,73 @@
1
+ import React, { useState, useEffect, useRef } from 'react'
2
+ import { useThrottledEffect } from './Helper'
3
+ import { ResizableTextareaProps } from './Types'
4
+
5
+ export const ResizableTextarea: React.FC<ResizableTextareaProps> = ({
6
+ minHeight,
7
+ maxHeight,
8
+ value,
9
+ onChange = null,
10
+ onBlur = null,
11
+ onFocus = null,
12
+ className = '',
13
+ placeholder = 'Enter your text here..',
14
+ lineHeight = 14,
15
+ padding = 12,
16
+ disabled = false,
17
+ dataTestId,
18
+ ...props
19
+ }) => {
20
+ const [text, setText] = useState('')
21
+ const _textRef = useRef(null)
22
+
23
+ useEffect(() => {
24
+ setText(value)
25
+ }, [value])
26
+
27
+ function handleChange(e) {
28
+ e.persist()
29
+ setText(e.target.value)
30
+ if (typeof onChange === 'function') onChange(e)
31
+ }
32
+
33
+ function handleBlur(e) {
34
+ if (typeof onBlur === 'function') onBlur(e)
35
+ }
36
+
37
+ function handleFocus(e) {
38
+ if (typeof onFocus === 'function') onFocus(e)
39
+ }
40
+
41
+ useThrottledEffect(
42
+ () => {
43
+ _textRef.current.style.height = 'auto'
44
+ let nextHeight = _textRef.current.scrollHeight
45
+ if (minHeight && nextHeight < minHeight) {
46
+ nextHeight = minHeight
47
+ }
48
+ if (maxHeight && nextHeight > maxHeight) {
49
+ nextHeight = maxHeight
50
+ }
51
+ _textRef.current.style.height = nextHeight + 2 + 'px'
52
+ },
53
+ 500,
54
+ [text],
55
+ )
56
+
57
+ return (
58
+ <textarea
59
+ data-testid={dataTestId}
60
+ ref={(el) => (_textRef.current = el)}
61
+ value={text}
62
+ placeholder={placeholder}
63
+ className={`dc__resizable-textarea ${className}`}
64
+ onChange={handleChange}
65
+ onBlur={handleBlur}
66
+ onFocus={handleFocus}
67
+ style={{ lineHeight: `${lineHeight}px`, padding: `${padding}px` }}
68
+ spellCheck={false}
69
+ disabled={disabled}
70
+ {...props}
71
+ />
72
+ )
73
+ }
@@ -371,4 +371,20 @@ export interface UseSearchString {
371
371
  searchParams: {
372
372
  [key: string]: string
373
373
  }
374
+ }
375
+
376
+ export interface ResizableTextareaProps {
377
+ minHeight?: number
378
+ maxHeight?: number
379
+ value?: string
380
+ onChange?: (e) => void
381
+ onBlur?: (e) => void
382
+ onFocus?: (e) => void
383
+ className?: string
384
+ placeholder?: string
385
+ lineHeight?: number
386
+ padding?: number
387
+ disabled?: boolean
388
+ name?: string
389
+ dataTestId?: string
374
390
  }
@@ -34,3 +34,4 @@ export * from './Policy.Types'
34
34
  export { default as DeleteComponent } from './DeleteComponentModal/DeleteComponent'
35
35
  export * from './ImageTags'
36
36
  export * from './ImageTags.Types'
37
+ export * from './ResizableTextarea'