@devtron-labs/devtron-fe-common-lib 0.0.44-beta-1 → 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.
Files changed (67) hide show
  1. package/dist/Common/DevtronProgressing/DevtronProgressing.d.ts +3 -0
  2. package/dist/Common/DevtronProgressing/index.d.ts +1 -0
  3. package/dist/Common/DevtronProgressing/types.d.ts +4 -0
  4. package/dist/Common/Helper.d.ts +15 -18
  5. package/dist/Common/RJSF/Form.d.ts +4 -0
  6. package/dist/Common/RJSF/common/FieldRow.d.ts +6 -0
  7. package/dist/Common/RJSF/common/types.d.ts +8 -0
  8. package/dist/Common/RJSF/config.d.ts +4 -0
  9. package/dist/Common/RJSF/constants.d.ts +7 -0
  10. package/dist/Common/RJSF/index.d.ts +3 -0
  11. package/dist/Common/RJSF/templates/ArrayFieldItemTemplate.d.ts +3 -0
  12. package/dist/Common/RJSF/templates/ArrayFieldTemplate.d.ts +3 -0
  13. package/dist/Common/RJSF/templates/BaseInput.d.ts +3 -0
  14. package/dist/Common/RJSF/templates/ButtonTemplates/AddButton.d.ts +3 -0
  15. package/dist/Common/RJSF/templates/ButtonTemplates/RemoveButton.d.ts +3 -0
  16. package/dist/Common/RJSF/templates/ButtonTemplates/SubmitButton.d.ts +3 -0
  17. package/dist/Common/RJSF/templates/ButtonTemplates/index.d.ts +3 -0
  18. package/dist/Common/RJSF/templates/Description.d.ts +3 -0
  19. package/dist/Common/RJSF/templates/Field.d.ts +3 -0
  20. package/dist/Common/RJSF/templates/FieldErrorTemplate.d.ts +3 -0
  21. package/dist/Common/RJSF/templates/ObjectFieldTemplate.d.ts +3 -0
  22. package/dist/Common/RJSF/templates/TitleField.d.ts +3 -0
  23. package/dist/Common/RJSF/templates/WrapIfAdditionalTemplate.d.ts +3 -0
  24. package/dist/Common/RJSF/templates/index.d.ts +10 -0
  25. package/dist/Common/RJSF/types.d.ts +3 -0
  26. package/dist/Common/RJSF/utils.d.ts +26 -0
  27. package/dist/Common/RJSF/widgets/Checkbox.d.ts +3 -0
  28. package/dist/Common/RJSF/widgets/Select.d.ts +3 -0
  29. package/dist/Common/RJSF/widgets/index.d.ts +2 -0
  30. package/dist/Common/Types.d.ts +18 -1
  31. package/dist/Common/index.d.ts +2 -0
  32. package/dist/index.js +9649 -6863
  33. package/package.json +4 -1
  34. package/src/Assets/Icon/ic-chevron-down.svg +5 -0
  35. package/src/Assets/Icon/ic-rotate-devtron.svg +103 -0
  36. package/src/Common/DevtronProgressing/DevtronProgressing.tsx +11 -0
  37. package/src/Common/DevtronProgressing/index.ts +1 -0
  38. package/src/Common/DevtronProgressing/types.ts +4 -0
  39. package/src/Common/Helper.tsx +42 -11
  40. package/src/Common/RJSF/Form.tsx +29 -0
  41. package/src/Common/RJSF/common/FieldRow.tsx +35 -0
  42. package/src/Common/RJSF/common/types.ts +9 -0
  43. package/src/Common/RJSF/config.ts +37 -0
  44. package/src/Common/RJSF/constants.ts +10 -0
  45. package/src/Common/RJSF/index.ts +3 -0
  46. package/src/Common/RJSF/rjsfForm.scss +18 -0
  47. package/src/Common/RJSF/templates/ArrayFieldItemTemplate.tsx +31 -0
  48. package/src/Common/RJSF/templates/ArrayFieldTemplate.tsx +78 -0
  49. package/src/Common/RJSF/templates/BaseInput.tsx +16 -0
  50. package/src/Common/RJSF/templates/ButtonTemplates/AddButton.tsx +18 -0
  51. package/src/Common/RJSF/templates/ButtonTemplates/RemoveButton.tsx +10 -0
  52. package/src/Common/RJSF/templates/ButtonTemplates/SubmitButton.tsx +18 -0
  53. package/src/Common/RJSF/templates/ButtonTemplates/index.ts +3 -0
  54. package/src/Common/RJSF/templates/Description.tsx +12 -0
  55. package/src/Common/RJSF/templates/Field.tsx +30 -0
  56. package/src/Common/RJSF/templates/FieldErrorTemplate.tsx +25 -0
  57. package/src/Common/RJSF/templates/ObjectFieldTemplate.tsx +105 -0
  58. package/src/Common/RJSF/templates/TitleField.tsx +9 -0
  59. package/src/Common/RJSF/templates/WrapIfAdditionalTemplate.tsx +51 -0
  60. package/src/Common/RJSF/templates/index.ts +10 -0
  61. package/src/Common/RJSF/types.ts +4 -0
  62. package/src/Common/RJSF/utils.ts +123 -0
  63. package/src/Common/RJSF/widgets/Checkbox.tsx +44 -0
  64. package/src/Common/RJSF/widgets/Select.tsx +77 -0
  65. package/src/Common/RJSF/widgets/index.ts +2 -0
  66. package/src/Common/Types.ts +19 -1
  67. package/src/Common/index.ts +2 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devtron-labs/devtron-fe-common-lib",
3
- "version": "0.0.44-beta-1",
3
+ "version": "0.0.45-beta-1",
4
4
  "description": "Supporting common component library",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -41,6 +41,9 @@
41
41
  "@sentry/browser": "^7.31.1"
42
42
  },
43
43
  "peerDependencies": {
44
+ "@rjsf/core": "^5.13.3",
45
+ "@rjsf/utils": "^5.13.3",
46
+ "@rjsf/validator-ajv8": "^5.13.3",
44
47
  "react": "^17.0.2",
45
48
  "react-dom": "^17.0.2",
46
49
  "react-router": "^5.3.0",
@@ -0,0 +1,5 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
2
+ <g fill="none" fill-rule="evenodd">
3
+ <path fill="#999" class="fill-color" fill-rule="nonzero" d="M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6z"/>
4
+ </g>
5
+ </svg>
@@ -0,0 +1,103 @@
1
+
2
+ <svg width="80" height="80" viewBox="0 0 100 100" fill="none" xmlns="http://www.w3.org/2000/svg">
3
+ <style>
4
+ .svg__loader_group-top {
5
+ animation: top-shape 1.2s infinite;
6
+ transform-origin: center center;
7
+ }
8
+ .svg__loader_group-bottom {
9
+ animation: bottom-shape 1.2s infinite;
10
+ transform-origin: center center;
11
+ }
12
+
13
+ .svg__loader_shapepath-top {
14
+ animation: path-fill 1.2s infinite;
15
+ }
16
+ .svg__loader_shapepath-bottom {
17
+ animation: path-fill 1.2s infinite;
18
+ }
19
+
20
+ .svg__loader_rotating-group {
21
+ animation: rotate-group 1.2s infinite reverse;
22
+ transform-origin: center center;
23
+ }
24
+
25
+ @keyframes path-fill {
26
+ 0% {
27
+ fill: #3989D9;
28
+ }
29
+ 30% {
30
+ fill: #3989D9;
31
+ }
32
+ 45% {
33
+ fill: #ABCFF3;
34
+ }
35
+ 100% {
36
+ fill: #3989D9;
37
+ }
38
+ }
39
+
40
+ @keyframes top-shape {
41
+ 0% {
42
+ transform: translateX(0px) translateY(0px) rotate(0deg);
43
+ transform-origin: center center;
44
+ }
45
+ 30% {
46
+ transform: translateX(0px) translateY(0px) rotate(10deg);
47
+ transform-origin: center center;
48
+ }
49
+ 45% {
50
+ transform: translateX(-6px) translateY(-6px) rotate(15deg);
51
+ transform-origin: center center;
52
+ }
53
+
54
+ 100% {
55
+ transform: translateX(0px) translateY(0px) rotate(0deg);
56
+ transform-origin: center center;
57
+ }
58
+ }
59
+
60
+ @keyframes bottom-shape {
61
+ 0% {
62
+ transform: translateX(0px) translateY(0px) rotate(0deg);
63
+ transform-origin: center center;
64
+ }
65
+ 30% {
66
+ transform: translateX(0px) translateY(0px) rotate(10deg);
67
+ transform-origin: center center;
68
+ }
69
+ 45% {
70
+ transform: translateX(6px) translateY(6px) rotate(15deg);
71
+ transform-origin: center center;
72
+ }
73
+
74
+ 100% {
75
+ transform: translateX(0px) translateY(0px) rotate(0deg);
76
+ transform-origin: center center;
77
+ }
78
+ }
79
+
80
+ @keyframes rotate-group {
81
+ 0% {
82
+ transform: rotate(0deg);
83
+ }
84
+ 44% {
85
+ transform: rotate(0deg);
86
+ }
87
+ 100% {
88
+ transform: rotate(360deg);
89
+ animation-timing-function: ease-in-out;
90
+ }
91
+ }
92
+ </style>
93
+ <rect width="100" height="100" rx="20" fill="#E5F2FF"/>
94
+ <g class="svg__loader_rotating-group">
95
+
96
+ <g class="svg__loader_group-top">
97
+ <path class="svg__loader_shapepath-top" d="M59.8584 21.95L38.6084 21.875C36.8042 21.8667 35.1292 22.8125 34.1792 24.3667L19.4625 48.5167C18.9899 49.293 18.7427 50.1855 18.7486 51.0943C18.7545 52.0031 19.0132 52.8924 19.4958 53.6625L30.9125 71.8792C31.2183 72.533 31.7308 73.0679 32.3709 73.4015C33.011 73.7351 33.7431 73.8488 34.4542 73.725C35.141 73.5973 35.7703 73.2572 36.2533 72.7525C36.7362 72.2478 37.0485 71.6042 37.1459 70.9125C37.2338 70.2725 37.143 69.6207 36.8834 69.0292L36.8334 68.9458C36.7375 68.7458 36.6167 68.5583 36.4875 68.3833L35.1958 66.3083L28.3458 55.3583C27.9912 54.8612 27.7883 54.2719 27.7617 53.6618C27.735 53.0517 27.8858 52.447 28.1958 51.9208C30.175 48.5958 34.5125 41.5042 35.4875 40.3458C35.854 40.0077 36.2862 39.7489 36.7572 39.5854C37.2282 39.4219 37.7279 39.3574 38.225 39.3958L43.6208 39.8125C43.8939 39.8472 44.1535 39.951 44.3752 40.1142C44.5969 40.2773 44.7733 40.4943 44.8876 40.7447C45.0019 40.9951 45.0504 41.2705 45.0286 41.5448C45.0067 41.8192 44.9151 42.0834 44.7625 42.3125L42.5125 45.7917C42.3947 45.9427 42.2915 46.1045 42.2042 46.275V46.2792C41.8913 46.8936 41.8029 47.5981 41.9542 48.2708C42.0838 48.8505 42.391 49.3753 42.833 49.7721C43.275 50.1689 43.8298 50.4179 44.4201 50.4844C45.0103 50.5509 45.6066 50.4316 46.1259 50.1431C46.6451 49.8546 47.0614 49.4113 47.3167 48.875L62.0625 26.225C63.2084 24.4667 62.0709 22.0625 60 21.9542C59.9528 21.9515 59.9056 21.9501 59.8584 21.95Z" fill="#3989D9"/>
98
+ </g>
99
+ <g class="svg__loader_group-bottom">
100
+ <path class="svg__loader_shapepath-bottom" d="M65.4458 26.2375C66.1567 26.1108 66.8896 26.2217 67.5313 26.553C68.1729 26.8844 68.6876 27.4178 68.9958 28.0709L80.4875 46.2334C81.4833 47.7959 81.5041 49.7959 80.55 51.3792L65.9375 75.5917C65.4801 76.3555 64.8332 76.9882 64.0594 77.4284C63.2855 77.8686 62.4111 78.1014 61.5208 78.1042L40.2708 78.125C40.2236 78.1263 40.1764 78.1263 40.1291 78.125C38.0583 78.025 36.9125 75.625 38.0458 73.8625L52.6916 51.1459C52.9442 50.6078 53.3584 50.162 53.8765 49.8707C54.3946 49.5794 54.9907 49.4571 55.5816 49.5209C56.1725 49.5847 56.7288 49.8313 57.1728 50.2265C57.6168 50.6216 57.9264 51.1455 58.0583 51.725C58.2135 52.3963 58.1295 53.1007 57.8208 53.7167C57.7327 53.8889 57.628 54.0564 57.5083 54.2084L55.2791 57.6959C55.1264 57.9255 55.035 58.1904 55.0135 58.4654C54.9921 58.7403 55.0413 59.0162 55.1566 59.2667C55.2718 59.5173 55.4493 59.7342 55.672 59.8968C55.8947 60.0595 56.1554 60.1624 56.4291 60.1959L61.8291 60.5875C62.3261 60.6226 62.8249 60.5548 63.2944 60.3885C63.764 60.2222 64.1942 59.9609 64.5583 59.6209C65.1 58.975 66.6666 56.4959 68.2916 53.8417L69.2666 52.2459C70.2333 50.6542 71.1458 49.1209 71.8041 48.0125C72.1109 47.4853 72.2584 46.8805 72.2288 46.2712C72.1992 45.6619 71.9938 45.0743 71.6375 44.5792L71.6583 44.5667L64.7375 33.6584L63.4416 31.5875C63.3053 31.4122 63.1866 31.2238 63.0875 31.025L63.0375 30.95C62.7742 30.3581 62.6805 29.7046 62.7666 29.0625C62.8608 28.3703 63.1702 27.7251 63.6509 27.2182C64.1317 26.7113 64.7595 26.3682 65.4458 26.2375Z" fill="#3989D9"/>
101
+ </g>
102
+ </g>
103
+ </svg>
@@ -0,0 +1,11 @@
1
+ import React from 'react'
2
+ import { ReactComponent as ICRotateDevtron } from '../../Assets/Icon/ic-rotate-devtron.svg'
3
+ import { DevtronProgressingProps } from './types'
4
+
5
+ export function DevtronProgressing({ classes, parentClasses }: DevtronProgressingProps): JSX.Element {
6
+ return (
7
+ <div className={parentClasses ? parentClasses : ''}>
8
+ <ICRotateDevtron className={classes ? classes : ''} />
9
+ </div>
10
+ )
11
+ }
@@ -0,0 +1 @@
1
+ export * from './DevtronProgressing'
@@ -0,0 +1,4 @@
1
+ export interface DevtronProgressingProps {
2
+ classes?: string
3
+ parentClasses?: string
4
+ }
@@ -1,13 +1,13 @@
1
+ import * as Sentry from '@sentry/browser'
2
+ import moment from 'moment'
1
3
  import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
2
4
  import { useLocation } from 'react-router-dom'
3
- import moment from 'moment'
4
5
  import { toast } from 'react-toastify'
5
- import * as Sentry from '@sentry/browser'
6
+ import { ReactComponent as FormError } from '../Assets/Icon/ic-warning.svg'
7
+ import { ERROR_EMPTY_SCREEN, TOKEN_COOKIE_NAME } from './Constants'
6
8
  import { ServerErrors } from './ServerError'
7
9
  import { toastAccessDenied } from './ToastBody'
8
- import { ERROR_EMPTY_SCREEN, TOKEN_COOKIE_NAME } from './Constants'
9
- import { ReactComponent as FormError } from '../Assets/Icon/ic-warning.svg'
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}>
@@ -495,3 +504,25 @@ export const processDeployedTime = (lastDeployed, isArgoInstalled) => {
495
504
  return isArgoInstalled ? '' : 'Not deployed'
496
505
  }
497
506
  }
507
+
508
+ /**
509
+ * Appends search parameters to the url as a query string
510
+ *
511
+ * @param url URL to which the search params needs to be added
512
+ * @param params Object for the search parameters
513
+ */
514
+ export const getUrlWithSearchParams = (url: string, params: Record<string | number, any>) => {
515
+ const searchParams = new URLSearchParams()
516
+ Object.keys(params).forEach((key) => {
517
+ if (params[key]) {
518
+ searchParams.append(key, params[key])
519
+ }
520
+ })
521
+ const queryString = searchParams.toString()
522
+ return url + (queryString ? `?${queryString}` : '')
523
+ }
524
+
525
+ /**
526
+ * Custom exception logger function for logging errors to sentry
527
+ */
528
+ export const logExceptionToSentry = Sentry.captureException.bind(window)
@@ -0,0 +1,29 @@
1
+ import React from 'react'
2
+ import RJSF from '@rjsf/core'
3
+ import RJSFValidator from '@rjsf/validator-ajv8'
4
+
5
+ import { templates, widgets } from './config'
6
+ import { FormProps } from './types'
7
+ import { translateString } from './utils'
8
+ import './rjsfForm.scss'
9
+
10
+ // Need to use this way because the default import was not working as expected
11
+ // The default import resolves to an object intead of a function
12
+ const Form = (RJSF as any).default as typeof RJSF
13
+ const validator = (RJSFValidator as any).default as typeof RJSFValidator
14
+
15
+ export const RJSFForm = (props: FormProps) => (
16
+ <Form
17
+ noHtml5Validate
18
+ showErrorList={false}
19
+ autoComplete="off"
20
+ {...props}
21
+ validator={validator}
22
+ templates={{
23
+ ...templates,
24
+ ...props.templates,
25
+ }}
26
+ widgets={{ ...widgets, ...props.widgets }}
27
+ translateString={translateString}
28
+ />
29
+ )
@@ -0,0 +1,35 @@
1
+ import React from 'react'
2
+ import { FieldRowProps } from './types'
3
+ import { DEFAULT_FIELD_TITLE, DO_NOT_SHOW_LABEL } from '../constants'
4
+
5
+ export const FieldRowWithLabel = ({
6
+ showLabel,
7
+ label,
8
+ required,
9
+ children,
10
+ id,
11
+ shouldAlignCenter = true,
12
+ }: Omit<FieldRowProps, 'label'> & {
13
+ label: FieldRowProps['label'] | typeof DO_NOT_SHOW_LABEL
14
+ }) => (
15
+ <div
16
+ className={
17
+ showLabel
18
+ ? `display-grid dc__gap-12 rjsf-form-template__field ${shouldAlignCenter ? 'flex-align-center' : ''}`
19
+ : ''
20
+ }
21
+ >
22
+ {showLabel && (
23
+ <label className="cn-7 fs-13 lh-32 fw-4 flexbox mb-0" htmlFor={id}>
24
+ {/* The check is added here intentionally for proper layout for array type field */}
25
+ {label !== DO_NOT_SHOW_LABEL && (
26
+ <>
27
+ <span className="dc__ellipsis-right">{label || DEFAULT_FIELD_TITLE}</span>
28
+ {required && <span className="cr-5">&nbsp;*</span>}
29
+ </>
30
+ )}
31
+ </label>
32
+ )}
33
+ {children}
34
+ </div>
35
+ )
@@ -0,0 +1,9 @@
1
+ import { FieldTemplateProps } from '@rjsf/utils'
2
+
3
+ export interface FieldRowProps extends Pick<FieldTemplateProps, 'children' | 'label' | 'required' | 'id'> {
4
+ showLabel?: boolean
5
+ /**
6
+ * @default true
7
+ */
8
+ shouldAlignCenter?: boolean
9
+ }
@@ -0,0 +1,37 @@
1
+ import React from 'react'
2
+ import { RegistryWidgetsType } from '@rjsf/utils'
3
+
4
+ import {
5
+ AddButton,
6
+ ArrayFieldItemTemplate,
7
+ ArrayFieldTemplate,
8
+ BaseInputTemplate,
9
+ DescriptionFieldTemplate,
10
+ FieldTemplate,
11
+ FieldErrorTemplate,
12
+ ObjectFieldTemplate,
13
+ RemoveButton,
14
+ SubmitButton,
15
+ TitleFieldTemplate,
16
+ WrapIfAdditionalTemplate,
17
+ } from './templates'
18
+ import { CheckboxWidget, SelectWidget } from './widgets'
19
+ import { FormProps } from './types'
20
+
21
+ export const widgets: RegistryWidgetsType = {
22
+ CheckboxWidget,
23
+ SelectWidget,
24
+ }
25
+
26
+ export const templates: FormProps['templates'] = {
27
+ ArrayFieldItemTemplate,
28
+ ArrayFieldTemplate,
29
+ BaseInputTemplate,
30
+ ButtonTemplates: { AddButton, RemoveButton, SubmitButton },
31
+ DescriptionFieldTemplate,
32
+ FieldTemplate,
33
+ FieldErrorTemplate,
34
+ ObjectFieldTemplate,
35
+ TitleFieldTemplate,
36
+ WrapIfAdditionalTemplate,
37
+ }
@@ -0,0 +1,10 @@
1
+ export const PLACEHOLDERS = {
2
+ SELECT: 'Please select an option',
3
+ INPUT: 'Please enter an input',
4
+ OBJECT_KEY: 'Please enter a value for the key',
5
+ }
6
+
7
+ export const DEFAULT_FIELD_TITLE = 'Key not available'
8
+
9
+ // Using symbol to ensure uniqueness across the fields
10
+ export const DO_NOT_SHOW_LABEL = Symbol('Do not show label')
@@ -0,0 +1,3 @@
1
+ export { RJSFForm } from './Form'
2
+ export * from './types'
3
+ export { getInferredTypeFromValueType, getRedirectionProps } from './utils'
@@ -0,0 +1,18 @@
1
+ .rjsf-form-template {
2
+ &__field {
3
+ grid-template-columns: 250px 1fr;
4
+ }
5
+
6
+ &__additional-fields {
7
+ grid-template-columns: 1fr 1fr minmax(20px, auto);
8
+ }
9
+
10
+ &__array-field-item {
11
+ grid-template-columns: 1fr auto;
12
+
13
+ & > :first-child {
14
+ // This is added as the array field itself has a margin bottom
15
+ margin: 0;
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,31 @@
1
+ import React, { CSSProperties } from 'react'
2
+ import { ArrayFieldTemplateItemType } from '@rjsf/utils'
3
+
4
+ export const ArrayFieldItemTemplate = ({
5
+ children,
6
+ className,
7
+ disabled,
8
+ hasToolbar,
9
+ hasRemove,
10
+ index,
11
+ onDropIndexClick,
12
+ readonly,
13
+ registry,
14
+ uiSchema,
15
+ }: ArrayFieldTemplateItemType) => {
16
+ const { RemoveButton } = registry.templates.ButtonTemplates
17
+
18
+ return (
19
+ <div className="display-grid rjsf-form-template__array-field-item flex-align-center dc__gap-8 mb-12">
20
+ {children}
21
+ {hasToolbar && hasRemove && (
22
+ <RemoveButton
23
+ disabled={disabled || readonly}
24
+ onClick={onDropIndexClick(index)}
25
+ uiSchema={uiSchema}
26
+ registry={registry}
27
+ />
28
+ )}
29
+ </div>
30
+ )
31
+ }
@@ -0,0 +1,78 @@
1
+ import React from 'react'
2
+ import { getTemplate, getUiOptions, ArrayFieldTemplateProps, ArrayFieldTemplateItemType } from '@rjsf/utils'
3
+ import { FieldRowWithLabel } from '../common/FieldRow'
4
+ import { DO_NOT_SHOW_LABEL } from '../constants'
5
+
6
+ const ActionButton = ({ canAdd, onAddClick, disabled, readonly, uiSchema, registry }) => {
7
+ const {
8
+ ButtonTemplates: { AddButton },
9
+ } = registry.templates
10
+
11
+ return (
12
+ canAdd && (
13
+ <AddButton onClick={onAddClick} disabled={disabled || readonly} uiSchema={uiSchema} registry={registry} />
14
+ )
15
+ )
16
+ }
17
+
18
+ export const ArrayFieldTemplate = ({
19
+ canAdd,
20
+ className,
21
+ disabled,
22
+ idSchema,
23
+ uiSchema,
24
+ items,
25
+ onAddClick,
26
+ readonly,
27
+ registry,
28
+ required,
29
+ title,
30
+ }: ArrayFieldTemplateProps) => {
31
+ const uiOptions = getUiOptions(uiSchema)
32
+ const ArrayFieldItemTemplate = getTemplate<'ArrayFieldItemTemplate'>('ArrayFieldItemTemplate', registry, uiOptions)
33
+ const label = uiOptions.title || title
34
+
35
+ return (
36
+ <fieldset className={className} id={idSchema.$id}>
37
+ {/* Show the label here in case there are no items, otherwise handled by Field Template */}
38
+ {items.length ? (
39
+ <>
40
+ {items.map(({ key, ...itemProps }: ArrayFieldTemplateItemType, index) => {
41
+ // Show the title as the label for the first field
42
+ const children = {
43
+ ...itemProps.children,
44
+ props: {
45
+ ...itemProps.children.props,
46
+ name: index === 0 ? label : DO_NOT_SHOW_LABEL,
47
+ },
48
+ }
49
+ return (
50
+ <ArrayFieldItemTemplate key={key} {...itemProps}>
51
+ {children}
52
+ </ArrayFieldItemTemplate>
53
+ )
54
+ })}
55
+ <ActionButton
56
+ canAdd={canAdd}
57
+ onAddClick={onAddClick}
58
+ disabled={disabled}
59
+ readonly={readonly}
60
+ uiSchema={uiSchema}
61
+ registry={registry}
62
+ />
63
+ </>
64
+ ) : (
65
+ <FieldRowWithLabel label={label} required={required} showLabel id={idSchema.$id}>
66
+ <ActionButton
67
+ canAdd={canAdd}
68
+ onAddClick={onAddClick}
69
+ disabled={disabled}
70
+ readonly={readonly}
71
+ uiSchema={uiSchema}
72
+ registry={registry}
73
+ />
74
+ </FieldRowWithLabel>
75
+ )}
76
+ </fieldset>
77
+ )
78
+ }
@@ -0,0 +1,16 @@
1
+ import React from 'react'
2
+ import { getDefaultRegistry } from '@rjsf/core'
3
+ import { BaseInputTemplateProps } from '@rjsf/utils'
4
+ import { PLACEHOLDERS } from '../constants'
5
+
6
+ const {
7
+ templates: { BaseInputTemplate },
8
+ } = getDefaultRegistry()
9
+
10
+ export const BaseInput = ({ placeholder, ...props }: BaseInputTemplateProps) => (
11
+ <BaseInputTemplate
12
+ placeholder={placeholder || PLACEHOLDERS.INPUT}
13
+ {...props}
14
+ className="form__input cn-9 fs-13 lh-20 fw-4"
15
+ />
16
+ )
@@ -0,0 +1,18 @@
1
+ import React from 'react'
2
+ import { IconButtonProps } from '@rjsf/utils'
3
+
4
+ import { ReactComponent as PlusIcon } from '../../../../Assets/Icon/ic-add.svg'
5
+
6
+ export const AddButton = ({ icon, iconType, registry, uiSchema, ...props }: IconButtonProps) => (
7
+ <div className="flexbox flex-justify-end">
8
+ <button
9
+ {...props}
10
+ type="button"
11
+ className="dc__outline-none-imp p-0 dc__transparent flex dc__gap-4 cursor"
12
+ title="Add"
13
+ >
14
+ <PlusIcon className="icon-dim-16 fcb-5" />
15
+ <span className="cb-5 fs-13 lh-20">Add</span>
16
+ </button>
17
+ </div>
18
+ )
@@ -0,0 +1,10 @@
1
+ import React from 'react'
2
+ import { IconButtonProps } from '@rjsf/utils'
3
+
4
+ import { ReactComponent as CrossIcon } from '../../../../Assets/Icon/ic-cross.svg'
5
+
6
+ export const RemoveButton = ({ icon, iconType, registry, uiSchema, ...props }: IconButtonProps) => (
7
+ <button {...props} type="button" className="dc__outline-none-imp p-0 dc__transparent flex cursor" title="Remove">
8
+ <CrossIcon className="icon-dim-16 fcr-5" />
9
+ </button>
10
+ )
@@ -0,0 +1,18 @@
1
+ import React from 'react'
2
+ import { getSubmitButtonOptions, SubmitButtonProps } from '@rjsf/utils'
3
+
4
+ export const SubmitButton = ({ uiSchema }: SubmitButtonProps) => {
5
+ const { submitText, norender, props: submitButtonProps = {} } = getSubmitButtonOptions(uiSchema)
6
+
7
+ return norender ? null : (
8
+ <div className="flexbox flex-justify-end">
9
+ <button
10
+ type="submit"
11
+ {...submitButtonProps}
12
+ className={`cta ${submitButtonProps.className || ''}`}
13
+ >
14
+ {submitText}
15
+ </button>
16
+ </div>
17
+ )
18
+ }
@@ -0,0 +1,3 @@
1
+ export { AddButton } from './AddButton'
2
+ export { RemoveButton } from './RemoveButton'
3
+ export { SubmitButton } from './SubmitButton'
@@ -0,0 +1,12 @@
1
+ import React from 'react'
2
+ import { DescriptionFieldProps } from '@rjsf/utils'
3
+
4
+ import { ReactComponent as Info } from '../../../Assets/Icon/ic-info-filled.svg'
5
+
6
+ export const Description = ({ id, description }: DescriptionFieldProps) =>
7
+ description && (
8
+ <div id={id} className="flex left flex-align-center mt-4 dc__gap-4">
9
+ <Info className="icon-dim-16 mw-16 info-icon-n5" />
10
+ <span className="cn-7 fs-11 fw-4 dc__ellipsis-right">{description}</span>
11
+ </div>
12
+ )
@@ -0,0 +1,30 @@
1
+ import React from 'react'
2
+ import { FieldTemplateProps, getUiOptions, getTemplate, ADDITIONAL_PROPERTY_FLAG } from '@rjsf/utils'
3
+ import { FieldRowWithLabel } from '../common/FieldRow'
4
+
5
+ export const Field = (props: FieldTemplateProps) => {
6
+ const { id, label, children, errors, hidden, required, displayLabel, registry, uiSchema, classNames, schema, description } =
7
+ props
8
+ const uiOptions = getUiOptions(uiSchema)
9
+ const WrapIfAdditionalTemplate = getTemplate<'WrapIfAdditionalTemplate'>(
10
+ 'WrapIfAdditionalTemplate',
11
+ registry,
12
+ uiOptions,
13
+ )
14
+ // Object type fields have additional properties for key/value pairs
15
+ const hasAdditionalProperties = ADDITIONAL_PROPERTY_FLAG in schema
16
+ // Label is not displayed for boolean fields by default and hide for object type fields
17
+ const showLabel = (displayLabel || schema.type === 'boolean') && !hasAdditionalProperties
18
+
19
+ return hidden ? (
20
+ <div className="hidden">{children}</div>
21
+ ) : (
22
+ <div className={`${classNames} mb-12`}>
23
+ <FieldRowWithLabel label={label} showLabel={showLabel} id={id} required={required}>
24
+ <WrapIfAdditionalTemplate {...props}>{children}</WrapIfAdditionalTemplate>
25
+ </FieldRowWithLabel>
26
+ {description}
27
+ {errors}
28
+ </div>
29
+ )
30
+ }
@@ -0,0 +1,25 @@
1
+ import React from 'react'
2
+ import { errorId, FieldErrorProps } from '@rjsf/utils'
3
+
4
+ import { ReactComponent as Error } from '../../../Assets/Icon/ic-warning.svg'
5
+
6
+ export const FieldErrorTemplate = ({ errors = [], idSchema }: FieldErrorProps) => {
7
+ const id = errorId(idSchema)
8
+
9
+ return (
10
+ errors.length > 0 && (
11
+ <span id={id}>
12
+ {errors
13
+ .filter((elem) => !!elem)
14
+ .map((error, index: number) => {
15
+ return (
16
+ <span className="form__error" key={index}>
17
+ <Error className="form__icon form__icon--error" />
18
+ {error}
19
+ </span>
20
+ )
21
+ })}
22
+ </span>
23
+ )
24
+ )
25
+ }