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.

Button Toggle

A toggle button component to switch between two states and display different content based on the current state.

Untoggled Toggled
<post-togglebutton class="btn btn-primary"> <span data-showwhen="untoggled">Untoggled</span> <span data-showwhen="toggled">Toggled</span> </post-togglebutton>
NameDescriptionDefaultControl
Content
Toggled text
Text within the button when it's toggled.
string
-
Untoggled text
Text within the button when it's untoggled.
string
-
General
Variant
Defines a style variant.
string
-
Size
Sets the size of the component.
string
-
props
toggled
If true, the button is in the "on" state, otherwise it is in the "off" state.
boolean
false
slots
default
Slot for the content of the button.
other
--

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

You can set the button to be toggled initially by using the toggled attribute. When set, the component will start in the toggled state and display the corresponding content.

Untoggled Toggled

The toggle button can contain any text or inline element.

You can control the visibility of an element based on the state of the toggle button using the data-showwhen attribute.

  • If the element has a data-showwhen="toggled" attribute, it will be visible when the button is toggled on.
  • If the element has a data-showwhen="untoggled" attribute, it will be visible when the button is toggled off.
  • If the element does not have a data-showwhen attribute, it will always be visible, regardless of the button's state.
Menu