Button Group

A Button Group component groups multiple buttons together for selecting from a set of related actions or options.

Demo

React Native components render to native views, so this is the component running in the example app, in the theme you are reading in.

9:41
Button Group running in the Nayan UI example app

Usage

ButtonGroup.tsx
import { View } from 'react-native';
import { useState } from 'react';
import { NButtonGroup, NText } from '@nayan-ui/native';
export default function ButtonGroupScreen() {
const [align, setAlign] = useState('left');
const [size, setSize] = useState('md');
return (
<View className="p-4 gap-4">
<NText className="text-lg font-bold">Basic</NText>
<NButtonGroup
items={[
{ label: 'Left', value: 'left' },
{ label: 'Center', value: 'center' },
{ label: 'Right', value: 'right' }
]}
value={align}
onValueChange={setAlign}
/>
<NText>Selected: {align}</NText>
<NText className="text-lg font-bold">Different items</NText>
<NButtonGroup
items={[
{ label: 'S', value: 'sm' },
{ label: 'M', value: 'md' },
{ label: 'L', value: 'lg' },
{ label: 'XL', value: 'xl' }
]}
value={size}
onValueChange={setSize}
/>
<NText className="text-lg font-bold">Disabled</NText>
<NButtonGroup
isDisabled
items={[
{ label: 'A', value: 'a' },
{ label: 'B', value: 'b' }
]}
value="a"
onValueChange={() => {}}
/>
</View>
);
}

Attributes

11 props
NameTypeDefaultDetails
itemsButtonGroupItem[]RequiredArray of items with label, value, optional icon and isDisabled.
valuestringRequiredCurrently selected value.
onValueChange(value: string) => voidRequiredCallback when selection changes.
labelstringOptionalLabel for the button group.
isDisabledbooleanfalseWhether the button group is disabled.
classNamestring' 'You can customise by passing tailwind classes.
buttonClassNamestring' 'You can customise by passing tailwind classes.
labelClassNamestring' 'You can customise by passing tailwind classes.
selectedstringOptionalAlias of value.
onChange(value: string) => voidOptionalAlias of onValueChange.
disabledbooleanfalseAlias of isDisabled.

Tags

Other components solving nearby problems.