@mui/icons-material#KeyboardBackspace TypeScript Examples
The following examples show how to use
@mui/icons-material#KeyboardBackspace.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.tsx From Search-Next with GNU General Public License v3.0 | 4 votes |
MenuLayoutNew: React.FC<MenuLayoutNewProps> = ({
children,
route,
pathname,
mode = 'page',
menu = [],
contentHeader,
menuFooter,
onChange,
...props
}) => {
const [menuList, setMenuList] = React.useState<Router[] | undefined>([]);
const [breads, setBreads] = React.useState<Router[]>([]);
const history = useNavigate();
const getBreadCrumbs = (routes: Router[], newLocation?: any) => {
let breadCrumbs: Router[] = [];
const findRoute = (routes: Router[] | undefined) => {
if (!routes) return routes;
const loc = newLocation ? newLocation : location;
routes.forEach((i) => {
if (loc.pathname.indexOf(i.path) !== -1) {
breadCrumbs.push(i);
}
if (i.routes) {
findRoute(i.routes);
}
});
};
findRoute(routes);
return breadCrumbs;
};
React.useEffect(() => {
if (mode === 'route') {
if (location.pathname === pathname) {
history(route?.routes?.[0].path || pathname, { replace: true });
}
setMenuList(route?.routes);
} else {
setMenuList(menu);
}
}, []);
React.useEffect(() => {
const breads = getBreadCrumbs(route.routes || []);
setBreads(breads);
}, [location]);
return (
<div className="flex flex-row h-screen bg-gray-70">
<div className="w-72 p-4 h-full flex flex-col">
<div className="flex gap-1">
<Tooltip title="回到首页" arrow>
<IconButton
size="small"
onClick={() => {
history('/');
}}
>
<Home />
</IconButton>
</Tooltip>
<Tooltip title="返回上级" arrow>
<IconButton
size="small"
onClick={() => {
history(-1);
}}
>
<KeyboardBackspace />
</IconButton>
</Tooltip>
</div>
<Menu datasource={menuList} mode="route" onChange={onChange} />
<div>{menuFooter}</div>
</div>
<div className="h-full overflow-hidden flex flex-col w-full px-6 py-4">
<div>{contentHeader}</div>
<div className="flex-grow overflow-y-auto w-full my-4 pb-2">
<div className="max-w-4xl pl-1">{children}</div>
</div>
<div className="text-center max-w-4xl">
<Copyright />
</div>
</div>
</div>
);
}
Example #2
Source File: index.tsx From Search-Next with GNU General Public License v3.0 | 4 votes |
SettingPage: React.FC<SettingPageProps> = ({
children,
route,
...props
}) => {
const history = useNavigate();
const location = useLocation();
const params = useParams();
const [menuList, setMenuList] = React.useState<Router[] | undefined>([]);
const [breads, setBreads] = React.useState<Router[]>([]);
const getBreadCrumbs = (routes: Router[], parentPath: string = '') => {
let breadCrumbs: Router[] = [];
const findRoute = (
routes: Router[] | undefined,
parentPath: string = '',
) => {
if (!routes) return routes;
const loc = location;
routes.forEach((i) => {
const fullPath = `${parentPath}/${i.path}`;
const splitPath = fullPath.split(':');
const paramsPath =
splitPath[0] +
Object.values(params)
.filter((u) => u !== '')
.join('/');
if (
loc.pathname.indexOf(i.path) !== -1 ||
loc.pathname === paramsPath
) {
breadCrumbs.push(i);
}
if (i.routes) {
findRoute(i.routes, fullPath);
}
});
};
findRoute(routes, parentPath);
return breadCrumbs;
};
React.useEffect(() => {
if (location.pathname === '/setting') {
history(route?.routes?.[0].path || '/setting', { replace: true });
}
setMenuList(route?.routes);
}, []);
React.useEffect(() => {
const breads = getBreadCrumbs(route.routes || [], '/setting');
setBreads(breads);
}, [location]);
return (
<div className="flex flex-row h-screen bg-gray-70">
<div className="w-72 p-4 h-full">
<div className="flex gap-1">
<Tooltip title="回到首页" arrow>
<IconButton
size="small"
onClick={() => {
history('/');
}}
>
<Home />
</IconButton>
</Tooltip>
<Tooltip title="返回上级" arrow>
<IconButton
size="small"
onClick={() => {
history(-1);
}}
>
<KeyboardBackspace />
</IconButton>
</Tooltip>
</div>
<div className="flex flex-col gap-1 my-4">
{menuList?.map((i) => (
<div
key={i.path}
className={classNames(
'hover:bg-gray-150',
'transition-all',
'px-2.5',
'py-1.5',
'cursor-pointer',
'rounded',
'text-sm',
'text-gray-800',
{
'bg-gray-150': location.pathname.indexOf(i.path) > -1,
},
)}
onClick={() => {
history(i.path);
}}
>
{i.title}
</div>
))}
</div>
</div>
<div className="h-full overflow-hidden flex flex-col w-full px-6 py-4">
<Breadcrumbs separator="›" aria-label="breadcrumb" className="mb-4">
{breads.map((i, index) => (
<div
className={classNames('text-2xl cursor-pointer mb-0', {
'font-semibold': index === breads.length - 1,
})}
key={i.path}
onClick={() => {
const path =
'/setting/' +
breads
.map((i) => i.path)
.filter((_, ji) => ji <= index)
.join('/');
index !== breads.length - 1 ? history(path) : null;
}}
>
<div className="flex items-center gap-1">
{i.title}
{i?.status === 'process' && (
<Chip
color="warning"
label={i?.status}
size="small"
variant="outlined"
/>
)}
</div>
</div>
))}
</Breadcrumbs>
<div className="flex-grow overflow-y-auto w-full">
<div className="max-w-4xl">
<Outlet />
</div>
</div>
<div className="text-center max-w-4xl">
<Copyright />
</div>
</div>
</div>
);
}