From 1eae7c484e73a33258a09cc2c3595e207da9df7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Sch=C3=BCrch?= Date: Thu, 28 Mar 2024 14:49:40 +0100 Subject: [PATCH] feat(components): add content slot to card-control component (#2844) Co-authored-by: Philipp Gfeller <1659006+gfellerph@users.noreply.github.com> --- .changeset/two-shrimps-argue.md | 6 +++++ .../post-card-control/post-card-control.scss | 26 ++++++++++++------- .../post-card-control/post-card-control.tsx | 14 ++++++++-- .../components/post-card-control/readme.md | 7 ++--- .../card-control/card-control.docs.mdx | 13 +++++++++- .../card-control/card-control.stories.ts | 25 ++++++++++++++++-- 6 files changed, 74 insertions(+), 17 deletions(-) create mode 100644 .changeset/two-shrimps-argue.md diff --git a/.changeset/two-shrimps-argue.md b/.changeset/two-shrimps-argue.md new file mode 100644 index 0000000000..46c20b0b0e --- /dev/null +++ b/.changeset/two-shrimps-argue.md @@ -0,0 +1,6 @@ +--- +'@swisspost/design-system-documentation': minor +'@swisspost/design-system-components': minor +--- + +Added the new default slot, to allow the integration of custom HTML in the card-control component. diff --git a/packages/components/src/components/post-card-control/post-card-control.scss b/packages/components/src/components/post-card-control/post-card-control.scss index e2ba443d2a..fdb0b368b1 100644 --- a/packages/components/src/components/post-card-control/post-card-control.scss +++ b/packages/components/src/components/post-card-control/post-card-control.scss @@ -22,7 +22,8 @@ --post-card-control-input-bg: #{post.$white}; flex-basis: 100%; - display: flex; + display: grid; + grid-template: 'input label icon' 'input content icon' / min-content auto min-content; gap: 0 post.$size-mini; padding: post.$size-regular; background-color: var(--post-card-control-bg); @@ -34,7 +35,7 @@ transition: background-color 100ms linear, border-color 100ms linear; .card-control--input { - flex: 0 0 auto; + grid-area: input; margin: post.$size-micro 0; background-color: var(--post-card-control-input-bg); border-color: var(--post-card-control-input-border-color) !important; @@ -46,21 +47,28 @@ &:focus-visible { box-shadow: none; } + } - ~ .card-control--label { - flex-grow: 2; - margin: post.$size-micro 0; - color: inherit !important; - pointer-events: none; - } + .card-control--label { + grid-area: label; + margin: post.$size-micro 0; + padding: 0; + color: inherit !important; + pointer-events: none; + transition-duration: 100ms; } .card-control--description { + grid-area: label; font-size: 0.75rem; } + .card-control--content { + grid-area: content; + } + .card-control--icon { - flex: 0 0 auto; + grid-area: icon; width: post.$size-big; height: post.$size-big; pointer-events: none; diff --git a/packages/components/src/components/post-card-control/post-card-control.tsx b/packages/components/src/components/post-card-control/post-card-control.tsx index dffe7f05f0..024df1c94c 100644 --- a/packages/components/src/components/post-card-control/post-card-control.tsx +++ b/packages/components/src/components/post-card-control/post-card-control.tsx @@ -26,7 +26,8 @@ let cardControlIds = 0; /** * @class PostCardControl - representing a stencil component * - * @slot icon - Content to place in the named `icon` slot.

Markup accepted: inline content.
It is only meant for img or svg elements and overrides the `icon` property.

+ * @slot default - Content to place into the `default` slot.

Markup accepted: block content.

Even if it is generally possible, we do not recommend using interactive elements in this slot because the background of the card control is clickable.
This can lead to confusion when the hit box of nested interactive controls is not clearly separated from the background, is invalid HTML and click events bubbling up to the card control will unexpectedly toggle it if they're not captured.
More info: https://accessibilityinsights.io/info-examples/web/nested-interactive/

+ * @slot icon - To insert a custom icon into the named `icon` slot.

Markup accepted: inline content.

It is only meant for img or svg elements and overrides the `icon` property.

*/ @Component({ tag: 'post-card-control', @@ -367,6 +368,7 @@ export class PostCardControl { name={this.name} value={this.value} checked={this.checked} + aria-describedby={`${this.controlId}_label ${this.controlId}_content`} aria-disabled={this.disabled} aria-invalid={this.validity === 'false'} onClick={this.controlClickHandler} @@ -377,7 +379,11 @@ export class PostCardControl { onKeyDown={this.controlKeyDownHandler} /> -