Collection
Hospitality / Revenue & Inventory · v0.3.0Validated
Inspect sellable room inventory and the supplied price for each night.
Sellable Nights · Preview
Loading widget…
Preparing source code…
Idle
Hospitality / Revenue & Inventory · v0.3.0Validated
Inspect sellable room inventory and the supplied price for each night.
Loading widget…
Preparing source code…
Import @lumo/widgets/widget-utilities.css in your Tailwind stylesheet, alongside the Lumo theme.
import "@lumo/tokens/tokens.css";
import { FreeNightsWidget } from "@lumo/widgets/catalog/hotel-revenue/free-nights";
export default function Example() {
return <FreeNightsWidget />;
}Props for integrating the React component in your app.
snapshotFreeNightsSnapshot | null (optional){
"property": "Olive Wharf",
"roomType": "Courtyard twin",
"currency": "EUR",
"nights": [
{
"date": "2026-12-16",
"available": 13,
"rate": 132
}
]
}"use client";
import { AnimatedNumber, Badge, Button, WidgetCard, WidgetDialog } from "@lumo/ui";
import { BedDouble, CalendarDays } from "lucide-react";
import { useMemo, useRef, useState } from "react";
import { WidgetReadingSeries } from "../../shared/WidgetReadingSeries";
import shared from "../../shared/operations-list.module.css";
import { demo } from "./free-nights.constants";
import type { AvailableNight, FreeNightsSnapshot } from "./free-nights.types";
export type { AvailableNight, FreeNightsSnapshot } from "./free-nights.types";
function shortDay(date: string) { return date.slice(8, 10); }
export function FreeNightsWidget({ snapshot = demo }: { index?: number; snapshot?: FreeNightsSnapshot | null } = {}) {
const [date, setDate] = useState<string>();
const [open, setOpen] = useState(false);
const trigger = useRef<HTMLButtonElement>(null);
const nights = useMemo(() => [...new Map(snapshot?.nights.filter(row => /^\d{4}-\d{2}-\d{2}$/.test(row.date))
.map(row => [row.date, { ...row, available: row.available !== null && Number.isSafeInteger(row.available) && row.available >= 0
? row.available : null }])).values()].sort((a, b) => a.date.localeCompare(b.date)).slice(0, 7), [snapshot?.nights]);
const points = useMemo(() => nights.map(row => ({ id: row.date, label: shortDay(row.date), value: row.available })), [nights]);
const most = nights.reduce<AvailableNight | undefined>((best, night) => (night.available ?? -1) > (best?.available ?? -1) ? night : best, undefined);
const current = nights.find(row => row.date === date) ?? most ?? nights[0];
const currency = snapshot?.currency ?? demo.currency;
const format = new Intl.NumberFormat("en-US", { style: "currency", currency: /^[A-Z]{3}$/.test(currency) ? currency : demo.currency });
const rateText = (row: AvailableNight) => typeof row.rate === "number" && Number.isFinite(row.rate) && row.rate >= 0 ? format.format(row.rate) : "Rate unavailable";
const surface = <WidgetCard title="Free Nights" description={snapshot ? `${snapshot.property} · ${snapshot.roomType}` : undefined}
size="medium" icon={<BedDouble />} className={`${shared.mediumCard} ${shared.stableCard}`}
action={current && <Button type="button" size="xs" variant="ghost" ref={trigger} aria-haspopup="dialog" aria-label="View all nights"
onClick={() => setOpen(true)}><CalendarDays size={15} aria-hidden /></Button>}>
{current ? <div className={shared.stack}>
<div className={shared.summary}><strong className={shared.hero}>{current.available === null ? "—" : <AnimatedNumber value={current.available} className={shared.compactNumber} />}</strong>
<span className={shared.unit}>Rooms available</span></div>
<WidgetReadingSeries points={points} activeId={current.date} onSelect={setDate} label="Room availability by night"
describe={point => `${point.id}, ${point.value === null ? "inventory unavailable" : `${point.value} rooms available`}`} />
<div className={`${shared.summary} ${shared.chartSummary}`}><span className={shared.identity}><strong>{current.date}</strong><span>{rateText(current)}</span></span>
{current === most && (most.available ?? 0) > 0 && <Badge size="sm" tone="success">Most available</Badge>}</div>
</div> : <p className={shared.muted}>{snapshot ? "No nights in this window." : "Room inventory unavailable."}</p>}
</WidgetCard>;
return <WidgetDialog className={shared.mediumFrame} surface={surface} title="Availability by night" placement="bottom" dragFromScrollStart
open={open && Boolean(current)} onClose={() => setOpen(false)} returnFocusRef={trigger}>
<ul className={`${shared.sheetList} ${shared.zebra}`} data-widget-list>
{nights.map(night => <li key={night.date}><button className={shared.row} type="button" onClick={() => { setDate(night.date); setOpen(false); }}>
<span className={shared.identity}><strong>{night.date}</strong><span>{rateText(night)}</span></span><strong>{night.available ?? "—"}</strong>
</button></li>)}
</ul>
</WidgetDialog>;
}
lucide-reactmotionreactreact-dom