UIPackage React Native
Search

Trip Progress

Rider-facing pickup, journey, arrival, and issue states with vehicle verification, route and help/share slots.

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 trip-progress

Source files

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

components/blocks/trip-progress/TripProgress.tsx
import type { ReactNode } from 'react'
import { View, type ViewProps } from 'react-native'
import { CarFront, CircleAlert, CircleCheck, CircleDot, MapPin } from 'lucide-react-native'
import { Button } from '@/components/ui/button'
import { Icon } from '@/components/ui/icon'
import { Progress } from '@/components/ui/progress'
import { Text } from '@/components/ui/text'
import { useAnnouncement } from '@/lib/accessibility'
import { cn } from '@/lib/utils'

export type TripStage = 'pickup' | 'in-progress' | 'arrived'

export type TripProgressState =
  | { kind: 'pickup' | 'in-progress'; detail?: string; estimate?: string }
  | { kind: 'arrived'; detail?: string }
  | { kind: 'issue'; detail: string; stage?: TripStage }

export interface TripProgressDriver {
  name: string
  vehicle: string
  plate: string
  portrait?: ReactNode
}

const defaultLabels = {
  pickup: 'Pickup',
  destination: 'Destination',
  enRoute: 'On the way',
  arrived: 'Arrived',
  pickupStatus: 'Meeting your driver',
  arrivedStatus: 'You’ve arrived',
  issue: 'Trip needs attention',
  progress: 'Trip progress',
  driver: 'Driver',
  plate: 'License plate',
  help: 'Trip help',
  share: 'Share trip',
}

const stagePositions: Record<TripStage, number> = { pickup: 1, 'in-progress': 2, arrived: 3 }

export interface TripProgressProps extends Omit<ViewProps, 'children'> {
  className?: string
  pickup: string
  destination: string
  state: TripProgressState
  driver?: TripProgressDriver
  /** Optional caller-owned route preview. Leave the map passive when embedded in a scroll view. */
  route?: ReactNode
  /** Opens the consuming application's help. */
  onHelp?: () => void
  /** Opens a caller-owned share flow only after the rider asks to share. */
  onShare?: () => void
  labels?: Partial<typeof defaultLabels>
}

export function TripProgress({
  pickup,
  destination,
  state,
  driver,
  route,
  onHelp,
  onShare,
  labels,
  className,
  ...props
}: TripProgressProps) {
  const copy = { ...defaultLabels, ...labels }
  const stages = { pickup: copy.pickup, 'in-progress': copy.enRoute, arrived: copy.arrived }
  const status = {
    pickup: copy.pickupStatus,
    'in-progress': copy.enRoute,
    arrived: copy.arrivedStatus,
    issue: copy.issue,
  }[state.kind]
  const icon = state.kind === 'issue' ? CircleAlert : state.kind === 'arrived' ? CircleCheck : CarFront
  const stage = state.kind === 'issue' ? state.stage : state.kind
  useAnnouncement(state.kind === 'issue' ? `${status}. ${state.detail}` : status)
  const actions =
    onHelp || onShare ? (
      <View className="flex-row flex-wrap gap-[8px]">
        {onHelp ? (
          <Button
            variant={state.kind === 'issue' ? 'default' : 'outline'}
            accessibilityLabel={copy.help}
            onPress={onHelp}
          >
            {copy.help}
          </Button>
        ) : null}
        {onShare ? (
          <Button variant="outline" accessibilityLabel={copy.share} onPress={onShare}>
            {copy.share}
          </Button>
        ) : null}
      </View>
    ) : null

  return (
    <View {...props} className={cn('gap-[16px]', className)}>
      <View className="gap-[12px] rounded-lg border border-border bg-card p-[16px]">
        <View className="flex-row items-start gap-[12px]">
          <View className="size-[40px] items-center justify-center rounded-md bg-muted">
            <Icon icon={icon} size={20} className={state.kind === 'issue' ? 'text-destructive' : 'text-foreground'} />
          </View>
          <View className="min-w-0 flex-1 gap-[2px]">
            <Text size="xl">{status}</Text>
            {state.detail ? <Text variant="muted">{state.detail}</Text> : null}
            {'estimate' in state && state.estimate ? (
              <Text size="sm" className="font-medium" style={{ fontVariant: ['tabular-nums'] }}>
                {state.estimate}
              </Text>
            ) : null}
          </View>
        </View>
        {stage ? (
          <View className="gap-[6px]">
            <Progress
              value={stagePositions[stage]}
              max={3}
              accessibilityLabel={copy.progress}
              accessibilityValue={{ min: 0, max: 3, now: stagePositions[stage], text: stages[stage] }}
            />
            <View className="flex-row gap-[8px]" aria-hidden>
              <Text
                size="xs"
                variant="muted"
                className={cn('min-w-0 flex-1', stage === 'pickup' && 'font-semibold text-foreground')}
              >
                {copy.pickup}
              </Text>
              <Text
                size="xs"
                variant="muted"
                className={cn('min-w-0 flex-1 text-center', stage === 'in-progress' && 'font-semibold text-foreground')}
              >
                {copy.enRoute}
              </Text>
              <View className="min-w-0 flex-1 items-end">
                <Text size="xs" variant="muted" className={cn(stage === 'arrived' && 'font-semibold text-foreground')}>
                  {copy.arrived}
                </Text>
              </View>
            </View>
          </View>
        ) : null}
      </View>

      {state.kind === 'issue' ? actions : null}

      {driver ? (
        <View className="flex-row flex-wrap items-start gap-[16px] rounded-lg bg-muted p-[16px]">
          {driver.portrait}
          <View className="min-w-[104px] flex-1 gap-[2px]">
            <Text size="xs" variant="muted">
              {copy.driver}
            </Text>
            <Text className="font-semibold">{driver.name}</Text>
            <Text size="sm">{driver.vehicle}</Text>
          </View>
          <View className="min-w-[104px] gap-[2px]">
            <Text size="xs" variant="muted">
              {copy.plate}
            </Text>
            <Text className="font-semibold" style={{ fontVariant: ['tabular-nums'] }}>
              {driver.plate}
            </Text>
          </View>
        </View>
      ) : null}

      <View className="gap-[8px]">
        <View className="flex-row items-start gap-[8px]">
          <Icon icon={CircleDot} size={17} className="mt-[3px] text-muted-foreground" />
          <View className="min-w-0 flex-1">
            <Text variant="muted" size="xs">
              {copy.pickup}
            </Text>
            <Text className="font-medium">{pickup}</Text>
          </View>
        </View>
        <View className="flex-row items-start gap-[8px]">
          <Icon icon={MapPin} size={17} className="mt-[3px] text-muted-foreground" />
          <View className="min-w-0 flex-1">
            <Text variant="muted" size="xs">
              {copy.destination}
            </Text>
            <Text className="font-medium">{destination}</Text>
          </View>
        </View>
        {route}
      </View>

      {state.kind !== 'issue' ? actions : null}
    </View>
  )
}
components/blocks/trip-progress/index.ts
export {
  TripProgress,
  type TripProgressDriver,
  type TripProgressProps,
  type TripProgressState,
  type TripStage,
} from './TripProgress'

Dependencies

Registry items

npm packages

  • lucide-react-native
Browse delivery and transport