@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.
- package/dist/cjs/a/Charts/AreaChart/AreaChart.js +3 -13
- package/dist/cjs/a/Charts/BarChart/BarChart.js +6 -4
- package/dist/cjs/a/Charts/Common/CustomLegend/CustomLegend.js +26 -7
- package/dist/cjs/a/Charts/Common/CustomLegend/styles.scss +41 -14
- package/dist/cjs/a/Charts/Common/CustomTooltipContent/CustomTooltipContent.js +18 -7
- package/dist/cjs/a/Charts/Common/YLabelsDropDown/YlabelsDropDown.js +3 -4
- package/dist/cjs/a/Charts/Common/YLabelsDropDown/styles.scss +7 -6
- package/dist/cjs/a/Charts/PieChart/PieChart.js +99 -0
- package/dist/cjs/a/Charts/PieChart/index.js +13 -0
- package/dist/cjs/a/Charts/PieChart/styles.scss +48 -0
- package/dist/cjs/a/Charts/index.js +8 -1
- package/dist/cjs/a/Notification/styles.scss +17 -5
- package/dist/cjs/a/index.js +6 -0
- package/dist/cjs/f/FormInput/FormInput.js +1 -1
- package/dist/cjs/f/fields/LatexPreviewInput/LatexPreviewInput.js +1 -1
- package/dist/cjs/f/fields/LatexPreviewInput/styles.scss +1 -0
- package/dist/cjs/f/fields/TextareaInput/TextareaInput.js +4 -2
- package/dist/cjs/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +27 -1
- package/dist/cjs/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +15 -0
- package/dist/cjs/g/FormBuilder/common/Builder/common/Section/Section.js +6 -2
- package/dist/cjs/g/FormBuilder/common/Renderer/Renderer.js +6 -0
- package/dist/cjs/utils/applyCharacterLimit.js +75 -0
- package/dist/cjs/utils/formatting.js +10 -2
- package/dist/cjs/utils/index.js +14 -1
- package/dist/es/a/Charts/AreaChart/AreaChart.js +3 -13
- package/dist/es/a/Charts/BarChart/BarChart.js +6 -4
- package/dist/es/a/Charts/Common/CustomLegend/CustomLegend.js +38 -21
- package/dist/es/a/Charts/Common/CustomLegend/styles.scss +41 -14
- package/dist/es/a/Charts/Common/CustomTooltipContent/CustomTooltipContent.js +19 -8
- package/dist/es/a/Charts/Common/YLabelsDropDown/YlabelsDropDown.js +3 -5
- package/dist/es/a/Charts/Common/YLabelsDropDown/styles.scss +7 -6
- package/dist/es/a/Charts/PieChart/PieChart.js +89 -0
- package/dist/es/a/Charts/PieChart/index.js +1 -0
- package/dist/es/a/Charts/PieChart/styles.scss +48 -0
- package/dist/es/a/Charts/index.js +2 -1
- package/dist/es/a/Notification/styles.scss +17 -5
- package/dist/es/a/index.js +1 -1
- package/dist/es/f/FormInput/FormInput.js +1 -1
- package/dist/es/f/fields/LatexPreviewInput/LatexPreviewInput.js +1 -1
- package/dist/es/f/fields/LatexPreviewInput/styles.scss +1 -0
- package/dist/es/f/fields/TextareaInput/TextareaInput.js +4 -2
- package/dist/es/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +27 -1
- package/dist/es/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +15 -0
- package/dist/es/g/FormBuilder/common/Builder/common/Section/Section.js +6 -2
- package/dist/es/g/FormBuilder/common/Renderer/Renderer.js +6 -0
- package/dist/es/utils/applyCharacterLimit.js +67 -0
- package/dist/es/utils/formatting.js +7 -0
- package/dist/es/utils/index.js +2 -1
- package/package.json +3 -3
- package/src/stories/a/AreaChart.stories.jsx +1 -1
- package/src/stories/a/BarChart.stories.jsx +1 -1
- package/src/stories/a/PieChart.stories.jsx +53 -0
- package/src/ui/a/Charts/AreaChart/AreaChart.jsx +8 -14
- package/src/ui/a/Charts/BarChart/BarChart.jsx +4 -2
- package/src/ui/a/Charts/Common/CustomLegend/CustomLegend.jsx +54 -29
- package/src/ui/a/Charts/Common/CustomLegend/styles.scss +41 -14
- package/src/ui/a/Charts/Common/CustomTooltipContent/CustomTooltipContent.jsx +25 -13
- package/src/ui/a/Charts/Common/YLabelsDropDown/YlabelsDropDown.jsx +4 -4
- package/src/ui/a/Charts/Common/YLabelsDropDown/styles.scss +7 -6
- package/src/ui/a/Charts/PieChart/PieChart.jsx +125 -0
- package/src/ui/a/Charts/PieChart/index.js +1 -0
- package/src/ui/a/Charts/PieChart/styles.scss +48 -0
- package/src/ui/a/Charts/index.js +1 -0
- package/src/ui/a/Notification/styles.scss +17 -5
- package/src/ui/a/index.js +1 -1
- package/src/ui/f/FormInput/FormInput.jsx +1 -0
- package/src/ui/f/fields/LatexPreviewInput/LatexPreviewInput.jsx +1 -0
- package/src/ui/f/fields/LatexPreviewInput/styles.scss +1 -0
- package/src/ui/f/fields/TextareaInput/TextareaInput.jsx +2 -0
- package/src/ui/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.jsx +34 -0
- package/src/ui/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +15 -0
- package/src/ui/g/FormBuilder/common/Builder/common/Section/Section.jsx +10 -2
- package/src/ui/g/FormBuilder/common/Renderer/Renderer.jsx +5 -0
- package/src/ui/g/FormBuilder/common/Renderer/common/Section/Section.jsx +0 -1
- package/src/ui/utils/applyCharacterLimit.js +80 -0
- package/src/ui/utils/formatting.js +8 -0
- package/src/ui/utils/index.js +4 -1
- 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
|
|
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={
|
|
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>
|
|
@@ -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
|
+
}
|
package/src/ui/utils/index.js
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
export { useWindowSize, useDynamicPosition, useOutsideClick } from './hooks'
|
|
2
|
-
export {
|
|
2
|
+
export {
|
|
3
|
+
formatTime, formatDate, DATE_FORMATS, snakeCaseToTitleCase,
|
|
4
|
+
} from './formatting'
|
|
5
|
+
export { applyCharacterLimit } from './applyCharacterLimit'
|