Delivery Tracking
Delivery overview with a status, delivery window, exception notice, and composable tracking history.
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 delivery-trackingSource files
Expand a file to read the source the installer copies into your app.
components/blocks/delivery-tracking/DeliveryTracking.tsx
import * as React from 'react'
import { View, type ViewProps } from 'react-native'
import { Badge } from '@/components/ui/badge'
import { Text } from '@/components/ui/text'
import { cn } from '@/lib/utils'
const statuses = {
preparing: { label: 'Preparing', variant: 'secondary' },
'in-transit': { label: 'In transit', variant: 'secondary' },
'out-for-delivery': { label: 'Out for delivery', variant: 'info' },
delivered: { label: 'Delivered', variant: 'success' },
exception: { label: 'Delivery delayed', variant: 'warning' },
} as const
export type DeliveryTrackingStatus = keyof typeof statuses
export interface DeliveryTrackingProps extends ViewProps {
title?: string
reference?: string
status?: DeliveryTrackingStatus
timing?: string
timingLabel?: string
attention?: React.ReactNode
map?: React.ReactNode
actions?: React.ReactNode
className?: string
}
export const DeliveryTracking = React.forwardRef<React.ComponentRef<typeof View>, DeliveryTrackingProps>(
(
{
title = 'Delivery',
reference,
status = 'in-transit',
timing,
timingLabel = status === 'delivered' ? 'Received' : 'Estimated delivery',
attention,
map,
actions,
className,
children,
...props
},
ref,
) => {
const { label, variant } = statuses[status]
return (
<View ref={ref} {...props} className={cn('gap-5 rounded-xl border border-border bg-card p-4', className)}>
<View className="flex-row flex-wrap items-start justify-between gap-3">
<View className="min-w-[120px] flex-1 gap-1">
<Text size="lg" className="font-semibold" accessibilityRole="header">
{title}
</Text>
{reference ? (
<Text size="sm" variant="muted">
{reference}
</Text>
) : null}
</View>
<Badge className="max-w-full self-start" variant={variant}>
{label}
</Badge>
</View>
{timing ? (
<View className="gap-1 rounded-lg bg-muted p-3">
<Text size="sm" variant="muted">
{timingLabel}
</Text>
<Text size="title">{timing}</Text>
</View>
) : null}
{attention ? (
<View className="gap-1 rounded-lg border border-warning p-3">
<Text className="font-semibold">Delivery update</Text>
{typeof attention === 'string' ? <Text>{attention}</Text> : attention}
</View>
) : null}
{map}
{children ? (
<View className="gap-3">
<Text size="lg" className="font-semibold" accessibilityRole="header">
Tracking history
</Text>
<View>{children}</View>
</View>
) : null}
{actions}
</View>
)
},
)
DeliveryTracking.displayName = 'DeliveryTracking'
export interface DeliveryTrackingEventProps extends ViewProps {
title: string
time?: string
current?: boolean
last?: boolean
className?: string
}
export const DeliveryTrackingEvent = React.forwardRef<React.ComponentRef<typeof View>, DeliveryTrackingEventProps>(
({ title, time, current = false, last = false, className, children, ...props }, ref) => (
<View ref={ref} {...props} className={cn('flex-row items-stretch gap-3', className)}>
<View className="w-[16px] items-center pt-[6px]" aria-hidden>
<View className={cn('size-[12px] rounded-full border-2 border-ring', current && 'bg-primary border-primary')} />
{last ? null : <View className="w-px flex-1 bg-border" />}
</View>
<View className={cn('min-w-0 flex-1 gap-1', !last && 'pb-4')}>
<Text className="font-semibold" accessibilityLabel={current ? `Latest update, ${title}` : undefined}>
{title}
</Text>
{time ? (
<Text size="sm" variant="muted">
{time}
</Text>
) : null}
{typeof children === 'string' ? <Text size="sm">{children}</Text> : children}
</View>
</View>
),
)
DeliveryTrackingEvent.displayName = 'DeliveryTrackingEvent'
components/blocks/delivery-tracking/index.ts
export * from './DeliveryTracking'