UIPackage React Native
Search
Menu

Transaction Activity

A searchable, date-grouped native ledger with money-in and money-out filters, signed localized amounts, transaction status, and optional detail 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 transaction-activity

Source files

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

components/blocks/transaction-activity/TransactionActivity.tsx
import * as React from 'react'
import { Platform, SectionList, View, useWindowDimensions, type ViewProps } from 'react-native'
import { ArrowDownLeft, ArrowUpRight, Minus } from 'lucide-react-native'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import { Icon } from '@/components/ui/icon'
import { ListItem, ListItemContent, ListItemDescription, ListItemTitle, ListSeparator } from '@/components/ui/list'
import { SearchBar } from '@/components/ui/search-bar'
import { SegmentedControl, SegmentedControlItem } from '@/components/ui/segmented-control'
import { Text } from '@/components/ui/text'
import { useAnnouncement } from '@/lib/accessibility'
import { cn } from '@/lib/utils'

export interface TransactionActivityEntry {
  id: string
  name: string
  description?: string
  /** Signed amount in major currency units. Positive values are credits. */
  amount: number
  /** Three-letter currency code, such as USD or EUR. */
  currency: string
  /** Unix timestamp in milliseconds. Sections use the device's calendar day. */
  occurredAt: number
  status?: 'posted' | 'pending' | 'reversed'
}

const labels = {
  search: 'Search transactions',
  all: 'All',
  incoming: 'Money in',
  outgoing: 'Money out',
  pending: 'Pending',
  reversed: 'Reversed',
  empty: 'No transactions yet',
  noMatches: 'No matching transactions',
  clearFilters: 'Clear filters',
  resultCount: (count: number) => `${count} ${count === 1 ? 'transaction' : 'transactions'}`,
}

export interface TransactionActivityProps extends ViewProps {
  className?: string
  /** Omit to show sample activity. Pass an empty array for a real empty state. */
  entries?: readonly TransactionActivityEntry[]
  /** Adds content above the search field inside the list's scroll area. */
  header?: React.ReactNode
  locale?: string
  labels?: Partial<typeof labels>
  /** Makes each transaction an action. Detail presentation is owned by the caller. */
  onEntryPress?: (entry: TransactionActivityEntry) => void
}

const sampleEntries: readonly TransactionActivityEntry[] = [
  {
    id: 'sample-1',
    name: 'Cedar Market',
    description: 'Groceries',
    amount: -28.45,
    currency: 'USD',
    occurredAt: Date.UTC(2026, 10, 24, 15),
  },
  {
    id: 'sample-2',
    name: 'Oliver Bennett',
    description: 'Transfer received',
    amount: 75,
    currency: 'USD',
    occurredAt: Date.UTC(2026, 10, 23, 18),
  },
]

type Direction = 'all' | 'incoming' | 'outgoing'

function activitySections(
  entries: readonly TransactionActivityEntry[],
  query: string,
  direction: Direction,
  dateFormat: Intl.DateTimeFormat,
  locale: string | undefined,
) {
  const search = query.trim().toLocaleLowerCase(locale)
  const sorted = entries
    .filter((entry) => {
      if (!Number.isFinite(entry.amount) || Number.isNaN(new Date(entry.occurredAt).getTime())) return false
      if (direction === 'incoming' && entry.amount <= 0) return false
      if (direction === 'outgoing' && entry.amount >= 0) return false
      return (
        !search ||
        [entry.name, entry.description, entry.currency].some((value) =>
          value?.toLocaleLowerCase(locale).includes(search),
        )
      )
    })
    .sort((a, b) => b.occurredAt - a.occurredAt)

  const sections = new Map<string, { key: string; title: string; data: TransactionActivityEntry[] }>()
  for (const entry of sorted) {
    const date = new Date(entry.occurredAt)
    const key = `${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`
    const section = sections.get(key)
    if (section) section.data.push(entry)
    else sections.set(key, { key, title: dateFormat.format(date), data: [entry] })
  }
  return { sections: [...sections.values()], count: sorted.length }
}

function formatAmount(entry: TransactionActivityEntry, locale: string | undefined) {
  const currency = entry.currency.trim().toUpperCase()
  const amount = entry.amount === 0 ? 0 : entry.amount
  if (!/^[A-Z]{3}$/.test(currency)) {
    return [new Intl.NumberFormat(locale, { signDisplay: 'exceptZero' }).format(amount), currency]
      .filter(Boolean)
      .join(' ')
  }
  return new Intl.NumberFormat(locale, { style: 'currency', currency, signDisplay: 'exceptZero' }).format(amount)
}

export function TransactionActivity({
  className,
  entries = sampleEntries,
  header,
  locale,
  labels: overrides,
  onEntryPress,
  ...props
}: TransactionActivityProps) {
  const copy = { ...labels, ...overrides }
  const [query, setQuery] = React.useState('')
  const [settledQuery, setSettledQuery] = React.useState(query)
  const [direction, setDirection] = React.useState<Direction>('all')
  const { width, fontScale } = useWindowDimensions()
  const stackDetails = width < 360 || fontScale >= 1.4
  const dateFormat = React.useMemo(
    () => new Intl.DateTimeFormat(locale, { weekday: 'short', day: 'numeric', month: 'short', year: 'numeric' }),
    [locale],
  )
  const { sections, count } = React.useMemo(
    () => activitySections(entries, query, direction, dateFormat, locale),
    [entries, query, direction, dateFormat, locale],
  )
  const hasFilters = !!query.trim() || direction !== 'all'
  const resultCount = copy.resultCount(count)
  React.useEffect(() => {
    if (query === settledQuery) return
    const timer = setTimeout(() => setSettledQuery(query), 300)
    return () => clearTimeout(timer)
  }, [query, settledQuery])
  useAnnouncement(hasFilters && query === settledQuery ? resultCount : undefined)

  return (
    <View {...props} className={cn('min-h-0 flex-1 bg-background', className)}>
      <SectionList
        sections={sections}
        keyExtractor={(entry) => entry.id}
        stickySectionHeadersEnabled={false}
        keyboardDismissMode="on-drag"
        keyboardShouldPersistTaps="handled"
        automaticallyAdjustKeyboardInsets={Platform.OS === 'ios'}
        contentContainerStyle={{ paddingBottom: 16 }}
        ListHeaderComponent={
          <View className="gap-3 pb-4">
            {header}
            <SearchBar
              accessibilityLabel={copy.search}
              placeholder={copy.search}
              value={query}
              onChangeText={setQuery}
            />
            <SegmentedControl
              value={direction}
              onValueChange={(value) => {
                if (value === 'all' || value === 'incoming' || value === 'outgoing') setDirection(value)
              }}
            >
              <SegmentedControlItem value="all">{copy.all}</SegmentedControlItem>
              <SegmentedControlItem value="incoming">{copy.incoming}</SegmentedControlItem>
              <SegmentedControlItem value="outgoing">{copy.outgoing}</SegmentedControlItem>
            </SegmentedControl>
            <Text size="xs" variant="muted">
              {resultCount}
            </Text>
          </View>
        }
        ListEmptyComponent={
          <View className="items-center gap-3 rounded-xl border border-border px-4 py-8">
            <Text className="text-center font-semibold">{hasFilters ? copy.noMatches : copy.empty}</Text>
            {hasFilters ? (
              <Button
                variant="outline"
                accessibilityLabel={copy.clearFilters}
                onPress={() => {
                  setQuery('')
                  setDirection('all')
                }}
              >
                {copy.clearFilters}
              </Button>
            ) : null}
          </View>
        }
        renderSectionHeader={({ section }) => (
          <Text size="sm" accessibilityRole="header" className="border-b border-border pb-2 pt-4 font-semibold">
            {section.title}
          </Text>
        )}
        ItemSeparatorComponent={ListSeparator}
        renderItem={({ item }) => {
          const amount = formatAmount(item, locale)
          const status =
            item.status === 'pending' ? copy.pending : item.status === 'reversed' ? copy.reversed : undefined
          const Glyph = item.amount > 0 ? ArrowDownLeft : item.amount < 0 ? ArrowUpRight : Minus
          return (
            <ListItem
              accessible
              accessibilityLabel={[item.name, item.description, amount, status].filter(Boolean).join(', ')}
              onPress={onEntryPress ? () => onEntryPress(item) : undefined}
              className="items-start px-0"
            >
              <View className="size-10 shrink-0 items-center justify-center rounded-lg bg-muted">
                <Icon icon={Glyph} size={18} className={item.amount > 0 ? 'text-success' : 'text-muted-foreground'} />
              </View>
              <ListItemContent className={cn('gap-2', !stackDetails && 'flex-row justify-between')}>
                <View className={cn('min-w-0 gap-1', !stackDetails && 'flex-1')}>
                  <ListItemTitle>{item.name}</ListItemTitle>
                  {item.description ? <ListItemDescription>{item.description}</ListItemDescription> : null}
                </View>
                <View className={cn('items-start gap-1', !stackDetails && 'max-w-[46%] items-end')}>
                  <Text
                    size="sm"
                    className={cn('font-medium', !stackDetails && 'text-right', item.amount > 0 && 'text-success')}
                    style={{ fontVariant: ['tabular-nums'] }}
                  >
                    {amount}
                  </Text>
                  {status ? (
                    <Badge variant={item.status === 'pending' ? 'outline' : 'secondary'} text={status} />
                  ) : null}
                </View>
              </ListItemContent>
            </ListItem>
          )
        }}
      />
    </View>
  )
}
components/blocks/transaction-activity/index.ts
export {
  TransactionActivity,
  type TransactionActivityEntry,
  type TransactionActivityProps,
} from './TransactionActivity'

Dependencies

Registry items

npm packages

  • lucide-react-native
Browse finance