@pareto-engineering/design-system 5.0.0 → 5.0.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 (112) hide show
  1. package/dist/cjs/a/{AreaChart → Charts/AreaChart}/AreaChart.js +89 -63
  2. package/dist/cjs/a/Charts/AreaChart/styles.scss +48 -0
  3. package/dist/cjs/a/Charts/BarChart/BarChart.js +135 -0
  4. package/dist/cjs/a/Charts/BarChart/index.js +13 -0
  5. package/dist/cjs/a/Charts/BarChart/styles.scss +48 -0
  6. package/dist/cjs/a/Charts/Common/CustomLegend/CustomLegend.js +69 -0
  7. package/dist/cjs/a/Charts/Common/CustomLegend/index.js +13 -0
  8. package/dist/cjs/a/Charts/Common/CustomLegend/styles.scss +40 -0
  9. package/dist/cjs/a/Charts/Common/CustomTooltipContent/CustomTooltipContent.js +86 -0
  10. package/dist/cjs/a/Charts/Common/CustomTooltipContent/index.js +13 -0
  11. package/dist/cjs/a/Charts/Common/CustomTooltipContent/styles.scss +22 -0
  12. package/dist/cjs/a/Charts/Common/YLabelsDropDown/YlabelsDropDown.js +98 -0
  13. package/dist/cjs/a/Charts/Common/YLabelsDropDown/index.js +13 -0
  14. package/dist/cjs/a/Charts/Common/YLabelsDropDown/styles.scss +88 -0
  15. package/dist/cjs/a/Charts/Common/index.js +26 -0
  16. package/dist/cjs/a/Charts/index.js +19 -0
  17. package/dist/cjs/a/Tooltip/styles.scss +1 -1
  18. package/dist/cjs/a/index.js +8 -2
  19. package/dist/cjs/f/FormInput/FormInput.js +6 -0
  20. package/dist/cjs/f/fields/FileUpload/FileUpload.js +18 -4
  21. package/dist/cjs/f/fields/LatexPreviewInput/LatexPreviewInput.js +78 -0
  22. package/dist/cjs/f/fields/LatexPreviewInput/convertLatexToHtml.js +46 -0
  23. package/dist/cjs/f/fields/LatexPreviewInput/index.js +20 -0
  24. package/dist/cjs/f/fields/LatexPreviewInput/styles.scss +24 -0
  25. package/dist/cjs/f/fields/index.js +13 -0
  26. package/dist/cjs/g/FormBuilder/FormBuilder.js +3 -6
  27. package/dist/cjs/g/FormBuilder/common/Builder/Builder.js +1 -3
  28. package/dist/cjs/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +5 -7
  29. package/dist/cjs/g/FormBuilder/common/Builder/common/Section/Section.js +2 -4
  30. package/dist/cjs/g/FormBuilder/common/Renderer/Renderer.js +2 -4
  31. package/dist/cjs/g/FormBuilder/common/Renderer/common/Section/Section.js +2 -10
  32. package/dist/cjs/utils/formatting.js +111 -0
  33. package/dist/cjs/utils/index.js +20 -1
  34. package/dist/es/a/{AreaChart → Charts/AreaChart}/AreaChart.js +88 -59
  35. package/dist/es/a/Charts/AreaChart/styles.scss +48 -0
  36. package/dist/es/a/Charts/BarChart/BarChart.js +126 -0
  37. package/dist/es/a/Charts/BarChart/index.js +1 -0
  38. package/dist/es/a/Charts/BarChart/styles.scss +48 -0
  39. package/dist/es/a/Charts/Common/CustomLegend/CustomLegend.js +59 -0
  40. package/dist/es/a/Charts/Common/CustomLegend/index.js +1 -0
  41. package/dist/es/a/Charts/Common/CustomLegend/styles.scss +40 -0
  42. package/dist/es/a/Charts/Common/CustomTooltipContent/CustomTooltipContent.js +76 -0
  43. package/dist/es/a/Charts/Common/CustomTooltipContent/index.js +1 -0
  44. package/dist/es/a/Charts/Common/CustomTooltipContent/styles.scss +22 -0
  45. package/dist/es/a/Charts/Common/YLabelsDropDown/YlabelsDropDown.js +88 -0
  46. package/dist/es/a/Charts/Common/YLabelsDropDown/index.js +1 -0
  47. package/dist/es/a/Charts/Common/YLabelsDropDown/styles.scss +88 -0
  48. package/dist/es/a/Charts/Common/index.js +3 -0
  49. package/dist/es/a/Charts/index.js +2 -0
  50. package/dist/es/a/Tooltip/styles.scss +1 -1
  51. package/dist/es/a/index.js +1 -1
  52. package/dist/es/f/FormInput/FormInput.js +7 -1
  53. package/dist/es/f/fields/FileUpload/FileUpload.js +18 -4
  54. package/dist/es/f/fields/LatexPreviewInput/LatexPreviewInput.js +70 -0
  55. package/dist/es/f/fields/LatexPreviewInput/convertLatexToHtml.js +31 -0
  56. package/dist/es/f/fields/LatexPreviewInput/index.js +3 -0
  57. package/dist/es/f/fields/LatexPreviewInput/styles.scss +24 -0
  58. package/dist/es/f/fields/index.js +1 -0
  59. package/dist/es/g/FormBuilder/FormBuilder.js +3 -6
  60. package/dist/es/g/FormBuilder/common/Builder/Builder.js +1 -3
  61. package/dist/es/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +5 -7
  62. package/dist/es/g/FormBuilder/common/Builder/common/Section/Section.js +2 -4
  63. package/dist/es/g/FormBuilder/common/Renderer/Renderer.js +2 -4
  64. package/dist/es/g/FormBuilder/common/Renderer/common/Section/Section.js +32 -42
  65. package/dist/es/utils/formatting.js +102 -0
  66. package/dist/es/utils/index.js +2 -1
  67. package/jest.config.js +3 -0
  68. package/package.json +7 -3
  69. package/src/stories/a/BarChart.stories.jsx +89 -0
  70. package/src/ui/a/{AreaChart → Charts/AreaChart}/AreaChart.jsx +109 -54
  71. package/src/ui/a/Charts/AreaChart/styles.scss +48 -0
  72. package/src/ui/a/Charts/BarChart/BarChart.jsx +165 -0
  73. package/src/ui/a/Charts/BarChart/index.js +1 -0
  74. package/src/ui/a/Charts/BarChart/styles.scss +48 -0
  75. package/src/ui/a/Charts/Common/CustomLegend/CustomLegend.jsx +84 -0
  76. package/src/ui/a/Charts/Common/CustomLegend/index.js +1 -0
  77. package/src/ui/a/Charts/Common/CustomLegend/styles.scss +40 -0
  78. package/src/ui/a/Charts/Common/CustomTooltipContent/CustomTooltipContent.jsx +105 -0
  79. package/src/ui/a/Charts/Common/CustomTooltipContent/index.js +1 -0
  80. package/src/ui/a/Charts/Common/CustomTooltipContent/styles.scss +22 -0
  81. package/src/ui/a/Charts/Common/YLabelsDropDown/YlabelsDropDown.jsx +121 -0
  82. package/src/ui/a/Charts/Common/YLabelsDropDown/index.js +1 -0
  83. package/src/ui/a/Charts/Common/YLabelsDropDown/styles.scss +88 -0
  84. package/src/ui/a/Charts/Common/index.js +3 -0
  85. package/src/ui/a/Charts/index.js +2 -0
  86. package/src/ui/a/Tooltip/styles.scss +1 -1
  87. package/src/ui/a/index.js +1 -1
  88. package/src/ui/f/FormInput/FormInput.jsx +11 -0
  89. package/src/ui/f/fields/FileUpload/FileUpload.jsx +24 -4
  90. package/src/ui/f/fields/LatexPreviewInput/LatexPreviewInput.jsx +91 -0
  91. package/src/ui/f/fields/LatexPreviewInput/convertLatexToHtml.jsx +38 -0
  92. package/src/ui/f/fields/LatexPreviewInput/index.js +3 -0
  93. package/src/ui/f/fields/LatexPreviewInput/styles.scss +24 -0
  94. package/src/ui/f/fields/index.js +4 -0
  95. package/src/ui/g/FormBuilder/FormBuilder.jsx +0 -3
  96. package/src/ui/g/FormBuilder/common/Builder/Builder.jsx +0 -2
  97. package/src/ui/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.jsx +4 -7
  98. package/src/ui/g/FormBuilder/common/Builder/common/Section/Section.jsx +0 -2
  99. package/src/ui/g/FormBuilder/common/Renderer/Renderer.jsx +0 -2
  100. package/src/ui/g/FormBuilder/common/Renderer/common/Section/Section.jsx +49 -64
  101. package/src/ui/utils/formatting.js +125 -0
  102. package/src/ui/utils/index.js +1 -0
  103. package/tests/__snapshots__/Storyshots.test.js.snap +1257 -62
  104. package/tests/emptyMock.js +3 -0
  105. package/tests/mockTextEncoder.js +7 -0
  106. package/tests/test-setup.js +7 -0
  107. package/dist/cjs/a/AreaChart/styles.scss +0 -89
  108. package/dist/es/a/AreaChart/styles.scss +0 -89
  109. package/src/ui/a/AreaChart/styles.scss +0 -89
  110. /package/dist/cjs/a/{AreaChart → Charts/AreaChart}/index.js +0 -0
  111. /package/dist/es/a/{AreaChart → Charts/AreaChart}/index.js +0 -0
  112. /package/src/ui/a/{AreaChart → Charts/AreaChart}/index.js +0 -0
@@ -41,7 +41,6 @@ const InputBuilder = ({
41
41
  sectionIndex,
42
42
  inputIndex,
43
43
  onDelete,
44
- customInputMap,
45
44
  // ...otherProps
46
45
  }) => {
47
46
  const { values, setFieldValue } = useFormikContext()
@@ -71,8 +70,6 @@ const InputBuilder = ({
71
70
  setFieldValue(`sections.${sectionIndex}.inputs.${inputIndex}.showSpecificFileTypes`, !input.showSpecificFileTypes)
72
71
  }
73
72
 
74
- const customInputTypes = customInputMap ? Object.keys(customInputMap) : []
75
-
76
73
  return (
77
74
  <div
78
75
  id={id}
@@ -130,10 +127,10 @@ const InputBuilder = ({
130
127
  value:'file',
131
128
  label:'File upload',
132
129
  },
133
- ...(customInputTypes && customInputTypes.map((customInputKey) => ({
134
- value:customInputKey,
135
- label:customInputMap[customInputKey].label,
136
- }))),
130
+ {
131
+ value:'latex-preview-input',
132
+ label:'Textbox with LaTeX preview',
133
+ },
137
134
  ]}
138
135
  />
139
136
  <div className="controls">
@@ -36,7 +36,6 @@ const Section = ({
36
36
  style,
37
37
  index,
38
38
  handleDeleteSection,
39
- customInputMap,
40
39
  // ...otherProps
41
40
  }) => {
42
41
  const { values, setFieldValue } = useFormikContext()
@@ -70,7 +69,6 @@ const Section = ({
70
69
  inputIndex={indx}
71
70
  onDelete={handleDeleteInput}
72
71
  onCopy={handleCopyInput}
73
- customInputMap={customInputMap}
74
72
  />,
75
73
  identifier:input.name,
76
74
  }))
@@ -78,7 +78,6 @@ const Renderer = ({
78
78
  handleFileDelete,
79
79
  onFileUpload,
80
80
  shouldUpdateInputStateInRealTime = true,
81
- customInputMap,
82
81
  // ...otherProps
83
82
  }) => {
84
83
  const [currentSectionIndex, setCurrentSectionIndex] = useState(0)
@@ -179,7 +178,6 @@ const Renderer = ({
179
178
  handleFileDelete={handleFileDelete}
180
179
  onFileUpload={onFileUpload}
181
180
  sectionIndex={sectionIndex}
182
- customInputMap={customInputMap}
183
181
  />
184
182
  )
185
183
  ))}
@@ -40,71 +40,56 @@ const Section = ({
40
40
  handleFileDelete,
41
41
  onFileUpload,
42
42
  sectionIndex,
43
- customInputMap,
44
43
  // ...otherProps
45
- }) => {
46
- const customInputTypes = customInputMap ? Object.keys(customInputMap) : []
47
-
48
- return (
49
- <div
50
- id={id}
51
- className={[
52
- baseClassName,
53
- componentClassName,
54
- userClassName,
55
- ]
56
- .filter((e) => e)
57
- .join(' ')}
58
- style={style}
59
- >
60
- <p className="h3">{title}</p>
61
- <ExpandableLexicalPreview
62
- nodes={description}
63
- name="instructions"
64
- />
65
- {inputs?.map((input, inputIndex) => {
66
- const isFileInput = input.type === 'file'
67
- const isCustomInput = customInputTypes.includes(input.type)
68
- const CustomInputComponent = isCustomInput ? customInputMap[input.type].component : null
69
-
70
- return (
71
- !isCustomInput ? (
72
- <FormInput
73
- key={input.name}
74
- {...input}
75
- disabled={readOnly}
76
- {...(isFileInput && {
77
- uploadStatus:fileUploadStatus,
78
- handleFileDelete,
79
- onChange :(files) => {
80
- const filesToUpload = files
81
- ?.filter((file) => file instanceof File)
82
- .map((file) => ({
83
- file,
84
- name :file.name,
85
- mimeType:file.type,
86
- type :fileTypeMapper[getFileType(file)] || 'Generic',
87
- title :file.name,
88
- sectionIndex,
89
- inputIndex,
90
- }))
91
-
92
- onFileUpload(filesToUpload)
93
- },
94
- })}
95
- />
96
- ) : (
97
- <CustomInputComponent
98
- key={input.name}
99
- {...input}
100
- disabled={readOnly}
101
- />
102
- )
103
- )
104
- })}
105
- </div>
106
- )
107
- }
44
+ }) => (
45
+ <div
46
+ id={id}
47
+ className={[
48
+ baseClassName,
49
+ componentClassName,
50
+ userClassName,
51
+ ]
52
+ .filter((e) => e)
53
+ .join(' ')}
54
+ style={style}
55
+ >
56
+ <p className="h3">{title}</p>
57
+ <ExpandableLexicalPreview
58
+ nodes={description}
59
+ name="instructions"
60
+ />
61
+ {inputs?.map((input, inputIndex) => {
62
+ const isFileInput = input.type === 'file'
63
+
64
+ return (
65
+ <FormInput
66
+ key={input.name}
67
+ {...input}
68
+ disabled={readOnly}
69
+ {...(isFileInput && {
70
+ uploadStatus:fileUploadStatus,
71
+ handleFileDelete,
72
+ onChange :(files) => {
73
+ const filesToUpload = files
74
+ ?.filter((file) => file instanceof File)
75
+ .map((file) => ({
76
+ file,
77
+ name :file.name,
78
+ mimeType:file.type,
79
+ type :fileTypeMapper[getFileType(file)] || 'Generic',
80
+ title :file.name,
81
+ sectionIndex,
82
+ inputIndex,
83
+ }))
84
+
85
+ onFileUpload(filesToUpload)
86
+ },
87
+ })}
88
+ />
89
+ )
90
+ })}
91
+ </div>
92
+ )
108
93
 
109
94
  Section.propTypes = {
110
95
  /**
@@ -0,0 +1,125 @@
1
+ export const DATE_FORMATS = {
2
+ HUMAN_READABLE:'human_readable',
3
+ TIME :'time',
4
+ DATETIME :'datetime',
5
+ CHART_DATE :'chart_date',
6
+ CHART_TIME :'chart_time',
7
+ WEEKDAY_DATE :'weekday_date',
8
+ DAY_VIEW :'day_view',
9
+ }
10
+
11
+ const isValidDate = (date) => date instanceof Date && !Number.isNaN(date)
12
+
13
+ const isTimeSliceFormat = (input) => {
14
+ const timeSliceRegex = /^([01]?[0-9]|2[0-3]):[0-5][0-9]$/
15
+ return timeSliceRegex.test(input)
16
+ }
17
+
18
+ const createTimeFromSlice = (timeSlice) => {
19
+ const [hours, minutes] = timeSlice.split(':').map(Number)
20
+ const date = new Date()
21
+ date.setHours(hours, minutes, 0, 0)
22
+ return date
23
+ }
24
+
25
+ const format12Hour = (date) => {
26
+ const hour = date.getHours()
27
+ const ampm = hour >= 12 ? 'PM' : 'AM'
28
+ const hour12 = hour % 12 || 12
29
+ return `${hour12} ${ampm}`
30
+ }
31
+
32
+ const shouldShowYear = (date) => {
33
+ const currentYear = new Date().getFullYear()
34
+ return date.getFullYear() !== currentYear
35
+ }
36
+
37
+ export const formatTime = (seconds) => {
38
+ if (!seconds) return '0s'
39
+
40
+ const hours = Math.floor(seconds / 3600)
41
+ const minutes = Math.floor((seconds % 3600) / 60)
42
+ const remainingSeconds = Math.floor(seconds % 60)
43
+
44
+ const parts = []
45
+ if (hours > 0) parts.push(`${hours}h`)
46
+ if (minutes > 0 || (hours > 0 && remainingSeconds > 0)) parts.push(`${minutes}m`)
47
+ if (remainingSeconds > 0) parts.push(`${remainingSeconds}s`)
48
+
49
+ return parts.join(' ')
50
+ }
51
+
52
+ const parseDate = (input) => {
53
+ if (input instanceof Date) return input
54
+ if (typeof input === 'number') return new Date(input)
55
+
56
+ if (typeof input === 'string') {
57
+ if (isTimeSliceFormat(input)) {
58
+ return createTimeFromSlice(input)
59
+ }
60
+
61
+ const parsed = new Date(input)
62
+ if (isValidDate(parsed)) return parsed
63
+
64
+ const timestamp = parseInt(input, 10)
65
+ if (!Number.isNaN(timestamp)) {
66
+ const date = new Date(timestamp * 1000)
67
+ if (isValidDate(date)) return date
68
+ }
69
+ }
70
+
71
+ return null
72
+ }
73
+
74
+ const formatStrategies = {
75
+ [DATE_FORMATS.CHART_DATE]:(date) => {
76
+ const monthDay = date.toLocaleDateString('en-US', {
77
+ month :'short',
78
+ day :'numeric',
79
+ timeZone:'UTC',
80
+ })
81
+ return shouldShowYear(date)
82
+ ? `${monthDay} ${date.getFullYear()}`
83
+ : monthDay
84
+ },
85
+
86
+ [DATE_FORMATS.CHART_TIME]:(date) => format12Hour(date),
87
+
88
+ [DATE_FORMATS.HUMAN_READABLE]:(date) => date.toLocaleDateString('en-US', {
89
+ year :'numeric',
90
+ month :'short',
91
+ day :'numeric',
92
+ timeZone:'UTC',
93
+ }),
94
+
95
+ default:(date) => date.toISOString(),
96
+ }
97
+
98
+ export const formatDate = (input, format = DATE_FORMATS.HUMAN_READABLE) => {
99
+ try {
100
+ if (typeof input === 'string' && isTimeSliceFormat(input)) {
101
+ if (format === DATE_FORMATS.CHART_TIME || format === DATE_FORMATS.TIME) {
102
+ const date = createTimeFromSlice(input)
103
+ if (format === DATE_FORMATS.CHART_TIME) {
104
+ return format12Hour(date)
105
+ }
106
+ return date.toLocaleTimeString('en-US', {
107
+ hour :'2-digit',
108
+ minute :'2-digit',
109
+ timeZone:'UTC',
110
+ })
111
+ }
112
+ return input
113
+ }
114
+
115
+ const date = parseDate(input)
116
+ if (!date && (typeof input === 'string' || typeof input === 'number')) {
117
+ return input.toString()
118
+ }
119
+
120
+ const formatStrategy = formatStrategies[format] || formatStrategies.default
121
+ return formatStrategy(date)
122
+ } catch (error) {
123
+ return 'Invalid Date'
124
+ }
125
+ }
@@ -1 +1,2 @@
1
1
  export { useWindowSize, useDynamicPosition, useOutsideClick } from './hooks'
2
+ export { formatTime, formatDate, DATE_FORMATS } from './formatting'