Collection
Tour Operator / Tour Bookings · v0.2.1Validated
Review month-to-date sales against the same prior period and inspect individual days.
Monthly Tour Revenue · Preview
Loading widget…
Preparing source code…
Idle
Tour Operator / Tour Bookings · v0.2.1Validated
Review month-to-date sales against the same prior period and inspect individual days.
Loading widget…
Preparing source code…
Load the Lumo theme once in your app entry point. The example uses the local Lumo workspace packages.
import "@lumo/tokens/tokens.css";
import { RevenueMonthWidget } from "@lumo/widgets/catalog/tour-sales/revenue-month";
export default function Example() {
return <RevenueMonthWidget />;
}Props for integrating the React component in your app.
snapshotMonthlyRevenueSnapshot | null (optional){
"snapshot": {
"period": "Dec 1–2",
"currency": "EUR",
"previousRevenueMinor": 624200,
"days": [
{
"id": "12-01",
"label": "Dec 1",
"revenueMinor": 340000,
"bookings": 8
},
{
"id": "12-02",
"label": "Dec 2",
"revenueMinor": 373400,
"bookings": 9
}
]
}
}"use client";
import { AnimatedNumber, Badge, Button, WidgetCard } from "@lumo/ui";
import { ChartNoAxesCombined } from "lucide-react";
import { useState } from "react";
import { WidgetReadingSeries } from "../../shared/WidgetReadingSeries";
import shared from "../../shared/operations-list.module.css";
import styles from "./revenue-month.module.css";
export interface MonthlyRevenueDay {
id: string;
label: string;
revenueMinor: number | null;
bookings?: number | null;
}
export interface MonthlyRevenueSnapshot {
period: string;
currency: string;
days: readonly MonthlyRevenueDay[];
previousRevenueMinor?: number | null;
}
const example: MonthlyRevenueSnapshot = {
period: "Nov 1–9 · Month to date", currency: "EUR", previousRevenueMinor: 3_212_400,
days: [3534, 3872, 3441, 4203, 5619, 5097, 3728, 4376, 4432].map((amount, i) => ({
id: `2026-11-0${i + 1}`, label: `Nov ${i + 1}`, revenueMinor: amount * 100, bookings: 7 + i % 5,
})),
};
const known = (value: unknown): value is number => typeof value === "number" && Number.isSafeInteger(value);
export function RevenueMonthWidget({ snapshot = example }: { snapshot?: MonthlyRevenueSnapshot | null; index?: number } = {}) {
const [pinned, pin] = useState<string>();
const [hover, preview] = useState<string>();
const points = snapshot?.days.map(day => ({ ...day, value: known(day.revenueMinor) ? day.revenueMinor : null })) ?? [];
const pinnedDay = points.find(day => day.id === pinned);
const selected = points.find(day => day.id === hover) ?? pinnedDay;
const reported = points.filter(day => day.value !== null);
const total = reported.length ? reported.reduce((sum, day) => sum + (day.value ?? 0), 0) : null;
const value = selected ? selected.value : total;
const previous = snapshot?.previousRevenueMinor;
const change = !selected && total !== null && reported.length === points.length && known(previous) && previous > 0 ? (total - previous) / previous : null;
const currency = snapshot && /^[A-Z]{3}$/.test(snapshot.currency) ? snapshot.currency : undefined;
const format = { style: currency ? "currency" : "decimal", currency, maximumFractionDigits: 0 } as const;
const money = new Intl.NumberFormat("en", format);
const scale = currency ? 10 ** (new Intl.NumberFormat("en", { style: "currency", currency }).resolvedOptions().maximumFractionDigits ?? 2) : 1;
return <WidgetCard title="Revenue This Month" description={snapshot?.period} icon={<ChartNoAxesCombined />} size="medium"
className={`${shared.mediumCard} ${shared.stableCard} ${styles.card}`}>
{snapshot ? <div className={styles.content}>
<div className={styles.readout}>
<div className={styles.amount} title={value !== null && currency ? money.format(value / scale) : undefined}>
{value === null || !currency ? <strong aria-label="Revenue unavailable">—</strong>
: <AnimatedNumber value={value / scale} className={styles.number} format={format} blur={false} />}
</div>
{change !== null && <Badge className={styles.comparison} size="sm" pill tone={change >= 0 ? "success" : "warning"}>
{new Intl.NumberFormat("en", { style: "percent", signDisplay: "exceptZero", maximumFractionDigits: 1 }).format(change)}
</Badge>}
</div>
<div className={styles.context}>
<strong title={selected?.label}>{selected?.label ?? "Month to date"}</strong>
<span className={styles.note}>{selected ? selected.bookings == null ? "Daily revenue" : `${selected.bookings} bookings`
: change !== null ? "vs same prior period" : `${reported.length} of ${points.length} days reported`}</span>
</div>
<div className={styles.chart}>
{points.length ? <WidgetReadingSeries points={points} activeId={selected?.id} onSelect={pin} onPreview={preview}
kind="line" signed={points.some(day => (day.value ?? 0) < 0)} color="var(--success)" label="Daily revenue"
describe={point => point.label + ", " + (point.value === null || !currency ? "unavailable" : money.format(point.value / scale))} />
: <p className={shared.muted}>No days reported.</p>}
</div>
<div className={styles.actions}>{pinnedDay && <Button size="xs" variant="ghost" onClick={() => { pin(undefined); preview(undefined); }}>Month total</Button>}</div>
</div> : <p className={shared.muted}>Revenue unavailable.</p>}
</WidgetCard>;
}
lucide-reactmotionreactreact-dom