UIPackage React Native
Search
Menu

Menu Item Configurator

Food-order item form with a modifier slot, bounded quantity, preparation note and a price-aware add action.

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 menu-item-configurator

Source files

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

components/blocks/menu-item-configurator/MenuItemConfigurator.tsx
import * as React from 'react'
import { View, type ViewProps } from 'react-native'
import { Button } from '@/components/ui/button'
import { QuantityStepper } from '@/components/ui/quantity-stepper'
import { Text } from '@/components/ui/text'
import { Textarea } from '@/components/ui/textarea'
import { cn } from '@/lib/utils'

export interface MenuItemSelection {
  quantity: number
  note: string
}

export interface MenuItemConfiguratorProps extends ViewProps {
  className?: string
  title: string
  description?: string
  /** An optional image or other item media supplied by the caller. */
  media?: React.ReactNode
  quantityLabel?: string
  noteLabel?: string
  addLabel?: string
  /** Current price for this quantity and the consumer's chosen options. */
  formatTotal?: (quantity: number) => string
  /** Visible explanation when a required choice or availability blocks adding. */
  blockedReason?: string
  /** An error returned by the caller, with the form still available for retry. */
  error?: string
  loading?: boolean
  /** Option controls are composed as children. The caller owns their selections. */
  children?: React.ReactNode
  onAdd: (selection: MenuItemSelection) => void
}

export function MenuItemConfigurator({
  className,
  title,
  description,
  media,
  quantityLabel = 'Quantity',
  noteLabel = 'Preparation note (optional)',
  addLabel = 'Add to order',
  formatTotal,
  blockedReason,
  error,
  loading = false,
  children,
  onAdd,
  ...props
}: MenuItemConfiguratorProps) {
  const [quantity, setQuantity] = React.useState(1)
  const [note, setNote] = React.useState('')
  const total = formatTotal?.(quantity)

  function addItem() {
    if (blockedReason || loading) return
    onAdd({ quantity, note: note.trim() })
  }

  return (
    <View {...props} className={cn('gap-[24px]', className)}>
      {media}
      <View className="gap-[8px]">
        <Text size="title" accessibilityRole="header">
          {title}
        </Text>
        {description ? <Text variant="muted">{description}</Text> : null}
      </View>
      {children}
      <View className="flex-row flex-wrap items-center justify-between gap-[8px]">
        <Text size="sm" aria-hidden className="shrink font-medium">
          {quantityLabel}
        </Text>
        <QuantityStepper
          min={1}
          value={quantity}
          onValueChange={setQuantity}
          disabled={loading}
          accessibilityLabel={quantityLabel}
        />
      </View>
      <View className="gap-[8px]">
        <Text size="sm" aria-hidden className="font-medium">
          {noteLabel}
        </Text>
        <Textarea
          accessibilityLabel={noteLabel}
          value={note}
          onChangeText={setNote}
          editable={!loading}
          className="max-h-[160px] min-h-[80px]"
        />
      </View>
      <View className="gap-[8px]">
        {blockedReason ? (
          <Text size="sm" variant="muted" accessibilityLiveRegion="polite">
            {blockedReason}
          </Text>
        ) : null}
        {error ? (
          <Text size="sm" accessibilityRole="alert" className="text-destructive">
            {error}
          </Text>
        ) : null}
        <Button
          accessibilityLabel={total ? `${addLabel}, ${total}` : addLabel}
          disabled={Boolean(blockedReason)}
          loading={loading}
          onPress={addItem}
        >
          {total ? `${addLabel} · ${total}` : addLabel}
        </Button>
      </View>
    </View>
  )
}
components/blocks/menu-item-configurator/index.ts
export { MenuItemConfigurator, type MenuItemConfiguratorProps, type MenuItemSelection } from './MenuItemConfigurator'

Dependencies

Browse shopping and reservations