@devtron-labs/devtron-fe-common-lib 0.0.44 → 0.0.45-beta-1

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.
@@ -1,6 +1,6 @@
1
1
  import * as Sentry from '@sentry/browser';
2
2
  import React from 'react';
3
- import { AsyncOptions, UseSearchString } from './Types';
3
+ import { AsyncOptions, CustomInputProps, UseSearchString } from './Types';
4
4
  export declare function showError(serverError: any, showToastOnUnknownError?: boolean, hideAccessError?: boolean): void;
5
5
  interface ConditionalWrapper<T> {
6
6
  condition: boolean;
@@ -12,7 +12,7 @@ export declare function sortCallback(key: string, a: any, b: any, isCaseSensitiv
12
12
  export declare const stopPropagation: (event: any) => void;
13
13
  export declare function useThrottledEffect(callback: any, delay: any, deps?: any[]): void;
14
14
  export declare function getRandomColor(email: string): string;
15
- export declare const getAlphabetIcon: (str: string) => JSX.Element;
15
+ export declare const getAlphabetIcon: (str: string, rootClassName?: string) => JSX.Element;
16
16
  export declare const getEmptyArrayOfLength: (length: number) => unknown[];
17
17
  export declare function noop(...args: any[]): any;
18
18
  export declare function not(e: any): boolean;
@@ -25,22 +25,7 @@ export declare function useForm(stateSchema: any, validationSchema: {}, callback
25
25
  handleOnChange: (event: any) => void;
26
26
  handleOnSubmit: (event: any) => void;
27
27
  };
28
- export declare function CustomInput({ name, value, error, onChange, onBlur, onFocus, label, type, disabled, autoComplete, labelClassName, placeholder, tabIndex, dataTestid, }: {
29
- name: any;
30
- value: any;
31
- error: any;
32
- onChange: any;
33
- onBlur?: (e: any) => void;
34
- onFocus?: (e: any) => void;
35
- label: any;
36
- type?: string;
37
- disabled?: boolean;
38
- autoComplete?: string;
39
- labelClassName?: string;
40
- placeholder?: string;
41
- tabIndex?: number;
42
- dataTestid?: string;
43
- }): JSX.Element;
28
+ export declare function CustomInput({ name, value, error, onChange, onBlur, onFocus, label, type, disabled, labelClassName, placeholder, tabIndex, dataTestid, isRequiredField, autoFocus, rootClassName, }: CustomInputProps): JSX.Element;
44
29
  export declare function handleUTCTime(ts: string, isRelativeTime?: boolean): string;
45
30
  export declare function useSearchString(): UseSearchString;
46
31
  export declare const closeOnEscKeyPressed: (e: any, actionClose: () => void) => void;
@@ -563,4 +563,22 @@ export interface CiPipeline {
563
563
  isOffendingMandatoryPlugin?: boolean;
564
564
  pipelineType?: string;
565
565
  }
566
+ export interface CustomInputProps {
567
+ name: string;
568
+ value: string;
569
+ error?: React.ReactNode;
570
+ onChange: (e: any) => void;
571
+ onBlur?: (e: any) => void;
572
+ onFocus?: (e: any) => void;
573
+ label?: React.ReactNode;
574
+ type?: string;
575
+ disabled?: boolean;
576
+ labelClassName?: string;
577
+ placeholder?: string;
578
+ tabIndex?: number;
579
+ dataTestid?: string;
580
+ isRequiredField?: boolean;
581
+ autoFocus?: boolean;
582
+ rootClassName?: string;
583
+ }
566
584
  export {};
package/dist/index.js CHANGED
@@ -9956,10 +9956,11 @@ function getRandomColor(email) {
9956
9956
  }
9957
9957
  return colors$1[sum % colors$1.length];
9958
9958
  }
9959
- var getAlphabetIcon = function (str) {
9959
+ var getAlphabetIcon = function (str, rootClassName) {
9960
+ if (rootClassName === void 0) { rootClassName = ""; }
9960
9961
  if (!str)
9961
9962
  return null;
9962
- return (jsxRuntime.jsx("span", __assign({ className: "alphabet-icon__initial fs-13 icon-dim-20 flex cn-0 mr-8", style: { backgroundColor: getRandomColor(str) } }, { children: str[0] })));
9963
+ return (jsxRuntime.jsx("span", __assign({ className: "".concat(rootClassName, " alphabet-icon__initial fs-13 icon-dim-20 flex cn-0 mr-8"), style: { backgroundColor: getRandomColor(str) } }, { children: str[0] })));
9963
9964
  };
9964
9965
  var getEmptyArrayOfLength = function (length) {
9965
9966
  return Array.from({ length: length });
@@ -10095,11 +10096,11 @@ function handleError(error) {
10095
10096
  return error;
10096
10097
  }
10097
10098
  function CustomInput(_a) {
10098
- var name = _a.name, value = _a.value, error = _a.error, onChange = _a.onChange, _b = _a.onBlur, onBlur = _b === void 0 ? function (e) { } : _b, _c = _a.onFocus, onFocus = _c === void 0 ? function (e) { } : _c, label = _a.label, _d = _a.type, type = _d === void 0 ? 'text' : _d, _e = _a.disabled, disabled = _e === void 0 ? false : _e; _a.autoComplete; var _g = _a.labelClassName, labelClassName = _g === void 0 ? '' : _g, _h = _a.placeholder, placeholder = _h === void 0 ? '' : _h, _j = _a.tabIndex, tabIndex = _j === void 0 ? 1 : _j, _k = _a.dataTestid, dataTestid = _k === void 0 ? '' : _k;
10099
- return (jsxRuntime.jsxs("div", __assign({ className: "flex column left top" }, { children: [jsxRuntime.jsx("label", __assign({ className: "form__label ".concat(labelClassName) }, { children: label })), jsxRuntime.jsx("input", { "data-testid": dataTestid, type: type, name: name, autoComplete: "off", className: "form__input", onChange: function (e) {
10099
+ var name = _a.name, value = _a.value, error = _a.error, onChange = _a.onChange, _b = _a.onBlur, onBlur = _b === void 0 ? function (e) { } : _b, _c = _a.onFocus, onFocus = _c === void 0 ? function (e) { } : _c, label = _a.label, _d = _a.type, type = _d === void 0 ? 'text' : _d, _e = _a.disabled, disabled = _e === void 0 ? false : _e, _f = _a.labelClassName, labelClassName = _f === void 0 ? '' : _f, _g = _a.placeholder, placeholder = _g === void 0 ? '' : _g, _h = _a.tabIndex, tabIndex = _h === void 0 ? 1 : _h, _j = _a.dataTestid, dataTestid = _j === void 0 ? '' : _j, _k = _a.isRequiredField, isRequiredField = _k === void 0 ? false : _k, _l = _a.autoFocus, autoFocus = _l === void 0 ? true : _l, _m = _a.rootClassName, rootClassName = _m === void 0 ? '' : _m;
10100
+ return (jsxRuntime.jsxs("div", __assign({ className: "flex column left top" }, { children: [label ? (jsxRuntime.jsx("label", __assign({ className: "form__label ".concat(labelClassName, " ").concat(isRequiredField ? 'dc__required-field' : '') }, { children: label }))) : (''), jsxRuntime.jsx("input", { "data-testid": dataTestid, type: type, name: name, autoComplete: "off", className: "form__input ".concat(rootClassName), onChange: function (e) {
10100
10101
  e.persist();
10101
10102
  onChange(e);
10102
- }, onBlur: onBlur, onFocus: onFocus, placeholder: placeholder, value: value, disabled: disabled, tabIndex: tabIndex }), handleError(error).map(function (err) { return (jsxRuntime.jsxs("div", __assign({ className: "form__error" }, { children: [jsxRuntime.jsx(SvgIcWarning, { className: "form__icon form__icon--error" }), err] }), err)); })] })));
10103
+ }, onBlur: onBlur, onFocus: onFocus, placeholder: placeholder, value: value, disabled: disabled, tabIndex: tabIndex, autoFocus: autoFocus }), handleError(error).map(function (err) { return (jsxRuntime.jsxs("div", __assign({ className: "form__error" }, { children: [jsxRuntime.jsx(SvgIcWarning, { className: "form__icon form__icon--error" }), err] }), err)); })] })));
10103
10104
  }
10104
10105
  function handleUTCTime(ts, isRelativeTime) {
10105
10106
  if (isRelativeTime === void 0) { isRelativeTime = false; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devtron-labs/devtron-fe-common-lib",
3
- "version": "0.0.44",
3
+ "version": "0.0.45-beta-1",
4
4
  "description": "Supporting common component library",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -7,7 +7,7 @@ import { ReactComponent as FormError } from '../Assets/Icon/ic-warning.svg'
7
7
  import { ERROR_EMPTY_SCREEN, TOKEN_COOKIE_NAME } from './Constants'
8
8
  import { ServerErrors } from './ServerError'
9
9
  import { toastAccessDenied } from './ToastBody'
10
- import { AsyncOptions, AsyncState, UseSearchString } from './Types'
10
+ import { AsyncOptions, AsyncState, CustomInputProps, UseSearchString } from './Types'
11
11
 
12
12
  toast.configure({
13
13
  autoClose: 3000,
@@ -116,11 +116,11 @@ export function getRandomColor(email: string): string {
116
116
  return colors[sum % colors.length]
117
117
  }
118
118
 
119
- export const getAlphabetIcon = (str: string) => {
119
+ export const getAlphabetIcon = (str: string, rootClassName: string = "") => {
120
120
  if (!str) return null
121
121
  return (
122
122
  <span
123
- className="alphabet-icon__initial fs-13 icon-dim-20 flex cn-0 mr-8"
123
+ className={`${rootClassName} alphabet-icon__initial fs-13 icon-dim-20 flex cn-0 mr-8`}
124
124
  style={{ backgroundColor: getRandomColor(str) }}
125
125
  >
126
126
  {str[0]}
@@ -299,21 +299,29 @@ export function CustomInput({
299
299
  label,
300
300
  type = 'text',
301
301
  disabled = false,
302
- autoComplete = 'off',
303
302
  labelClassName = '',
304
303
  placeholder = '',
305
304
  tabIndex = 1,
306
305
  dataTestid = '',
307
- }) {
306
+ isRequiredField = false,
307
+ autoFocus = true,
308
+ rootClassName = '',
309
+ }: CustomInputProps) {
308
310
  return (
309
311
  <div className="flex column left top">
310
- <label className={`form__label ${labelClassName}`}>{label}</label>
312
+ {label ? (
313
+ <label className={`form__label ${labelClassName} ${isRequiredField ? 'dc__required-field' : ''}`}>
314
+ {label}
315
+ </label>
316
+ ) : (
317
+ ''
318
+ )}
311
319
  <input
312
320
  data-testid={dataTestid}
313
321
  type={type}
314
322
  name={name}
315
323
  autoComplete="off"
316
- className="form__input"
324
+ className={`form__input ${rootClassName}`}
317
325
  onChange={(e) => {
318
326
  e.persist()
319
327
  onChange(e)
@@ -324,6 +332,7 @@ export function CustomInput({
324
332
  value={value}
325
333
  disabled={disabled}
326
334
  tabIndex={tabIndex}
335
+ autoFocus={autoFocus}
327
336
  />
328
337
  {handleError(error).map((err) => (
329
338
  <div className="form__error" key={err}>
@@ -623,3 +623,22 @@ export interface CiPipeline {
623
623
  isOffendingMandatoryPlugin?: boolean
624
624
  pipelineType?: string
625
625
  }
626
+
627
+ export interface CustomInputProps {
628
+ name: string
629
+ value: string
630
+ error?: React.ReactNode
631
+ onChange: (e: any) => void
632
+ onBlur?: (e: any) => void
633
+ onFocus?: (e: any) => void
634
+ label?: React.ReactNode
635
+ type?: string
636
+ disabled?: boolean
637
+ labelClassName?: string
638
+ placeholder?: string
639
+ tabIndex?: number
640
+ dataTestid?: string
641
+ isRequiredField?: boolean
642
+ autoFocus?: boolean
643
+ rootClassName?: string
644
+ }