@pareto-engineering/design-system 5.0.0 → 5.0.2
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/{AreaChart → Charts/AreaChart}/AreaChart.js +89 -73
- package/dist/cjs/a/Charts/AreaChart/styles.scss +48 -0
- package/dist/cjs/a/Charts/BarChart/BarChart.js +137 -0
- package/dist/cjs/a/Charts/BarChart/index.js +13 -0
- package/dist/cjs/a/Charts/BarChart/styles.scss +48 -0
- package/dist/cjs/a/Charts/Common/CustomLegend/CustomLegend.js +88 -0
- package/dist/cjs/a/Charts/Common/CustomLegend/index.js +13 -0
- package/dist/cjs/a/Charts/Common/CustomLegend/styles.scss +67 -0
- package/dist/cjs/a/Charts/Common/CustomTooltipContent/CustomTooltipContent.js +97 -0
- package/dist/cjs/a/Charts/Common/CustomTooltipContent/index.js +13 -0
- package/dist/cjs/a/Charts/Common/CustomTooltipContent/styles.scss +22 -0
- package/dist/cjs/a/Charts/Common/YLabelsDropDown/YlabelsDropDown.js +97 -0
- package/dist/cjs/a/Charts/Common/YLabelsDropDown/index.js +13 -0
- package/dist/cjs/a/Charts/Common/YLabelsDropDown/styles.scss +89 -0
- package/dist/cjs/a/Charts/Common/index.js +26 -0
- 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 +26 -0
- package/dist/cjs/a/Tooltip/styles.scss +1 -1
- package/dist/cjs/a/index.js +14 -2
- package/dist/cjs/f/FormInput/FormInput.js +6 -0
- package/dist/cjs/f/fields/FileUpload/FileUpload.js +18 -4
- package/dist/cjs/f/fields/LatexPreviewInput/LatexPreviewInput.js +78 -0
- package/dist/cjs/f/fields/LatexPreviewInput/convertLatexToHtml.js +46 -0
- package/dist/cjs/f/fields/LatexPreviewInput/index.js +20 -0
- package/dist/cjs/f/fields/LatexPreviewInput/styles.scss +24 -0
- package/dist/cjs/f/fields/index.js +13 -0
- package/dist/cjs/g/FormBuilder/FormBuilder.js +3 -6
- package/dist/cjs/g/FormBuilder/common/Builder/Builder.js +1 -3
- package/dist/cjs/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +5 -7
- package/dist/cjs/g/FormBuilder/common/Builder/common/Section/Section.js +2 -4
- package/dist/cjs/g/FormBuilder/common/Renderer/Renderer.js +2 -4
- package/dist/cjs/g/FormBuilder/common/Renderer/common/Section/Section.js +2 -10
- package/dist/cjs/utils/formatting.js +119 -0
- package/dist/cjs/utils/index.js +26 -1
- package/dist/es/a/{AreaChart → Charts/AreaChart}/AreaChart.js +88 -69
- package/dist/es/a/Charts/AreaChart/styles.scss +48 -0
- package/dist/es/a/Charts/BarChart/BarChart.js +128 -0
- package/dist/es/a/Charts/BarChart/index.js +1 -0
- package/dist/es/a/Charts/BarChart/styles.scss +48 -0
- package/dist/es/a/Charts/Common/CustomLegend/CustomLegend.js +76 -0
- package/dist/es/a/Charts/Common/CustomLegend/index.js +1 -0
- package/dist/es/a/Charts/Common/CustomLegend/styles.scss +67 -0
- package/dist/es/a/Charts/Common/CustomTooltipContent/CustomTooltipContent.js +87 -0
- package/dist/es/a/Charts/Common/CustomTooltipContent/index.js +1 -0
- package/dist/es/a/Charts/Common/CustomTooltipContent/styles.scss +22 -0
- package/dist/es/a/Charts/Common/YLabelsDropDown/YlabelsDropDown.js +86 -0
- package/dist/es/a/Charts/Common/YLabelsDropDown/index.js +1 -0
- package/dist/es/a/Charts/Common/YLabelsDropDown/styles.scss +89 -0
- package/dist/es/a/Charts/Common/index.js +3 -0
- 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 +3 -0
- package/dist/es/a/Tooltip/styles.scss +1 -1
- package/dist/es/a/index.js +1 -1
- package/dist/es/f/FormInput/FormInput.js +7 -1
- package/dist/es/f/fields/FileUpload/FileUpload.js +18 -4
- package/dist/es/f/fields/LatexPreviewInput/LatexPreviewInput.js +70 -0
- package/dist/es/f/fields/LatexPreviewInput/convertLatexToHtml.js +31 -0
- package/dist/es/f/fields/LatexPreviewInput/index.js +3 -0
- package/dist/es/f/fields/LatexPreviewInput/styles.scss +24 -0
- package/dist/es/f/fields/index.js +1 -0
- package/dist/es/g/FormBuilder/FormBuilder.js +3 -6
- package/dist/es/g/FormBuilder/common/Builder/Builder.js +1 -3
- package/dist/es/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +5 -7
- package/dist/es/g/FormBuilder/common/Builder/common/Section/Section.js +2 -4
- package/dist/es/g/FormBuilder/common/Renderer/Renderer.js +2 -4
- package/dist/es/g/FormBuilder/common/Renderer/common/Section/Section.js +32 -42
- package/dist/es/utils/formatting.js +109 -0
- package/dist/es/utils/index.js +2 -1
- package/jest.config.js +3 -0
- package/package.json +7 -3
- package/src/stories/a/AreaChart.stories.jsx +1 -1
- package/src/stories/a/BarChart.stories.jsx +89 -0
- package/src/stories/a/PieChart.stories.jsx +53 -0
- package/src/ui/a/{AreaChart → Charts/AreaChart}/AreaChart.jsx +114 -65
- package/src/ui/a/Charts/AreaChart/styles.scss +48 -0
- package/src/ui/a/Charts/BarChart/BarChart.jsx +167 -0
- package/src/ui/a/Charts/BarChart/index.js +1 -0
- package/src/ui/a/Charts/BarChart/styles.scss +48 -0
- package/src/ui/a/Charts/Common/CustomLegend/CustomLegend.jsx +109 -0
- package/src/ui/a/Charts/Common/CustomLegend/index.js +1 -0
- package/src/ui/a/Charts/Common/CustomLegend/styles.scss +67 -0
- package/src/ui/a/Charts/Common/CustomTooltipContent/CustomTooltipContent.jsx +117 -0
- package/src/ui/a/Charts/Common/CustomTooltipContent/index.js +1 -0
- package/src/ui/a/Charts/Common/CustomTooltipContent/styles.scss +22 -0
- package/src/ui/a/Charts/Common/YLabelsDropDown/YlabelsDropDown.jsx +121 -0
- package/src/ui/a/Charts/Common/YLabelsDropDown/index.js +1 -0
- package/src/ui/a/Charts/Common/YLabelsDropDown/styles.scss +89 -0
- package/src/ui/a/Charts/Common/index.js +3 -0
- 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 +3 -0
- package/src/ui/a/Tooltip/styles.scss +1 -1
- package/src/ui/a/index.js +1 -1
- package/src/ui/f/FormInput/FormInput.jsx +11 -0
- package/src/ui/f/fields/FileUpload/FileUpload.jsx +24 -4
- package/src/ui/f/fields/LatexPreviewInput/LatexPreviewInput.jsx +91 -0
- package/src/ui/f/fields/LatexPreviewInput/convertLatexToHtml.jsx +38 -0
- package/src/ui/f/fields/LatexPreviewInput/index.js +3 -0
- package/src/ui/f/fields/LatexPreviewInput/styles.scss +24 -0
- package/src/ui/f/fields/index.js +4 -0
- package/src/ui/g/FormBuilder/FormBuilder.jsx +0 -3
- package/src/ui/g/FormBuilder/common/Builder/Builder.jsx +0 -2
- package/src/ui/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.jsx +4 -7
- package/src/ui/g/FormBuilder/common/Builder/common/Section/Section.jsx +0 -2
- package/src/ui/g/FormBuilder/common/Renderer/Renderer.jsx +0 -2
- package/src/ui/g/FormBuilder/common/Renderer/common/Section/Section.jsx +49 -64
- package/src/ui/utils/formatting.js +133 -0
- package/src/ui/utils/index.js +3 -0
- package/tests/__snapshots__/Storyshots.test.js.snap +2227 -296
- package/tests/emptyMock.js +3 -0
- package/tests/mockTextEncoder.js +7 -0
- package/tests/test-setup.js +7 -0
- package/dist/cjs/a/AreaChart/styles.scss +0 -89
- package/dist/es/a/AreaChart/styles.scss +0 -89
- package/src/ui/a/AreaChart/styles.scss +0 -89
- /package/dist/cjs/a/{AreaChart → Charts/AreaChart}/index.js +0 -0
- /package/dist/es/a/{AreaChart → Charts/AreaChart}/index.js +0 -0
- /package/src/ui/a/{AreaChart → Charts/AreaChart}/index.js +0 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
|
|
3
|
+
import PropTypes from 'prop-types'
|
|
4
|
+
|
|
5
|
+
import styleNames from '@pareto-engineering/bem/exports'
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
formatTime, formatDate, DATE_FORMATS, snakeCaseToTitleCase,
|
|
9
|
+
} from 'ui/utils'
|
|
10
|
+
|
|
11
|
+
import './styles.scss'
|
|
12
|
+
|
|
13
|
+
const baseClassName = styleNames.base
|
|
14
|
+
|
|
15
|
+
const componentClassName = 'custom-tooltip-content'
|
|
16
|
+
|
|
17
|
+
const CustomTooltipContent = ({
|
|
18
|
+
id,
|
|
19
|
+
className: userClassName,
|
|
20
|
+
dateFormat,
|
|
21
|
+
isTimeFormat,
|
|
22
|
+
isDateValue,
|
|
23
|
+
active,
|
|
24
|
+
payload,
|
|
25
|
+
label,
|
|
26
|
+
}) => {
|
|
27
|
+
const formatLabelValue = (value) => {
|
|
28
|
+
if (isTimeFormat) {
|
|
29
|
+
return formatTime(value)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (typeof value === 'number') {
|
|
33
|
+
if (Number.isInteger(value)) return value
|
|
34
|
+
return value.toFixed(2)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return value
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (active && payload && payload.length) {
|
|
41
|
+
const newPayload = payload.filter((item) => item.name !== 'bounds')
|
|
42
|
+
return (
|
|
43
|
+
<div
|
|
44
|
+
id={id}
|
|
45
|
+
className={[
|
|
46
|
+
baseClassName,
|
|
47
|
+
componentClassName,
|
|
48
|
+
userClassName,
|
|
49
|
+
]
|
|
50
|
+
.filter((e) => e)
|
|
51
|
+
.join(' ')}
|
|
52
|
+
>
|
|
53
|
+
<p className="label">
|
|
54
|
+
{isDateValue ? formatDate(label, dateFormat) : label}
|
|
55
|
+
</p>
|
|
56
|
+
{newPayload.map((entry) => (
|
|
57
|
+
<p className="label" key={`${entry.name}`} style={{ color: entry.color, textTransform: 'capitalize' }}>
|
|
58
|
+
{`${snakeCaseToTitleCase(entry.name)}: ${formatLabelValue(entry.value)}`}
|
|
59
|
+
</p>
|
|
60
|
+
))}
|
|
61
|
+
</div>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
return null
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
CustomTooltipContent.propTypes = {
|
|
68
|
+
/**
|
|
69
|
+
* The id of the dropdown component.
|
|
70
|
+
*/
|
|
71
|
+
id:PropTypes.string,
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Additional class names for the dropdown component.
|
|
75
|
+
*/
|
|
76
|
+
className:PropTypes.string,
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Flag on whether it is a timeformat or not
|
|
80
|
+
*/
|
|
81
|
+
isTimeFormat:PropTypes.bool,
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The type of format for the datetime value
|
|
85
|
+
*/
|
|
86
|
+
dateFormat:PropTypes.oneOf(Object.values(DATE_FORMATS)),
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Flag on whether the label is a date value or not
|
|
90
|
+
*/
|
|
91
|
+
isDateValue:PropTypes.bool,
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* If set true, the tooltip is displayed.
|
|
95
|
+
* If set false, the tooltip is hidden, usually calculated internally.
|
|
96
|
+
*/
|
|
97
|
+
active:PropTypes.bool.isRequired,
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The source data of the content to be displayed in the tooltip,
|
|
101
|
+
* always calculated internally and cannot be user set.
|
|
102
|
+
*/
|
|
103
|
+
payload:PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
*The label value which is active now, usually calculated internally.
|
|
107
|
+
*/
|
|
108
|
+
label:PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
CustomTooltipContent.defaultProps = {
|
|
112
|
+
isTimeFormat:false,
|
|
113
|
+
isDateValue :true,
|
|
114
|
+
dateFormat :DATE_FORMATS.HUMAN_READABLE,
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export default CustomTooltipContent
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as CustomTooltipContent } from './CustomTooltipContent'
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
@use "@pareto-engineering/bem";
|
|
2
|
+
|
|
3
|
+
$default-margin: 1rem;
|
|
4
|
+
$default-padding: 1rem;
|
|
5
|
+
$default-text-font-size: calc(var(--s-1) * 1rem);
|
|
6
|
+
$default-border-radius: .25rem;
|
|
7
|
+
$default-border-line-width: .0625rem;
|
|
8
|
+
|
|
9
|
+
.#{bem.$base} {
|
|
10
|
+
&.custom-tooltip-content {
|
|
11
|
+
background-color: var(--background-far);
|
|
12
|
+
border: $default-border-line-width solid var(--ui-lines);
|
|
13
|
+
border-radius: $default-border-radius;
|
|
14
|
+
padding: calc($default-padding * .25);
|
|
15
|
+
|
|
16
|
+
.label {
|
|
17
|
+
color: var(--hard-paragraph);
|
|
18
|
+
font-size: $default-text-font-size;
|
|
19
|
+
margin: calc($default-margin * .25);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// DropdownStatus.js
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
|
|
4
|
+
import PropTypes from 'prop-types'
|
|
5
|
+
|
|
6
|
+
import styleNames from '@pareto-engineering/bem/exports'
|
|
7
|
+
|
|
8
|
+
import { snakeCaseToTitleCase } from 'ui/utils'
|
|
9
|
+
|
|
10
|
+
import './styles.scss'
|
|
11
|
+
|
|
12
|
+
const baseClassName = styleNames.base
|
|
13
|
+
|
|
14
|
+
const componentClassName = 'y-labels-dropdown'
|
|
15
|
+
|
|
16
|
+
const YLabelsDropDown = ({
|
|
17
|
+
id,
|
|
18
|
+
className: userClassName,
|
|
19
|
+
placeholder,
|
|
20
|
+
selectedYLabels,
|
|
21
|
+
setSelectedYLabels,
|
|
22
|
+
allYLabels,
|
|
23
|
+
}) => {
|
|
24
|
+
const [isOpen, setIsOpen] = React.useState(false)
|
|
25
|
+
|
|
26
|
+
const toggleYLabel = (yLabel) => {
|
|
27
|
+
setSelectedYLabels((prev) => (prev.some((label) => label.label === yLabel.label)
|
|
28
|
+
? prev.filter((label) => label.label !== yLabel.label)
|
|
29
|
+
: [...prev, yLabel]),
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<div
|
|
35
|
+
id={id}
|
|
36
|
+
className={[
|
|
37
|
+
baseClassName,
|
|
38
|
+
componentClassName,
|
|
39
|
+
userClassName,
|
|
40
|
+
]
|
|
41
|
+
.filter((e) => e)
|
|
42
|
+
.join(' ')}
|
|
43
|
+
>
|
|
44
|
+
<button
|
|
45
|
+
className="dropdown-button"
|
|
46
|
+
onClick={() => setIsOpen(!isOpen)}
|
|
47
|
+
type="button"
|
|
48
|
+
>
|
|
49
|
+
{placeholder}
|
|
50
|
+
<span className={`icon ${isOpen ? styleNames.modifierOpen : ''}`}>
|
|
51
|
+
W
|
|
52
|
+
</span>
|
|
53
|
+
</button>
|
|
54
|
+
<div className={`dropdown-content ${isOpen ? styleNames.modifierOpen : ''}`}>
|
|
55
|
+
{allYLabels.map((item) => (
|
|
56
|
+
// eslint-disable-next-line max-len
|
|
57
|
+
// eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events
|
|
58
|
+
<div
|
|
59
|
+
key={item.label}
|
|
60
|
+
className={`dropdown-item ${selectedYLabels.some((label) => label.label === item.label) ? styleNames.modifierActive : ''}`}
|
|
61
|
+
// eslint-disable-next-line jsx-a11y/click-events-have-key-events
|
|
62
|
+
onClick={() => toggleYLabel(item)}
|
|
63
|
+
>
|
|
64
|
+
<span
|
|
65
|
+
className="status-dot"
|
|
66
|
+
style={{ backgroundColor: item.color }}
|
|
67
|
+
/>
|
|
68
|
+
{snakeCaseToTitleCase(item.label)}
|
|
69
|
+
{selectedYLabels.some((label) => label.label === item.label) && (
|
|
70
|
+
<span className="icon checkmark">I</span>
|
|
71
|
+
)}
|
|
72
|
+
</div>
|
|
73
|
+
))}
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
YLabelsDropDown.propTypes = {
|
|
80
|
+
/**
|
|
81
|
+
* The id of the dropdown component.
|
|
82
|
+
*/
|
|
83
|
+
id:PropTypes.string,
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Additional class names for the dropdown component.
|
|
87
|
+
*/
|
|
88
|
+
className:PropTypes.string,
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Placeholder text for the dropdown button.
|
|
92
|
+
*/
|
|
93
|
+
placeholder:PropTypes.string,
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Array of selected Y labels with their corresponding colors.
|
|
97
|
+
*/
|
|
98
|
+
selectedYLabels:PropTypes.arrayOf(PropTypes.shape({
|
|
99
|
+
label:PropTypes.string,
|
|
100
|
+
color:PropTypes.string,
|
|
101
|
+
})),
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Function to set the selected Y labels.
|
|
105
|
+
*/
|
|
106
|
+
setSelectedYLabels:PropTypes.func,
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Array of all Y labels with their corresponding colors.
|
|
110
|
+
*/
|
|
111
|
+
allYLabels:PropTypes.arrayOf(PropTypes.shape({
|
|
112
|
+
label:PropTypes.string,
|
|
113
|
+
color:PropTypes.string,
|
|
114
|
+
})),
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
YLabelsDropDown.defaultProps = {
|
|
118
|
+
placeholder:'Select Item',
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export default YLabelsDropDown
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as YLabelsDropDown } from './YlabelsDropDown'
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
@use "@pareto-engineering/bem";
|
|
2
|
+
|
|
3
|
+
$default-margin: 1rem;
|
|
4
|
+
$default-border: var(--theme-default-input-border);
|
|
5
|
+
$default-border-radius: var(--theme-default-input-border-radius);
|
|
6
|
+
$default-padding: 1rem;
|
|
7
|
+
$default-width: 15rem;
|
|
8
|
+
$default-box-shadow: 0 .25rem .75rem var(--ui-lines);
|
|
9
|
+
$default-dot-width: .5rem;
|
|
10
|
+
$default-dot-height: .5rem;
|
|
11
|
+
$default-checkmark-font-size: calc(var(--s-1) * .75rem);
|
|
12
|
+
|
|
13
|
+
.#{bem.$base} {
|
|
14
|
+
&.y-labels-dropdown {
|
|
15
|
+
display: inline-block;
|
|
16
|
+
position: relative;
|
|
17
|
+
|
|
18
|
+
.dropdown-button {
|
|
19
|
+
align-items: center;
|
|
20
|
+
background-color: var(--background-far);
|
|
21
|
+
border: $default-border;
|
|
22
|
+
border-radius: calc($default-border-radius / 2);
|
|
23
|
+
color: var(--hard-paragraph);
|
|
24
|
+
cursor: pointer;
|
|
25
|
+
display: flex;
|
|
26
|
+
justify-content: space-between;
|
|
27
|
+
padding: calc($default-padding * .5);
|
|
28
|
+
text-align: left;
|
|
29
|
+
width: $default-width;
|
|
30
|
+
|
|
31
|
+
.icon {
|
|
32
|
+
color: var(--hard-ui-icons);
|
|
33
|
+
font-size: calc($default-checkmark-font-size * 1.25);
|
|
34
|
+
|
|
35
|
+
&.#{bem.$modifier-open} {
|
|
36
|
+
transform: rotate(180deg);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.dropdown-content {
|
|
42
|
+
background-color: var(--background-far);
|
|
43
|
+
border-radius: $default-border-radius;
|
|
44
|
+
box-shadow: $default-box-shadow;
|
|
45
|
+
display: none;
|
|
46
|
+
margin-top: calc($default-margin * .125);
|
|
47
|
+
position: absolute;
|
|
48
|
+
width: $default-width;
|
|
49
|
+
z-index: 1;
|
|
50
|
+
|
|
51
|
+
&.#{bem.$modifier-open} {
|
|
52
|
+
display: block;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.dropdown-item {
|
|
56
|
+
align-items: center;
|
|
57
|
+
border-radius: calc($default-border-radius / 2);
|
|
58
|
+
color: var(--paragraph);
|
|
59
|
+
cursor: pointer;
|
|
60
|
+
display: flex;
|
|
61
|
+
margin: calc($default-margin * .125);
|
|
62
|
+
padding: calc($default-padding * .5);
|
|
63
|
+
text-decoration: none;
|
|
64
|
+
|
|
65
|
+
&.#{bem.$modifier-active} {
|
|
66
|
+
background-color: var(--background-near);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
&:hover {
|
|
70
|
+
background-color: var(--background-near);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.status-dot {
|
|
74
|
+
border-radius: 50%;
|
|
75
|
+
display: inline-block;
|
|
76
|
+
height: $default-dot-height;
|
|
77
|
+
margin-right: calc($default-margin * .5);
|
|
78
|
+
width: $default-dot-width;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.checkmark {
|
|
82
|
+
color: var(--hard-main);
|
|
83
|
+
font-size: $default-checkmark-font-size;
|
|
84
|
+
margin-left: auto;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
|
|
3
|
+
import PropTypes from 'prop-types'
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
PieChart as RechartsPieChart,
|
|
7
|
+
Pie,
|
|
8
|
+
Cell,
|
|
9
|
+
ResponsiveContainer,
|
|
10
|
+
Tooltip,
|
|
11
|
+
} from 'recharts'
|
|
12
|
+
|
|
13
|
+
import styleNames from '@pareto-engineering/bem/exports'
|
|
14
|
+
|
|
15
|
+
import { CustomLegend, CustomTooltipContent } from '../Common'
|
|
16
|
+
|
|
17
|
+
import './styles.scss'
|
|
18
|
+
|
|
19
|
+
const baseClassName = styleNames.base
|
|
20
|
+
|
|
21
|
+
const componentClassName = 'pie-chart'
|
|
22
|
+
|
|
23
|
+
const PieChart = ({
|
|
24
|
+
id,
|
|
25
|
+
className: userClassName,
|
|
26
|
+
data,
|
|
27
|
+
title,
|
|
28
|
+
valueKey,
|
|
29
|
+
labelKey,
|
|
30
|
+
colors,
|
|
31
|
+
height,
|
|
32
|
+
width,
|
|
33
|
+
innerRadius,
|
|
34
|
+
outerRadius,
|
|
35
|
+
}) => {
|
|
36
|
+
const total = data.reduce((sum, item) => sum + item[valueKey], 0)
|
|
37
|
+
|
|
38
|
+
const formattedData = data.map((item) => ({
|
|
39
|
+
...item,
|
|
40
|
+
label :item[labelKey],
|
|
41
|
+
color :colors[data.indexOf(item)],
|
|
42
|
+
percentage:((item[valueKey] / total) * 100).toFixed(0),
|
|
43
|
+
}))
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<div
|
|
47
|
+
id={id}
|
|
48
|
+
className={[
|
|
49
|
+
baseClassName,
|
|
50
|
+
componentClassName,
|
|
51
|
+
userClassName,
|
|
52
|
+
]
|
|
53
|
+
.filter((e) => e)
|
|
54
|
+
.join(' ')}
|
|
55
|
+
>
|
|
56
|
+
<div className="chart-header">
|
|
57
|
+
<h3>{title}</h3>
|
|
58
|
+
</div>
|
|
59
|
+
<div className="chart-content">
|
|
60
|
+
<ResponsiveContainer width={width} height={height}>
|
|
61
|
+
<RechartsPieChart>
|
|
62
|
+
<Pie
|
|
63
|
+
data={formattedData}
|
|
64
|
+
dataKey={valueKey}
|
|
65
|
+
nameKey={labelKey}
|
|
66
|
+
cx="50%"
|
|
67
|
+
cy="50%"
|
|
68
|
+
innerRadius={innerRadius}
|
|
69
|
+
outerRadius={outerRadius}
|
|
70
|
+
label={false}
|
|
71
|
+
paddingAngle={0}
|
|
72
|
+
>
|
|
73
|
+
{formattedData.map((entry, index) => (
|
|
74
|
+
<Cell
|
|
75
|
+
key={entry[labelKey]}
|
|
76
|
+
fill={colors[index]}
|
|
77
|
+
strokeWidth={0}
|
|
78
|
+
/>
|
|
79
|
+
))}
|
|
80
|
+
</Pie>
|
|
81
|
+
<Tooltip content={<CustomTooltipContent isDateValue={false} />} />
|
|
82
|
+
</RechartsPieChart>
|
|
83
|
+
</ResponsiveContainer>
|
|
84
|
+
<CustomLegend
|
|
85
|
+
colorsArray={colors}
|
|
86
|
+
yKeysArray={formattedData}
|
|
87
|
+
capitalizedLegend
|
|
88
|
+
orientation="vertical"
|
|
89
|
+
getLegendItemTitle={(entry) => entry[labelKey]}
|
|
90
|
+
getLegendItemSubtitle={(entry) => entry[valueKey]}
|
|
91
|
+
/>
|
|
92
|
+
</div>
|
|
93
|
+
</div>
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
PieChart.propTypes = {
|
|
98
|
+
id :PropTypes.string,
|
|
99
|
+
className:PropTypes.string,
|
|
100
|
+
data :PropTypes.arrayOf(PropTypes.shape({
|
|
101
|
+
[PropTypes.string]:PropTypes.oneOfType([
|
|
102
|
+
PropTypes.string,
|
|
103
|
+
PropTypes.number,
|
|
104
|
+
]),
|
|
105
|
+
})).isRequired,
|
|
106
|
+
title :PropTypes.string.isRequired,
|
|
107
|
+
valueKey :PropTypes.string.isRequired,
|
|
108
|
+
labelKey :PropTypes.string.isRequired,
|
|
109
|
+
colors :PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
110
|
+
height :PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
111
|
+
width :PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
112
|
+
innerRadius:PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
113
|
+
outerRadius:PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
PieChart.defaultProps = {
|
|
117
|
+
id :undefined,
|
|
118
|
+
className :undefined,
|
|
119
|
+
width :'100%',
|
|
120
|
+
height :300,
|
|
121
|
+
innerRadius:'0%',
|
|
122
|
+
outerRadius:'100%',
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export default PieChart
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as PieChart } from './PieChart'
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
@use "@pareto-engineering/bem";
|
|
2
|
+
|
|
3
|
+
$default-margin: 1rem;
|
|
4
|
+
$default-padding: 1rem;
|
|
5
|
+
$default-box-shadow: 0 .25rem .75rem var(--ui-lines);
|
|
6
|
+
$default-text-font-size: calc(var(--s-1) * 1rem);
|
|
7
|
+
|
|
8
|
+
.#{bem.$base} {
|
|
9
|
+
&.pie-chart {
|
|
10
|
+
background-color: var(--background-far);
|
|
11
|
+
border-radius: var(--theme-default-border-radius);
|
|
12
|
+
box-shadow: $default-box-shadow;
|
|
13
|
+
margin: $default-margin 0;
|
|
14
|
+
padding: $default-padding;
|
|
15
|
+
|
|
16
|
+
.chart-header {
|
|
17
|
+
align-items: center;
|
|
18
|
+
display: flex;
|
|
19
|
+
justify-content: space-between;
|
|
20
|
+
margin-bottom: $default-margin;
|
|
21
|
+
|
|
22
|
+
h3 {
|
|
23
|
+
color: var(--subtitle);
|
|
24
|
+
margin: calc($default-margin / 5);
|
|
25
|
+
text-align: left;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.chart-content {
|
|
30
|
+
align-items: flex-start;
|
|
31
|
+
display: flex;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.recharts-wrapper {
|
|
35
|
+
.recharts-surface {
|
|
36
|
+
.recharts-text {
|
|
37
|
+
fill: var(--soft-paragraph);
|
|
38
|
+
font-size: calc($default-text-font-size * .75);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.recharts-text.recharts-label {
|
|
42
|
+
fill: var(--paragraph);
|
|
43
|
+
font-size: $default-text-font-size;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -14,6 +14,7 @@ $default-width: var(--tooltip-width, 20rem);
|
|
|
14
14
|
background: var(--x);
|
|
15
15
|
border: var(--theme-default-border-style) var(--ui-lines);
|
|
16
16
|
border-radius: calc(var(--theme-default-border-radius) / 2);
|
|
17
|
+
min-width: $default-width;
|
|
17
18
|
opacity: 0;
|
|
18
19
|
overflow: hidden;
|
|
19
20
|
padding: $default-block-padding $default-inline-padding;
|
|
@@ -21,7 +22,6 @@ $default-width: var(--tooltip-width, 20rem);
|
|
|
21
22
|
transform: translateX(var(--horizontal, 0)) translateY(var(--vertical, 0));
|
|
22
23
|
transition: opacity .2s ease, transform .2s ease;
|
|
23
24
|
visibility: hidden;
|
|
24
|
-
width: $default-width;
|
|
25
25
|
z-index: 10;
|
|
26
26
|
|
|
27
27
|
&.top {
|
package/src/ui/a/index.js
CHANGED
|
@@ -30,4 +30,4 @@ export { ToggleSwitch } from './ToggleSwitch'
|
|
|
30
30
|
export { XMLEditor } from './XMLEditor'
|
|
31
31
|
export { DatePicker } from './DatePicker'
|
|
32
32
|
export { Tooltip } from './Tooltip'
|
|
33
|
-
export { AreaChart } from './
|
|
33
|
+
export { AreaChart, BarChart, PieChart } from './Charts'
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
LinkInput,
|
|
19
19
|
EditorInput,
|
|
20
20
|
FileUpload,
|
|
21
|
+
LatexPreviewInput,
|
|
21
22
|
} from '../fields'
|
|
22
23
|
|
|
23
24
|
import './styles.scss'
|
|
@@ -158,6 +159,16 @@ const FormInput = ({
|
|
|
158
159
|
)
|
|
159
160
|
}
|
|
160
161
|
|
|
162
|
+
if (type === 'latex-preview-input') {
|
|
163
|
+
return (
|
|
164
|
+
<LatexPreviewInput
|
|
165
|
+
className={newClassName}
|
|
166
|
+
disabled={disabled}
|
|
167
|
+
{...otherProps}
|
|
168
|
+
/>
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
|
|
161
172
|
if (extraTypes?.[type]) {
|
|
162
173
|
const Component = extraTypes[type]
|
|
163
174
|
return (
|
|
@@ -19,6 +19,16 @@ const baseClassName = styleNames.base
|
|
|
19
19
|
|
|
20
20
|
const componentClassName = 'file-upload'
|
|
21
21
|
|
|
22
|
+
const generateUniqueFileName = (originalName, existingFileNames) => {
|
|
23
|
+
const lastDotIndex = originalName.lastIndexOf('.')
|
|
24
|
+
const name = originalName.substring(0, lastDotIndex)
|
|
25
|
+
const ext = originalName.split('.').pop()
|
|
26
|
+
const numDuplicates = existingFileNames.filter(
|
|
27
|
+
(existingFileName) => existingFileName?.startsWith(name),
|
|
28
|
+
).length
|
|
29
|
+
return numDuplicates > 0 ? `${name} (${numDuplicates}).${ext}` : originalName
|
|
30
|
+
}
|
|
31
|
+
|
|
22
32
|
/**
|
|
23
33
|
* This is the component description.
|
|
24
34
|
*/
|
|
@@ -54,7 +64,7 @@ const FileUpload = ({
|
|
|
54
64
|
|
|
55
65
|
const handleChange = (event) => {
|
|
56
66
|
setTouched(true, false)
|
|
57
|
-
|
|
67
|
+
let newFiles = Array.from(event.currentTarget.files)
|
|
58
68
|
const currentFiles = value || []
|
|
59
69
|
|
|
60
70
|
const currentCount = currentFiles.length + newFiles.length
|
|
@@ -63,13 +73,23 @@ const FileUpload = ({
|
|
|
63
73
|
return
|
|
64
74
|
}
|
|
65
75
|
|
|
76
|
+
const uploadedFiles = Object.keys(uploadStatus) || []
|
|
77
|
+
|
|
66
78
|
const duplicateFiles = newFiles.filter(
|
|
67
|
-
(newFile) =>
|
|
79
|
+
(newFile) => uploadedFiles.some((uploadedFile) => uploadedFile === newFile.name),
|
|
68
80
|
)
|
|
69
81
|
|
|
70
82
|
if (duplicateFiles.length > 0) {
|
|
71
|
-
|
|
72
|
-
|
|
83
|
+
newFiles = newFiles.map((file) => {
|
|
84
|
+
if (duplicateFiles.some((duplicateFile) => duplicateFile.name === file.name)) {
|
|
85
|
+
return new File(
|
|
86
|
+
[file],
|
|
87
|
+
generateUniqueFileName(file.name, uploadedFiles),
|
|
88
|
+
{ type: file.type },
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
return file
|
|
92
|
+
})
|
|
73
93
|
}
|
|
74
94
|
|
|
75
95
|
if (maxSize) {
|