• Docs
  • Blog
    • 0.25.1

    • light

      dark

      system

      Switch mode
    • Cerberus

      Acheron

      Elysium

    Get Started
    Components
    Styling
    Theming

    Concepts

    OverviewCompositionTesting

    Layout

    Aspect RatioBleedBoxCenterContainerDividerFlexFloatGridLink OverlayScrollableStackWrap

    Components

    AccordionAdmonitionAvatarButtonCarouselCheckboxClipboardCollapsibleComboboxConfirm ModalCTAModalDate PickerDialogFieldFieldsetFile UploaderIcon ButtonInputLoading StatesMenuNotificationsNumber InputPin InputProgressPrompt ModalRadioRatingSelectSplit ButtonSwitchTableTabsTagTextTextareaToggleTooltip

    Utilities

    Client OnlyDownload TriggerEnvironmentFeature FlagsFocus TrapForFormat ByteFormat NumberFormat Relative TimeFrameHighlightJSON Tree ViewLocaleLocal StoragePortalPresenceShowsplitPropsTheme

    Toggle

    Toggle allows users to toggle between states via an action.

    • npm
    • source
    • Ark

    The Toggle component is a two-state button that allows users to toggle between states via an action.

    When not to use

    If you need to conditionally render content based on a binary condition, use the Show component.

    import { ToggleParts } from '@cerberus/react'

    Usage

    The Toggle component is unstyled to fit any scenario you may need.

    Copy
    notification-toggle.tsx
    import { NotificationOff, Notification } from '@carbon/icons-react'
    import { ToggleParts, IconButton } from '@cerberus/react'
    export default function BasicPreview() {
    return (
    <ToggleParts.Root defaultPressed={true} asChild>
    <IconButton ariaLabel="Notification preferences">
    <ToggleParts.Indicator fallback={<NotificationOff />}>
    <Notification />
    </ToggleParts.Indicator>
    </IconButton>
    </ToggleParts.Root>
    )
    }

    Primitives

    You can utilize the primitive components or the css prop to customize the toggle.

    ComponentDescription
    ToggleRootThe context provider for the Toggle parts
    ToggleIndicatorThe indicator shown based on the toggle state

    API

    Parts

    The ToggleParts API is an Object containing the full family of components.

    Note

    It is best to only use the ToggleParts if you are building a custom solution. Importing Object based components will ship every property it includes into your bundle, regardless if you use it or not.

    NameDescription
    RootThe ToggleRoot component which is the Provider for the family.
    IndicatorThe ToggleIndicator component which displays based on the pressed state.

    On this page

    • Edit this page on Github
    Cerberus Design System | Docs