diff --git a/packages/dnb-design-system-portal/src/docs/uilib/components/breadcrumb/Examples.tsx b/packages/dnb-design-system-portal/src/docs/uilib/components/breadcrumb/Examples.tsx index 7374bb6aa34..b2ba63fd7d3 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/components/breadcrumb/Examples.tsx +++ b/packages/dnb-design-system-portal/src/docs/uilib/components/breadcrumb/Examples.tsx @@ -16,8 +16,8 @@ export const BreadcrumbSingle = () => ( ) -export const BreadcrumbMultipleData = () => ( - +export const BreadcrumbDefault = () => ( + {() => { // You can also import pages from a store and only do a remapping const pages = [ @@ -44,8 +44,8 @@ export const BreadcrumbMultipleData = () => ( ) -export const BreadcrumbMultiple = () => ( - +export const BreadcrumbChildren = () => ( + { @@ -70,7 +70,7 @@ export const BreadcrumbMultiple = () => ( ) -export const BreadcrumbVariants = () => ( +export const BreadcrumbCollapse = () => ( {() => { const pages = [ @@ -88,16 +88,13 @@ export const BreadcrumbVariants = () => ( }, ] - return ( - // Try changing variant here - - ) + return }} ) -export const BreadcrumbCollapseOpen = () => ( - +export const BreadcrumbMultiple = () => ( + {() => { const pages = [ { @@ -112,16 +109,13 @@ export const BreadcrumbCollapseOpen = () => ( text: 'Components', href: '/uilib/components', }, + { + text: 'Breadcrumbs', + href: '/uilib/components/breadcrumbs', + }, ] - return ( - - ) + return }} ) diff --git a/packages/dnb-design-system-portal/src/docs/uilib/components/breadcrumb/demos.mdx b/packages/dnb-design-system-portal/src/docs/uilib/components/breadcrumb/demos.mdx index b420b5fe52f..cc31e1fe355 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/components/breadcrumb/demos.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/components/breadcrumb/demos.mdx @@ -3,46 +3,45 @@ showTabs: true --- import { + BreadcrumbDefault, + BreadcrumbChildren, BreadcrumbSingle, + BreadcrumbCollapse, BreadcrumbMultiple, - BreadcrumbMultipleData, - BreadcrumbVariants, - BreadcrumbCollapseOpen, } from 'Docs/uilib/components/breadcrumb/Examples' ## Demos -### Multiple Breadcrumb (recommended) +### Breadcrumb -To ensure the correct use of the Breadcrumb, we recommend passing down pages as a variable to `data`. If you have other specific cases, check out how to customize with [children in Multiple Breadcrumb](/uilib/components/breadcrumb/#multiple-breadcrumb-with-children). +To ensure the correct use of the Breadcrumb, we recommend passing down pages as a variable to `data`. If you have other specific cases, check out how to customize with [children in Breadcrumb](/uilib/components/breadcrumb/#pages-as-child-components). - - -Some extra functionality is provided to this variant: + - The first item, `Home`, gets assigned a home icon and an appropriate text label based on the current locale. - The last item in pages will be static text, corresponding to the current page. -- Another variant, `collapse`, appears for small screens. +- Breadcumb will collapse on small screens -### Single Breadcrumb +### Pages as child components -When you only want a single button for `back`, this variant is recommended and default when neither `data` nor `children` is present. +For customizing the Breadcrumb to fit your needs, you can add each page as a child component. - + + +### Single Breadcrumb -### Multiple Breadcrumb with children +When you only want a single button for `back`. -For customizing the Breadcrumb to fit your needs, this variant can be utilized. + - +This can also be forced using the `variant="single"` prop. -### Setting property 'variant' +### Always be collapsed (`variant="collapse"`) -Property variant is by default set based on the combination of children and data properties, and also screen size. -If you want to override this property, pass in the prop `variant` to be either `single`, `multiple`, or `collapse`. +Expands when user clicks - + -### Setting property 'variant' and overriding 'isCollapsed' +### Never collapse (`variant="multiple"`) - + diff --git a/packages/dnb-design-system-portal/src/docs/uilib/components/breadcrumb/properties.mdx b/packages/dnb-design-system-portal/src/docs/uilib/components/breadcrumb/properties.mdx index 0d374c9df27..bd8dee40268 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/components/breadcrumb/properties.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/components/breadcrumb/properties.mdx @@ -11,7 +11,7 @@ showTabs: true | `data` | _(optional)_ List of pages to render as breadcrumbitems. Each object in data can include all properties from [BreadcrumbItem props](/uilib/components/breadcrumb/properties#breadcrumbitem-properties). | | `children` | _(optional)_ Content of the component. Can be used instead of property `data`, by adding Breadcrumbitem children ``. | | `skeleton` | _(optional)_ Applies loading skeleton. | -| `variant` | _(optional)_ Override the variant of the component. Options: `single` \| `multiple` \| `collapse`. | +| `variant` | _(optional)_ Defaults to 'responsive' or 'single' depending on content. Options: `responsive` \| `single` \| `multiple` \| `collapse` . | | `onClick` | _(optional)_ Handle click event on "Back" for variant `single` and "Back to..." for variant `collapse`. | | `href` | _(optional)_ For variant `single`, set `href` for button click. Can be used instead of property `onClick`. | | `navText` | _(optional)_ Every ` ) } diff --git a/packages/dnb-eufemia/src/components/breadcrumb/__tests__/Breadcrumb.screenshot.test.ts b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/Breadcrumb.screenshot.test.ts index 05ad3dbf74a..fe36c65c7f0 100644 --- a/packages/dnb-eufemia/src/components/breadcrumb/__tests__/Breadcrumb.screenshot.test.ts +++ b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/Breadcrumb.screenshot.test.ts @@ -21,17 +21,16 @@ describe.each(['ui', 'sbanken'])('Breadcrumb for %s', (themeName) => { expect(screenshot).toMatchImageSnapshot() }) - it('have to match Breadcrumb multiple', async () => { + it('have to match Breadcrumb default', async () => { const screenshot = await makeScreenshot({ - selector: '[data-visual-test="breadcrumb-multiple"] .dnb-breadcrumb', + selector: '[data-visual-test="breadcrumb-default"] .dnb-breadcrumb', }) expect(screenshot).toMatchImageSnapshot() }) - it('have to match Breadcrumb multiple with children', async () => { + it('have to match Breadcrumb with custom children', async () => { const screenshot = await makeScreenshot({ - selector: - '[data-visual-test="breadcrumb-multiple-children"] .dnb-breadcrumb', + selector: '[data-visual-test="breadcrumb-children"] .dnb-breadcrumb', }) expect(screenshot).toMatchImageSnapshot() }) @@ -45,21 +44,80 @@ describe.each(['ui', 'sbanken'])('Breadcrumb for %s', (themeName) => { it('have to match Breadcrumb collapse opened', async () => { const screenshot = await makeScreenshot({ - selector: - '[data-visual-test="breadcrumb-collapse-open"] .dnb-breadcrumb', + selector: '[data-visual-test="breadcrumb-collapse"] .dnb-breadcrumb', + simulateSelector: + '[data-visual-test="breadcrumb-collapse"] .dnb-breadcrumb__toggle', + recalculateHeightAfterSimulate: true, + simulate: 'click', + }) + expect(screenshot).toMatchImageSnapshot() + }) + + it('have to match Breadcrumb hover state', async () => { + const screenshot = await makeScreenshot({ + selector: '[data-visual-test="breadcrumb-default"] .dnb-breadcrumb', + screenshotSelector: + '[data-visual-test="breadcrumb-default"] .dnb-breadcrumb .dnb-breadcrumb__bar', + simulateSelector: + '[data-visual-test="breadcrumb-default"] .dnb-breadcrumb__list .dnb-breadcrumb__item:nth-of-type(2) a', + simulate: 'hover', + }) + expect(screenshot).toMatchImageSnapshot() + }) + + it('have to match Breadcrumb active state', async () => { + const screenshot = await makeScreenshot({ + selector: '[data-visual-test="breadcrumb-default"] .dnb-breadcrumb', + screenshotSelector: + '[data-visual-test="breadcrumb-default"] .dnb-breadcrumb .dnb-breadcrumb__bar', + simulateSelector: + '[data-visual-test="breadcrumb-default"] .dnb-breadcrumb__list .dnb-breadcrumb__item:nth-of-type(2) a', + simulate: 'active', }) expect(screenshot).toMatchImageSnapshot() }) it('have to match Breadcrumb focus state', async () => { const screenshot = await makeScreenshot({ - selector: '[data-visual-test="breadcrumb-multiple"] .dnb-breadcrumb', + selector: '[data-visual-test="breadcrumb-default"] .dnb-breadcrumb', screenshotSelector: - '[data-visual-test="breadcrumb-multiple"] .dnb-breadcrumb .dnb-breadcrumb__bar', + '[data-visual-test="breadcrumb-default"] .dnb-breadcrumb .dnb-breadcrumb__bar', simulateSelector: - '[data-visual-test="breadcrumb-multiple"] .dnb-breadcrumb__list .dnb-breadcrumb__item:nth-of-type(2) a', + '[data-visual-test="breadcrumb-default"] .dnb-breadcrumb__list .dnb-breadcrumb__item:nth-of-type(2) a', simulate: 'focus', }) expect(screenshot).toMatchImageSnapshot() }) + + it('have to match Breadcrumb multiple', async () => { + const screenshot = await makeScreenshot({ + selector: '[data-visual-test="breadcrumb-multiple"] .dnb-breadcrumb', + }) + expect(screenshot).toMatchImageSnapshot() + }) + + describe('on small screen', () => { + setupPageScreenshot({ + url: '/uilib/components/breadcrumb/demos', + pageViewport: { + width: 700, + }, + }) + + it('have to match Breadcrumb default', async () => { + const screenshot = await makeScreenshot({ + selector: + '[data-visual-test="breadcrumb-default"] .dnb-breadcrumb', + }) + expect(screenshot).toMatchImageSnapshot() + }) + + it('have to match Breadcrumb multiple', async () => { + const screenshot = await makeScreenshot({ + selector: + '[data-visual-test="breadcrumb-multiple"] .dnb-breadcrumb', + }) + expect(screenshot).toMatchImageSnapshot() + }) + }) }) diff --git a/packages/dnb-eufemia/src/components/breadcrumb/__tests__/Breadcrumb.test.tsx b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/Breadcrumb.test.tsx index e2098c4040a..d4407349d8b 100644 --- a/packages/dnb-eufemia/src/components/breadcrumb/__tests__/Breadcrumb.test.tsx +++ b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/Breadcrumb.test.tsx @@ -269,7 +269,7 @@ describe('Breadcrumb', () => { expect(attributes).toEqual(['aria-label', 'class']) expect(Array.from(element.classList)).toEqual([ 'dnb-breadcrumb', - 'dnb-breadcrumb--variant-multiple', + 'dnb-breadcrumb--variant-responsive', 'dnb-space__top--large', ]) }) diff --git a/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-sbanken-have-to-match-breadcrumb-active-state.snap.png b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-sbanken-have-to-match-breadcrumb-active-state.snap.png new file mode 100644 index 00000000000..d426d31b030 Binary files /dev/null and b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-sbanken-have-to-match-breadcrumb-active-state.snap.png differ diff --git a/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-sbanken-have-to-match-breadcrumb-default.snap.png b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-sbanken-have-to-match-breadcrumb-default.snap.png new file mode 100644 index 00000000000..9e20fccb892 Binary files /dev/null and b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-sbanken-have-to-match-breadcrumb-default.snap.png differ diff --git a/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-sbanken-have-to-match-breadcrumb-hover-state.snap.png b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-sbanken-have-to-match-breadcrumb-hover-state.snap.png new file mode 100644 index 00000000000..7ed50a35d44 Binary files /dev/null and b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-sbanken-have-to-match-breadcrumb-hover-state.snap.png differ diff --git a/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-sbanken-have-to-match-breadcrumb-multiple.snap.png b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-sbanken-have-to-match-breadcrumb-multiple.snap.png index 9e20fccb892..93b55e238de 100644 Binary files a/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-sbanken-have-to-match-breadcrumb-multiple.snap.png and b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-sbanken-have-to-match-breadcrumb-multiple.snap.png differ diff --git a/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-sbanken-have-to-match-breadcrumb-multiple-with-children.snap.png b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-sbanken-have-to-match-breadcrumb-with-custom-children.snap.png similarity index 100% rename from packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-sbanken-have-to-match-breadcrumb-multiple-with-children.snap.png rename to packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-sbanken-have-to-match-breadcrumb-with-custom-children.snap.png diff --git a/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-sbanken-on-small-screen-have-to-match-breadcrumb-default.snap.png b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-sbanken-on-small-screen-have-to-match-breadcrumb-default.snap.png new file mode 100644 index 00000000000..3716e81a0e2 Binary files /dev/null and b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-sbanken-on-small-screen-have-to-match-breadcrumb-default.snap.png differ diff --git a/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-sbanken-on-small-screen-have-to-match-breadcrumb-multiple.snap.png b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-sbanken-on-small-screen-have-to-match-breadcrumb-multiple.snap.png new file mode 100644 index 00000000000..0f32a5ea210 Binary files /dev/null and b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-sbanken-on-small-screen-have-to-match-breadcrumb-multiple.snap.png differ diff --git a/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-ui-have-to-match-breadcrumb-active-state.snap.png b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-ui-have-to-match-breadcrumb-active-state.snap.png new file mode 100644 index 00000000000..3a18e065fa3 Binary files /dev/null and b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-ui-have-to-match-breadcrumb-active-state.snap.png differ diff --git a/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-ui-have-to-match-breadcrumb-default.snap.png b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-ui-have-to-match-breadcrumb-default.snap.png new file mode 100644 index 00000000000..79836165875 Binary files /dev/null and b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-ui-have-to-match-breadcrumb-default.snap.png differ diff --git a/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-ui-have-to-match-breadcrumb-hover-state.snap.png b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-ui-have-to-match-breadcrumb-hover-state.snap.png new file mode 100644 index 00000000000..bb529b6daaa Binary files /dev/null and b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-ui-have-to-match-breadcrumb-hover-state.snap.png differ diff --git a/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-ui-have-to-match-breadcrumb-multiple.snap.png b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-ui-have-to-match-breadcrumb-multiple.snap.png index 79836165875..0f32a5ea210 100644 Binary files a/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-ui-have-to-match-breadcrumb-multiple.snap.png and b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-ui-have-to-match-breadcrumb-multiple.snap.png differ diff --git a/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-ui-have-to-match-breadcrumb-multiple-with-children.snap.png b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-ui-have-to-match-breadcrumb-with-custom-children.snap.png similarity index 100% rename from packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-ui-have-to-match-breadcrumb-multiple-with-children.snap.png rename to packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-ui-have-to-match-breadcrumb-with-custom-children.snap.png diff --git a/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-ui-on-small-screen-have-to-match-breadcrumb-default.snap.png b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-ui-on-small-screen-have-to-match-breadcrumb-default.snap.png new file mode 100644 index 00000000000..3716e81a0e2 Binary files /dev/null and b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-ui-on-small-screen-have-to-match-breadcrumb-default.snap.png differ diff --git a/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-ui-on-small-screen-have-to-match-breadcrumb-multiple.snap.png b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-ui-on-small-screen-have-to-match-breadcrumb-multiple.snap.png new file mode 100644 index 00000000000..0f32a5ea210 Binary files /dev/null and b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__image_snapshots__/breadcrumb-for-ui-on-small-screen-have-to-match-breadcrumb-multiple.snap.png differ diff --git a/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__snapshots__/Breadcrumb.test.tsx.snap b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__snapshots__/Breadcrumb.test.tsx.snap index 6382b417454..644cff992f5 100644 --- a/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__snapshots__/Breadcrumb.test.tsx.snap +++ b/packages/dnb-eufemia/src/components/breadcrumb/__tests__/__snapshots__/Breadcrumb.test.tsx.snap @@ -729,6 +729,8 @@ button.dnb-button::-moz-focus-inner { padding: 0; display: flex; flex-direction: column; + /* stylelint-disable no-descending-specificity, no-duplicate-selectors */ + /* stylelint-enable */ } .dnb-breadcrumb__bar.dnb-section { display: flex; @@ -763,13 +765,16 @@ button.dnb-button::-moz-focus-inner { .dnb-breadcrumb__multiple.dnb-height-animation--parallax .dnb-breadcrumb__item { transform: translateX(0); } +html[data-visual-test] .dnb-breadcrumb__multiple .dnb-breadcrumb__item { + transition: none; +} @media screen and (max-width: 60em) { - .dnb-breadcrumb__bar .dnb-breadcrumb__multiple { + .dnb-breadcrumb--variant-responsive .dnb-breadcrumb__bar .dnb-breadcrumb__multiple { display: none; } } @media screen and (min-width: 60em) { - .dnb-breadcrumb--variant-multiple .dnb-breadcrumb__toggle { + .dnb-breadcrumb--variant-responsive .dnb-breadcrumb__toggle { display: none; } } diff --git a/packages/dnb-eufemia/src/components/breadcrumb/style/dnb-breadcrumb.scss b/packages/dnb-eufemia/src/components/breadcrumb/style/dnb-breadcrumb.scss index 110f0f87e06..801ed0f7e9e 100644 --- a/packages/dnb-eufemia/src/components/breadcrumb/style/dnb-breadcrumb.scss +++ b/packages/dnb-eufemia/src/components/breadcrumb/style/dnb-breadcrumb.scss @@ -59,13 +59,21 @@ transform: translateX(0); } - &__bar &__multiple { + /* stylelint-disable no-descending-specificity, no-duplicate-selectors */ + &__multiple &__item { + html[data-visual-test] & { + transition: none; + } + } + /* stylelint-enable */ + + &--variant-responsive &__bar &__multiple { @include allBelow(medium) { display: none; } } - &--variant-multiple &__toggle { + &--variant-responsive &__toggle { @include allAbove(medium) { display: none; }