No Preview

Sorry, but you either have no stories or none are selected somehow.

If the problem persists, check the browser console, or the terminal you've run Storybook from.

The component failed to render properly, likely due to a configuration issue in Storybook. Here are some common causes and how you can address them:

  1. Missing Context/Providers: You can use decorators to supply specific contexts or providers, which are sometimes necessary for components to render correctly. For detailed instructions on using decorators, please visit the Decorators documentation.
  2. Misconfigured Webpack or Vite: Verify that Storybook picks up all necessary settings for loaders, plugins, and other relevant parameters. You can find step-by-step guides for configuring Webpack or Vite with Storybook.
  3. Missing Environment Variables: Your Storybook may require specific environment variables to function as intended. You can set up custom environment variables as outlined in the Environment Variables documentation.

This is a pre-release version and is not production ready. For new and ongoing projects, please refer to the latest Design System version.

For a more specialized visualization of checkbox and radio elements.

There are various methods to integrate this component into your project.

We advise opting for the "Standard HTML" approach for when you need full access to the input field and using the "Web Component" method in every other case.

Standard HTML
<div class="checkbox-button-card"> <input id="CardControl_1" name="checkbox-button-card-control_1" type="checkbox" /> <label for="CardControl_1"> <span>Label</span> </label> </div>
NameDescriptionDefaultControl
GroupValidation
boolean
-
General
Type
string
-
Label
The main label of the input
string
-
Description
A short additional description
string
-
Icon
string
-
States
Checked
When set to true, places the component in the checked state.
boolean
-
Disabled
When set to true, disables the component's functionality and places it in a disabled state.
boolean
-
Validation
Defines the validation state of the card control and controls the display of the corresponding return message.
string
-

Checkbox cards can be grouped together. Use a fieldset/legend combination to label the group. If there is an error, link the legend with the error message through the aria-describedby attribute on the legend, pointing to the id of the error message.

Legend
NameDescriptionDefaultControl
General
Type
string
-
States
Validation
Defines the validation state of the card control and controls the display of the corresponding return message.
string
-

This snippet adds a global event listener to mirror the focused and checked states to the parent of the input. This fallback has to be applied as long as Firefox does not support the :has selector.

document.addEventListener('input', e => { if (!(e.target instanceof Element) || e.target.nodeName !== 'input') return; const parent = e.target.parentElement; if ( parent?.classList.contains('checkbox-button-card') || parent?.classList.contains('radio-button-card') ) { parent.classList.toggle('checked', (e.target as HTMLInputElement).checked); } });

Make sure the @swisspost/design-system-styles package is already present in your project or follow the installation guidelines.

To import all Design System styles:

@use '@swisspost/design-system-styles/post-compact.scss';

To import only the styles required for this component:

@use '@swisspost/design-system-styles/basics.scss'; @use '@swisspost/design-system-styles/components/choice-control-card.scss';
Webcomponent
<post-card-control label="Label" type="checkbox"> </post-card-control>
NameDescriptionDefaultControl
props
label*
Defines the text in the control-label.
string
description
Defines the description in the control-label.
string
null
type*
Defines the type attribute of the control.
"checkbox""radio"
name

Defines the name attribute of the control.

string
null
value
Defines the value attribute of the control.
string
null
checked
Defines the checked attribute of the control. If true, the control is selected at its value will be included in the forms' data.
boolean
false
disabled
Defines the disabled attribute of the control. If true, the user can not interact with the control and the controls value will not be included in the forms' data.
boolean
false
validity

Defines the validation validity of the control. To reset validity to an undefined state, simply remove the attribute from the control.

nullboolean
null
icon

Defines the icon name inside the card.

string
null
slots
default
Content to place into the default slot.

Markup accepted: block content.
other
-
icon
To insert a custom icon into the named icon slot.

Markup accepted: inline content.
other
-
events
postInput

An event emitted whenever the components checked state is toggled. The event payload (emitted under event.detail.state) is a boolean: true if the component is checked, false if it is unchecked.

{ state: boolean; value: string; }
--
postChange

An event emitted whenever the components checked state is toggled. The event payload (emitted under event.detail.state) is a boolean: true if the component is checked, false if it is unchecked.

{ state: boolean; value: string; }
--
methods
reset

A public method to reset the controls checked and validity state. The validity state is set to null, so it's neither valid nor invalid.

reset() => Promise<void>
--

The <post-card-control> element is part of the @swisspost/design-system-components package. For more information, read the getting started with components guide.

You can use our built-in icons by just adding the icon property with the name of the desired icon.
If this is not enough, you can also use the named icon slot and add your very own custom icon.

If you need to add other content to the component, you can use the default slot to do so.

  • List item
  • List item
  • List item

You can use the component directly in your forms, the control value will be available in the FormData of the surrounding <form> element, just as you are used to from native input elements.

Legend
Legend

FormData

Submit or reset the form to see how the FormData will look like.

{}
NameDescriptionDefaultControl
Checkbox
value
Set the value of the checkbox card.
string
null
disabled
Set the disabled state of the checkbox card.
boolean
false
validity

Defines the validation validity of the control. To reset validity to an undefined state, simply remove the attribute from the control.

nullboolean
null
disabled fieldset
Set the disabled attribute of the fieldset around the checkbox card.
boolean
-
Radio
value
Set the value prefix of the radio cards.
string
-
disabled
Set the disabled state of the second radio card.
string
-
disabled fieldset
Set the disabled attribute of the fieldset around the radio cards.
boolean
-
validity
Defines the validation validity of the control. To reset validity to an undefiend state, simply remove the attribute from the control.
nullboolean
-

Change the width of a <card-control> component, by putting it (for example) in a grid. If you like to stretch all <card-control> components within a row to the same height, simply add the class .h-full to them.

NameDescriptionDefaultControl
General
Columns
Controls the amount of elements per row shown in the grid.
number
-
Full Height
Stretch elements in one row to the maximum height.
boolean
-

As you can create radio button groups with native <radio> elements, you can do the same with our <post-card-control> component as well.
Just add the same name attribute value to multiple <post-card-control type="radio"> components.

Legend

The <post-card-control> offers a reset method to reset it to the initial state (validity and checked state). The method can be called directly on the element itself.

const cardControl = document.querySelector('post-card-control') as HTMLPostCardControlElement; cardControl.reset();