Skip to content
Source
Sign inSign up
fuko/trytanstackdb.com
Open History to see the last commit

controls.tsx

82 lines2.6 KB

1import type { ComponentProps, ReactElement, ReactNode } from "react";
2​
3import { cn } from "@/lib/utils";
4​
5import { NotImplemented } from "../not-implemented";
6​
7type MacButtonProps = ComponentProps<"button"> & {
8 /** The feature isn't built: show a not-allowed cursor and a "Not implemented" tooltip. */
9 notImplemented?: boolean;
10};
11​
12/** Shared by the toolbar buttons: hover feedback only for buttons that do something. */
13const buttonStates =
14 "not-aria-disabled:not-disabled:hover:text-mac-text aria-disabled:cursor-not-allowed disabled:cursor-not-allowed";
15​
16function withNotImplemented(button: ReactElement, notImplemented: boolean | undefined) {
17 return notImplemented ? <NotImplemented>{button}</NotImplemented> : button;
19​
20/** The round, slightly raised toolbar buttons of macOS 26. */
21export function MacCircleButton({ className, notImplemented, title, ...props }: MacButtonProps) {
22 return withNotImplemented(
23 <button
24 type="button"
25 title={notImplemented ? undefined : title}
26 aria-disabled={notImplemented || undefined}
27 className={cn(
28 "grid size-[34px] shrink-0 place-items-center rounded-full border border-mac-control-border bg-mac-control text-mac-icon shadow-[0_1px_1px_rgb(0_0_0/0.03)] transition-colors [&_svg]:size-[17px] [&_svg]:stroke-[1.6]",
29 buttonStates,
30 className,
31 )}
32 {...props}
33 />,
34 notImplemented,
35 );
37​
38/** A capsule that groups several toolbar buttons. */
39export function MacPill({ className, children }: { className?: string; children: ReactNode }) {
40 return (
41 <div
42 className={cn(
43 "flex h-[34px] shrink-0 items-center rounded-full border border-mac-control-border bg-mac-control px-1 text-mac-icon shadow-[0_1px_1px_rgb(0_0_0/0.03)]",
44 className,
45 )}
46 >
47 {children}
48 </div>
49 );
51​
52export function MacPillButton({ className, notImplemented, title, ...props }: MacButtonProps) {
53 return withNotImplemented(
54 <button
55 type="button"
56 title={notImplemented ? undefined : title}
57 aria-disabled={notImplemented || undefined}
58 className={cn(
59 "grid h-[28px] w-[32px] place-items-center rounded-full transition-colors [&_svg]:size-[17px] [&_svg]:stroke-[1.6]",
60 buttonStates,
61 className,
62 )}
63 {...props}
64 />,
65 notImplemented,
66 );
68​
69/** Header row at the top of each column; together they form the window toolbar. */
70export function MacColumnHeader({
71 className,
72 children,
73}: {
74 className?: string;
75 children: ReactNode;
76}) {
77 return (
78 <div className={cn("flex h-[52px] shrink-0 items-center gap-2 px-3", className)}>
79 {children}
80 </div>
81 );