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:
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.
preview-5491--swisspost-design-system-next.netlify.app/?path=/docs/047501dd-a185-4835-be91-09130fa3dad9--docs&story=Default#047501dd-a185-4835-be91-09130fa3dad9--default
/?path=/story/047501dd-a185-4835-be91-09130fa3dad9--default&full=true
<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>
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.
preview-5491--swisspost-design-system-next.netlify.app/?path=/docs/047501dd-a185-4835-be91-09130fa3dad9--docs&story=Group#047501dd-a185-4835-be91-09130fa3dad9--group
/?path=/story/047501dd-a185-4835-be91-09130fa3dad9--group&full=true
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';
preview-5491--swisspost-design-system-next.netlify.app/?path=/docs/886fabcf-148b-4054-a2ec-4869668294fb--docs&story=Default#886fabcf-148b-4054-a2ec-4869668294fb--default
/?path=/story/886fabcf-148b-4054-a2ec-4869668294fb--default&full=true
<post-card-control label="Label" type="checkbox"> </post-card-control>
Name | Description | Default | Control |
---|---|---|---|
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 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 nullboolean | null | |
icon | Defines the icon 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 { state: boolean; value: string; } | - | - |
postChange | An event emitted whenever the components checked state is toggled.
The event payload (emitted under { state: boolean; value: string; } | - | - |
methods | |||
reset | A public method to reset the controls 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.
preview-5491--swisspost-design-system-next.netlify.app/?path=/docs/886fabcf-148b-4054-a2ec-4869668294fb--docs&story=Custom Icon#886fabcf-148b-4054-a2ec-4869668294fb--custom-icon
/?path=/story/886fabcf-148b-4054-a2ec-4869668294fb--custom-icon&full=true
If you need to add other content to the component, you can use the default slot to do so.
preview-5491--swisspost-design-system-next.netlify.app/?path=/docs/886fabcf-148b-4054-a2ec-4869668294fb--docs&story=Custom Content#886fabcf-148b-4054-a2ec-4869668294fb--custom-content
/?path=/story/886fabcf-148b-4054-a2ec-4869668294fb--custom-content&full=true
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.
preview-5491--swisspost-design-system-next.netlify.app/?path=/docs/886fabcf-148b-4054-a2ec-4869668294fb--docs&story=Form Integration#886fabcf-148b-4054-a2ec-4869668294fb--form-integration
/?path=/story/886fabcf-148b-4054-a2ec-4869668294fb--form-integration&full=true
Submit or reset the form to see how the FormData will look like.
{}
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.
preview-5491--swisspost-design-system-next.netlify.app/?path=/docs/886fabcf-148b-4054-a2ec-4869668294fb--docs&story=Lined Up#886fabcf-148b-4054-a2ec-4869668294fb--lined-up
/?path=/story/886fabcf-148b-4054-a2ec-4869668294fb--lined-up&full=true
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.
preview-5491--swisspost-design-system-next.netlify.app/?path=/docs/886fabcf-148b-4054-a2ec-4869668294fb--docs&story=Radio Group#886fabcf-148b-4054-a2ec-4869668294fb--radio-group
/?path=/story/886fabcf-148b-4054-a2ec-4869668294fb--radio-group&full=true
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();