Tabs
Controlled in-page content tabs with wrapping, touch-sized triggers and selected state.
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 tabsSource files
Expand a file to read the source the installer copies into your app.
components/ui/tabs/Tabs.tsx
import * as React from 'react'
import { cssInterop } from 'react-native-css-interop'
import * as Primitive from '@rn-primitives/tabs'
import { renderTextChildren } from '@/lib/label-children'
import { cn } from '@/lib/utils'
export type TabsProps = Primitive.RootProps & { className?: string }
export const Tabs = React.forwardRef<Primitive.RootRef, TabsProps>((props, ref) => (
<Primitive.Root {...props} ref={ref} className={cn('gap-[12px]', props.className)} />
))
Tabs.displayName = 'Tabs'
export type TabsListProps = Primitive.ListProps & { className?: string }
export const TabsList = React.forwardRef<Primitive.ListRef, TabsListProps>((props, ref) => (
<Primitive.List
{...props}
ref={ref}
className={cn('flex-row flex-wrap gap-[4px] rounded-lg bg-muted p-[4px]', props.className)}
/>
))
TabsList.displayName = 'TabsList'
export type TabsTriggerProps = Omit<Primitive.TriggerProps, 'children'> & {
children?: React.ReactNode
className?: string
}
export const TabsTrigger = React.forwardRef<Primitive.TriggerRef, TabsTriggerProps>(
({ children, className, ...props }, ref) => {
const { value } = Primitive.useRootContext()
return (
<Primitive.Trigger
{...props}
ref={ref}
className={cn(
'min-h-[48px] min-w-[80px] max-w-full shrink-0 grow items-center justify-center rounded-md px-[12px] py-[10px]',
value === props.value && 'bg-background',
props.disabled && 'opacity-50',
className,
)}
>
{renderTextChildren(children, 'text-center font-medium')}
</Primitive.Trigger>
)
},
)
TabsTrigger.displayName = 'TabsTrigger'
export type TabsContentProps = Primitive.ContentProps & { className?: string }
export const TabsContent = React.forwardRef<Primitive.ContentRef, TabsContentProps>(
({ children, className, ...props }, ref) => (
<Primitive.Content {...props} ref={ref} className={cn('gap-[12px]', className)}>
{renderTextChildren(children)}
</Primitive.Content>
),
)
TabsContent.displayName = 'TabsContent'
// The published headless components forward className outside the NativeWind JSX transform.
cssInterop(Primitive.Root, { className: 'style' })
cssInterop(Primitive.List, { className: 'style' })
cssInterop(Primitive.Trigger, { className: 'style' })
cssInterop(Primitive.Content, { className: 'style' })
components/ui/tabs/index.ts
export * from './Tabs'
Dependencies
Registry items
npm packages
react-native-css-interop@rn-primitives/tabs