From ee109df863878ef530cd162c86ec9f488be2e298 Mon Sep 17 00:00:00 2001
From: tudi2d
Date: Wed, 10 Feb 2021 23:14:02 +0100
Subject: [PATCH 1/7] Start building Breadcrumbs component
- Implement hidden breadcrumbs
---
.../Breadcrumbs/Breadcrumbs.stories.tsx | 45 +++++++++
.../layout/Breadcrumbs/Breadcrumbs.test.tsx | 15 +++
.../src/layout/Breadcrumbs/Breadcrumbs.tsx | 93 +++++++++++++++++++
packages/core/src/layout/Breadcrumbs/index.ts | 17 ++++
packages/core/src/layout/index.ts | 1 +
5 files changed, 171 insertions(+)
create mode 100644 packages/core/src/layout/Breadcrumbs/Breadcrumbs.stories.tsx
create mode 100644 packages/core/src/layout/Breadcrumbs/Breadcrumbs.test.tsx
create mode 100644 packages/core/src/layout/Breadcrumbs/Breadcrumbs.tsx
create mode 100644 packages/core/src/layout/Breadcrumbs/index.ts
diff --git a/packages/core/src/layout/Breadcrumbs/Breadcrumbs.stories.tsx b/packages/core/src/layout/Breadcrumbs/Breadcrumbs.stories.tsx
new file mode 100644
index 0000000000..18569a8dad
--- /dev/null
+++ b/packages/core/src/layout/Breadcrumbs/Breadcrumbs.stories.tsx
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2020 Spotify AB
+ *
+ * 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 React from 'react';
+import { Breadcrumbs } from '.';
+
+export default {
+ title: 'Layout/Breadcrumbs',
+ component: Breadcrumbs,
+};
+
+const pages = [
+ {
+ href: '/',
+ name: 'A',
+ },
+ {
+ href: '/',
+ name: 'B',
+ },
+ {
+ href: '/',
+ name: 'C',
+ },
+ {
+ href: '/',
+ name: 'D',
+ },
+];
+
+// export const InHeader = () => ;
+export const OutsideOfHeader = () => ;
+// export const ExampleUsage = () => ;
diff --git a/packages/core/src/layout/Breadcrumbs/Breadcrumbs.test.tsx b/packages/core/src/layout/Breadcrumbs/Breadcrumbs.test.tsx
new file mode 100644
index 0000000000..f3b69cc361
--- /dev/null
+++ b/packages/core/src/layout/Breadcrumbs/Breadcrumbs.test.tsx
@@ -0,0 +1,15 @@
+/*
+ * Copyright 2020 Spotify AB
+ *
+ * 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.
+ */
diff --git a/packages/core/src/layout/Breadcrumbs/Breadcrumbs.tsx b/packages/core/src/layout/Breadcrumbs/Breadcrumbs.tsx
new file mode 100644
index 0000000000..78761d9db2
--- /dev/null
+++ b/packages/core/src/layout/Breadcrumbs/Breadcrumbs.tsx
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2020 Spotify AB
+ *
+ * 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 React from 'react';
+import {
+ Link,
+ Typography,
+ Breadcrumbs as MUIBreadcrumbs,
+ Popover,
+ withStyles,
+} from '@material-ui/core';
+
+type BreadcrumbPage = {
+ href: string;
+ name: string;
+};
+
+type BreadcrumbsProps = {
+ pages: (BreadcrumbPage | BreadcrumbPage)[];
+};
+
+const UnderlinedText = withStyles({ root: { textDecoration: 'underline' } })(
+ Typography,
+);
+
+const Breadcrumb = ({ page }: { page: BreadcrumbPage }) => (
+
+ {page.name}
+
+);
+
+// Should propbably take Routes instead, to work with the react-router
+export const Breadcrumbs = ({ pages }: BreadcrumbsProps) => {
+ const [anchorEl, setAnchorEl] = React.useState(
+ null,
+ );
+ const hasHiddenBreadcrumbs = pages.length > 3;
+ const [firstPage, secondPage, ...expandablePages] = pages;
+ const currentPage = pages[pages.length - 1];
+
+ const handleClick = (event: React.MouseEvent) => {
+ setAnchorEl(event.currentTarget);
+ };
+
+ const handleClose = () => {
+ setAnchorEl(null);
+ };
+
+ const open = Boolean(anchorEl);
+
+ return (
+
+ {firstPage && pages.length > 1 && }
+ {secondPage && pages.length > 2 && }
+ {hasHiddenBreadcrumbs && (
+ ...
+ )}
+ {currentPage && {currentPage.name}}
+
+ The content of the Popover.
+
+
+ );
+};
diff --git a/packages/core/src/layout/Breadcrumbs/index.ts b/packages/core/src/layout/Breadcrumbs/index.ts
new file mode 100644
index 0000000000..6c5c2539df
--- /dev/null
+++ b/packages/core/src/layout/Breadcrumbs/index.ts
@@ -0,0 +1,17 @@
+/*
+ * Copyright 2020 Spotify AB
+ *
+ * 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.
+ */
+
+export { Breadcrumbs } from './Breadcrumbs';
diff --git a/packages/core/src/layout/index.ts b/packages/core/src/layout/index.ts
index d97d30982e..2ab1ebaf5b 100644
--- a/packages/core/src/layout/index.ts
+++ b/packages/core/src/layout/index.ts
@@ -28,3 +28,4 @@ export * from './Page';
export * from './Sidebar';
export * from './SignInPage';
export * from './TabbedCard';
+export * from './Breadcrumbs';
From f4f4ad1f4fe6d411da72e5d91d3bd8debc2a1da5 Mon Sep 17 00:00:00 2001
From: tudi2d
Date: Thu, 11 Feb 2021 12:14:36 +0100
Subject: [PATCH 2/7] Rethink component structure to be more flexible -
Following MUI's Breadcrumbs component design
---
.../Breadcrumbs/Breadcrumbs.stories.tsx | 30 ++----
.../src/layout/Breadcrumbs/Breadcrumbs.tsx | 99 +++++++++----------
2 files changed, 57 insertions(+), 72 deletions(-)
diff --git a/packages/core/src/layout/Breadcrumbs/Breadcrumbs.stories.tsx b/packages/core/src/layout/Breadcrumbs/Breadcrumbs.stories.tsx
index 18569a8dad..f21b5a94e6 100644
--- a/packages/core/src/layout/Breadcrumbs/Breadcrumbs.stories.tsx
+++ b/packages/core/src/layout/Breadcrumbs/Breadcrumbs.stories.tsx
@@ -15,31 +15,21 @@
*/
import React from 'react';
import { Breadcrumbs } from '.';
+import { MemoryRouter } from 'react-router-dom';
+import { Link } from '../../components/Link';
export default {
title: 'Layout/Breadcrumbs',
component: Breadcrumbs,
};
-const pages = [
- {
- href: '/',
- name: 'A',
- },
- {
- href: '/',
- name: 'B',
- },
- {
- href: '/',
- name: 'C',
- },
- {
- href: '/',
- name: 'D',
- },
-];
-
// export const InHeader = () => ;
-export const OutsideOfHeader = () => ;
+export const OutsideOfHeader = () => (
+
+
+ Home
+ Home
+
+
+);
// export const ExampleUsage = () => ;
diff --git a/packages/core/src/layout/Breadcrumbs/Breadcrumbs.tsx b/packages/core/src/layout/Breadcrumbs/Breadcrumbs.tsx
index 78761d9db2..c88b446d8c 100644
--- a/packages/core/src/layout/Breadcrumbs/Breadcrumbs.tsx
+++ b/packages/core/src/layout/Breadcrumbs/Breadcrumbs.tsx
@@ -14,80 +14,75 @@
* limitations under the License.
*/
-import React from 'react';
+import React, { Fragment } from 'react';
import {
- Link,
Typography,
Breadcrumbs as MUIBreadcrumbs,
Popover,
withStyles,
} from '@material-ui/core';
-type BreadcrumbPage = {
- href: string;
- name: string;
-};
-
type BreadcrumbsProps = {
- pages: (BreadcrumbPage | BreadcrumbPage)[];
+ children?: React.ReactNode;
};
const UnderlinedText = withStyles({ root: { textDecoration: 'underline' } })(
Typography,
);
-const Breadcrumb = ({ page }: { page: BreadcrumbPage }) => (
-
- {page.name}
-
-);
+const StyledBreadcrumbs = withStyles({
+ root: {},
+ li: { textDecoration: 'underline' },
+})(MUIBreadcrumbs);
-// Should propbably take Routes instead, to work with the react-router
-export const Breadcrumbs = ({ pages }: BreadcrumbsProps) => {
+export const Breadcrumbs = ({ children }: BreadcrumbsProps) => {
const [anchorEl, setAnchorEl] = React.useState(
null,
);
- const hasHiddenBreadcrumbs = pages.length > 3;
- const [firstPage, secondPage, ...expandablePages] = pages;
- const currentPage = pages[pages.length - 1];
- const handleClick = (event: React.MouseEvent) => {
- setAnchorEl(event.currentTarget);
- };
+ if (children instanceof Array) {
+ const [firstPage, secondPage, ...expandablePages] = children;
+ const currentPage = children[children.length - 1];
+ const hasHiddenBreadcrumbs = children.length > 3;
- const handleClose = () => {
- setAnchorEl(null);
- };
+ const handleClick = (event: React.MouseEvent) => {
+ setAnchorEl(event.currentTarget);
+ };
- const open = Boolean(anchorEl);
+ const handleClose = () => {
+ setAnchorEl(null);
+ };
+ const open = Boolean(anchorEl);
+ return (
+
+
+ {children.length > 1 && firstPage}
+ {children.length > 2 && secondPage}
+ {hasHiddenBreadcrumbs && (
+ ...
+ )}
+ {currentPage}
+
+
+ The content of the Popover.
+
+
+ );
+ }
return (
-
- {firstPage && pages.length > 1 && }
- {secondPage && pages.length > 2 && }
- {hasHiddenBreadcrumbs && (
- ...
- )}
- {currentPage && {currentPage.name}}
-
- The content of the Popover.
-
-
+ {children}
);
};
From c040c9d118c192d8cffe7fade30fecadd684d2ae Mon Sep 17 00:00:00 2001
From: tudi2d
Date: Fri, 12 Feb 2021 00:27:49 +0100
Subject: [PATCH 3/7] 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.
+
+ Underlined pages are links. This should show a hierarchical relationship.
+
+
+
+
+
+
+);
+
export const OutsideOfHeader = () => {
const [anchorEl, setAnchorEl] = React.useState(
null,
@@ -47,23 +60,20 @@ export const OutsideOfHeader = () => {
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
-