Open History to see the last commit
1import { createLink, useRouter } from "@tanstack/react-router";
2import { ChevronDown, ChevronLeft, ChevronRight, Mic, Search, SquarePen } from "lucide-react";
3import type { ComponentProps, ReactNode } from "react";
4
5import { useCurrentEntrySheetOpen, usePreviousEntry } from "@/lib/history-tracker";
6import { isRecordingSheetState } from "@/lib/sheet-aware-history";
7import { cn } from "@/lib/utils";
8
9import { NotImplemented } from "../not-implemented";
10
11/* iOS 26 "Liquid Glass": translucent capsules floating over the content. */
12const glass =
13 "border border-ios-glass-border bg-ios-glass text-ios-text shadow-[0_6px_24px_rgb(0_0_0/0.12)] backdrop-blur-xl backdrop-saturate-150";
14
15export function GlassCircle({ className, ...props }: ComponentProps<"button">) {
16 return (
17 <button
18 type="button"
19 className={cn(
20 glass,
21 "grid size-11 shrink-0 place-items-center rounded-full disabled:cursor-not-allowed [&_svg]:size-[22px]",
22 className,
23 )}
24 {...props}
25 />
26 );
27}
28
29/**
30 * Goes up the iPhone navigation stack to `href`: pops history when the parent
31 * screen is the previous entry, like a real navigation stack (so history
32 * doesn't grow and the parent's scroll is restored). Returns `false` when it
33 * can't, and the caller should navigate instead.
34 */
35export function usePopTo(): (href: string) => boolean {
36 const router = useRouter();
37 const previous = usePreviousEntry();
38 const sheetOpen = useCurrentEntrySheetOpen();
39
40 return (href) => {
41 // Not if that entry is from before the app sheet opened: popping it would close the sheet.
42 const parentIsPrevious =
43 previous?.pathname === new URL(href, window.location.href).pathname &&
44 (!isRecordingSheetState() || previous.sheetOpen === sheetOpen);
45 if (!parentIsPrevious) return false;
46 router.history.back();
47 return true;
48 };
49}
50
51function BackAnchor({ className, href, onClick, ...props }: ComponentProps<"a">) {
52 const popTo = usePopTo();
53
54 return (
55 <a
56 {...props}
57 href={href}
58 onClick={(event) => {
59 const plainClick = !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey;
60 if (plainClick && href !== undefined && popTo(href)) {
61 event.preventDefault();
62 return;
63 }
64 // Opened directly (or from elsewhere): go to the parent screen.
65 onClick?.(event);
66 }}
67 className={cn(glass, "grid size-11 shrink-0 place-items-center rounded-full", className)}
68 >
69 <ChevronLeft className="size-6 -translate-x-px" strokeWidth={2.2} />
70 </a>
71 );
72}
73
74/**
75 * Round floating back button (top left of every pushed screen). A typed router
76 * link to the parent screen that pops history when the parent is the previous entry.
77 */
78export const BackLink = createLink(BackAnchor);
79
80export function GlassPill({ className, children }: { className?: string; children: ReactNode }) {
81 return (
82 <div className={cn(glass, "flex h-11 items-center rounded-full px-1.5", className)}>
83 {children}
84 </div>
85 );
86}
87
88export function GlassPillButton({
89 className,
90 notImplemented,
91 ...props
92}: ComponentProps<"button"> & {
93 /** The feature isn't built: show a not-allowed cursor and a "Not implemented" tooltip. */
94 notImplemented?: boolean;
95}) {
96 const button = (
97 <button
98 type="button"
99 aria-disabled={notImplemented || undefined}
100 className={cn(
101 "grid h-11 min-w-11 place-items-center px-2 disabled:cursor-not-allowed aria-disabled:cursor-not-allowed [&_svg]:size-[21px]",
102 className,
103 )}
104 {...props}
105 />
106 );
107 return notImplemented ? <NotImplemented>{button}</NotImplemented> : button;
108}
109
110interface IosScreenProps {
111 /** `grouped` for lists of inset cards, `plain` for the editor. */
112 background?: "grouped" | "plain";
113 leading?: ReactNode;
114 trailing?: ReactNode;
115 bottom?: ReactNode;
116 children: ReactNode;
117}
118
119/**
120 * One full-screen page of the iPhone navigation stack. The floating buttons
121 * sit on blurred bars (iOS 26's scroll edge effect), and the content is padded
122 * so its first and last rows can always scroll clear of them.
123 */
124export function IosScreen({
125 background = "grouped",
126 leading,
127 trailing,
128 bottom,
129 children,
130}: IosScreenProps) {
131 const grouped = background === "grouped";
132 return (
133 <div
134 className={cn(
135 "group/screen relative h-full font-sans text-ios-text",
136 // Height of the bottom bar: a 3rem pill, 1rem below it, plus the home indicator.
137 "[--ios-bottom-bar:calc(4rem+env(safe-area-inset-bottom))]",
138 grouped ? "bg-ios-bg" : "bg-ios-plain",
139 )}
140 >
141 <div
142 data-page-scroll
143 className={cn(
144 "notes-scroll h-full overflow-y-auto px-4 pt-[68px]",
145 bottom
146 ? "pb-[calc(var(--ios-bottom-bar)+1.5rem)]"
147 : "pb-[calc(2rem+env(safe-area-inset-bottom))]",
148 )}
149 >
150 {children}
151 </div>
152
153 <div
154 aria-hidden
155 className={cn(
156 "pointer-events-none absolute inset-x-0 top-0 h-[68px] mask-b-from-70% backdrop-blur-xl",
157 grouped ? "bg-ios-bg/85" : "bg-ios-plain/85",
158 )}
159 />
160 <div className="absolute inset-x-0 top-0 flex items-center justify-between gap-2 px-4 pt-3">
161 <div className="flex items-center gap-2">{leading}</div>
162 <div className="flex items-center gap-2">{trailing}</div>
163 </div>
164
165 {bottom && (
166 <>
167 <div
168 aria-hidden
169 className={cn(
170 "pointer-events-none absolute inset-x-0 bottom-0 h-(--ios-bottom-bar) mask-t-from-50% backdrop-blur-md",
171 grouped ? "bg-ios-bg/70" : "bg-ios-plain/70",
172 )}
173 />
174 <div className="absolute inset-x-0 bottom-0 flex items-center gap-3 px-5 pb-[calc(1rem+env(safe-area-inset-bottom))]">
175 {bottom}
176 </div>
177 </>
178 )}
179 </div>
180 );
181}
182
183export function LargeTitle({ title, subtitle }: { title: string; subtitle?: string }) {
184 return (
185 <header className="mb-4 px-1">
186 <h1 className="text-[32px] leading-tight font-bold tracking-[-0.02em]">{title}</h1>
187 {subtitle && <p className="text-[15px] text-ios-secondary">{subtitle}</p>}
188 </header>
189 );
190}
191
192export function SectionHeader({
193 children,
194 chevron,
195 onToggle,
196 open = true,
197}: {
198 children: ReactNode;
199 chevron?: boolean;
200 onToggle?: () => void;
201 open?: boolean;
202}) {
203 const content = (
204 <>
205 <span className="flex-1 text-left">{children}</span>
206 {chevron && (
207 <ChevronDown
208 className={cn("size-5 text-ios-secondary transition-transform", !open && "-rotate-90")}
209 />
210 )}
211 </>
212 );
213 const className = "flex w-full items-center px-1 pt-6 pb-2.5 text-[21px] font-bold";
214 return onToggle ? (
215 <button type="button" onClick={onToggle} aria-expanded={open} className={className}>
216 {content}
217 </button>
218 ) : (
219 <h2 className={className}>{content}</h2>
220 );
221}
222
223/** A rounded, inset grouped list card. */
224export function InsetCard({
225 className,
226 children,
227 ...props
228}: { className?: string; children: ReactNode } & { "data-spotlight"?: string }) {
229 return (
230 <ul className={cn("overflow-hidden rounded-[26px] bg-ios-card", className)} {...props}>
231 {children}
232 </ul>
233 );
234}
235
236/**
237 * A row in an inset card. The separator starts where the text starts
238 * (`separatorInset`), like UIKit's inset separators.
239 */
240export function InsetRow({
241 children,
242 first,
243 separatorInset = 16,
244}: {
245 children: ReactNode;
246 first?: boolean;
247 separatorInset?: number;
248}) {
249 return (
250 <li className="relative">
251 {!first && (
252 <span
253 aria-hidden
254 className="absolute top-0 right-4 h-px bg-ios-separator"
255 style={{ left: separatorInset }}
256 />
257 )}
258 {children}
259 </li>
260 );
261}
262
263export function RowChevron() {
264 return <ChevronRight className="size-[18px] shrink-0 text-ios-secondary/70" strokeWidth={2.4} />;
265}
266
267/** Bottom bar of list screens: search capsule + round compose button. */
268export function SearchAndCompose({ onCompose }: { onCompose: (() => void) | undefined }) {
269 return (
270 <>
271 <NotImplemented>
272 <label
273 className={cn(
274 glass,
275 "flex h-12 min-w-0 flex-1 cursor-not-allowed items-center gap-2 rounded-full px-4",
276 )}
277 >
278 <Search className="size-5 shrink-0 text-ios-text" />
279 <input
280 type="search"
281 placeholder="Search"
282 readOnly
283 aria-disabled
284 className="min-w-0 flex-1 cursor-not-allowed bg-transparent text-[17px] outline-none placeholder:text-ios-secondary"
285 />
286 <Mic className="size-5 shrink-0 text-ios-text" />
287 </label>
288 </NotImplemented>
289 <ComposeButton onCompose={onCompose} />
290 </>
291 );
292}
293
294export function ComposeButton({ onCompose }: { onCompose: (() => void) | undefined }) {
295 return (
296 <GlassCircle
297 aria-label="New note"
298 className="size-12 disabled:opacity-40"
299 disabled={!onCompose}
300 onClick={onCompose}
301 >
302 <SquarePen />
303 </GlassCircle>
304 );
305}