"use client"; import { useSyncExternalStore } from "react"; // --------------------------------------------------------------------------- // THE PHONE, as a fact a client component can read (the mobile-first layout, // 2026-10-24): below `md` (768 px) is the phone, `md` and up the desk exactly // as it was. // // Most of the phone is CSS -- base styles below md, the desk's behind `md:`. // This is for the few places where the phone needs a DIFFERENT control rather // than the same one laid out differently (the lifecycle as three labelled // buttons, a menu as a bottom sheet) or a second copy of something in another // place (the policy chip in the ⋯ sheet). The rule that keeps the desk // unchanged: a phone-only copy is rendered only when the phone is true, so on // the desk the DOM is what it always was -- no hidden twin for a selector to // find twice. // // The server cannot know the width, so it renders the desk; a phone swaps on // hydration. Everything that swaps sits inside a closed sheet, so nothing is // seen to change. // --------------------------------------------------------------------------- export const PHONE_QUERY = "(max-width: 767.98px)"; function subscribe(on: () => void) { const mq = window.matchMedia(PHONE_QUERY); mq.addEventListener("change", on); return () => mq.removeEventListener("change", on); } /** True below `md`; false on the server and on the desk. */ export function usePhone(): boolean { return useSyncExternalStore( subscribe, () => window.matchMedia(PHONE_QUERY).matches, () => false, ); } /** Its children on a phone only: never in the desk's DOM. */ export function PhoneOnly({ children }: { children: React.ReactNode }) { return usePhone() ? <>{children} : null; }