@jcsoftdev/ui 0.7.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +60 -0
- package/README.md +4 -0
- package/dist/atoms/elapsed-time/elapsed-time.d.ts +29 -0
- package/dist/atoms/elapsed-time/elapsed-time.js +65 -0
- package/dist/atoms/elapsed-time/index.d.ts +2 -0
- package/dist/atoms/elapsed-time/index.js +9 -0
- package/dist/atoms/elapsed-time/model.d.ts +17 -0
- package/dist/atoms/elapsed-time/model.js +37 -0
- package/dist/atoms/elapsed-time/ticker.d.ts +5 -0
- package/dist/atoms/elapsed-time/ticker.js +37 -0
- package/dist/atoms/index.d.ts +2 -0
- package/dist/atoms/index.js +2 -0
- package/dist/atoms/table-glyph/index.d.ts +2 -0
- package/dist/atoms/table-glyph/index.js +14 -0
- package/dist/atoms/table-glyph/layout.d.ts +38 -0
- package/dist/atoms/table-glyph/layout.js +152 -0
- package/dist/atoms/table-glyph/table-glyph.d.ts +32 -0
- package/dist/atoms/table-glyph/table-glyph.js +131 -0
- package/dist/containers/floor-plan/edit-model.d.ts +33 -0
- package/dist/containers/floor-plan/edit-model.js +82 -0
- package/dist/containers/floor-plan/floor-plan.d.ts +83 -0
- package/dist/containers/floor-plan/floor-plan.js +278 -0
- package/dist/containers/floor-plan/index.d.ts +3 -0
- package/dist/containers/floor-plan/index.js +21 -0
- package/dist/containers/floor-plan/model.d.ts +36 -0
- package/dist/containers/floor-plan/model.js +52 -0
- package/dist/containers/floor-plan/use-floor-plan-edit.d.ts +26 -0
- package/dist/containers/floor-plan/use-floor-plan-edit.js +97 -0
- package/dist/containers/index.d.ts +2 -0
- package/dist/containers/index.js +2 -0
- package/dist/containers/order-ticket/index.d.ts +2 -0
- package/dist/containers/order-ticket/index.js +16 -0
- package/dist/containers/order-ticket/model.d.ts +18 -0
- package/dist/containers/order-ticket/model.js +36 -0
- package/dist/containers/order-ticket/order-ticket.d.ts +34 -0
- package/dist/containers/order-ticket/order-ticket.js +390 -0
- package/dist/glass/crystal-map.d.ts +3 -1
- package/dist/glass/crystal-map.js +13 -2
- package/dist/i18n/strings.d.ts +104 -0
- package/dist/i18n/strings.js +62 -0
- package/dist/icons/alarm-clock.d.ts +2 -0
- package/dist/icons/alarm-clock.js +15 -0
- package/dist/icons/hourglass.d.ts +2 -0
- package/dist/icons/hourglass.js +13 -0
- package/dist/icons/index.d.ts +2 -0
- package/dist/icons/index.js +4 -0
- package/icons/svg/alarm-clock.svg +8 -0
- package/icons/svg/hourglass.svg +6 -0
- package/package.json +2 -2
- package/src/atoms/elapsed-time/elapsed-time.tsx +101 -0
- package/src/atoms/elapsed-time/index.ts +6 -0
- package/src/atoms/elapsed-time/model.ts +54 -0
- package/src/atoms/elapsed-time/ticker.ts +39 -0
- package/src/atoms/index.ts +2 -0
- package/src/atoms/table-glyph/index.ts +14 -0
- package/src/atoms/table-glyph/layout.ts +187 -0
- package/src/atoms/table-glyph/table-glyph.tsx +161 -0
- package/src/containers/floor-plan/edit-model.ts +115 -0
- package/src/containers/floor-plan/floor-plan.tsx +393 -0
- package/src/containers/floor-plan/index.ts +20 -0
- package/src/containers/floor-plan/model.ts +81 -0
- package/src/containers/floor-plan/use-floor-plan-edit.ts +135 -0
- package/src/containers/index.ts +2 -0
- package/src/containers/order-ticket/index.ts +15 -0
- package/src/containers/order-ticket/model.ts +55 -0
- package/src/containers/order-ticket/order-ticket.tsx +463 -0
- package/src/glass/crystal-map.ts +21 -3
- package/src/i18n/strings.ts +104 -0
- package/src/icons/alarm-clock.tsx +16 -0
- package/src/icons/hourglass.tsx +14 -0
- package/src/icons/index.ts +2 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { type PointerEvent, type RefObject, useRef, useState } from "react";
|
|
2
|
+
import {
|
|
3
|
+
type EditBounds,
|
|
4
|
+
editKey,
|
|
5
|
+
moveBox,
|
|
6
|
+
type ResizeHandle,
|
|
7
|
+
resizeBox,
|
|
8
|
+
sameBox,
|
|
9
|
+
} from "./edit-model.js";
|
|
10
|
+
import type { Box, FloorPlanBox } from "./model.js";
|
|
11
|
+
|
|
12
|
+
type DragMode = "move" | ResizeHandle;
|
|
13
|
+
|
|
14
|
+
interface Drag {
|
|
15
|
+
id: string;
|
|
16
|
+
mode: DragMode;
|
|
17
|
+
startX: number;
|
|
18
|
+
startY: number;
|
|
19
|
+
origin: Box;
|
|
20
|
+
unit: number;
|
|
21
|
+
moved: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const DRAG_THRESHOLD_PX = 3;
|
|
25
|
+
|
|
26
|
+
function capturePointer(element: HTMLElement, pointerId: number): boolean {
|
|
27
|
+
try {
|
|
28
|
+
element.setPointerCapture(pointerId);
|
|
29
|
+
return true;
|
|
30
|
+
} catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const pick = ({ x, y, width, height }: Box): Box => ({ x, y, width, height });
|
|
36
|
+
|
|
37
|
+
interface Options<I extends FloorPlanBox, L extends FloorPlanBox> {
|
|
38
|
+
enabled: boolean;
|
|
39
|
+
items: readonly I[];
|
|
40
|
+
landmarks: readonly L[];
|
|
41
|
+
bounds: EditBounds;
|
|
42
|
+
canvasRef: RefObject<HTMLElement | null>;
|
|
43
|
+
onChange?: ((items: I[], landmarks: L[]) => void) | undefined;
|
|
44
|
+
onSelect?: ((id: string) => void) | undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Drag, resize, rotate and keyboard edits of floor plan boxes; commits only on release, never mid-drag. */
|
|
48
|
+
export function useFloorPlanEdit<I extends FloorPlanBox, L extends FloorPlanBox>({
|
|
49
|
+
enabled,
|
|
50
|
+
items,
|
|
51
|
+
landmarks,
|
|
52
|
+
bounds,
|
|
53
|
+
canvasRef,
|
|
54
|
+
onChange,
|
|
55
|
+
onSelect,
|
|
56
|
+
}: Options<I, L>) {
|
|
57
|
+
const [draft, setDraft] = useState<{ id: string; box: Box } | null>(null);
|
|
58
|
+
const drag = useRef<Drag | null>(null);
|
|
59
|
+
|
|
60
|
+
const view = <T extends FloorPlanBox>(entry: T): T =>
|
|
61
|
+
draft?.id === entry.id ? { ...entry, ...draft.box } : entry;
|
|
62
|
+
|
|
63
|
+
const commit = (id: string, box: Box) => {
|
|
64
|
+
const current = [...items, ...landmarks].find((entry) => entry.id === id);
|
|
65
|
+
if (!current || sameBox(pick(current), box)) return;
|
|
66
|
+
const apply = <T extends FloorPlanBox>(list: readonly T[]): T[] =>
|
|
67
|
+
list.map((entry) => (entry.id === id ? { ...entry, ...box } : entry));
|
|
68
|
+
onChange?.(apply(items), apply(landmarks));
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const dragProps = (entry: FloorPlanBox, mode: DragMode) => ({
|
|
72
|
+
onPointerDown: (event: PointerEvent<HTMLElement>) => {
|
|
73
|
+
if (!enabled || event.button !== 0) return;
|
|
74
|
+
const canvas = canvasRef.current;
|
|
75
|
+
if (!canvas) return;
|
|
76
|
+
event.stopPropagation();
|
|
77
|
+
capturePointer(event.currentTarget, event.pointerId);
|
|
78
|
+
drag.current = {
|
|
79
|
+
id: entry.id,
|
|
80
|
+
mode,
|
|
81
|
+
startX: event.clientX,
|
|
82
|
+
startY: event.clientY,
|
|
83
|
+
origin: pick(entry),
|
|
84
|
+
unit: canvas.getBoundingClientRect().width / bounds.width,
|
|
85
|
+
moved: false,
|
|
86
|
+
};
|
|
87
|
+
onSelect?.(entry.id);
|
|
88
|
+
},
|
|
89
|
+
onPointerMove: (event: PointerEvent<HTMLElement>) => {
|
|
90
|
+
const current = drag.current;
|
|
91
|
+
if (!current || current.id !== entry.id) return;
|
|
92
|
+
const px = Math.hypot(event.clientX - current.startX, event.clientY - current.startY);
|
|
93
|
+
if (!current.moved && px < DRAG_THRESHOLD_PX) return;
|
|
94
|
+
current.moved = true;
|
|
95
|
+
const dx = (event.clientX - current.startX) / current.unit;
|
|
96
|
+
const dy = (event.clientY - current.startY) / current.unit;
|
|
97
|
+
const box =
|
|
98
|
+
current.mode === "move"
|
|
99
|
+
? moveBox(current.origin, dx, dy, bounds)
|
|
100
|
+
: resizeBox(current.origin, current.mode, dx, dy, bounds);
|
|
101
|
+
setDraft((previous) =>
|
|
102
|
+
previous && sameBox(previous.box, box) ? previous : { id: entry.id, box },
|
|
103
|
+
);
|
|
104
|
+
},
|
|
105
|
+
onPointerUp: (event: PointerEvent<HTMLElement>) => {
|
|
106
|
+
const current = drag.current;
|
|
107
|
+
if (!current || current.id !== entry.id) return;
|
|
108
|
+
drag.current = null;
|
|
109
|
+
if (event.currentTarget.hasPointerCapture?.(event.pointerId)) {
|
|
110
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
111
|
+
}
|
|
112
|
+
if (current.moved && draft) commit(entry.id, draft.box);
|
|
113
|
+
setDraft(null);
|
|
114
|
+
},
|
|
115
|
+
onPointerCancel: () => {
|
|
116
|
+
drag.current = null;
|
|
117
|
+
setDraft(null);
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const onKeyDown = (entry: FloorPlanBox) => (event: React.KeyboardEvent<HTMLElement>) => {
|
|
122
|
+
if (!enabled) return;
|
|
123
|
+
const result = editKey(pick(entry), event, bounds);
|
|
124
|
+
if (!result) return;
|
|
125
|
+
event.preventDefault();
|
|
126
|
+
commit(entry.id, result.box);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const rotate = (entry: FloorPlanBox) => {
|
|
130
|
+
const result = editKey(pick(entry), { key: "r", altKey: false, shiftKey: false }, bounds);
|
|
131
|
+
if (result) commit(entry.id, result.box);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
return { view, dragProps, onKeyDown, rotate };
|
|
135
|
+
}
|
package/src/containers/index.ts
CHANGED
|
@@ -17,6 +17,7 @@ export * from "./facts/index.js";
|
|
|
17
17
|
export * from "./feed/index.js";
|
|
18
18
|
export * from "./file-tree/index.js";
|
|
19
19
|
export * from "./filter-bar/index.js";
|
|
20
|
+
export * from "./floor-plan/index.js";
|
|
20
21
|
export * from "./generic-row/index.js";
|
|
21
22
|
export * from "./grid/index.js";
|
|
22
23
|
export * from "./hbars/index.js";
|
|
@@ -27,6 +28,7 @@ export * from "./kpi/index.js";
|
|
|
27
28
|
export * from "./kpi-group/index.js";
|
|
28
29
|
export * from "./list-detail/index.js";
|
|
29
30
|
export * from "./note/index.js";
|
|
31
|
+
export * from "./order-ticket/index.js";
|
|
30
32
|
export * from "./page/index.js";
|
|
31
33
|
export * from "./page-header/index.js";
|
|
32
34
|
export * from "./pagination/index.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export {
|
|
2
|
+
type OrderTicketLine,
|
|
3
|
+
type OrderTicketLineStatus,
|
|
4
|
+
type OrderTicketState,
|
|
5
|
+
orderTicketState,
|
|
6
|
+
splitTicketLines,
|
|
7
|
+
ticketLineCost,
|
|
8
|
+
warnLeadSeconds,
|
|
9
|
+
} from "./model.js";
|
|
10
|
+
export {
|
|
11
|
+
OrderTicket,
|
|
12
|
+
type OrderTicketChannel,
|
|
13
|
+
type OrderTicketPart,
|
|
14
|
+
type OrderTicketProps,
|
|
15
|
+
} from "./order-ticket.js";
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export type OrderTicketState = "ok" | "warn" | "late";
|
|
2
|
+
|
|
3
|
+
export type OrderTicketLineStatus = "pending" | "in-progress" | "done";
|
|
4
|
+
|
|
5
|
+
export interface OrderTicketLine {
|
|
6
|
+
id: string;
|
|
7
|
+
qty: number;
|
|
8
|
+
name: string;
|
|
9
|
+
modifiers?: readonly string[] | undefined;
|
|
10
|
+
note?: string | undefined;
|
|
11
|
+
allergy?: string | undefined;
|
|
12
|
+
status?: OrderTicketLineStatus | undefined;
|
|
13
|
+
onToggle?: (() => void) | undefined;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const MIN_WARN_LEAD_SECONDS = 120;
|
|
17
|
+
const WARN_LEAD_SHARE = 0.25;
|
|
18
|
+
|
|
19
|
+
export function warnLeadSeconds(targetMinutes: number): number {
|
|
20
|
+
return Math.max(MIN_WARN_LEAD_SECONDS, targetMinutes * 60 * WARN_LEAD_SHARE);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function orderTicketState(elapsedSeconds: number, targetMinutes: number): OrderTicketState {
|
|
24
|
+
const target = targetMinutes * 60;
|
|
25
|
+
if (elapsedSeconds > target) return "late";
|
|
26
|
+
if (elapsedSeconds >= target - warnLeadSeconds(targetMinutes)) return "warn";
|
|
27
|
+
return "ok";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type LineShape = Pick<OrderTicketLine, "modifiers" | "note" | "allergy">;
|
|
31
|
+
|
|
32
|
+
export function ticketLineCost(line: LineShape): number {
|
|
33
|
+
return 1 + (line.modifiers?.length ? 0.6 : 0) + (line.note ? 0.9 : 0) + (line.allergy ? 0.9 : 0);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function splitTicketLines<Line extends LineShape>(
|
|
37
|
+
lines: readonly Line[],
|
|
38
|
+
budget: number,
|
|
39
|
+
cost: (line: Line) => number = ticketLineCost,
|
|
40
|
+
): Line[][] {
|
|
41
|
+
const parts: Line[][] = [];
|
|
42
|
+
let used = 0;
|
|
43
|
+
for (const line of lines) {
|
|
44
|
+
const weight = cost(line);
|
|
45
|
+
const current = parts.at(-1);
|
|
46
|
+
if (current && used + weight <= budget) {
|
|
47
|
+
current.push(line);
|
|
48
|
+
used += weight;
|
|
49
|
+
} else {
|
|
50
|
+
parts.push([line]);
|
|
51
|
+
used = weight;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return parts;
|
|
55
|
+
}
|
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { type ComponentPropsWithoutRef, type ReactNode, useId, useSyncExternalStore } from "react";
|
|
4
|
+
import { Button } from "../../atoms/button/button.js";
|
|
5
|
+
import { Chip } from "../../atoms/chip/chip.js";
|
|
6
|
+
import { ElapsedTime } from "../../atoms/elapsed-time/elapsed-time.js";
|
|
7
|
+
import { readElapsed } from "../../atoms/elapsed-time/model.js";
|
|
8
|
+
import { getTickerSnapshot, subscribeTicker } from "../../atoms/elapsed-time/ticker.js";
|
|
9
|
+
import { Progress, type ProgressBuiltinTone } from "../../atoms/progress/progress.js";
|
|
10
|
+
import { type UiStrings, useUiStrings } from "../../i18n/index.js";
|
|
11
|
+
import {
|
|
12
|
+
AlarmClock,
|
|
13
|
+
CircleAlert,
|
|
14
|
+
CircleCheck,
|
|
15
|
+
Hourglass,
|
|
16
|
+
Play,
|
|
17
|
+
RotateCcw,
|
|
18
|
+
Square,
|
|
19
|
+
TriangleAlert,
|
|
20
|
+
} from "../../icons/index.js";
|
|
21
|
+
import type { ClassNames } from "../../utils/class-names.js";
|
|
22
|
+
import { cn } from "../../utils/cn.js";
|
|
23
|
+
import { usePrefersReducedMotion } from "../../utils/reduced-motion.js";
|
|
24
|
+
import {
|
|
25
|
+
type OrderTicketLine,
|
|
26
|
+
type OrderTicketLineStatus,
|
|
27
|
+
type OrderTicketState,
|
|
28
|
+
orderTicketState,
|
|
29
|
+
} from "./model.js";
|
|
30
|
+
|
|
31
|
+
export type OrderTicketPart =
|
|
32
|
+
| "root"
|
|
33
|
+
| "paper"
|
|
34
|
+
| "band"
|
|
35
|
+
| "title"
|
|
36
|
+
| "meta"
|
|
37
|
+
| "timer"
|
|
38
|
+
| "progress"
|
|
39
|
+
| "lines"
|
|
40
|
+
| "line"
|
|
41
|
+
| "footer";
|
|
42
|
+
|
|
43
|
+
export interface OrderTicketChannel {
|
|
44
|
+
label: string;
|
|
45
|
+
icon?: ReactNode;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface OrderTicketProps
|
|
49
|
+
extends Omit<ComponentPropsWithoutRef<"article">, "title" | "children"> {
|
|
50
|
+
table?: string | undefined;
|
|
51
|
+
number?: string | number | undefined;
|
|
52
|
+
channel?: OrderTicketChannel | undefined;
|
|
53
|
+
guests?: number | undefined;
|
|
54
|
+
server?: string | undefined;
|
|
55
|
+
customer?: string | undefined;
|
|
56
|
+
since: Date | string;
|
|
57
|
+
targetMinutes: number;
|
|
58
|
+
serverOffsetMs?: number | undefined;
|
|
59
|
+
state?: OrderTicketState | undefined;
|
|
60
|
+
lines: readonly OrderTicketLine[];
|
|
61
|
+
partIndex?: number | undefined;
|
|
62
|
+
partCount?: number | undefined;
|
|
63
|
+
recovered?: boolean | undefined;
|
|
64
|
+
chip?: ReactNode;
|
|
65
|
+
readOnly?: boolean | undefined;
|
|
66
|
+
onStartAll?: ((lines: readonly OrderTicketLine[]) => void) | undefined;
|
|
67
|
+
onReadyAll?: ((lines: readonly OrderTicketLine[]) => void) | undefined;
|
|
68
|
+
actions?: ReactNode;
|
|
69
|
+
hanging?: boolean | undefined;
|
|
70
|
+
headingLevel?: 2 | 3 | 4 | undefined;
|
|
71
|
+
viewTransitionName?: string | undefined;
|
|
72
|
+
classNames?: ClassNames<OrderTicketPart> | undefined;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const progressTone: Record<OrderTicketState, ProgressBuiltinTone> = {
|
|
76
|
+
ok: "accent",
|
|
77
|
+
warn: "warning",
|
|
78
|
+
late: "danger",
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const timerTone: Record<OrderTicketState, string> = {
|
|
82
|
+
ok: "font-normal text-ink",
|
|
83
|
+
warn: "font-normal text-warning",
|
|
84
|
+
late: "font-normal text-current",
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const stateWord: Record<OrderTicketState, keyof UiStrings> = {
|
|
88
|
+
ok: "orderTicketOnTime",
|
|
89
|
+
warn: "orderTicketDueSoon",
|
|
90
|
+
late: "orderTicketLate",
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const lineStateWord: Record<OrderTicketLineStatus, keyof UiStrings> = {
|
|
94
|
+
pending: "orderTicketPending",
|
|
95
|
+
"in-progress": "orderTicketInProgress",
|
|
96
|
+
done: "orderTicketDone",
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const lineStateIcon: Record<OrderTicketLineStatus, ReactNode> = {
|
|
100
|
+
pending: <Square size={18} aria-hidden="true" />,
|
|
101
|
+
"in-progress": <Play size={18} aria-hidden="true" />,
|
|
102
|
+
done: <CircleCheck size={18} aria-hidden="true" />,
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const lineToneClasses: Record<OrderTicketLineStatus, string> = {
|
|
106
|
+
pending: "",
|
|
107
|
+
"in-progress": "bg-accent-soft",
|
|
108
|
+
done: "",
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const lineStateClasses: Record<OrderTicketLineStatus, string> = {
|
|
112
|
+
pending: "text-ink-2",
|
|
113
|
+
"in-progress": "text-accent-ink",
|
|
114
|
+
done: "text-success",
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const lineStateTextClasses: Record<OrderTicketLineStatus, string> = {
|
|
118
|
+
pending: "sr-only",
|
|
119
|
+
"in-progress": "sr-only @[340px]/ticket:not-sr-only",
|
|
120
|
+
done: "sr-only @[340px]/ticket:not-sr-only",
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const pressedOf: Record<OrderTicketLineStatus, boolean | "mixed"> = {
|
|
124
|
+
pending: false,
|
|
125
|
+
"in-progress": "mixed",
|
|
126
|
+
done: true,
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const fill = (template: string, values: Record<string, string | number>) =>
|
|
130
|
+
Object.entries(values).reduce(
|
|
131
|
+
(text, [key, value]) => text.replace(`{${key}}`, String(value)),
|
|
132
|
+
template,
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
const clock = (seconds: number) =>
|
|
136
|
+
`${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")}`;
|
|
137
|
+
|
|
138
|
+
const noteClasses =
|
|
139
|
+
"inline-flex max-w-full items-start gap-1 self-start rounded-chip px-1.5 py-0.5 text-meta font-medium [&_svg]:mt-0.5 [&_svg]:shrink-0";
|
|
140
|
+
|
|
141
|
+
function LineContent({
|
|
142
|
+
line,
|
|
143
|
+
status,
|
|
144
|
+
strings,
|
|
145
|
+
}: {
|
|
146
|
+
line: OrderTicketLine;
|
|
147
|
+
status: OrderTicketLineStatus;
|
|
148
|
+
strings: UiStrings;
|
|
149
|
+
}) {
|
|
150
|
+
const done = status === "done";
|
|
151
|
+
return (
|
|
152
|
+
<>
|
|
153
|
+
<span
|
|
154
|
+
className={cn(
|
|
155
|
+
"text-right text-card-title tabular-nums",
|
|
156
|
+
done && "text-ink-2 line-through decoration-2",
|
|
157
|
+
)}
|
|
158
|
+
>
|
|
159
|
+
{line.qty}
|
|
160
|
+
</span>
|
|
161
|
+
<span className="flex min-w-0 flex-col gap-0.5">
|
|
162
|
+
<span
|
|
163
|
+
className={cn(
|
|
164
|
+
"text-card-title [overflow-wrap:anywhere]",
|
|
165
|
+
done && "text-ink-2 line-through decoration-2",
|
|
166
|
+
)}
|
|
167
|
+
>
|
|
168
|
+
{line.name}
|
|
169
|
+
</span>
|
|
170
|
+
{line.modifiers && line.modifiers.length > 0 && (
|
|
171
|
+
<span className="text-meta text-ink-2 [overflow-wrap:anywhere]">
|
|
172
|
+
{line.modifiers.join(" · ")}
|
|
173
|
+
</span>
|
|
174
|
+
)}
|
|
175
|
+
{line.note && (
|
|
176
|
+
<span
|
|
177
|
+
data-part="note"
|
|
178
|
+
className={cn(noteClasses, "text-ink shadow-[inset_0_0_0_1px_var(--line-strong)]")}
|
|
179
|
+
>
|
|
180
|
+
<TriangleAlert size={14} aria-hidden="true" />
|
|
181
|
+
{fill(strings.orderTicketNote, { note: line.note })}
|
|
182
|
+
</span>
|
|
183
|
+
)}
|
|
184
|
+
{line.allergy && (
|
|
185
|
+
<span
|
|
186
|
+
data-part="allergy"
|
|
187
|
+
className={cn(
|
|
188
|
+
noteClasses,
|
|
189
|
+
"font-semibold text-danger shadow-[inset_0_0_0_1.5px_var(--danger)]",
|
|
190
|
+
)}
|
|
191
|
+
>
|
|
192
|
+
<CircleAlert size={14} aria-hidden="true" />
|
|
193
|
+
{fill(strings.orderTicketAllergy, { allergy: line.allergy })}
|
|
194
|
+
</span>
|
|
195
|
+
)}
|
|
196
|
+
</span>
|
|
197
|
+
<span
|
|
198
|
+
className={cn(
|
|
199
|
+
"inline-flex min-h-[1.4em] items-center justify-end gap-1.5 text-meta font-semibold",
|
|
200
|
+
lineStateClasses[status],
|
|
201
|
+
)}
|
|
202
|
+
>
|
|
203
|
+
<span className={lineStateTextClasses[status]}>{strings[lineStateWord[status]]}</span>
|
|
204
|
+
{lineStateIcon[status]}
|
|
205
|
+
</span>
|
|
206
|
+
</>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function TicketLineRow({
|
|
211
|
+
line,
|
|
212
|
+
readOnly,
|
|
213
|
+
strings,
|
|
214
|
+
className,
|
|
215
|
+
}: {
|
|
216
|
+
line: OrderTicketLine;
|
|
217
|
+
readOnly: boolean;
|
|
218
|
+
strings: UiStrings;
|
|
219
|
+
className: string | undefined;
|
|
220
|
+
}) {
|
|
221
|
+
const status = line.status ?? "pending";
|
|
222
|
+
const rowClasses = cn(
|
|
223
|
+
"grid min-h-[max(var(--touch-target),2rem)] w-full grid-cols-[2.4ch_minmax(0,1fr)_auto] items-start gap-x-2.5 rounded-control px-1.5 py-1 text-left text-ink",
|
|
224
|
+
lineToneClasses[status],
|
|
225
|
+
className,
|
|
226
|
+
);
|
|
227
|
+
const content = <LineContent line={line} status={status} strings={strings} />;
|
|
228
|
+
return (
|
|
229
|
+
<li data-line={line.id} data-status={status}>
|
|
230
|
+
{line.onToggle && !readOnly ? (
|
|
231
|
+
<button
|
|
232
|
+
type="button"
|
|
233
|
+
aria-pressed={pressedOf[status]}
|
|
234
|
+
onClick={line.onToggle}
|
|
235
|
+
className={cn(
|
|
236
|
+
rowClasses,
|
|
237
|
+
"cursor-pointer transition-colors focus-visible:focus-ring motion-reduce:transition-none",
|
|
238
|
+
status !== "in-progress" && "hover:bg-surface-2",
|
|
239
|
+
)}
|
|
240
|
+
>
|
|
241
|
+
{content}
|
|
242
|
+
</button>
|
|
243
|
+
) : (
|
|
244
|
+
<div className={rowClasses}>{content}</div>
|
|
245
|
+
)}
|
|
246
|
+
</li>
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export function OrderTicket({
|
|
251
|
+
table,
|
|
252
|
+
number,
|
|
253
|
+
channel,
|
|
254
|
+
guests,
|
|
255
|
+
server,
|
|
256
|
+
customer,
|
|
257
|
+
since,
|
|
258
|
+
targetMinutes,
|
|
259
|
+
serverOffsetMs,
|
|
260
|
+
state: stateProp,
|
|
261
|
+
lines,
|
|
262
|
+
partIndex,
|
|
263
|
+
partCount,
|
|
264
|
+
recovered,
|
|
265
|
+
chip,
|
|
266
|
+
readOnly = false,
|
|
267
|
+
onStartAll,
|
|
268
|
+
onReadyAll,
|
|
269
|
+
actions,
|
|
270
|
+
hanging,
|
|
271
|
+
headingLevel = 3,
|
|
272
|
+
viewTransitionName,
|
|
273
|
+
classNames,
|
|
274
|
+
className,
|
|
275
|
+
style,
|
|
276
|
+
...props
|
|
277
|
+
}: OrderTicketProps) {
|
|
278
|
+
const strings = useUiStrings();
|
|
279
|
+
const reducedMotion = usePrefersReducedMotion();
|
|
280
|
+
const headingId = useId();
|
|
281
|
+
const now = useSyncExternalStore(subscribeTicker, getTickerSnapshot, getTickerSnapshot);
|
|
282
|
+
const { seconds } = readElapsed({ since, now, serverOffsetMs });
|
|
283
|
+
const targetSeconds = Math.max(1, targetMinutes * 60);
|
|
284
|
+
const state = stateProp ?? orderTicketState(seconds, targetMinutes);
|
|
285
|
+
const late = state === "late";
|
|
286
|
+
const overrun = Math.max(0, seconds - targetSeconds);
|
|
287
|
+
const Heading = `h${headingLevel}` as const;
|
|
288
|
+
const title = table ?? fill(strings.orderTicketNumber, { number: number ?? "" });
|
|
289
|
+
const titleIcon = table ? null : channel?.icon;
|
|
290
|
+
const guestsText =
|
|
291
|
+
guests === undefined
|
|
292
|
+
? undefined
|
|
293
|
+
: fill(guests === 1 ? strings.orderTicketGuestsOne : strings.orderTicketGuests, {
|
|
294
|
+
count: guests,
|
|
295
|
+
});
|
|
296
|
+
const meta = [table ? undefined : channel?.label, guestsText, server, customer]
|
|
297
|
+
.filter(Boolean)
|
|
298
|
+
.join(" · ");
|
|
299
|
+
const split = partCount !== undefined && partCount > 1;
|
|
300
|
+
const partLabel =
|
|
301
|
+
split && (partIndex ?? 1) > 1
|
|
302
|
+
? strings.orderTicketContinued
|
|
303
|
+
: fill(strings.orderTicketPart, { index: 1, count: partCount ?? 1 });
|
|
304
|
+
const overrunText = reducedMotion
|
|
305
|
+
? fill(strings.minutesShort, { count: Math.ceil(overrun / 60) })
|
|
306
|
+
: clock(overrun);
|
|
307
|
+
const showActions = !readOnly && Boolean(actions || onStartAll || onReadyAll);
|
|
308
|
+
|
|
309
|
+
return (
|
|
310
|
+
<article
|
|
311
|
+
aria-labelledby={headingId}
|
|
312
|
+
data-state={state}
|
|
313
|
+
data-read-only={readOnly ? "" : undefined}
|
|
314
|
+
data-part-index={split ? (partIndex ?? 1) : undefined}
|
|
315
|
+
className={cn(
|
|
316
|
+
"@container/ticket relative min-w-0 [--ticket-edge:var(--hair)] data-[state=late]:[--ticket-edge:var(--danger)]",
|
|
317
|
+
"[filter:drop-shadow(1px_0_0_var(--ticket-edge))_drop-shadow(-1px_0_0_var(--ticket-edge))_drop-shadow(0_1px_0_var(--ticket-edge))_drop-shadow(0_-1px_0_var(--ticket-edge))]",
|
|
318
|
+
hanging &&
|
|
319
|
+
"pt-2.5 before:absolute before:top-0 before:left-1/2 before:z-1 before:h-4 before:w-11 before:-translate-x-1/2 before:rounded-[4px_4px_2px_2px] before:bg-line-strong before:shadow-[inset_0_-3px_0_var(--sunken)] before:content-['']",
|
|
320
|
+
classNames?.root,
|
|
321
|
+
className,
|
|
322
|
+
)}
|
|
323
|
+
style={viewTransitionName ? { ...style, viewTransitionName } : style}
|
|
324
|
+
{...props}
|
|
325
|
+
>
|
|
326
|
+
<div
|
|
327
|
+
data-part="paper"
|
|
328
|
+
className={cn(
|
|
329
|
+
"relative flex flex-col gap-2.5 rounded-t-card bg-surface p-3 pb-[calc(--spacing(3)+6px)] text-ink",
|
|
330
|
+
"[mask:conic-gradient(from_-45deg_at_bottom,transparent,black_1deg_89deg,transparent_90deg)_50%/12px_100%]",
|
|
331
|
+
classNames?.paper,
|
|
332
|
+
)}
|
|
333
|
+
>
|
|
334
|
+
<div
|
|
335
|
+
data-part="band"
|
|
336
|
+
className={cn(
|
|
337
|
+
"-mx-3 -mt-3 flex flex-col gap-1.5 rounded-t-card px-3 pt-3 pb-2.5",
|
|
338
|
+
hanging && "pt-4",
|
|
339
|
+
late && "bg-danger text-surface",
|
|
340
|
+
classNames?.band,
|
|
341
|
+
)}
|
|
342
|
+
>
|
|
343
|
+
<header className="grid grid-cols-[minmax(0,1fr)_auto] items-baseline gap-x-3">
|
|
344
|
+
<div className="flex min-w-0 flex-wrap items-baseline gap-x-2">
|
|
345
|
+
<Heading
|
|
346
|
+
id={headingId}
|
|
347
|
+
className={cn(
|
|
348
|
+
"m-0 inline-flex items-center gap-1.5 text-kpi-number text-balance [overflow-wrap:anywhere] [&_svg]:shrink-0",
|
|
349
|
+
classNames?.title,
|
|
350
|
+
)}
|
|
351
|
+
>
|
|
352
|
+
{titleIcon}
|
|
353
|
+
<span>{title}</span>
|
|
354
|
+
{split && <span className="text-control">{partLabel}</span>}
|
|
355
|
+
<span className="sr-only">{`, ${strings[stateWord[state]]}`}</span>
|
|
356
|
+
</Heading>
|
|
357
|
+
{meta && (
|
|
358
|
+
<span
|
|
359
|
+
className={cn(
|
|
360
|
+
"min-w-0 text-meta",
|
|
361
|
+
late ? "text-current" : "text-ink-2",
|
|
362
|
+
classNames?.meta,
|
|
363
|
+
)}
|
|
364
|
+
>
|
|
365
|
+
{meta}
|
|
366
|
+
</span>
|
|
367
|
+
)}
|
|
368
|
+
</div>
|
|
369
|
+
<span
|
|
370
|
+
className={cn(
|
|
371
|
+
"inline-flex items-center gap-1 whitespace-nowrap",
|
|
372
|
+
state === "warn" && "text-warning",
|
|
373
|
+
classNames?.timer,
|
|
374
|
+
)}
|
|
375
|
+
>
|
|
376
|
+
{state === "warn" && <Hourglass size={18} aria-hidden="true" />}
|
|
377
|
+
<ElapsedTime
|
|
378
|
+
since={since}
|
|
379
|
+
{...(serverOffsetMs === undefined ? {} : { serverOffsetMs })}
|
|
380
|
+
className={cn("text-kpi-number", timerTone[state])}
|
|
381
|
+
/>
|
|
382
|
+
</span>
|
|
383
|
+
</header>
|
|
384
|
+
{late && (
|
|
385
|
+
<span className="inline-flex items-center gap-1.5 text-row-title">
|
|
386
|
+
<AlarmClock size={18} aria-hidden="true" />
|
|
387
|
+
{fill(strings.orderTicketLateBy, { time: overrunText })}
|
|
388
|
+
</span>
|
|
389
|
+
)}
|
|
390
|
+
</div>
|
|
391
|
+
<Progress
|
|
392
|
+
value={Math.min(seconds, targetSeconds)}
|
|
393
|
+
max={targetSeconds}
|
|
394
|
+
tone={progressTone[state]}
|
|
395
|
+
aria-label={fill(strings.orderTicketProgress, { target: targetMinutes })}
|
|
396
|
+
getValueLabel={() =>
|
|
397
|
+
fill(strings.orderTicketProgressValue, {
|
|
398
|
+
elapsed: Math.floor(seconds / 60),
|
|
399
|
+
target: targetMinutes,
|
|
400
|
+
})
|
|
401
|
+
}
|
|
402
|
+
className={classNames?.progress}
|
|
403
|
+
/>
|
|
404
|
+
{recovered && (
|
|
405
|
+
<div className="flex flex-wrap gap-1.5">
|
|
406
|
+
<Chip tone="info" icon={<RotateCcw size={14} aria-hidden="true" />}>
|
|
407
|
+
{strings.orderTicketRecovered}
|
|
408
|
+
</Chip>
|
|
409
|
+
</div>
|
|
410
|
+
)}
|
|
411
|
+
<ul
|
|
412
|
+
aria-label={strings.orderTicketItems}
|
|
413
|
+
className={cn("-mx-1.5 my-0 flex list-none flex-col gap-0.5 p-0", classNames?.lines)}
|
|
414
|
+
>
|
|
415
|
+
{lines.map((line) => (
|
|
416
|
+
<TicketLineRow
|
|
417
|
+
key={line.id}
|
|
418
|
+
line={line}
|
|
419
|
+
readOnly={readOnly}
|
|
420
|
+
strings={strings}
|
|
421
|
+
className={classNames?.line}
|
|
422
|
+
/>
|
|
423
|
+
))}
|
|
424
|
+
</ul>
|
|
425
|
+
{(chip || showActions) && (
|
|
426
|
+
<footer
|
|
427
|
+
className={cn(
|
|
428
|
+
"flex items-center gap-2 border-t border-dashed border-line-strong pt-2.5",
|
|
429
|
+
classNames?.footer,
|
|
430
|
+
)}
|
|
431
|
+
>
|
|
432
|
+
<div className="flex min-w-0 grow flex-wrap gap-1.5 @max-[310px]/ticket:hidden">
|
|
433
|
+
{chip && (
|
|
434
|
+
<Chip tone="neutral" className="min-w-0">
|
|
435
|
+
{chip}
|
|
436
|
+
</Chip>
|
|
437
|
+
)}
|
|
438
|
+
</div>
|
|
439
|
+
{showActions && actions}
|
|
440
|
+
{showActions && onStartAll && (
|
|
441
|
+
<Button
|
|
442
|
+
variant={onReadyAll ? "secondary" : "primary"}
|
|
443
|
+
className="whitespace-nowrap @max-[310px]/ticket:flex-1"
|
|
444
|
+
onClick={() => onStartAll(lines)}
|
|
445
|
+
>
|
|
446
|
+
{strings.orderTicketStartAll}
|
|
447
|
+
</Button>
|
|
448
|
+
)}
|
|
449
|
+
{showActions && onReadyAll && (
|
|
450
|
+
<Button
|
|
451
|
+
variant="primary"
|
|
452
|
+
className="whitespace-nowrap @max-[310px]/ticket:flex-1"
|
|
453
|
+
onClick={() => onReadyAll(lines)}
|
|
454
|
+
>
|
|
455
|
+
{strings.orderTicketReadyAll}
|
|
456
|
+
</Button>
|
|
457
|
+
)}
|
|
458
|
+
</footer>
|
|
459
|
+
)}
|
|
460
|
+
</div>
|
|
461
|
+
</article>
|
|
462
|
+
);
|
|
463
|
+
}
|