@judo/components 0.3.0 → 0.4.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/dist/cjs/components.cjs +1 -1
- package/dist/cjs/components.cjs.map +1 -1
- package/dist/components.d.cts +10 -4
- package/dist/components.d.mts +10 -4
- package/dist/esm/components.mjs +1 -1
- package/dist/esm/components.mjs.map +1 -1
- package/package.json +8 -6
- package/src/MenuTree.tsx +112 -0
- package/src/index.tsx +1 -1
- package/src/CustomLink.tsx +0 -35
package/src/MenuTree.tsx
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { JudoTreeItemProps, MenuProps, StyledTreeItemProps } from '@judo/components-api';
|
|
2
|
+
import { ArrowDropDown, ArrowRight } from '@mui/icons-material';
|
|
3
|
+
import { Box, styled, Typography } from '@mui/material';
|
|
4
|
+
import { TreeItem, treeItemClasses } from '@mui/lab';
|
|
5
|
+
import { useIntl } from 'react-intl';
|
|
6
|
+
import { TreeView } from '@mui/lab';
|
|
7
|
+
import { useJudoNavigation } from './CustomBreadcrumb';
|
|
8
|
+
|
|
9
|
+
declare module 'react' {
|
|
10
|
+
interface CSSProperties {
|
|
11
|
+
'--tree-view-color'?: string;
|
|
12
|
+
'--tree-view-bg-color'?: string;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const StyledTreeItemRoot = styled(TreeItem)(({ theme }) => ({
|
|
17
|
+
color: theme.palette.text.secondary,
|
|
18
|
+
[`& .${treeItemClasses.content}`]: {
|
|
19
|
+
color: theme.palette.text.secondary,
|
|
20
|
+
// borderTopRightRadius: theme.spacing(2),
|
|
21
|
+
// borderBottomRightRadius: theme.spacing(2),
|
|
22
|
+
// paddingRight: theme.spacing(1),
|
|
23
|
+
padding: 0,
|
|
24
|
+
marginBottom: '1rem',
|
|
25
|
+
width: 'auto',
|
|
26
|
+
fontWeight: theme.typography.fontWeightMedium,
|
|
27
|
+
'&.Mui-expanded': {
|
|
28
|
+
fontWeight: theme.typography.fontWeightRegular,
|
|
29
|
+
},
|
|
30
|
+
'&:hover': {
|
|
31
|
+
// backgroundColor: theme.palette.action.hover,
|
|
32
|
+
backgroundColor: 'inherit',
|
|
33
|
+
},
|
|
34
|
+
'&.Mui-focused, &.Mui-selected, &.Mui-selected.Mui-focused': {
|
|
35
|
+
// backgroundColor: `var(--tree-view-bg-color, ${theme.palette.action.selected})`,
|
|
36
|
+
backgroundColor: 'inherit',
|
|
37
|
+
color: 'var(--tree-view-color)',
|
|
38
|
+
},
|
|
39
|
+
[`& .${treeItemClasses.label}`]: {
|
|
40
|
+
fontWeight: 'inherit',
|
|
41
|
+
color: 'inherit',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
[`& .${treeItemClasses.group}`]: {
|
|
45
|
+
marginLeft: 0,
|
|
46
|
+
[`& .${treeItemClasses.content}`]: {
|
|
47
|
+
paddingLeft: theme.spacing(2),
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
}));
|
|
51
|
+
|
|
52
|
+
function StyledTreeItem(props: StyledTreeItemProps) {
|
|
53
|
+
const { bgColor, color, labelIcon: LabelIcon, labelInfo, labelText, ...other } = props;
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<StyledTreeItemRoot
|
|
57
|
+
label={
|
|
58
|
+
<Box sx={{ display: 'flex', alignItems: 'center', p: 0.5, pr: 0 }}>
|
|
59
|
+
<Box component={LabelIcon} color="inherit" sx={{ mr: 1 }} />
|
|
60
|
+
<Typography variant="body2" sx={{ fontWeight: 'inherit', flexGrow: 1 }}>
|
|
61
|
+
{labelText}
|
|
62
|
+
</Typography>
|
|
63
|
+
<Typography variant="caption" color="inherit">
|
|
64
|
+
{labelInfo}
|
|
65
|
+
</Typography>
|
|
66
|
+
</Box>
|
|
67
|
+
}
|
|
68
|
+
style={{
|
|
69
|
+
'--tree-view-color': color,
|
|
70
|
+
'--tree-view-bg-color': bgColor,
|
|
71
|
+
}}
|
|
72
|
+
{...other}
|
|
73
|
+
/>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export const MenuTree = ({ items, height, maxWidth, defaultExpanded }: MenuProps) => {
|
|
78
|
+
const { clearNavigate } = useJudoNavigation();
|
|
79
|
+
const intl = useIntl();
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<TreeView
|
|
83
|
+
aria-label="MenuTree"
|
|
84
|
+
defaultExpanded={defaultExpanded}
|
|
85
|
+
defaultCollapseIcon={<ArrowDropDown />}
|
|
86
|
+
defaultExpandIcon={<ArrowRight />}
|
|
87
|
+
defaultEndIcon={<div style={{ width: 24 }} />}
|
|
88
|
+
sx={{ height, flexGrow: 1, maxWidth, overflowY: 'auto' }}
|
|
89
|
+
>
|
|
90
|
+
{items.map(({ labelText, to, items, ...iRest }: JudoTreeItemProps) => (
|
|
91
|
+
<StyledTreeItem
|
|
92
|
+
nodeId={labelText}
|
|
93
|
+
labelText={intl.formatMessage({ id: `menuTree.${labelText}`, defaultMessage: labelText })}
|
|
94
|
+
onClick={() => to && clearNavigate(to)}
|
|
95
|
+
to={to}
|
|
96
|
+
{...iRest}
|
|
97
|
+
>
|
|
98
|
+
{items &&
|
|
99
|
+
items.map(({ labelText: jLabelText, to: jTo, ...jRest }: JudoTreeItemProps) => (
|
|
100
|
+
<StyledTreeItem
|
|
101
|
+
nodeId={jLabelText}
|
|
102
|
+
labelText={intl.formatMessage({ id: `menuTree.${jLabelText}`, defaultMessage: jLabelText })}
|
|
103
|
+
onClick={() => clearNavigate(jTo)}
|
|
104
|
+
to={jTo}
|
|
105
|
+
{...jRest}
|
|
106
|
+
/>
|
|
107
|
+
))}
|
|
108
|
+
</StyledTreeItem>
|
|
109
|
+
))}
|
|
110
|
+
</TreeView>
|
|
111
|
+
);
|
|
112
|
+
};
|
package/src/index.tsx
CHANGED
|
@@ -2,10 +2,10 @@ export * from './dialog';
|
|
|
2
2
|
export * from './table';
|
|
3
3
|
export * from './AggregationInput';
|
|
4
4
|
export * from './CustomBreadcrumb';
|
|
5
|
-
export * from './CustomLink';
|
|
6
5
|
export * from './CustomTablePagination';
|
|
7
6
|
export * from './DropdownButton';
|
|
8
7
|
export * from './Hero';
|
|
9
8
|
export * from './Logo';
|
|
9
|
+
export * from './MenuTree';
|
|
10
10
|
export * from './PageHeader';
|
|
11
11
|
export * from './TrinaryLogicCombobox';
|
package/src/CustomLink.tsx
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { useMatch, useResolvedPath } from 'react-router-dom';
|
|
2
|
-
import type { LinkProps } from 'react-router-dom';
|
|
3
|
-
import { theme } from '@judo/theme';
|
|
4
|
-
import { ListItem, ListItemButton } from '@mui/material';
|
|
5
|
-
import { useJudoNavigation } from './CustomBreadcrumb';
|
|
6
|
-
|
|
7
|
-
const customLinkItemStyle = {
|
|
8
|
-
py: '2px',
|
|
9
|
-
px: 3,
|
|
10
|
-
color: theme.palette.text.secondary,
|
|
11
|
-
'&:hover, &:focus': {
|
|
12
|
-
color: theme.palette.secondary.main,
|
|
13
|
-
},
|
|
14
|
-
'&.Mui-selected': {
|
|
15
|
-
color: theme.palette.secondary.main,
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export function CustomLink({ children, to, ...props }: LinkProps) {
|
|
20
|
-
const resolved = useResolvedPath(to);
|
|
21
|
-
const match = useMatch({ path: resolved.pathname, end: true });
|
|
22
|
-
const { clearNavigate } = useJudoNavigation();
|
|
23
|
-
|
|
24
|
-
const onClickHandler = () => {
|
|
25
|
-
clearNavigate(to);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
<ListItem disablePadding style={{ textDecoration: 'none' }}>
|
|
30
|
-
<ListItemButton selected={!!match} sx={customLinkItemStyle} onClick={onClickHandler}>
|
|
31
|
-
{children}
|
|
32
|
-
</ListItemButton>
|
|
33
|
-
</ListItem>
|
|
34
|
-
);
|
|
35
|
-
}
|