@axinom/mosaic-ui 0.32.0-rc.12 → 0.32.0-rc.13
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/Accordion/AccordionItem/AccordionItem.d.ts +2 -0
- package/dist/components/Accordion/AccordionItem/AccordionItem.d.ts.map +1 -1
- package/dist/components/InfoPanel/Section/Section.d.ts +3 -1
- package/dist/components/InfoPanel/Section/Section.d.ts.map +1 -1
- package/dist/index.es.js +3 -3
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/components/Accordion/AccordionItem/AccordionItem.spec.tsx +11 -0
- package/src/components/Accordion/AccordionItem/AccordionItem.tsx +5 -1
- package/src/components/InfoPanel/Paragraph/Paragraph.scss +1 -1
- package/src/components/InfoPanel/Section/Section.scss +34 -2
- package/src/components/InfoPanel/Section/Section.spec.tsx +117 -0
- package/src/components/InfoPanel/Section/Section.tsx +32 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axinom/mosaic-ui",
|
|
3
|
-
"version": "0.32.0-rc.
|
|
3
|
+
"version": "0.32.0-rc.13",
|
|
4
4
|
"description": "UI components for building Axinom Mosaic applications",
|
|
5
5
|
"author": "Axinom",
|
|
6
6
|
"license": "PROPRIETARY",
|
|
@@ -102,5 +102,5 @@
|
|
|
102
102
|
"publishConfig": {
|
|
103
103
|
"access": "public"
|
|
104
104
|
},
|
|
105
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "b3a214238f1d54e9f537981372ab779e7fdc7d62"
|
|
106
106
|
}
|
|
@@ -105,4 +105,15 @@ describe('AccordionItem', () => {
|
|
|
105
105
|
|
|
106
106
|
expect(containerStyles).toEqual({ maxHeight: 100 });
|
|
107
107
|
});
|
|
108
|
+
|
|
109
|
+
it('creates a class based off of the className prop', () => {
|
|
110
|
+
const mockClassName = 'test-class';
|
|
111
|
+
const wrapper = shallow(
|
|
112
|
+
<AccordionItem header={<b>Item 1</b>} className={mockClassName} />,
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const item = wrapper.find('.test-class');
|
|
116
|
+
|
|
117
|
+
expect(item.hasClass(mockClassName)).toBe(true);
|
|
118
|
+
});
|
|
108
119
|
});
|
|
@@ -18,6 +18,9 @@ export interface AccordionItemProps {
|
|
|
18
18
|
|
|
19
19
|
/** Sticky state of the current row. When used within the Accordion component, this prop will be overridden with the value from stickyRows. */
|
|
20
20
|
sticky?: boolean;
|
|
21
|
+
|
|
22
|
+
/** CSS Class name for additional styles */
|
|
23
|
+
className?: string;
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
/**
|
|
@@ -34,6 +37,7 @@ export const AccordionItem: React.FC<AccordionItemProps> = ({
|
|
|
34
37
|
isExpanded = false,
|
|
35
38
|
allowLeftSpacing = true,
|
|
36
39
|
sticky = false,
|
|
40
|
+
className,
|
|
37
41
|
}) => {
|
|
38
42
|
const [scrollHeight, setScrollHeight] = useState<number>(0);
|
|
39
43
|
const elementRef = useRef<HTMLDivElement>(null);
|
|
@@ -45,7 +49,7 @@ export const AccordionItem: React.FC<AccordionItemProps> = ({
|
|
|
45
49
|
}, [scrollHeight, children]);
|
|
46
50
|
|
|
47
51
|
return (
|
|
48
|
-
<div data-test-id="accordion-item">
|
|
52
|
+
<div data-test-id="accordion-item" className={className}>
|
|
49
53
|
<div
|
|
50
54
|
data-test-id="accordion-item-row"
|
|
51
55
|
className={clsx(
|
|
@@ -7,12 +7,19 @@
|
|
|
7
7
|
grid-template-columns: 1fr;
|
|
8
8
|
|
|
9
9
|
&.hasTitle {
|
|
10
|
-
grid-template-rows: max-content
|
|
10
|
+
grid-template-rows: max-content;
|
|
11
|
+
|
|
12
|
+
padding-top: 6px;
|
|
13
|
+
padding-bottom: 6px;
|
|
14
|
+
|
|
15
|
+
&.expanded {
|
|
16
|
+
grid-template-rows: max-content max-content;
|
|
17
|
+
}
|
|
11
18
|
}
|
|
12
19
|
|
|
13
20
|
padding: 30px;
|
|
14
21
|
|
|
15
|
-
row-gap:
|
|
22
|
+
row-gap: 20px;
|
|
16
23
|
|
|
17
24
|
.title,
|
|
18
25
|
.main {
|
|
@@ -37,4 +44,29 @@
|
|
|
37
44
|
--infopanel-background-color,
|
|
38
45
|
$infopanel-background-color
|
|
39
46
|
);
|
|
47
|
+
|
|
48
|
+
.collapsibleSection {
|
|
49
|
+
& > div:first-child {
|
|
50
|
+
background-color: unset;
|
|
51
|
+
|
|
52
|
+
div:last-child {
|
|
53
|
+
margin-left: -18px;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
svg {
|
|
57
|
+
margin-left: -34px;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
& > div:last-child {
|
|
62
|
+
border-bottom: unset;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
& > div > div:last-child {
|
|
66
|
+
background-color: var(
|
|
67
|
+
--infopanel-background-color,
|
|
68
|
+
$infopanel-background-color
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
40
72
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { shallow } from 'enzyme';
|
|
2
2
|
import React from 'react';
|
|
3
|
+
import { AccordionItem } from '../../Accordion';
|
|
3
4
|
import { Section } from './Section';
|
|
4
5
|
|
|
5
6
|
describe('Section Tests', () => {
|
|
@@ -8,4 +9,120 @@ describe('Section Tests', () => {
|
|
|
8
9
|
|
|
9
10
|
expect(wrapper).toBeTruthy();
|
|
10
11
|
});
|
|
12
|
+
|
|
13
|
+
it('should not render anything if section has no children', () => {
|
|
14
|
+
const wrapper = shallow(<Section></Section>);
|
|
15
|
+
|
|
16
|
+
const section = wrapper.find('.container');
|
|
17
|
+
|
|
18
|
+
expect(section.exists()).toBe(false);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('creates a class based off of the className prop', () => {
|
|
22
|
+
const mockClassName = 'test-class';
|
|
23
|
+
const wrapper = shallow(
|
|
24
|
+
<Section className={mockClassName}>
|
|
25
|
+
<p>test</p>
|
|
26
|
+
</Section>,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const item = wrapper.find('.test-class');
|
|
30
|
+
|
|
31
|
+
expect(item.hasClass(mockClassName)).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('accepts styles', () => {
|
|
35
|
+
const mockStyles: React.CSSProperties = { backgroundColor: 'blue' };
|
|
36
|
+
const wrapper = shallow(
|
|
37
|
+
<Section style={mockStyles}>
|
|
38
|
+
<p>test</p>
|
|
39
|
+
</Section>,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const section = wrapper.find('.container');
|
|
43
|
+
|
|
44
|
+
expect(section.prop('style')).toBe(mockStyles);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it(`should not be toggleable if no 'title' is given`, () => {
|
|
48
|
+
const wrapper = shallow(
|
|
49
|
+
<Section>
|
|
50
|
+
<p>test</p>
|
|
51
|
+
</Section>,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const item = wrapper.find(AccordionItem);
|
|
55
|
+
|
|
56
|
+
expect(item.exists()).toBe(false);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it(`should be toggleable if a 'title' is given`, () => {
|
|
60
|
+
const wrapper = shallow(
|
|
61
|
+
<Section title="test">
|
|
62
|
+
<p>test</p>
|
|
63
|
+
</Section>,
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const item = wrapper.find(AccordionItem);
|
|
67
|
+
|
|
68
|
+
expect(item.exists()).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('section should be expanded by default', () => {
|
|
72
|
+
const wrapper = shallow(
|
|
73
|
+
<Section>
|
|
74
|
+
<p>test</p>
|
|
75
|
+
</Section>,
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const section = wrapper.find('.container');
|
|
79
|
+
|
|
80
|
+
expect(section.hasClass('expanded')).toBe(true);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it(`section is collasped if 'expandedByDefault' is set to false`, () => {
|
|
84
|
+
const wrapper = shallow(
|
|
85
|
+
<Section expandedByDefault={false}>
|
|
86
|
+
<p>test</p>
|
|
87
|
+
</Section>,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const section = wrapper.find('.container');
|
|
91
|
+
|
|
92
|
+
expect(section.hasClass('expanded')).toBe(false);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('section can be toggled when the title is clicked', () => {
|
|
96
|
+
const wrapper = shallow(
|
|
97
|
+
<Section title="test">
|
|
98
|
+
<p>test</p>
|
|
99
|
+
</Section>,
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
let section = wrapper.find('.container').first();
|
|
103
|
+
let item = wrapper.find(AccordionItem);
|
|
104
|
+
|
|
105
|
+
expect(section.hasClass('expanded')).toBe(true);
|
|
106
|
+
expect(item.prop('isExpanded')).toBe(true);
|
|
107
|
+
|
|
108
|
+
item = wrapper.find(AccordionItem);
|
|
109
|
+
item.prop('toggleExpanded')!();
|
|
110
|
+
wrapper.update();
|
|
111
|
+
|
|
112
|
+
section = wrapper.find('.container').first();
|
|
113
|
+
item = wrapper.find(AccordionItem);
|
|
114
|
+
|
|
115
|
+
expect(section.hasClass('expanded')).toBe(false);
|
|
116
|
+
expect(item.prop('isExpanded')).toBe(false);
|
|
117
|
+
|
|
118
|
+
item = wrapper.find(AccordionItem);
|
|
119
|
+
item.prop('toggleExpanded')!();
|
|
120
|
+
wrapper.update();
|
|
121
|
+
|
|
122
|
+
section = wrapper.find('.container').first();
|
|
123
|
+
item = wrapper.find(AccordionItem);
|
|
124
|
+
|
|
125
|
+
expect(section.hasClass('expanded')).toBe(true);
|
|
126
|
+
expect(item.prop('isExpanded')).toBe(true);
|
|
127
|
+
});
|
|
11
128
|
});
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import clsx from 'clsx';
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import React, { useState } from 'react';
|
|
3
|
+
import { AccordionItem } from '../../Accordion';
|
|
3
4
|
import { Paragraph } from '../Paragraph/Paragraph';
|
|
4
5
|
import classes from './Section.scss';
|
|
5
6
|
|
|
6
7
|
export interface SectionProps {
|
|
7
|
-
/** Section Title */
|
|
8
|
+
/** Section Title. If set, will allow the section to be expandable/collapsible */
|
|
8
9
|
title?: string;
|
|
9
10
|
|
|
10
11
|
/** Optional class */
|
|
@@ -12,6 +13,9 @@ export interface SectionProps {
|
|
|
12
13
|
|
|
13
14
|
/** Optional styles */
|
|
14
15
|
style?: React.CSSProperties;
|
|
16
|
+
|
|
17
|
+
/** Whether the section should be expanded or collapsed intially (default: true)*/
|
|
18
|
+
expandedByDefault?: boolean;
|
|
15
19
|
}
|
|
16
20
|
|
|
17
21
|
export const Section: React.FC<SectionProps> = ({
|
|
@@ -19,7 +23,9 @@ export const Section: React.FC<SectionProps> = ({
|
|
|
19
23
|
title,
|
|
20
24
|
style,
|
|
21
25
|
children,
|
|
26
|
+
expandedByDefault = true,
|
|
22
27
|
}) => {
|
|
28
|
+
const [expanded, setExpanded] = useState<boolean>(expandedByDefault);
|
|
23
29
|
const validChildren: React.ReactNode[] = [];
|
|
24
30
|
|
|
25
31
|
// Special case for removing paragraph components if they are empty
|
|
@@ -42,21 +48,38 @@ export const Section: React.FC<SectionProps> = ({
|
|
|
42
48
|
<div
|
|
43
49
|
className={clsx(
|
|
44
50
|
classes.container,
|
|
45
|
-
{ [classes.hasTitle]: title },
|
|
51
|
+
{ [classes.hasTitle]: title, [classes.expanded]: expanded },
|
|
46
52
|
'info-panel-section-container',
|
|
47
53
|
className,
|
|
48
54
|
)}
|
|
49
55
|
style={style}
|
|
50
56
|
data-test-id="section"
|
|
51
57
|
>
|
|
52
|
-
{title
|
|
53
|
-
<
|
|
54
|
-
{
|
|
58
|
+
{title ? (
|
|
59
|
+
<AccordionItem
|
|
60
|
+
header={
|
|
61
|
+
title ? (
|
|
62
|
+
<div className={classes.title} data-test-id="section-title">
|
|
63
|
+
{title}
|
|
64
|
+
</div>
|
|
65
|
+
) : (
|
|
66
|
+
<div className={classes.title} data-test-id="section-title"></div>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
allowLeftSpacing={false}
|
|
70
|
+
isExpanded={expanded}
|
|
71
|
+
toggleExpanded={() => setExpanded((prev) => !prev)}
|
|
72
|
+
className={classes.collapsibleSection}
|
|
73
|
+
>
|
|
74
|
+
<div className={classes.main} data-test-id="section-content">
|
|
75
|
+
{validChildren}
|
|
76
|
+
</div>
|
|
77
|
+
</AccordionItem>
|
|
78
|
+
) : (
|
|
79
|
+
<div className={classes.main} data-test-id="section-content">
|
|
80
|
+
{validChildren}
|
|
55
81
|
</div>
|
|
56
82
|
)}
|
|
57
|
-
<div className={classes.main} data-test-id="section-content">
|
|
58
|
-
{validChildren}
|
|
59
|
-
</div>
|
|
60
83
|
</div>
|
|
61
84
|
);
|
|
62
85
|
};
|