Skip to content

Commit 8338125

Browse files
committed
Merge remote-tracking branch 'origin/feat/themes-example-app' into beta
2 parents ce2338e + aab7f1f commit 8338125

File tree

4 files changed

+60
-10
lines changed

4 files changed

+60
-10
lines changed

.babelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
}
1414
],
1515
"@babel/preset-typescript"
16-
]
16+
],
17+
"ignore": ["./src/themes/**/*.bundle.js"]
1718
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import {
2+
Button,
3+
DropDown,
4+
DropDownItem,
5+
DropDownMenu,
6+
DropDownTrigger,
7+
Icon,
8+
NavigationElementWithChildrenProps,
9+
} from '@adminjs/design-system';
10+
import { ReduxState, useNavigationResources } from 'adminjs';
11+
import React, { FC } from 'react';
12+
import { useSelector } from 'react-redux';
13+
14+
const NavigationComponent: FC = () => {
15+
const resources = useSelector((state: ReduxState) => state.resources);
16+
const navigatonElements = useNavigationResources(resources);
17+
18+
console.log(navigatonElements);
19+
20+
return (
21+
<>
22+
{navigatonElements.map(element => (
23+
<DropDown key={element.label}>
24+
<DropDownTrigger>
25+
<Button color="text">
26+
<Icon icon={element.icon} />
27+
{element.label}
28+
</Button>
29+
</DropDownTrigger>
30+
<DropDownMenu>
31+
<NavigationElement key={element.href} element={element} />
32+
</DropDownMenu>
33+
</DropDown>
34+
))}
35+
</>
36+
);
37+
};
38+
39+
const NavigationElement: FC<{
40+
element: NavigationElementWithChildrenProps;
41+
}> = ({ element }) => (
42+
<DropDownItem>
43+
<Icon icon={element.icon} />
44+
{element.label}
45+
{element.elements && (
46+
<DropDownMenu>
47+
{element.elements.map(nested => (
48+
<NavigationElement key={nested.href} element={nested} />
49+
))}
50+
</DropDownMenu>
51+
)}
52+
</DropDownItem>
53+
);
54+
55+
export const Navigation = React.memo(NavigationComponent);

src/themes/no-sidebar/components/TopBar.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@ import {
1313
} from 'adminjs';
1414
import React from 'react';
1515
import { useSelector } from 'react-redux';
16+
import { Navigation } from '../assets/Navigation.jsx';
1617

1718
const h = new ViewHelpers();
1819

1920
const TopBar: React.FC = () => {
20-
const resources = useSelector((state: ReduxState) => state.resources);
2121
const session = useSelector((state: ReduxState) => state.session);
2222
const branding = useSelector((state: ReduxState) => state.branding);
2323
const { logo, companyName } = branding;
2424

25-
const elements = useNavigationResources(resources);
2625
const { tb } = useTranslation();
2726

2827
const dropActions: CurrentUserNavProps['dropActions'] = [
@@ -40,12 +39,7 @@ const TopBar: React.FC = () => {
4039
<Box as="a" href={h.dashboardUrl()} mx="xl">
4140
{logo ? <img src={logo} alt={companyName} /> : <h1>{companyName}</h1>}
4241
</Box>
43-
{elements.map(element => (
44-
<Button as="a" href={element.href} color="text" key={element.href}>
45-
<Icon icon={element.icon} />
46-
{element.label}
47-
</Button>
48-
))}
42+
<Navigation />
4943
<Box as="div" flex flexGrow={1} />
5044
{session && (
5145
<CurrentUserNav

src/themes/no-sidebar/theme.bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)