UIPackage React Native
Search
Menu

Storefront Collection

A responsive native product grid with availability, photos and caller-owned product selection.

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 storefront-collection

Source files

Expand a file to read the source the installer copies into your app.

components/blocks/storefront-collection/StorefrontCollection.tsx
import { Pressable, useWindowDimensions, View, type ViewProps } from 'react-native'
import { Grid, GridItem } from '@/components/ui/grid'
import { Image, ImageFallback, ImageSource, type ImageSourceValue } from '@/components/ui/image'
import { Text } from '@/components/ui/text'
import { cn } from '@/lib/utils'

export interface StorefrontProduct {
  id: string
  title: string
  detail?: string
  /** Caller-localized price. */
  price?: string
  image?: ImageSourceValue
  soldOut?: boolean
}

export interface StorefrontCollectionProps extends Omit<ViewProps, 'children'> {
  className?: string
  title: string
  /** Bounded collection; page or replace items at the parent for long result sets. */
  items?: readonly StorefrontProduct[]
  labels?: Partial<Record<'soldOut' | 'empty' | 'photoUnavailable' | 'openHint', string>>
  onOpen: (productId: string) => void
}

export function StorefrontCollection({
  className,
  title,
  items = [],
  labels,
  onOpen,
  ...props
}: StorefrontCollectionProps) {
  const { fontScale } = useWindowDimensions()

  return (
    <View {...props} className={cn('gap-[16px]', className)}>
      <Text size="title" accessibilityRole="header">
        {title}
      </Text>
      {items.length > 0 ? (
        <Grid minColumnWidth={132} maxColumns={fontScale >= 1.5 ? 1 : 3} gap={16}>
          {items.map(({ id, title, detail, price, image, soldOut }) => {
            const availability = soldOut ? (labels?.soldOut ?? 'Sold out') : undefined
            return (
              <GridItem key={id}>
                <Pressable
                  accessibilityRole="button"
                  accessibilityLabel={[title, detail, price, availability].filter(Boolean).join(', ')}
                  accessibilityHint={labels?.openHint ?? 'Opens product details'}
                  className="min-h-[48px] gap-[8px] rounded-lg border border-transparent p-px focus:border-ring active:bg-muted"
                  onPress={() => onOpen(id)}
                >
                  <Image
                    source={image}
                    style={{ aspectRatio: 1 }}
                    className="rounded-md"
                    accessibilityElementsHidden
                    importantForAccessibility="no-hide-descendants"
                  >
                    <ImageSource accessible={false} />
                    <ImageFallback>
                      <Text size="sm" variant="muted" className="text-center">
                        {labels?.photoUnavailable ?? 'Photo unavailable'}
                      </Text>
                    </ImageFallback>
                  </Image>
                  <View aria-hidden className="gap-[4px] px-[4px] pb-[4px]">
                    <Text className="font-semibold">{title}</Text>
                    {detail ? (
                      <Text size="sm" variant="muted">
                        {detail}
                      </Text>
                    ) : null}
                    {price ? <Text size="sm">{price}</Text> : null}
                    {availability ? (
                      <Text size="sm" variant="muted">
                        {availability}
                      </Text>
                    ) : null}
                  </View>
                </Pressable>
              </GridItem>
            )
          })}
        </Grid>
      ) : (
        <Text variant="muted">{labels?.empty ?? 'No products to show.'}</Text>
      )}
    </View>
  )
}
components/blocks/storefront-collection/index.ts
export { StorefrontCollection, type StorefrontCollectionProps, type StorefrontProduct } from './StorefrontCollection'

Dependencies

Registry items

Browse shopping and reservations