-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(web-twig): Introduce BreadcrumbsItem component
* and refactor Breadcrumbs to use it refs #DS-835
- Loading branch information
Showing
11 changed files
with
134 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 17 additions & 3 deletions
20
packages/web-react/src/components/Breadcrumbs/useBreadcrumbsStyleProps.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,33 @@ | ||
import classNames from 'classnames'; | ||
import { useClassNamePrefix } from '../../hooks/useClassNamePrefix'; | ||
import { BreadcrumbsStyleProps } from '../../types'; | ||
|
||
export interface BreadcrumbsStyles { | ||
/** className props */ | ||
classProps: string; | ||
classProps: { | ||
root: string; | ||
item: string; | ||
}; | ||
/** props to be passed to the element */ | ||
props: BreadcrumbsStyleProps; | ||
} | ||
|
||
export function useBreadcrumbsStyleProps<P extends BreadcrumbsStyleProps>(props: P): BreadcrumbsStyles { | ||
const { isGoBackOnly, ...restProps } = props; | ||
const breadcrumbsClass = useClassNamePrefix('Breadcrumbs'); | ||
const displayNoneClassName = useClassNamePrefix('d-none'); | ||
const displayTabletFlexClassName = useClassNamePrefix('d-tablet-flex'); | ||
const displayTabletNoneClassName = useClassNamePrefix('d-tablet-none'); | ||
|
||
return { | ||
classProps: breadcrumbsClass, | ||
props, | ||
classProps: { | ||
root: breadcrumbsClass, | ||
item: classNames({ | ||
[displayNoneClassName]: !isGoBackOnly, | ||
[displayTabletFlexClassName]: !isGoBackOnly, | ||
[displayTabletNoneClassName]: isGoBackOnly, | ||
}), | ||
}, | ||
props: restProps, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/web-twig/src/Resources/components/Breadcrumbs/BreadcrumbsItem.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{# API #} | ||
{%- set props = props | default([]) -%} | ||
{%- set _children = block('content') -%} | ||
{%- set _href = props.href -%} | ||
{%- set _iconNameEnd = props.iconNameEnd | default('chevron-right') -%} | ||
{%- set _iconNameStart = props.iconNameStart | default('chevron-left') -%} | ||
{%- set _isCurrent = props.isCurrent | default(false) -%} | ||
{%- set _isGoBackOnly = props.isGoBackOnly | default(false) -%} | ||
|
||
{# Class names #} | ||
{%- set _displayNoneClassName = _spiritClassPrefix ~ 'd-none' -%} | ||
{%- set _displayTabletNoneClassName = _spiritClassPrefix ~ 'd-tablet-none' -%} | ||
{%- set _displayTabletFlexClassName = _spiritClassPrefix ~ 'd-tablet-flex' -%} | ||
|
||
{# Miscellaneous #} | ||
{%- set _styleProps = useStyleProps(props) -%} | ||
{% if _isGoBackOnly is not same as(true) %} | ||
{%- set _classNames = [ _styleProps.className, _displayNoneClassName, _displayTabletFlexClassName ] -%} | ||
{% else %} | ||
{%- set _classNames = [ _styleProps.className, _displayTabletNoneClassName ] -%} | ||
{% endif %} | ||
|
||
<li {{ mainProps(props) }} {{ styleProp(_styleProps) }} {{ classProp(_classNames) }}> | ||
{% if _isGoBackOnly and _iconNameStart %} | ||
<Icon name={ _iconNameStart } /> | ||
{% endif %} | ||
<Link | ||
href={ _href } | ||
color="{{ _isCurrent ? 'secondary' : 'primary' }}" | ||
isUnderlined="{{ _isCurrent is not same as(true) }}" | ||
aria-current="{{ _isCurrent ? 'page' : 'false' }}" | ||
> | ||
{{ _children }} | ||
</Link> | ||
{% if _isCurrent is not same as(true) and _isGoBackOnly is not same as(true) and _iconNameEnd %} | ||
<Icon name={ _iconNameEnd } /> | ||
{% endif %} | ||
</li> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 17 additions & 17 deletions
34
packages/web-twig/src/Resources/components/Breadcrumbs/stories/BreadcrumbsDefault.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
{% set items = [ | ||
{ | ||
title: 'Root', | ||
url: '#rootUrl', | ||
}, | ||
{ | ||
title: 'Category', | ||
url: '#categoryUrl', | ||
}, | ||
{ | ||
title: 'Subcategory', | ||
url: '#subcategoryUrl', | ||
}, | ||
{ | ||
title: 'Current page', | ||
url: '#currentUrl', | ||
}, | ||
{ | ||
title: 'Root', | ||
url: '#rootUrl', | ||
}, | ||
{ | ||
title: 'Category', | ||
url: '#categoryUrl', | ||
}, | ||
{ | ||
title: 'Subcategory', | ||
url: '#subcategoryUrl', | ||
}, | ||
{ | ||
title: 'Current page', | ||
url: '#currentUrl', | ||
}, | ||
] %} | ||
|
||
<Breadcrumbs items={{ items }} /> | ||
<Breadcrumbs goBackTitle="Back" items={{ items }} /> |
1 change: 1 addition & 0 deletions
1
packages/web-twig/src/Resources/twig-components/breadcrumbsItem.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% extends '@spirit/Breadcrumbs/BreadcrumbsItem.twig' %} |