From c040c9d118c192d8cffe7fade30fecadd684d2ae Mon Sep 17 00:00:00 2001 From: tudi2d Date: Fri, 12 Feb 2021 00:27:49 +0100 Subject: [PATCH] Add hidden & layered breadcrumbs - Override style of given components --- .../Breadcrumbs/Breadcrumbs.stories.tsx | 114 +++++++++++++++-- .../src/layout/Breadcrumbs/Breadcrumbs.tsx | 121 ++++++++++-------- 2 files changed, 170 insertions(+), 65 deletions(-) diff --git a/packages/core/src/layout/Breadcrumbs/Breadcrumbs.stories.tsx b/packages/core/src/layout/Breadcrumbs/Breadcrumbs.stories.tsx index f21b5a94e6..f2a6611d03 100644 --- a/packages/core/src/layout/Breadcrumbs/Breadcrumbs.stories.tsx +++ b/packages/core/src/layout/Breadcrumbs/Breadcrumbs.stories.tsx @@ -13,9 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import React from 'react'; -import { Breadcrumbs } from '.'; +import { Popover, Typography, Box, List, ListItem } from '@material-ui/core'; +import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; +import ExpandLessIcon from '@material-ui/icons/ExpandLess'; +import React, { Fragment } from 'react'; import { MemoryRouter } from 'react-router-dom'; +import { Breadcrumbs } from '.'; import { Link } from '../../components/Link'; export default { @@ -24,12 +27,101 @@ export default { }; // export const InHeader = () => ; -export const OutsideOfHeader = () => ( - - - Home - Home - - -); -// export const ExampleUsage = () => ; +export const OutsideOfHeader = () => { + const [anchorEl, setAnchorEl] = React.useState( + null, + ); + const handleClick = (event: React.MouseEvent) => { + setAnchorEl(event.currentTarget); + }; + + const handleClose = () => { + setAnchorEl(null); + }; + + const open = Boolean(anchorEl); + return ( + +

+ It might be the case that you want to keep your breadcrumbs outside of + the header. In that case, they should be positioned above the title of + the page. +

+

Standard breadcrumbs

+

+ Underlined pages are links. This should show a hierarchical + relationship. +

+ + General Page + Second Page + Current page + + + General Page + Current page + + + Current page + + +

Hidden breadcrumbs

+

+ Use this when you have more than three breadcrumbs. When user clicks on + ellipses, expand the breadcrumbs out. +

+ + + General Page + Second Page + Third Page + Fourth Page + Current page + + +

Layered breadcrumbs

+

+ Use this when you want to show alternative breadcrumbs on the same + hierarchical level. +

+ + + + General Page + + + Second Page + {open ? : } + + + Current page + + + + + Parallel second page + + + Another parallel second page + + + Yet another, parallel second page + + + + +
+ ); +}; diff --git a/packages/core/src/layout/Breadcrumbs/Breadcrumbs.tsx b/packages/core/src/layout/Breadcrumbs/Breadcrumbs.tsx index c88b446d8c..6da9d7ad4d 100644 --- a/packages/core/src/layout/Breadcrumbs/Breadcrumbs.tsx +++ b/packages/core/src/layout/Breadcrumbs/Breadcrumbs.tsx @@ -14,75 +14,88 @@ * limitations under the License. */ -import React, { Fragment } from 'react'; import { - Typography, - Breadcrumbs as MUIBreadcrumbs, + Box, + Breadcrumbs as MaterialBreadcrumbs, + List, + ListItem, Popover, + Typography, withStyles, } from '@material-ui/core'; +import React, { ComponentProps, Fragment } from 'react'; -type BreadcrumbsProps = { - children?: React.ReactNode; -}; +type Props = ComponentProps; -const UnderlinedText = withStyles({ root: { textDecoration: 'underline' } })( - Typography, -); +const ClickableText = withStyles({ + root: { + textDecoration: 'underline', + cursor: 'pointer', + }, +})(Typography); -const StyledBreadcrumbs = withStyles({ - root: {}, - li: { textDecoration: 'underline' }, -})(MUIBreadcrumbs); +const StyledBox = withStyles(theme => ({ + root: { + textDecoration: 'underline', + color: theme.palette.text.primary, + }, +}))(Box); -export const Breadcrumbs = ({ children }: BreadcrumbsProps) => { +export const Breadcrumbs = ({ children, ...props }: Props) => { const [anchorEl, setAnchorEl] = React.useState( null, ); - if (children instanceof Array) { - const [firstPage, secondPage, ...expandablePages] = children; - const currentPage = children[children.length - 1]; - const hasHiddenBreadcrumbs = children.length > 3; + const childrenArray = React.Children.toArray(children); - const handleClick = (event: React.MouseEvent) => { - setAnchorEl(event.currentTarget); - }; + const [firstPage, secondPage, ...expandablePages] = childrenArray; + const currentPage = expandablePages.length + ? expandablePages.pop() + : childrenArray[childrenArray.length - 1]; + const hasHiddenBreadcrumbs = childrenArray.length > 3; - const handleClose = () => { - setAnchorEl(null); - }; + const handleClick = (event: React.MouseEvent) => { + setAnchorEl(event.currentTarget); + }; - const open = Boolean(anchorEl); - return ( - - - {children.length > 1 && firstPage} - {children.length > 2 && secondPage} - {hasHiddenBreadcrumbs && ( - ... - )} - {currentPage} - - - The content of the Popover. - - - ); - } + const handleClose = () => { + setAnchorEl(null); + }; + + const open = Boolean(anchorEl); return ( - {children} + + + {childrenArray.length > 1 && {firstPage}} + {childrenArray.length > 2 && {secondPage}} + {hasHiddenBreadcrumbs && ( + ... + )} + + {currentPage} + + + + + {expandablePages.map(pageLink => ( + + {pageLink} + + ))} + + + ); };