Collection
Hospitality / Revenue & Inventory · v0.2.1Validated
Adjust a draft base price and compare derived rates before applying it.
Room Rate Tiers · Preview
Loading widget…
Preparing source code…
Idle
Hospitality / Revenue & Inventory · v0.2.1Validated
Adjust a draft base price and compare derived rates before applying it.
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 { PriceLadderWidget } from "@lumo/widgets/catalog/hotel-revenue/price-ladder";
export default function Example() {
return <PriceLadderWidget />;
}Props for integrating the React component in your app.
snapshotPriceLadderSnapshot | null (optional)onAction(action: PriceLadderAction) => void | Promise<void>{
"snapshot": {
"plan": "Courtyard King",
"stayDate": "2026-12-18",
"currency": "EUR",
"revision": "1",
"masterMinor": 24500,
"derived": [
{
"id": "nr",
"label": "Advance purchase",
"multiplier": 0.9,
"offsetMinor": 0
}
],
"editRange": {
"minimum": 15000,
"maximum": 42500,
"step": 500
}
}
}"use client";
import { Button, FormError, Progress, Slider, SlotText, useScrollShadow, WidgetCard } from "@lumo/ui";
import { ChartNoAxesGantt } from "lucide-react";
import { useState } from "react";
import type { z } from "zod";
import { nonnegativeInteger, operationMoney, useOperationSnapshot } from "../../shared/operation-snapshot";
import shared from "../../shared/operations-list.module.css";
import { useWidgetCommand } from "../../shared/use-widget-command";
import { priceLadderUpdateSchema } from "./price-ladder.schema";
import styles from "./price-ladder.module.css";
export interface PricePlanRule { id: string; label: string; multiplier: number; offsetMinor: number }
export interface PriceLadderSnapshot {
plan: string; stayDate: string; currency: string; revision: string; masterMinor: number | null;
derived: readonly PricePlanRule[]; editRange?: { minimum: number; maximum: number; step: number };
}
export type PriceLadderAction = z.infer<typeof priceLadderUpdateSchema>;
const example: PriceLadderSnapshot = { plan: "Courtyard King", stayDate: "2026-12-18", currency: "EUR", revision: "1", masterMinor: 24500,
derived: [{ id: "nr", label: "Advance purchase", multiplier: .9, offsetMinor: 0 }, { id: "bf", label: "Breakfast included", multiplier: 1, offsetMinor: 3000 }],
editRange: { minimum: 15000, maximum: 42500, step: 500 },
};
function deriveRate(base: number | null | undefined, rule: PricePlanRule) {
if (!nonnegativeInteger(base) || !Number.isFinite(rule.multiplier) || rule.multiplier < 0 || !Number.isSafeInteger(rule.offsetMinor)) return null;
const result = Math.max(0, Math.round(base * rule.multiplier + rule.offsetMinor));
return nonnegativeInteger(result) ? result : null;
}
export function PriceLadderWidget({ snapshot, onAction }: { index?: number; snapshot?: PriceLadderSnapshot | null; onAction?: (action: PriceLadderAction) => void | Promise<void> } = {}) {
const { data, action } = useOperationSnapshot(snapshot, example, onAction, (current, command) => (
command.revision === current.revision ? { ...current, masterMinor: command.rateMinor, revision: current.revision + "*" } : current
));
const [draft, setDraft] = useState<{ revision: string; value: number }>();
const active = data && draft?.revision === data.revision ? draft.value : data?.masterMinor;
const money = operationMoney(data?.currency ?? "EUR");
const shadow = useScrollShadow<HTMLUListElement>();
const command = useWidgetCommand(action);
const range = data?.editRange;
const editable = !!action && !!range && nonnegativeInteger(active) && nonnegativeInteger(range.minimum) &&
nonnegativeInteger(range.maximum) && nonnegativeInteger(range.step) && range.step > 0 && range.maximum > range.minimum &&
active >= range.minimum && active <= range.maximum;
const changed = active !== data?.masterMinor;
const atTop = editable ? range.maximum : data?.masterMinor;
const scale = (data?.derived ?? []).reduce((max, rule) => Math.max(max, deriveRate(atTop, rule) ?? 0), Math.max(1, atTop ?? 0));
const saving = command.status === "saving";
return <WidgetCard size="medium" icon={<ChartNoAxesGantt />} title="Room Rate Tiers" description={data && `${data.plan} · ${data.stayDate}`}
className={`${shared.mediumCard} ${shared.stableCard} ${styles.card}`}>
{data ? <div className={`${shared.stack} ${shared.fillStack}`}>
<div className={styles.base}>
<div className={styles.baseLabel}><span className={changed ? styles.draft : undefined}>{changed ? "Draft" : "Base rate"}</span><span>/ night</span></div>
<strong className={styles.baseAmount}>{nonnegativeInteger(active) ? <SlotText value={active} format={money} /> : money(active)}</strong>
</div>
{editable && range && <Slider className={styles.slider} label="Preview base rate" min={range.minimum} max={range.maximum} step={range.step} thumbSize="sm" disabled={saving}
value={active} format={money} showValue={false} onValueChange={value => { setDraft({ revision: data.revision, value }); command.reset(); }} />}
{data.derived.length > 0 ? <ul ref={shadow} tabIndex={0} aria-label="Derived nightly rates" data-widget-list className={`${shared.list} ${shared.fillList} ${styles.list}`}>
{data.derived.map(rule => {
const result = deriveRate(active, rule);
const delta = result !== null && nonnegativeInteger(active) ? result - active : null;
return <li key={rule.id} className={styles.tier}>
<div className={styles.tierHeading}><strong className={styles.tierName}>{rule.label}</strong><span className={styles.tierAmount}>{money(result)}</span></div>
{result !== null && delta !== null && nonnegativeInteger(active) && <div className={styles.graph}>
<div className={styles.rail} data-rate={delta < 0 ? "lower" : delta > 0 ? "higher" : undefined} aria-hidden="true">
<Progress value={result} max={scale} animateOnMount />
<span className={styles.marker} style={{ insetInlineStart: `clamp(0px, ${active / scale * 100}%, calc(100% - 1px))` }} />
</div>
<span className={styles.delta}>{delta === 0 ? "At base" : <>{delta < 0 ? "−" : "+"}{money(Math.abs(delta))}<span className={styles.srOnly}> vs base</span></>}</span>
</div>}
</li>;
})}
</ul> : <p className={shared.muted}>No linked tiers.</p>}
{editable && <div className={styles.footer}><div className={styles.actions}>
<Button type="button" size="xs" disabled={!changed || saving || command.status === "saved"} onClick={() => {
const input = priceLadderUpdateSchema.safeParse({ revision: data.revision, rateMinor: active });
if (input.success) void command.run(input.data);
}}>Apply base rate</Button>
<Button type="button" size="xs" variant="ghost" disabled={!changed || saving} onClick={() => { setDraft(undefined); command.reset(); }}>Reset draft</Button>
</div><div className={styles.message}>
{command.status === "error" && <FormError>Couldn’t apply the rate.</FormError>}
{command.status === "saved" && <p role="status">Rate change submitted.</p>}
</div></div>}
</div> : <p className={shared.muted}>Rates unavailable.</p>}
</WidgetCard>;
}
lucide-reactmotionreactreact-domzod