@devtron-labs/devtron-fe-common-lib 0.0.18-beta-2 → 0.0.18-beta-6

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>;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import './Toggle.scss';
3
- declare const Toggle: ({ selected, onSelect, color, rootClassName, disabled, dataTestId, Icon, iconClass, ...props }: {
3
+ declare const Toggle: ({ selected, onSelect, color, rootClassName, disabled, dataTestId, ...props }: {
4
4
  [x: string]: any;
5
5
  selected?: boolean;
6
6
  onSelect?: any;
@@ -8,7 +8,5 @@ declare const Toggle: ({ selected, onSelect, color, rootClassName, disabled, dat
8
8
  rootClassName?: string;
9
9
  disabled?: boolean;
10
10
  dataTestId?: string;
11
- Icon?: any;
12
- iconClass?: string;
13
11
  }) => JSX.Element;
14
12
  export default Toggle;
@@ -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
@@ -22675,13 +22675,13 @@ var Checkbox = /** @class */ (function (_super) {
22675
22675
  return Checkbox;
22676
22676
  }(React.Component));
22677
22677
 
22678
- var css_248z$2 = ".toggle__switch {\n position: relative;\n display: inline-block;\n width: 100%;\n height: 100%;\n}\n.toggle__switch.disabled {\n cursor: not-allowed;\n}\n.toggle__switch.disabled .toggle__slider {\n cursor: not-allowed;\n}\n\n/* Hide default HTML checkbox */\n.toggle__switch input {\n opacity: 0;\n width: 0;\n height: 0;\n}\n\n/* The slider */\n.toggle__slider {\n position: absolute;\n cursor: pointer;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background-color: #ccc;\n transition: all 0.4s ease;\n}\n.toggle__slider.round {\n border-radius: 34px;\n}\n.toggle__slider.round:before {\n border-radius: 50%;\n}\n.toggle__slider:before {\n position: absolute;\n content: \"\";\n height: calc(100% - 8px);\n width: calc(50% - 4px);\n left: 4px;\n bottom: 4px;\n background-color: white;\n transition: all 0.4s ease;\n}\n.toggle__slider.with-icon {\n background-color: var(--N000) !important;\n}\n.toggle__slider.with-icon svg {\n position: absolute;\n content: \"\";\n top: -1px;\n left: -1px;\n background-color: var(--N300);\n transition: all 0.4s ease;\n}\n\ninput:checked + .toggle__slider {\n background-color: var(--color);\n}\ninput:checked + .toggle__slider:before {\n transform: translateX(100%);\n}\ninput:checked + .toggle__slider.with-icon svg {\n transform: translateX(100%);\n background-color: var(--color);\n}\n\ninput:focus + .toggle__slider {\n box-shadow: 0 0 1px var(--color);\n}";
22678
+ var css_248z$2 = ".toggle__switch {\n position: relative;\n display: inline-block;\n width: 100%;\n height: 100%;\n}\n.toggle__switch.disabled {\n cursor: not-allowed;\n}\n.toggle__switch.disabled .toggle__slider {\n cursor: not-allowed;\n}\n\n/* Hide default HTML checkbox */\n.toggle__switch input {\n opacity: 0;\n width: 0;\n height: 0;\n}\n\n/* The slider */\n.toggle__slider {\n position: absolute;\n cursor: pointer;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background-color: #ccc;\n transition: all 0.4s ease;\n}\n\n.toggle__slider:before {\n position: absolute;\n content: \"\";\n height: calc(100% - 8px);\n width: calc(50% - 4px);\n left: 4px;\n bottom: 4px;\n background-color: white;\n transition: all 0.4s ease;\n}\n\ninput:checked + .toggle__slider {\n background-color: var(--color);\n}\n\ninput:focus + .toggle__slider {\n box-shadow: 0 0 1px var(--color);\n}\n\ninput:checked + .toggle__slider:before {\n transform: translateX(100%);\n}\n\n/* Rounded sliders */\n.toggle__slider.round {\n border-radius: 34px;\n}\n\n.toggle__slider.round:before {\n border-radius: 50%;\n}";
22679
22679
  styleInject(css_248z$2);
22680
22680
 
22681
22681
  var Toggle = function (_a) {
22682
22682
  var _b;
22683
- var _c = _a.selected, selected = _c === void 0 ? false : _c, _d = _a.onSelect, onSelect = _d === void 0 ? null : _d, _e = _a.color, color = _e === void 0 ? '#36b37e' : _e, _f = _a.rootClassName, rootClassName = _f === void 0 ? '' : _f, _g = _a.disabled, disabled = _g === void 0 ? false : _g, _h = _a.dataTestId, dataTestId = _h === void 0 ? 'handle-toggle-button' : _h, _j = _a.Icon, Icon = _j === void 0 ? null : _j, _k = _a.iconClass, iconClass = _k === void 0 ? '' : _k, props = __rest(_a, ["selected", "onSelect", "color", "rootClassName", "disabled", "dataTestId", "Icon", "iconClass"]);
22684
- var _l = __read(React.useState(selected), 2), active = _l[0], setActive = _l[1];
22683
+ var _c = _a.selected, selected = _c === void 0 ? false : _c, _d = _a.onSelect, onSelect = _d === void 0 ? null : _d, _e = _a.color, color = _e === void 0 ? "#36b37e" : _e, _f = _a.rootClassName, rootClassName = _f === void 0 ? "" : _f, _g = _a.disabled, disabled = _g === void 0 ? false : _g, _h = _a.dataTestId, dataTestId = _h === void 0 ? "handle-toggle-button" : _h, props = __rest(_a, ["selected", "onSelect", "color", "rootClassName", "disabled", "dataTestId"]);
22684
+ var _j = __read(React.useState(selected), 2), active = _j[0], setActive = _j[1];
22685
22685
  useEffectAfterMount(function () {
22686
22686
  if (typeof onSelect === 'function') {
22687
22687
  if (active !== selected) {
@@ -22697,7 +22697,7 @@ var Toggle = function (_a) {
22697
22697
  setActive(function (active) { return !active; });
22698
22698
  }
22699
22699
  }
22700
- return (jsxRuntime.jsxs("label", __assign({}, props, { className: "".concat(rootClassName, " toggle__switch ").concat(disabled ? 'disabled' : ''), style: (_b = {}, _b['--color'] = color, _b) }, { children: [jsxRuntime.jsx("input", { type: "checkbox", checked: !!active, onChange: handleClick, className: "toggle__input" }), jsxRuntime.jsx("span", __assign({ className: "toggle__slider ".concat(Icon ? 'with-icon br-4 dc__border' : 'round'), "data-testid": dataTestId }, { children: Icon && jsxRuntime.jsx(Icon, { className: "icon-dim-20 br-4 p-2 ".concat(iconClass) }) }))] })));
22700
+ return (jsxRuntime.jsxs("label", __assign({}, props, { className: "".concat(rootClassName, " toggle__switch ").concat(disabled ? 'disabled' : ''), style: (_b = {}, _b['--color'] = color, _b) }, { children: [jsxRuntime.jsx("input", { type: "checkbox", checked: !!active, onChange: handleClick, className: "toggle__input" }), jsxRuntime.jsx("span", { className: "toggle__slider round", "data-testid": dataTestId })] })));
22701
22701
  };
22702
22702
 
22703
22703
  var css_248z$1 = ".modal-body--scan-details {\n position: fixed;\n top: 0;\n right: 0;\n background: var(--N000);\n width: 800px;\n}\n\n.security-tab__table {\n width: 100%;\n}\n\n.security-tab__table-header {\n border-bottom: solid 1px var(--N200);\n}\n\n.security-cell-header {\n font-size: 12px;\n font-weight: 600;\n line-height: 1.5;\n letter-spacing: normal;\n text-transform: uppercase;\n color: var(--N500);\n}\n\n.dc__security-tab__table-row {\n font-size: 13px;\n font-weight: normal;\n line-height: 1.54;\n letter-spacing: normal;\n color: var(--N900);\n box-shadow: inset 0 -1px 0 0 #f5f5f5;\n}\n\n.security-tab__cell-cve,\n.security-tab__cell-severity,\n.security-tab__cell-package,\n.security-tab__cell-current-ver,\n.security-tab__cell-fixed-ver,\n.security-tab__cell-policy {\n padding: 10px;\n}\n\n.security-tab__cell-cve {\n padding-left: 0px;\n text-align: left;\n width: 20%;\n}\n\n.security-tab__cell-policy {\n padding-right: 0px;\n}\n\n.security-tab__cell-policy--whitelist,\n.security-tab__cell-policy--whitelisted {\n color: var(--G500);\n text-transform: capitalize;\n}\n\n.security-tab__cell-policy--block {\n color: var(--R500);\n text-transform: capitalize;\n}\n\n.scanned-object__results {\n margin: 0 20px;\n}";
@@ -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-beta-2",
3
+ "version": "0.0.18-beta-6",
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
+ }
@@ -4,14 +4,15 @@
4
4
  width: 100%;
5
5
  height: 100%;
6
6
 
7
- &.disabled {
7
+ &.disabled{
8
8
  cursor: not-allowed;
9
- .toggle__slider {
9
+ .toggle__slider{
10
10
  cursor: not-allowed;
11
11
  }
12
12
  }
13
13
  }
14
14
 
15
+
15
16
  /* Hide default HTML checkbox */
16
17
 
17
18
  .toggle__switch input {
@@ -20,6 +21,7 @@
20
21
  height: 0;
21
22
  }
22
23
 
24
+
23
25
  /* The slider */
24
26
 
25
27
  .toggle__slider {
@@ -30,49 +32,39 @@
30
32
  right: 0;
31
33
  bottom: 0;
32
34
  background-color: #ccc;
35
+ transition: all .4s ease;
36
+ }
37
+
38
+ .toggle__slider:before {
39
+ position: absolute;
40
+ content: "";
41
+ height: calc( 100% - 8px);
42
+ width: calc( 50% - 4px);
43
+ left: 4px;
44
+ bottom: 4px;
45
+ background-color: white;
33
46
  transition: all 0.4s ease;
34
- &.round {
35
- border-radius: 34px;
36
- &:before {
37
- border-radius: 50%;
38
- }
39
- }
40
- &:before {
41
- position: absolute;
42
- content: '';
43
- height: calc(100% - 8px);
44
- width: calc(50% - 4px);
45
- left: 4px;
46
- bottom: 4px;
47
- background-color: white;
48
- transition: all 0.4s ease;
49
- }
50
- &.with-icon {
51
- background-color: var(--N000) !important;
52
- svg {
53
- position: absolute;
54
- content: '';
55
- top: -1px;
56
- left: -1px;
57
- background-color: var(--N300);
58
- transition: all 0.4s ease;
59
- }
60
- }
61
47
  }
62
48
 
63
- input:checked + .toggle__slider {
49
+ input:checked+.toggle__slider {
64
50
  background-color: var(--color);
65
- &:before {
66
- transform: translateX(calc(100%));
67
- }
68
- &.with-icon {
69
- svg {
70
- transform: translateX(calc(100%));
71
- background-color: var(--color);
72
- }
73
- }
74
51
  }
75
52
 
76
- input:focus + .toggle__slider {
53
+ input:focus+.toggle__slider {
77
54
  box-shadow: 0 0 1px var(--color);
78
55
  }
56
+
57
+ input:checked+.toggle__slider:before {
58
+ transform: translateX(calc( 100%));
59
+ }
60
+
61
+
62
+ /* Rounded sliders */
63
+
64
+ .toggle__slider.round {
65
+ border-radius: 34px;
66
+ }
67
+
68
+ .toggle__slider.round:before {
69
+ border-radius: 50%;
70
+ }
@@ -1,35 +1,25 @@
1
- import React from 'react'
2
- import { useEffectAfterMount } from '../Helper'
1
+ import React from 'react';
2
+ import { useEffectAfterMount } from '../Helper';
3
3
  import './Toggle.scss'
4
4
 
5
- const Toggle = ({
6
- selected = false,
7
- onSelect = null,
8
- color = '#36b37e',
9
- rootClassName = '',
10
- disabled = false,
11
- dataTestId = 'handle-toggle-button',
12
- Icon = null,
13
- iconClass= '',
14
- ...props
15
- }) => {
16
- const [active, setActive] = React.useState(selected)
5
+ const Toggle = ({selected=false, onSelect=null, color="#36b37e", rootClassName="", disabled=false, dataTestId="handle-toggle-button", ...props})=>{
6
+ const [active, setActive] = React.useState(selected);
17
7
 
18
- useEffectAfterMount(() => {
19
- if (typeof onSelect === 'function') {
20
- if (active !== selected) {
8
+ useEffectAfterMount(()=>{
9
+ if(typeof onSelect === 'function'){
10
+ if(active !== selected){
21
11
  onSelect(active)
22
12
  }
23
13
  }
24
- }, [active])
14
+ },[active])
25
15
 
26
16
  useEffectAfterMount(() => {
27
17
  setActive(selected)
28
18
  }, [selected])
29
19
 
30
- function handleClick(e) {
31
- if (!disabled) {
32
- setActive((active) => !active)
20
+ function handleClick(e){
21
+ if(!disabled){
22
+ setActive(active=>!active)
33
23
  }
34
24
  }
35
25
 
@@ -40,11 +30,9 @@ const Toggle = ({
40
30
  style={{ ['--color' as any]: color }}
41
31
  >
42
32
  <input type="checkbox" checked={!!active} onChange={handleClick} className="toggle__input" />
43
- <span className={`toggle__slider ${Icon ? 'with-icon br-4 dc__border' : 'round'}`} data-testid={dataTestId}>
44
- {Icon && <Icon className={`icon-dim-20 br-4 p-2 ${iconClass}`} />}
45
- </span>
33
+ <span className="toggle__slider round" data-testid={dataTestId}></span>
46
34
  </label>
47
35
  )
48
36
  }
49
37
 
50
- export default Toggle
38
+ export default Toggle
@@ -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'