update sidebar
This commit is contained in:
parent
c3d9a696f6
commit
be4a6ed120
23
README.md
23
README.md
@ -814,3 +814,26 @@ function UsersTable({ data, columns }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Sidebar.Exit
|
||||||
|
|
||||||
|
`Sidebar` بهصورت پیشفرض گزینه خروج را نمایش نمیدهد. برای فعالکردن خروج Keycloak داخلی UI Kit، آن را بهصورت compound component اضافه کنید:
|
||||||
|
|
||||||
|
```jsx
|
||||||
|
<Sidebar
|
||||||
|
items={items}
|
||||||
|
currentPath={router.asPath}
|
||||||
|
linkComponent={NextLink}
|
||||||
|
>
|
||||||
|
<Sidebar.Exit />
|
||||||
|
</Sidebar>
|
||||||
|
```
|
||||||
|
|
||||||
|
عنوان و آیکون خروج قابل تغییر هستند:
|
||||||
|
|
||||||
|
```jsx
|
||||||
|
<Sidebar.Exit title="خروج از سامانه" icon={MyExitIcon} />
|
||||||
|
```
|
||||||
|
|
||||||
|
`Sidebar.Exit` از `logoutKeycloak` داخلی UI Kit استفاده میکند و callback خروج از سامانه مقصد نیاز ندارد.
|
||||||
|
|||||||
12
dist/layout.d.ts
vendored
12
dist/layout.d.ts
vendored
@ -13,8 +13,7 @@ export type SidebarProps = {
|
|||||||
currentPath?: string;
|
currentPath?: string;
|
||||||
linkComponent?: any;
|
linkComponent?: any;
|
||||||
onNavigate?: (item: SidebarItem) => void;
|
onNavigate?: (item: SidebarItem) => void;
|
||||||
logoutTitle?: string;
|
children?: any;
|
||||||
logoutIcon?: any;
|
|
||||||
primaryMobileCount?: number;
|
primaryMobileCount?: number;
|
||||||
moreTitle?: string;
|
moreTitle?: string;
|
||||||
moreDrawerTitle?: string;
|
moreDrawerTitle?: string;
|
||||||
@ -22,7 +21,14 @@ export type SidebarProps = {
|
|||||||
mobileProps?: Record<string, any>;
|
mobileProps?: Record<string, any>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function Sidebar(props: SidebarProps): any;
|
export type SidebarExitProps = {
|
||||||
|
title?: string;
|
||||||
|
icon?: any;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Sidebar: ((props: SidebarProps) => any) & {
|
||||||
|
Exit: (props: SidebarExitProps) => any;
|
||||||
|
};
|
||||||
export function isSidebarPathActive(
|
export function isSidebarPathActive(
|
||||||
currentPath: string | undefined,
|
currentPath: string | undefined,
|
||||||
item: SidebarItem,
|
item: SidebarItem,
|
||||||
|
|||||||
322
dist/layout.js
vendored
322
dist/layout.js
vendored
File diff suppressed because one or more lines are too long
@ -19,9 +19,9 @@ import {
|
|||||||
VStack,
|
VStack,
|
||||||
useDisclosure,
|
useDisclosure,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import { forwardRef, useEffect, useRef } from "react";
|
import { Children, forwardRef, isValidElement, useEffect, useRef } from "react";
|
||||||
import { FiMoreHorizontal } from "react-icons/fi";
|
import { FiMoreHorizontal } from "react-icons/fi/index.js";
|
||||||
import { IoExit } from "react-icons/io5";
|
import { IoExit } from "react-icons/io5/index.js";
|
||||||
import { logoutKeycloak } from "../core/keycloak.jsx";
|
import { logoutKeycloak } from "../core/keycloak.jsx";
|
||||||
import { usePermission } from "../core/permission.jsx";
|
import { usePermission } from "../core/permission.jsx";
|
||||||
|
|
||||||
@ -165,13 +165,14 @@ const MobileNavigationButton = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Sidebar = ({
|
const SidebarExit = () => null;
|
||||||
|
|
||||||
|
const SidebarRoot = ({
|
||||||
items = [],
|
items = [],
|
||||||
currentPath,
|
currentPath,
|
||||||
linkComponent,
|
linkComponent,
|
||||||
onNavigate,
|
onNavigate,
|
||||||
logoutTitle = "خروج",
|
children,
|
||||||
logoutIcon = IoExit,
|
|
||||||
primaryMobileCount = 4,
|
primaryMobileCount = 4,
|
||||||
moreTitle = "بیشتر",
|
moreTitle = "بیشتر",
|
||||||
moreDrawerTitle = "سایر بخشهای سامانه",
|
moreDrawerTitle = "سایر بخشهای سامانه",
|
||||||
@ -182,6 +183,13 @@ export const Sidebar = ({
|
|||||||
const moreButtonRef = useRef();
|
const moreButtonRef = useRef();
|
||||||
const { cannot, can, isLoading } = usePermission();
|
const { cannot, can, isLoading } = usePermission();
|
||||||
|
|
||||||
|
const exitElement = Children.toArray(children).find(
|
||||||
|
(child) => isValidElement(child) && child.type === SidebarExit,
|
||||||
|
);
|
||||||
|
const hasExit = Boolean(exitElement);
|
||||||
|
const logoutTitle = exitElement?.props?.title || "خروج";
|
||||||
|
const logoutIcon = exitElement?.props?.icon || IoExit;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isLoading) return;
|
if (isLoading) return;
|
||||||
|
|
||||||
@ -209,7 +217,7 @@ export const Sidebar = ({
|
|||||||
const active = (item) => isSidebarPathActive(resolvedCurrentPath, item);
|
const active = (item) => isSidebarPathActive(resolvedCurrentPath, item);
|
||||||
|
|
||||||
const isSecondaryItemActive = secondaryItems.some(active);
|
const isSecondaryItemActive = secondaryItems.some(active);
|
||||||
const hasMoreContent = true;
|
const hasMoreContent = secondaryItems.length > 0 || hasExit;
|
||||||
|
|
||||||
const handleNavigate = (item) => {
|
const handleNavigate = (item) => {
|
||||||
onNavigate?.(item);
|
onNavigate?.(item);
|
||||||
@ -252,6 +260,7 @@ export const Sidebar = ({
|
|||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
|
{hasExit && (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
label={logoutTitle}
|
label={logoutTitle}
|
||||||
placement="left-start"
|
placement="left-start"
|
||||||
@ -271,6 +280,7 @@ export const Sidebar = ({
|
|||||||
onClick={handleLogout}
|
onClick={handleLogout}
|
||||||
/>
|
/>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
)}
|
||||||
</VStack>
|
</VStack>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
@ -414,6 +424,7 @@ export const Sidebar = ({
|
|||||||
})}
|
})}
|
||||||
</SimpleGrid>
|
</SimpleGrid>
|
||||||
|
|
||||||
|
{hasExit && (
|
||||||
<Box mt={4} pt={4} borderTopWidth="1px" borderColor="gray.200">
|
<Box mt={4} pt={4} borderTopWidth="1px" borderColor="gray.200">
|
||||||
<HStack
|
<HStack
|
||||||
as="button"
|
as="button"
|
||||||
@ -429,9 +440,10 @@ export const Sidebar = ({
|
|||||||
onClick={handleLogout}
|
onClick={handleLogout}
|
||||||
>
|
>
|
||||||
<Icon as={logoutIcon} boxSize={5} />
|
<Icon as={logoutIcon} boxSize={5} />
|
||||||
<Text fontWeight="bold">خروج از سامانه</Text>
|
<Text fontWeight="bold">{logoutTitle}</Text>
|
||||||
</HStack>
|
</HStack>
|
||||||
</Box>
|
</Box>
|
||||||
|
)}
|
||||||
</DrawerBody>
|
</DrawerBody>
|
||||||
</DrawerContent>
|
</DrawerContent>
|
||||||
</Drawer>
|
</Drawer>
|
||||||
@ -439,3 +451,7 @@ export const Sidebar = ({
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const Sidebar = Object.assign(SidebarRoot, {
|
||||||
|
Exit: SidebarExit,
|
||||||
|
});
|
||||||
|
|||||||
12
src/layout/index.d.ts
vendored
12
src/layout/index.d.ts
vendored
@ -13,8 +13,7 @@ export type SidebarProps = {
|
|||||||
currentPath?: string;
|
currentPath?: string;
|
||||||
linkComponent?: any;
|
linkComponent?: any;
|
||||||
onNavigate?: (item: SidebarItem) => void;
|
onNavigate?: (item: SidebarItem) => void;
|
||||||
logoutTitle?: string;
|
children?: any;
|
||||||
logoutIcon?: any;
|
|
||||||
primaryMobileCount?: number;
|
primaryMobileCount?: number;
|
||||||
moreTitle?: string;
|
moreTitle?: string;
|
||||||
moreDrawerTitle?: string;
|
moreDrawerTitle?: string;
|
||||||
@ -22,7 +21,14 @@ export type SidebarProps = {
|
|||||||
mobileProps?: Record<string, any>;
|
mobileProps?: Record<string, any>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function Sidebar(props: SidebarProps): any;
|
export type SidebarExitProps = {
|
||||||
|
title?: string;
|
||||||
|
icon?: any;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Sidebar: ((props: SidebarProps) => any) & {
|
||||||
|
Exit: (props: SidebarExitProps) => any;
|
||||||
|
};
|
||||||
export function isSidebarPathActive(
|
export function isSidebarPathActive(
|
||||||
currentPath: string | undefined,
|
currentPath: string | undefined,
|
||||||
item: SidebarItem,
|
item: SidebarItem,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user