Skip to main content

ButtonGroup

Effect demonstration

1. Default effect

<ButtonGroup
options={[
{
label: "test1",
onPress: () => {
console.log(111);
},
},
{ label: "test2" },
{ label: "test3" },
]}
/>
buttonGroup-ios1.png

2. Set button groups of different sizes

<WhiteSpace />
<ButtonGroup
options={[{ label: 'L' }, { label: 'R' }]}
size='x5'
containerStyle={{ width: '75%' }}
/>
<WhiteSpace />
<ButtonGroup
options={[{ label: 'L' }, { label: 'R' }]}
containerStyle={{ width: '50%' }}
/>
<WhiteSpace />
<ButtonGroup
options={[{ label: 'L' }, { label: 'R' }]}
size='x1'
containerStyle={{ width: '25%' }}
/>
buttonGroup-ios2.png

3. Custom style

<ButtonGroup
options={[{ label: 'test1', style: { backgroundColor: 'pink' } }, { label: 'test2' }, { label: 'test3' }]}
disabledItems={[1]}
containerStyle={{ padding: px(2), backgroundColor: '#005DFF', borderRadius: px(4) }}
/>
<WhiteSpace />
<ButtonGroup
options={[{ label: 'year' }, { label: 'month' }, { label: 'week' }]}
size='x2'
containerStyle={{ width: '50%' }}
/>
buttonGroup-ios3.png

4. The content is a custom icon (component)

<ButtonGroup
options={[
{
label: <SvgIcon name="bells" />,
},
{
label: <SvgIcon name="date" />,
},
{
label: <SvgIcon name="down" />,
},
{
label: <SvgIcon name="search" />,
},
{
label: <SvgIcon name="ellipsis" />,
},
]}
/>
buttonGroup-ios4.png

API

ButtonGroup API

PropertiesRequiredDescriptionTypeDefault Value
optionstrueSpecify optional optionsOption[]
sizefalseSizexxs | xs | s | m | l | xl | xxlm
disabledItemsfalseSet disabled items, the value is the array index of optionsnumber[]
activeIndexfalseItem in the clicked state by default, the value is the array index of optionsnumber
activeOpacityfalseOpacity when not disablednumber0.6
itemStylefalseCustom Item styleViewStyle
containerStylefalseCustom container styleViewStyle

Option type

PropertiesRequiredDescriptionTypeDefault Value
labeltruetext or componentReactNode
onPressfalsePressed callback function() => void
stylefalseCustom styleStyleProp<ViewStyle>