From b7c1a5a040bb2151aea39b68e9815d67bcb46e7f Mon Sep 17 00:00:00 2001 From: Philipp Hugenroth Date: Wed, 11 Aug 2021 20:11:22 +0200 Subject: [PATCH] Add SidebarGroup & BottomNavigation components Signed-off-by: Philipp Hugenroth --- packages/app/src/components/Root/Root.tsx | 7 +++ .../src/layout/Sidebar/Bar.tsx | 22 ++++---- .../src/layout/Sidebar/BottomNavigation.tsx | 52 +++++++++++++++++++ .../src/layout/Sidebar/Group.tsx | 28 ++++++++++ .../src/layout/Sidebar/index.ts | 3 +- 5 files changed, 98 insertions(+), 14 deletions(-) create mode 100644 packages/core-components/src/layout/Sidebar/BottomNavigation.tsx create mode 100644 packages/core-components/src/layout/Sidebar/Group.tsx diff --git a/packages/app/src/components/Root/Root.tsx b/packages/app/src/components/Root/Root.tsx index 7a666a020a..a8ce1451da 100644 --- a/packages/app/src/components/Root/Root.tsx +++ b/packages/app/src/components/Root/Root.tsx @@ -40,6 +40,8 @@ import { SidebarDivider, SidebarSpace, SidebarScrollWrapper, + BottomNavigation, + SidebarGroup, } from '@backstage/core-components'; const useSidebarLogoStyles = makeStyles({ @@ -101,6 +103,11 @@ export const Root = ({ children }: PropsWithChildren<{}>) => ( + + + + + {children} ); diff --git a/packages/core-components/src/layout/Sidebar/Bar.tsx b/packages/core-components/src/layout/Sidebar/Bar.tsx index e6fa3820ad..9ee63c1c3d 100644 --- a/packages/core-components/src/layout/Sidebar/Bar.tsx +++ b/packages/core-components/src/layout/Sidebar/Bar.tsx @@ -133,20 +133,17 @@ export function Sidebar(props: PropsWithChildren) { const isOpen = (state === State.Open && !isSmallScreen) || isPinned; return ( -
-
) { {children}
-
); } diff --git a/packages/core-components/src/layout/Sidebar/BottomNavigation.tsx b/packages/core-components/src/layout/Sidebar/BottomNavigation.tsx new file mode 100644 index 0000000000..2356cab249 --- /dev/null +++ b/packages/core-components/src/layout/Sidebar/BottomNavigation.tsx @@ -0,0 +1,52 @@ +/* + * Copyright 2020 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + BottomNavigation as MUIBottomNavigation, + makeStyles, +} from '@material-ui/core'; +import React from 'react'; + +const useStyles = makeStyles({ + root: { + position: 'fixed', + bottom: 0, + left: 0, + right: 0, + }, +}); + +/** + * Filters for sidebar groups and reorders them to create a custom BottomNavigation + */ +export const BottomNavigation = ({ children }: React.PropsWithChildren<{}>) => { + const classes = useStyles(); + const [value, setValue] = React.useState('recents'); + + const handleChange = (event: React.ChangeEvent<{}>, newValue: string) => { + setValue(newValue); + }; + + return ( + + {children} + + ); +}; diff --git a/packages/core-components/src/layout/Sidebar/Group.tsx b/packages/core-components/src/layout/Sidebar/Group.tsx new file mode 100644 index 0000000000..f346daa9a1 --- /dev/null +++ b/packages/core-components/src/layout/Sidebar/Group.tsx @@ -0,0 +1,28 @@ +/* + * Copyright 2020 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { BottomNavigationAction } from '@material-ui/core'; +import MenuIcon from '@material-ui/icons/Menu'; +import React from 'react'; + +/** + * If the page is mobile it should be BottomNavigationAction - otherwise just a fragment + * Links to page, which will be displayed + * - If 'to' Prop is not defined it will render a Menu page out of the children (if children given) + */ +export const SidebarGroup = ({ children }: React.PropsWithChildren<{}>) => { + return } />; +}; diff --git a/packages/core-components/src/layout/Sidebar/index.ts b/packages/core-components/src/layout/Sidebar/index.ts index 067a9bf2eb..cc1d127787 100644 --- a/packages/core-components/src/layout/Sidebar/index.ts +++ b/packages/core-components/src/layout/Sidebar/index.ts @@ -15,7 +15,8 @@ */ export { Sidebar } from './Bar'; -export type { SidebarClassKey } from './Bar'; +export { BottomNavigation } from './BottomNavigation'; +export { SidebarGroup } from './Group'; export { SidebarPage, SidebarPinStateContext } from './Page'; export type { SidebarPinStateContextType, SidebarPageClassKey } from './Page'; export {