mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-28 14:16:41 +07:00
added sidebar navigation
This commit is contained in:
parent
1bb08f72e6
commit
a03f80259d
6 changed files with 150 additions and 70 deletions
|
@ -1,11 +1,21 @@
|
|||
import React, { createContext, FC, PropsWithChildren, useCallback, useContext, useMemo, useState } from 'react';
|
||||
import React, {
|
||||
createContext,
|
||||
FC,
|
||||
PropsWithChildren,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useState,
|
||||
} from "react";
|
||||
|
||||
import { isNil } from '~/utils/ramda';
|
||||
import { isNil } from "~/utils/ramda";
|
||||
|
||||
import styles from './styles.module.scss';
|
||||
import styles from "./styles.module.scss";
|
||||
|
||||
interface SidebarStackProps extends PropsWithChildren<{}> {
|
||||
initialTab?: number;
|
||||
tab?: number;
|
||||
onTabChange?: (index?: number) => void;
|
||||
}
|
||||
|
||||
interface SidebarStackContextValue {
|
||||
|
@ -38,12 +48,31 @@ const SidebarCards: FC = ({ children }) => {
|
|||
return <div className={styles.card}>{nonEmptyChildren[activeTab]}</div>;
|
||||
};
|
||||
|
||||
const SidebarStack = function({ children, initialTab }: SidebarStackProps) {
|
||||
const [activeTab, setActiveTab] = useState<number | undefined>(initialTab);
|
||||
const closeAllTabs = useCallback(() => setActiveTab(undefined), []);
|
||||
const SidebarStack = function({
|
||||
children,
|
||||
tab,
|
||||
onTabChange,
|
||||
}: SidebarStackProps) {
|
||||
const [activeTab, setActiveTab] = useState<number | undefined>(tab);
|
||||
|
||||
const closeAllTabs = useCallback(() => {
|
||||
setActiveTab(undefined);
|
||||
onTabChange?.(undefined);
|
||||
}, []);
|
||||
|
||||
const onChangeTab = useCallback(
|
||||
(index: number) => {
|
||||
onTabChange?.(index);
|
||||
setActiveTab(index);
|
||||
},
|
||||
[onTabChange],
|
||||
);
|
||||
|
||||
useEffect(() => setActiveTab(tab), [tab]);
|
||||
return (
|
||||
<SidebarStackContext.Provider value={{ activeTab, setActiveTab, closeAllTabs }}>
|
||||
<SidebarStackContext.Provider
|
||||
value={{ activeTab, setActiveTab: onChangeTab, closeAllTabs }}
|
||||
>
|
||||
<div className={styles.stack}>{children}</div>
|
||||
</SidebarStackContext.Provider>
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue