Ride Receipt
Completed ride receipt with an authoritative total, visible fare lines, pickup and drop-off times, and optional receipt and fare-review actions.
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 ride-receiptSource files
Expand a file to read the source the installer copies into your app.
components/blocks/ride-receipt/RideReceipt.tsx
import { Children, Fragment, isValidElement, type ReactNode } from 'react'
import { View, type ViewProps } from 'react-native'
import { CircleDot, MapPin } from 'lucide-react-native'
import { Button } from '@/components/ui/button'
import { Icon } from '@/components/ui/icon'
import { Separator } from '@/components/ui/separator'
import { Text } from '@/components/ui/text'
import { cn } from '@/lib/utils'
export interface RideReceiptStop {
address: string
/** Caller-formatted local time. */
time?: string
}
const defaultLabels = {
total: 'Trip total',
trip: 'Trip details',
pickup: 'Pickup',
dropoff: 'Drop-off',
breakdown: 'Fare breakdown',
receipt: 'Open receipt',
report: 'Report a fare issue',
}
export interface RideReceiptProps extends ViewProps {
className?: string
/** The authoritative, caller-formatted amount charged. */
total: string
/** A masked payment label, for example "Card ending in 2048". */
paymentLabel?: string
/** A localized date and receipt reference. */
metadata?: string
pickup: RideReceiptStop
dropoff: RideReceiptStop
/** An optional explanation of a fare adjustment. */
note?: string
onOpenReceipt?: () => void
onReportIssue?: () => void
labels?: Partial<typeof defaultLabels>
}
function hasFareRows(children: ReactNode): boolean {
return Children.toArray(children).some((child) =>
isValidElement<{ children?: ReactNode }>(child) && child.type === Fragment
? hasFareRows(child.props.children)
: true,
)
}
export function RideReceipt({
total,
paymentLabel,
metadata,
pickup,
dropoff,
note,
onOpenReceipt,
onReportIssue,
labels,
children,
className,
...props
}: RideReceiptProps) {
const copy = { ...defaultLabels, ...labels }
const hasLines = hasFareRows(children)
return (
<View {...props} className={cn('gap-[20px]', className)}>
<View className="gap-[4px] rounded-lg bg-muted p-[16px]">
<Text size="sm" variant="muted">
{copy.total}
</Text>
<Text size="title" style={{ fontVariant: ['tabular-nums'] }}>
{total}
</Text>
{paymentLabel ? <Text size="sm">{paymentLabel}</Text> : null}
{metadata ? (
<Text size="sm" variant="muted">
{metadata}
</Text>
) : null}
</View>
{hasLines || note ? (
<View className="gap-[8px]">
<Text className="font-semibold">{copy.breakdown}</Text>
<View className="gap-[8px] rounded-lg border border-border bg-card p-[16px]">
{children}
{note ? (
<>
{hasLines ? <Separator /> : null}
<Text size="sm" variant="muted">
{note}
</Text>
</>
) : null}
</View>
</View>
) : null}
<View className="gap-[8px]">
<Text className="font-semibold">{copy.trip}</Text>
<View className="gap-[8px] rounded-lg border border-border bg-card p-[16px]">
<View className="flex-row items-start gap-[12px]">
<Icon icon={CircleDot} size={18} className="mt-[2px] text-muted-foreground" />
<View className="min-w-0 flex-1">
<Text size="xs" variant="muted">
{copy.pickup}
</Text>
<Text className="font-medium">{pickup.address}</Text>
{pickup.time ? (
<Text size="sm" variant="muted" style={{ fontVariant: ['tabular-nums'] }}>
{pickup.time}
</Text>
) : null}
</View>
</View>
<Separator />
<View className="flex-row items-start gap-[12px]">
<Icon icon={MapPin} size={18} className="mt-[2px] text-muted-foreground" />
<View className="min-w-0 flex-1">
<Text size="xs" variant="muted">
{copy.dropoff}
</Text>
<Text className="font-medium">{dropoff.address}</Text>
{dropoff.time ? (
<Text size="sm" variant="muted" style={{ fontVariant: ['tabular-nums'] }}>
{dropoff.time}
</Text>
) : null}
</View>
</View>
</View>
</View>
{onOpenReceipt || onReportIssue ? (
<View className="flex-row flex-wrap gap-[8px]">
{onOpenReceipt ? (
<Button accessibilityLabel={copy.receipt} onPress={onOpenReceipt}>
{copy.receipt}
</Button>
) : null}
{onReportIssue ? (
<Button variant="outline" accessibilityLabel={copy.report} onPress={onReportIssue}>
{copy.report}
</Button>
) : null}
</View>
) : null}
</View>
)
}
export interface RideReceiptLineProps extends ViewProps {
className?: string
label: string
amount: string
detail?: string
}
export function RideReceiptLine({ label, amount, detail, className, ...props }: RideReceiptLineProps) {
return (
<View {...props} className={cn('gap-[4px]', className)}>
<View className="flex-row flex-wrap items-baseline justify-between gap-[8px]">
<Text size="sm" className="min-w-[120px] shrink grow">
{label}
</Text>
<Text size="sm" className="font-semibold" style={{ fontVariant: ['tabular-nums'] }}>
{amount}
</Text>
</View>
{detail ? (
<Text size="xs" variant="muted">
{detail}
</Text>
) : null}
</View>
)
}
components/blocks/ride-receipt/index.ts
export {
RideReceipt,
RideReceiptLine,
type RideReceiptLineProps,
type RideReceiptProps,
type RideReceiptStop,
} from './RideReceipt'