@scality/core-ui 0.165.0 → 0.166.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/components/barchartv2/Barchart.component.d.ts +19 -0
- package/dist/components/barchartv2/Barchart.component.d.ts.map +1 -1
- package/dist/components/barchartv2/Barchart.component.js +31 -5
- package/dist/components/barchartv2/ChartTooltip.d.ts +18 -0
- package/dist/components/barchartv2/ChartTooltip.d.ts.map +1 -0
- package/dist/components/barchartv2/ChartTooltip.js +31 -0
- package/dist/components/barchartv2/utils.d.ts +0 -7
- package/dist/components/barchartv2/utils.d.ts.map +1 -1
- package/dist/components/barchartv2/utils.js +1 -29
- package/dist/components/chartlegend/ChartLegend.d.ts +9 -0
- package/dist/components/chartlegend/ChartLegend.d.ts.map +1 -1
- package/dist/components/chartlegend/ChartLegend.js +38 -9
- package/dist/components/chartlegend/ChartLegendWrapper.d.ts +4 -0
- package/dist/components/chartlegend/ChartLegendWrapper.d.ts.map +1 -1
- package/dist/components/chartlegend/ChartLegendWrapper.js +23 -2
- package/dist/components/constants.d.ts +2 -0
- package/dist/components/constants.d.ts.map +1 -1
- package/dist/components/constants.js +6 -0
- package/dist/components/constrainedtext/Constrainedtext.component.d.ts +3 -1
- package/dist/components/constrainedtext/Constrainedtext.component.d.ts.map +1 -1
- package/dist/components/constrainedtext/Constrainedtext.component.js +2 -2
- package/dist/components/date/FormattedDateTime.d.ts +2 -1
- package/dist/components/date/FormattedDateTime.d.ts.map +1 -1
- package/dist/components/date/FormattedDateTime.js +10 -0
- package/dist/components/linetimeseriechart/linetimeseriechart.component.d.ts +3 -1
- package/dist/components/linetimeseriechart/linetimeseriechart.component.d.ts.map +1 -1
- package/dist/components/linetimeseriechart/linetimeseriechart.component.js +5 -7
- package/dist/components/text/Text.component.js +1 -1
- package/dist/components/toast/Toast.component.d.ts.map +1 -1
- package/dist/components/toast/Toast.component.js +24 -11
- package/dist/next.d.ts +1 -0
- package/dist/next.d.ts.map +1 -1
- package/dist/next.js +1 -0
- package/package.json +1 -2
- package/src/lib/components/barchartv2/Barchart.component.test.tsx +99 -1
- package/src/lib/components/barchartv2/Barchart.component.tsx +39 -11
- package/src/lib/components/barchartv2/ChartTooltip.tsx +76 -0
- package/src/lib/components/barchartv2/utils.ts +2 -33
- package/src/lib/components/chartlegend/ChartLegend.test.tsx +218 -0
- package/src/lib/components/chartlegend/ChartLegend.tsx +42 -8
- package/src/lib/components/chartlegend/ChartLegendWrapper.tsx +75 -29
- package/src/lib/components/constants.ts +11 -0
- package/src/lib/components/constrainedtext/Constrainedtext.component.tsx +5 -2
- package/src/lib/components/date/FormattedDateTime.tsx +15 -1
- package/src/lib/components/linetimeseriechart/linetimeseriechart.component.tsx +8 -6
- package/src/lib/components/text/Text.component.tsx +1 -1
- package/src/lib/components/toast/Toast.component.tsx +27 -19
- package/src/lib/next.ts +1 -0
- package/stories/constrainedtext.stories.tsx +4 -1
- package/stories/linetimeseriechart.stories.tsx +30 -25
|
@@ -18,7 +18,10 @@ const Legend = styled.div<{ direction: 'horizontal' | 'vertical' }>`
|
|
|
18
18
|
flex-wrap: wrap;
|
|
19
19
|
`;
|
|
20
20
|
|
|
21
|
-
const LegendItem = styled.div<{
|
|
21
|
+
export const LegendItem = styled.div<{
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
selected?: boolean;
|
|
24
|
+
}>`
|
|
22
25
|
display: flex;
|
|
23
26
|
align-items: center;
|
|
24
27
|
gap: 8px;
|
|
@@ -31,7 +34,7 @@ const LegendItem = styled.div<{ disabled?: boolean; selected?: boolean }>`
|
|
|
31
34
|
}
|
|
32
35
|
`;
|
|
33
36
|
|
|
34
|
-
const LegendShape = styled.div<{
|
|
37
|
+
export const LegendShape = styled.div<{
|
|
35
38
|
color?: string;
|
|
36
39
|
shape: 'line' | 'rectangle';
|
|
37
40
|
chartColors: Record<string, string>;
|
|
@@ -69,21 +72,51 @@ export const ChartLegend = ({
|
|
|
69
72
|
isSelected,
|
|
70
73
|
addSelectedResource,
|
|
71
74
|
removeSelectedResource,
|
|
75
|
+
selectAllResources,
|
|
76
|
+
getAllResourcesCount,
|
|
77
|
+
getSelectedCount,
|
|
78
|
+
selectOnlyResource,
|
|
72
79
|
} = useChartLegend();
|
|
73
80
|
|
|
74
81
|
const resources = listResources();
|
|
75
82
|
|
|
76
83
|
const handleLegendClick = useCallback(
|
|
77
|
-
(resource: string) => {
|
|
84
|
+
(resource: string, event: React.MouseEvent) => {
|
|
78
85
|
if (disabled) return;
|
|
79
86
|
|
|
80
|
-
|
|
81
|
-
|
|
87
|
+
const isModifierClick = event.metaKey || event.ctrlKey;
|
|
88
|
+
const itemIsSelected = isSelected(resource);
|
|
89
|
+
|
|
90
|
+
if (isModifierClick) {
|
|
91
|
+
if (itemIsSelected) {
|
|
92
|
+
if (getSelectedCount() === 1) {
|
|
93
|
+
selectAllResources();
|
|
94
|
+
} else {
|
|
95
|
+
removeSelectedResource(resource);
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
addSelectedResource(resource);
|
|
99
|
+
}
|
|
82
100
|
} else {
|
|
83
|
-
|
|
101
|
+
if (getSelectedCount() === getAllResourcesCount()) {
|
|
102
|
+
selectOnlyResource(resource);
|
|
103
|
+
} else if (itemIsSelected) {
|
|
104
|
+
selectAllResources();
|
|
105
|
+
} else {
|
|
106
|
+
selectOnlyResource(resource);
|
|
107
|
+
}
|
|
84
108
|
}
|
|
85
109
|
},
|
|
86
|
-
[
|
|
110
|
+
[
|
|
111
|
+
disabled,
|
|
112
|
+
isSelected,
|
|
113
|
+
addSelectedResource,
|
|
114
|
+
removeSelectedResource,
|
|
115
|
+
selectAllResources,
|
|
116
|
+
selectOnlyResource,
|
|
117
|
+
getAllResourcesCount,
|
|
118
|
+
getSelectedCount,
|
|
119
|
+
],
|
|
87
120
|
);
|
|
88
121
|
|
|
89
122
|
return (
|
|
@@ -97,7 +130,8 @@ export const ChartLegend = ({
|
|
|
97
130
|
key={resource}
|
|
98
131
|
disabled={disabled}
|
|
99
132
|
selected={selected}
|
|
100
|
-
|
|
133
|
+
aria-label={`${resource} ${selected ? 'selected' : 'not selected'}`}
|
|
134
|
+
onClick={(event) => handleLegendClick(resource, event)}
|
|
101
135
|
>
|
|
102
136
|
<LegendShape
|
|
103
137
|
color={color}
|
|
@@ -1,13 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
useContext,
|
|
4
|
+
useState,
|
|
5
|
+
ReactNode,
|
|
6
|
+
useMemo,
|
|
7
|
+
useCallback,
|
|
8
|
+
} from 'react';
|
|
2
9
|
import { ChartColors } from '../../style/theme';
|
|
3
10
|
|
|
4
11
|
export type ChartLegendState = {
|
|
5
12
|
selectedResources: string[];
|
|
6
13
|
addSelectedResource: (resource: string) => void;
|
|
7
14
|
removeSelectedResource: (resource: string) => void;
|
|
15
|
+
selectAllResources: () => void;
|
|
16
|
+
selectOnlyResource: (resource: string) => void;
|
|
8
17
|
isSelected: (resource: string) => boolean;
|
|
9
18
|
getColor: (resource: string) => string | undefined;
|
|
10
19
|
listResources: () => string[];
|
|
20
|
+
getAllResourcesCount: () => number;
|
|
21
|
+
getSelectedCount: () => number;
|
|
11
22
|
};
|
|
12
23
|
|
|
13
24
|
const ChartLegendContext = createContext<ChartLegendState | null>(null);
|
|
@@ -21,7 +32,9 @@ export const ChartLegendWrapper = ({
|
|
|
21
32
|
children,
|
|
22
33
|
colorSet,
|
|
23
34
|
}: ChartLegendWrapperProps) => {
|
|
24
|
-
const
|
|
35
|
+
const allResources = Object.keys(colorSet);
|
|
36
|
+
const [selectedResources, setSelectedResources] =
|
|
37
|
+
useState<string[]>(allResources);
|
|
25
38
|
|
|
26
39
|
const addSelectedResource = useCallback((resource: string) => {
|
|
27
40
|
setSelectedResources((prev) =>
|
|
@@ -33,40 +46,73 @@ export const ChartLegendWrapper = ({
|
|
|
33
46
|
setSelectedResources((prev) => prev.filter((r) => r !== resource));
|
|
34
47
|
}, []);
|
|
35
48
|
|
|
36
|
-
const
|
|
37
|
-
|
|
49
|
+
const selectAllResources = useCallback(() => {
|
|
50
|
+
setSelectedResources(allResources);
|
|
51
|
+
}, [allResources]);
|
|
52
|
+
|
|
53
|
+
const selectOnlyResource = useCallback((resource: string) => {
|
|
54
|
+
setSelectedResources([resource]);
|
|
55
|
+
}, []);
|
|
56
|
+
|
|
57
|
+
const getAllResourcesCount = useCallback(() => {
|
|
58
|
+
return allResources.length;
|
|
59
|
+
}, [allResources]);
|
|
60
|
+
|
|
61
|
+
const getSelectedCount = useCallback(() => {
|
|
62
|
+
return selectedResources.length;
|
|
38
63
|
}, [selectedResources]);
|
|
39
64
|
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
65
|
+
const isSelected = useCallback(
|
|
66
|
+
(resource: string) => {
|
|
67
|
+
return selectedResources.includes(resource);
|
|
68
|
+
},
|
|
69
|
+
[selectedResources],
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const getColor = useCallback(
|
|
73
|
+
(resource: string) => {
|
|
74
|
+
const color = colorSet[resource];
|
|
75
|
+
if (!color) {
|
|
76
|
+
console.warn(
|
|
77
|
+
`ChartLegendWrapper: No color defined for resource "${resource}"`,
|
|
78
|
+
);
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
return color;
|
|
82
|
+
},
|
|
83
|
+
[colorSet],
|
|
84
|
+
);
|
|
50
85
|
|
|
51
86
|
const listResources = useCallback(() => {
|
|
52
87
|
return Object.keys(colorSet);
|
|
53
88
|
}, [colorSet]);
|
|
54
89
|
|
|
55
|
-
const chartLegendState = useMemo(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
90
|
+
const chartLegendState = useMemo(
|
|
91
|
+
() => ({
|
|
92
|
+
selectedResources,
|
|
93
|
+
addSelectedResource,
|
|
94
|
+
removeSelectedResource,
|
|
95
|
+
selectAllResources,
|
|
96
|
+
selectOnlyResource,
|
|
97
|
+
isSelected,
|
|
98
|
+
getColor,
|
|
99
|
+
listResources,
|
|
100
|
+
getAllResourcesCount,
|
|
101
|
+
getSelectedCount,
|
|
102
|
+
}),
|
|
103
|
+
[
|
|
104
|
+
selectedResources,
|
|
105
|
+
addSelectedResource,
|
|
106
|
+
removeSelectedResource,
|
|
107
|
+
selectAllResources,
|
|
108
|
+
selectOnlyResource,
|
|
109
|
+
isSelected,
|
|
110
|
+
getColor,
|
|
111
|
+
listResources,
|
|
112
|
+
getAllResourcesCount,
|
|
113
|
+
getSelectedCount,
|
|
114
|
+
],
|
|
115
|
+
);
|
|
70
116
|
|
|
71
117
|
return (
|
|
72
118
|
<ChartLegendContext.Provider value={chartLegendState}>
|
|
@@ -40,29 +40,40 @@ export type QueryTimeSpan = {
|
|
|
40
40
|
label: string;
|
|
41
41
|
// the label display in the timespan selector
|
|
42
42
|
duration: number;
|
|
43
|
+
// time difference between two samples in second
|
|
44
|
+
interval: number;
|
|
43
45
|
// time span in second
|
|
46
|
+
/** @deprecated Use `interval` instead */
|
|
44
47
|
frequency: number;
|
|
45
48
|
};
|
|
49
|
+
|
|
46
50
|
export const queryTimeSpansCodes: QueryTimeSpan[] = [
|
|
47
51
|
{
|
|
48
52
|
query: QUERY_LAST_SEVEN_DAYS,
|
|
49
53
|
label: LAST_SEVEN_DAYS,
|
|
50
54
|
duration: SAMPLE_DURATION_LAST_SEVEN_DAYS,
|
|
55
|
+
interval: SAMPLE_FREQUENCY_LAST_SEVEN_DAYS,
|
|
56
|
+
/** @deprecated Use `interval` instead */
|
|
51
57
|
frequency: SAMPLE_FREQUENCY_LAST_SEVEN_DAYS,
|
|
52
58
|
},
|
|
53
59
|
{
|
|
54
60
|
query: QUERY_LAST_TWENTY_FOUR_HOURS,
|
|
55
61
|
label: LAST_TWENTY_FOUR_HOURS,
|
|
56
62
|
duration: SAMPLE_DURATION_LAST_TWENTY_FOUR_HOURS,
|
|
63
|
+
interval: SAMPLE_FREQUENCY_LAST_TWENTY_FOUR_HOURS,
|
|
64
|
+
/** @deprecated Use `interval` instead */
|
|
57
65
|
frequency: SAMPLE_FREQUENCY_LAST_TWENTY_FOUR_HOURS,
|
|
58
66
|
},
|
|
59
67
|
{
|
|
60
68
|
query: QUERY_LAST_ONE_HOUR,
|
|
61
69
|
label: LAST_ONE_HOUR,
|
|
62
70
|
duration: SAMPLE_DURATION_LAST_ONE_HOUR,
|
|
71
|
+
interval: SAMPLE_FREQUENCY_LAST_ONE_HOUR,
|
|
72
|
+
/** @deprecated Use `interval` instead */
|
|
63
73
|
frequency: SAMPLE_FREQUENCY_LAST_ONE_HOUR,
|
|
64
74
|
},
|
|
65
75
|
];
|
|
76
|
+
|
|
66
77
|
export const NAN_STRING = 'NAN';
|
|
67
78
|
|
|
68
79
|
export const STATUS_CRITICAL = 'critical';
|
|
@@ -6,6 +6,7 @@ import styled from 'styled-components';
|
|
|
6
6
|
import { Tooltip } from '../tooltip/Tooltip.component';
|
|
7
7
|
import { Props as TooltipProps } from '../tooltip/Tooltip.component';
|
|
8
8
|
import { Text } from '../text/Text.component';
|
|
9
|
+
import { CoreUITheme } from '../../style/theme';
|
|
9
10
|
|
|
10
11
|
type Props = {
|
|
11
12
|
text: string | number | JSX.Element | JSX.Element[];
|
|
@@ -13,6 +14,7 @@ type Props = {
|
|
|
13
14
|
tooltipPlacement?: $PropertyType<TooltipProps, 'placement'>;
|
|
14
15
|
lineClamp?: number;
|
|
15
16
|
centered?: boolean;
|
|
17
|
+
color?: keyof CoreUITheme;
|
|
16
18
|
};
|
|
17
19
|
// for lineClamp cf https://css-tricks.com/almanac/properties/l/line-clamp/
|
|
18
20
|
// it should work on all major navigator, despite the --webkit prefix
|
|
@@ -74,6 +76,7 @@ function ConstrainedText({
|
|
|
74
76
|
tooltipStyle,
|
|
75
77
|
tooltipPlacement,
|
|
76
78
|
lineClamp = 1,
|
|
79
|
+
color,
|
|
77
80
|
centered = false,
|
|
78
81
|
}: Props): JSX.Element {
|
|
79
82
|
const [displayToolTip, setDisplayToolTip] = useState(false);
|
|
@@ -91,7 +94,7 @@ function ConstrainedText({
|
|
|
91
94
|
overlayStyle={tooltipStyle}
|
|
92
95
|
placement={tooltipPlacement}
|
|
93
96
|
>
|
|
94
|
-
<Text>
|
|
97
|
+
<Text color={color}>
|
|
95
98
|
{getConstrainedTextContainer(
|
|
96
99
|
constrainedTextRef,
|
|
97
100
|
lineClamp,
|
|
@@ -101,7 +104,7 @@ function ConstrainedText({
|
|
|
101
104
|
</Text>
|
|
102
105
|
</Tooltip>
|
|
103
106
|
) : (
|
|
104
|
-
<Text>
|
|
107
|
+
<Text color={color}>
|
|
105
108
|
{getConstrainedTextContainer(
|
|
106
109
|
constrainedTextRef,
|
|
107
110
|
lineClamp,
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { getDateDaysDiff } from './dateDiffer';
|
|
2
2
|
import { Tooltip } from '../tooltip/Tooltip.component';
|
|
3
3
|
|
|
4
|
+
export const LONG_DATE_FORMATER = Intl.DateTimeFormat('en-GB', {
|
|
5
|
+
weekday: 'long',
|
|
6
|
+
year: 'numeric',
|
|
7
|
+
month: 'long',
|
|
8
|
+
day: 'numeric',
|
|
9
|
+
});
|
|
10
|
+
|
|
4
11
|
export const DATE_FORMATER = Intl.DateTimeFormat('fr-CA', {
|
|
5
12
|
year: 'numeric',
|
|
6
13
|
month: '2-digit',
|
|
@@ -56,7 +63,10 @@ type FormattedDateTimeProps = {
|
|
|
56
63
|
| 'time-second'
|
|
57
64
|
| 'relative'
|
|
58
65
|
| 'day-month-abbreviated-hour-minute'
|
|
59
|
-
| 'day-month-abbreviated-hour-minute-second'
|
|
66
|
+
| 'day-month-abbreviated-hour-minute-second'
|
|
67
|
+
| 'long-date'
|
|
68
|
+
| 'chart-date';
|
|
69
|
+
|
|
60
70
|
value: Date;
|
|
61
71
|
};
|
|
62
72
|
|
|
@@ -184,6 +194,10 @@ export const FormattedDateTime = ({
|
|
|
184
194
|
)}
|
|
185
195
|
</>
|
|
186
196
|
);
|
|
197
|
+
case 'long-date':
|
|
198
|
+
return <>{LONG_DATE_FORMATER.format(value)}</>;
|
|
199
|
+
case 'chart-date':
|
|
200
|
+
return <>{DAY_MONTH_FORMATER.format(value).replace(/[ ,]/g, '')}</>;
|
|
187
201
|
default:
|
|
188
202
|
return <></>;
|
|
189
203
|
}
|
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
} from 'recharts';
|
|
11
11
|
import { useMemo, useRef } from 'react';
|
|
12
12
|
import { useTheme } from 'styled-components';
|
|
13
|
-
import { useMetricsTimeSpan } from '../linetemporalchart/MetricTimespanProvider';
|
|
14
13
|
import { addMissingDataPoint } from '../linetemporalchart/ChartUtil';
|
|
15
14
|
import styled from 'styled-components';
|
|
16
15
|
import { fontSize, fontWeight } from '../../style/theme';
|
|
@@ -123,6 +122,8 @@ export type LineChartProps = (
|
|
|
123
122
|
title: string;
|
|
124
123
|
height: number;
|
|
125
124
|
startingTimeStamp: number;
|
|
125
|
+
interval: number;
|
|
126
|
+
duration: number;
|
|
126
127
|
unitRange?: {
|
|
127
128
|
threshold: number;
|
|
128
129
|
label: string;
|
|
@@ -200,6 +201,8 @@ export function LineTimeSerieChart({
|
|
|
200
201
|
title,
|
|
201
202
|
height,
|
|
202
203
|
startingTimeStamp,
|
|
204
|
+
interval,
|
|
205
|
+
duration,
|
|
203
206
|
unitRange,
|
|
204
207
|
isLoading = false,
|
|
205
208
|
yAxisType = 'default',
|
|
@@ -208,7 +211,6 @@ export function LineTimeSerieChart({
|
|
|
208
211
|
...rest
|
|
209
212
|
}: LineChartProps) {
|
|
210
213
|
const theme = useTheme();
|
|
211
|
-
const { frequency, duration } = useMetricsTimeSpan();
|
|
212
214
|
const { getColor } = useChartLegend();
|
|
213
215
|
const chartRef = useRef(null);
|
|
214
216
|
|
|
@@ -223,7 +225,7 @@ export function LineTimeSerieChart({
|
|
|
223
225
|
line.data,
|
|
224
226
|
startingTimeStamp,
|
|
225
227
|
duration,
|
|
226
|
-
|
|
228
|
+
interval,
|
|
227
229
|
),
|
|
228
230
|
})),
|
|
229
231
|
// Convert positive values to negative values
|
|
@@ -233,7 +235,7 @@ export function LineTimeSerieChart({
|
|
|
233
235
|
line.data,
|
|
234
236
|
startingTimeStamp,
|
|
235
237
|
duration,
|
|
236
|
-
|
|
238
|
+
interval,
|
|
237
239
|
).map(
|
|
238
240
|
([timestamp, value]) =>
|
|
239
241
|
[timestamp, value === null ? null : `-${Number(value)}`] as [
|
|
@@ -249,7 +251,7 @@ export function LineTimeSerieChart({
|
|
|
249
251
|
line.data,
|
|
250
252
|
startingTimeStamp,
|
|
251
253
|
duration,
|
|
252
|
-
|
|
254
|
+
interval,
|
|
253
255
|
),
|
|
254
256
|
}));
|
|
255
257
|
|
|
@@ -287,7 +289,7 @@ export function LineTimeSerieChart({
|
|
|
287
289
|
b: { timestamp: number } & Record<string, string | number | null>,
|
|
288
290
|
) => (a.timestamp as number) - (b.timestamp as number),
|
|
289
291
|
);
|
|
290
|
-
}, [series, startingTimeStamp, duration,
|
|
292
|
+
}, [series, startingTimeStamp, duration, interval, yAxisType]);
|
|
291
293
|
|
|
292
294
|
// Calculate 5 perfectly evenly spaced ticks
|
|
293
295
|
const xAxisTicks = useMemo(() => {
|
|
@@ -133,7 +133,7 @@ export const Text = styled.span<{
|
|
|
133
133
|
isEmphazed?: boolean;
|
|
134
134
|
isGentleEmphazed?: boolean;
|
|
135
135
|
}>`
|
|
136
|
-
|
|
136
|
+
${(props) => props.color && `color: ${props.theme[props.color]};`}
|
|
137
137
|
${(props) =>
|
|
138
138
|
props.variant === 'Larger'
|
|
139
139
|
? `
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { motion } from 'framer-motion';
|
|
2
1
|
import { ReactNode, useRef } from 'react';
|
|
3
2
|
import { useTheme } from 'styled-components';
|
|
4
3
|
import { Box } from '../box/Box';
|
|
@@ -99,6 +98,31 @@ const ContentContainer = styled.div`
|
|
|
99
98
|
position: relative;
|
|
100
99
|
`;
|
|
101
100
|
|
|
101
|
+
const FadingToast = styled.div`
|
|
102
|
+
align-items: flex-end;
|
|
103
|
+
background-color: ${props => props.theme.backgroundLevel1};
|
|
104
|
+
border: 1px solid ${props => props.theme.border};
|
|
105
|
+
box-shadow: 0px 4px 10px 4px #000;
|
|
106
|
+
display: flex;
|
|
107
|
+
border-radius: 4px;
|
|
108
|
+
position: relative;
|
|
109
|
+
|
|
110
|
+
@keyframes toastEnter {
|
|
111
|
+
from {
|
|
112
|
+
opacity: 0;
|
|
113
|
+
transform: translateY(-20px);
|
|
114
|
+
}
|
|
115
|
+
to {
|
|
116
|
+
opacity: 1;
|
|
117
|
+
transform: translateY(0);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
`;
|
|
121
|
+
|
|
122
|
+
const ToastEnter = styled(FadingToast)`
|
|
123
|
+
animation: toastEnter 0.3s ease forwards;
|
|
124
|
+
`;
|
|
125
|
+
|
|
102
126
|
function Toast({
|
|
103
127
|
open,
|
|
104
128
|
message,
|
|
@@ -123,7 +147,6 @@ function Toast({
|
|
|
123
147
|
|
|
124
148
|
const bgColor = useGetBackgroundColor(status);
|
|
125
149
|
const rgbBgColor = useGetRgbBackgroundColor(status);
|
|
126
|
-
const theme = useTheme();
|
|
127
150
|
|
|
128
151
|
if (!open) {
|
|
129
152
|
return null;
|
|
@@ -141,22 +164,7 @@ function Toast({
|
|
|
141
164
|
width,
|
|
142
165
|
}}
|
|
143
166
|
>
|
|
144
|
-
<
|
|
145
|
-
key="toast"
|
|
146
|
-
initial={{ opacity: 0, y: -20 }}
|
|
147
|
-
animate={{ opacity: 1, y: 0 }}
|
|
148
|
-
exit={{ opacity: 0, y: 20 }}
|
|
149
|
-
transition={{ duration: 0.3 }}
|
|
150
|
-
style={{
|
|
151
|
-
alignItems: 'flex-end',
|
|
152
|
-
backgroundColor: theme.backgroundLevel1,
|
|
153
|
-
border: `1px solid ${theme.border}`,
|
|
154
|
-
boxShadow: '0px 4px 10px 4px #000',
|
|
155
|
-
display: 'flex',
|
|
156
|
-
borderRadius: '4px',
|
|
157
|
-
position: 'relative',
|
|
158
|
-
}}
|
|
159
|
-
>
|
|
167
|
+
<ToastEnter>
|
|
160
168
|
<IconContainer bgColor={rgbBgColor}>{icon}</IconContainer>
|
|
161
169
|
<ContentContainer>
|
|
162
170
|
<BasicText>{message}</BasicText>
|
|
@@ -169,7 +177,7 @@ function Toast({
|
|
|
169
177
|
tooltip={{ overlay: 'Close', placement: 'top' }}
|
|
170
178
|
/>
|
|
171
179
|
</Box>
|
|
172
|
-
</
|
|
180
|
+
</ToastEnter>
|
|
173
181
|
{withProgressBar && (
|
|
174
182
|
<DurationBasedProgressBar
|
|
175
183
|
duration={autoDismiss ? duration : null}
|
package/src/lib/next.ts
CHANGED
|
@@ -21,6 +21,7 @@ export {
|
|
|
21
21
|
BarchartSortFn,
|
|
22
22
|
BarchartTooltipFn,
|
|
23
23
|
} from './components/barchartv2/Barchart.component';
|
|
24
|
+
export { ChartTooltip } from './components/barchartv2/ChartTooltip';
|
|
24
25
|
export { ChartLegendWrapper } from './components/chartlegend/ChartLegendWrapper';
|
|
25
26
|
export { ChartLegend } from './components/chartlegend/ChartLegend';
|
|
26
27
|
export { LineTimeSerieChart } from './components/linetimeseriechart/linetimeseriechart.component';
|
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { ConstrainedText } from '../src/lib/components/constrainedtext/Constrainedtext.component';
|
|
3
3
|
import { Wrapper } from './common';
|
|
4
4
|
import { placementOptions } from './controls';
|
|
5
|
+
import { Text } from '../src/lib/components/text/Text.component';
|
|
5
6
|
export default {
|
|
6
7
|
title: 'Components/Constrained Text',
|
|
7
8
|
component: ConstrainedText,
|
|
@@ -34,10 +35,12 @@ export const Default = {
|
|
|
34
35
|
};
|
|
35
36
|
|
|
36
37
|
export const CustomizedTooltip = {
|
|
38
|
+
...Default,
|
|
37
39
|
args: {
|
|
38
|
-
text:
|
|
40
|
+
text: <Text>This is a long long phrase</Text>,
|
|
39
41
|
tooltipStyle: { width: '100px', color: 'lightblue' },
|
|
40
42
|
tooltipPlacement: 'right',
|
|
43
|
+
color: 'statusCritical',
|
|
41
44
|
},
|
|
42
45
|
};
|
|
43
46
|
|
|
@@ -1,42 +1,41 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Meta, StoryObj } from '@storybook/react';
|
|
3
|
-
import { MetricsTimeSpanProvider } from '../src/lib/components/linetemporalchart/MetricTimespanProvider';
|
|
4
3
|
import { LineTimeSerieChart } from '../src/lib/components/linetimeseriechart/linetimeseriechart.component';
|
|
5
4
|
import { ChartLegendWrapper } from '../src/lib/components/chartlegend/ChartLegendWrapper';
|
|
6
5
|
import { lineTimeSeriesColorRange } from '../src/lib/style/theme';
|
|
7
6
|
import { ChartLegend } from '../src/lib/components/chartlegend/ChartLegend';
|
|
7
|
+
import {
|
|
8
|
+
SAMPLE_DURATION_LAST_TWENTY_FOUR_HOURS,
|
|
9
|
+
SAMPLE_FREQUENCY_LAST_TWENTY_FOUR_HOURS,
|
|
10
|
+
} from '../src/lib/components/constants';
|
|
8
11
|
|
|
9
12
|
const ChartWithProviders = (props) => {
|
|
10
13
|
return (
|
|
11
|
-
<
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
</ChartLegendWrapper>
|
|
21
|
-
</MetricsTimeSpanProvider>
|
|
14
|
+
<ChartLegendWrapper
|
|
15
|
+
colorSet={{
|
|
16
|
+
'ip-10-160-122-207.eu-north-1.compute.internal':
|
|
17
|
+
lineTimeSeriesColorRange[0],
|
|
18
|
+
}}
|
|
19
|
+
>
|
|
20
|
+
<LineTimeSerieChart {...props} />
|
|
21
|
+
<ChartLegend shape="line" />
|
|
22
|
+
</ChartLegendWrapper>
|
|
22
23
|
);
|
|
23
24
|
};
|
|
24
25
|
|
|
25
26
|
const ChartWithProviders2 = (props) => {
|
|
26
27
|
return (
|
|
27
|
-
<
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
</ChartLegendWrapper>
|
|
39
|
-
</MetricsTimeSpanProvider>
|
|
28
|
+
<ChartLegendWrapper
|
|
29
|
+
colorSet={{
|
|
30
|
+
'ip-10-160-122-207.eu-north-1.compute.internal':
|
|
31
|
+
lineTimeSeriesColorRange[0],
|
|
32
|
+
'ip-10-160-122-207.eu-north-2.compute.internal':
|
|
33
|
+
lineTimeSeriesColorRange[1],
|
|
34
|
+
}}
|
|
35
|
+
>
|
|
36
|
+
<LineTimeSerieChart {...props} />
|
|
37
|
+
<ChartLegend shape="line" direction="vertical" />
|
|
38
|
+
</ChartLegendWrapper>
|
|
40
39
|
);
|
|
41
40
|
};
|
|
42
41
|
const meta: Meta<typeof LineTimeSerieChart> = {
|
|
@@ -399,6 +398,8 @@ export const PercentageChartExample: Story = {
|
|
|
399
398
|
helpText: 'This is the help text',
|
|
400
399
|
yAxisType: 'percentage',
|
|
401
400
|
yAxisTitle: '',
|
|
401
|
+
interval: SAMPLE_FREQUENCY_LAST_TWENTY_FOUR_HOURS,
|
|
402
|
+
duration: SAMPLE_DURATION_LAST_TWENTY_FOUR_HOURS,
|
|
402
403
|
},
|
|
403
404
|
};
|
|
404
405
|
const UNIT_RANGE_BS = [
|
|
@@ -464,6 +465,8 @@ export const SymmetricalAxisExample: Story = {
|
|
|
464
465
|
isLegendHidden: false,
|
|
465
466
|
yAxisType: 'symmetrical',
|
|
466
467
|
yAxisTitle: 'in(+)/out(-)',
|
|
468
|
+
interval: SAMPLE_FREQUENCY_LAST_TWENTY_FOUR_HOURS,
|
|
469
|
+
duration: SAMPLE_DURATION_LAST_TWENTY_FOUR_HOURS,
|
|
467
470
|
},
|
|
468
471
|
};
|
|
469
472
|
export const AutoUnitChartExample: Story = {
|
|
@@ -481,5 +484,7 @@ export const AutoUnitChartExample: Story = {
|
|
|
481
484
|
height: 200,
|
|
482
485
|
unitRange: UNIT_RANGE_BS,
|
|
483
486
|
yAxisType: 'default',
|
|
487
|
+
interval: SAMPLE_FREQUENCY_LAST_TWENTY_FOUR_HOURS,
|
|
488
|
+
duration: SAMPLE_DURATION_LAST_TWENTY_FOUR_HOURS,
|
|
484
489
|
},
|
|
485
490
|
};
|