Table
Composable native table with horizontal overflow and caller-owned rows.
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 tableSource files
Expand a file to read the source the installer copies into your app.
components/ui/table/Table.tsx
import * as React from 'react'
import { cssInterop } from 'react-native-css-interop'
import { ScrollView } from 'react-native'
import * as Primitive from '@rn-primitives/table'
import { renderTextChildren } from '@/lib/label-children'
import { cn } from '@/lib/utils'
export type TableProps = Primitive.RootProps & { className?: string }
export const Table = React.forwardRef<Primitive.RootRef, TableProps>((props, ref) => (
<ScrollView horizontal contentContainerStyle={{ flexGrow: 1 }}>
<Primitive.Root
{...props}
ref={ref}
className={cn('min-w-[320px] flex-1 overflow-hidden rounded-lg border border-border bg-card', props.className)}
/>
</ScrollView>
))
Table.displayName = 'Table'
export type TableHeaderProps = Primitive.HeaderProps & { className?: string }
export const TableHeader = React.forwardRef<Primitive.HeaderRef, TableHeaderProps>((props, ref) => (
<Primitive.Header {...props} ref={ref} className={cn('bg-muted', props.className)} />
))
TableHeader.displayName = 'TableHeader'
export const TableBody = Primitive.Body
export type TableBodyProps = Primitive.BodyProps
export type TableRowProps = Primitive.RowProps & { className?: string }
export const TableRow = React.forwardRef<Primitive.RowRef, TableRowProps>((props, ref) => (
<Primitive.Row {...props} ref={ref} className={cn('min-h-[48px] flex-row border-b border-border', props.className)} />
))
TableRow.displayName = 'TableRow'
export type TableHeadProps = Primitive.HeadProps & { className?: string }
export const TableHead = React.forwardRef<Primitive.HeadRef, TableHeadProps>(
({ children, className, ...props }, ref) => (
<Primitive.Head
{...props}
ref={ref}
className={cn('min-w-[96px] flex-1 justify-center px-[12px] py-[12px]', className)}
>
{renderTextChildren(children, 'font-semibold')}
</Primitive.Head>
),
)
TableHead.displayName = 'TableHead'
export type TableCellProps = Primitive.CellProps & { className?: string }
export const TableCell = React.forwardRef<Primitive.CellRef, TableCellProps>(
({ children, className, ...props }, ref) => (
<Primitive.Cell
{...props}
ref={ref}
className={cn('min-w-[96px] flex-1 justify-center px-[12px] py-[12px]', className)}
>
{renderTextChildren(children)}
</Primitive.Cell>
),
)
TableCell.displayName = 'TableCell'
export type TableFooterProps = Primitive.FooterProps & { className?: string }
export const TableFooter = React.forwardRef<Primitive.FooterRef, TableFooterProps>((props, ref) => (
<Primitive.Footer {...props} ref={ref} className={cn('bg-muted', props.className)} />
))
TableFooter.displayName = 'TableFooter'
// The published headless components forward className outside the NativeWind JSX transform.
cssInterop(Primitive.Root, { className: 'style' })
cssInterop(Primitive.Header, { className: 'style' })
cssInterop(Primitive.Body, { className: 'style' })
cssInterop(Primitive.Row, { className: 'style' })
cssInterop(Primitive.Head, { className: 'style' })
cssInterop(Primitive.Cell, { className: 'style' })
cssInterop(Primitive.Footer, { className: 'style' })
components/ui/table/index.ts
export * from './Table'
Dependencies
Registry items
npm packages
react-native-css-interop@rn-primitives/table