diff --git a/packages/web-react/src/components/Breadcrumbs/Breadcrumbs.tsx b/packages/web-react/src/components/Breadcrumbs/Breadcrumbs.tsx index 13bed3fbec..6b74a81af0 100644 --- a/packages/web-react/src/components/Breadcrumbs/Breadcrumbs.tsx +++ b/packages/web-react/src/components/Breadcrumbs/Breadcrumbs.tsx @@ -4,7 +4,7 @@ import { useBreadcrumbsStyleProps } from './useBreadcrumbsStyleProps'; import { SpiritBreadcrumbsProps } from '../../types'; import { useStyleProps } from '../../hooks/styleProps'; import { Icon } from '../Icon'; -import { Link } from '../Link'; +import BreadcrumbsItem from './BreadcrumbsItem'; const defaultProps = { items: [], @@ -31,24 +31,17 @@ export const Breadcrumbs = (props: SpiritBreadcru items?.map((item, index) => ( {index === items.length - 2 && goBackTitle && ( -
  • - - - {goBackTitle} - -
  • + } isGoBackOnly> + {goBackTitle} + )} -
  • - {index !== 0 && } - - {item.title} - -
  • + + {item.title} +
    ))} @@ -59,3 +52,10 @@ export const Breadcrumbs = (props: SpiritBreadcru Breadcrumbs.defaultProps = defaultProps; export default Breadcrumbs; + +/* {/*
  • + + + {goBackTitle} + +
  • */ diff --git a/packages/web-react/src/components/Breadcrumbs/BreadcrumbsItem.tsx b/packages/web-react/src/components/Breadcrumbs/BreadcrumbsItem.tsx new file mode 100644 index 0000000000..baf5788a34 --- /dev/null +++ b/packages/web-react/src/components/Breadcrumbs/BreadcrumbsItem.tsx @@ -0,0 +1,52 @@ +import classNames from 'classnames'; +import React from 'react'; +import { useClassNamePrefix } from '../../hooks'; +import { useStyleProps } from '../../hooks/styleProps'; +import { SpiritBreadcrumbsItemProps } from '../../types'; +import { Icon } from '../Icon'; +import { Link } from '../Link'; + +const defaultProps = { + iconStart: undefined, + iconEnd: , + isCurrent: false, + isGoBackOnly: false, +}; + +const BreadcrumbsItem = (props: SpiritBreadcrumbsItemProps) => { + const { children, href, isCurrent, iconStart, iconEnd, isGoBackOnly, ...restProps } = props; + const { styleProps, props: otherProps } = useStyleProps(restProps); + const displayNoneClassName = useClassNamePrefix('d-none'); + const displayTabletFlexClassName = useClassNamePrefix('d-tablet-flex'); + const displayTabletNoneClassName = useClassNamePrefix('d-tablet-none'); + + return ( +
  • + {iconStart} + + {children} + + {!isCurrent && !isGoBackOnly && iconEnd} +
  • + ); +}; + +BreadcrumbsItem.defaultProps = defaultProps; + +export default BreadcrumbsItem; diff --git a/packages/web-react/src/components/Breadcrumbs/README.md b/packages/web-react/src/components/Breadcrumbs/README.md index a6b6ea5079..fc1bba7d46 100644 --- a/packages/web-react/src/components/Breadcrumbs/README.md +++ b/packages/web-react/src/components/Breadcrumbs/README.md @@ -1,10 +1,14 @@ # Breadcrumbs +## Usage + +### Basic + ```jsx import { Breadcrumbs } from '@lmc-eu/spirit-web-react/components'; ``` -Define breadcrumb items as array type of `BreadcrumbsItem[]`. +Define breadcrumb items as an array type of `BreadcrumbsItem[]`. ```jsx const items = [ @@ -27,17 +31,15 @@ const items = [ ]; ``` -## Basic example usage - Simply pass the breadcrumbs array as a prop: ```jsx ``` -## Example of custom usage +### Custom usage -Use custom content for ordered list as component's children instead of passing breadcrumb items array via props: +Use custom content for the ordered list as component's children instead of passing breadcrumb items array via props: ```jsx @@ -51,7 +53,7 @@ Use custom content for ordered list as component's children instead of passing b ``` -## API +### API | Name | Type | Default | Required | Description | | ------------------ | ------------------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | @@ -62,4 +64,31 @@ Use custom content for ordered list as component's children instead of passing b | `UNSAFE_className` | `string` | — | ✕ | Wrapper custom class name | | `UNSAFE_style` | `CSSProperties` | — | ✕ | Wrapper custom style | +## BreadcrumbsItem + +Use the `BreadcrumbsItem` component for the ordered list as the component's children instead of passing the breadcrumb items array via props: + +```jsx + + {items.map((item, index) => ( + + {item.title} + + ))} + +``` + +### API + +| Name | Type | Default | Required | Description | +| ------------------ | --------------- | ------------------------------- | -------- | ----------------------------------------------------- | +| `children` | `ReactNode` | — | ✕ | Custom content to override items rendering from array | +| `href` | `string` | — | ✔ | URL | +| `iconEnd` | `ReactNode` | `` | ✕ | Icon element on the end of the item wrapper | +| `iconStart` | `ReactNode` | - | ✕ | Icon component on the start of the item | +| `isCurrent` | `boolean` | `false` | ✕ | Whether is the item the current page | +| `isGoBackOnly` | `boolean` | `fasle` | ✕ | Whether should be displayed in go back mode | +| `UNSAFE_className` | `string` | — | ✕ | Wrapper custom class name | +| `UNSAFE_style` | `CSSProperties` | — | ✕ | Wrapper custom style | + For detailed information see [Breadcrumbs](https://github.com/lmc-eu/spirit-design-system/blob/main/packages/web/src/scss/components/Breadcrumbs/README.md) component diff --git a/packages/web-react/src/components/Breadcrumbs/demo/BreadcrumbsDefault.tsx b/packages/web-react/src/components/Breadcrumbs/demo/BreadcrumbsDefault.tsx index 63bb88dfa6..4acbb0c95d 100644 --- a/packages/web-react/src/components/Breadcrumbs/demo/BreadcrumbsDefault.tsx +++ b/packages/web-react/src/components/Breadcrumbs/demo/BreadcrumbsDefault.tsx @@ -21,7 +21,7 @@ const BreadcrumbsDefault = () => { }, ]; - return ; + return ; }; export default BreadcrumbsDefault; diff --git a/packages/web-react/src/types/breadcrumbs.ts b/packages/web-react/src/types/breadcrumbs.ts index 5a512d1267..1eefceb8c8 100644 --- a/packages/web-react/src/types/breadcrumbs.ts +++ b/packages/web-react/src/types/breadcrumbs.ts @@ -1,4 +1,4 @@ -import { ElementType, JSXElementConstructor } from 'react'; +import { ElementType, JSXElementConstructor, ReactNode } from 'react'; import { ChildrenProps, StyleProps, TransferProps } from './shared'; export type BreadcrumbsItem = { @@ -6,6 +6,14 @@ export type BreadcrumbsItem = { url: string; }; +export interface SpiritBreadcrumbsItemProps extends ChildrenProps { + href: string; + iconStart?: ReactNode; + iconEnd?: ReactNode; + isCurrent: boolean; + isGoBackOnly: boolean; +} + export interface AriaBreadcrumbsElementTypeProps { /** * The HTML element or React element used to render the breadcrumbs, e.g. 'div', 'span'.