Skip to content

Toggle Group

Toggle Group Primitive Text Component

Demo


A collection of buttons with true or false states, which can be activated or deactivated by toggling.

Installation

Terminal window
npx @react-native-reusables/cli@latest add toggle-group

Usage

import * as React from 'react';
import { View } from 'react-native';
import { ToggleGroup, ToggleGroupIcon, ToggleGroupItem } from '~/components/ui/toggle-group';
import { Bold } from '~/lib/icons/Bold';
import { Italic } from '~/lib/icons/Italic';
import { Underline } from '~/lib/icons/Underline';
function Example() {
const [value, setValue] = React.useState<string[]>([]);
return (
<View className='flex-1 justify-center items-center p-6 gap-12'>
<ToggleGroup value={value} onValueChange={setValue} type='multiple'>
<ToggleGroupItem value='bold' aria-label='Toggle bold'>
<ToggleGroupIcon icon={Bold} size={18} />
</ToggleGroupItem>
<ToggleGroupItem value='italic' aria-label='Toggle italic'>
<ToggleGroupIcon icon={Italic} size={18} />
</ToggleGroupItem>
<ToggleGroupItem value='underline' aria-label='Toggle underline'>
<ToggleGroupIcon icon={Underline} size={18} />
</ToggleGroupItem>
</ToggleGroup>
</View>
);
}

Props

ToggleGroup

Extends View props

PropTypeNote
type’single’ | ‘multiple’
valuestring | undefined | string[]
onValueChange(val: string | undefined | string[]) => void
asChildboolean(optional)
disabledboolean(optional)
rovingFocusbooleanWeb only (optional)
orientation’horizontal’ | ‘vertical’Web only (optional)
dir’ltr’ | ‘rtl’Web only (optional)
ltrbooleanWeb only (optional)

ToggleGroupItem

Extends Pressable props

PropTypeNote
valuestring
asChildboolean(optional)
variant’default’ | ‘outline’(optional)
size’default’ | ‘sm’ | ‘lg’(optional)

ToggleIcon

Extends LucideIcon props

PropTypeNote
iconLucideIcon