-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(components): create the post-breadcrumb-item (#3659)
Co-authored-by: Zherdetska Alona, IT21.1 <[email protected]> Co-authored-by: Alizé Debray <[email protected]>
- Loading branch information
1 parent
9af9d6b
commit 5cb2030
Showing
8 changed files
with
171 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@swisspost/design-system-components': major | ||
'@swisspost/design-system-styles': major | ||
--- | ||
|
||
Removed the `.breadcrumb-item` class, which previously handled styling for breadcrumb items. Introduced a new `post-breadcrumb-item` that should be used in place of the `.breadcrumb-item` class. |
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
44 changes: 44 additions & 0 deletions
44
packages/components/src/components/post-breadcrumb-item/post-breadcrumb-item.scss
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,44 @@ | ||
@use 'sass:map'; | ||
@use '@swisspost/design-system-styles/mixins/media'; | ||
@use '@swisspost/design-system-styles/functions/tokens'; | ||
@use '@swisspost/design-system-styles/tokens/components'; | ||
@use '@swisspost/design-system-styles/mixins/utilities'; | ||
|
||
tokens.$default-map: components.$post-breadcrumb; | ||
|
||
:host { | ||
display: inline-block; | ||
@include utilities.focus-style; | ||
} | ||
|
||
.breadcrumb-item { | ||
display: inline-flex; | ||
align-items: center; | ||
justify-content: center; | ||
padding-block: tokens.get('breadcrumb-padding-block-text'); | ||
gap: tokens.get('breadcrumb-gap-inline-inner'); | ||
color: tokens.get('breadcrumb-enabled-fg'); | ||
text-decoration: tokens.get('breadcrumb-link-enabled-text-decoration'); | ||
|
||
post-icon { | ||
height: tokens.get('breadcrum-icon-size'); | ||
width: tokens.get('breadcrum-icon-size'); | ||
} | ||
|
||
&:hover { | ||
color: tokens.get('breadcrumb-hover-fg'); | ||
text-decoration: tokens.get('breadcrumb-link-hover-text-decoration'); | ||
} | ||
|
||
@include utilities.high-contrast-mode() { | ||
&, | ||
&:focus, | ||
&:hover { | ||
color: LinkText !important; | ||
} | ||
|
||
&:visited { | ||
color: VisitedText !important; | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
packages/components/src/components/post-breadcrumb-item/post-breadcrumb-item.tsx
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,60 @@ | ||
import { Component, Element, h, Host, Prop, Watch } from '@stencil/core'; | ||
import { version } from '@root/package.json'; | ||
import { checkEmptyOrUrl } from '@/utils'; | ||
|
||
/** | ||
* @slot default - Slot for placing the text inside the breadcrumb item. | ||
*/ | ||
@Component({ | ||
tag: 'post-breadcrumb-item', | ||
styleUrl: 'post-breadcrumb-item.scss', | ||
shadow: true, | ||
}) | ||
export class PostBreadcrumbItem { | ||
@Element() host: HTMLPostBreadcrumbItemElement; | ||
|
||
/** | ||
* The optional URL to which the breadcrumb item will link. | ||
*/ | ||
@Prop() url?: string | URL; | ||
|
||
private validUrl?: string; | ||
|
||
@Watch('url') | ||
validateUrl() { | ||
try { | ||
this.validUrl = this.constructUrl(this.url); | ||
} catch (error) { | ||
this.validUrl = undefined; | ||
} | ||
} | ||
|
||
// Helper to construct a valid URL string or return undefined | ||
private constructUrl(value: unknown): string | undefined { | ||
const hasBaseURL = /^https?:\/\//.test(String(this.url)); | ||
if (typeof value === 'string') { | ||
const urlString = hasBaseURL | ||
? value | ||
: `${window.location.origin}${value}`; | ||
checkEmptyOrUrl(urlString, 'The "url" property of the post-breadcrumb-item is invalid'); | ||
return urlString; | ||
} return undefined; | ||
} | ||
|
||
connectedCallback() { | ||
this.validateUrl(); | ||
} | ||
|
||
render() { | ||
const BreadcrumbTag = this.validUrl ? 'a' : 'span'; | ||
|
||
return ( | ||
<Host data-version={version}> | ||
<BreadcrumbTag class="breadcrumb-item" {...(this.validUrl ? { href: this.validUrl } : {})}> | ||
<post-icon name="2111" class="breadcrumb-item-icon" /> | ||
<slot></slot> | ||
</BreadcrumbTag> | ||
</Host> | ||
); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
packages/components/src/components/post-breadcrumb-item/readme.md
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,37 @@ | ||
# post-breadcrumb-item | ||
|
||
|
||
|
||
<!-- Auto Generated Below --> | ||
|
||
|
||
## Properties | ||
|
||
| Property | Attribute | Description | Type | Default | | ||
| -------- | --------- | -------------------------------------------------------- | --------------- | ----------- | | ||
| `url` | `url` | The optional URL to which the breadcrumb item will link. | `URL \| string` | `undefined` | | ||
|
||
|
||
## Slots | ||
|
||
| Slot | Description | | ||
| ----------- | ----------------------------------------------------- | | ||
| `"default"` | Slot for placing the text inside the breadcrumb item. | | ||
|
||
|
||
## Dependencies | ||
|
||
### Depends on | ||
|
||
- [post-icon](../post-icon) | ||
|
||
### Graph | ||
```mermaid | ||
graph TD; | ||
post-breadcrumb-item --> post-icon | ||
style post-breadcrumb-item fill:#f9f,stroke:#333,stroke-width:4px | ||
``` | ||
|
||
---------------------------------------------- | ||
|
||
*Built with [StencilJS](https://stenciljs.com/)* |
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