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