Open History to see the last commit
1import {
2 DUO_POSES,
3 type DuoCommand,
4 type DuoControlState,
5} from "@t3tools/client-runtime/device/duo-control";
6import type { DeviceScreenSize } from "@t3tools/client-runtime/device/stream";
7import { DeviceDuoGlyph } from "./DeviceDuoGlyph";
8import { Button } from "~/components/ui/button";
9import { Tooltip, TooltipPopup, TooltipTrigger } from "~/components/ui/tooltip";
10
11/** Physical presets live beside the device. Pinching supplies continuous hinge control. */
12export function DeviceDuoControls(props: {
13 screen: DeviceScreenSize;
14 state: DuoControlState;
15 enabled: boolean;
16 onCommand: (command: DuoCommand) => void;
17}) {
18 const angle = props.screen.hingeAngle;
19 const fold = angle == null ? null : angle === 0 ? "closed" : angle === 180 ? "open" : "book";
20 const selected = (id: (typeof DUO_POSES)[number]["id"]) =>
21 id === "laptop" || id === "tent" ? props.screen.hingePose === id : fold === id;
22 return (
23 <div aria-label="iPhone Duo stands" className="flex flex-col items-center gap-2">
24 {([DUO_POSES.slice(0, 3), DUO_POSES.slice(3)] as const).map((poses, index) => (
25 <div
26 key={poses[0]?.id}
27 role="group"
28 aria-label={index === 0 ? "Fold shape" : "Device stance"}
29 className="pointer-events-auto flex shrink-0 flex-col items-center gap-1 rounded-full border border-border/50 bg-background/80 p-1 shadow-sm"
30 >
31 {poses.map((pose) => (
32 <Tooltip key={pose.id}>
33 <TooltipTrigger
34 render={
35 <Button
36 size="icon"
37 variant={selected(pose.id) ? "secondary" : "ghost"}
38 disabled={!props.enabled}
39 aria-label={`${pose.label} stand`}
40 aria-pressed={selected(pose.id)}
41 data-pressed={selected(pose.id) ? "" : undefined}
42 onClick={() => props.onCommand({ control: "pose", value: pose.id })}
43 />
44 }
45 >
46 <DeviceDuoGlyph pose={pose.id} />
47 </TooltipTrigger>
48 <TooltipPopup side="left">
49 {pose.label}
50 {pose.id === "book" ? " / bookshelf" : ""}
51 </TooltipPopup>
52 </Tooltip>
53 ))}
54 </div>
55 ))}
56 {props.state.error ? (
57 <Tooltip>
58 <TooltipTrigger
59 render={
60 <span
61 tabIndex={0}
62 role="alert"
63 aria-label={props.state.error}
64 className="pointer-events-auto text-xs text-destructive"
65 >
66 !
67 </span>
68 }
69 />
70 <TooltipPopup side="left">{props.state.error}</TooltipPopup>
71 </Tooltip>
72 ) : null}
73 </div>
74 );
75}