Collection
Business / Real Estate · v0.2.0Validated
Browse upcoming or ongoing showings, check capacity and open arrival details.
Property Showing Schedule · Preview
Loading widget…
Preparing source code…
Idle
Business / Real Estate · v0.2.0Validated
Browse upcoming or ongoing showings, check capacity and open arrival details.
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 { OpenHouseWidget } from "@lumo/widgets/catalog/real-estate/open-house";
export default function Example() {
return <OpenHouseWidget />;
}Props for integrating the React component in your app.
showingsreadonly OpenHouseShowing[] | null (optional)asOfnumber (optional)indexnumber (optional){
"asOf": 1795616400000,
"showings": [
{
"id": "nantes-1",
"home": "Maple Courtyard",
"address": "15 rue du Moulin, Nantes",
"startsAt": 1795623600000,
"endsAt": 1795629000000,
"timeZone": "Europe/Paris",
"rsvps": 12,
"capacity": 18,
"arrivalNote": "Meet inside the courtyard gate."
}
]
}"use client";
import { useAnimationInterval, useHorizontalSwipe } from "@lumo/hooks";
import { AnimatedNumber, Avatar, Badge, WidgetDialog, WidgetHeader, WidgetPagination } from "@lumo/ui";
import { CalendarDays, MapPin } from "lucide-react";
import { useMemo, useRef, useState } from "react";
import { demoAvatarSrc } from "../../shared/avatar-library";
import { nonnegativeInteger, validTimestamp } from "../../shared/operation-snapshot";
import { PropertyTile } from "./PropertyTile";
import { demoShowings } from "./open-house.constants";
import type { OpenHouseShowing, OpenHouseWidgetProps } from "./open-house.types";
import { usePropertyClientReady } from "./use-property-client-ready";
import styles from "./real-estate-layout.module.css";
export type { OpenHouseShowing, OpenHouseWidgetProps } from "./open-house.types";
function formatShowingDate(showing: OpenHouseShowing, timestamp = showing.startsAt) {
const options: Intl.DateTimeFormatOptions = { weekday: "short", month: "short", day: "numeric",
hour: "numeric", minute: "2-digit", timeZoneName: "short" };
try { return new Intl.DateTimeFormat("en-US", { ...options, timeZone: showing.timeZone }).format(timestamp); }
catch { return new Intl.DateTimeFormat("en-US", { ...options, timeZone: "UTC" }).format(timestamp); }
}
function endOf(showing: OpenHouseShowing) {
return validTimestamp(showing.endsAt) && showing.endsAt > showing.startsAt ? showing.endsAt : null;
}
export function OpenHouseWidget({ index, showings, asOf }: OpenHouseWidgetProps = {}) {
const [selected, setSelected] = useState<string>();
const [detailId, setDetailId] = useState<string>();
const [clock, setClock] = useState(Date.now);
const [demo] = useState(() => demoShowings(clock));
const trigger = useRef<HTMLButtonElement>(null);
const clockReady = usePropertyClientReady();
const now = asOf === undefined ? clock : validTimestamp(asOf) ? asOf : null;
const source = showings === undefined ? demo : showings;
const future = useMemo(() => {
const ids = new Set<string>();
return (source ?? []).filter(showing => {
if (!showing.id || ids.has(showing.id) || showing.status === "cancelled" || !validTimestamp(showing.startsAt) ||
(now !== null && (endOf(showing) ?? showing.startsAt) <= now)) return false;
ids.add(showing.id);
return true;
}).sort((a, b) => a.startsAt - b.startsAt);
}, [source, now]);
const page = Math.max(0, future.findIndex(({ id }) => id === selected));
const ready = asOf !== undefined || clockReady;
const showing = ready ? future[page] : undefined;
const detail = ready ? future.find(({ id }) => id === detailId) : undefined;
if (detailId && ready && !detail) setDetailId(undefined);
const select = (next: number) => { if (future[next]) setSelected(future[next].id); };
const swipe = useHorizontalSwipe(direction => select(page + (direction === "left" ? 1 : -1)), future.length > 1);
useAnimationInterval(() => {
if (!showing) return;
const timestamp = Date.now();
const nextBoundary = endOf(showing);
setClock(previous => Math.ceil((showing.startsAt - previous) / 60_000) !== Math.ceil((showing.startsAt - timestamp) / 60_000)
|| (timestamp >= showing.startsAt && previous < showing.startsAt)
|| (nextBoundary !== null && timestamp >= nextBoundary && previous < nextBoundary) ? timestamp : previous);
}, asOf === undefined && future.length ? 1000 : null);
const minutes = showing && now !== null ? Math.max(0, Math.ceil((showing.startsAt - now) / 60_000)) : null;
const days = minutes === null ? 0 : Math.floor(minutes / 1440);
const time = minutes === null ? null : minutes >= 1440
? { amount: days, unit: days === 1 ? "day" : "days", extra: `${Math.floor(minutes % 1440 / 60)} h` }
: minutes >= 60 ? { amount: Math.floor(minutes / 60), unit: "h", extra: `${minutes % 60} min` } : { amount: minutes, unit: "min" };
const reservable = showing && nonnegativeInteger(showing.capacity) && showing.capacity > 0 && nonnegativeInteger(showing.rsvps);
const seats = reservable ? Math.max(0, showing.capacity! - showing.rsvps) : undefined;
const surface = <PropertyTile index={index} label="Open house" className={styles.openHouse}>
<WidgetHeader icon={<CalendarDays />} title="Open House" description={showing?.home} />
{showing ? <div {...swipe} data-studio-swipe-ignore className={styles.showingSchedule}>
<div className={`${styles.reading} ${styles.showingTime}`}>
{minutes === 0 && now !== null && now >= showing.startsAt ? <Badge size="sm" tone="success">Open now</Badge> :
time ? <><AnimatedNumber className={styles.showingNumber} value={time.amount} blur={false} /><small>{time.unit}{time.extra && ` · ${time.extra}`}</small></>
: <span className={styles.showingDetails}>Countdown unavailable</span>}
</div>
<button ref={trigger} type="button" aria-label={`Show address for ${showing.home}`}
aria-haspopup="dialog" className={`${styles.showingDetails} ${styles.showingAddress}`} onClick={() => setDetailId(showing.id)}>
<strong>{formatShowingDate(showing)}</strong>
<span className={styles.showingLocation}><MapPin size={12} aria-hidden="true" /><span>{showing.address}</span></span>
</button>
<div className={styles.showingFooter}>
<div className={styles.faces}>{showing.guests?.slice(0, 3).map((guest, i) =>
<span className={styles.face} key={`${guest}-${i}`}><Avatar size="sm" name={guest}
src={showings === undefined ? demoAvatarSrc(guest) : undefined} /></span>)}</div>
<p className={styles.rsvps}>{seats === 0 ? "At capacity" : seats !== undefined ? `${seats} places left`
: nonnegativeInteger(showing.rsvps) ? `${showing.rsvps} going` : "RSVPs unavailable"}</p>
</div>
<WidgetPagination label="Upcoming showings" pageLabel="Showing" pageLabels={future.map(item => item.home)}
count={future.length} page={page} onChange={select} />
</div> : <p className={styles.showingDetails}>{source === null ? "Showing data unavailable" : ready ? "No upcoming showings" : "Upcoming showings"}</p>}
</PropertyTile>;
const end = detail ? endOf(detail) : null;
return <WidgetDialog className={styles.propertyDialog} surface={surface} title={detail?.home ?? "Open House"}
placement="bottom" dragFromScrollStart contentLabel="Showing details" closeLabel="Close showing details"
open={Boolean(detail)} returnFocusRef={trigger} onClose={() => setDetailId(undefined)}>
{detail && <div className={styles.propertyDetail}>
<p>{detail.address}</p>
<time dateTime={new Date(detail.startsAt).toISOString()}>{formatShowingDate(detail)}</time>
{end !== null && <p>Closes <time dateTime={new Date(end).toISOString()}>{formatShowingDate(detail, end)}</time></p>}
{nonnegativeInteger(detail.rsvps) && <p>{detail.rsvps}{nonnegativeInteger(detail.capacity) ? ` / ${detail.capacity}` : ""} confirmed</p>}
{detail.arrivalNote && <p>{detail.arrivalNote}</p>}
</div>}
</WidgetDialog>;
}
clsxlucide-reactmotionreactreact-domtailwind-merge/avatars/01.webp/avatars/02.webp/avatars/04.webp/avatars/06.webp/avatars/07.webp/avatars/08.webp/avatars/10.webp/avatars/16.webp/avatars/18.webp/avatars/19.webp/avatars/20.webp/avatars/23.webp/avatars/24.webp/avatars/25.webp/avatars/26.webp/avatars/27.webp/avatars/28.webp/avatars/31.webp/avatars/33.webp