From 0ae0d789d553e77e81b596ce610ca780dbf7e257 Mon Sep 17 00:00:00 2001 From: oliverschuerch Date: Thu, 21 Mar 2024 15:14:22 +0100 Subject: [PATCH 1/5] feat(components): add content slot to card-control component --- .changeset/two-shrimps-argue.md | 6 +++++ .../post-card-control/post-card-control.scss | 26 ++++++++++++------- .../post-card-control/post-card-control.tsx | 12 ++++++++- .../components/post-card-control/readme.md | 7 ++--- .../card-control/card-control.docs.mdx | 10 ++++++- .../card-control/card-control.stories.ts | 23 ++++++++++++++-- 6 files changed, 68 insertions(+), 16 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..12c29d65b3 --- /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 named slot `content`, 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..7b48cbc396 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: 'checkbox label icon' 'checkbox 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: checkbox; 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..e97af3af90 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,6 +26,7 @@ let cardControlIds = 0; /** * @class PostCardControl - representing a stencil component * + * @slot content - Content to place in the named `description` slot.

Markup accepted: block content.

Even if it is generally possible, we do not recommend using interactive elements in this slot for accessibility reasons.

* @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.

*/ @Component({ @@ -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} /> -