Collection
Business / Restaurant · v0.3.1Validated
See which dishes are running low, check their remaining portions, and pause or resume sales during service.
Service Stock · Preview
Loading widget…
Preparing source code…
Idle
Business / Restaurant · v0.3.1Validated
See which dishes are running low, check their remaining portions, and pause or resume sales during service.
Loading widget…
Preparing source code…
Load the Lumo theme once in your app entry point. The example uses the local Lumo workspace packages.
"use client";
import "@lumo/tokens/tokens.css";
import { useState } from "react";
import { EightySixWidget, type EightySixItem, type EightySixAvailabilityChange } from "@lumo/widgets/catalog/restaurant/eighty-six";
type StockBoardProps = {
initialItems: readonly EightySixItem[];
saveAvailability: (change: EightySixAvailabilityChange) => Promise<readonly EightySixItem[]>;
};
export default function StockBoard({ initialItems, saveAvailability }: StockBoardProps) {
const [items, setItems] = useState(initialItems);
return (
<EightySixWidget
items={items}
theme="ambient"
digits="dots"
onAvailabilityChange={async (change) => setItems(await saveAvailability(change))}
/>
);
}import "@lumo/tokens/tokens.css";
import { ServiceStockDemo } from "./ServiceStockDemo";
export default function Example() {
return <ServiceStockDemo />;
}Props for integrating the React component in your app.
itemsreadonly EightySixItem[]?status"ready" | "loading" | "error"theme"lumo" | "ambient"digits"plain" | "dots"onAvailabilityChange(change: EightySixAvailabilityChange) => void | Promise<void>simulateboolean (optional)[
{
"id": "gnocchi",
"name": "Potato gnocchi",
"station": "Pasta",
"remaining": 6,
"target": 24,
"lowAt": 8,
"available": true
},
{
"id": "sea-bass",
"name": "Sea bass",
"station": "Sauté",
"remaining": 0,
"target": 18,
"lowAt": 4,
"available": false
}
]"use client";
import { Fragment, useId, useRef, useState } from "react";
import { CookingPot, ListFilter, Pause, Play, X } from "lucide-react";
import { AnimatedNumber, Button, DotMatrixReading, SlotText, WidgetCard, WidgetDialog, WidgetPagination } from "@lumo/ui";
import { criticalPortions } from "./eighty-six.constants";
import { PortionGrid } from "./PortionGrid";
import { StockAlertsList } from "./StockAlertsList";
import { useEightySixBoard } from "./use-eighty-six-board";
import type { EightySixItem, EightySixWidgetProps } from "./eighty-six.types";
import styles from "./eighty-six.module.css";
export type { EightySixAvailabilityChange, EightySixItem, EightySixWidgetProps } from "./eighty-six.types";
const title = "Service Stock";
export function EightySixWidget(props: EightySixWidgetProps) {
const { status = "ready", theme = "lumo", digits = "plain" } = props;
const board = useEightySixBoard(props);
const item = board.selected;
const [alertsOpen, setAlertsOpen] = useState(false);
const alertsId = useId();
const alertsTrigger = useRef<HTMLButtonElement>(null);
const canOpenAlerts = status === "ready" && Boolean(item);
const reviewCount = board.low.length + board.out.length;
if (alertsOpen && !canOpenAlerts) setAlertsOpen(false);
const surface = (
<WidgetCard size="small" className={styles.card} title={title} label={title} icon={<CookingPot />}
description={status === "ready" && reviewCount > 0 ? `${reviewCount} ${reviewCount === 1 ? "dish" : "dishes"} to review` : undefined}
action={canOpenAlerts && (
<Button ref={alertsTrigger} type="button" size="xs" variant="secondary" className={styles.alertsTrigger}
aria-label="Browse stock alerts" aria-haspopup="dialog" aria-expanded={alertsOpen}
aria-controls={alertsOpen ? alertsId : undefined} onClick={() => setAlertsOpen(true)}>
<ListFilter size={15} aria-hidden="true" />
</Button>
)}>
<div className={styles.board}>
{status !== "ready" || !item ? (
<p className={styles.empty} role={status === "error" ? "alert" : "status"}>
{status === "loading" ? "Loading stock…" : status === "error" ? "Stock unavailable" : "No stock alerts"}
</p>
) : (
<>
<div className={styles.detail} data-critical={!item.available || item.remaining <= criticalPortions || undefined}>
<div className={styles.dish}>
<h4 aria-label={item.name}><DishName name={item.name} /></h4>
<p className={styles.context}>
{item.station && <span>{item.station}</span>}
<span className={styles.stockStatus}>{item.available ? "Running low" : "Sales paused"}</span>
</p>
</div>
<div className={styles.stockPanel} data-wide-reading={item.remaining >= 1000 || undefined}
data-dense-reading={item.remaining >= 100_000 || undefined}>
<div className={styles.reading} role="img" aria-label={`${item.remaining} of ${item.target} portions remaining`}>
{digits === "dots"
? <span className={styles.dotReading}><DotMatrixReading text={String(item.remaining)} /></span>
: <AnimatedNumber value={item.remaining} className={styles.remaining} blur={false} />}
<span className={styles.unit}>portions left</span>
</div>
<PortionGrid item={item} />
</div>
</div>
<div className={styles.footer}>
{board.failedId === item.id && board.canChange &&
<p className={styles.error} role="alert">Update failed. Try again.</p>}
{board.canChange && <StockAction key={`${item.id}:${item.available}`} item={item}
pending={board.pendingId === item.id} busy={board.pendingId !== undefined}
onChange={() => void board.changeAvailability(item)} />}
{board.pageCount > 1 && <WidgetPagination className={styles.stockDots} label="Stock alert pages" pageLabel="Dish"
page={board.page} count={board.pageCount} onChange={board.selectPage} />}
</div>
</>
)}
</div>
</WidgetCard>
);
return (
<WidgetDialog id={alertsId} title="Stock queue" label="Stock alerts" closeLabel="Close stock alerts" contentLabel="Alert list"
open={alertsOpen} onClose={() => setAlertsOpen(false)} returnFocusRef={alertsTrigger}
className={theme === "ambient" ? `${styles.frame} ${styles.ambient}` : styles.frame} surface={surface}>
{item && <StockAlertsList low={board.low} out={board.out} selectedId={item.id}
onSelect={(id) => { board.select(id); setAlertsOpen(false); }} />}
</WidgetDialog>
);
}
function DishName({ name }: { name: string }) {
const words = name.split(/\s+/);
if (words.some(word => word.length > 14)) return name;
return <span aria-hidden="true">{words.map((word, index) => (
<Fragment key={index}>{index > 0 && " "}<SlotText value={word} duration={.26} stagger={.012} spins={0} /></Fragment>
))}</span>;
}
function StockAction({ item, pending, busy, onChange }: {
item: EightySixItem;
pending: boolean;
busy: boolean;
onChange: () => void;
}) {
const [confirming, setConfirming] = useState(false);
const action = useRef<HTMLButtonElement>(null);
const confirm = confirming && item.available;
const label = item.available ? (confirm ? "Confirm pause" : "Pause sales") : "Resume sales";
function cancel() {
setConfirming(false);
action.current?.focus({ preventScroll: true });
}
return (
<div className={styles.actionRow} onKeyDown={(event) => { if (event.key === "Escape" && confirm) cancel(); }}>
<Button ref={action} type="button" size="xs" variant={confirm ? "danger" : "secondary"} className={styles.action}
disabled={busy && !pending} loading={pending} aria-label={`${label} for ${item.name}`}
onClick={() => {
if (item.available && !confirm) { setConfirming(true); return; }
setConfirming(false);
onChange();
}}>
{item.available ? <Pause size={13} aria-hidden="true" fill="currentColor" /> : <Play size={13} aria-hidden="true" fill="currentColor" />}
{label}
</Button>
{confirm && <Button type="button" size="xs" variant="secondary" className={styles.cancel}
aria-label="Cancel pause" onClick={cancel}><X size={13} aria-hidden="true" /></Button>}
</div>
);
}
lucide-reactmotionreactreact-dom