@nurvus/ui 0.1.0-alpha.1
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/LICENSE +21 -0
- package/README.md +59 -0
- package/dist/index.js +6 -0
- package/package.json +68 -0
- package/src/app.js +29 -0
- package/src/components/Button/Button.jsx +61 -0
- package/src/components/Button/Button.md +79 -0
- package/src/components/Button/Button.scss +104 -0
- package/src/components/ButtonGroup/ButtonGroup.jsx +17 -0
- package/src/components/ButtonGroup/ButtonGroup.md +25 -0
- package/src/components/ButtonGroup/ButtonGroup.scss +19 -0
- package/src/components/FullPageModal/FullPageModal.jsx +108 -0
- package/src/components/FullPageModal/FullPageModal.md +32 -0
- package/src/components/FullPageModal/FullPageModal.scss +102 -0
- package/src/components/Layout/Layout.jsx +30 -0
- package/src/components/Layout/Layout.md +55 -0
- package/src/components/Layout/Layout.scss +91 -0
- package/src/components/Link/Link.jsx +39 -0
- package/src/components/Link/Link.md +5 -0
- package/src/components/Link/Link.scss +18 -0
- package/src/components/Menu/Menu.jsx +109 -0
- package/src/components/Menu/Menu.md +135 -0
- package/src/components/Menu/Menu.scss +36 -0
- package/src/components/Progress/Progress.jsx +58 -0
- package/src/components/Progress/Progress.md +32 -0
- package/src/components/Progress/Progress.scss +54 -0
- package/src/components/Table/Table.jsx +92 -0
- package/src/components/Table/Table.md +211 -0
- package/src/components/Table/Table.scss +63 -0
- package/src/components/Text/Text.jsx +24 -0
- package/src/components/Text/Text.md +25 -0
- package/src/components/Title/Title.jsx +51 -0
- package/src/components/Title/Title.md +24 -0
- package/src/components/Title/Title.scss +44 -0
- package/src/constants.js +3 -0
- package/src/font/Inter-Black.ttf +0 -0
- package/src/font/Inter-Bold.ttf +0 -0
- package/src/font/Inter-ExtraBold.ttf +0 -0
- package/src/font/Inter-ExtraLight.ttf +0 -0
- package/src/font/Inter-Light.ttf +0 -0
- package/src/font/Inter-Medium.ttf +0 -0
- package/src/font/Inter-Regular.ttf +0 -0
- package/src/font/Inter-SemiBold.ttf +0 -0
- package/src/font/Inter-Thin.ttf +0 -0
- package/src/index.js +11 -0
- package/src/managers/ThemeManager.js +0 -0
- package/src/styles/tokens.scss +459 -0
- package/src/styles/variables.scss +23 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
@import "../../styles/variables.scss";
|
|
2
|
+
|
|
3
|
+
.#{$cls-prefix}.button-group {
|
|
4
|
+
.#{$cls-prefix}.button {
|
|
5
|
+
border-radius: 0;
|
|
6
|
+
|
|
7
|
+
&:first-child {
|
|
8
|
+
border-radius: $border-radius 0 0 $border-radius;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
&:last-child {
|
|
12
|
+
border-radius: 0 $border-radius $border-radius 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
&:only-child {
|
|
16
|
+
border-radius: $border-radius;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
3
|
+
import { PropTypes } from 'prop-types';
|
|
4
|
+
import CONSTANT from '../../constants.js';
|
|
5
|
+
import Layout from '../Layout/Layout.jsx';
|
|
6
|
+
import Title from '../Title/Title.jsx';
|
|
7
|
+
import './FullPageModal.scss';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The FullPageModal shows additonal content overlayed on the screen.
|
|
11
|
+
*/
|
|
12
|
+
function FullPageModal(props) {
|
|
13
|
+
const {
|
|
14
|
+
children,
|
|
15
|
+
headerActions,
|
|
16
|
+
title,
|
|
17
|
+
visible = false,
|
|
18
|
+
...restProps
|
|
19
|
+
} = props;
|
|
20
|
+
|
|
21
|
+
function getAnimationState() {
|
|
22
|
+
if (visible) {
|
|
23
|
+
return 'reveal-in';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return 'reveal-out';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const [animationState, setAnimationState] = useState('');
|
|
30
|
+
const [isVisible, setIsVisible] = useState(visible);
|
|
31
|
+
|
|
32
|
+
// Clear animation and sync visibility states
|
|
33
|
+
function clearAnimation() {
|
|
34
|
+
if (animationState) {
|
|
35
|
+
if (visible !== isVisible) {
|
|
36
|
+
setIsVisible(visible);
|
|
37
|
+
setAnimationState('');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Trigger animation when visibility changes
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (visible !== isVisible) {
|
|
45
|
+
const animState = getAnimationState();
|
|
46
|
+
setAnimationState(animState);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (visible && !animationState) {
|
|
50
|
+
setIsVisible(visible);
|
|
51
|
+
}
|
|
52
|
+
}, [visible]);
|
|
53
|
+
|
|
54
|
+
const modalMask = isVisible ? <div className="mask" data-animate={ animationState } /> : null;
|
|
55
|
+
|
|
56
|
+
const modalEl = (
|
|
57
|
+
<div className={`${CONSTANT.CLASS_PREFIX} portal`} data-visible={ visible }>
|
|
58
|
+
{ modalMask }
|
|
59
|
+
<div
|
|
60
|
+
className={`${CONSTANT.CLASS_PREFIX} modal`}
|
|
61
|
+
data-visible={ isVisible }
|
|
62
|
+
data-animate={ animationState }
|
|
63
|
+
onAnimationEnd={ clearAnimation }
|
|
64
|
+
{ ...restProps }
|
|
65
|
+
>
|
|
66
|
+
<div className="header">
|
|
67
|
+
<Layout display="flex" alignItems="center" justifyContent="space-between">
|
|
68
|
+
<Title>
|
|
69
|
+
{ title }
|
|
70
|
+
</Title>
|
|
71
|
+
<div className="header-actions">
|
|
72
|
+
{ headerActions }
|
|
73
|
+
</div>
|
|
74
|
+
</Layout>
|
|
75
|
+
</div>
|
|
76
|
+
{ children }
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
// Note: Using Fragment for JS-DOCS to read prop-types
|
|
82
|
+
return (
|
|
83
|
+
<React.Fragment>
|
|
84
|
+
{ ReactDOM.createPortal(modalEl, document.body) }
|
|
85
|
+
</React.Fragment>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
FullPageModal.propTypes = {
|
|
90
|
+
/**
|
|
91
|
+
* Custom class name.
|
|
92
|
+
*/
|
|
93
|
+
className: PropTypes.string,
|
|
94
|
+
/**
|
|
95
|
+
* Title of Modal
|
|
96
|
+
*/
|
|
97
|
+
title: PropTypes.node,
|
|
98
|
+
/**
|
|
99
|
+
* Header actions of Modal
|
|
100
|
+
*/
|
|
101
|
+
headerActions: PropTypes.node,
|
|
102
|
+
/**
|
|
103
|
+
* Visibility of Modal
|
|
104
|
+
*/
|
|
105
|
+
visible: PropTypes.bool
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export default FullPageModal;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
```jsx
|
|
2
|
+
import React, { useState } from 'react';
|
|
3
|
+
import { Button, FullPageModal, Layout } from '@nurvus/ui';
|
|
4
|
+
|
|
5
|
+
const MyApp = () => {
|
|
6
|
+
const [visible, setVisible] = useState(false);
|
|
7
|
+
|
|
8
|
+
const actions = (
|
|
9
|
+
<Layout display="flex">
|
|
10
|
+
<span>SAVE</span>
|
|
11
|
+
<span onClick={ () => setVisible(false) }>CLOSE</span>
|
|
12
|
+
</Layout>
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<div>
|
|
17
|
+
<Button onClick={ () => setVisible(true) }>
|
|
18
|
+
Show Modal
|
|
19
|
+
</Button>
|
|
20
|
+
<FullPageModal
|
|
21
|
+
title="My Modal"
|
|
22
|
+
headerActions={ actions }
|
|
23
|
+
visible={ visible }
|
|
24
|
+
>
|
|
25
|
+
Modal Stuff
|
|
26
|
+
</FullPageModal>
|
|
27
|
+
</div>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
<MyApp />
|
|
32
|
+
```
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
@import "../../styles/variables.scss";
|
|
2
|
+
|
|
3
|
+
@keyframes reveal-in {
|
|
4
|
+
from {
|
|
5
|
+
top: 100%;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
to {
|
|
9
|
+
top: 0%;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@keyframes reveal-out {
|
|
14
|
+
from {
|
|
15
|
+
top: 0%;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
to {
|
|
19
|
+
top: 100%;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@keyframes fade-in {
|
|
24
|
+
from {
|
|
25
|
+
opacity: 0;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
to {
|
|
29
|
+
opacity: 1;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@keyframes fade-out {
|
|
34
|
+
from {
|
|
35
|
+
opacity: 1;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
to {
|
|
39
|
+
opacity: 0;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.#{$cls-prefix}.portal {
|
|
44
|
+
|
|
45
|
+
&[data-visible="false"] {
|
|
46
|
+
.mask {
|
|
47
|
+
opacity: 0;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.mask {
|
|
52
|
+
position: fixed;
|
|
53
|
+
width: 100%;
|
|
54
|
+
height: 100%;
|
|
55
|
+
top: 0;
|
|
56
|
+
left: 0;
|
|
57
|
+
right: 0;
|
|
58
|
+
bottom: 0;
|
|
59
|
+
z-index: $modal-z-index;
|
|
60
|
+
background-color: rgb(64 57 96 / 50%);
|
|
61
|
+
transition: all 0.3s ease;
|
|
62
|
+
|
|
63
|
+
&[data-animate="reveal-in"] {
|
|
64
|
+
animation: 0.3s ease fade-in;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
&[data-animate="reveal-out"] {
|
|
68
|
+
animation: 0.3s ease fade-out;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.#{$cls-prefix}.modal {
|
|
73
|
+
position: fixed;
|
|
74
|
+
width: 100%;
|
|
75
|
+
height: 100%;
|
|
76
|
+
top: 0;
|
|
77
|
+
left: 0;
|
|
78
|
+
right: 0;
|
|
79
|
+
bottom: 0;
|
|
80
|
+
z-index: $modal-z-index;
|
|
81
|
+
background-color: #403960;
|
|
82
|
+
|
|
83
|
+
.header {
|
|
84
|
+
background-color: rgb(46, 36, 66);
|
|
85
|
+
color: $white;
|
|
86
|
+
padding: 10px;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
&[data-animate="reveal-in"] {
|
|
90
|
+
animation: 0.3s ease reveal-in;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
&[data-animate="reveal-out"] {
|
|
94
|
+
animation: 0.3s ease reveal-out;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
&[data-visible="false"] {
|
|
98
|
+
display: none;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import CONSTANT from '../../constants.js';
|
|
4
|
+
import './Layout.scss';
|
|
5
|
+
|
|
6
|
+
export default function Layout(props) {
|
|
7
|
+
const {
|
|
8
|
+
alignItems,
|
|
9
|
+
className,
|
|
10
|
+
display = 'block',
|
|
11
|
+
flexDirection,
|
|
12
|
+
justifyContent,
|
|
13
|
+
itemDisplay,
|
|
14
|
+
itemSpacing = 20,
|
|
15
|
+
...restProps
|
|
16
|
+
} = props;
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<div
|
|
20
|
+
className={ classNames(`${CONSTANT.CLASS_PREFIX}`, 'layout', className) }
|
|
21
|
+
data-align-items={ alignItems }
|
|
22
|
+
data-display={ display }
|
|
23
|
+
data-flex-direction={ flexDirection }
|
|
24
|
+
data-item-display={ itemDisplay }
|
|
25
|
+
data-item-spacing={ itemSpacing }
|
|
26
|
+
data-justify-content={ justifyContent }
|
|
27
|
+
{ ...restProps }
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Basic Example
|
|
2
|
+
```jsx
|
|
3
|
+
import { Button, Layout, Title } from '@nurvus/ui';
|
|
4
|
+
import AddIcon from '@material-ui/icons/Add';
|
|
5
|
+
import FileCopyIcon from '@material-ui/icons/FileCopy';
|
|
6
|
+
import RemoveRedEyeIcon from '@material-ui/icons/RemoveRedEye';
|
|
7
|
+
import LockOpenIcon from '@material-ui/icons/LockOpen';
|
|
8
|
+
|
|
9
|
+
<Layout>
|
|
10
|
+
<Title level={ 3 }>Layers</Title>
|
|
11
|
+
<Button>
|
|
12
|
+
<AddIcon />
|
|
13
|
+
</Button>
|
|
14
|
+
</Layout>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Horizontal Example
|
|
18
|
+
```jsx
|
|
19
|
+
import { Button, Layout, Title } from '@nurvus/ui';
|
|
20
|
+
import AddIcon from '@material-ui/icons/Add';
|
|
21
|
+
import FileCopyIcon from '@material-ui/icons/FileCopy';
|
|
22
|
+
import RemoveRedEyeIcon from '@material-ui/icons/RemoveRedEye';
|
|
23
|
+
import LockOpenIcon from '@material-ui/icons/LockOpen';
|
|
24
|
+
|
|
25
|
+
<Layout itemSpacing={ 40 }>
|
|
26
|
+
<Layout itemSpacing={ 10 }>
|
|
27
|
+
<Title level={ 4 }>Display Flex</Title>
|
|
28
|
+
<Layout display="flex">
|
|
29
|
+
<Title level={ 3 }>Layers</Title>
|
|
30
|
+
<Button>
|
|
31
|
+
<AddIcon />
|
|
32
|
+
</Button>
|
|
33
|
+
</Layout>
|
|
34
|
+
</Layout>
|
|
35
|
+
<Layout itemSpacing={ 10 }>
|
|
36
|
+
<Title level={ 4 }>Display Flex and Align Item</Title>
|
|
37
|
+
<Layout display="flex" alignItems="center">
|
|
38
|
+
<Title level={ 3 }>Layers</Title>
|
|
39
|
+
<Button>
|
|
40
|
+
<AddIcon />
|
|
41
|
+
</Button>
|
|
42
|
+
</Layout>
|
|
43
|
+
</Layout>
|
|
44
|
+
<Layout itemSpacing={ 10 }>
|
|
45
|
+
<Title level={ 4 }>Display Flex and Align Item and Spaced Apart</Title>
|
|
46
|
+
<Layout display="flex" alignItems="center" justifyContent="space-between">
|
|
47
|
+
<Title level={ 3 }>Layers</Title>
|
|
48
|
+
<Button>
|
|
49
|
+
<AddIcon />
|
|
50
|
+
</Button>
|
|
51
|
+
</Layout>
|
|
52
|
+
</Layout>
|
|
53
|
+
</Layout>
|
|
54
|
+
```
|
|
55
|
+
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
@import "../../styles/variables.scss";
|
|
2
|
+
|
|
3
|
+
.#{$cls-prefix}.layout {
|
|
4
|
+
&[data-display="block"] {
|
|
5
|
+
display: block;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// Vertical Item Stacking
|
|
9
|
+
&[data-display="block"],
|
|
10
|
+
&[data-flex-direction="column"] {
|
|
11
|
+
&[data-item-spacing="10"] {
|
|
12
|
+
> * + * {
|
|
13
|
+
margin-top: $spacing-10;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
&[data-item-spacing="13"] {
|
|
18
|
+
> * + * {
|
|
19
|
+
margin-top: 13px;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
&[data-item-spacing="20"] {
|
|
24
|
+
> * + * {
|
|
25
|
+
margin-top: $spacing-medium;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
&[data-item-spacing="30"] {
|
|
30
|
+
> * + * {
|
|
31
|
+
margin-top: $spacing-extra-medium;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
&[data-item-spacing="40"] {
|
|
36
|
+
> * + * {
|
|
37
|
+
margin-top: $spacing-40;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
&[data-display="flex"] {
|
|
43
|
+
display: flex;
|
|
44
|
+
|
|
45
|
+
&[data-item-spacing="10"] {
|
|
46
|
+
> * + * {
|
|
47
|
+
margin-left: 10px;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
&[data-item-spacing="20"] {
|
|
52
|
+
> * + * {
|
|
53
|
+
margin-left: $spacing-medium;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
&[data-item-spacing="40"] {
|
|
58
|
+
> * + * {
|
|
59
|
+
margin-left: 40px;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
// Align Items
|
|
66
|
+
&[data-align-items="flex-start"] {
|
|
67
|
+
align-items: flex-start;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
&[data-align-items="center"] {
|
|
71
|
+
align-items: center;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
&[data-align-items="flex-end"] {
|
|
75
|
+
align-items: flex-end;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
&[data-justify-content="space-between"] {
|
|
79
|
+
justify-content: space-between;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
&[data-item-display="block"] {
|
|
83
|
+
> * {
|
|
84
|
+
display: block;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
&[data-flex-direction="column"] {
|
|
89
|
+
flex-direction: column;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import CONSTANT from '../../constants.js';
|
|
5
|
+
import './Link.scss';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Link component.
|
|
9
|
+
* @returns {ReactElement} of Link component.
|
|
10
|
+
*/
|
|
11
|
+
function Link(props) {
|
|
12
|
+
const {
|
|
13
|
+
children,
|
|
14
|
+
className,
|
|
15
|
+
...restProps
|
|
16
|
+
} = props;
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<a
|
|
20
|
+
className={ classNames(`${CONSTANT.CLASS_PREFIX}`, 'link', className) }
|
|
21
|
+
{ ...restProps }
|
|
22
|
+
>
|
|
23
|
+
{ children }
|
|
24
|
+
</a>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
Link.propTypes = {
|
|
29
|
+
/**
|
|
30
|
+
* Custom class name.
|
|
31
|
+
*/
|
|
32
|
+
className: PropTypes.string,
|
|
33
|
+
/**
|
|
34
|
+
* Content to render.
|
|
35
|
+
*/
|
|
36
|
+
children: PropTypes.node
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export default Link;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import CONSTANT from '../../constants.js';
|
|
5
|
+
import './Menu.scss';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Menu component.
|
|
9
|
+
* @returns {ReactElement} of Menu component.
|
|
10
|
+
*/
|
|
11
|
+
class Menu extends React.Component {
|
|
12
|
+
|
|
13
|
+
handleClick = (e, path) => {
|
|
14
|
+
e.stopPropagation();
|
|
15
|
+
if (this.props.onClick) {
|
|
16
|
+
this.props.onClick(e, path);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
isActiveItem(path, currentIndex) {
|
|
21
|
+
return path.length && path.length === 1 && path[0] === currentIndex;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
renderItems(items, activePath=[], path = []) {
|
|
25
|
+
const { itemRenderer } = this.props;
|
|
26
|
+
|
|
27
|
+
if (items) {
|
|
28
|
+
return items.map((item, i) => {
|
|
29
|
+
const { className, label, style } = item;
|
|
30
|
+
const type = path.length > 1 ? 'group' : '';
|
|
31
|
+
const isActive = this.isActiveItem(activePath, i);
|
|
32
|
+
const [ first, ...remainingPath ] = activePath;
|
|
33
|
+
const nextPath = [...path, i];
|
|
34
|
+
const indent = (20 * path.length) + 10;
|
|
35
|
+
|
|
36
|
+
let itemChildren;
|
|
37
|
+
if (itemRenderer) {
|
|
38
|
+
itemChildren = itemRenderer(item);
|
|
39
|
+
} else {
|
|
40
|
+
itemChildren = label;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<React.Fragment key={ i }>
|
|
45
|
+
<div
|
|
46
|
+
className={ classNames(`${CONSTANT.CLASS_PREFIX}`, 'menu-item', className) }
|
|
47
|
+
data-active={ isActive }
|
|
48
|
+
data-type={ type }
|
|
49
|
+
onClick={ e => this.handleClick(e, nextPath) }
|
|
50
|
+
style={ {
|
|
51
|
+
paddingLeft: indent,
|
|
52
|
+
...style
|
|
53
|
+
} }
|
|
54
|
+
>
|
|
55
|
+
{ itemChildren }
|
|
56
|
+
</div>
|
|
57
|
+
{ this.renderItems(item.items, first === i ? remainingPath : [], nextPath) }
|
|
58
|
+
|
|
59
|
+
</React.Fragment>
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
render() {
|
|
69
|
+
const { activePath, className, children, itemRenderer, items, ...props } = this.props;
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<div
|
|
73
|
+
className={ classNames(`${CONSTANT.CLASS_PREFIX}`, 'menu', className) }
|
|
74
|
+
{ ...props }
|
|
75
|
+
>
|
|
76
|
+
{ this.renderItems(items, activePath) }
|
|
77
|
+
</div>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
Menu.propTypes = {
|
|
83
|
+
/**
|
|
84
|
+
* Active menu item path.
|
|
85
|
+
*/
|
|
86
|
+
activePath: PropTypes.array,
|
|
87
|
+
/**
|
|
88
|
+
* Menu item list to render.
|
|
89
|
+
*/
|
|
90
|
+
items: PropTypes.arrayOf(PropTypes.shape({
|
|
91
|
+
/**
|
|
92
|
+
* Menu item label.
|
|
93
|
+
*/
|
|
94
|
+
label: PropTypes.node
|
|
95
|
+
})),
|
|
96
|
+
/**
|
|
97
|
+
* Custom renderer for menu items.
|
|
98
|
+
* @param {object} item - of current menu item
|
|
99
|
+
*/
|
|
100
|
+
itemRenderer: PropTypes.func,
|
|
101
|
+
/**
|
|
102
|
+
* Event handler for menu item onClick.
|
|
103
|
+
* @param {object} event - object
|
|
104
|
+
* @param {array} activePath - of clicked menu item.
|
|
105
|
+
*/
|
|
106
|
+
onClick: PropTypes.func
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export default Menu;
|