@sereno-ds/ui 0.42.1 → 0.44.0

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.
Files changed (39) hide show
  1. package/README.md +16 -3
  2. package/dist/core/ActionCard.d.ts +1 -1
  3. package/dist/core/ActionCard.js +9 -8
  4. package/dist/core/ActionCard.js.map +1 -1
  5. package/dist/core/Button.d.ts +1 -9
  6. package/dist/core/Button.js +1 -22
  7. package/dist/core/Button.js.map +1 -1
  8. package/dist/forms/Autocomplete.js +3 -4
  9. package/dist/forms/Autocomplete.js.map +1 -1
  10. package/dist/forms/AvatarUpload.js +1 -4
  11. package/dist/forms/AvatarUpload.js.map +1 -1
  12. package/dist/forms/Checkbox.js +6 -5
  13. package/dist/forms/Checkbox.js.map +1 -1
  14. package/dist/forms/DatePicker.js +2 -1
  15. package/dist/forms/DatePicker.js.map +1 -1
  16. package/dist/forms/Input.js +5 -15
  17. package/dist/forms/Input.js.map +1 -1
  18. package/dist/forms/Radio.js +6 -5
  19. package/dist/forms/Radio.js.map +1 -1
  20. package/dist/forms/SearchInput.js.map +1 -1
  21. package/dist/forms/Select.js +3 -1
  22. package/dist/forms/Select.js.map +1 -1
  23. package/dist/forms/Textarea.js +6 -17
  24. package/dist/forms/Textarea.js.map +1 -1
  25. package/dist/forms/_internal/choiceVars.d.ts +9 -0
  26. package/dist/forms/_internal/choiceVars.js +7 -0
  27. package/dist/forms/_internal/choiceVars.js.map +1 -0
  28. package/dist/forms/_internal/fieldBoxStyle.d.ts +6 -2
  29. package/dist/forms/_internal/fieldBoxStyle.js +6 -4
  30. package/dist/forms/_internal/fieldBoxStyle.js.map +1 -1
  31. package/dist/forms/_internal/fieldFrame.d.ts +26 -0
  32. package/dist/forms/_internal/fieldFrame.js +11 -0
  33. package/dist/forms/_internal/fieldFrame.js.map +1 -0
  34. package/dist/navigation/SidebarNav.js +10 -3
  35. package/dist/navigation/SidebarNav.js.map +1 -1
  36. package/dist/navigation/_internal/SidebarNavItems.js +14 -31
  37. package/dist/navigation/_internal/SidebarNavItems.js.map +1 -1
  38. package/dist/styles.css +77 -3
  39. package/package.json +1 -1
@@ -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, ImagePlus, Pencil, Trash2 } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { Field } from '../_internal/Field';\nimport { fieldA11y } from '../_internal/fieldA11y';\nimport { mergeRefs } from '../_internal/mergeRefs';\nimport { CaptureDialog, type Step } from './_internal/AvatarCaptureDialog';\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"],"mappings":";AA0RM,cAEA,YAFA;AAxRN,YAAY,WAAW;AACvB,SAAS,oBAAoB;AAC7B,SAAS,QAAQ,WAAW,QAAQ,cAAc;AAClD,SAAS,UAAU;AACnB,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,qBAAgC;AAmCzC,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,E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AY;AAAA,QACZ,UAAU;AAAA,QACV,OAAO,SAAS,6BAA6B;AAAA,QAC7C,WAAW;AAAA,MACb,CAAC;AAAA,MAEA;AAAA;AAAA,QACA;AAAA;AAAA;AAAA,EACH;AAEJ;","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, ImagePlus, Pencil, Trash2 } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { Field } from '../_internal/Field';\nimport { fieldA11y } from '../_internal/fieldA11y';\nimport { mergeRefs } from '../_internal/mergeRefs';\nimport { CaptureDialog, type Step } from './_internal/AvatarCaptureDialog';\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 return (\n <button\n type=\"button\"\n role=\"menuitem\"\n className=\"sereno-menuitem\"\n onClick={onClick}\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 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"],"mappings":";AA0RM,cAEA,YAFA;AAxRN,YAAY,WAAW;AACvB,SAAS,oBAAoB;AAC7B,SAAS,QAAQ,WAAW,QAAQ,cAAc;AAClD,SAAS,UAAU;AACnB,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,qBAAgC;AAmCzC,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,OAA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 +3,8 @@ import { jsx, jsxs } from "react/jsx-runtime";
3
3
  import * as React from "react";
4
4
  import { sx } from "../_internal/style.js";
5
5
  import { mergeRefs } from "../_internal/mergeRefs.js";
6
+ import { choiceVars } from "./_internal/choiceVars.js";
6
7
  const Checkbox = React.forwardRef(function Checkbox2({ label, description, error, checked, defaultChecked, disabled, indeterminate, size = "md", preserveHelperSpace = false, onChange, style, ...rest }, forwardedRef) {
7
- const [hover, setHover] = React.useState(false);
8
8
  const box = size === "sm" ? 16 : 20;
9
9
  const innerRef = React.useRef(null);
10
10
  React.useEffect(() => {
@@ -13,9 +13,8 @@ const Checkbox = React.forwardRef(function Checkbox2({ label, description, error
13
13
  return /* @__PURE__ */ jsxs(
14
14
  "label",
15
15
  {
16
- onMouseEnter: () => setHover(true),
17
- onMouseLeave: () => setHover(false),
18
- style: sx({ display: "flex", gap: "var(--space-3)", alignItems: "flex-start", cursor: disabled ? "not-allowed" : "pointer", opacity: disabled ? 0.6 : 1, ...style }),
16
+ className: "sereno-choice",
17
+ style: sx({ ...choiceVars(error), display: "flex", gap: "var(--space-3)", alignItems: "flex-start", cursor: disabled ? "not-allowed" : "pointer", opacity: disabled ? 0.6 : 1, ...style }),
19
18
  children: [
20
19
  /* @__PURE__ */ jsx("span", { style: sx({ position: "relative", display: "inline-flex", flex: "0 0 auto", marginTop: size === "sm" ? 3 : 1 }), children: /* @__PURE__ */ jsx(
21
20
  "input",
@@ -36,7 +35,9 @@ const Checkbox = React.forwardRef(function Checkbox2({ label, description, error
36
35
  height: box,
37
36
  margin: 0,
38
37
  borderRadius: "var(--radius-sm)",
39
- border: "var(--border-width-emphasis) solid " + (error ? "var(--interactive-error)" : hover && !disabled ? "var(--border-brand)" : "var(--border-strong)"),
38
+ // The colour is the stylesheet's (`border-color` of `.sereno-check`), so the hover can change it.
39
+ borderWidth: "var(--border-width-emphasis)",
40
+ borderStyle: "solid",
40
41
  // `backgroundColor`, not `background` - the shorthand would set an inline
41
42
  // `background-size: auto` that overrides the `:checked` glyph scaling.
42
43
  backgroundColor: "var(--bg-surface)",
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/forms/Checkbox.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { sx } from '../_internal/style';\nimport { mergeRefs } from '../_internal/mergeRefs';\n\n/** Opt-in control for consents and multi-select filters. Host must include the `.sereno-check:checked` and `.sereno-check:indeterminate` rules (see globals.css). */\nexport interface CheckboxProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type' | 'size'> {\n label?: string;\n /** Secondary line under the label. Replaced by `error` when present. */\n description?: string;\n /** Error message - tints the box and the secondary line red. Replaces `description`. */\n error?: string;\n /** Mixed state - some but not all children selected. Visual only; a form still submits it as unchecked. */\n indeterminate?: boolean;\n /** Box size. `sm` (16px) for dense filter lists; `md` (20px) everywhere else. */\n size?: 'sm' | 'md';\n /**\n * Reserve the description/error row's height even with neither set - keeps\n * the row stable as `error` comes and goes (SS-259, same mechanism as\n * `Input`'s `preserveHelperSpace`). Off by default.\n */\n preserveHelperSpace?: boolean;\n}\n\nexport const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(function Checkbox(\n { label, description, error, checked, defaultChecked, disabled, indeterminate, size = 'md', preserveHelperSpace = false, onChange, style, ...rest },\n forwardedRef,\n) {\n const [hover, setHover] = React.useState(false);\n const box = size === 'sm' ? 16 : 20;\n const innerRef = React.useRef<HTMLInputElement>(null);\n // `indeterminate` is a DOM property, not an attribute - set it imperatively, and\n // re-assert on every render so a `checked` change never leaves it stale.\n React.useEffect(() => {\n if (innerRef.current) innerRef.current.indeterminate = Boolean(indeterminate);\n });\n return (\n <label\n onMouseEnter={() => setHover(true)}\n onMouseLeave={() => setHover(false)}\n style={sx({ display: 'flex', gap: 'var(--space-3)', alignItems: 'flex-start', cursor: disabled ? 'not-allowed' : 'pointer', opacity: disabled ? 0.6 : 1, ...style })}\n >\n <span style={sx({ position: 'relative', display: 'inline-flex', flex: '0 0 auto', marginTop: size === 'sm' ? 3 : 1 })}>\n <input\n ref={mergeRefs(innerRef, forwardedRef)}\n type=\"checkbox\"\n checked={checked}\n defaultChecked={defaultChecked}\n disabled={disabled}\n onChange={onChange}\n {...rest}\n // Only the state: the error line is inside the <label>, so it is already part of the\n // name. `aria-describedby` would read it twice.\n aria-invalid={error ? true : rest['aria-invalid']}\n data-size={size}\n className=\"sereno-check\"\n style={sx({\n appearance: 'none',\n width: box,\n height: box,\n margin: 0,\n borderRadius: 'var(--radius-sm)',\n border: 'var(--border-width-emphasis) solid ' + (error ? 'var(--interactive-error)' : hover && !disabled ? 'var(--border-brand)' : 'var(--border-strong)'),\n // `backgroundColor`, not `background` - the shorthand would set an inline\n // `background-size: auto` that overrides the `:checked` glyph scaling.\n backgroundColor: 'var(--bg-surface)',\n cursor: 'inherit',\n transition: 'var(--transition-control)',\n })}\n />\n </span>\n <span style={sx({ display: 'flex', flexDirection: 'column', gap: 2 })}>\n {label && <span style={sx({ fontFamily: 'var(--font-body)', fontSize: 'var(--text-base)', color: 'var(--text-primary)', lineHeight: 1.35 })}>{label}</span>}\n {(description || error || preserveHelperSpace) && (\n <span\n style={sx({\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-xs)',\n color: error ? 'var(--interactive-error)' : 'var(--text-muted)',\n lineHeight: 1.45,\n minHeight: preserveHelperSpace ? 'calc(var(--text-xs) * 1.45)' : undefined,\n })}\n >\n {error || description}\n </span>\n )}\n </span>\n </label>\n );\n});\n\nCheckbox.displayName = 'Checkbox';"],"mappings":";AA4CQ,cA4BF,YA5BE;AA1CR,YAAY,WAAW;AACvB,SAAS,UAAU;AACnB,SAAS,iBAAiB;AAqBnB,MAAM,WAAW,MAAM,WAA4C,SAASA,UACjF,EAAE,OAAO,aAAa,OAAO,SAAS,gBAAgB,UAAU,eAAe,OAAO,MAAM,sBAAsB,OAAO,UAAU,OAAO,GAAG,KAAK,GAClJ,cACA;AACA,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAS,KAAK;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AK,CAAC,GAAI,iBAAM;AAAA,WAClJ,eAAe,SAAS,wBACxB;AAAA,YAAC;AAAA;AAAA,cACC,OAAO,GAAG;AAAA,gBACR,YAAY;AAAA,gBACZ,UAAU;AAAA,gBACV,OAAO,QAAQ,6BAA6B;AAAA,gBAC5C,YAAY;AAAA,gBACZ,WAAW,sBAAsB,gCAAgC;AAAA,cACnE,CAAC;AAAA,cAEA,mBAAS;AAAA;AAAA,UACZ;AAAA,WAEJ;AAAA;AAAA;AAAA,EACF;AAEJ,CAAC;AAED,SAAS,cAAc;","names":["Checkbox"]}
1
+ {"version":3,"sources":["../../src/forms/Checkbox.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { sx } from '../_internal/style';\nimport { mergeRefs } from '../_internal/mergeRefs';\nimport { choiceVars } from './_internal/choiceVars';\n\n/** Opt-in control for consents and multi-select filters. Host must include the `.sereno-check:checked` and `.sereno-check:indeterminate` rules (see globals.css). */\nexport interface CheckboxProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type' | 'size'> {\n label?: string;\n /** Secondary line under the label. Replaced by `error` when present. */\n description?: string;\n /** Error message - tints the box and the secondary line red. Replaces `description`. */\n error?: string;\n /** Mixed state - some but not all children selected. Visual only; a form still submits it as unchecked. */\n indeterminate?: boolean;\n /** Box size. `sm` (16px) for dense filter lists; `md` (20px) everywhere else. */\n size?: 'sm' | 'md';\n /**\n * Reserve the description/error row's height even with neither set - keeps\n * the row stable as `error` comes and goes (SS-259, same mechanism as\n * `Input`'s `preserveHelperSpace`). Off by default.\n */\n preserveHelperSpace?: boolean;\n}\n\nexport const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(function Checkbox(\n { label, description, error, checked, defaultChecked, disabled, indeterminate, size = 'md', preserveHelperSpace = false, onChange, style, ...rest },\n forwardedRef,\n) {\n const box = size === 'sm' ? 16 : 20;\n const innerRef = React.useRef<HTMLInputElement>(null);\n // `indeterminate` is a DOM property, not an attribute - set it imperatively, and\n // re-assert on every render so a `checked` change never leaves it stale.\n React.useEffect(() => {\n if (innerRef.current) innerRef.current.indeterminate = Boolean(indeterminate);\n });\n return (\n <label\n className=\"sereno-choice\"\n // The border colours `.sereno-check` (styles.css) paints, idle and while the pointer is on the row (SS-577).\n style={sx({ ...choiceVars(error), display: 'flex', gap: 'var(--space-3)', alignItems: 'flex-start', cursor: disabled ? 'not-allowed' : 'pointer', opacity: disabled ? 0.6 : 1, ...style })}\n >\n <span style={sx({ position: 'relative', display: 'inline-flex', flex: '0 0 auto', marginTop: size === 'sm' ? 3 : 1 })}>\n <input\n ref={mergeRefs(innerRef, forwardedRef)}\n type=\"checkbox\"\n checked={checked}\n defaultChecked={defaultChecked}\n disabled={disabled}\n onChange={onChange}\n {...rest}\n // Only the state: the error line is inside the <label>, so it is already part of the\n // name. `aria-describedby` would read it twice.\n aria-invalid={error ? true : rest['aria-invalid']}\n data-size={size}\n className=\"sereno-check\"\n style={sx({\n appearance: 'none',\n width: box,\n height: box,\n margin: 0,\n borderRadius: 'var(--radius-sm)',\n // The colour is the stylesheet's (`border-color` of `.sereno-check`), so the hover can change it.\n borderWidth: 'var(--border-width-emphasis)',\n borderStyle: 'solid',\n // `backgroundColor`, not `background` - the shorthand would set an inline\n // `background-size: auto` that overrides the `:checked` glyph scaling.\n backgroundColor: 'var(--bg-surface)',\n cursor: 'inherit',\n transition: 'var(--transition-control)',\n })}\n />\n </span>\n <span style={sx({ display: 'flex', flexDirection: 'column', gap: 2 })}>\n {label && <span style={sx({ fontFamily: 'var(--font-body)', fontSize: 'var(--text-base)', color: 'var(--text-primary)', lineHeight: 1.35 })}>{label}</span>}\n {(description || error || preserveHelperSpace) && (\n <span\n style={sx({\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-xs)',\n color: error ? 'var(--interactive-error)' : 'var(--text-muted)',\n lineHeight: 1.45,\n minHeight: preserveHelperSpace ? 'calc(var(--text-xs) * 1.45)' : undefined,\n })}\n >\n {error || description}\n </span>\n )}\n </span>\n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Q;AAAA,cACR,YAAY;AAAA,YACd,CAAC;AAAA;AAAA,QACH,GACF;AAAA,QACA,qBAAC,UAAK,OAAO,GAAG,EAAE,SAAS,QAAQ,eAAe,UAAU,KAAK,EAAE,CAAC,GACjE;AAAA,mBAAS,oBAAC,UAAK,OAAO,GAAG,EAAE,YAAY,oBAAoB,UAAU,oBAAoB,OAAO,uBAAuB,YAAY,KAAK,CAAC,GAAI,iBAAM;AAAA,WAClJ,eAAe,SAAS,wBACxB;AAAA,YAAC;AAAA;AAAA,cACC,OAAO,GAAG;AAAA,gBACR,YAAY;AAAA,gBACZ,UAAU;AAAA,gBACV,OAAO,QAAQ,6BAA6B;AAAA,gBAC5C,YAAY;AAAA,gBACZ,WAAW,sBAAsB,gCAAgC;AAAA,cACnE,CAAC;AAAA,cAEA,mBAAS;AAAA;AAAA,UACZ;AAAA,WAEJ;AAAA;AAAA;AAAA,EACF;AAEJ,CAAC;AAED,SAAS,cAAc;","names":["Checkbox"]}
@@ -12,6 +12,7 @@ import { useOutsidePress } from "../_internal/useOutsidePress.js";
12
12
  import { CalendarGrid } from "./_internal/CalendarGrid.js";
13
13
  import { parseISODate as parseISO, toISODate as toISO } from "./_internal/calendarRange.js";
14
14
  import { fieldBoxStyle } from "./_internal/fieldBoxStyle.js";
15
+ import { fieldBoxProps } from "./_internal/fieldFrame.js";
15
16
  const TEXT = {
16
17
  "pt-BR": { placeholder: "Selecionar data", dialogLabel: "Escolher data", clearLabel: "Limpar data" },
17
18
  en: { placeholder: "Pick a date", dialogLabel: "Choose a date", clearLabel: "Clear date" }
@@ -188,7 +189,7 @@ const DatePicker = React.forwardRef(function DatePicker2({
188
189
  }
189
190
  );
190
191
  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: [
191
- /* @__PURE__ */ jsxs("div", { ref: boxRef, onKeyDown: onBoxKeyDown, style: fieldBoxStyle(size, !!error, open, disabled), children: [
192
+ /* @__PURE__ */ jsxs("div", { ref: boxRef, onKeyDown: onBoxKeyDown, ...fieldBoxProps(open), style: fieldBoxStyle(size, !!error, disabled), children: [
192
193
  /* @__PURE__ */ jsxs(
193
194
  "button",
194
195
  {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/forms/DatePicker.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { Calendar as CalendarIcon, X } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { Field } from '../_internal/Field';\nimport { fieldA11y } from '../_internal/fieldA11y';\nimport { useIsoLayoutEffect } from '../_internal/useIsoLayoutEffect';\nimport { useMenuPlacement } from '../_internal/useMenuPlacement';\nimport { useOutsidePress } from '../_internal/useOutsidePress';\nimport { CalendarGrid } from './_internal/CalendarGrid';\nimport type { CalendarDayContext, CalendarDayDots } from './_internal/calendarDots';\nimport { parseISODate as parseISO, toISODate as toISO } from './_internal/calendarRange';\nimport { fieldBoxStyle } from './_internal/fieldBoxStyle';\n\nconst TEXT = {\n 'pt-BR': { placeholder: 'Selecionar data', dialogLabel: 'Escolher data', clearLabel: 'Limpar data' },\n en: { placeholder: 'Pick a date', dialogLabel: 'Choose a date', clearLabel: 'Clear date' },\n} as const;\n\n/**\n * The widest a calendar gets once it leaves the field's own width, i.e. when portalled out of a Dialog. Its\n * cells are square, so it is as tall as it is wide: at the width of a wide dialog field it would be a\n * 450px-tall slab that covers the field and half the window. Inline it is untouched (still the field's width).\n */\nconst PORTALLED_MAX_WIDTH = 320;\n\n/** What a keyboard can reach inside `root`, in tab order (the calendar's roving day has `tabindex=\"0\"`, the others `-1`). */\nfunction tabbables(root: HTMLElement | null): HTMLElement[] {\n if (!root) return [];\n return Array.from(root.querySelectorAll<HTMLElement>('button:not(:disabled), [tabindex]')).filter((el) => el.tabIndex >= 0);\n}\n\n/**\n * Imperative handle exposed via `ref` - there's no single native element\n * underneath (the trigger is a `<button>`, the value a plain ISO string in\n * React state), so `ref` can't hand back something `.value`-readable the way\n * a real `<input>` would. `focus()` is real and covers `setFocus()`-on-error;\n * reading the current value still means the `value`/`onChange` props, not the\n * ref. `onChange(value: string)` also isn't a `ChangeEvent`, so a plain\n * `{...register(name)}` spread won't work regardless - use `Controller`.\n */\nexport interface DatePickerHandle {\n focus: () => void;\n}\n\nexport interface DatePickerProps {\n label?: string;\n hint?: string;\n error?: string;\n required?: boolean;\n /** Defaults to the `locale`-appropriate text (\"Selecionar data\" / \"Pick a date\"). */\n placeholder?: string;\n size?: 'sm' | 'md' | 'lg';\n disabled?: boolean;\n /** Controlled value, ISO \"YYYY-MM-DD\". */\n value?: string;\n /** Uncontrolled initial value, ISO \"YYYY-MM-DD\". */\n defaultValue?: string;\n onChange?: (value: string) => void;\n /**\n * Earliest selectable date, ISO \"YYYY-MM-DD\". Every day before it is struck through, and the\n * calendar cannot be navigated to an earlier month or year (the previous-month arrow disables,\n * PageUp and the arrow keys stop at the edge, the month / year popover disables what is out of\n * range). An initial value or month before it opens on `min`'s month.\n */\n min?: string;\n /** 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. */\n max?: string;\n /**\n * Fires when the month on screen changes (the arrows, or the month / year popover), with the\n * new year and the 0-indexed month. Not when the popover opens: it opens on the month of the\n * value, or on the current one. Refresh `dayDots` / `renderDay` here.\n */\n onMonthChange?: (year: number, month: number) => void;\n /**\n * Content under each day number (a count, a note), the same as `DateTimePicker`'s. The second\n * argument says whether the day is `selected`, `today` or `unavailable`. When set, the day cells\n * grow taller to hold it.\n */\n renderDay?: (day: number, context: CalendarDayContext) => React.ReactNode;\n /**\n * The days that get a dot under their number, the same as `DateTimePicker`'s: day numbers\n * (`[3, 17]`), or an object keyed by day number for a per-dot `tone` or `label`. Day numbers of\n * the month on screen, so refresh them in `onMonthChange`.\n */\n dayDots?: CalendarDayDots;\n /** What a screen reader says for a dot with no `label` of its own. Defaults to the `locale`-appropriate text. */\n dayDotLabel?: string;\n id?: string;\n containerStyle?: React.CSSProperties;\n /** aria-label for the clear (×) button. Defaults to the `locale`-appropriate text. */\n clearLabel?: string;\n /**\n * The real Sereno product always renders pt-BR - this only exists so the\n * docs showcase can demo an English-speaking consumer without forking the\n * component. Default stays `'pt-BR'`.\n */\n locale?: 'pt-BR' | 'en';\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\nfunction formatDisplay(iso: string, locale: 'pt-BR' | 'en'): string {\n const d = parseISO(iso);\n if (!d) return iso;\n return new Intl.DateTimeFormat(locale === 'en' ? 'en-US' : 'pt-BR', { day: '2-digit', month: '2-digit', year: 'numeric' }).format(\n new Date(d.year, d.month, d.day),\n );\n}\n\n/**\n * Field for picking a single date - no time, no slots (`DateTimePicker`'s\n * job). A text-field-styled trigger showing the selected date opens a\n * popover with the same calendar grid `DateTimePicker` uses (roving\n * tabindex, month/year jump - see `./_internal/CalendarGrid`), so the two\n * share every bit of calendar behavior (SS-243).\n *\n * Value contract matches the rest of the forms package: `value` /\n * `defaultValue` + `onChange(value)`, a plain ISO \"YYYY-MM-DD\" string -\n * drops in wherever `<input type=\"date\">` would go, but themed instead of\n * the browser's own, and in pt-BR by default (the real Sereno product\n * always uses it; `locale=\"en\"` exists only for docs/demo purposes). A\n * clear (×) button appears once a value is set.\n */\nexport const DatePicker = React.forwardRef<DatePickerHandle, DatePickerProps>(function DatePicker(\n {\n label,\n hint,\n error,\n required,\n placeholder,\n size = 'md',\n disabled = false,\n value,\n defaultValue,\n onChange,\n min,\n max,\n onMonthChange,\n renderDay,\n dayDots,\n dayDotLabel,\n id,\n containerStyle,\n clearLabel,\n locale = 'pt-BR',\n preserveHelperSpace,\n },\n ref,\n) {\n const copy = TEXT[locale];\n const [inner, setInner] = React.useState(defaultValue ?? '');\n const iso = value !== undefined ? value : inner;\n const parsed = parseISO(iso);\n const now = React.useMemo(() => new Date(), []);\n\n const [open, setOpen] = React.useState(false);\n // The month currently shown in the popover - resets to the value's month\n // (or today's) every time the popover opens, via the conditional mount\n // below; CalendarGrid itself only takes year/month as its *initial* view.\n const [viewYear, setViewYear] = React.useState(parsed?.year ?? now.getFullYear());\n const [viewMonth, setViewMonth] = React.useState(parsed?.month ?? now.getMonth());\n\n const rootRef = React.useRef<HTMLDivElement>(null);\n const boxRef = React.useRef<HTMLDivElement>(null);\n const popoverRef = React.useRef<HTMLDivElement>(null);\n const triggerRef = React.useRef<HTMLButtonElement>(null);\n const generatedId = React.useId();\n const rid = id || generatedId;\n\n React.useImperativeHandle(ref, () => ({ focus: () => triggerRef.current?.focus() }), []);\n\n // Where the calendar sits. Normally a plain `position: absolute` child of\n // `rootRef` (itself `position: relative`) - the same \"inline\" strategy\n // Select's panel uses for its common case, and the same one DateTimePicker's\n // own month/year popover already uses. The browser glues it to the trigger\n // through *any* scroll (page or a nested overflow container) for free - no JS\n // measuring position, no listening for scroll/resize, and critically, it\n // never has to close on scroll the way a `position: fixed` popover computed\n // once would (that was tried first here and didn't hold up - see PR history).\n //\n // The one place that fails is inside a `position: fixed` container (a\n // Dialog): its body scrolls and clips an inline child, cutting the calendar\n // off. There `useMenuPlacement` answers 'fixed' (what Select and\n // Autocomplete already do) and the calendar is portalled to <body> at the\n // field's viewport rect, closing if the field moves. Outside a dialog nothing\n // changes: still inline, still below the field, never flipped (the hook's\n // `above` / `maxH` are not used at all: see `fitTop` for the portalled case).\n // `itemCount` is just the hook's height estimate; a calendar is not a list.\n const place = useMenuPlacement({\n open,\n anchorRef: boxRef,\n panelRef: popoverRef,\n itemCount: 8,\n onDismiss: () => setOpen(false),\n });\n const portalled = open && place?.strategy === 'fixed';\n\n // The hook picks \"below\" or \"above\" from a rough guess at the height, which suits a list capped at 288px but not\n // a calendar (about as tall as it is wide). So once the portalled calendar is on screen it is measured and kept\n // inside the window: under the field if it fits, else above it, else as far up as it needs (over the field rather\n // than cut off). The month changes the row count, hence the dependencies. Runs before paint: no visible jump.\n const [fitTop, setFitTop] = React.useState<number | null>(null);\n useIsoLayoutEffect(() => {\n const popover = popoverRef.current;\n const box = boxRef.current;\n if (!portalled || !popover || !box) return;\n const GAP = 6;\n const EDGE = 8;\n const field = box.getBoundingClientRect();\n const height = popover.offsetHeight;\n const viewport = window.innerHeight || document.documentElement.clientHeight || 900;\n const below = field.bottom + GAP;\n const above = field.top - GAP - height;\n setFitTop(below + height <= viewport - EDGE ? below : above >= EDGE ? above : Math.max(EDGE, viewport - EDGE - height));\n }, [portalled, place, viewYear, viewMonth]);\n\n // A press outside the field closes the calendar. The portalled calendar is outside `rootRef` in the DOM but\n // still part of the field, so both count as inside.\n useOutsidePress(open, [rootRef, popoverRef], () => setOpen(false));\n React.useEffect(() => {\n if (!open) return;\n const onKey = (e: KeyboardEvent) => {\n if (e.key === 'Escape') {\n e.preventDefault(); // handled: a Dialog around the field keeps its own Esc for the next press\n setOpen(false);\n triggerRef.current?.focus();\n }\n };\n document.addEventListener('keydown', onKey, true);\n return () => document.removeEventListener('keydown', onKey, true);\n }, [open]);\n\n const openPopover = () => {\n if (disabled) return;\n setViewYear(parsed?.year ?? now.getFullYear());\n setViewMonth(parsed?.month ?? now.getMonth());\n setOpen(true);\n };\n\n const commit = (day: number) => {\n const next = toISO(viewYear, viewMonth, day);\n if (value === undefined) setInner(next);\n onChange?.(next);\n setOpen(false);\n triggerRef.current?.focus();\n };\n\n const clear = () => {\n if (value === undefined) setInner('');\n onChange?.('');\n triggerRef.current?.focus();\n };\n\n // Inline, the calendar follows the field in the DOM, so Tab walks field -> calendar -> next field on its\n // own. Portalled to the end of <body> it does not, so the focus is handed over by hand to keep that order.\n const onBoxKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n if (e.key !== 'Tab' || e.shiftKey || !portalled) return;\n const controls = tabbables(e.currentTarget);\n if (e.target !== controls[controls.length - 1]) return; // not the control the calendar follows\n const first = tabbables(popoverRef.current)[0];\n if (!first) return;\n e.preventDefault();\n first.focus();\n };\n\n const onPopoverKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n if (e.key !== 'Tab') return;\n const controls = tabbables(boxRef.current);\n const field = controls[controls.length - 1]; // the control the calendar follows in the DOM\n const inside = tabbables(e.currentTarget);\n if (e.shiftKey && e.target === inside[0]) {\n e.preventDefault();\n field?.focus();\n } else if (!e.shiftKey && e.target === inside[inside.length - 1]) {\n // Not prevented on purpose: with the focus back on the field the Tab goes on to whatever follows it.\n setOpen(false);\n field?.focus();\n }\n };\n\n // One popover, two positions (see `useMenuPlacement` above): the calendar and its look are the same.\n const renderPopover = (position: React.CSSProperties) => (\n <div\n ref={popoverRef}\n role=\"dialog\"\n aria-label={label || copy.dialogLabel}\n tabIndex={-1}\n onKeyDown={portalled ? onPopoverKeyDown : undefined}\n style={sx({\n ...position,\n // The 7-column grid needs some floor width to stay readable -\n // a narrow field (e.g. a compact \"Data\" next to \"Motivo\")\n // would otherwise squeeze it. `left`/`right: 0` already\n // matches the trigger's own width for anything wider.\n minWidth: 272,\n background: 'var(--bg-surface)',\n border: 'var(--border-width-hairline) solid var(--border-default)',\n borderRadius: 'var(--radius-md)',\n boxShadow: 'var(--shadow-lg)',\n padding: 'var(--space-3)',\n outline: 'none',\n })}\n >\n <CalendarGrid\n year={viewYear}\n month={viewMonth}\n selectedDate={parsed && parsed.year === viewYear && parsed.month === viewMonth ? parsed.day : undefined}\n min={min}\n max={max}\n onMonthChange={(y, m) => {\n setViewYear(y);\n setViewMonth(m);\n onMonthChange?.(y, m);\n }}\n renderDay={renderDay}\n dayDots={dayDots}\n dayDotLabel={dayDotLabel}\n onSelectDate={commit}\n squareCells\n trimEmptyRows\n locale={locale}\n />\n </div>\n );\n\n return (\n <Field label={label} hint={hint} error={error} required={required} htmlFor={rid} style={containerStyle} preserveHelperSpace={preserveHelperSpace}>\n <div ref={rootRef} style={{ position: 'relative', width: '100%' }}>\n {/* The bordered box lives on this wrapper `div`, not on a `<button>`\n - the open-trigger and the clear (×) button are real, independent\n sibling buttons inside it, since a button can't nest another. */}\n <div ref={boxRef} onKeyDown={onBoxKeyDown} style={fieldBoxStyle(size, !!error, open, disabled)}>\n <button\n ref={triggerRef}\n id={rid}\n type=\"button\"\n disabled={disabled}\n aria-haspopup=\"dialog\"\n aria-expanded={open}\n // Ties the trigger to the hint / error line below, so they are read when it takes focus.\n {...fieldA11y(rid, { hint, error })}\n onClick={() => (open ? setOpen(false) : openPopover())}\n style={sx({\n flex: 1,\n minWidth: 0,\n display: 'flex',\n alignItems: 'center',\n gap: 'var(--space-2)',\n border: 'none',\n background: 'transparent',\n padding: 0,\n font: 'inherit',\n color: 'inherit',\n cursor: 'inherit',\n textAlign: 'left',\n })}\n >\n <CalendarIcon size={16} strokeWidth={1.75} style={{ flex: '0 0 auto', opacity: 0.7 }} />\n <span\n style={sx({\n flex: 1,\n textAlign: 'left',\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n whiteSpace: 'nowrap',\n color: iso ? 'inherit' : 'var(--text-muted)',\n })}\n >\n {iso ? formatDisplay(iso, locale) : (placeholder ?? copy.placeholder)}\n </span>\n </button>\n {iso && !disabled && (\n <button\n type=\"button\"\n aria-label={clearLabel ?? copy.clearLabel}\n onClick={(e) => {\n e.stopPropagation();\n clear();\n }}\n style={sx({\n flex: '0 0 auto',\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n marginRight: -4,\n padding: 4,\n border: 'none',\n borderRadius: 'var(--radius-sm)',\n background: 'transparent',\n color: 'var(--text-muted)',\n cursor: 'pointer',\n })}\n >\n <X size={14} strokeWidth={2} />\n </button>\n )}\n </div>\n\n {open && place?.strategy === 'inline' &&\n renderPopover({ position: 'absolute', top: 'calc(100% + 6px)', left: 0, right: 0, zIndex: 20 })}\n {open && place?.strategy === 'fixed' &&\n createPortal(\n renderPopover({\n position: 'fixed',\n top: fitTop ?? place.top, // `fitTop` is measured (see above); the hook's guess only holds the first, unpainted render\n left: place.left,\n width: Math.min(place.width, PORTALLED_MAX_WIDTH),\n boxSizing: 'border-box',\n zIndex: 1100, // above the Dialog (1000), level with Select / Autocomplete's portalled lists\n }),\n document.body,\n )}\n </div>\n </Field>\n );\n});\n\nDatePicker.displayName = 'DatePicker';\n"],"mappings":";AAmTM,cA6BI,YA7BJ;AAjTN,YAAY,WAAW;AACvB,SAAS,oBAAoB;AAC7B,SAAS,YAAY,cAAc,SAAS;AAC5C,SAAS,UAAU;AACnB,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,0BAA0B;AACnC,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;AAE7B,SAAS,gBAAgB,UAAU,aAAa,aAAa;AAC7D,SAAS,qBAAqB;AAE9B,MAAM,OAAO;AAAA,EACX,SAAS,EAAE,aAAa,mBAAmB,aAAa,iBAAiB,YAAY,cAAc;AAAA,EACnG,IAAI,EAAE,aAAa,eAAe,aAAa,iBAAiB,YAAY,aAAa;AAC3F;AAOA,MAAM,sBAAsB;AAG5B,SAAS,UAAU,MAAyC;AAC1D,MAAI,CAAC,KAAM,QAAO,CAAC;AACnB,SAAO,MAAM,KAAK,KAAK,iBAA8B,mCAAmC,CAAC,EAAE,OAAO,CAAC,OAAO,GAAG,YAAY,CAAC;AAC5H;AAyEA,SAAS,cAAc,KAAa,QAAgC;AAClE,QAAM,IAAI,SAAS,GAAG;AACtB,MAAI,CAAC,EAAG,QAAO;AACf,SAAO,IAAI,KAAK,eAAe,WAAW,OAAO,UAAU,SAAS,EAAE,KAAK,WAAW,OAAO,WAAW,MAAM,UAAU,CAAC,EAAE;AAAA,IACzH,IAAI,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG;AAAA,EACjC;AACF;AAgBO,MAAM,aAAa,MAAM,WAA8C,SAASA,YACrF;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,OAAO;AAAA,EACP,WAAW;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AA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,MAAM,YAAY;AAAA,gBAC3B,CAAC;AAAA,gBAEA,gBAAM,cAAc,KAAK,MAAM,IAAK,eAAe,KAAK;AAAA;AAAA,YAC3D;AAAA;AAAA;AAAA,MACF;AAAA,MACC,OAAO,CAAC,YACP;AAAA,QAAC;AAAA;AAAA,UACC,MAAK;AAAA,UACL,cAAY,cAAc,KAAK;AAAA,UAC/B,SAAS,CAAC,MAAM;AACd,cAAE,gBAAgB;AAClB,kBAAM;AAAA,UACR;AAAA,UACA,OAAO,GAAG;AAAA,YACR,MAAM;AAAA,YACN,SAAS;AAAA,YACT,YAAY;AAAA,YACZ,gBAAgB;AAAA,YAChB,aAAa;AAAA,YACb,SAAS;AAAA,YACT,QAAQ;AAAA,YACR,cAAc;AAAA,YACd,YAAY;AAAA,YACZ,OAAO;AAAA,YACP,QAAQ;AAAA,UACV,CAAC;AAAA,UAED,8BAAC,KAAE,MAAM,IAAI,aAAa,GAAG;AAAA;AAAA,MAC/B;AAAA,OAEJ;AAAA,IAEC,QAAQ,OAAO,aAAa,YAC3B,cAAc,EAAE,UAAU,YAAY,KAAK,oBAAoB,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,CAAC;AAAA,IAC/F,QAAQ,OAAO,aAAa,WAC3B;AAAA,MACE,cAAc;AAAA,QACZ,UAAU;AAAA,QACV,KAAK,UAAU,MAAM;AAAA;AAAA,QACrB,MAAM,MAAM;AAAA,QACZ,OAAO,KAAK,IAAI,MAAM,OAAO,mBAAmB;AAAA,QAChD,WAAW;AAAA,QACX,QAAQ;AAAA;AAAA,MACV,CAAC;AAAA,MACD,SAAS;AAAA,IACX;AAAA,KACJ,GACF;AAEJ,CAAC;AAED,WAAW,cAAc;","names":["DatePicker"]}
1
+ {"version":3,"sources":["../../src/forms/DatePicker.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { Calendar as CalendarIcon, X } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { Field } from '../_internal/Field';\nimport { fieldA11y } from '../_internal/fieldA11y';\nimport { useIsoLayoutEffect } from '../_internal/useIsoLayoutEffect';\nimport { useMenuPlacement } from '../_internal/useMenuPlacement';\nimport { useOutsidePress } from '../_internal/useOutsidePress';\nimport { CalendarGrid } from './_internal/CalendarGrid';\nimport type { CalendarDayContext, CalendarDayDots } from './_internal/calendarDots';\nimport { parseISODate as parseISO, toISODate as toISO } from './_internal/calendarRange';\nimport { fieldBoxStyle } from './_internal/fieldBoxStyle';\nimport { fieldBoxProps } from './_internal/fieldFrame';\n\nconst TEXT = {\n 'pt-BR': { placeholder: 'Selecionar data', dialogLabel: 'Escolher data', clearLabel: 'Limpar data' },\n en: { placeholder: 'Pick a date', dialogLabel: 'Choose a date', clearLabel: 'Clear date' },\n} as const;\n\n/**\n * The widest a calendar gets once it leaves the field's own width, i.e. when portalled out of a Dialog. Its\n * cells are square, so it is as tall as it is wide: at the width of a wide dialog field it would be a\n * 450px-tall slab that covers the field and half the window. Inline it is untouched (still the field's width).\n */\nconst PORTALLED_MAX_WIDTH = 320;\n\n/** What a keyboard can reach inside `root`, in tab order (the calendar's roving day has `tabindex=\"0\"`, the others `-1`). */\nfunction tabbables(root: HTMLElement | null): HTMLElement[] {\n if (!root) return [];\n return Array.from(root.querySelectorAll<HTMLElement>('button:not(:disabled), [tabindex]')).filter((el) => el.tabIndex >= 0);\n}\n\n/**\n * Imperative handle exposed via `ref` - there's no single native element\n * underneath (the trigger is a `<button>`, the value a plain ISO string in\n * React state), so `ref` can't hand back something `.value`-readable the way\n * a real `<input>` would. `focus()` is real and covers `setFocus()`-on-error;\n * reading the current value still means the `value`/`onChange` props, not the\n * ref. `onChange(value: string)` also isn't a `ChangeEvent`, so a plain\n * `{...register(name)}` spread won't work regardless - use `Controller`.\n */\nexport interface DatePickerHandle {\n focus: () => void;\n}\n\nexport interface DatePickerProps {\n label?: string;\n hint?: string;\n error?: string;\n required?: boolean;\n /** Defaults to the `locale`-appropriate text (\"Selecionar data\" / \"Pick a date\"). */\n placeholder?: string;\n size?: 'sm' | 'md' | 'lg';\n disabled?: boolean;\n /** Controlled value, ISO \"YYYY-MM-DD\". */\n value?: string;\n /** Uncontrolled initial value, ISO \"YYYY-MM-DD\". */\n defaultValue?: string;\n onChange?: (value: string) => void;\n /**\n * Earliest selectable date, ISO \"YYYY-MM-DD\". Every day before it is struck through, and the\n * calendar cannot be navigated to an earlier month or year (the previous-month arrow disables,\n * PageUp and the arrow keys stop at the edge, the month / year popover disables what is out of\n * range). An initial value or month before it opens on `min`'s month.\n */\n min?: string;\n /** 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. */\n max?: string;\n /**\n * Fires when the month on screen changes (the arrows, or the month / year popover), with the\n * new year and the 0-indexed month. Not when the popover opens: it opens on the month of the\n * value, or on the current one. Refresh `dayDots` / `renderDay` here.\n */\n onMonthChange?: (year: number, month: number) => void;\n /**\n * Content under each day number (a count, a note), the same as `DateTimePicker`'s. The second\n * argument says whether the day is `selected`, `today` or `unavailable`. When set, the day cells\n * grow taller to hold it.\n */\n renderDay?: (day: number, context: CalendarDayContext) => React.ReactNode;\n /**\n * The days that get a dot under their number, the same as `DateTimePicker`'s: day numbers\n * (`[3, 17]`), or an object keyed by day number for a per-dot `tone` or `label`. Day numbers of\n * the month on screen, so refresh them in `onMonthChange`.\n */\n dayDots?: CalendarDayDots;\n /** What a screen reader says for a dot with no `label` of its own. Defaults to the `locale`-appropriate text. */\n dayDotLabel?: string;\n id?: string;\n containerStyle?: React.CSSProperties;\n /** aria-label for the clear (×) button. Defaults to the `locale`-appropriate text. */\n clearLabel?: string;\n /**\n * The real Sereno product always renders pt-BR - this only exists so the\n * docs showcase can demo an English-speaking consumer without forking the\n * component. Default stays `'pt-BR'`.\n */\n locale?: 'pt-BR' | 'en';\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\nfunction formatDisplay(iso: string, locale: 'pt-BR' | 'en'): string {\n const d = parseISO(iso);\n if (!d) return iso;\n return new Intl.DateTimeFormat(locale === 'en' ? 'en-US' : 'pt-BR', { day: '2-digit', month: '2-digit', year: 'numeric' }).format(\n new Date(d.year, d.month, d.day),\n );\n}\n\n/**\n * Field for picking a single date - no time, no slots (`DateTimePicker`'s\n * job). A text-field-styled trigger showing the selected date opens a\n * popover with the same calendar grid `DateTimePicker` uses (roving\n * tabindex, month/year jump - see `./_internal/CalendarGrid`), so the two\n * share every bit of calendar behavior (SS-243).\n *\n * Value contract matches the rest of the forms package: `value` /\n * `defaultValue` + `onChange(value)`, a plain ISO \"YYYY-MM-DD\" string -\n * drops in wherever `<input type=\"date\">` would go, but themed instead of\n * the browser's own, and in pt-BR by default (the real Sereno product\n * always uses it; `locale=\"en\"` exists only for docs/demo purposes). A\n * clear (×) button appears once a value is set.\n */\nexport const DatePicker = React.forwardRef<DatePickerHandle, DatePickerProps>(function DatePicker(\n {\n label,\n hint,\n error,\n required,\n placeholder,\n size = 'md',\n disabled = false,\n value,\n defaultValue,\n onChange,\n min,\n max,\n onMonthChange,\n renderDay,\n dayDots,\n dayDotLabel,\n id,\n containerStyle,\n clearLabel,\n locale = 'pt-BR',\n preserveHelperSpace,\n },\n ref,\n) {\n const copy = TEXT[locale];\n const [inner, setInner] = React.useState(defaultValue ?? '');\n const iso = value !== undefined ? value : inner;\n const parsed = parseISO(iso);\n const now = React.useMemo(() => new Date(), []);\n\n const [open, setOpen] = React.useState(false);\n // The month currently shown in the popover - resets to the value's month\n // (or today's) every time the popover opens, via the conditional mount\n // below; CalendarGrid itself only takes year/month as its *initial* view.\n const [viewYear, setViewYear] = React.useState(parsed?.year ?? now.getFullYear());\n const [viewMonth, setViewMonth] = React.useState(parsed?.month ?? now.getMonth());\n\n const rootRef = React.useRef<HTMLDivElement>(null);\n const boxRef = React.useRef<HTMLDivElement>(null);\n const popoverRef = React.useRef<HTMLDivElement>(null);\n const triggerRef = React.useRef<HTMLButtonElement>(null);\n const generatedId = React.useId();\n const rid = id || generatedId;\n\n React.useImperativeHandle(ref, () => ({ focus: () => triggerRef.current?.focus() }), []);\n\n // Where the calendar sits. Normally a plain `position: absolute` child of\n // `rootRef` (itself `position: relative`) - the same \"inline\" strategy\n // Select's panel uses for its common case, and the same one DateTimePicker's\n // own month/year popover already uses. The browser glues it to the trigger\n // through *any* scroll (page or a nested overflow container) for free - no JS\n // measuring position, no listening for scroll/resize, and critically, it\n // never has to close on scroll the way a `position: fixed` popover computed\n // once would (that was tried first here and didn't hold up - see PR history).\n //\n // The one place that fails is inside a `position: fixed` container (a\n // Dialog): its body scrolls and clips an inline child, cutting the calendar\n // off. There `useMenuPlacement` answers 'fixed' (what Select and\n // Autocomplete already do) and the calendar is portalled to <body> at the\n // field's viewport rect, closing if the field moves. Outside a dialog nothing\n // changes: still inline, still below the field, never flipped (the hook's\n // `above` / `maxH` are not used at all: see `fitTop` for the portalled case).\n // `itemCount` is just the hook's height estimate; a calendar is not a list.\n const place = useMenuPlacement({\n open,\n anchorRef: boxRef,\n panelRef: popoverRef,\n itemCount: 8,\n onDismiss: () => setOpen(false),\n });\n const portalled = open && place?.strategy === 'fixed';\n\n // The hook picks \"below\" or \"above\" from a rough guess at the height, which suits a list capped at 288px but not\n // a calendar (about as tall as it is wide). So once the portalled calendar is on screen it is measured and kept\n // inside the window: under the field if it fits, else above it, else as far up as it needs (over the field rather\n // than cut off). The month changes the row count, hence the dependencies. Runs before paint: no visible jump.\n const [fitTop, setFitTop] = React.useState<number | null>(null);\n useIsoLayoutEffect(() => {\n const popover = popoverRef.current;\n const box = boxRef.current;\n if (!portalled || !popover || !box) return;\n const GAP = 6;\n const EDGE = 8;\n const field = box.getBoundingClientRect();\n const height = popover.offsetHeight;\n const viewport = window.innerHeight || document.documentElement.clientHeight || 900;\n const below = field.bottom + GAP;\n const above = field.top - GAP - height;\n setFitTop(below + height <= viewport - EDGE ? below : above >= EDGE ? above : Math.max(EDGE, viewport - EDGE - height));\n }, [portalled, place, viewYear, viewMonth]);\n\n // A press outside the field closes the calendar. The portalled calendar is outside `rootRef` in the DOM but\n // still part of the field, so both count as inside.\n useOutsidePress(open, [rootRef, popoverRef], () => setOpen(false));\n React.useEffect(() => {\n if (!open) return;\n const onKey = (e: KeyboardEvent) => {\n if (e.key === 'Escape') {\n e.preventDefault(); // handled: a Dialog around the field keeps its own Esc for the next press\n setOpen(false);\n triggerRef.current?.focus();\n }\n };\n document.addEventListener('keydown', onKey, true);\n return () => document.removeEventListener('keydown', onKey, true);\n }, [open]);\n\n const openPopover = () => {\n if (disabled) return;\n setViewYear(parsed?.year ?? now.getFullYear());\n setViewMonth(parsed?.month ?? now.getMonth());\n setOpen(true);\n };\n\n const commit = (day: number) => {\n const next = toISO(viewYear, viewMonth, day);\n if (value === undefined) setInner(next);\n onChange?.(next);\n setOpen(false);\n triggerRef.current?.focus();\n };\n\n const clear = () => {\n if (value === undefined) setInner('');\n onChange?.('');\n triggerRef.current?.focus();\n };\n\n // Inline, the calendar follows the field in the DOM, so Tab walks field -> calendar -> next field on its\n // own. Portalled to the end of <body> it does not, so the focus is handed over by hand to keep that order.\n const onBoxKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n if (e.key !== 'Tab' || e.shiftKey || !portalled) return;\n const controls = tabbables(e.currentTarget);\n if (e.target !== controls[controls.length - 1]) return; // not the control the calendar follows\n const first = tabbables(popoverRef.current)[0];\n if (!first) return;\n e.preventDefault();\n first.focus();\n };\n\n const onPopoverKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n if (e.key !== 'Tab') return;\n const controls = tabbables(boxRef.current);\n const field = controls[controls.length - 1]; // the control the calendar follows in the DOM\n const inside = tabbables(e.currentTarget);\n if (e.shiftKey && e.target === inside[0]) {\n e.preventDefault();\n field?.focus();\n } else if (!e.shiftKey && e.target === inside[inside.length - 1]) {\n // Not prevented on purpose: with the focus back on the field the Tab goes on to whatever follows it.\n setOpen(false);\n field?.focus();\n }\n };\n\n // One popover, two positions (see `useMenuPlacement` above): the calendar and its look are the same.\n const renderPopover = (position: React.CSSProperties) => (\n <div\n ref={popoverRef}\n role=\"dialog\"\n aria-label={label || copy.dialogLabel}\n tabIndex={-1}\n onKeyDown={portalled ? onPopoverKeyDown : undefined}\n style={sx({\n ...position,\n // The 7-column grid needs some floor width to stay readable -\n // a narrow field (e.g. a compact \"Data\" next to \"Motivo\")\n // would otherwise squeeze it. `left`/`right: 0` already\n // matches the trigger's own width for anything wider.\n minWidth: 272,\n background: 'var(--bg-surface)',\n border: 'var(--border-width-hairline) solid var(--border-default)',\n borderRadius: 'var(--radius-md)',\n boxShadow: 'var(--shadow-lg)',\n padding: 'var(--space-3)',\n outline: 'none',\n })}\n >\n <CalendarGrid\n year={viewYear}\n month={viewMonth}\n selectedDate={parsed && parsed.year === viewYear && parsed.month === viewMonth ? parsed.day : undefined}\n min={min}\n max={max}\n onMonthChange={(y, m) => {\n setViewYear(y);\n setViewMonth(m);\n onMonthChange?.(y, m);\n }}\n renderDay={renderDay}\n dayDots={dayDots}\n dayDotLabel={dayDotLabel}\n onSelectDate={commit}\n squareCells\n trimEmptyRows\n locale={locale}\n />\n </div>\n );\n\n return (\n <Field label={label} hint={hint} error={error} required={required} htmlFor={rid} style={containerStyle} preserveHelperSpace={preserveHelperSpace}>\n <div ref={rootRef} style={{ position: 'relative', width: '100%' }}>\n {/* The bordered box lives on this wrapper `div`, not on a `<button>`\n - the open-trigger and the clear (×) button are real, independent\n sibling buttons inside it, since a button can't nest another. */}\n <div ref={boxRef} onKeyDown={onBoxKeyDown} {...fieldBoxProps(open)} style={fieldBoxStyle(size, !!error, disabled)}>\n <button\n ref={triggerRef}\n id={rid}\n type=\"button\"\n disabled={disabled}\n aria-haspopup=\"dialog\"\n aria-expanded={open}\n // Ties the trigger to the hint / error line below, so they are read when it takes focus.\n {...fieldA11y(rid, { hint, error })}\n onClick={() => (open ? setOpen(false) : openPopover())}\n style={sx({\n flex: 1,\n minWidth: 0,\n display: 'flex',\n alignItems: 'center',\n gap: 'var(--space-2)',\n border: 'none',\n background: 'transparent',\n padding: 0,\n font: 'inherit',\n color: 'inherit',\n cursor: 'inherit',\n textAlign: 'left',\n })}\n >\n <CalendarIcon size={16} strokeWidth={1.75} style={{ flex: '0 0 auto', opacity: 0.7 }} />\n <span\n style={sx({\n flex: 1,\n textAlign: 'left',\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n whiteSpace: 'nowrap',\n color: iso ? 'inherit' : 'var(--text-muted)',\n })}\n >\n {iso ? formatDisplay(iso, locale) : (placeholder ?? copy.placeholder)}\n </span>\n </button>\n {iso && !disabled && (\n <button\n type=\"button\"\n aria-label={clearLabel ?? copy.clearLabel}\n onClick={(e) => {\n e.stopPropagation();\n clear();\n }}\n style={sx({\n flex: '0 0 auto',\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n marginRight: -4,\n padding: 4,\n border: 'none',\n borderRadius: 'var(--radius-sm)',\n background: 'transparent',\n color: 'var(--text-muted)',\n cursor: 'pointer',\n })}\n >\n <X size={14} strokeWidth={2} />\n </button>\n )}\n </div>\n\n {open && place?.strategy === 'inline' &&\n renderPopover({ position: 'absolute', top: 'calc(100% + 6px)', left: 0, right: 0, zIndex: 20 })}\n {open && place?.strategy === 'fixed' &&\n createPortal(\n renderPopover({\n position: 'fixed',\n top: fitTop ?? place.top, // `fitTop` is measured (see above); the hook's guess only holds the first, unpainted render\n left: place.left,\n width: Math.min(place.width, PORTALLED_MAX_WIDTH),\n boxSizing: 'border-box',\n zIndex: 1100, // above the Dialog (1000), level with Select / Autocomplete's portalled lists\n }),\n document.body,\n )}\n </div>\n </Field>\n );\n});\n\nDatePicker.displayName = 'DatePicker';\n"],"mappings":";AAoTM,cA6BI,YA7BJ;AAlTN,YAAY,WAAW;AACvB,SAAS,oBAAoB;AAC7B,SAAS,YAAY,cAAc,SAAS;AAC5C,SAAS,UAAU;AACnB,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,0BAA0B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AAClB,kBAAM;AAAA,UACR;AAAA,UACA,OAAO,GAAG;AAAA,YACR,MAAM;AAAA,YACN,SAAS;AAAA,YACT,YAAY;AAAA,YACZ,gBAAgB;AAAA,YAChB,aAAa;AAAA,YACb,SAAS;AAAA,YACT,QAAQ;AAAA,YACR,cAAc;AAAA,YACd,YAAY;AAAA,YACZ,OAAO;AAAA,YACP,QAAQ;AAAA,UACV,CAAC;AAAA,UAED,8BAAC,KAAE,MAAM,IAAI,aAAa,GAAG;AAAA;AAAA,MAC/B;AAAA,OAEJ;AAAA,IAEC,QAAQ,OAAO,aAAa,YAC3B,cAAc,EAAE,UAAU,YAAY,KAAK,oBAAoB,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,CAAC;AAAA,IAC/F,QAAQ,OAAO,aAAa,WAC3B;AAAA,MACE,cAAc;AAAA,QACZ,UAAU;AAAA,QACV,KAAK,UAAU,MAAM;AAAA;AAAA,QACrB,MAAM,MAAM;AAAA,QACZ,OAAO,KAAK,IAAI,MAAM,OAAO,mBAAmB;AAAA,QAChD,WAAW;AAAA,QACX,QAAQ;AAAA;AAAA,MACV,CAAC;AAAA,MACD,SAAS;AAAA,IACX;AAAA,KACJ,GACF;AAEJ,CAAC;AAED,WAAW,cAAc;","names":["DatePicker"]}
@@ -9,6 +9,7 @@ import { CharCount } from "../_internal/CharCount.js";
9
9
  import { formatMask, MASK_INPUTMODE, MASK_MAXLENGTH } from "../_internal/mask.js";
10
10
  import { mergeRefs } from "../_internal/mergeRefs.js";
11
11
  import { useValueLength } from "../_internal/useValueLength.js";
12
+ import { fieldFrameVars } from "./_internal/fieldFrame.js";
12
13
  const H = { sm: "var(--control-height-sm)", md: "var(--control-height-md)", lg: "var(--control-height-lg)" };
13
14
  const Input = React.forwardRef(function Input2({
14
15
  label,
@@ -28,8 +29,6 @@ const Input = React.forwardRef(function Input2({
28
29
  preserveHelperSpace,
29
30
  type,
30
31
  onChange,
31
- onFocus,
32
- onBlur,
33
32
  inputMode,
34
33
  maxLength,
35
34
  defaultValue,
@@ -38,7 +37,6 @@ const Input = React.forwardRef(function Input2({
38
37
  "aria-required": ariaRequired,
39
38
  ...rest
40
39
  }, ref) {
41
- const [focus, setFocus] = React.useState(false);
42
40
  const [reveal, setReveal] = React.useState(false);
43
41
  const inputRef = React.useRef(null);
44
42
  const autoId = React.useId();
@@ -65,14 +63,6 @@ const Input = React.forwardRef(function Input2({
65
63
  }
66
64
  onChange?.(e);
67
65
  } : onChange;
68
- const handleFocus = (e) => {
69
- setFocus(true);
70
- onFocus?.(e);
71
- };
72
- const handleBlur = (e) => {
73
- setFocus(false);
74
- onBlur?.(e);
75
- };
76
66
  return /* @__PURE__ */ jsx(
77
67
  Field,
78
68
  {
@@ -88,7 +78,9 @@ const Input = React.forwardRef(function Input2({
88
78
  children: /* @__PURE__ */ jsxs(
89
79
  "div",
90
80
  {
81
+ className: "sereno-field",
91
82
  style: sx({
83
+ ...fieldFrameVars(!!error),
92
84
  display: "flex",
93
85
  alignItems: "center",
94
86
  gap: "var(--space-2)",
@@ -96,8 +88,8 @@ const Input = React.forwardRef(function Input2({
96
88
  padding: "0 var(--space-3)",
97
89
  borderRadius: "var(--radius-control)",
98
90
  background: disabled ? "var(--interactive-disabled-bg)" : "var(--bg-surface)",
99
- border: "var(--border-width-hairline) solid " + (error ? "var(--interactive-error)" : focus ? "var(--border-focus)" : "var(--border-default)"),
100
- boxShadow: focus ? error ? "none" : "var(--focus-ring)" : "none",
91
+ borderWidth: "var(--border-width-hairline)",
92
+ borderStyle: "solid",
101
93
  transition: "var(--transition-control)"
102
94
  }),
103
95
  children: [
@@ -112,8 +104,6 @@ const Input = React.forwardRef(function Input2({
112
104
  ...a11y,
113
105
  ref: mergeRefs(inputRef, ref),
114
106
  type: isPassword && reveal ? "text" : type,
115
- onFocus: handleFocus,
116
- onBlur: handleBlur,
117
107
  onChange: handleChange,
118
108
  inputMode: mask ? inputMode ?? MASK_INPUTMODE[mask] ?? "numeric" : inputMode,
119
109
  maxLength: mask ? maxLength ?? MASK_MAXLENGTH[mask] : maxLength,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/forms/Input.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { Eye, EyeOff } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { Field } from '../_internal/Field';\nimport { fieldA11y } from '../_internal/fieldA11y';\nimport { CharCount } from '../_internal/CharCount';\nimport { formatMask, MASK_INPUTMODE, MASK_MAXLENGTH, type MaskName } from '../_internal/mask';\nimport { mergeRefs } from '../_internal/mergeRefs';\nimport { useValueLength } from '../_internal/useValueLength';\n\n/**\n * Single-line text field with label, hint and error states.\n */\nexport interface InputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size' | 'prefix'> {\n label?: string;\n /** Helper text under the field. Replaced by `error` when present. */\n hint?: string;\n /** Error message; also turns the border red. */\n error?: string;\n required?: boolean;\n size?: 'sm' | 'md' | 'lg';\n iconLeft?: React.ReactNode;\n /** Leading text adornment (e.g. \"R$\", \"@\", \"+55\"). Not part of the value. */\n prefix?: React.ReactNode;\n /** Trailing text or control (e.g. \"min\", a clear button). Not part of the value. */\n suffix?: React.ReactNode;\n /**\n * Format the value as the user types. A preset (`phone` / `cpf` / `cep` /\n * `currency`) or a custom pattern where `#` is one digit (`(##) #####-####`).\n * Sets `inputMode` and `maxLength` unless you pass your own.\n */\n mask?: MaskName | string;\n /**\n * Show a `n / max` character counter on the hint row. Implied when `maxLength`\n * is set; pass `showCount` on its own for a bare count with no ceiling.\n */\n showCount?: boolean;\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\nconst H = { sm: 'var(--control-height-sm)', md: 'var(--control-height-md)', lg: 'var(--control-height-lg)' } as const;\n\nexport const Input = React.forwardRef<HTMLInputElement, InputProps>(function Input(\n {\n label,\n hint,\n error,\n required,\n size = 'md',\n iconLeft,\n prefix,\n suffix,\n disabled,\n id,\n style,\n containerStyle,\n mask,\n showCount,\n preserveHelperSpace,\n type,\n onChange,\n onFocus,\n onBlur,\n inputMode,\n maxLength,\n defaultValue,\n 'aria-describedby': describedBy,\n 'aria-invalid': invalid,\n 'aria-required': ariaRequired,\n ...rest\n },\n ref,\n) {\n const [focus, setFocus] = React.useState(false);\n const [reveal, setReveal] = React.useState(false);\n const inputRef = React.useRef<HTMLInputElement>(null);\n // SSR-stable id (the DS source used Math.random(), which breaks hydration).\n const autoId = React.useId();\n const rid = id || autoId;\n // Names the hint / error line and flags the error, so a screen reader reads both with the field.\n const a11y = fieldA11y(rid, { hint, error, describedBy, invalid, required, ariaRequired });\n\n const isPassword = type === 'password';\n const showCounter = Boolean(showCount) || maxLength != null;\n\n const seed = mask && typeof defaultValue === 'string' ? formatMask(mask, defaultValue) : defaultValue;\n // Controlled: the count comes from `value`. Uncontrolled: from the element itself, so a\n // value written by code (react-hook-form's `reset()` / `setValue()`, `el.value = …`) counts too.\n const uncount = useValueLength(\n inputRef,\n showCounter && rest.value === undefined,\n typeof seed === 'string' || typeof seed === 'number' ? String(seed).length : 0,\n );\n const count = rest.value !== undefined ? String(rest.value ?? '').length : uncount;\n\n const handleChange = mask\n ? (e: React.ChangeEvent<HTMLInputElement>) => {\n const formatted = formatMask(mask, e.currentTarget.value);\n if (formatted !== e.currentTarget.value) {\n const el = e.currentTarget;\n el.value = formatted;\n // keep the caret at the end, the natural spot while typing forward\n try {\n el.setSelectionRange(formatted.length, formatted.length);\n } catch {\n /* type doesn't support selection */\n }\n }\n onChange?.(e);\n }\n : onChange;\n\n // Composed the same way as `handleChange` above - the focus ring's own\n // onFocus/onBlur must never be silently replaced by a caller's handler\n // (or by react-hook-form's `register()`, which always injects its own\n // onBlur), the way a plain `{...rest}` spread after them would do.\n const handleFocus = (e: React.FocusEvent<HTMLInputElement>) => {\n setFocus(true);\n onFocus?.(e);\n };\n const handleBlur = (e: React.FocusEvent<HTMLInputElement>) => {\n setFocus(false);\n onBlur?.(e);\n };\n\n return (\n <Field\n label={label}\n hint={hint}\n error={error}\n required={required}\n requiredExposed\n htmlFor={rid}\n style={containerStyle}\n counter={showCounter ? <CharCount count={count} max={maxLength ?? undefined} /> : undefined}\n preserveHelperSpace={preserveHelperSpace}\n >\n <div\n style={sx({\n display: 'flex',\n alignItems: 'center',\n gap: 'var(--space-2)',\n height: H[size] || H.md,\n padding: '0 var(--space-3)',\n borderRadius: 'var(--radius-control)',\n background: disabled ? 'var(--interactive-disabled-bg)' : 'var(--bg-surface)',\n border: 'var(--border-width-hairline) solid ' + (error ? 'var(--interactive-error)' : focus ? 'var(--border-focus)' : 'var(--border-default)'),\n boxShadow: focus ? (error ? 'none' : 'var(--focus-ring)') : 'none',\n transition: 'var(--transition-control)',\n })}\n >\n {iconLeft && <span style={sx({ display: 'flex', color: 'var(--text-muted)', flex: '0 0 auto' })}>{iconLeft}</span>}\n {prefix && (\n <span style={sx({ display: 'flex', alignItems: 'center', color: 'var(--text-muted)', fontSize: size === 'sm' ? 'var(--text-sm)' : 'var(--text-base)', lineHeight: 1.2, flex: '0 0 auto' })}>{prefix}</span>\n )}\n <input\n id={rid}\n disabled={disabled}\n {...rest}\n {...a11y}\n ref={mergeRefs(inputRef, ref)}\n type={isPassword && reveal ? 'text' : type}\n onFocus={handleFocus}\n onBlur={handleBlur}\n onChange={handleChange}\n inputMode={mask ? inputMode ?? MASK_INPUTMODE[mask] ?? 'numeric' : inputMode}\n maxLength={mask ? maxLength ?? MASK_MAXLENGTH[mask] : maxLength}\n defaultValue={mask && typeof defaultValue === 'string' ? formatMask(mask, defaultValue) : defaultValue}\n style={sx({\n flex: 1,\n minWidth: 0,\n margin: 0,\n padding: 0, // reset the UA input padding - the row's own padding insets it\n border: 'none',\n outline: 'none',\n background: 'transparent',\n fontFamily: 'var(--font-body)',\n fontSize: size === 'sm' ? 'var(--text-sm)' : 'var(--text-base)',\n lineHeight: 1.2, // match the prefix/suffix line box so baselines align\n color: disabled ? 'var(--text-disabled)' : 'var(--text-primary)',\n ...style,\n })}\n />\n {isPassword ? (\n <button\n type=\"button\"\n className=\"ds-affix-btn\"\n aria-label={reveal ? 'Ocultar senha' : 'Mostrar senha'}\n aria-pressed={reveal}\n onClick={() => {\n setReveal((r) => !r);\n inputRef.current?.focus();\n }}\n >\n {reveal ? <EyeOff size={16} strokeWidth={1.75} /> : <Eye size={16} strokeWidth={1.75} />}\n </button>\n ) : (\n suffix && (\n <span style={sx({ display: 'flex', alignItems: 'center', color: 'var(--text-muted)', fontSize: size === 'sm' ? 'var(--text-sm)' : 'var(--text-base)', lineHeight: 1.2, flex: '0 0 auto' })}>{suffix}</span>\n )\n )}\n </div>\n </Field>\n );\n});\n\nInput.displayName = 'Input';\n"],"mappings":";AA2I6B,cAGvB,YAHuB;AAzI7B,YAAY,WAAW;AACvB,SAAS,KAAK,cAAc;AAC5B,SAAS,UAAU;AACnB,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,YAAY,gBAAgB,sBAAqC;AAC1E,SAAS,iBAAiB;AAC1B,SAAS,sBAAsB;AAmC/B,MAAM,IAAI,EAAE,IAAI,4BAA4B,IAAI,4BAA4B,IAAI,2BAA2B;AAEpG,MAAM,QAAQ,MAAM,WAAyC,SAASA,OAC3E;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,OAAO;AAAA,EACP;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,oBAAoB;AAAA,EACpB,gBAAgB;AAAA,EAChB,iBAAiB;AAAA,EACjB,GAAG;AACL,GACA,KACA;AACA,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAS,KAAK;AAC9C,QAAM,CAAC,QAAQ,SAAS,IAA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AAmB;AAAA,kBAC7C,YAAY;AAAA;AAAA,kBACZ,OAAO,WAAW,yBAAyB;AAAA,kBAC3C,GAAG;AAAA,gBACL,CAAC;AAAA;AAAA,YACH;AAAA,YACC,aACC;AAAA,cAAC;AAAA;AAAA,gBACC,MAAK;AAAA,gBACL,WAAU;AAAA,gBACV,cAAY,SAAS,kBAAkB;AAAA,gBACvC,gBAAc;AAAA,gBACd,SAAS,MAAM;AACb,4BAAU,CAAC,MAAM,CAAC,CAAC;AACnB,2BAAS,SAAS,MAAM;AAAA,gBAC1B;AAAA,gBAEC,mBAAS,oBAAC,UAAO,MAAM,IAAI,aAAa,MAAM,IAAK,oBAAC,OAAI,MAAM,IAAI,aAAa,MAAM;AAAA;AAAA,YACxF,IAEA,UACE,oBAAC,UAAK,OAAO,GAAG,EAAE,SAAS,QAAQ,YAAY,UAAU,OAAO,qBAAqB,UAAU,SAAS,OAAO,mBAAmB,oBAAoB,YAAY,KAAK,MAAM,WAAW,CAAC,GAAI,kBAAO;AAAA;AAAA;AAAA,MAG1M;AAAA;AAAA,EACF;AAEJ,CAAC;AAED,MAAM,cAAc;","names":["Input"]}
1
+ {"version":3,"sources":["../../src/forms/Input.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { Eye, EyeOff } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { Field } from '../_internal/Field';\nimport { fieldA11y } from '../_internal/fieldA11y';\nimport { CharCount } from '../_internal/CharCount';\nimport { formatMask, MASK_INPUTMODE, MASK_MAXLENGTH, type MaskName } from '../_internal/mask';\nimport { mergeRefs } from '../_internal/mergeRefs';\nimport { useValueLength } from '../_internal/useValueLength';\nimport { fieldFrameVars } from './_internal/fieldFrame';\n\n/**\n * Single-line text field with label, hint and error states.\n */\nexport interface InputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size' | 'prefix'> {\n label?: string;\n /** Helper text under the field. Replaced by `error` when present. */\n hint?: string;\n /** Error message; also turns the border red. */\n error?: string;\n required?: boolean;\n size?: 'sm' | 'md' | 'lg';\n iconLeft?: React.ReactNode;\n /** Leading text adornment (e.g. \"R$\", \"@\", \"+55\"). Not part of the value. */\n prefix?: React.ReactNode;\n /** Trailing text or control (e.g. \"min\", a clear button). Not part of the value. */\n suffix?: React.ReactNode;\n /**\n * Format the value as the user types. A preset (`phone` / `cpf` / `cep` /\n * `currency`) or a custom pattern where `#` is one digit (`(##) #####-####`).\n * Sets `inputMode` and `maxLength` unless you pass your own.\n */\n mask?: MaskName | string;\n /**\n * Show a `n / max` character counter on the hint row. Implied when `maxLength`\n * is set; pass `showCount` on its own for a bare count with no ceiling.\n */\n showCount?: boolean;\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\nconst H = { sm: 'var(--control-height-sm)', md: 'var(--control-height-md)', lg: 'var(--control-height-lg)' } as const;\n\nexport const Input = React.forwardRef<HTMLInputElement, InputProps>(function Input(\n {\n label,\n hint,\n error,\n required,\n size = 'md',\n iconLeft,\n prefix,\n suffix,\n disabled,\n id,\n style,\n containerStyle,\n mask,\n showCount,\n preserveHelperSpace,\n type,\n onChange,\n inputMode,\n maxLength,\n defaultValue,\n 'aria-describedby': describedBy,\n 'aria-invalid': invalid,\n 'aria-required': ariaRequired,\n ...rest\n },\n ref,\n) {\n const [reveal, setReveal] = React.useState(false);\n const inputRef = React.useRef<HTMLInputElement>(null);\n // SSR-stable id (the DS source used Math.random(), which breaks hydration).\n const autoId = React.useId();\n const rid = id || autoId;\n // Names the hint / error line and flags the error, so a screen reader reads both with the field.\n const a11y = fieldA11y(rid, { hint, error, describedBy, invalid, required, ariaRequired });\n\n const isPassword = type === 'password';\n const showCounter = Boolean(showCount) || maxLength != null;\n\n const seed = mask && typeof defaultValue === 'string' ? formatMask(mask, defaultValue) : defaultValue;\n // Controlled: the count comes from `value`. Uncontrolled: from the element itself, so a\n // value written by code (react-hook-form's `reset()` / `setValue()`, `el.value = …`) counts too.\n const uncount = useValueLength(\n inputRef,\n showCounter && rest.value === undefined,\n typeof seed === 'string' || typeof seed === 'number' ? String(seed).length : 0,\n );\n const count = rest.value !== undefined ? String(rest.value ?? '').length : uncount;\n\n const handleChange = mask\n ? (e: React.ChangeEvent<HTMLInputElement>) => {\n const formatted = formatMask(mask, e.currentTarget.value);\n if (formatted !== e.currentTarget.value) {\n const el = e.currentTarget;\n el.value = formatted;\n // keep the caret at the end, the natural spot while typing forward\n try {\n el.setSelectionRange(formatted.length, formatted.length);\n } catch {\n /* type doesn't support selection */\n }\n }\n onChange?.(e);\n }\n : onChange;\n\n return (\n <Field\n label={label}\n hint={hint}\n error={error}\n required={required}\n requiredExposed\n htmlFor={rid}\n style={containerStyle}\n counter={showCounter ? <CharCount count={count} max={maxLength ?? undefined} /> : undefined}\n preserveHelperSpace={preserveHelperSpace}\n >\n <div\n // The border colour and the focus ring are CSS: the row lights up while its text box has the focus\n // (`.sereno-field` in styles.css, SS-582), so the field keeps no focus state and a caller's\n // `onFocus` / `onBlur` (react-hook-form's `register()` injects one) reaches the `<input>` untouched.\n className=\"sereno-field\"\n style={sx({\n ...fieldFrameVars(!!error),\n display: 'flex',\n alignItems: 'center',\n gap: 'var(--space-2)',\n height: H[size] || H.md,\n padding: '0 var(--space-3)',\n borderRadius: 'var(--radius-control)',\n background: disabled ? 'var(--interactive-disabled-bg)' : 'var(--bg-surface)',\n borderWidth: 'var(--border-width-hairline)',\n borderStyle: 'solid',\n transition: 'var(--transition-control)',\n })}\n >\n {iconLeft && <span style={sx({ display: 'flex', color: 'var(--text-muted)', flex: '0 0 auto' })}>{iconLeft}</span>}\n {prefix && (\n <span style={sx({ display: 'flex', alignItems: 'center', color: 'var(--text-muted)', fontSize: size === 'sm' ? 'var(--text-sm)' : 'var(--text-base)', lineHeight: 1.2, flex: '0 0 auto' })}>{prefix}</span>\n )}\n <input\n id={rid}\n disabled={disabled}\n {...rest}\n {...a11y}\n ref={mergeRefs(inputRef, ref)}\n type={isPassword && reveal ? 'text' : type}\n onChange={handleChange}\n inputMode={mask ? inputMode ?? MASK_INPUTMODE[mask] ?? 'numeric' : inputMode}\n maxLength={mask ? maxLength ?? MASK_MAXLENGTH[mask] : maxLength}\n defaultValue={mask && typeof defaultValue === 'string' ? formatMask(mask, defaultValue) : defaultValue}\n style={sx({\n flex: 1,\n minWidth: 0,\n margin: 0,\n padding: 0, // reset the UA input padding - the row's own padding insets it\n border: 'none',\n outline: 'none',\n background: 'transparent',\n fontFamily: 'var(--font-body)',\n fontSize: size === 'sm' ? 'var(--text-sm)' : 'var(--text-base)',\n lineHeight: 1.2, // match the prefix/suffix line box so baselines align\n color: disabled ? 'var(--text-disabled)' : 'var(--text-primary)',\n ...style,\n })}\n />\n {isPassword ? (\n <button\n type=\"button\"\n className=\"ds-affix-btn\"\n aria-label={reveal ? 'Ocultar senha' : 'Mostrar senha'}\n aria-pressed={reveal}\n onClick={() => {\n setReveal((r) => !r);\n inputRef.current?.focus();\n }}\n >\n {reveal ? <EyeOff size={16} strokeWidth={1.75} /> : <Eye size={16} strokeWidth={1.75} />}\n </button>\n ) : (\n suffix && (\n <span style={sx({ display: 'flex', alignItems: 'center', color: 'var(--text-muted)', fontSize: size === 'sm' ? 'var(--text-sm)' : 'var(--text-base)', lineHeight: 1.2, flex: '0 0 auto' })}>{suffix}</span>\n )\n )}\n </div>\n </Field>\n );\n});\n\nInput.displayName = 'Input';\n"],"mappings":";AA4H6B,cAGvB,YAHuB;AA1H7B,YAAY,WAAW;AACvB,SAAS,KAAK,cAAc;AAC5B,SAAS,UAAU;AACnB,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,YAAY,gBAAgB,sBAAqC;AAC1E,SAAS,iBAAiB;AAC1B,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAmC/B,MAAM,IAAI,EAAE,IAAI,4BAA4B,IAAI,4BAA4B,IAAI,2BAA2B;AAEpG,MAAM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R,MAAM;AAAA,kBACN,UAAU;AAAA,kBACV,QAAQ;AAAA,kBACR,SAAS;AAAA;AAAA,kBACT,QAAQ;AAAA,kBACR,SAAS;AAAA,kBACT,YAAY;AAAA,kBACZ,YAAY;AAAA,kBACZ,UAAU,SAAS,OAAO,mBAAmB;AAAA,kBAC7C,YAAY;AAAA;AAAA,kBACZ,OAAO,WAAW,yBAAyB;AAAA,kBAC3C,GAAG;AAAA,gBACL,CAAC;AAAA;AAAA,YACH;AAAA,YACC,aACC;AAAA,cAAC;AAAA;AAAA,gBACC,MAAK;AAAA,gBACL,WAAU;AAAA,gBACV,cAAY,SAAS,kBAAkB;AAAA,gBACvC,gBAAc;AAAA,gBACd,SAAS,MAAM;AACb,4BAAU,CAAC,MAAM,CAAC,CAAC;AACnB,2BAAS,SAAS,MAAM;AAAA,gBAC1B;AAAA,gBAEC,mBAAS,oBAAC,UAAO,MAAM,IAAI,aAAa,MAAM,IAAK,oBAAC,OAAI,MAAM,IAAI,aAAa,MAAM;AAAA;AAAA,YACxF,IAEA,UACE,oBAAC,UAAK,OAAO,GAAG,EAAE,SAAS,QAAQ,YAAY,UAAU,OAAO,qBAAqB,UAAU,SAAS,OAAO,mBAAmB,oBAAoB,YAAY,KAAK,MAAM,WAAW,CAAC,GAAI,kBAAO;AAAA;AAAA;AAAA,MAG1M;AAAA;AAAA,EACF;AAEJ,CAAC;AAED,MAAM,cAAc;","names":["Input"]}
@@ -2,15 +2,14 @@
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
3
  import * as React from "react";
4
4
  import { sx } from "../_internal/style.js";
5
+ import { choiceVars } from "./_internal/choiceVars.js";
5
6
  const Radio = React.forwardRef(function Radio2({ label, description, error, checked, defaultChecked, disabled, size = "md", preserveHelperSpace = false, onChange, style, ...rest }, ref) {
6
- const [hover, setHover] = React.useState(false);
7
7
  const box = size === "sm" ? 16 : 20;
8
8
  return /* @__PURE__ */ jsxs(
9
9
  "label",
10
10
  {
11
- onMouseEnter: () => setHover(true),
12
- onMouseLeave: () => setHover(false),
13
- style: sx({ display: "flex", gap: "var(--space-3)", alignItems: "flex-start", cursor: disabled ? "not-allowed" : "pointer", opacity: disabled ? 0.6 : 1, ...style }),
11
+ className: "sereno-choice",
12
+ style: sx({ ...choiceVars(error), display: "flex", gap: "var(--space-3)", alignItems: "flex-start", cursor: disabled ? "not-allowed" : "pointer", opacity: disabled ? 0.6 : 1, ...style }),
14
13
  children: [
15
14
  /* @__PURE__ */ jsx("span", { style: sx({ position: "relative", display: "inline-flex", flex: "0 0 auto", marginTop: size === "sm" ? 3 : 1 }), children: /* @__PURE__ */ jsx(
16
15
  "input",
@@ -30,7 +29,9 @@ const Radio = React.forwardRef(function Radio2({ label, description, error, chec
30
29
  height: box,
31
30
  margin: 0,
32
31
  borderRadius: "var(--radius-pill)",
33
- border: "var(--border-width-emphasis) solid " + (error ? "var(--interactive-error)" : hover && !disabled ? "var(--border-brand)" : "var(--border-strong)"),
32
+ // The colour is the stylesheet's (`border-color` of `.sereno-radio`), so the hover can change it.
33
+ borderWidth: "var(--border-width-emphasis)",
34
+ borderStyle: "solid",
34
35
  backgroundColor: "var(--bg-surface)",
35
36
  cursor: "inherit",
36
37
  transition: "var(--transition-control)"
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/forms/Radio.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { sx } from '../_internal/style';\n\n/**\n * Single-choice control for mutually exclusive options (payment method, appointment format).\n * Group by giving every option the same `name`. Visually matched to `Checkbox` - same 20px\n * box, same hover and label/description rhythm - differing only in the pill radius and dot.\n * Host must include the `.sereno-radio:checked` rule (see globals.css).\n *\n * Wrap every group in a `<fieldset>` / `<legend>` - `name` alone makes the browser treat\n * the options as one native group (arrow keys move between them, only one can be checked),\n * but without a `<legend>` a screen reader has no accessible name for what the choice is\n * between, only \"Online, radio button, 1 of 3\" with no context.\n */\nexport interface RadioProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type' | 'size'> {\n label?: string;\n /** Secondary line under the label. Replaced by `error` when present. */\n description?: string;\n /** Error message - tints the circle and the secondary line red. Replaces `description`. */\n error?: string;\n /** Circle size. `sm` (16px) for dense lists; `md` (20px) everywhere else. Matches `Checkbox`. */\n size?: 'sm' | 'md';\n /**\n * Reserve the description/error row's height even with neither set - keeps\n * the row stable as `error` comes and goes (SS-259, same mechanism as\n * `Input`'s `preserveHelperSpace`). Off by default.\n */\n preserveHelperSpace?: boolean;\n}\n\nexport const Radio = React.forwardRef<HTMLInputElement, RadioProps>(function Radio(\n { label, description, error, checked, defaultChecked, disabled, size = 'md', preserveHelperSpace = false, onChange, style, ...rest },\n ref,\n) {\n const [hover, setHover] = React.useState(false);\n const box = size === 'sm' ? 16 : 20;\n return (\n <label\n onMouseEnter={() => setHover(true)}\n onMouseLeave={() => setHover(false)}\n style={sx({ display: 'flex', gap: 'var(--space-3)', alignItems: 'flex-start', cursor: disabled ? 'not-allowed' : 'pointer', opacity: disabled ? 0.6 : 1, ...style })}\n >\n <span style={sx({ position: 'relative', display: 'inline-flex', flex: '0 0 auto', marginTop: size === 'sm' ? 3 : 1 })}>\n <input\n ref={ref}\n type=\"radio\"\n checked={checked}\n defaultChecked={defaultChecked}\n disabled={disabled}\n onChange={onChange}\n {...rest}\n data-size={size}\n className=\"sereno-radio\"\n style={sx({\n appearance: 'none',\n width: box,\n height: box,\n margin: 0,\n borderRadius: 'var(--radius-pill)',\n border: 'var(--border-width-emphasis) solid ' + (error ? 'var(--interactive-error)' : hover && !disabled ? 'var(--border-brand)' : 'var(--border-strong)'),\n backgroundColor: 'var(--bg-surface)',\n cursor: 'inherit',\n transition: 'var(--transition-control)',\n })}\n />\n </span>\n <span style={sx({ display: 'flex', flexDirection: 'column', gap: 2 })}>\n {label && <span style={sx({ fontFamily: 'var(--font-body)', fontSize: 'var(--text-base)', color: 'var(--text-primary)', lineHeight: 1.35 })}>{label}</span>}\n {(description || error || preserveHelperSpace) && (\n <span\n style={sx({\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-xs)',\n color: error ? 'var(--interactive-error)' : 'var(--text-muted)',\n lineHeight: 1.45,\n minHeight: preserveHelperSpace ? 'calc(var(--text-xs) * 1.45)' : undefined,\n })}\n >\n {error || description}\n </span>\n )}\n </span>\n </label>\n );\n});\n\nRadio.displayName = 'Radio';"],"mappings":";AA6CQ,cAuBF,YAvBE;AA3CR,YAAY,WAAW;AACvB,SAAS,UAAU;AA6BZ,MAAM,QAAQ,MAAM,WAAyC,SAASA,OAC3E,EAAE,OAAO,aAAa,OAAO,SAAS,gBAAgB,UAAU,OAAO,MAAM,sBAAsB,OAAO,UAAU,OAAO,GAAG,KAAK,GACnI,KACA;AACA,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAS,KAAK;AAC9C,QAAM,MAAM,SAAS,OAAO,KAAK;AACjC,SACE;AAAA,IAAC;AAAA;AAAA,MACC,cAAc,MAAM,SAAS,IAAI;AAAA,MACjC,cAAc,MAAM,SAAS,KAAK;AAAA,MAClC,OAAO,GAAG,EAAE,SAAS,QAAQ,KAAK,kBAAkB,YAAY,cAAc,QAAQ,WAAW,gBAAgB,WAAW,SAAS,WAAW,MAAM,GAAG,GAAG,MAAM,CAAC;AAAA,MAEnK;AAAA,4BAAC,UAAK,OAAO,GAAG,EAAE,UAAU,YAAY,SAAS,eAAe,MAAM,YAAY,WAAW,SAAS,OAAO,IAAI,EAAE,CAAC,GAClH;AAAA,UAAC;AAAA;AAAA,YACC;AAAA,YACA,MAAK;AAAA,YACL;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACC,GAAG;AAAA,YACJ,aAAW;AAAA,YACX,WAAU;AAAA,YACV,OAAO,GAAG;AAAA,cACR,YAAY;AAAA,cACZ,OAAO;AAAA,cACP,QAAQ;AAAA,cACR,QAAQ;AAAA,cACR,cAAc;AAAA,cACd,QAAQ,yCAAyC,QAAQ,6BAA6B,SAAS,CAAC,WAAW,wBAAwB;AAAA,cACnI,iBAAiB;AAAA,cACjB,QAAQ;AAAA,cACR,YAAY;AAAA,YACd,CAAC;AAAA;AAAA,QACH,GACF;AAAA,QACA,qBAAC,UAAK,OAAO,GAAG,EAAE,SAAS,QAAQ,eAAe,UAAU,KAAK,EAAE,CAAC,GACjE;AAAA,mBAAS,oBAAC,UAAK,OAAO,GAAG,EAAE,YAAY,oBAAoB,UAAU,oBAAoB,OAAO,uBAAuB,YAAY,KAAK,CAAC,GAAI,iBAAM;AAAA,WAClJ,eAAe,SAAS,wBACxB;AAAA,YAAC;AAAA;AAAA,cACC,OAAO,GAAG;AAAA,gBACR,YAAY;AAAA,gBACZ,UAAU;AAAA,gBACV,OAAO,QAAQ,6BAA6B;AAAA,gBAC5C,YAAY;AAAA,gBACZ,WAAW,sBAAsB,gCAAgC;AAAA,cACnE,CAAC;AAAA,cAEA,mBAAS;AAAA;AAAA,UACZ;AAAA,WAEJ;AAAA;AAAA;AAAA,EACF;AAEJ,CAAC;AAED,MAAM,cAAc;","names":["Radio"]}
1
+ {"version":3,"sources":["../../src/forms/Radio.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { sx } from '../_internal/style';\nimport { choiceVars } from './_internal/choiceVars';\n\n/**\n * Single-choice control for mutually exclusive options (payment method, appointment format).\n * Group by giving every option the same `name`. Visually matched to `Checkbox` - same 20px\n * box, same hover and label/description rhythm - differing only in the pill radius and dot.\n * Host must include the `.sereno-radio:checked` rule (see globals.css).\n *\n * Wrap every group in a `<fieldset>` / `<legend>` - `name` alone makes the browser treat\n * the options as one native group (arrow keys move between them, only one can be checked),\n * but without a `<legend>` a screen reader has no accessible name for what the choice is\n * between, only \"Online, radio button, 1 of 3\" with no context.\n */\nexport interface RadioProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type' | 'size'> {\n label?: string;\n /** Secondary line under the label. Replaced by `error` when present. */\n description?: string;\n /** Error message - tints the circle and the secondary line red. Replaces `description`. */\n error?: string;\n /** Circle size. `sm` (16px) for dense lists; `md` (20px) everywhere else. Matches `Checkbox`. */\n size?: 'sm' | 'md';\n /**\n * Reserve the description/error row's height even with neither set - keeps\n * the row stable as `error` comes and goes (SS-259, same mechanism as\n * `Input`'s `preserveHelperSpace`). Off by default.\n */\n preserveHelperSpace?: boolean;\n}\n\nexport const Radio = React.forwardRef<HTMLInputElement, RadioProps>(function Radio(\n { label, description, error, checked, defaultChecked, disabled, size = 'md', preserveHelperSpace = false, onChange, style, ...rest },\n ref,\n) {\n const box = size === 'sm' ? 16 : 20;\n return (\n <label\n className=\"sereno-choice\"\n // The border colours `.sereno-radio` (styles.css) paints, idle and while the pointer is on the row (SS-577).\n style={sx({ ...choiceVars(error), display: 'flex', gap: 'var(--space-3)', alignItems: 'flex-start', cursor: disabled ? 'not-allowed' : 'pointer', opacity: disabled ? 0.6 : 1, ...style })}\n >\n <span style={sx({ position: 'relative', display: 'inline-flex', flex: '0 0 auto', marginTop: size === 'sm' ? 3 : 1 })}>\n <input\n ref={ref}\n type=\"radio\"\n checked={checked}\n defaultChecked={defaultChecked}\n disabled={disabled}\n onChange={onChange}\n {...rest}\n data-size={size}\n className=\"sereno-radio\"\n style={sx({\n appearance: 'none',\n width: box,\n height: box,\n margin: 0,\n borderRadius: 'var(--radius-pill)',\n // The colour is the stylesheet's (`border-color` of `.sereno-radio`), so the hover can change it.\n borderWidth: 'var(--border-width-emphasis)',\n borderStyle: 'solid',\n backgroundColor: 'var(--bg-surface)',\n cursor: 'inherit',\n transition: 'var(--transition-control)',\n })}\n />\n </span>\n <span style={sx({ display: 'flex', flexDirection: 'column', gap: 2 })}>\n {label && <span style={sx({ fontFamily: 'var(--font-body)', fontSize: 'var(--text-base)', color: 'var(--text-primary)', lineHeight: 1.35 })}>{label}</span>}\n {(description || error || preserveHelperSpace) && (\n <span\n style={sx({\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-xs)',\n color: error ? 'var(--interactive-error)' : 'var(--text-muted)',\n lineHeight: 1.45,\n minHeight: preserveHelperSpace ? 'calc(var(--text-xs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AAoB,UAAU,oBAAoB,OAAO,uBAAuB,YAAY,KAAK,CAAC,GAAI,iBAAM;AAAA,WAClJ,eAAe,SAAS,wBACxB;AAAA,YAAC;AAAA;AAAA,cACC,OAAO,GAAG;AAAA,gBACR,YAAY;AAAA,gBACZ,UAAU;AAAA,gBACV,OAAO,QAAQ,6BAA6B;AAAA,gBAC5C,YAAY;AAAA,gBACZ,WAAW,sBAAsB,gCAAgC;AAAA,cACnE,CAAC;AAAA,cAEA,mBAAS;AAAA;AAAA,UACZ;AAAA,WAEJ;AAAA;AAAA;AAAA,EACF;AAEJ,CAAC;AAED,MAAM,cAAc;","names":["Radio"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/forms/SearchInput.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { Search, X } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { Input, type InputProps } from './Input';\n\n/**\n * A search field: `Input` with a leading magnifier, a clear (×) button, and a\n * **debounced** `onSearch`. `Enter` searches immediately; `Esc` clears.\n *\n * A caller's `onKeyDown` runs first, on every key. Calling `preventDefault()` on\n * the event there says it was handled, and the built-in `Enter` / `Esc` are skipped\n * (the same \"handled\" rule a popup's `Esc` follows inside a `Dialog`).\n */\nexport interface SearchInputProps\n extends Omit<InputProps, 'iconLeft' | 'suffix' | 'prefix' | 'type' | 'mask' | 'showCount' | 'value' | 'defaultValue' | 'onChange'> {\n value?: string;\n defaultValue?: string;\n /** Every keystroke and on clear - the plain string. */\n onValueChange?: (value: string) => void;\n /** Debounced (and on `Enter` / clear) - run the actual query here. */\n onSearch?: (value: string) => void;\n /** Debounce for `onSearch`, in ms. */\n debounce?: number;\n /** aria-label for the clear button. */\n clearLabel?: string;\n}\n\nexport const SearchInput = React.forwardRef<HTMLInputElement, SearchInputProps>(function SearchInput(\n { value, defaultValue, onValueChange, onSearch, onKeyDown, debounce = 250, clearLabel = 'Clear search', placeholder = 'Search…', disabled, ...rest },\n ref,\n) {\n const [internal, setInternal] = React.useState(defaultValue ?? '');\n const text = value !== undefined ? value : internal;\n\n const timer = React.useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n React.useEffect(() => () => clearTimeout(timer.current), []);\n\n const runSearch = (v: string, immediate: boolean) => {\n clearTimeout(timer.current);\n if (immediate) onSearch?.(v);\n else timer.current = setTimeout(() => onSearch?.(v), debounce);\n };\n\n const update = (v: string, immediate = false) => {\n if (value === undefined) setInternal(v);\n onValueChange?.(v);\n runSearch(v, immediate);\n };\n\n const clear = () => update('', true);\n\n // Composed, not replaced: a plain `{...rest}` spread followed by our own `onKeyDown` used to drop the caller's\n // silently (the same class of bug `Input` and `Textarea` already guard against for onFocus / onBlur / onChange).\n // The caller's runs first and can opt out of the built-in keys with `preventDefault()`.\n const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n onKeyDown?.(e);\n if (e.defaultPrevented) return;\n if (e.key === 'Enter') runSearch(e.currentTarget.value, true);\n else if (e.key === 'Escape' && text) {\n e.preventDefault();\n clear();\n }\n };\n\n return (\n <Input\n ref={ref}\n {...rest}\n role=\"searchbox\"\n enterKeyHint=\"search\"\n autoComplete=\"off\"\n spellCheck={false}\n placeholder={placeholder}\n disabled={disabled}\n value={text}\n onChange={(e) => update(e.currentTarget.value)}\n onKeyDown={handleKeyDown}\n iconLeft={<Search size={16} strokeWidth={1.75} />}\n suffix={\n text && !disabled ? (\n <button\n type=\"button\"\n className=\"ds-affix-btn\"\n aria-label={clearLabel}\n onClick={clear}\n style={sx({ display: 'inline-flex', alignItems: 'center', border: 'none', background: 'transparent', color: 'var(--text-muted)', cursor: 'pointer', padding: 0 })}\n >\n <X size={16} strokeWidth={2} />\n </button>\n ) : undefined\n }\n />\n );\n});\n\nSearchInput.displayName = 'SearchInput';\n"],"mappings":";AA+EgB;AA7EhB,YAAY,WAAW;AACvB,SAAS,QAAQ,SAAS;AAC1B,SAAS,UAAU;AACnB,SAAS,aAA8B;AAwBhC,MAAM,cAAc,MAAM,WAA+C,SAASA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AAC;AAAA;AAAA,UACC,MAAK;AAAA,UACL,WAAU;AAAA,UACV,cAAY;AAAA,UACZ,SAAS;AAAA,UACT,OAAO,GAAG,EAAE,SAAS,eAAe,YAAY,UAAU,QAAQ,QAAQ,YAAY,eAAe,OAAO,qBAAqB,QAAQ,WAAW,SAAS,EAAE,CAAC;AAAA,UAEhK,8BAAC,KAAE,MAAM,IAAI,aAAa,GAAG;AAAA;AAAA,MAC/B,IACE;AAAA;AAAA,EAER;AAEJ,CAAC;AAED,YAAY,cAAc;","names":["SearchInput"]}
1
+ {"version":3,"sources":["../../src/forms/SearchInput.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { Search, X } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { Input, type InputProps } from './Input';\n\n/**\n * A search field: `Input` with a leading magnifier, a clear (×) button, and a\n * **debounced** `onSearch`. `Enter` searches immediately; `Esc` clears.\n *\n * A caller's `onKeyDown` runs first, on every key. Calling `preventDefault()` on\n * the event there says it was handled, and the built-in `Enter` / `Esc` are skipped\n * (the same \"handled\" rule a popup's `Esc` follows inside a `Dialog`).\n */\nexport interface SearchInputProps\n extends Omit<InputProps, 'iconLeft' | 'suffix' | 'prefix' | 'type' | 'mask' | 'showCount' | 'value' | 'defaultValue' | 'onChange'> {\n value?: string;\n defaultValue?: string;\n /** Every keystroke and on clear - the plain string. */\n onValueChange?: (value: string) => void;\n /** Debounced (and on `Enter` / clear) - run the actual query here. */\n onSearch?: (value: string) => void;\n /** Debounce for `onSearch`, in ms. */\n debounce?: number;\n /** aria-label for the clear button. */\n clearLabel?: string;\n}\n\nexport const SearchInput = React.forwardRef<HTMLInputElement, SearchInputProps>(function SearchInput(\n { value, defaultValue, onValueChange, onSearch, onKeyDown, debounce = 250, clearLabel = 'Clear search', placeholder = 'Search…', disabled, ...rest },\n ref,\n) {\n const [internal, setInternal] = React.useState(defaultValue ?? '');\n const text = value !== undefined ? value : internal;\n\n const timer = React.useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n React.useEffect(() => () => clearTimeout(timer.current), []);\n\n const runSearch = (v: string, immediate: boolean) => {\n clearTimeout(timer.current);\n if (immediate) onSearch?.(v);\n else timer.current = setTimeout(() => onSearch?.(v), debounce);\n };\n\n const update = (v: string, immediate = false) => {\n if (value === undefined) setInternal(v);\n onValueChange?.(v);\n runSearch(v, immediate);\n };\n\n const clear = () => update('', true);\n\n // Composed, not replaced: a plain `{...rest}` spread followed by our own `onKeyDown` used to drop the caller's\n // silently (the same class of bug `Input` guards against for `onChange`).\n // The caller's runs first and can opt out of the built-in keys with `preventDefault()`.\n const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n onKeyDown?.(e);\n if (e.defaultPrevented) return;\n if (e.key === 'Enter') runSearch(e.currentTarget.value, true);\n else if (e.key === 'Escape' && text) {\n e.preventDefault();\n clear();\n }\n };\n\n return (\n <Input\n ref={ref}\n {...rest}\n role=\"searchbox\"\n enterKeyHint=\"search\"\n autoComplete=\"off\"\n spellCheck={false}\n placeholder={placeholder}\n disabled={disabled}\n value={text}\n onChange={(e) => update(e.currentTarget.value)}\n onKeyDown={handleKeyDown}\n iconLeft={<Search size={16} strokeWidth={1.75} />}\n suffix={\n text && !disabled ? (\n <button\n type=\"button\"\n className=\"ds-affix-btn\"\n aria-label={clearLabel}\n onClick={clear}\n style={sx({ display: 'inline-flex', alignItems: 'center', border: 'none', background: 'transparent', color: 'var(--text-muted)', cursor: 'pointer', padding: 0 })}\n >\n <X size={16} strokeWidth={2} />\n </button>\n ) : undefined\n }\n />\n );\n});\n\nSearchInput.displayName = 'SearchInput';\n"],"mappings":";AA+EgB;AA7EhB,YAAY,WAAW;AACvB,SAAS,QAAQ,SAAS;AAC1B,SAAS,UAAU;AACnB,SAAS,aAA8B;AAwBhC,MAAM,cAAc,MAAM,WAA+C,SAASA,aACvF,EAAE,OAAO,cAAc,eAAe,UAAU,WAAW,WAAW,KAAK,aAAa,gBAAgB,cAAc,gBAAW,UAAU,GAA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AO,GAAG,EAAE,SAAS,eAAe,YAAY,UAAU,QAAQ,QAAQ,YAAY,eAAe,OAAO,qBAAqB,QAAQ,WAAW,SAAS,EAAE,CAAC;AAAA,UAEhK,8BAAC,KAAE,MAAM,IAAI,aAAa,GAAG;AAAA;AAAA,MAC/B,IACE;AAAA;AAAA,EAER;AAEJ,CAAC;AAED,YAAY,cAAc;","names":["SearchInput"]}
@@ -13,6 +13,7 @@ import { MenuOption, menuListStyle, menuRowPadY, menuSurfaceStyle } from "../_in
13
13
  import { Field } from "../_internal/Field.js";
14
14
  import { fieldA11y } from "../_internal/fieldA11y.js";
15
15
  import { fieldBoxStyle } from "./_internal/fieldBoxStyle.js";
16
+ import { fieldBoxProps } from "./_internal/fieldFrame.js";
16
17
  function CustomSelect({
17
18
  rid,
18
19
  label,
@@ -185,7 +186,8 @@ function CustomSelect({
185
186
  else openMenu();
186
187
  },
187
188
  onKeyDown,
188
- style: fieldBoxStyle(size, error, open, !!disabled),
189
+ ...fieldBoxProps(open),
190
+ style: fieldBoxStyle(size, error, !!disabled),
189
191
  children: [
190
192
  /* @__PURE__ */ jsx(
191
193
  "span",