@pareto-engineering/design-system 5.0.5 → 5.1.0

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 (78) hide show
  1. package/dist/cjs/a/Charts/AreaChart/AreaChart.js +3 -13
  2. package/dist/cjs/a/Charts/BarChart/BarChart.js +6 -4
  3. package/dist/cjs/a/Charts/Common/CustomLegend/CustomLegend.js +26 -7
  4. package/dist/cjs/a/Charts/Common/CustomLegend/styles.scss +41 -14
  5. package/dist/cjs/a/Charts/Common/CustomTooltipContent/CustomTooltipContent.js +18 -7
  6. package/dist/cjs/a/Charts/Common/YLabelsDropDown/YlabelsDropDown.js +3 -4
  7. package/dist/cjs/a/Charts/Common/YLabelsDropDown/styles.scss +7 -6
  8. package/dist/cjs/a/Charts/PieChart/PieChart.js +99 -0
  9. package/dist/cjs/a/Charts/PieChart/index.js +13 -0
  10. package/dist/cjs/a/Charts/PieChart/styles.scss +48 -0
  11. package/dist/cjs/a/Charts/index.js +8 -1
  12. package/dist/cjs/a/Notification/styles.scss +17 -5
  13. package/dist/cjs/a/index.js +6 -0
  14. package/dist/cjs/f/FormInput/FormInput.js +1 -1
  15. package/dist/cjs/f/fields/LatexPreviewInput/LatexPreviewInput.js +1 -1
  16. package/dist/cjs/f/fields/LatexPreviewInput/styles.scss +1 -0
  17. package/dist/cjs/f/fields/TextareaInput/TextareaInput.js +4 -2
  18. package/dist/cjs/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +27 -1
  19. package/dist/cjs/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +15 -0
  20. package/dist/cjs/g/FormBuilder/common/Builder/common/Section/Section.js +6 -2
  21. package/dist/cjs/g/FormBuilder/common/Renderer/Renderer.js +6 -0
  22. package/dist/cjs/utils/applyCharacterLimit.js +75 -0
  23. package/dist/cjs/utils/formatting.js +10 -2
  24. package/dist/cjs/utils/index.js +14 -1
  25. package/dist/es/a/Charts/AreaChart/AreaChart.js +3 -13
  26. package/dist/es/a/Charts/BarChart/BarChart.js +6 -4
  27. package/dist/es/a/Charts/Common/CustomLegend/CustomLegend.js +38 -21
  28. package/dist/es/a/Charts/Common/CustomLegend/styles.scss +41 -14
  29. package/dist/es/a/Charts/Common/CustomTooltipContent/CustomTooltipContent.js +19 -8
  30. package/dist/es/a/Charts/Common/YLabelsDropDown/YlabelsDropDown.js +3 -5
  31. package/dist/es/a/Charts/Common/YLabelsDropDown/styles.scss +7 -6
  32. package/dist/es/a/Charts/PieChart/PieChart.js +89 -0
  33. package/dist/es/a/Charts/PieChart/index.js +1 -0
  34. package/dist/es/a/Charts/PieChart/styles.scss +48 -0
  35. package/dist/es/a/Charts/index.js +2 -1
  36. package/dist/es/a/Notification/styles.scss +17 -5
  37. package/dist/es/a/index.js +1 -1
  38. package/dist/es/f/FormInput/FormInput.js +1 -1
  39. package/dist/es/f/fields/LatexPreviewInput/LatexPreviewInput.js +1 -1
  40. package/dist/es/f/fields/LatexPreviewInput/styles.scss +1 -0
  41. package/dist/es/f/fields/TextareaInput/TextareaInput.js +4 -2
  42. package/dist/es/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +27 -1
  43. package/dist/es/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +15 -0
  44. package/dist/es/g/FormBuilder/common/Builder/common/Section/Section.js +6 -2
  45. package/dist/es/g/FormBuilder/common/Renderer/Renderer.js +6 -0
  46. package/dist/es/utils/applyCharacterLimit.js +67 -0
  47. package/dist/es/utils/formatting.js +7 -0
  48. package/dist/es/utils/index.js +2 -1
  49. package/package.json +3 -3
  50. package/src/stories/a/AreaChart.stories.jsx +1 -1
  51. package/src/stories/a/BarChart.stories.jsx +1 -1
  52. package/src/stories/a/PieChart.stories.jsx +53 -0
  53. package/src/ui/a/Charts/AreaChart/AreaChart.jsx +8 -14
  54. package/src/ui/a/Charts/BarChart/BarChart.jsx +4 -2
  55. package/src/ui/a/Charts/Common/CustomLegend/CustomLegend.jsx +54 -29
  56. package/src/ui/a/Charts/Common/CustomLegend/styles.scss +41 -14
  57. package/src/ui/a/Charts/Common/CustomTooltipContent/CustomTooltipContent.jsx +25 -13
  58. package/src/ui/a/Charts/Common/YLabelsDropDown/YlabelsDropDown.jsx +4 -4
  59. package/src/ui/a/Charts/Common/YLabelsDropDown/styles.scss +7 -6
  60. package/src/ui/a/Charts/PieChart/PieChart.jsx +125 -0
  61. package/src/ui/a/Charts/PieChart/index.js +1 -0
  62. package/src/ui/a/Charts/PieChart/styles.scss +48 -0
  63. package/src/ui/a/Charts/index.js +1 -0
  64. package/src/ui/a/Notification/styles.scss +17 -5
  65. package/src/ui/a/index.js +1 -1
  66. package/src/ui/f/FormInput/FormInput.jsx +1 -0
  67. package/src/ui/f/fields/LatexPreviewInput/LatexPreviewInput.jsx +1 -0
  68. package/src/ui/f/fields/LatexPreviewInput/styles.scss +1 -0
  69. package/src/ui/f/fields/TextareaInput/TextareaInput.jsx +2 -0
  70. package/src/ui/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.jsx +34 -0
  71. package/src/ui/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +15 -0
  72. package/src/ui/g/FormBuilder/common/Builder/common/Section/Section.jsx +10 -2
  73. package/src/ui/g/FormBuilder/common/Renderer/Renderer.jsx +5 -0
  74. package/src/ui/g/FormBuilder/common/Renderer/common/Section/Section.jsx +0 -1
  75. package/src/ui/utils/applyCharacterLimit.js +80 -0
  76. package/src/ui/utils/formatting.js +8 -0
  77. package/src/ui/utils/index.js +4 -1
  78. package/tests/__snapshots__/Storyshots.test.js.snap +1165 -429
@@ -64,6 +64,21 @@ $default-list-width: var(--action-button-width, 18rem);
64
64
  margin-bottom: $default-margin;
65
65
  }
66
66
 
67
+ > .character-limit-container {
68
+ display: flex;
69
+ flex-direction: column;
70
+ gap: var(--gap);
71
+
72
+ > .is-required {
73
+ display: flex;
74
+ flex-direction: row;
75
+ }
76
+
77
+ > .character-limit-input {
78
+ flex-direction: column;
79
+ }
80
+ }
81
+
67
82
  > .input-options {
68
83
  display: flex;
69
84
  flex-direction: column;
@@ -62,7 +62,13 @@ const Section = ({
62
62
  const { inputs } = section
63
63
 
64
64
  useEffect(() => {
65
- const items = inputs.map((input, indx) => ({
65
+ const orderMap = new Map()
66
+ section.orderedInputDragIds.forEach(
67
+ (identifier, indx) => orderMap.set(identifier, indx),
68
+ )
69
+ const orderedInputs = inputs.sort((a, b) => orderMap.get(a.name) - orderMap.get(b.name))
70
+
71
+ const items = orderedInputs.map((input, indx) => ({
66
72
  Content:<InputBuilder
67
73
  key={input.name}
68
74
  sectionIndex={index}
@@ -75,6 +81,8 @@ const Section = ({
75
81
  setDraggableInputs(items)
76
82
  }, [inputs.length, index])
77
83
 
84
+ const dragAndDropKey = draggableInputs.map((e) => e.identifier).join(',')
85
+
78
86
  return (
79
87
  <div
80
88
  id={id}
@@ -128,7 +136,7 @@ const Section = ({
128
136
  const ids = reOrderedItems.map((e) => e.identifier)
129
137
  setFieldValue(`sections.${index}.orderedInputDragIds`, ids)
130
138
  }}
131
- key={draggableInputs.length}
139
+ key={dragAndDropKey}
132
140
  />
133
141
  <button
134
142
  type="button"
@@ -15,6 +15,7 @@ import './styles.scss'
15
15
 
16
16
  // Local Definitions
17
17
 
18
+ import { applyCharacterLimit } from 'ui/utils'
18
19
  import { Section } from './common'
19
20
 
20
21
  const baseClassName = styleNames.base
@@ -165,6 +166,10 @@ const Renderer = ({
165
166
  }
166
167
  }, [values])
167
168
 
169
+ useEffect(() => {
170
+ applyCharacterLimit({ setMaxLength: false })
171
+ }, [values])
172
+
168
173
  const hasErrors = Object.keys(errors).length > 0
169
174
  return (
170
175
  <Form>
@@ -60,7 +60,6 @@ const Section = ({
60
60
  />
61
61
  {inputs?.map((input, inputIndex) => {
62
62
  const isFileInput = input.type === 'file'
63
-
64
63
  return (
65
64
  <FormInput
66
65
  key={input.name}
@@ -0,0 +1,80 @@
1
+ export const applyCharacterLimit = (setMaxLength = true) => {
2
+ setTimeout(() => {
3
+ document.querySelectorAll("[class*='limit-character-count-']").forEach((parent) => {
4
+ const match = parent.className.match(/limit-character-count-(\d+)/)
5
+ if (!match) return
6
+
7
+ const maxLength = parseInt(match[1], 10)
8
+
9
+ const fields = parent.matches("input[type='text'], input[type='email'], input[type='password'], input[type='search'], textarea")
10
+ ? [parent]
11
+ : Array.from(parent.querySelectorAll("input[type='text'], input[type='email'], input[type='password'], input[type='search'], textarea"))
12
+
13
+ if (!fields.length) return
14
+
15
+ const characterCounterBaseClassName = 's-2 character-counter'
16
+ const characterCounterClassName = `${characterCounterBaseClassName} x-paragraph c-x`
17
+ const characterCounterWarningClassName = `${characterCounterBaseClassName} x-orange c-x`
18
+ const characterCounterErrorClassName = `${characterCounterBaseClassName} x-error c-x`
19
+
20
+ fields.forEach((field) => {
21
+ if (field.parentNode.querySelector('.character-counter')) return
22
+
23
+ if (setMaxLength) {
24
+ field.setAttribute('maxlength', maxLength)
25
+ }
26
+
27
+ const counter = document.createElement('span')
28
+ counter.className = characterCounterClassName
29
+ counter.style.position = 'absolute'
30
+ counter.style.right = '10px'
31
+ counter.style.bottom = '-20px'
32
+ counter.style.pointerEvents = 'none'
33
+
34
+ let wrapper
35
+ const { parentNode } = field
36
+ const computedStyle = window.getComputedStyle(parentNode)
37
+ if ((parentNode.style && parentNode.style.position === 'relative') || computedStyle.getPropertyValue('position') === 'relative') {
38
+ wrapper = parentNode
39
+ } else {
40
+ wrapper = document.createElement('div')
41
+ wrapper.style.position = 'relative'
42
+ wrapper.style.display = 'inline-block'
43
+ wrapper.style.width = '100%'
44
+ field.parentNode.insertBefore(wrapper, field)
45
+ wrapper.appendChild(field)
46
+ }
47
+
48
+ wrapper.appendChild(counter)
49
+
50
+ function updateCounter() {
51
+ if (field.value.length > maxLength) {
52
+ // eslint-disable-next-line no-param-reassign
53
+ field.value = field.value.substring(0, maxLength)
54
+ }
55
+
56
+ const { length } = field.value
57
+ counter.textContent = `${length}/${maxLength}`
58
+
59
+ if (length >= maxLength) {
60
+ counter.className = characterCounterErrorClassName
61
+ } else if (length >= maxLength * 0.9) {
62
+ counter.className = characterCounterWarningClassName
63
+ } else {
64
+ counter.className = characterCounterClassName
65
+ }
66
+ }
67
+
68
+ field.removeEventListener('input', updateCounter)
69
+ field.removeEventListener('paste', updateCounter)
70
+
71
+ field.addEventListener('input', updateCounter)
72
+ field.addEventListener('paste', () => {
73
+ setTimeout(updateCounter, 0)
74
+ })
75
+
76
+ updateCounter()
77
+ })
78
+ })
79
+ }, 100) // Small delay to ensure DOM is ready
80
+ }
@@ -46,6 +46,9 @@ export const formatTime = (seconds) => {
46
46
  if (minutes > 0 || (hours > 0 && remainingSeconds > 0)) parts.push(`${minutes}m`)
47
47
  if (remainingSeconds > 0) parts.push(`${remainingSeconds}s`)
48
48
 
49
+ // Cater for decimal seconds
50
+ if (parts.length === 0) return '0s'
51
+
49
52
  return parts.join(' ')
50
53
  }
51
54
 
@@ -123,3 +126,8 @@ export const formatDate = (input, format = DATE_FORMATS.HUMAN_READABLE) => {
123
126
  return 'Invalid Date'
124
127
  }
125
128
  }
129
+
130
+ export const snakeCaseToTitleCase = (word) => {
131
+ const result = word.replace(/([A-Z])/g, ' $1')
132
+ return result.charAt(0).toUpperCase() + result.slice(1)
133
+ }
@@ -1,2 +1,5 @@
1
1
  export { useWindowSize, useDynamicPosition, useOutsideClick } from './hooks'
2
- export { formatTime, formatDate, DATE_FORMATS } from './formatting'
2
+ export {
3
+ formatTime, formatDate, DATE_FORMATS, snakeCaseToTitleCase,
4
+ } from './formatting'
5
+ export { applyCharacterLimit } from './applyCharacterLimit'