Accordion

An Accordion component allows users to expand and collapse sections of content, organizing information compactly. Built on top of heroui-native Accordion.

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
Accordion running in the Nayan UI example app

Usage

Accordion.tsx
import { View } from 'react-native';
import { NAccordion, NText } from '@nayan-ui/native';
export default function AccordionScreen() {
return (
<View className="p-4 gap-4">
<NText className="text-lg font-bold">Single (default)</NText>
<NAccordion
items={[
{ title: 'What is React Native?', content: 'A framework for building native apps using React.' },
{ title: 'What is Expo?', content: 'A set of tools for building React Native apps faster.' },
{ title: 'What is HeroUI?', content: 'A component library for React Native.' }
]}
/>
<NText className="text-lg font-bold">Multiple selection</NText>
<NAccordion
selectionMode="multiple"
items={[
{ title: 'Item A', content: 'Content A' },
{ title: 'Item B', content: 'Content B' },
{ title: 'Item C', content: 'Content C' }
]}
/>
<NText className="text-lg font-bold">With disabled item</NText>
<NAccordion
items={[
{ title: 'Enabled', content: 'You can expand this.' },
{ title: 'Disabled', content: 'Cannot expand.', isDisabled: true }
]}
/>
<NText className="text-lg font-bold">Surface variant</NText>
<NAccordion
variant="surface"
items={[
{ title: 'Surface A', content: 'Content in surface variant.' },
{ title: 'Surface B', content: 'Another surface item.' }
]}
/>
</View>
);
}

Attributes

13 props
NameTypeDefaultDetails
itemsAccordionItemData[]RequiredArray of accordion items with id, title, content, and optional isDisabled.
selectionMode'single' | 'multiple''single'Whether single or multiple items can be expanded.
defaultValuestring | string[]OptionalDefault expanded item values.
variant'default' | 'surface'OptionalVisual variant style.
hideSeparatorbooleanfalseWhether to hide separators between items.
isCollapsiblebooleanfalseWhether expanded items can be collapsed.
isDisabledbooleanfalseWhether the accordion is disabled.
classNamestring' 'You can customise by passing tailwind classes.
itemClassNamestring' 'You can customise by passing tailwind classes.
titleClassNamestring' 'You can customise by passing tailwind classes.
contentClassNamestring' 'You can customise by passing tailwind classes.
type'single' | 'multiple''single'Alias of selectionMode.
disabledbooleanfalseAlias of isDisabled.

Tags

Other components solving nearby problems.