Skip Navigation

Toggle Button

ToggleButton uses both the Button and IconButton components to enable active states.

Basic Usage

import React from 'react';
import { ToggleButton } from 'react-magma-dom';
export function Example() {
return <ToggleButton value="1">Toggle</ToggleButton>;
}

Default Selected Value

When a pre-selected state is needed, isChecked enables an active selected state on render.

import React from 'react';
import { ToggleButton } from 'react-magma-dom';
export function Example() {
return (
<ToggleButton value="1" isChecked>
Toggle
</ToggleButton>
);
}

Types

Toggle Buttons come in three formats. Icon only, text only, or text with an icon. aria-label prop is required for icon only buttons.

import React from 'react';
import { Flex, FlexBehavior, ToggleButton } from 'react-magma-dom';
import { SettingsIcon } from 'react-magma-icons';
export function Example() {
return (
<>
<Flex behavior={FlexBehavior.container} spacing={1}>
<Flex behavior={FlexBehavior.item}>
<ToggleButton
value="1"
icon={<SettingsIcon />}
aria-label="Settings"
/>
</Flex>
<Flex behavior={FlexBehavior.item}>
<ToggleButton value="2">Text only</ToggleButton>
</Flex>
<Flex behavior={FlexBehavior.item}>
<ToggleButton value="3" icon={<SettingsIcon />}>
Text and icon
</ToggleButton>
</Flex>
</Flex>
</>
);
}

Size

Three sizes are configurable with the ButtonSize prop between small, medium (default), and large.

import React from 'react';
import { Flex, FlexBehavior, ToggleButton, ButtonSize } from 'react-magma-dom';
import { SettingsIcon } from 'react-magma-icons';
export function Example() {
return (
<>
<Flex behavior={FlexBehavior.container} spacing={1}>
<Flex behavior={FlexBehavior.item}>
<ToggleButton
value="1"
size={ButtonSize.small}
icon={<SettingsIcon />}
aria-label="Settings"
/>
</Flex>
<Flex behavior={FlexBehavior.item}>
<ToggleButton value="2" size={ButtonSize.medium}>
Text only
</ToggleButton>
</Flex>
<Flex behavior={FlexBehavior.item}>
<ToggleButton
value="3"
size={ButtonSize.large}
icon={<SettingsIcon />}
>
Text and icon
</ToggleButton>
</Flex>
</Flex>
</>
);
}

Disabled

import React from 'react';
import { Flex, FlexBehavior, ToggleButton } from 'react-magma-dom';
import { SettingsIcon } from 'react-magma-icons';
export function Example() {
return (
<>
<Flex behavior={FlexBehavior.container} spacing={1}>
<Flex behavior={FlexBehavior.item}>
<ToggleButton
value="1"
disabled
icon={<SettingsIcon />}
aria-label="Settings"
/>
</Flex>
<Flex behavior={FlexBehavior.item}>
<ToggleButton value="2" disabled>
Text only
</ToggleButton>
</Flex>
<Flex behavior={FlexBehavior.item}>
<ToggleButton value="3" disabled icon={<SettingsIcon />}>
Text and icon
</ToggleButton>
</Flex>
</Flex>
</>
);
}

Inverse

import React from 'react';
import { Container, Flex, FlexBehavior, ToggleButton } from 'react-magma-dom';
import { SettingsIcon } from 'react-magma-icons';
export function Example() {
return (
<Container isInverse style={{ padding: '12px' }}>
<Flex behavior={FlexBehavior.container} spacing={1}>
<Flex behavior={FlexBehavior.item}>
<ToggleButton
value="1"
isInverse
icon={<SettingsIcon />}
aria-label="Settings"
/>
</Flex>
<Flex behavior={FlexBehavior.item}>
<ToggleButton value="2" isInverse>
Text only
</ToggleButton>
</Flex>
<Flex behavior={FlexBehavior.item}>
<ToggleButton value="3" isInverse icon={<SettingsIcon />}>
Text and icon
</ToggleButton>
</Flex>
</Flex>
</Container>
);
}

ToggleButton Props

Any other props supplied will be provided to the wrapping div element.

ToggleButtonText Props

disabled

Description

Sets a disabled state for a button.

Type

boolean

Default

-


isChecked

Description

Sets an active button state for a single button.

Type

boolean

Default

-


isFullWidth

Description

Set the button to display full-width.

Type

boolean

Default

false


isInverse

Description

If true, the component will have inverse styling to better appear on a dark background

Type

boolean

Default

false


isLoading

Description

Set the button to a loading state

Type

boolean

Default

false


shape

Description

Defines the border radius

Type

enum, one of:
ButtonShape.fill
ButtonShape.leftCap
ButtonShape.rightCap
ButtonShape.round

Default

ButtonShape.fill


size

Description

Changes the button size: 'small', 'medium', and 'large'.

Type

enum, one of:
ButtonSize.large
ButtonSize.medium
ButtonSize.small

Default

-


textTransform

Description

Determines whether the button appears in all-caps

Type

enum, one of:
ButtonTextTransform.none
ButtonTextTransform.uppercase

Default

ButtonTextTransform.uppercase


type

Description

The type attribute of the button ButtonType.button

Type

enum, one of:
ButtonType.button
ButtonType.reset
ButtonType.submit

Default

-


value

Required

Description

Value of the button element

Type

string

Default

-


variant

Description

The variant of the button

Type

enum, one of:
ButtonVariant.link
ButtonVariant.solid

Default

ButtonVariant.solid


ToggleButtonIcon Props

aria-label

Description

Sets the aria-label which is required for icon only buttons.

Type

string

Default

-


disabled

Description

Sets a disabled state for a button.

Type

boolean

Default

-


icon

Required

Description

Icon which displays alongside text.

Type

ReactElement

Default

-


isChecked

Description

Sets an active button state for a single button.

Type

boolean

Default

-


isFullWidth

Description

Set the button to display full-width.

Type

boolean

Default

false


isInverse

Description

If true, the component will have inverse styling to better appear on a dark background

Type

boolean

Default

false


isLoading

Description

Set the button to a loading state

Type

boolean

Default

false


shape

Description

Defines the border radius

Type

enum, one of:
ButtonShape.fill
ButtonShape.leftCap
ButtonShape.rightCap
ButtonShape.round

Default

ButtonShape.fill


size

Description

Changes the button size: 'small', 'medium', and 'large'.

Type

enum, one of:
ButtonSize.large
ButtonSize.medium
ButtonSize.small

Default

-


textTransform

Description

Determines whether the button appears in all-caps

Type

enum, one of:
ButtonTextTransform.none
ButtonTextTransform.uppercase

Default

ButtonTextTransform.uppercase


type

Description

The type attribute of the button ButtonType.button

Type

enum, one of:
ButtonType.button
ButtonType.reset
ButtonType.submit

Default

-


value

Required

Description

Value of the button element

Type

string

Default

-


variant

Description

The variant of the button

Type

enum, one of:
ButtonVariant.link
ButtonVariant.solid

Default

ButtonVariant.solid


Deploys by Netlify