List
Composable native list surface and static or pressable items with caller-owned row content.
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 listSource files
Expand a file to read the source the installer copies into your app.
components/ui/list/List.tsx
import * as React from 'react'
import { Pressable, View, type PressableProps, type ViewProps } from 'react-native'
import { Text, type TextProps } from '@/components/ui/text'
import { renderTextChildren } from '@/lib/label-children'
import { cn } from '@/lib/utils'
type ListViewProps = ViewProps & { className?: string }
export const List = React.forwardRef<React.ComponentRef<typeof View>, ListViewProps>(({ className, ...props }, ref) => (
<View ref={ref} className={cn('overflow-hidden rounded-lg border border-border bg-card', className)} {...props} />
))
List.displayName = 'List'
export interface ListItemProps extends Omit<PressableProps, 'children' | 'style'> {
children?: React.ReactNode
className?: string
style?: ViewProps['style']
}
export const ListItem = React.forwardRef<React.ComponentRef<typeof Pressable>, ListItemProps>(
({ className, children, onPress, onLongPress, disabled, accessibilityState, style, ...props }, ref) => {
const classes = cn('min-h-[48px] flex-row items-center gap-[12px] px-4 py-3', disabled && 'opacity-50', className)
if (!onPress && !onLongPress) {
return (
<View ref={ref} {...props} accessibilityState={accessibilityState} className={classes} style={style}>
{renderTextChildren(children)}
</View>
)
}
return (
<Pressable
ref={ref}
{...props}
accessibilityRole={props.accessibilityRole ?? 'button'}
accessibilityState={{ ...accessibilityState, disabled: !!disabled }}
disabled={disabled}
style={style}
onPress={onPress}
onLongPress={onLongPress}
className={cn(classes, 'active:bg-muted')}
>
{renderTextChildren(children)}
</Pressable>
)
},
)
ListItem.displayName = 'ListItem'
export const ListItemContent = React.forwardRef<React.ComponentRef<typeof View>, ListViewProps>(
({ className, ...props }, ref) => <View ref={ref} className={cn('min-w-0 flex-1 gap-1', className)} {...props} />,
)
ListItemContent.displayName = 'ListItemContent'
export const ListItemTitle = React.forwardRef<React.ComponentRef<typeof Text>, TextProps>(
({ className, ...props }, ref) => <Text ref={ref} className={cn('font-medium', className)} {...props} />,
)
ListItemTitle.displayName = 'ListItemTitle'
export const ListItemDescription = React.forwardRef<React.ComponentRef<typeof Text>, TextProps>((props, ref) => (
<Text ref={ref} size="sm" variant="muted" {...props} />
))
ListItemDescription.displayName = 'ListItemDescription'
export { Separator as ListSeparator } from '@/components/ui/separator'
components/ui/list/index.ts
export * from './List'