@centreon/ui 24.4.40 → 24.4.42
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/package.json +1 -1
- package/src/components/ItemComposition/ItemComposition.cypress.spec.tsx +16 -19
- package/src/components/ItemComposition/ItemComposition.stories.tsx +14 -0
- package/src/components/ItemComposition/ItemComposition.styles.ts +26 -0
- package/src/components/ItemComposition/ItemComposition.tsx +15 -1
package/package.json
CHANGED
|
@@ -1,30 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Props } from './ItemComposition';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
addButtonHidden?: boolean;
|
|
5
|
-
addbuttonDisabled?: boolean;
|
|
6
|
-
deleteButtonHidden?: boolean;
|
|
7
|
-
secondaryLabel?: string;
|
|
8
|
-
}
|
|
3
|
+
import { ItemComposition } from '.';
|
|
9
4
|
|
|
10
5
|
const initialize = ({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
deleteButtonHidden
|
|
15
|
-
}
|
|
6
|
+
deleteButtonHidden,
|
|
7
|
+
...props
|
|
8
|
+
}: Partial<Props> & {
|
|
9
|
+
deleteButtonHidden?: boolean;
|
|
10
|
+
}): unknown => {
|
|
16
11
|
const addItem = cy.stub();
|
|
17
12
|
const deleteItem = cy.stub();
|
|
18
13
|
|
|
19
14
|
cy.mount({
|
|
20
15
|
Component: (
|
|
21
|
-
<ItemComposition
|
|
22
|
-
addButtonHidden={addButtonHidden}
|
|
23
|
-
addbuttonDisabled={addbuttonDisabled}
|
|
24
|
-
labelAdd="Add"
|
|
25
|
-
secondaryLabel={secondaryLabel}
|
|
26
|
-
onAddItem={addItem}
|
|
27
|
-
>
|
|
16
|
+
<ItemComposition {...props} labelAdd="Add" onAddItem={addItem}>
|
|
28
17
|
<ItemComposition.Item
|
|
29
18
|
deleteButtonHidden={deleteButtonHidden}
|
|
30
19
|
labelDelete="Delete"
|
|
@@ -113,4 +102,12 @@ describe('ItemComposition', () => {
|
|
|
113
102
|
expect(deleteItem).to.have.been.calledWith();
|
|
114
103
|
});
|
|
115
104
|
});
|
|
105
|
+
|
|
106
|
+
it('displays items as linked when the prop is set to true', () => {
|
|
107
|
+
initialize({ displayItemsAsLinked: true });
|
|
108
|
+
|
|
109
|
+
cy.get('[data-linked]').should('be.visible');
|
|
110
|
+
|
|
111
|
+
cy.makeSnapshot();
|
|
112
|
+
});
|
|
116
113
|
});
|
|
@@ -76,3 +76,17 @@ export const WithSelectInputs: Story = {
|
|
|
76
76
|
onAddItem: stub
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
|
+
|
|
80
|
+
export const WithLinkedItems: Story = {
|
|
81
|
+
args: {
|
|
82
|
+
children: [...Array(5)].map((_, i) => (
|
|
83
|
+
<ItemComposition.Item key={i} labelDelete="Delete" onDeleteItem={stub}>
|
|
84
|
+
<Typography>Item 1</Typography>
|
|
85
|
+
<Typography>Item 2</Typography>
|
|
86
|
+
</ItemComposition.Item>
|
|
87
|
+
)),
|
|
88
|
+
displayItemsAsLinked: true,
|
|
89
|
+
labelAdd: 'Add',
|
|
90
|
+
onAddItem: stub
|
|
91
|
+
}
|
|
92
|
+
};
|
|
@@ -14,6 +14,32 @@ export const useItemCompositionStyles = makeStyles()((theme) => ({
|
|
|
14
14
|
flexDirection: 'column',
|
|
15
15
|
gap: theme.spacing(2),
|
|
16
16
|
width: '100%'
|
|
17
|
+
},
|
|
18
|
+
itemCompositionItems: {
|
|
19
|
+
width: '100%'
|
|
20
|
+
},
|
|
21
|
+
itemCompositionItemsAndLink: {
|
|
22
|
+
display: 'flex',
|
|
23
|
+
flexDirection: 'row-reverse',
|
|
24
|
+
gap: theme.spacing(0.5),
|
|
25
|
+
width: '100%'
|
|
26
|
+
},
|
|
27
|
+
linkIcon: {
|
|
28
|
+
backgroundColor: theme.palette.background.paper,
|
|
29
|
+
padding: theme.spacing(0.5, 0),
|
|
30
|
+
transform: `rotate3d(0, 0, 1, 90deg) translate3d(0, ${theme.spacing(
|
|
31
|
+
1.6
|
|
32
|
+
)}, 0)`
|
|
33
|
+
},
|
|
34
|
+
linkedItems: {
|
|
35
|
+
alignItems: 'center',
|
|
36
|
+
border: `1px solid ${theme.palette.divider}`,
|
|
37
|
+
borderRight: 'none',
|
|
38
|
+
display: 'flex',
|
|
39
|
+
margin: theme.spacing(2, 0, 2, 1),
|
|
40
|
+
minHeight: '100%',
|
|
41
|
+
position: 'relative',
|
|
42
|
+
width: theme.spacing(1)
|
|
17
43
|
}
|
|
18
44
|
}));
|
|
19
45
|
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
2
|
|
|
3
|
+
import { gt } from 'ramda';
|
|
4
|
+
|
|
3
5
|
import AddIcon from '@mui/icons-material/Add';
|
|
6
|
+
import LinkIcon from '@mui/icons-material/Link';
|
|
4
7
|
import { Typography } from '@mui/material';
|
|
5
8
|
|
|
6
9
|
import { Button } from '..';
|
|
@@ -12,6 +15,7 @@ export type Props = {
|
|
|
12
15
|
addButtonHidden?: boolean;
|
|
13
16
|
addbuttonDisabled?: boolean;
|
|
14
17
|
children: Array<ReactElement>;
|
|
18
|
+
displayItemsAsLinked?: boolean;
|
|
15
19
|
labelAdd: string;
|
|
16
20
|
onAddItem: () => void;
|
|
17
21
|
secondaryLabel?: string;
|
|
@@ -24,13 +28,23 @@ export const ItemComposition = ({
|
|
|
24
28
|
addbuttonDisabled,
|
|
25
29
|
addButtonHidden,
|
|
26
30
|
IconAdd,
|
|
31
|
+
displayItemsAsLinked,
|
|
27
32
|
secondaryLabel
|
|
28
33
|
}: Props): JSX.Element => {
|
|
29
34
|
const { classes } = useItemCompositionStyles();
|
|
30
35
|
|
|
36
|
+
const hasMoreThanOneChildren = gt(children.length, 1);
|
|
37
|
+
|
|
31
38
|
return (
|
|
32
39
|
<div className={classes.itemCompositionContainer}>
|
|
33
|
-
{
|
|
40
|
+
<div className={classes.itemCompositionItemsAndLink}>
|
|
41
|
+
<div className={classes.itemCompositionItems}>{children}</div>
|
|
42
|
+
{displayItemsAsLinked && hasMoreThanOneChildren && (
|
|
43
|
+
<div data-linked className={classes.linkedItems}>
|
|
44
|
+
<LinkIcon className={classes.linkIcon} viewBox="0 0 24 24" />
|
|
45
|
+
</div>
|
|
46
|
+
)}
|
|
47
|
+
</div>
|
|
34
48
|
<div className={classes.buttonAndSecondaryLabel}>
|
|
35
49
|
{!addButtonHidden && (
|
|
36
50
|
<Button
|