Skip to content
Harness Design System Harness Design System Harness Design System

Toggle

beta

The Toggle component provides a customizable button that can be toggled between two states. It supports various styling options through variants and sizes.

Usage

import { Toggle } from '@harnessio/ui/components'
//...
return (
<Toggle
size="sm"
variant="outline"
selectedVariant="primary"
rounded
tooltipProps={{
content: <p>This is a tooltip</p>
}}
text="Toggle"
/>
)

Controlled and Uncontrolled

The Toggle component can be used in both controlled and uncontrolled modes. In controlled mode, the selected prop is used to control the toggle’s state, and the onChange prop is called when the toggle’s state changes. In uncontrolled mode, the defaultValue prop is used to set the initial state of the toggle, and the component manages its own state internally.

Variants

The Toggle component accepts a variant prop to control its applyed styles. Supported values are: outline, ghost, and transparent. The selectedVariant prop controls the style when the toggle is pressed, with options for primary and secondary.

Sizes

The Toggle component accepts a size prop to control its overall dimensions. Supported values are: md, sm, and xs.

Rounded

The Toggle component accepts a rounded prop. When provided, the underlying button will have fully rounded corners.

Icon only

The Toggle component accepts a iconOnly prop. When this prop is set, the Toggle is styled to fit the dimensions of an icon, making it suitable for icon-only buttons. Note that when iconOnly is set, the text prop will be used for the area-label, and the prefixIcon prop will be used as the only icon displayed.

With tooltip

The Toggle component accepts a tooltipProps prop. When provided, the Toggle will be wrapped in a Tooltip component. The tooltipProps object can include the following properties from TooltipProps: title, content, side, and align.

API Reference

The Toggle component is a button that can be toggled on and off.

Prop
Required
Default
Type
variantfalseoutline'outline' | 'ghost' | 'transparent'
selectedVariantfalseprimary'primary' | 'secondary'
onChangefalse(selected: boolean) => void
iconOnlyfalsefalseboolean
disabledfalsefalseboolean
roundedfalsefalseboolean
textfalsestring
sizefalsemd'md' | 'sm' | 'xs'
classNamefalsestring
prefixIconfalseIconV2NamesType
prefixIconPropsfalseIconPropsV2
suffixIconfalseIconV2NamesType
suffixIconPropsfalseIconPropsV2
defaultValuefalsefalseboolean
selectedfalseboolean
tooltipPropsfalseundefinedPick<TooltipProps, 'title' | 'content' | 'side' | 'align'>