@sereno-ds/ui 0.36.4 → 0.37.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_internal/scrollLock.d.ts +22 -0
- package/dist/_internal/scrollLock.js +29 -0
- package/dist/_internal/scrollLock.js.map +1 -0
- package/dist/feedback/Dialog.js +3 -6
- package/dist/feedback/Dialog.js.map +1 -1
- package/dist/forms/AvatarUpload.js +0 -22
- package/dist/forms/AvatarUpload.js.map +1 -1
- package/dist/forms/DatePicker.d.ts +7 -2
- package/dist/forms/DatePicker.js +3 -31
- package/dist/forms/DatePicker.js.map +1 -1
- package/dist/forms/DateTimePicker.d.ts +11 -0
- package/dist/forms/DateTimePicker.js +4 -0
- package/dist/forms/DateTimePicker.js.map +1 -1
- package/dist/forms/Select.js +2 -8
- package/dist/forms/Select.js.map +1 -1
- package/dist/forms/_internal/CalendarGrid.d.ts +10 -1
- package/dist/forms/_internal/CalendarGrid.js +53 -29
- package/dist/forms/_internal/CalendarGrid.js.map +1 -1
- package/dist/forms/_internal/calendarRange.d.ts +41 -0
- package/dist/forms/_internal/calendarRange.js +45 -0
- package/dist/forms/_internal/calendarRange.js.map +1 -0
- package/dist/styles.css +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one lock on the page scroll, shared by everything that needs it (`Dialog`, and the touch
|
|
3
|
+
* sheet of `Select`).
|
|
4
|
+
*
|
|
5
|
+
* Each of them used to lock on its own: remember the `overflow` it found on <html> and <body>,
|
|
6
|
+
* set `hidden`, and put the remembered value back on close. With two held at once that goes
|
|
7
|
+
* wrong in both directions. The second one remembers `hidden` as if it were the page's own
|
|
8
|
+
* value, so when the locks are released in the wrong order the page ends up with `hidden` for
|
|
9
|
+
* good (and a client-side navigation does not reload it to clear that); and the one that
|
|
10
|
+
* closes first can unlock the page behind a window that is still open (SS-402).
|
|
11
|
+
*
|
|
12
|
+
* Here the first holder records what the page had and sets `hidden`, every other holder just
|
|
13
|
+
* counts, and the last one to let go puts the recorded value back. Order does not matter.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Locks the page scroll and returns the function that lets go. Letting go twice is harmless
|
|
17
|
+
* (only the first counts), so a cleanup that runs more than once cannot unlock someone else.
|
|
18
|
+
* Does nothing on the server.
|
|
19
|
+
*/
|
|
20
|
+
declare function acquireScrollLock(): () => void;
|
|
21
|
+
|
|
22
|
+
export { acquireScrollLock };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
let holders = 0;
|
|
2
|
+
let saved = null;
|
|
3
|
+
function acquireScrollLock() {
|
|
4
|
+
if (typeof document === "undefined") return () => {
|
|
5
|
+
};
|
|
6
|
+
const root = document.documentElement;
|
|
7
|
+
const body = document.body;
|
|
8
|
+
if (holders === 0) {
|
|
9
|
+
saved = { html: root.style.overflow, body: body.style.overflow };
|
|
10
|
+
root.style.overflow = "hidden";
|
|
11
|
+
body.style.overflow = "hidden";
|
|
12
|
+
}
|
|
13
|
+
holders += 1;
|
|
14
|
+
let released = false;
|
|
15
|
+
return () => {
|
|
16
|
+
if (released) return;
|
|
17
|
+
released = true;
|
|
18
|
+
holders -= 1;
|
|
19
|
+
if (holders === 0 && saved) {
|
|
20
|
+
root.style.overflow = saved.html;
|
|
21
|
+
body.style.overflow = saved.body;
|
|
22
|
+
saved = null;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
acquireScrollLock
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=scrollLock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/_internal/scrollLock.ts"],"sourcesContent":["/**\n * The one lock on the page scroll, shared by everything that needs it (`Dialog`, and the touch\n * sheet of `Select`).\n *\n * Each of them used to lock on its own: remember the `overflow` it found on <html> and <body>,\n * set `hidden`, and put the remembered value back on close. With two held at once that goes\n * wrong in both directions. The second one remembers `hidden` as if it were the page's own\n * value, so when the locks are released in the wrong order the page ends up with `hidden` for\n * good (and a client-side navigation does not reload it to clear that); and the one that\n * closes first can unlock the page behind a window that is still open (SS-402).\n *\n * Here the first holder records what the page had and sets `hidden`, every other holder just\n * counts, and the last one to let go puts the recorded value back. Order does not matter.\n */\n\nlet holders = 0;\nlet saved: { html: string; body: string } | null = null;\n\n/**\n * Locks the page scroll and returns the function that lets go. Letting go twice is harmless\n * (only the first counts), so a cleanup that runs more than once cannot unlock someone else.\n * Does nothing on the server.\n */\nexport function acquireScrollLock(): () => void {\n if (typeof document === 'undefined') return () => {};\n const root = document.documentElement;\n const body = document.body;\n if (holders === 0) {\n saved = { html: root.style.overflow, body: body.style.overflow };\n root.style.overflow = 'hidden';\n body.style.overflow = 'hidden';\n }\n holders += 1;\n\n let released = false;\n return () => {\n if (released) return;\n released = true;\n holders -= 1;\n if (holders === 0 && saved) {\n root.style.overflow = saved.html;\n body.style.overflow = saved.body;\n saved = null;\n }\n };\n}\n"],"mappings":"AAeA,IAAI,UAAU;AACd,IAAI,QAA+C;AAO5C,SAAS,oBAAgC;AAC9C,MAAI,OAAO,aAAa,YAAa,QAAO,MAAM;AAAA,EAAC;AACnD,QAAM,OAAO,SAAS;AACtB,QAAM,OAAO,SAAS;AACtB,MAAI,YAAY,GAAG;AACjB,YAAQ,EAAE,MAAM,KAAK,MAAM,UAAU,MAAM,KAAK,MAAM,SAAS;AAC/D,SAAK,MAAM,WAAW;AACtB,SAAK,MAAM,WAAW;AAAA,EACxB;AACA,aAAW;AAEX,MAAI,WAAW;AACf,SAAO,MAAM;AACX,QAAI,SAAU;AACd,eAAW;AACX,eAAW;AACX,QAAI,YAAY,KAAK,OAAO;AAC1B,WAAK,MAAM,WAAW,MAAM;AAC5B,WAAK,MAAM,WAAW,MAAM;AAC5B,cAAQ;AAAA,IACV;AAAA,EACF;AACF;","names":[]}
|
package/dist/feedback/Dialog.js
CHANGED
|
@@ -4,6 +4,7 @@ import * as React from "react";
|
|
|
4
4
|
import { createPortal } from "react-dom";
|
|
5
5
|
import { X } from "lucide-react";
|
|
6
6
|
import { sx } from "../_internal/style.js";
|
|
7
|
+
import { acquireScrollLock } from "../_internal/scrollLock.js";
|
|
7
8
|
import { Typography } from "../core/Typography.js";
|
|
8
9
|
const SIZE_W = { sm: 440, md: 600, lg: 800, xl: 1e3 };
|
|
9
10
|
const FOCUSABLE_SELECTOR = 'a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
@@ -44,10 +45,7 @@ function DialogRoot({
|
|
|
44
45
|
React.useEffect(() => {
|
|
45
46
|
if (!open) return;
|
|
46
47
|
const previouslyFocused = document.activeElement;
|
|
47
|
-
const
|
|
48
|
-
const prev = { h: root.style.overflow, b: document.body.style.overflow };
|
|
49
|
-
root.style.overflow = "hidden";
|
|
50
|
-
document.body.style.overflow = "hidden";
|
|
48
|
+
const unlock = acquireScrollLock();
|
|
51
49
|
const onKey = (e) => {
|
|
52
50
|
if (e.key === "Escape") {
|
|
53
51
|
if (dismissibleRef.current) onCloseRef.current?.();
|
|
@@ -73,8 +71,7 @@ function DialogRoot({
|
|
|
73
71
|
};
|
|
74
72
|
document.addEventListener("keydown", onKey);
|
|
75
73
|
return () => {
|
|
76
|
-
|
|
77
|
-
document.body.style.overflow = prev.b;
|
|
74
|
+
unlock();
|
|
78
75
|
document.removeEventListener("keydown", onKey);
|
|
79
76
|
previouslyFocused?.focus();
|
|
80
77
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/feedback/Dialog.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { X } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { Typography } from '../core/Typography';\n\n/**\n * Modal (desktop), bottom sheet (mobile) or full-screen - a **compound\n * component**. Portalled to `<body>` and fixed to the viewport, so no\n * ancestor's `overflow`/`transform`/positioning can trap it. While open it\n * locks page scroll and closes on `Escape`. Host needs the `sereno-pop` /\n * `sereno-slide-up` keyframes (see globals.css).\n *\n * ```tsx\n * <Dialog open={open} onClose={close} footer={false}>\n * <Dialog.Header title=\"Cancel booking?\" description=\"…\">\n * <Dialog.Close />\n * </Dialog.Header>\n * <Dialog.Body>…</Dialog.Body>\n * <Dialog.Footer>\n * <Button variant=\"ghost\" onClick={close}>Back</Button>\n * <Button variant=\"error\" onClick={confirm}>Cancel booking</Button>\n * </Dialog.Footer>\n * </Dialog>\n * ```\n *\n * `Dialog.Header` / `Dialog.Footer` are both optional - a dialog can be just\n * a `Dialog.Body`. `Dialog.Close` goes wherever you put it (typically inside\n * `Dialog.Header`); nothing renders a close button unless you add one.\n */\nexport interface DialogProps extends React.HTMLAttributes<HTMLDivElement> {\n open?: boolean;\n onClose?: () => void;\n /** `sheet` slides up from the bottom (mobile default); `fullscreen` fills the viewport. */\n variant?: 'center' | 'sheet' | 'fullscreen';\n /** Max width of the centered modal. Ignored for `sheet` / `fullscreen`. */\n size?: 'sm' | 'md' | 'lg' | 'xl';\n /** Hairline rules between header / body / footer, MUI-style. The body scrolls on its own. */\n dividers?: boolean;\n /**\n * When `false`, a scrim click and `Escape` no longer close the dialog - only\n * `Dialog.Close`, a footer action, or `open={false}` do. Use it for a choice\n * the user must make explicitly. Defaults to `true`.\n */\n dismissible?: boolean;\n /** Explicit pixel width - overrides `size`. */\n width?: number;\n children?: React.ReactNode;\n}\n\nexport interface DialogHeaderProps {\n title?: string;\n description?: string;\n /** Extra content below the description - or the whole header, if you skip `title`/`description`. Put `Dialog.Close` here. */\n children?: React.ReactNode;\n}\n\nexport interface DialogBodyProps {\n children?: React.ReactNode;\n}\n\nexport interface DialogFooterProps {\n /** Action buttons, right-aligned. */\n children?: React.ReactNode;\n /**\n * Let the buttons share the row and grow to fill it, and each line if they wrap, instead\n * of hugging the right edge at their natural width. For a footer with three actions or\n * long (translated) labels, where a plain wrap leaves the last button, usually the\n * primary one, alone, small and pushed right on a second line. Off by default, so no\n * existing dialog changes.\n */\n fill?: boolean;\n}\n\ninterface DialogContextValue {\n titleId: string;\n onClose?: () => void;\n full: boolean;\n dividers: boolean;\n hasHeader: boolean;\n hasFooter: boolean;\n}\n\nconst SIZE_W = { sm: 440, md: 600, lg: 800, xl: 1000 } as const;\n\n// Cheap, dependency-free focusable check - matches what most hand-rolled\n// focus traps use. No visibility filtering: nothing inside a Dialog is ever\n// conditionally hidden today, and jsdom doesn't compute layout (offsetParent\n// is always null there), so a visibility check would be untestable dead\n// weight rather than a real safeguard.\nconst FOCUSABLE_SELECTOR = 'a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\nfunction focusableIn(el: HTMLElement): HTMLElement[] {\n return Array.from(el.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR));\n}\n\nconst DialogContext = React.createContext<DialogContextValue | null>(null);\n\nfunction useDialogContext(component: string): DialogContextValue {\n const ctx = React.useContext(DialogContext);\n if (!ctx) throw new Error(`<Dialog.${component}> must be rendered inside <Dialog>.`);\n return ctx;\n}\n\nfunction DialogRoot({\n open = true,\n children,\n onClose,\n variant = 'center',\n size = 'sm',\n dividers = false,\n dismissible = true,\n width,\n style,\n ...rest\n}: DialogProps) {\n const sheet = variant === 'sheet';\n const full = variant === 'fullscreen';\n const rid = React.useId();\n const titleId = `${rid}-title`;\n\n // Portal target is client-only.\n const [mounted, setMounted] = React.useState(false);\n // eslint-disable-next-line react-hooks/set-state-in-effect -- portal target is client-only\n React.useEffect(() => setMounted(true), []);\n\n // While open: lock page scroll, bind Escape to close, trap Tab inside the\n // panel, and restore focus to whatever had it before opening once closed.\n // `onClose` / `dismissible` are read through refs so the effect only\n // re-runs when `open` flips.\n const onCloseRef = React.useRef(onClose);\n const dismissibleRef = React.useRef(dismissible);\n React.useEffect(() => {\n onCloseRef.current = onClose;\n dismissibleRef.current = dismissible;\n });\n const panelRef = React.useRef<HTMLDivElement>(null);\n React.useEffect(() => {\n if (!open) return;\n const previouslyFocused = document.activeElement as HTMLElement | null;\n const root = document.documentElement;\n const prev = { h: root.style.overflow, b: document.body.style.overflow };\n root.style.overflow = 'hidden';\n document.body.style.overflow = 'hidden';\n const onKey = (e: KeyboardEvent) => {\n if (e.key === 'Escape') {\n if (dismissibleRef.current) onCloseRef.current?.();\n return;\n }\n if (e.key !== 'Tab') return;\n const panel = panelRef.current;\n if (!panel) return;\n const focusables = focusableIn(panel);\n // No focusable content (a bare Dialog.Body with plain text): keep\n // focus pinned on the panel itself rather than leaking to the page.\n if (focusables.length === 0) {\n e.preventDefault();\n return;\n }\n const first = focusables[0];\n const last = focusables[focusables.length - 1];\n if (e.shiftKey && document.activeElement === first) {\n e.preventDefault();\n last.focus();\n } else if (!e.shiftKey && document.activeElement === last) {\n e.preventDefault();\n first.focus();\n }\n };\n document.addEventListener('keydown', onKey);\n return () => {\n root.style.overflow = prev.h;\n document.body.style.overflow = prev.b;\n document.removeEventListener('keydown', onKey);\n // The trigger may itself have unmounted (e.g. a row it lived in was\n // removed) - focus() on a detached element is a silent no-op, not a\n // throw, so no need to guard beyond the null check.\n previouslyFocused?.focus();\n };\n }, [open]);\n\n // Pull focus into the dialog when it opens.\n React.useEffect(() => {\n if (open && mounted) panelRef.current?.focus();\n }, [open, mounted]);\n\n if (!open || !mounted) return null;\n\n // Body/Footer padding depends on whether a Header/Footer is actually\n // present - read straight off the children, the same technique\n // SidebarNav.Item / Stepper use for data they need before render.\n const items = React.Children.toArray(children);\n const hasHeader = items.some((c) => React.isValidElement(c) && c.type === Header);\n const hasFooter = items.some((c) => React.isValidElement(c) && c.type === Footer);\n\n const ctx: DialogContextValue = { titleId, onClose, full, dividers, hasHeader, hasFooter };\n\n return createPortal(\n <div\n style={sx({\n position: 'fixed',\n inset: 0,\n zIndex: 1000,\n display: 'flex',\n alignItems: sheet ? 'flex-end' : 'center',\n justifyContent: 'center',\n background: 'var(--bg-overlay)',\n backdropFilter: 'blur(2px)',\n padding: sheet || full ? 0 : 'var(--space-5)',\n })}\n onClick={dismissible ? onClose : undefined}\n >\n <div\n ref={panelRef}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-labelledby={hasHeader ? titleId : undefined}\n tabIndex={-1}\n onClick={(e) => e.stopPropagation()}\n {...rest}\n style={sx({\n width: full || sheet ? '100%' : 'min(100%,' + (width ?? SIZE_W[size]) + 'px)',\n height: full ? '100%' : undefined,\n maxHeight: full ? undefined : sheet ? '90dvh' : 'calc(100dvh - var(--space-6))',\n display: 'flex',\n flexDirection: 'column',\n overflow: 'hidden',\n outline: 'none',\n background: 'var(--bg-surface)',\n borderRadius: full ? 0 : sheet ? 'var(--radius-sheet) var(--radius-sheet) 0 0' : 'var(--radius-lg)',\n border: full ? 'none' : 'var(--border-width-hairline) solid var(--border-default)',\n boxShadow: full ? 'none' : sheet ? 'var(--shadow-sheet)' : 'var(--shadow-lg)',\n animation: sheet ? 'sereno-slide-up var(--duration-sheet) var(--ease-gentle)' : 'sereno-pop var(--duration-normal) var(--ease-out)',\n ...style,\n })}\n >\n {sheet && (\n <span\n aria-hidden\n style={sx({ width: 36, height: 4, borderRadius: '999px', background: 'var(--border-strong)', alignSelf: 'center', marginTop: 'var(--space-2)', flex: '0 0 auto' })}\n />\n )}\n <DialogContext.Provider value={ctx}>{children}</DialogContext.Provider>\n </div>\n </div>,\n document.body,\n );\n}\n\nfunction Header({ title, description, children }: DialogHeaderProps) {\n const { titleId, dividers } = useDialogContext('Header');\n const pad = 'var(--space-5)';\n const hairline = 'var(--border-width-hairline) solid var(--border-default)';\n\n const items = React.Children.toArray(children);\n const closeEl = items.find((c) => React.isValidElement(c) && c.type === Close);\n const extra = items.filter((c) => c !== closeEl);\n\n return (\n <div\n style={sx({\n flex: '0 0 auto',\n display: 'flex',\n alignItems: 'flex-start',\n gap: 'var(--space-3)',\n padding: dividers ? pad : `${pad} ${pad} var(--space-3)`,\n borderBottom: dividers ? hairline : undefined,\n })}\n >\n <div id={titleId} style={sx({ flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 'var(--space-2)' })}>\n {title && (\n <Typography as=\"h3\" variant=\"h2\" style={{ letterSpacing: 'var(--tracking-tight)' }}>\n {title}\n </Typography>\n )}\n {description && (\n <Typography variant=\"body\" color=\"secondary\">\n {description}\n </Typography>\n )}\n {extra}\n </div>\n {closeEl}\n </div>\n );\n}\n\nfunction Body({ children }: DialogBodyProps) {\n const { dividers, hasHeader, hasFooter, full } = useDialogContext('Body');\n const pad = 'var(--space-5)';\n return (\n <div\n style={sx({\n flex: full ? '1 1 auto' : '0 1 auto',\n minHeight: 0,\n overflowY: 'auto',\n padding: dividers ? pad : hasHeader ? `0 ${pad} ${hasFooter ? 'var(--space-3)' : pad}` : pad,\n })}\n >\n {children}\n </div>\n );\n}\n\nfunction Footer({ children, fill = false }: DialogFooterProps) {\n const { dividers } = useDialogContext('Footer');\n const pad = 'var(--space-5)';\n const hairline = 'var(--border-width-hairline) solid var(--border-default)';\n return (\n <div\n // `fill` (see styles.css) makes each child `flex: 1 1 auto`. It can't be inline: it's on the children.\n className=\"sereno-dialog-footer\"\n data-fill={fill || undefined}\n style={sx({\n flex: '0 0 auto',\n display: 'flex',\n gap: 'var(--space-3)',\n justifyContent: 'flex-end',\n flexWrap: 'wrap',\n padding: dividers ? pad : `0 ${pad} ${pad}`,\n borderTop: dividers ? hairline : undefined,\n })}\n >\n {children}\n </div>\n );\n}\n\nfunction Close() {\n const { onClose, full } = useDialogContext('Close');\n return (\n <button\n type=\"button\"\n className=\"sereno-dialog-close\"\n aria-label=\"Fechar\"\n onClick={onClose}\n style={sx({\n flex: '0 0 auto',\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n width: full ? 40 : 34,\n height: full ? 40 : 34,\n margin: full ? 0 : '-3px -5px 0 0',\n border: 'none',\n borderRadius: 'var(--radius-md)',\n background: full ? 'var(--bg-subtle)' : 'transparent',\n color: 'var(--text-secondary)',\n cursor: 'pointer',\n })}\n >\n <X size={full ? 22 : 18} strokeWidth={2} />\n </button>\n );\n}\n\nexport const Dialog = Object.assign(DialogRoot, { Header, Body, Footer, Close });\n"],"mappings":";AAqNM,SAyBI,KAzBJ;AAnNN,YAAY,WAAW;AACvB,SAAS,oBAAoB;AAC7B,SAAS,SAAS;AAClB,SAAS,UAAU;AACnB,SAAS,kBAAkB;AA+E3B,MAAM,SAAS,EAAE,IAAI,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI,IAAK;AAOrD,MAAM,qBAAqB;AAC3B,SAAS,YAAY,IAAgC;AACnD,SAAO,MAAM,KAAK,GAAG,iBAA8B,kBAAkB,CAAC;AACxE;AAEA,MAAM,gBAAgB,MAAM,cAAyC,IAAI;AAEzE,SAAS,iBAAiB,WAAuC;AAC/D,QAAM,MAAM,MAAM,WAAW,aAAa;AAC1C,MAAI,CAAC,IAAK,OAAM,IAAI,MAAM,WAAW,SAAS,qCAAqC;AACnF,SAAO;AACT;AAEA,SAAS,WAAW;AAAA,EAClB,OAAO;AAAA,EACP;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV,OAAO;AAAA,EACP,WAAW;AAAA,EACX,cAAc;AAAA,EACd;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAgB;AACd,QAAM,QAAQ,YAAY;AAC1B,QAAM,OAAO,YAAY;AACzB,QAAM,MAAM,MAAM,MAAM;AACxB,QAAM,UAAU,GAAG,GAAG;AAGtB,QAAM,CAAC,SAAS,UAAU,IAAI,MAAM,SAAS,KAAK;AAElD,QAAM,UAAU,MAAM,WAAW,IAAI,GAAG,CAAC,CAAC;AAM1C,QAAM,aAAa,MAAM,OAAO,OAAO;AACvC,QAAM,iBAAiB,MAAM,OAAO,WAAW;AAC/C,QAAM,UAAU,MAAM;AACpB,eAAW,UAAU;AACrB,mBAAe,UAAU;AAAA,EAC3B,CAAC;AACD,QAAM,WAAW,MAAM,OAAuB,IAAI;AAClD,QAAM,UAAU,MAAM;AACpB,QAAI,CAAC,KAAM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AG;AAAA;AAAA,EAC3C;AAEJ;AAEO,MAAM,SAAS,OAAO,OAAO,YAAY,EAAE,QAAQ,MAAM,QAAQ,MAAM,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/feedback/Dialog.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { X } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { acquireScrollLock } from '../_internal/scrollLock';\nimport { Typography } from '../core/Typography';\n\n/**\n * Modal (desktop), bottom sheet (mobile) or full-screen - a **compound\n * component**. Portalled to `<body>` and fixed to the viewport, so no\n * ancestor's `overflow`/`transform`/positioning can trap it. While open it\n * locks page scroll and closes on `Escape`. Host needs the `sereno-pop` /\n * `sereno-slide-up` keyframes (see globals.css).\n *\n * ```tsx\n * <Dialog open={open} onClose={close} footer={false}>\n * <Dialog.Header title=\"Cancel booking?\" description=\"…\">\n * <Dialog.Close />\n * </Dialog.Header>\n * <Dialog.Body>…</Dialog.Body>\n * <Dialog.Footer>\n * <Button variant=\"ghost\" onClick={close}>Back</Button>\n * <Button variant=\"error\" onClick={confirm}>Cancel booking</Button>\n * </Dialog.Footer>\n * </Dialog>\n * ```\n *\n * `Dialog.Header` / `Dialog.Footer` are both optional - a dialog can be just\n * a `Dialog.Body`. `Dialog.Close` goes wherever you put it (typically inside\n * `Dialog.Header`); nothing renders a close button unless you add one.\n */\nexport interface DialogProps extends React.HTMLAttributes<HTMLDivElement> {\n open?: boolean;\n onClose?: () => void;\n /** `sheet` slides up from the bottom (mobile default); `fullscreen` fills the viewport. */\n variant?: 'center' | 'sheet' | 'fullscreen';\n /** Max width of the centered modal. Ignored for `sheet` / `fullscreen`. */\n size?: 'sm' | 'md' | 'lg' | 'xl';\n /** Hairline rules between header / body / footer, MUI-style. The body scrolls on its own. */\n dividers?: boolean;\n /**\n * When `false`, a scrim click and `Escape` no longer close the dialog - only\n * `Dialog.Close`, a footer action, or `open={false}` do. Use it for a choice\n * the user must make explicitly. Defaults to `true`.\n */\n dismissible?: boolean;\n /** Explicit pixel width - overrides `size`. */\n width?: number;\n children?: React.ReactNode;\n}\n\nexport interface DialogHeaderProps {\n title?: string;\n description?: string;\n /** Extra content below the description - or the whole header, if you skip `title`/`description`. Put `Dialog.Close` here. */\n children?: React.ReactNode;\n}\n\nexport interface DialogBodyProps {\n children?: React.ReactNode;\n}\n\nexport interface DialogFooterProps {\n /** Action buttons, right-aligned. */\n children?: React.ReactNode;\n /**\n * Let the buttons share the row and grow to fill it, and each line if they wrap, instead\n * of hugging the right edge at their natural width. For a footer with three actions or\n * long (translated) labels, where a plain wrap leaves the last button, usually the\n * primary one, alone, small and pushed right on a second line. Off by default, so no\n * existing dialog changes.\n */\n fill?: boolean;\n}\n\ninterface DialogContextValue {\n titleId: string;\n onClose?: () => void;\n full: boolean;\n dividers: boolean;\n hasHeader: boolean;\n hasFooter: boolean;\n}\n\nconst SIZE_W = { sm: 440, md: 600, lg: 800, xl: 1000 } as const;\n\n// Cheap, dependency-free focusable check - matches what most hand-rolled\n// focus traps use. No visibility filtering: nothing inside a Dialog is ever\n// conditionally hidden today, and jsdom doesn't compute layout (offsetParent\n// is always null there), so a visibility check would be untestable dead\n// weight rather than a real safeguard.\nconst FOCUSABLE_SELECTOR = 'a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\nfunction focusableIn(el: HTMLElement): HTMLElement[] {\n return Array.from(el.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR));\n}\n\nconst DialogContext = React.createContext<DialogContextValue | null>(null);\n\nfunction useDialogContext(component: string): DialogContextValue {\n const ctx = React.useContext(DialogContext);\n if (!ctx) throw new Error(`<Dialog.${component}> must be rendered inside <Dialog>.`);\n return ctx;\n}\n\nfunction DialogRoot({\n open = true,\n children,\n onClose,\n variant = 'center',\n size = 'sm',\n dividers = false,\n dismissible = true,\n width,\n style,\n ...rest\n}: DialogProps) {\n const sheet = variant === 'sheet';\n const full = variant === 'fullscreen';\n const rid = React.useId();\n const titleId = `${rid}-title`;\n\n // Portal target is client-only.\n const [mounted, setMounted] = React.useState(false);\n // eslint-disable-next-line react-hooks/set-state-in-effect -- portal target is client-only\n React.useEffect(() => setMounted(true), []);\n\n // While open: lock page scroll, bind Escape to close, trap Tab inside the\n // panel, and restore focus to whatever had it before opening once closed.\n // `onClose` / `dismissible` are read through refs so the effect only\n // re-runs when `open` flips.\n const onCloseRef = React.useRef(onClose);\n const dismissibleRef = React.useRef(dismissible);\n React.useEffect(() => {\n onCloseRef.current = onClose;\n dismissibleRef.current = dismissible;\n });\n const panelRef = React.useRef<HTMLDivElement>(null);\n React.useEffect(() => {\n if (!open) return;\n const previouslyFocused = document.activeElement as HTMLElement | null;\n const unlock = acquireScrollLock();\n const onKey = (e: KeyboardEvent) => {\n if (e.key === 'Escape') {\n if (dismissibleRef.current) onCloseRef.current?.();\n return;\n }\n if (e.key !== 'Tab') return;\n const panel = panelRef.current;\n if (!panel) return;\n const focusables = focusableIn(panel);\n // No focusable content (a bare Dialog.Body with plain text): keep\n // focus pinned on the panel itself rather than leaking to the page.\n if (focusables.length === 0) {\n e.preventDefault();\n return;\n }\n const first = focusables[0];\n const last = focusables[focusables.length - 1];\n if (e.shiftKey && document.activeElement === first) {\n e.preventDefault();\n last.focus();\n } else if (!e.shiftKey && document.activeElement === last) {\n e.preventDefault();\n first.focus();\n }\n };\n document.addEventListener('keydown', onKey);\n return () => {\n unlock();\n document.removeEventListener('keydown', onKey);\n // The trigger may itself have unmounted (e.g. a row it lived in was\n // removed) - focus() on a detached element is a silent no-op, not a\n // throw, so no need to guard beyond the null check.\n previouslyFocused?.focus();\n };\n }, [open]);\n\n // Pull focus into the dialog when it opens.\n React.useEffect(() => {\n if (open && mounted) panelRef.current?.focus();\n }, [open, mounted]);\n\n if (!open || !mounted) return null;\n\n // Body/Footer padding depends on whether a Header/Footer is actually\n // present - read straight off the children, the same technique\n // SidebarNav.Item / Stepper use for data they need before render.\n const items = React.Children.toArray(children);\n const hasHeader = items.some((c) => React.isValidElement(c) && c.type === Header);\n const hasFooter = items.some((c) => React.isValidElement(c) && c.type === Footer);\n\n const ctx: DialogContextValue = { titleId, onClose, full, dividers, hasHeader, hasFooter };\n\n return createPortal(\n <div\n style={sx({\n position: 'fixed',\n inset: 0,\n zIndex: 1000,\n display: 'flex',\n alignItems: sheet ? 'flex-end' : 'center',\n justifyContent: 'center',\n background: 'var(--bg-overlay)',\n backdropFilter: 'blur(2px)',\n padding: sheet || full ? 0 : 'var(--space-5)',\n })}\n onClick={dismissible ? onClose : undefined}\n >\n <div\n ref={panelRef}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-labelledby={hasHeader ? titleId : undefined}\n tabIndex={-1}\n onClick={(e) => e.stopPropagation()}\n {...rest}\n style={sx({\n width: full || sheet ? '100%' : 'min(100%,' + (width ?? SIZE_W[size]) + 'px)',\n height: full ? '100%' : undefined,\n maxHeight: full ? undefined : sheet ? '90dvh' : 'calc(100dvh - var(--space-6))',\n display: 'flex',\n flexDirection: 'column',\n overflow: 'hidden',\n outline: 'none',\n background: 'var(--bg-surface)',\n borderRadius: full ? 0 : sheet ? 'var(--radius-sheet) var(--radius-sheet) 0 0' : 'var(--radius-lg)',\n border: full ? 'none' : 'var(--border-width-hairline) solid var(--border-default)',\n boxShadow: full ? 'none' : sheet ? 'var(--shadow-sheet)' : 'var(--shadow-lg)',\n animation: sheet ? 'sereno-slide-up var(--duration-sheet) var(--ease-gentle)' : 'sereno-pop var(--duration-normal) var(--ease-out)',\n ...style,\n })}\n >\n {sheet && (\n <span\n aria-hidden\n style={sx({ width: 36, height: 4, borderRadius: '999px', background: 'var(--border-strong)', alignSelf: 'center', marginTop: 'var(--space-2)', flex: '0 0 auto' })}\n />\n )}\n <DialogContext.Provider value={ctx}>{children}</DialogContext.Provider>\n </div>\n </div>,\n document.body,\n );\n}\n\nfunction Header({ title, description, children }: DialogHeaderProps) {\n const { titleId, dividers } = useDialogContext('Header');\n const pad = 'var(--space-5)';\n const hairline = 'var(--border-width-hairline) solid var(--border-default)';\n\n const items = React.Children.toArray(children);\n const closeEl = items.find((c) => React.isValidElement(c) && c.type === Close);\n const extra = items.filter((c) => c !== closeEl);\n\n return (\n <div\n style={sx({\n flex: '0 0 auto',\n display: 'flex',\n alignItems: 'flex-start',\n gap: 'var(--space-3)',\n padding: dividers ? pad : `${pad} ${pad} var(--space-3)`,\n borderBottom: dividers ? hairline : undefined,\n })}\n >\n <div id={titleId} style={sx({ flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 'var(--space-2)' })}>\n {title && (\n <Typography as=\"h3\" variant=\"h2\" style={{ letterSpacing: 'var(--tracking-tight)' }}>\n {title}\n </Typography>\n )}\n {description && (\n <Typography variant=\"body\" color=\"secondary\">\n {description}\n </Typography>\n )}\n {extra}\n </div>\n {closeEl}\n </div>\n );\n}\n\nfunction Body({ children }: DialogBodyProps) {\n const { dividers, hasHeader, hasFooter, full } = useDialogContext('Body');\n const pad = 'var(--space-5)';\n return (\n <div\n style={sx({\n flex: full ? '1 1 auto' : '0 1 auto',\n minHeight: 0,\n overflowY: 'auto',\n padding: dividers ? pad : hasHeader ? `0 ${pad} ${hasFooter ? 'var(--space-3)' : pad}` : pad,\n })}\n >\n {children}\n </div>\n );\n}\n\nfunction Footer({ children, fill = false }: DialogFooterProps) {\n const { dividers } = useDialogContext('Footer');\n const pad = 'var(--space-5)';\n const hairline = 'var(--border-width-hairline) solid var(--border-default)';\n return (\n <div\n // `fill` (see styles.css) makes each child `flex: 1 1 auto`. It can't be inline: it's on the children.\n className=\"sereno-dialog-footer\"\n data-fill={fill || undefined}\n style={sx({\n flex: '0 0 auto',\n display: 'flex',\n gap: 'var(--space-3)',\n justifyContent: 'flex-end',\n flexWrap: 'wrap',\n padding: dividers ? pad : `0 ${pad} ${pad}`,\n borderTop: dividers ? hairline : undefined,\n })}\n >\n {children}\n </div>\n );\n}\n\nfunction Close() {\n const { onClose, full } = useDialogContext('Close');\n return (\n <button\n type=\"button\"\n className=\"sereno-dialog-close\"\n aria-label=\"Fechar\"\n onClick={onClose}\n style={sx({\n flex: '0 0 auto',\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n width: full ? 40 : 34,\n height: full ? 40 : 34,\n margin: full ? 0 : '-3px -5px 0 0',\n border: 'none',\n borderRadius: 'var(--radius-md)',\n background: full ? 'var(--bg-subtle)' : 'transparent',\n color: 'var(--text-secondary)',\n cursor: 'pointer',\n })}\n >\n <X size={full ? 22 : 18} strokeWidth={2} />\n </button>\n );\n}\n\nexport const Dialog = Object.assign(DialogRoot, { Header, Body, Footer, Close });\n"],"mappings":";AAkNM,SAyBI,KAzBJ;AAhNN,YAAY,WAAW;AACvB,SAAS,oBAAoB;AAC7B,SAAS,SAAS;AAClB,SAAS,UAAU;AACnB,SAAS,yBAAyB;AAClC,SAAS,kBAAkB;AA+E3B,MAAM,SAAS,EAAE,IAAI,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI,IAAK;AAOrD,MAAM,qBAAqB;AAC3B,SAAS,YAAY,IAAgC;AACnD,SAAO,MAAM,KAAK,GAAG,iBAA8B,kBAAkB,CAAC;AACxE;AAEA,MAAM,gBAAgB,MAAM,cAAyC,IAAI;AAEzE,SAAS,iBAAiB,WAAuC;AAC/D,QAAM,MAAM,MAAM,WAAW,aAAa;AAC1C,MAAI,CAAC,IAAK,OAAM,IAAI,MAAM,WAAW,SAAS,qCAAqC;AACnF,SAAO;AACT;AAEA,SAAS,WAAW;AAAA,EAClB,OAAO;AAAA,EACP;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV,OAAO;AAAA,EACP,WAAW;AAAA,EACX,cAAc;AAAA,EACd;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAgB;AACd,QAAM,QAAQ,YAAY;AAC1B,QAAM,OAAO,YAAY;AACzB,QAAM,MAAM,MAAM,MAAM;AACxB,QAAM,UAAU,GAAG,GAAG;AAGtB,QAAM,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R,cAAc;AAAA,QACd,YAAY,OAAO,qBAAqB;AAAA,QACxC,OAAO;AAAA,QACP,QAAQ;AAAA,MACV,CAAC;AAAA,MAED,8BAAC,KAAE,MAAM,OAAO,KAAK,IAAI,aAAa,GAAG;AAAA;AAAA,EAC3C;AAEJ;AAEO,MAAM,SAAS,OAAO,OAAO,YAAY,EAAE,QAAQ,MAAM,QAAQ,MAAM,CAAC;","names":[]}
|
|
@@ -116,28 +116,6 @@ const AvatarUpload = React.forwardRef(function AvatarUpload2({
|
|
|
116
116
|
};
|
|
117
117
|
}, [menuOpen]);
|
|
118
118
|
const step = cropSrc ? "crop" : allowCamera && cameraOpen ? "camera" : null;
|
|
119
|
-
const modalUp = step !== null;
|
|
120
|
-
React.useEffect(() => {
|
|
121
|
-
if (!modalUp) return;
|
|
122
|
-
const root = document.documentElement;
|
|
123
|
-
const prev = { h: root.style.overflow, b: document.body.style.overflow };
|
|
124
|
-
root.style.overflow = "hidden";
|
|
125
|
-
document.body.style.overflow = "hidden";
|
|
126
|
-
const onKey = (e) => {
|
|
127
|
-
if (e.key !== "Escape") return;
|
|
128
|
-
setCameraOpen(false);
|
|
129
|
-
setCropSrc((s) => {
|
|
130
|
-
if (s) URL.revokeObjectURL(s);
|
|
131
|
-
return null;
|
|
132
|
-
});
|
|
133
|
-
};
|
|
134
|
-
document.addEventListener("keydown", onKey);
|
|
135
|
-
return () => {
|
|
136
|
-
root.style.overflow = prev.h;
|
|
137
|
-
document.body.style.overflow = prev.b;
|
|
138
|
-
document.removeEventListener("keydown", onKey);
|
|
139
|
-
};
|
|
140
|
-
}, [modalUp]);
|
|
141
119
|
const pick = (files) => {
|
|
142
120
|
const f = files?.[0];
|
|
143
121
|
if (!f) return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/forms/AvatarUpload.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { Camera, Check, ImagePlus, Pencil, RotateCcw, Trash2, X, ZoomIn, ZoomOut } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { Field } from '../_internal/Field';\nimport { fieldA11y } from '../_internal/fieldA11y';\nimport { mergeRefs } from '../_internal/mergeRefs';\nimport { Dialog } from '../feedback/Dialog';\nimport { Button } from '../core/Button';\n\n/**\n * Profile-photo picker: an avatar disc with a camera button. Pick from the\n * library (or the camera on touch), frame the face in a circular crop, and it\n * hands back a **cropped, downscaled** `File` (JPEG). For attachments / documents\n * / multiple files use `FileUpload` instead.\n *\n * Client-side only downscales and re-encodes; it does not decode HEIC (no\n * browser but Safari can) - that is a server-side job. HEIC picks are rejected\n * with a message.\n */\n/** User-facing strings - English by default; pass overrides for another locale. */\nexport interface AvatarUploadLabels {\n trigger: string;\n upload: string;\n takePhoto: string;\n remove: string;\n cropTitle: string;\n cropHint: string;\n cameraTitle: string;\n cameraHint: string;\n capture: string;\n /** On the crop step, only shown for a shot taken with the camera; reopens it directly. */\n retake: string;\n cancel: string;\n save: string;\n zoom: string;\n heicError: string;\n notImage: string;\n tooLarge: (mb: number) => string;\n unreadable: string;\n cameraError: string;\n}\n\nconst EN: AvatarUploadLabels = {\n trigger: 'Change photo',\n upload: 'Upload a photo',\n takePhoto: 'Take a photo',\n remove: 'Remove photo',\n cropTitle: 'Adjust the photo',\n cropHint: 'Drag to reposition · scroll to zoom.',\n cameraTitle: 'Take a photo',\n cameraHint: 'Line your face up with the circle.',\n capture: 'Capture',\n retake: 'Retake',\n cancel: 'Cancel',\n save: 'Save',\n zoom: 'Zoom',\n heicError: \"That format (HEIC) won't open in the browser, upload a JPG or PNG.\",\n notImage: 'Choose an image file.',\n tooLarge: (mb) => `The image is over ${mb} MB.`,\n unreadable: \"Couldn't read that image. Try a JPG or PNG.\",\n cameraError: \"Couldn't open the camera: upload a photo from your library instead.\",\n};\n\nexport interface AvatarUploadProps {\n /** Full name - drives the initials fallback and the alt text. */\n name?: string;\n /** Current photo: a `File` (freshly cropped) or an existing URL string. */\n value?: File | string | null;\n onChange?: (file: File | null) => void;\n /** Disc diameter in px. */\n size?: number;\n /** Exported square size in px - the crop is drawn to this. */\n outputSize?: number;\n /** Reject picks larger than this (before crop). */\n maxSizeMB?: number;\n /** Override the English UI strings (menu, crop dialog, messages). */\n labels?: Partial<AvatarUploadLabels>;\n label?: string;\n hint?: string;\n error?: string;\n required?: boolean;\n disabled?: boolean;\n id?: string;\n containerStyle?: React.CSSProperties;\n /** Reserve the hint/error row's height even with neither set - stops the\n * field from growing the moment a validation message appears. */\n preserveHelperSpace?: boolean;\n /**\n * Whether to allow taking a photo via camera (default true).\n * Set to `false` when picking an organization or brand logo, where taking a\n * live selfie/photo makes no sense.\n */\n allowCamera?: boolean;\n}\n\nfunction initials(name: string): string {\n return (name || '')\n .trim()\n .split(/\\s+/)\n .slice(0, 2)\n .map((w) => w[0] || '')\n .join('')\n .toUpperCase();\n}\n\nconst isHeic = (f: File) => /image\\/heic|image\\/heif/i.test(f.type) || /\\.(heic|heif)$/i.test(f.name);\n\nexport const AvatarUpload = React.forwardRef<HTMLInputElement, AvatarUploadProps>(function AvatarUpload(\n {\n name = '',\n value,\n onChange,\n size = 96,\n outputSize = 512,\n maxSizeMB = 8,\n labels: labelsProp,\n label,\n hint,\n error,\n required,\n disabled,\n id,\n containerStyle,\n preserveHelperSpace,\n allowCamera = true,\n },\n forwardedRef,\n) {\n const t = React.useMemo<AvatarUploadLabels>(() => ({ ...EN, ...labelsProp }), [labelsProp]);\n const autoId = React.useId();\n const rid = id || autoId;\n const libRef = React.useRef<HTMLInputElement>(null);\n const triggerRef = React.useRef<HTMLButtonElement>(null);\n const menuRef = React.useRef<HTMLDivElement>(null);\n\n const [menuOpen, setMenuOpen] = React.useState(false);\n const [menuPos, setMenuPos] = React.useState<{ top: number; left: number } | null>(null);\n const [rejected, setRejected] = React.useState<string | null>(null);\n const [cropSrc, setCropSrc] = React.useState<string | null>(null);\n // Whether the photo now in the crop step came from the camera. Only then does the crop\n // modal offer \"Retake\" (a library pick already has its own way to change: cancel and pick\n // another file from the system's own dialog).\n const [cropFromCamera, setCropFromCamera] = React.useState(false);\n const [cameraOpen, setCameraOpen] = React.useState(false);\n const [internal, setInternal] = React.useState<File | null>(null);\n\n const current = value !== undefined ? value : internal;\n\n // Preview URL for the current photo.\n const [preview, setPreview] = React.useState<string | null>(typeof current === 'string' ? current : null);\n React.useEffect(() => {\n if (current instanceof File) {\n const u = URL.createObjectURL(current);\n // eslint-disable-next-line react-hooks/set-state-in-effect -- syncing to an object URL\n setPreview(u);\n return () => URL.revokeObjectURL(u);\n }\n setPreview(typeof current === 'string' ? current : null);\n }, [current]);\n\n const itemCount = (allowCamera ? 1 : 0) + 1 + (current ? 1 : 0);\n\n const toggleMenu = () => {\n if (!allowCamera && !current) {\n libRef.current?.click();\n return;\n }\n if (menuOpen) {\n setMenuOpen(false);\n return;\n }\n const r = triggerRef.current?.getBoundingClientRect();\n if (r) {\n const h = itemCount * 40 + 8;\n const flipUp = r.bottom + 6 + h > window.innerHeight - 8;\n setMenuPos({\n top: flipUp ? Math.max(8, r.top - 6 - h) : r.bottom + 6,\n left: Math.max(8, Math.min(r.left, window.innerWidth - 208)),\n });\n }\n setMenuOpen(true);\n };\n\n // Close the menu on outside click / Escape / scroll - it is portalled to <body>.\n React.useEffect(() => {\n if (!menuOpen) return;\n const onDown = (e: MouseEvent) => {\n const target = e.target as Node;\n if (triggerRef.current?.contains(target) || menuRef.current?.contains(target)) return;\n setMenuOpen(false);\n };\n const close = () => setMenuOpen(false);\n const onKey = (e: KeyboardEvent) => e.key === 'Escape' && close();\n document.addEventListener('mousedown', onDown);\n document.addEventListener('keydown', onKey);\n window.addEventListener('scroll', close, true);\n window.addEventListener('resize', close);\n return () => {\n document.removeEventListener('mousedown', onDown);\n document.removeEventListener('keydown', onKey);\n window.removeEventListener('scroll', close, true);\n window.removeEventListener('resize', close);\n };\n }, [menuOpen]);\n\n // Dialog doesn't lock scroll or bind Escape - do it here while a modal is up.\n // One dialog for the flow, on whichever step is current: the crop once there is a photo,\n // else the live camera. A shot or a Retake flips both at once, so the step just changes.\n const step: Step | null = cropSrc ? 'crop' : allowCamera && cameraOpen ? 'camera' : null;\n const modalUp = step !== null;\n React.useEffect(() => {\n if (!modalUp) return;\n const root = document.documentElement;\n const prev = { h: root.style.overflow, b: document.body.style.overflow };\n root.style.overflow = 'hidden';\n document.body.style.overflow = 'hidden';\n const onKey = (e: KeyboardEvent) => {\n if (e.key !== 'Escape') return;\n setCameraOpen(false);\n setCropSrc((s) => {\n if (s) URL.revokeObjectURL(s);\n return null;\n });\n };\n document.addEventListener('keydown', onKey);\n return () => {\n root.style.overflow = prev.h;\n document.body.style.overflow = prev.b;\n document.removeEventListener('keydown', onKey);\n };\n }, [modalUp]);\n\n const pick = (files: FileList | null) => {\n const f = files?.[0];\n if (!f) return;\n if (isHeic(f)) {\n setRejected(t.heicError);\n return;\n }\n if (!f.type.startsWith('image/')) {\n setRejected(t.notImage);\n return;\n }\n if (f.size > maxSizeMB * 1048576) {\n setRejected(t.tooLarge(maxSizeMB));\n return;\n }\n const url = URL.createObjectURL(f);\n const probe = new Image();\n probe.onload = () => {\n setRejected(null);\n setCropFromCamera(false);\n setCropSrc(url);\n };\n probe.onerror = () => {\n URL.revokeObjectURL(url);\n setRejected(t.unreadable);\n };\n probe.src = url;\n };\n\n const commit = (file: File | null) => {\n if (value === undefined) setInternal(file);\n onChange?.(file);\n };\n\n const onCropSave = (blob: Blob) => {\n const file = new File([blob], 'avatar.jpg', { type: 'image/jpeg' });\n if (cropSrc) URL.revokeObjectURL(cropSrc);\n setCropSrc(null);\n commit(file);\n };\n const onCropCancel = () => {\n if (cropSrc) URL.revokeObjectURL(cropSrc);\n setCropSrc(null);\n };\n\n const onCameraShot = (blob: Blob) => {\n setCameraOpen(false);\n setRejected(null);\n setCropFromCamera(true);\n setCropSrc(URL.createObjectURL(blob));\n };\n\n // Straight back to the live camera, no menu in between: the crop modal's \"Retake\".\n const onRetake = () => {\n if (cropSrc) URL.revokeObjectURL(cropSrc);\n setCropSrc(null);\n setCameraOpen(true);\n };\n\n const cameraBtn = Math.max(30, Math.round(size * 0.34));\n\n // What `Field` shows as the error: the consumer's, or a rejected pick's (type, size, unreadable).\n const shownError = error || rejected || undefined;\n // The hidden `<input type=\"file\">` is out of the accessibility tree: the pencil is what takes focus.\n const a11y = fieldA11y(rid, { hint, error: shownError });\n\n return (\n <Field label={label} hint={hint} error={shownError} required={required} htmlFor={rid} style={containerStyle} preserveHelperSpace={preserveHelperSpace}>\n <input ref={mergeRefs(libRef, forwardedRef)} id={rid} type=\"file\" accept=\"image/*\" disabled={disabled} onChange={(e) => pick(e.target.files)} style={{ display: 'none' }} />\n\n <div style={sx({ position: 'relative', width: size, height: size, flex: '0 0 auto', opacity: disabled ? 0.6 : 1 })}>\n <span\n style={sx({\n width: size,\n height: size,\n borderRadius: '999px',\n overflow: 'hidden',\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n background: preview ? 'var(--bg-subtle)' : 'color-mix(in srgb, var(--brand-500) 22%, var(--bg-surface))',\n border: '1px solid ' + (preview ? 'var(--border-subtle)' : 'color-mix(in srgb, var(--brand-500) 30%, transparent)'),\n color: 'var(--text-brand)',\n fontFamily: 'var(--font-display)',\n fontWeight: 'var(--weight-bold)',\n fontSize: Math.round(size * 0.34),\n letterSpacing: 'var(--tracking-snug)',\n })}\n >\n {preview ? (\n // eslint-disable-next-line @next/next/no-img-element\n <img src={preview} alt={name} style={sx({ width: '100%', height: '100%', objectFit: 'cover' })} />\n ) : (\n initials(name) || <ImagePlus size={Math.round(size * 0.3)} strokeWidth={1.75} />\n )}\n </span>\n\n {!disabled && (\n <button\n ref={triggerRef}\n type=\"button\"\n className=\"ds-affix-btn\"\n aria-label={t.trigger}\n aria-haspopup=\"menu\"\n aria-expanded={menuOpen}\n {...a11y}\n onClick={toggleMenu}\n style={sx({\n position: 'absolute',\n right: -2,\n bottom: -2,\n width: cameraBtn,\n height: cameraBtn,\n borderRadius: '999px',\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n background: 'var(--bg-surface)',\n border: '1px solid var(--border-default)',\n boxShadow: 'var(--shadow-sm)',\n color: 'var(--text-secondary)',\n cursor: 'pointer',\n })}\n >\n <Pencil size={Math.round(cameraBtn * 0.46)} strokeWidth={1.75} />\n </button>\n )}\n\n </div>\n\n {menuOpen &&\n menuPos &&\n createPortal(\n <div\n ref={menuRef}\n role=\"menu\"\n style={sx({\n position: 'fixed',\n top: menuPos.top,\n left: menuPos.left,\n minWidth: 200,\n zIndex: 1000,\n padding: 'var(--space-1)',\n borderRadius: 'var(--radius-md)',\n background: 'var(--bg-surface)',\n border: '1px solid var(--border-default)',\n boxShadow: 'var(--shadow-lg)',\n display: 'flex',\n flexDirection: 'column',\n })}\n >\n <MenuItem\n icon={<ImagePlus size={16} strokeWidth={1.75} />}\n label={t.upload}\n onClick={() => {\n setMenuOpen(false);\n libRef.current?.click();\n }}\n />\n {allowCamera && (\n <MenuItem\n icon={<Camera size={16} strokeWidth={1.75} />}\n label={t.takePhoto}\n onClick={() => {\n setMenuOpen(false);\n setRejected(null);\n setCameraOpen(true);\n }}\n />\n )}\n {current && (\n <MenuItem\n icon={<Trash2 size={16} strokeWidth={1.75} />}\n label={t.remove}\n danger\n onClick={() => {\n setMenuOpen(false);\n commit(null);\n }}\n />\n )}\n </div>,\n document.body,\n )}\n\n {step && (\n <CaptureDialog\n step={step}\n src={cropSrc}\n outputSize={outputSize}\n labels={t}\n onClose={step === 'camera' ? () => setCameraOpen(false) : onCropCancel}\n onCameraShot={onCameraShot}\n onCameraError={() => {\n setCameraOpen(false);\n setRejected(t.cameraError);\n }}\n onSave={onCropSave}\n onRetake={cropFromCamera ? onRetake : undefined}\n />\n )}\n </Field>\n );\n});\n\nAvatarUpload.displayName = 'AvatarUpload';\n\nfunction MenuItem({ icon, label, onClick, danger }: { icon: React.ReactNode; label: string; onClick: () => void; danger?: boolean }) {\n const [hover, setHover] = React.useState(false);\n return (\n <button\n type=\"button\"\n role=\"menuitem\"\n onClick={onClick}\n onMouseEnter={() => setHover(true)}\n onMouseLeave={() => setHover(false)}\n style={sx({\n display: 'flex',\n alignItems: 'center',\n gap: 'var(--space-2)',\n width: '100%',\n minHeight: 40,\n padding: '0 var(--space-3)',\n border: 'none',\n borderRadius: 'var(--radius-sm)',\n background: hover ? 'var(--bg-subtle)' : 'transparent',\n cursor: 'pointer',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-sm)',\n color: danger ? 'var(--interactive-error)' : 'var(--text-primary)',\n textAlign: 'left',\n })}\n >\n {icon}\n {label}\n </button>\n );\n}\n\nconst DEFAULT_STAGE = 280; // crop stage's assumed size (px) before its own ResizeObserver measures it\n\n/**\n * Width of the camera and crop dialogs. They are two steps of one flow (a shot goes straight\n * to the crop), so they share it: a dialog that changed size between the steps would jump.\n * Wider than `Dialog`'s default 352: with Retake the crop footer has three real Buttons, and\n * in Portuguese (\"Tirar outra\", \"Cancelar\", \"Gravar\") they add up to 384px, more than the\n * 358px of content a 400px dialog leaves. 440 gives 398px, so they fit on one line with ~14px\n * to spare. `Dialog` already caps at `min(100%, ...)` for narrow viewports (see\n * feedback/Dialog.tsx), so a phone just gets a narrower dialog. Widening only moves the limit\n * though: the crop footer's `fill` is what keeps a longer language, or that phone, from\n * stranding the primary button.\n */\nconst MODAL_WIDTH = 440;\n\n/** Height reserved for the zoom row, so the camera step (which has none) is as tall as the crop step. */\nconst ZOOM_ROW_HEIGHT = 24;\n\n/**\n * The square viewport + circular guide, shared by the crop and camera modals.\n * `width: 100%` + `aspectRatio: 1`, not a fixed pixel box: it spans exactly the same\n * width as `Dialog.Header`'s title and `Dialog.Footer`'s buttons (both just block-level\n * or flex content inside the same padded `Dialog.Body`), instead of a fixed size\n * centered with margins of its own that didn't match theirs (SS-322 follow-up, the\n * stage read as misaligned from the rest of the dialog). Also needs no separate\n * mobile-width handling of its own: whatever width the dialog ends up at (already\n * responsive, see `feedback/Dialog.tsx`), the stage fills it exactly, staying square\n * via `aspectRatio`.\n */\nfunction CropStage({ children, onPointerDown, onPointerMove, onPointerUp, onWheel, stageRef }: {\n children: React.ReactNode;\n onPointerDown?: (e: React.PointerEvent) => void;\n onPointerMove?: (e: React.PointerEvent) => void;\n onPointerUp?: (e: React.PointerEvent) => void;\n onWheel?: (e: React.WheelEvent) => void;\n /** `useCropper` reads the live rendered size off this to drive the crop math (`V`). */\n stageRef?: React.Ref<HTMLDivElement>;\n}) {\n return (\n <div\n ref={stageRef}\n onPointerDown={onPointerDown}\n onPointerMove={onPointerMove}\n onPointerUp={onPointerUp}\n onPointerCancel={onPointerUp}\n onWheel={onWheel}\n style={sx({\n position: 'relative',\n width: '100%',\n aspectRatio: '1',\n overflow: 'hidden',\n borderRadius: 'var(--radius-lg)',\n background: 'var(--bg-sunken)',\n cursor: onPointerDown ? 'grab' : 'default',\n touchAction: 'none',\n })}\n >\n {children}\n <span\n style={sx({\n position: 'absolute',\n inset: 0,\n pointerEvents: 'none',\n borderRadius: '999px',\n boxShadow: '0 0 0 9999px color-mix(in srgb, var(--bg-overlay) 80%, transparent)',\n outline: '1px solid rgba(255, 255, 255, 0.9)',\n outlineOffset: -1,\n })}\n />\n </div>\n );\n}\n\n/** Which step of the photo flow the dialog is on. */\ntype Step = 'camera' | 'crop';\n\n/**\n * Live camera via `getUserMedia`, while `active`. A failure (no API, permission denied)\n * goes through `onError`. `ready` turns true once the stream is flowing; going inactive\n * stops the tracks, so the camera light goes off as soon as the dialog leaves this step.\n */\nfunction useCamera(active: boolean, onError: () => void) {\n const videoRef = React.useRef<HTMLVideoElement | null>(null);\n const streamRef = React.useRef<MediaStream | null>(null);\n const [ready, setReady] = React.useState(false);\n // Read through a ref so a new `onError` closure each render does not restart the camera.\n const onErrorRef = React.useRef(onError);\n React.useEffect(() => {\n onErrorRef.current = onError;\n });\n\n React.useEffect(() => {\n if (!active) return;\n let cancelled = false;\n let started: MediaStream | null = null;\n const md = typeof navigator !== 'undefined' ? navigator.mediaDevices : undefined;\n if (!md?.getUserMedia) {\n onErrorRef.current();\n return;\n }\n md.getUserMedia({ video: { facingMode: 'user', width: { ideal: 1280 }, height: { ideal: 1280 } }, audio: false })\n .then((s) => {\n if (cancelled) {\n s.getTracks().forEach((tr) => tr.stop());\n return;\n }\n started = s;\n streamRef.current = s;\n if (videoRef.current) videoRef.current.srcObject = s;\n setReady(true);\n })\n .catch(() => onErrorRef.current());\n return () => {\n cancelled = true;\n started?.getTracks().forEach((tr) => tr.stop());\n streamRef.current = null;\n setReady(false);\n };\n }, [active]);\n\n // The `<video>` may mount after the stream arrives (`Dialog` renders its children a render\n // late) or the other way round, so wire them up whichever comes last: here for the element,\n // above for the stream.\n const attachVideo = React.useCallback((el: HTMLVideoElement | null) => {\n videoRef.current = el;\n if (el && streamRef.current) el.srcObject = streamRef.current;\n }, []);\n\n /** Grabs the centred square of the current frame, mirrored like the preview, as a JPEG. */\n const shoot = (onShot: (b: Blob) => void) => {\n const v = videoRef.current;\n if (!v || !v.videoWidth) return;\n const s = Math.min(v.videoWidth, v.videoHeight);\n const canvas = document.createElement('canvas');\n canvas.width = canvas.height = s;\n const ctx = canvas.getContext('2d');\n if (!ctx) return;\n ctx.translate(s, 0);\n ctx.scale(-1, 1);\n ctx.drawImage(v, (v.videoWidth - s) / 2, (v.videoHeight - s) / 2, s, s, 0, 0, s, s);\n canvas.toBlob((b) => b && onShot(b), 'image/jpeg', 0.9);\n };\n\n return { attachVideo, ready, shoot };\n}\n\n/**\n * The crop state and math for one picked photo (`src`): pan, zoom, the stage's live size,\n * and the export. It lives above the dialog, not inside the crop step, so the header, body\n * and footer of a single `Dialog` can all read it while the camera step swaps in and out.\n * Everything resets when `src` changes, so a retaken photo starts centred at 1x.\n */\nfunction useCropper(src: string | null, outputSize: number) {\n const [imgEl, setImgEl] = React.useState<HTMLImageElement | null>(null);\n // A *callback* ref (kept as state), not a plain `useRef` + a `[]`-effect: `Dialog` renders\n // its children only from the render *after* its own `mounted` flips true (SSR-safe portal),\n // so on the stage's very first mount a `useEffect(..., [])` reading `stageRef.current` at\n // that point would still see `null` and, with no deps to fire again on, never retry, so `V`\n // would then stay stuck at the `DEFAULT_STAGE` guess forever (this exact bug, caught live:\n // the displayed image stayed 280px inside a stage CSS had already sized at ~344px, a gray\n // gap on two edges). The callback fires the moment React actually attaches the node.\n const [stageEl, setStageEl] = React.useState<HTMLDivElement | null>(null);\n // The stage's own live rendered size (it's `width: 100%` of the dialog body now, not a\n // fixed px box), read via ResizeObserver. `DEFAULT_STAGE` is only the guess for the very\n // first paint, before the observer's first callback lands.\n const [V, setV] = React.useState(DEFAULT_STAGE);\n const prevV = React.useRef(V);\n const [nat, setNat] = React.useState<{ w: number; h: number } | null>(null);\n const [zoom, setZoom] = React.useState(1);\n const [offset, setOffset] = React.useState({ x: 0, y: 0 });\n const drag = React.useRef<{ x: number; y: number } | null>(null);\n\n // A new photo starts from scratch. Adjusting state while rendering (rather than in an\n // effect) means the stale pan / zoom is never painted against the new image.\n const [seenSrc, setSeenSrc] = React.useState(src);\n if (src !== seenSrc) {\n setSeenSrc(src);\n setNat(null);\n setZoom(1);\n setOffset({ x: 0, y: 0 });\n }\n\n React.useEffect(() => {\n if (!stageEl) return;\n const ro = new ResizeObserver((entries) => {\n const w = Math.round(entries[0]?.contentRect.width ?? 0);\n if (!w || w === prevV.current) return;\n // A live resize while the dialog is open (a phone rotated, a window resized) or the\n // very first real measurement replacing `DEFAULT_STAGE`: rescale the pan offset by\n // the same factor as the viewport itself, so the framed crop doesn't jump. `scale`\n // (see below) is linear in `V`, so multiplying the offset by `newV / oldV` keeps\n // the same fraction of the image framed.\n const factor = w / prevV.current;\n prevV.current = w;\n setV(w);\n setOffset((o) => ({ x: o.x * factor, y: o.y * factor }));\n });\n ro.observe(stageEl);\n return () => ro.disconnect();\n }, [stageEl]);\n\n const scaleMin = nat ? V / Math.min(nat.w, nat.h) : 1;\n const scale = scaleMin * zoom;\n const dispW = nat ? nat.w * scale : V;\n const dispH = nat ? nat.h * scale : V;\n\n const clamp = React.useCallback(\n (o: { x: number; y: number }) => ({\n x: Math.min(0, Math.max(V - dispW, o.x)),\n y: Math.min(0, Math.max(V - dispH, o.y)),\n }),\n [V, dispW, dispH],\n );\n\n const onImgLoad = (el: HTMLImageElement) => {\n const w = el.naturalWidth;\n const h = el.naturalHeight;\n setNat({ w, h });\n const s = V / Math.min(w, h);\n setOffset({ x: (V - w * s) / 2, y: (V - h * s) / 2 });\n };\n\n const setZoomAt = (nextZoom: number) => {\n const z = Math.min(3, Math.max(1, nextZoom));\n setZoom((prevZ) => {\n const oldScale = scaleMin * prevZ;\n const newScale = scaleMin * z;\n setOffset((o) => {\n const imgX = (V / 2 - o.x) / oldScale;\n const imgY = (V / 2 - o.y) / oldScale;\n return clamp({ x: V / 2 - imgX * newScale, y: V / 2 - imgY * newScale });\n });\n return z;\n });\n };\n\n const onPointerDown = (e: React.PointerEvent) => {\n (e.target as HTMLElement).setPointerCapture(e.pointerId);\n drag.current = { x: e.clientX, y: e.clientY };\n };\n const onPointerMove = (e: React.PointerEvent) => {\n if (!drag.current) return;\n const dx = e.clientX - drag.current.x;\n const dy = e.clientY - drag.current.y;\n drag.current = { x: e.clientX, y: e.clientY };\n setOffset((o) => clamp({ x: o.x + dx, y: o.y + dy }));\n };\n const onPointerUp = () => {\n drag.current = null;\n };\n\n const save = (onSave: (b: Blob) => void) => {\n if (!imgEl || !nat) return;\n const canvas = document.createElement('canvas');\n canvas.width = canvas.height = outputSize;\n const ctx = canvas.getContext('2d');\n if (!ctx) return;\n const sSize = V / scale;\n ctx.drawImage(imgEl, -offset.x / scale, -offset.y / scale, sSize, sSize, 0, 0, outputSize, outputSize);\n canvas.toBlob((b) => b && onSave(b), 'image/jpeg', 0.85);\n };\n\n return { setImgEl, setStageEl, zoom, setZoomAt, offset, dispW, dispH, onImgLoad, onPointerDown, onPointerMove, onPointerUp, save };\n}\n\n/**\n * The one dialog for the whole photo flow: the live camera, then the crop (and back, on\n * Retake). It stays mounted across the steps and only its header text, stage and buttons\n * swap, so the panel does not close and reopen (no second pop-in, no scroll-lock or focus\n * hand-off) and it keeps one size. `Dialog.Header` / `Body` / `Footer` are direct children\n * on purpose: `Dialog` reads them off its children to pad the body and label itself, which\n * a wrapper component per step would hide from it.\n */\nfunction CaptureDialog({\n step,\n src,\n outputSize,\n labels,\n onClose,\n onCameraShot,\n onCameraError,\n onSave,\n onRetake,\n}: {\n step: Step;\n /** The photo being cropped; only set on the crop step. */\n src: string | null;\n outputSize: number;\n labels: AvatarUploadLabels;\n onClose: () => void;\n onCameraShot: (b: Blob) => void;\n onCameraError: () => void;\n onSave: (b: Blob) => void;\n /** Only set for a shot taken with the camera; shows the \"Retake\" button. */\n onRetake?: () => void;\n}) {\n const isCamera = step === 'camera';\n const camera = useCamera(isCamera, onCameraError);\n const crop = useCropper(src, outputSize);\n\n // The step's buttons unmount with it, and with them the focused one: without this, focus\n // would fall to the page behind the dialog and Tab would leave the trap. `Dialog` only\n // pulls focus in when it opens, so do it again on every step change.\n const [contentEl, setContentEl] = React.useState<HTMLDivElement | null>(null);\n React.useEffect(() => {\n contentEl?.closest<HTMLElement>('[role=\"dialog\"]')?.focus();\n }, [step, contentEl]);\n\n /* eslint-disable react-hooks/refs -- `useCamera` / `useCropper` return event handlers that reach a\n ref (`videoRef`, the drag origin), so the lint marks every property read off them; but those\n refs are only touched when a handler runs from an event, never during this render. */\n return (\n <Dialog width={MODAL_WIDTH} onClose={onClose}>\n <Dialog.Header title={isCamera ? labels.cameraTitle : labels.cropTitle} description={isCamera ? labels.cameraHint : labels.cropHint} />\n <Dialog.Body>\n <div ref={setContentEl}>\n {isCamera ? (\n <CropStage key=\"camera\">\n <video ref={camera.attachVideo} autoPlay playsInline muted style={sx({ width: '100%', height: '100%', objectFit: 'cover', transform: 'scaleX(-1)' })} />\n </CropStage>\n ) : (\n <CropStage\n key=\"crop\"\n stageRef={crop.setStageEl}\n onPointerDown={crop.onPointerDown}\n onPointerMove={crop.onPointerMove}\n onPointerUp={crop.onPointerUp}\n onWheel={(e) => crop.setZoomAt(crop.zoom - e.deltaY * 0.002)}\n >\n {src && (\n // eslint-disable-next-line @next/next/no-img-element\n <img\n ref={crop.setImgEl}\n src={src}\n alt=\"\"\n draggable={false}\n onLoad={(e) => crop.onImgLoad(e.currentTarget)}\n style={sx({ position: 'absolute', left: crop.offset.x, top: crop.offset.y, width: crop.dispW, height: crop.dispH, maxWidth: 'none', userSelect: 'none', pointerEvents: 'none' })}\n />\n )}\n </CropStage>\n )}\n\n {/* The zoom row is only there on the crop step, but the camera step keeps its room, so the dialog is the same height on both. */}\n <div style={sx({ display: 'flex', alignItems: 'center', gap: 'var(--space-3)', marginTop: 'var(--space-4)', minHeight: ZOOM_ROW_HEIGHT, color: 'var(--text-muted)' })}>\n {!isCamera && (\n <>\n <ZoomOut size={16} strokeWidth={1.75} style={{ flex: '0 0 auto' }} />\n <input\n type=\"range\"\n min={1}\n max={3}\n step={0.01}\n value={crop.zoom}\n onChange={(e) => crop.setZoomAt(Number(e.target.value))}\n aria-label={labels.zoom}\n style={sx({ flex: 1, accentColor: 'var(--interactive-primary)' })}\n />\n <ZoomIn size={16} strokeWidth={1.75} style={{ flex: '0 0 auto' }} />\n </>\n )}\n </div>\n </div>\n </Dialog.Body>\n {/* Three actions (crop after a camera shot, with Retake) share the row and each line they wrap onto; two stay right-aligned, as before. */}\n <Dialog.Footer fill={!isCamera && Boolean(onRetake)}>\n {isCamera ? (\n <React.Fragment key=\"camera\">\n <Button variant=\"secondary\" iconLeft={<X size={16} strokeWidth={2} />} onClick={onClose}>\n {labels.cancel}\n </Button>\n <Button iconLeft={<Camera size={16} strokeWidth={2} />} onClick={() => camera.shoot(onCameraShot)} disabled={!camera.ready}>\n {labels.capture}\n </Button>\n </React.Fragment>\n ) : (\n <React.Fragment key=\"crop\">\n {onRetake && (\n <Button variant=\"secondary\" iconLeft={<RotateCcw size={16} strokeWidth={2} />} onClick={onRetake}>\n {labels.retake}\n </Button>\n )}\n <Button variant=\"secondary\" iconLeft={<X size={16} strokeWidth={2} />} onClick={onClose}>\n {labels.cancel}\n </Button>\n <Button iconLeft={<Check size={16} strokeWidth={2.5} />} onClick={() => crop.save(onSave)}>\n {labels.save}\n </Button>\n </React.Fragment>\n )}\n </Dialog.Footer>\n </Dialog>\n );\n /* eslint-enable react-hooks/refs */\n}\n"],"mappings":";AA+SM,SAqgBQ,UArgBR,KAEA,YAFA;AA7SN,YAAY,WAAW;AACvB,SAAS,oBAAoB;AAC7B,SAAS,QAAQ,OAAO,WAAW,QAAQ,WAAW,QAAQ,GAAG,QAAQ,eAAe;AACxF,SAAS,UAAU;AACnB,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AACvB,SAAS,cAAc;AAmCvB,MAAM,KAAyB;AAAA,EAC7B,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,UAAU;AAAA,EACV,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,MAAM;AAAA,EACN,WAAW;AAAA,EACX,UAAU;AAAA,EACV,UAAU,CAAC,OAAO,qBAAqB,EAAE;AAAA,EACzC,YAAY;AAAA,EACZ,aAAa;AACf;AAkCA,SAAS,SAAS,MAAsB;AACtC,UAAQ,QAAQ,IACb,KAAK,EACL,MAAM,KAAK,EACX,MAAM,GAAG,CAAC,EACV,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EACrB,KAAK,EAAE,EACP,YAAY;AACjB;AAEA,MAAM,SAAS,CAAC,MAAY,2BAA2B,KAAK,EAAE,IAAI,KAAK,kBAAkB,KAAK,EAAE,IAAI;AAE7F,MAAM,eAAe,MAAM,WAAgD,SAASA,cACzF;AAAA,EACE,OAAO;AAAA,EACP;AAAA,EACA;AAAA,EACA,OAAO;AAA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AAC,KAAE,MAAM,IAAI,aAAa,GAAG,GAAI,SAAS,SAC7E,iBAAO,QACV;AAAA,MACA,oBAAC,UAAO,UAAU,oBAAC,UAAO,MAAM,IAAI,aAAa,GAAG,GAAI,SAAS,MAAM,OAAO,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,OAClH,iBAAO,SACV;AAAA,SANkB,QAOpB,IAEA,qBAAC,MAAM,UAAN,EACE;AAAA,kBACC,oBAAC,UAAO,SAAQ,aAAY,UAAU,oBAAC,aAAU,MAAM,IAAI,aAAa,GAAG,GAAI,SAAS,UACrF,iBAAO,QACV;AAAA,MAEF,oBAAC,UAAO,SAAQ,aAAY,UAAU,oBAAC,KAAE,MAAM,IAAI,aAAa,GAAG,GAAI,SAAS,SAC7E,iBAAO,QACV;AAAA,MACA,oBAAC,UAAO,UAAU,oBAAC,SAAM,MAAM,IAAI,aAAa,KAAK,GAAI,SAAS,MAAM,KAAK,KAAK,MAAM,GACrF,iBAAO,MACV;AAAA,SAXkB,MAYpB,GAEJ;AAAA,KACF;AAGJ;","names":["AvatarUpload"]}
|
|
1
|
+
{"version":3,"sources":["../../src/forms/AvatarUpload.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { Camera, Check, ImagePlus, Pencil, RotateCcw, Trash2, X, ZoomIn, ZoomOut } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { Field } from '../_internal/Field';\nimport { fieldA11y } from '../_internal/fieldA11y';\nimport { mergeRefs } from '../_internal/mergeRefs';\nimport { Dialog } from '../feedback/Dialog';\nimport { Button } from '../core/Button';\n\n/**\n * Profile-photo picker: an avatar disc with a camera button. Pick from the\n * library (or the camera on touch), frame the face in a circular crop, and it\n * hands back a **cropped, downscaled** `File` (JPEG). For attachments / documents\n * / multiple files use `FileUpload` instead.\n *\n * Client-side only downscales and re-encodes; it does not decode HEIC (no\n * browser but Safari can) - that is a server-side job. HEIC picks are rejected\n * with a message.\n */\n/** User-facing strings - English by default; pass overrides for another locale. */\nexport interface AvatarUploadLabels {\n trigger: string;\n upload: string;\n takePhoto: string;\n remove: string;\n cropTitle: string;\n cropHint: string;\n cameraTitle: string;\n cameraHint: string;\n capture: string;\n /** On the crop step, only shown for a shot taken with the camera; reopens it directly. */\n retake: string;\n cancel: string;\n save: string;\n zoom: string;\n heicError: string;\n notImage: string;\n tooLarge: (mb: number) => string;\n unreadable: string;\n cameraError: string;\n}\n\nconst EN: AvatarUploadLabels = {\n trigger: 'Change photo',\n upload: 'Upload a photo',\n takePhoto: 'Take a photo',\n remove: 'Remove photo',\n cropTitle: 'Adjust the photo',\n cropHint: 'Drag to reposition · scroll to zoom.',\n cameraTitle: 'Take a photo',\n cameraHint: 'Line your face up with the circle.',\n capture: 'Capture',\n retake: 'Retake',\n cancel: 'Cancel',\n save: 'Save',\n zoom: 'Zoom',\n heicError: \"That format (HEIC) won't open in the browser, upload a JPG or PNG.\",\n notImage: 'Choose an image file.',\n tooLarge: (mb) => `The image is over ${mb} MB.`,\n unreadable: \"Couldn't read that image. Try a JPG or PNG.\",\n cameraError: \"Couldn't open the camera: upload a photo from your library instead.\",\n};\n\nexport interface AvatarUploadProps {\n /** Full name - drives the initials fallback and the alt text. */\n name?: string;\n /** Current photo: a `File` (freshly cropped) or an existing URL string. */\n value?: File | string | null;\n onChange?: (file: File | null) => void;\n /** Disc diameter in px. */\n size?: number;\n /** Exported square size in px - the crop is drawn to this. */\n outputSize?: number;\n /** Reject picks larger than this (before crop). */\n maxSizeMB?: number;\n /** Override the English UI strings (menu, crop dialog, messages). */\n labels?: Partial<AvatarUploadLabels>;\n label?: string;\n hint?: string;\n error?: string;\n required?: boolean;\n disabled?: boolean;\n id?: string;\n containerStyle?: React.CSSProperties;\n /** Reserve the hint/error row's height even with neither set - stops the\n * field from growing the moment a validation message appears. */\n preserveHelperSpace?: boolean;\n /**\n * Whether to allow taking a photo via camera (default true).\n * Set to `false` when picking an organization or brand logo, where taking a\n * live selfie/photo makes no sense.\n */\n allowCamera?: boolean;\n}\n\nfunction initials(name: string): string {\n return (name || '')\n .trim()\n .split(/\\s+/)\n .slice(0, 2)\n .map((w) => w[0] || '')\n .join('')\n .toUpperCase();\n}\n\nconst isHeic = (f: File) => /image\\/heic|image\\/heif/i.test(f.type) || /\\.(heic|heif)$/i.test(f.name);\n\nexport const AvatarUpload = React.forwardRef<HTMLInputElement, AvatarUploadProps>(function AvatarUpload(\n {\n name = '',\n value,\n onChange,\n size = 96,\n outputSize = 512,\n maxSizeMB = 8,\n labels: labelsProp,\n label,\n hint,\n error,\n required,\n disabled,\n id,\n containerStyle,\n preserveHelperSpace,\n allowCamera = true,\n },\n forwardedRef,\n) {\n const t = React.useMemo<AvatarUploadLabels>(() => ({ ...EN, ...labelsProp }), [labelsProp]);\n const autoId = React.useId();\n const rid = id || autoId;\n const libRef = React.useRef<HTMLInputElement>(null);\n const triggerRef = React.useRef<HTMLButtonElement>(null);\n const menuRef = React.useRef<HTMLDivElement>(null);\n\n const [menuOpen, setMenuOpen] = React.useState(false);\n const [menuPos, setMenuPos] = React.useState<{ top: number; left: number } | null>(null);\n const [rejected, setRejected] = React.useState<string | null>(null);\n const [cropSrc, setCropSrc] = React.useState<string | null>(null);\n // Whether the photo now in the crop step came from the camera. Only then does the crop\n // modal offer \"Retake\" (a library pick already has its own way to change: cancel and pick\n // another file from the system's own dialog).\n const [cropFromCamera, setCropFromCamera] = React.useState(false);\n const [cameraOpen, setCameraOpen] = React.useState(false);\n const [internal, setInternal] = React.useState<File | null>(null);\n\n const current = value !== undefined ? value : internal;\n\n // Preview URL for the current photo.\n const [preview, setPreview] = React.useState<string | null>(typeof current === 'string' ? current : null);\n React.useEffect(() => {\n if (current instanceof File) {\n const u = URL.createObjectURL(current);\n // eslint-disable-next-line react-hooks/set-state-in-effect -- syncing to an object URL\n setPreview(u);\n return () => URL.revokeObjectURL(u);\n }\n setPreview(typeof current === 'string' ? current : null);\n }, [current]);\n\n const itemCount = (allowCamera ? 1 : 0) + 1 + (current ? 1 : 0);\n\n const toggleMenu = () => {\n if (!allowCamera && !current) {\n libRef.current?.click();\n return;\n }\n if (menuOpen) {\n setMenuOpen(false);\n return;\n }\n const r = triggerRef.current?.getBoundingClientRect();\n if (r) {\n const h = itemCount * 40 + 8;\n const flipUp = r.bottom + 6 + h > window.innerHeight - 8;\n setMenuPos({\n top: flipUp ? Math.max(8, r.top - 6 - h) : r.bottom + 6,\n left: Math.max(8, Math.min(r.left, window.innerWidth - 208)),\n });\n }\n setMenuOpen(true);\n };\n\n // Close the menu on outside click / Escape / scroll - it is portalled to <body>.\n React.useEffect(() => {\n if (!menuOpen) return;\n const onDown = (e: MouseEvent) => {\n const target = e.target as Node;\n if (triggerRef.current?.contains(target) || menuRef.current?.contains(target)) return;\n setMenuOpen(false);\n };\n const close = () => setMenuOpen(false);\n const onKey = (e: KeyboardEvent) => e.key === 'Escape' && close();\n document.addEventListener('mousedown', onDown);\n document.addEventListener('keydown', onKey);\n window.addEventListener('scroll', close, true);\n window.addEventListener('resize', close);\n return () => {\n document.removeEventListener('mousedown', onDown);\n document.removeEventListener('keydown', onKey);\n window.removeEventListener('scroll', close, true);\n window.removeEventListener('resize', close);\n };\n }, [menuOpen]);\n\n // One dialog for the flow, on whichever step is current: the crop once there is a photo,\n // else the live camera. A shot or a Retake flips both at once, so the step just changes.\n // The `Dialog` it is drawn in already locks the page scroll and closes on Escape (through the\n // `onClose` handed to it below), so nothing here does: a second lock of our own used to be\n // released after the Dialog's and left the page unable to scroll (SS-402).\n const step: Step | null = cropSrc ? 'crop' : allowCamera && cameraOpen ? 'camera' : null;\n\n const pick = (files: FileList | null) => {\n const f = files?.[0];\n if (!f) return;\n if (isHeic(f)) {\n setRejected(t.heicError);\n return;\n }\n if (!f.type.startsWith('image/')) {\n setRejected(t.notImage);\n return;\n }\n if (f.size > maxSizeMB * 1048576) {\n setRejected(t.tooLarge(maxSizeMB));\n return;\n }\n const url = URL.createObjectURL(f);\n const probe = new Image();\n probe.onload = () => {\n setRejected(null);\n setCropFromCamera(false);\n setCropSrc(url);\n };\n probe.onerror = () => {\n URL.revokeObjectURL(url);\n setRejected(t.unreadable);\n };\n probe.src = url;\n };\n\n const commit = (file: File | null) => {\n if (value === undefined) setInternal(file);\n onChange?.(file);\n };\n\n const onCropSave = (blob: Blob) => {\n const file = new File([blob], 'avatar.jpg', { type: 'image/jpeg' });\n if (cropSrc) URL.revokeObjectURL(cropSrc);\n setCropSrc(null);\n commit(file);\n };\n const onCropCancel = () => {\n if (cropSrc) URL.revokeObjectURL(cropSrc);\n setCropSrc(null);\n };\n\n const onCameraShot = (blob: Blob) => {\n setCameraOpen(false);\n setRejected(null);\n setCropFromCamera(true);\n setCropSrc(URL.createObjectURL(blob));\n };\n\n // Straight back to the live camera, no menu in between: the crop modal's \"Retake\".\n const onRetake = () => {\n if (cropSrc) URL.revokeObjectURL(cropSrc);\n setCropSrc(null);\n setCameraOpen(true);\n };\n\n const cameraBtn = Math.max(30, Math.round(size * 0.34));\n\n // What `Field` shows as the error: the consumer's, or a rejected pick's (type, size, unreadable).\n const shownError = error || rejected || undefined;\n // The hidden `<input type=\"file\">` is out of the accessibility tree: the pencil is what takes focus.\n const a11y = fieldA11y(rid, { hint, error: shownError });\n\n return (\n <Field label={label} hint={hint} error={shownError} required={required} htmlFor={rid} style={containerStyle} preserveHelperSpace={preserveHelperSpace}>\n <input ref={mergeRefs(libRef, forwardedRef)} id={rid} type=\"file\" accept=\"image/*\" disabled={disabled} onChange={(e) => pick(e.target.files)} style={{ display: 'none' }} />\n\n <div style={sx({ position: 'relative', width: size, height: size, flex: '0 0 auto', opacity: disabled ? 0.6 : 1 })}>\n <span\n style={sx({\n width: size,\n height: size,\n borderRadius: '999px',\n overflow: 'hidden',\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n background: preview ? 'var(--bg-subtle)' : 'color-mix(in srgb, var(--brand-500) 22%, var(--bg-surface))',\n border: '1px solid ' + (preview ? 'var(--border-subtle)' : 'color-mix(in srgb, var(--brand-500) 30%, transparent)'),\n color: 'var(--text-brand)',\n fontFamily: 'var(--font-display)',\n fontWeight: 'var(--weight-bold)',\n fontSize: Math.round(size * 0.34),\n letterSpacing: 'var(--tracking-snug)',\n })}\n >\n {preview ? (\n // eslint-disable-next-line @next/next/no-img-element\n <img src={preview} alt={name} style={sx({ width: '100%', height: '100%', objectFit: 'cover' })} />\n ) : (\n initials(name) || <ImagePlus size={Math.round(size * 0.3)} strokeWidth={1.75} />\n )}\n </span>\n\n {!disabled && (\n <button\n ref={triggerRef}\n type=\"button\"\n className=\"ds-affix-btn\"\n aria-label={t.trigger}\n aria-haspopup=\"menu\"\n aria-expanded={menuOpen}\n {...a11y}\n onClick={toggleMenu}\n style={sx({\n position: 'absolute',\n right: -2,\n bottom: -2,\n width: cameraBtn,\n height: cameraBtn,\n borderRadius: '999px',\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n background: 'var(--bg-surface)',\n border: '1px solid var(--border-default)',\n boxShadow: 'var(--shadow-sm)',\n color: 'var(--text-secondary)',\n cursor: 'pointer',\n })}\n >\n <Pencil size={Math.round(cameraBtn * 0.46)} strokeWidth={1.75} />\n </button>\n )}\n\n </div>\n\n {menuOpen &&\n menuPos &&\n createPortal(\n <div\n ref={menuRef}\n role=\"menu\"\n style={sx({\n position: 'fixed',\n top: menuPos.top,\n left: menuPos.left,\n minWidth: 200,\n zIndex: 1000,\n padding: 'var(--space-1)',\n borderRadius: 'var(--radius-md)',\n background: 'var(--bg-surface)',\n border: '1px solid var(--border-default)',\n boxShadow: 'var(--shadow-lg)',\n display: 'flex',\n flexDirection: 'column',\n })}\n >\n <MenuItem\n icon={<ImagePlus size={16} strokeWidth={1.75} />}\n label={t.upload}\n onClick={() => {\n setMenuOpen(false);\n libRef.current?.click();\n }}\n />\n {allowCamera && (\n <MenuItem\n icon={<Camera size={16} strokeWidth={1.75} />}\n label={t.takePhoto}\n onClick={() => {\n setMenuOpen(false);\n setRejected(null);\n setCameraOpen(true);\n }}\n />\n )}\n {current && (\n <MenuItem\n icon={<Trash2 size={16} strokeWidth={1.75} />}\n label={t.remove}\n danger\n onClick={() => {\n setMenuOpen(false);\n commit(null);\n }}\n />\n )}\n </div>,\n document.body,\n )}\n\n {step && (\n <CaptureDialog\n step={step}\n src={cropSrc}\n outputSize={outputSize}\n labels={t}\n onClose={step === 'camera' ? () => setCameraOpen(false) : onCropCancel}\n onCameraShot={onCameraShot}\n onCameraError={() => {\n setCameraOpen(false);\n setRejected(t.cameraError);\n }}\n onSave={onCropSave}\n onRetake={cropFromCamera ? onRetake : undefined}\n />\n )}\n </Field>\n );\n});\n\nAvatarUpload.displayName = 'AvatarUpload';\n\nfunction MenuItem({ icon, label, onClick, danger }: { icon: React.ReactNode; label: string; onClick: () => void; danger?: boolean }) {\n const [hover, setHover] = React.useState(false);\n return (\n <button\n type=\"button\"\n role=\"menuitem\"\n onClick={onClick}\n onMouseEnter={() => setHover(true)}\n onMouseLeave={() => setHover(false)}\n style={sx({\n display: 'flex',\n alignItems: 'center',\n gap: 'var(--space-2)',\n width: '100%',\n minHeight: 40,\n padding: '0 var(--space-3)',\n border: 'none',\n borderRadius: 'var(--radius-sm)',\n background: hover ? 'var(--bg-subtle)' : 'transparent',\n cursor: 'pointer',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-sm)',\n color: danger ? 'var(--interactive-error)' : 'var(--text-primary)',\n textAlign: 'left',\n })}\n >\n {icon}\n {label}\n </button>\n );\n}\n\nconst DEFAULT_STAGE = 280; // crop stage's assumed size (px) before its own ResizeObserver measures it\n\n/**\n * Width of the camera and crop dialogs. They are two steps of one flow (a shot goes straight\n * to the crop), so they share it: a dialog that changed size between the steps would jump.\n * Wider than `Dialog`'s default 352: with Retake the crop footer has three real Buttons, and\n * in Portuguese (\"Tirar outra\", \"Cancelar\", \"Gravar\") they add up to 384px, more than the\n * 358px of content a 400px dialog leaves. 440 gives 398px, so they fit on one line with ~14px\n * to spare. `Dialog` already caps at `min(100%, ...)` for narrow viewports (see\n * feedback/Dialog.tsx), so a phone just gets a narrower dialog. Widening only moves the limit\n * though: the crop footer's `fill` is what keeps a longer language, or that phone, from\n * stranding the primary button.\n */\nconst MODAL_WIDTH = 440;\n\n/** Height reserved for the zoom row, so the camera step (which has none) is as tall as the crop step. */\nconst ZOOM_ROW_HEIGHT = 24;\n\n/**\n * The square viewport + circular guide, shared by the crop and camera modals.\n * `width: 100%` + `aspectRatio: 1`, not a fixed pixel box: it spans exactly the same\n * width as `Dialog.Header`'s title and `Dialog.Footer`'s buttons (both just block-level\n * or flex content inside the same padded `Dialog.Body`), instead of a fixed size\n * centered with margins of its own that didn't match theirs (SS-322 follow-up, the\n * stage read as misaligned from the rest of the dialog). Also needs no separate\n * mobile-width handling of its own: whatever width the dialog ends up at (already\n * responsive, see `feedback/Dialog.tsx`), the stage fills it exactly, staying square\n * via `aspectRatio`.\n */\nfunction CropStage({ children, onPointerDown, onPointerMove, onPointerUp, onWheel, stageRef }: {\n children: React.ReactNode;\n onPointerDown?: (e: React.PointerEvent) => void;\n onPointerMove?: (e: React.PointerEvent) => void;\n onPointerUp?: (e: React.PointerEvent) => void;\n onWheel?: (e: React.WheelEvent) => void;\n /** `useCropper` reads the live rendered size off this to drive the crop math (`V`). */\n stageRef?: React.Ref<HTMLDivElement>;\n}) {\n return (\n <div\n ref={stageRef}\n onPointerDown={onPointerDown}\n onPointerMove={onPointerMove}\n onPointerUp={onPointerUp}\n onPointerCancel={onPointerUp}\n onWheel={onWheel}\n style={sx({\n position: 'relative',\n width: '100%',\n aspectRatio: '1',\n overflow: 'hidden',\n borderRadius: 'var(--radius-lg)',\n background: 'var(--bg-sunken)',\n cursor: onPointerDown ? 'grab' : 'default',\n touchAction: 'none',\n })}\n >\n {children}\n <span\n style={sx({\n position: 'absolute',\n inset: 0,\n pointerEvents: 'none',\n borderRadius: '999px',\n boxShadow: '0 0 0 9999px color-mix(in srgb, var(--bg-overlay) 80%, transparent)',\n outline: '1px solid rgba(255, 255, 255, 0.9)',\n outlineOffset: -1,\n })}\n />\n </div>\n );\n}\n\n/** Which step of the photo flow the dialog is on. */\ntype Step = 'camera' | 'crop';\n\n/**\n * Live camera via `getUserMedia`, while `active`. A failure (no API, permission denied)\n * goes through `onError`. `ready` turns true once the stream is flowing; going inactive\n * stops the tracks, so the camera light goes off as soon as the dialog leaves this step.\n */\nfunction useCamera(active: boolean, onError: () => void) {\n const videoRef = React.useRef<HTMLVideoElement | null>(null);\n const streamRef = React.useRef<MediaStream | null>(null);\n const [ready, setReady] = React.useState(false);\n // Read through a ref so a new `onError` closure each render does not restart the camera.\n const onErrorRef = React.useRef(onError);\n React.useEffect(() => {\n onErrorRef.current = onError;\n });\n\n React.useEffect(() => {\n if (!active) return;\n let cancelled = false;\n let started: MediaStream | null = null;\n const md = typeof navigator !== 'undefined' ? navigator.mediaDevices : undefined;\n if (!md?.getUserMedia) {\n onErrorRef.current();\n return;\n }\n md.getUserMedia({ video: { facingMode: 'user', width: { ideal: 1280 }, height: { ideal: 1280 } }, audio: false })\n .then((s) => {\n if (cancelled) {\n s.getTracks().forEach((tr) => tr.stop());\n return;\n }\n started = s;\n streamRef.current = s;\n if (videoRef.current) videoRef.current.srcObject = s;\n setReady(true);\n })\n .catch(() => onErrorRef.current());\n return () => {\n cancelled = true;\n started?.getTracks().forEach((tr) => tr.stop());\n streamRef.current = null;\n setReady(false);\n };\n }, [active]);\n\n // The `<video>` may mount after the stream arrives (`Dialog` renders its children a render\n // late) or the other way round, so wire them up whichever comes last: here for the element,\n // above for the stream.\n const attachVideo = React.useCallback((el: HTMLVideoElement | null) => {\n videoRef.current = el;\n if (el && streamRef.current) el.srcObject = streamRef.current;\n }, []);\n\n /** Grabs the centred square of the current frame, mirrored like the preview, as a JPEG. */\n const shoot = (onShot: (b: Blob) => void) => {\n const v = videoRef.current;\n if (!v || !v.videoWidth) return;\n const s = Math.min(v.videoWidth, v.videoHeight);\n const canvas = document.createElement('canvas');\n canvas.width = canvas.height = s;\n const ctx = canvas.getContext('2d');\n if (!ctx) return;\n ctx.translate(s, 0);\n ctx.scale(-1, 1);\n ctx.drawImage(v, (v.videoWidth - s) / 2, (v.videoHeight - s) / 2, s, s, 0, 0, s, s);\n canvas.toBlob((b) => b && onShot(b), 'image/jpeg', 0.9);\n };\n\n return { attachVideo, ready, shoot };\n}\n\n/**\n * The crop state and math for one picked photo (`src`): pan, zoom, the stage's live size,\n * and the export. It lives above the dialog, not inside the crop step, so the header, body\n * and footer of a single `Dialog` can all read it while the camera step swaps in and out.\n * Everything resets when `src` changes, so a retaken photo starts centred at 1x.\n */\nfunction useCropper(src: string | null, outputSize: number) {\n const [imgEl, setImgEl] = React.useState<HTMLImageElement | null>(null);\n // A *callback* ref (kept as state), not a plain `useRef` + a `[]`-effect: `Dialog` renders\n // its children only from the render *after* its own `mounted` flips true (SSR-safe portal),\n // so on the stage's very first mount a `useEffect(..., [])` reading `stageRef.current` at\n // that point would still see `null` and, with no deps to fire again on, never retry, so `V`\n // would then stay stuck at the `DEFAULT_STAGE` guess forever (this exact bug, caught live:\n // the displayed image stayed 280px inside a stage CSS had already sized at ~344px, a gray\n // gap on two edges). The callback fires the moment React actually attaches the node.\n const [stageEl, setStageEl] = React.useState<HTMLDivElement | null>(null);\n // The stage's own live rendered size (it's `width: 100%` of the dialog body now, not a\n // fixed px box), read via ResizeObserver. `DEFAULT_STAGE` is only the guess for the very\n // first paint, before the observer's first callback lands.\n const [V, setV] = React.useState(DEFAULT_STAGE);\n const prevV = React.useRef(V);\n const [nat, setNat] = React.useState<{ w: number; h: number } | null>(null);\n const [zoom, setZoom] = React.useState(1);\n const [offset, setOffset] = React.useState({ x: 0, y: 0 });\n const drag = React.useRef<{ x: number; y: number } | null>(null);\n\n // A new photo starts from scratch. Adjusting state while rendering (rather than in an\n // effect) means the stale pan / zoom is never painted against the new image.\n const [seenSrc, setSeenSrc] = React.useState(src);\n if (src !== seenSrc) {\n setSeenSrc(src);\n setNat(null);\n setZoom(1);\n setOffset({ x: 0, y: 0 });\n }\n\n React.useEffect(() => {\n if (!stageEl) return;\n const ro = new ResizeObserver((entries) => {\n const w = Math.round(entries[0]?.contentRect.width ?? 0);\n if (!w || w === prevV.current) return;\n // A live resize while the dialog is open (a phone rotated, a window resized) or the\n // very first real measurement replacing `DEFAULT_STAGE`: rescale the pan offset by\n // the same factor as the viewport itself, so the framed crop doesn't jump. `scale`\n // (see below) is linear in `V`, so multiplying the offset by `newV / oldV` keeps\n // the same fraction of the image framed.\n const factor = w / prevV.current;\n prevV.current = w;\n setV(w);\n setOffset((o) => ({ x: o.x * factor, y: o.y * factor }));\n });\n ro.observe(stageEl);\n return () => ro.disconnect();\n }, [stageEl]);\n\n const scaleMin = nat ? V / Math.min(nat.w, nat.h) : 1;\n const scale = scaleMin * zoom;\n const dispW = nat ? nat.w * scale : V;\n const dispH = nat ? nat.h * scale : V;\n\n const clamp = React.useCallback(\n (o: { x: number; y: number }) => ({\n x: Math.min(0, Math.max(V - dispW, o.x)),\n y: Math.min(0, Math.max(V - dispH, o.y)),\n }),\n [V, dispW, dispH],\n );\n\n const onImgLoad = (el: HTMLImageElement) => {\n const w = el.naturalWidth;\n const h = el.naturalHeight;\n setNat({ w, h });\n const s = V / Math.min(w, h);\n setOffset({ x: (V - w * s) / 2, y: (V - h * s) / 2 });\n };\n\n const setZoomAt = (nextZoom: number) => {\n const z = Math.min(3, Math.max(1, nextZoom));\n setZoom((prevZ) => {\n const oldScale = scaleMin * prevZ;\n const newScale = scaleMin * z;\n setOffset((o) => {\n const imgX = (V / 2 - o.x) / oldScale;\n const imgY = (V / 2 - o.y) / oldScale;\n return clamp({ x: V / 2 - imgX * newScale, y: V / 2 - imgY * newScale });\n });\n return z;\n });\n };\n\n const onPointerDown = (e: React.PointerEvent) => {\n (e.target as HTMLElement).setPointerCapture(e.pointerId);\n drag.current = { x: e.clientX, y: e.clientY };\n };\n const onPointerMove = (e: React.PointerEvent) => {\n if (!drag.current) return;\n const dx = e.clientX - drag.current.x;\n const dy = e.clientY - drag.current.y;\n drag.current = { x: e.clientX, y: e.clientY };\n setOffset((o) => clamp({ x: o.x + dx, y: o.y + dy }));\n };\n const onPointerUp = () => {\n drag.current = null;\n };\n\n const save = (onSave: (b: Blob) => void) => {\n if (!imgEl || !nat) return;\n const canvas = document.createElement('canvas');\n canvas.width = canvas.height = outputSize;\n const ctx = canvas.getContext('2d');\n if (!ctx) return;\n const sSize = V / scale;\n ctx.drawImage(imgEl, -offset.x / scale, -offset.y / scale, sSize, sSize, 0, 0, outputSize, outputSize);\n canvas.toBlob((b) => b && onSave(b), 'image/jpeg', 0.85);\n };\n\n return { setImgEl, setStageEl, zoom, setZoomAt, offset, dispW, dispH, onImgLoad, onPointerDown, onPointerMove, onPointerUp, save };\n}\n\n/**\n * The one dialog for the whole photo flow: the live camera, then the crop (and back, on\n * Retake). It stays mounted across the steps and only its header text, stage and buttons\n * swap, so the panel does not close and reopen (no second pop-in, no scroll-lock or focus\n * hand-off) and it keeps one size. `Dialog.Header` / `Body` / `Footer` are direct children\n * on purpose: `Dialog` reads them off its children to pad the body and label itself, which\n * a wrapper component per step would hide from it.\n */\nfunction CaptureDialog({\n step,\n src,\n outputSize,\n labels,\n onClose,\n onCameraShot,\n onCameraError,\n onSave,\n onRetake,\n}: {\n step: Step;\n /** The photo being cropped; only set on the crop step. */\n src: string | null;\n outputSize: number;\n labels: AvatarUploadLabels;\n onClose: () => void;\n onCameraShot: (b: Blob) => void;\n onCameraError: () => void;\n onSave: (b: Blob) => void;\n /** Only set for a shot taken with the camera; shows the \"Retake\" button. */\n onRetake?: () => void;\n}) {\n const isCamera = step === 'camera';\n const camera = useCamera(isCamera, onCameraError);\n const crop = useCropper(src, outputSize);\n\n // The step's buttons unmount with it, and with them the focused one: without this, focus\n // would fall to the page behind the dialog and Tab would leave the trap. `Dialog` only\n // pulls focus in when it opens, so do it again on every step change.\n const [contentEl, setContentEl] = React.useState<HTMLDivElement | null>(null);\n React.useEffect(() => {\n contentEl?.closest<HTMLElement>('[role=\"dialog\"]')?.focus();\n }, [step, contentEl]);\n\n /* eslint-disable react-hooks/refs -- `useCamera` / `useCropper` return event handlers that reach a\n ref (`videoRef`, the drag origin), so the lint marks every property read off them; but those\n refs are only touched when a handler runs from an event, never during this render. */\n return (\n <Dialog width={MODAL_WIDTH} onClose={onClose}>\n <Dialog.Header title={isCamera ? labels.cameraTitle : labels.cropTitle} description={isCamera ? labels.cameraHint : labels.cropHint} />\n <Dialog.Body>\n <div ref={setContentEl}>\n {isCamera ? (\n <CropStage key=\"camera\">\n <video ref={camera.attachVideo} autoPlay playsInline muted style={sx({ width: '100%', height: '100%', objectFit: 'cover', transform: 'scaleX(-1)' })} />\n </CropStage>\n ) : (\n <CropStage\n key=\"crop\"\n stageRef={crop.setStageEl}\n onPointerDown={crop.onPointerDown}\n onPointerMove={crop.onPointerMove}\n onPointerUp={crop.onPointerUp}\n onWheel={(e) => crop.setZoomAt(crop.zoom - e.deltaY * 0.002)}\n >\n {src && (\n // eslint-disable-next-line @next/next/no-img-element\n <img\n ref={crop.setImgEl}\n src={src}\n alt=\"\"\n draggable={false}\n onLoad={(e) => crop.onImgLoad(e.currentTarget)}\n style={sx({ position: 'absolute', left: crop.offset.x, top: crop.offset.y, width: crop.dispW, height: crop.dispH, maxWidth: 'none', userSelect: 'none', pointerEvents: 'none' })}\n />\n )}\n </CropStage>\n )}\n\n {/* The zoom row is only there on the crop step, but the camera step keeps its room, so the dialog is the same height on both. */}\n <div style={sx({ display: 'flex', alignItems: 'center', gap: 'var(--space-3)', marginTop: 'var(--space-4)', minHeight: ZOOM_ROW_HEIGHT, color: 'var(--text-muted)' })}>\n {!isCamera && (\n <>\n <ZoomOut size={16} strokeWidth={1.75} style={{ flex: '0 0 auto' }} />\n <input\n type=\"range\"\n min={1}\n max={3}\n step={0.01}\n value={crop.zoom}\n onChange={(e) => crop.setZoomAt(Number(e.target.value))}\n aria-label={labels.zoom}\n style={sx({ flex: 1, accentColor: 'var(--interactive-primary)' })}\n />\n <ZoomIn size={16} strokeWidth={1.75} style={{ flex: '0 0 auto' }} />\n </>\n )}\n </div>\n </div>\n </Dialog.Body>\n {/* Three actions (crop after a camera shot, with Retake) share the row and each line they wrap onto; two stay right-aligned, as before. */}\n <Dialog.Footer fill={!isCamera && Boolean(onRetake)}>\n {isCamera ? (\n <React.Fragment key=\"camera\">\n <Button variant=\"secondary\" iconLeft={<X size={16} strokeWidth={2} />} onClick={onClose}>\n {labels.cancel}\n </Button>\n <Button iconLeft={<Camera size={16} strokeWidth={2} />} onClick={() => camera.shoot(onCameraShot)} disabled={!camera.ready}>\n {labels.capture}\n </Button>\n </React.Fragment>\n ) : (\n <React.Fragment key=\"crop\">\n {onRetake && (\n <Button variant=\"secondary\" iconLeft={<RotateCcw size={16} strokeWidth={2} />} onClick={onRetake}>\n {labels.retake}\n </Button>\n )}\n <Button variant=\"secondary\" iconLeft={<X size={16} strokeWidth={2} />} onClick={onClose}>\n {labels.cancel}\n </Button>\n <Button iconLeft={<Check size={16} strokeWidth={2.5} />} onClick={() => crop.save(onSave)}>\n {labels.save}\n </Button>\n </React.Fragment>\n )}\n </Dialog.Footer>\n </Dialog>\n );\n /* eslint-enable react-hooks/refs */\n}\n"],"mappings":";AA2RM,SAqgBQ,UArgBR,KAEA,YAFA;AAzRN,YAAY,WAAW;AACvB,SAAS,oBAAoB;AAC7B,SAAS,QAAQ,OAAO,WAAW,QAAQ,WAAW,QAAQ,GAAG,QAAQ,eAAe;AACxF,SAAS,UAAU;AACnB,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AACvB,SAAS,cAAc;AAmCvB,MAAM,KAAyB;AAAA,EAC7B,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,UAAU;AAAA,EACV,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,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,UAAO,UAAU,oBAAC,UAAO,MAAM,IAAI,aAAa,GAAG,GAAI,SAAS,MAAM,OAAO,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,OAClH,iBAAO,SACV;AAAA,SANkB,QAOpB,IAEA,qBAAC,MAAM,UAAN,EACE;AAAA,kBACC,oBAAC,UAAO,SAAQ,aAAY,UAAU,oBAAC,aAAU,MAAM,IAAI,aAAa,GAAG,GAAI,SAAS,UACrF,iBAAO,QACV;AAAA,MAEF,oBAAC,UAAO,SAAQ,aAAY,UAAU,oBAAC,KAAE,MAAM,IAAI,aAAa,GAAG,GAAI,SAAS,SAC7E,iBAAO,QACV;AAAA,MACA,oBAAC,UAAO,UAAU,oBAAC,SAAM,MAAM,IAAI,aAAa,KAAK,GAAI,SAAS,MAAM,KAAK,KAAK,MAAM,GACrF,iBAAO,MACV;AAAA,SAXkB,MAYpB,GAEJ;AAAA,KACF;AAGJ;","names":["AvatarUpload"]}
|
|
@@ -26,9 +26,14 @@ interface DatePickerProps {
|
|
|
26
26
|
/** Uncontrolled initial value, ISO "YYYY-MM-DD". */
|
|
27
27
|
defaultValue?: string;
|
|
28
28
|
onChange?: (value: string) => void;
|
|
29
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Earliest selectable date, ISO "YYYY-MM-DD". Every day before it is struck through, and the
|
|
31
|
+
* calendar cannot be navigated to an earlier month or year (the previous-month arrow disables,
|
|
32
|
+
* PageUp and the arrow keys stop at the edge, the month / year popover disables what is out of
|
|
33
|
+
* range). An initial value or month before it opens on `min`'s month.
|
|
34
|
+
*/
|
|
30
35
|
min?: string;
|
|
31
|
-
/** Latest selectable date, ISO "YYYY-MM-DD"
|
|
36
|
+
/** Latest selectable date, ISO "YYYY-MM-DD". The mirror image of `min`: later days are struck through and later months and years cannot be reached. */
|
|
32
37
|
max?: string;
|
|
33
38
|
id?: string;
|
|
34
39
|
containerStyle?: React.CSSProperties;
|
package/dist/forms/DatePicker.js
CHANGED
|
@@ -6,20 +6,12 @@ import { sx } from "../_internal/style.js";
|
|
|
6
6
|
import { Field } from "../_internal/Field.js";
|
|
7
7
|
import { fieldA11y } from "../_internal/fieldA11y.js";
|
|
8
8
|
import { CalendarGrid } from "./_internal/CalendarGrid.js";
|
|
9
|
+
import { parseISODate as parseISO, toISODate as toISO } from "./_internal/calendarRange.js";
|
|
9
10
|
import { fieldBoxStyle } from "./_internal/fieldBoxStyle.js";
|
|
10
11
|
const TEXT = {
|
|
11
12
|
"pt-BR": { placeholder: "Selecionar data", dialogLabel: "Escolher data", clearLabel: "Limpar data" },
|
|
12
13
|
en: { placeholder: "Pick a date", dialogLabel: "Choose a date", clearLabel: "Clear date" }
|
|
13
14
|
};
|
|
14
|
-
function parseISO(iso) {
|
|
15
|
-
if (!iso) return null;
|
|
16
|
-
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(iso);
|
|
17
|
-
if (!m) return null;
|
|
18
|
-
return { year: Number(m[1]), month: Number(m[2]) - 1, day: Number(m[3]) };
|
|
19
|
-
}
|
|
20
|
-
function toISO(year, month, day) {
|
|
21
|
-
return `${String(year).padStart(4, "0")}-${String(month + 1).padStart(2, "0")}-${String(day).padStart(2, "0")}`;
|
|
22
|
-
}
|
|
23
15
|
function formatDisplay(iso, locale) {
|
|
24
16
|
const d = parseISO(iso);
|
|
25
17
|
if (!d) return iso;
|
|
@@ -27,26 +19,6 @@ function formatDisplay(iso, locale) {
|
|
|
27
19
|
new Date(d.year, d.month, d.day)
|
|
28
20
|
);
|
|
29
21
|
}
|
|
30
|
-
function daysIn(year, month) {
|
|
31
|
-
return new Date(year, month + 1, 0).getDate();
|
|
32
|
-
}
|
|
33
|
-
function unavailableForMonth(year, month, min, max) {
|
|
34
|
-
if (!min && !max) return [];
|
|
35
|
-
const minD = parseISO(min);
|
|
36
|
-
const maxD = parseISO(max);
|
|
37
|
-
const out = [];
|
|
38
|
-
const total = daysIn(year, month);
|
|
39
|
-
for (let day = 1; day <= total; day++) {
|
|
40
|
-
if (minD && year * 372 + month * 31 + day < minD.year * 372 + minD.month * 31 + minD.day) {
|
|
41
|
-
out.push(day);
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
if (maxD && year * 372 + month * 31 + day > maxD.year * 372 + maxD.month * 31 + maxD.day) {
|
|
45
|
-
out.push(day);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return out;
|
|
49
|
-
}
|
|
50
22
|
const DatePicker = React.forwardRef(function DatePicker2({
|
|
51
23
|
label,
|
|
52
24
|
hint,
|
|
@@ -117,7 +89,6 @@ const DatePicker = React.forwardRef(function DatePicker2({
|
|
|
117
89
|
onChange?.("");
|
|
118
90
|
triggerRef.current?.focus();
|
|
119
91
|
};
|
|
120
|
-
const unavailable = React.useMemo(() => unavailableForMonth(viewYear, viewMonth, min, max), [viewYear, viewMonth, min, max]);
|
|
121
92
|
return /* @__PURE__ */ jsx(Field, { label, hint, error, required, htmlFor: rid, style: containerStyle, preserveHelperSpace, children: /* @__PURE__ */ jsxs("div", { ref: rootRef, style: { position: "relative", width: "100%" }, children: [
|
|
122
93
|
/* @__PURE__ */ jsxs("div", { style: fieldBoxStyle(size, !!error, open, disabled), children: [
|
|
123
94
|
/* @__PURE__ */ jsxs(
|
|
@@ -220,7 +191,8 @@ const DatePicker = React.forwardRef(function DatePicker2({
|
|
|
220
191
|
year: viewYear,
|
|
221
192
|
month: viewMonth,
|
|
222
193
|
selectedDate: parsed && parsed.year === viewYear && parsed.month === viewMonth ? parsed.day : void 0,
|
|
223
|
-
|
|
194
|
+
min,
|
|
195
|
+
max,
|
|
224
196
|
onMonthChange: (y, m) => {
|
|
225
197
|
setViewYear(y);
|
|
226
198
|
setViewMonth(m);
|