Collapsible
Expandable native content with an explicit disclosure trigger.
Install
First install? Set up the registry in your app.
npx --yes --package=https://native.uipkge.dev/cli/uipkge-native-0.1.1.tgz uipkge-native add collapsibleSource files
Expand a file to read the source the installer copies into your app.
components/ui/collapsible/Collapsible.tsx
import * as React from 'react'
import { cssInterop } from 'react-native-css-interop'
import * as Primitive from '@rn-primitives/collapsible'
import { renderTextChildren } from '@/lib/label-children'
import { cn } from '@/lib/utils'
export const Collapsible = Primitive.Root
export type CollapsibleProps = Primitive.RootProps
export type CollapsibleTriggerProps = Omit<Primitive.TriggerProps, 'children'> & {
children?: React.ReactNode
className?: string
}
export const CollapsibleTrigger = React.forwardRef<Primitive.TriggerRef, CollapsibleTriggerProps>(
({ className, children, ...props }, ref) => (
<Primitive.Trigger
{...props}
ref={ref}
className={cn(
'min-h-[48px] flex-row items-center gap-[8px] rounded-md border border-border px-[16px] py-[12px]',
props.disabled && 'opacity-50',
className,
)}
>
{renderTextChildren(children, 'font-medium')}
</Primitive.Trigger>
),
)
CollapsibleTrigger.displayName = 'CollapsibleTrigger'
export type CollapsibleContentProps = Primitive.ContentProps & { className?: string }
export const CollapsibleContent = React.forwardRef<Primitive.ContentRef, CollapsibleContentProps>(
({ className, children, ...props }, ref) => (
<Primitive.Content
{...props}
ref={ref}
className={cn('mt-[8px] gap-[8px] rounded-md border border-border p-[16px]', className)}
>
{renderTextChildren(children)}
</Primitive.Content>
),
)
CollapsibleContent.displayName = 'CollapsibleContent'
// The published headless components forward className outside the NativeWind JSX transform.
cssInterop(Primitive.Root, { className: 'style' })
cssInterop(Primitive.Trigger, { className: 'style' })
cssInterop(Primitive.Content, { className: 'style' })
components/ui/collapsible/index.ts
export * from './Collapsible'
Dependencies
Registry items
npm packages
react-native-css-interop@rn-primitives/collapsible