diff --git a/.changeset/fifty-peaches-change.md b/.changeset/fifty-peaches-change.md new file mode 100644 index 00000000..1343db96 --- /dev/null +++ b/.changeset/fifty-peaches-change.md @@ -0,0 +1,5 @@ +--- +'@jpmorganchase/mosaic-plugins': patch +--- + +Fixed BreadcrumbsPlugin not working on Windows. diff --git a/.changeset/pretty-socks-judge.md b/.changeset/pretty-socks-judge.md new file mode 100644 index 00000000..6db54c8c --- /dev/null +++ b/.changeset/pretty-socks-judge.md @@ -0,0 +1,6 @@ +--- +'@jpmorganchase/mosaic-site-components': minor +--- + +Refactor Breadcrumbs to remove usage of lab components. +Fixed non-unique key error in AppHeaderControls. diff --git a/packages/plugins/src/BreadcrumbsPlugin.ts b/packages/plugins/src/BreadcrumbsPlugin.ts index fe666b51..29adb0b5 100644 --- a/packages/plugins/src/BreadcrumbsPlugin.ts +++ b/packages/plugins/src/BreadcrumbsPlugin.ts @@ -31,7 +31,7 @@ const BreadcrumbsPlugin: PluginType( (result, _pathPart, partIndex) => { const breadcrumbRoot = `/${pathParts[0]}`; - const breadcrumbPath = path.join( + const breadcrumbPath = path.posix.join( breadcrumbRoot, ...topAndTailedPath.slice(0, topAndTailedPath.length - partIndex), options.indexPageName diff --git a/packages/site-components/src/AppHeaderControls/index.tsx b/packages/site-components/src/AppHeaderControls/index.tsx index fe2f2682..57c8c92c 100644 --- a/packages/site-components/src/AppHeaderControls/index.tsx +++ b/packages/site-components/src/AppHeaderControls/index.tsx @@ -88,7 +88,9 @@ export const AppHeaderControls: React.FC = () => { {actionMenuOptions.map(option => ( - {option.title} + + {option.title} + ))} diff --git a/packages/site-components/src/Breadcrumbs/Breadcrumb.tsx b/packages/site-components/src/Breadcrumbs/Breadcrumb.tsx index d2b566da..a1aa18a1 100644 --- a/packages/site-components/src/Breadcrumbs/Breadcrumb.tsx +++ b/packages/site-components/src/Breadcrumbs/Breadcrumb.tsx @@ -1,5 +1,5 @@ import React, { forwardRef, ReactNode } from 'react'; -import { Link } from '@jpmorganchase/mosaic-components'; +import { Icon, Link } from '@jpmorganchase/mosaic-components'; import styles from './styles.css'; @@ -7,22 +7,27 @@ export interface BreadcrumbProps { children?: ReactNode; href?: string; isCurrentLevel?: boolean; - overflowLabel?: string; + hideSeparator?: boolean; } -// TODO replace with Salt Breadcrumb when it supports an API that can customize Links export const Breadcrumb = forwardRef(function Breadcrumb( - { children, isCurrentLevel, ...props }, + { children, isCurrentLevel, href, hideSeparator }, ref ) { return ( -
  • +
  • {isCurrentLevel ? ( - {children} + <> + {!hideSeparator && } + {children} + ) : ( - - {children} - + <> + + {children} + + {!hideSeparator && } + )}
  • ); diff --git a/packages/site-components/src/Breadcrumbs/Breadcrumbs.tsx b/packages/site-components/src/Breadcrumbs/Breadcrumbs.tsx index 4e7ac312..f3dcfbeb 100644 --- a/packages/site-components/src/Breadcrumbs/Breadcrumbs.tsx +++ b/packages/site-components/src/Breadcrumbs/Breadcrumbs.tsx @@ -1,9 +1,10 @@ import React from 'react'; import { useRouter } from 'next/router'; -import { Breadcrumbs as SaltBreadcrumbs } from '@salt-ds/lab'; -import { Breadcrumb } from './Breadcrumb'; +import { Menu, MenuItem, MenuPanel, MenuTrigger } from '@salt-ds/core'; +import { Button, Icon } from '@jpmorganchase/mosaic-components'; import styles from './styles.css'; +import { Breadcrumb } from './Breadcrumb'; export type BreadcrumbProps = { id: string; @@ -22,36 +23,61 @@ export const Breadcrumbs: React.FC = ({ breadcrumbs, enabled } return null; } - /** - * TODO - we need appropriate keyboard nav support as well - * The slat cascading menu keyboard nav does not seem to work - * so not much point adding support for enter key selection here - */ const handleClick = (event: React.MouseEvent) => { - const target = event.target as HTMLDivElement; - if (target.classList.contains('saltMenuItem-menuItemText')) { - const breadcrumbIndex = breadcrumbs.findIndex( - breadcrumb => breadcrumb.label.toLowerCase() === target.textContent?.toLowerCase() - ); - - if (breadcrumbIndex > -1) { - router.push(breadcrumbs[breadcrumbIndex].path); - } + const path = event.currentTarget.getAttribute('data-path'); + if (path) { + router.push(path); } }; + const maxItems = 5; + const itemsBeforeCollapse = 1; + + let visibleItemsBefore = breadcrumbs; + let hiddenItems: typeof breadcrumbs = []; + let visibleItemsAfter: typeof breadcrumbs = []; + + if (breadcrumbs.length > maxItems) { + visibleItemsBefore = breadcrumbs.slice(0, itemsBeforeCollapse); + hiddenItems = breadcrumbs.slice(itemsBeforeCollapse, -1); + visibleItemsAfter = breadcrumbs.slice(visibleItemsBefore.length + hiddenItems.length); + } + return ( -
    - - {breadcrumbs.map( - value => - value && ( - - {value.label} - - ) +
    + {visibleItemsAfter.map(({ id, label, path }) => ( + + {label} + + ))} + + ); }; diff --git a/packages/site-components/src/Breadcrumbs/styles.css.ts b/packages/site-components/src/Breadcrumbs/styles.css.ts index ede30f70..953d11b0 100644 --- a/packages/site-components/src/Breadcrumbs/styles.css.ts +++ b/packages/site-components/src/Breadcrumbs/styles.css.ts @@ -8,5 +8,27 @@ export default { paddingBottom: ['x4', 'x4', 'x4', 'x4'] }) ]), - wrapper: unorderedListItem({ variant: 'blank', size: 'small' }) + ol: style([ + { + display: 'flex', + padding: 0, + listStyle: 'none', + alignItems: 'center', + justifyContent: 'flex-start' + }, + responsiveSprinkles({ + gap: ['x2', 'x2', 'x2', 'x2'] + }) + ]), + breadcrumb: style([ + { + display: 'flex', + alignItems: 'center', + justifyContent: 'flex-start' + }, + responsiveSprinkles({ + gap: ['x2', 'x2', 'x2', 'x2'] + }), + unorderedListItem({ variant: 'blank', size: 'small' }) + ]) };