@loworbitstudio/visor 1.53.0 → 1.53.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CHANGELOG.json +1 -1
- package/dist/registry.json +3 -3
- package/dist/visor-manifest.json +1 -1
- package/package.json +1 -1
package/dist/CHANGELOG.json
CHANGED
package/dist/registry.json
CHANGED
|
@@ -920,7 +920,7 @@
|
|
|
920
920
|
{
|
|
921
921
|
"path": "components/ui/dialog/dialog.module.css",
|
|
922
922
|
"type": "registry:ui",
|
|
923
|
-
"content": "/* Dialog overlay\n * Default: 4px backdrop blur. Density axis: editorial uses 2px. */\n.overlay {\n position: fixed;\n inset: 0;\n z-index: 50;\n background-color: var(--dialog-overlay-bg, var(--overlay-bg, rgba(0, 0, 0, 0.8)));\n backdrop-filter: blur(var(--dialog-overlay-blur, 4px));\n
|
|
923
|
+
"content": "/* Dialog overlay\n * Default: 4px backdrop blur. Density axis: editorial uses 2px.\n * Prefixed line first: Lightning CSS (in Next) keeps only the last of the pair when\n * the value holds a var(), so unprefixed-first loses backdrop-filter (VI-788). */\n.overlay {\n position: fixed;\n inset: 0;\n z-index: 50;\n background-color: var(--dialog-overlay-bg, var(--overlay-bg, rgba(0, 0, 0, 0.8)));\n -webkit-backdrop-filter: blur(var(--dialog-overlay-blur, 4px));\n backdrop-filter: blur(var(--dialog-overlay-blur, 4px));\n}\n\n:global([data-density=\"editorial\"]) .overlay {\n -webkit-backdrop-filter: blur(var(--dialog-overlay-blur, 2px));\n backdrop-filter: blur(var(--dialog-overlay-blur, 2px));\n}\n\n.overlay[data-state=\"open\"] {\n animation: fadeIn var(--motion-duration-150, 150ms) var(--motion-easing-enter, ease-out);\n}\n\n.overlay[data-state=\"closed\"] {\n animation: fadeOut var(--motion-duration-150, 150ms) var(--motion-easing-exit, ease-in);\n}\n\n/* Dialog content\n * Default: 32rem max-width, radius-lg, surface-page, spacing-6, shadow-xl.\n * Density axis: editorial uses 480px, radius-xl, surface-card, spacing-8, shadow-lg.\n * VI-784: a theme skins it through the --dialog-* hooks; unbound, each falls back to the value above. */\n.content {\n position: fixed;\n top: 50%;\n left: 50%;\n z-index: 50;\n width: 100%;\n max-width: var(--dialog-max-width, 32rem);\n transform: translate(-50%, -50%);\n border-radius: var(--dialog-radius, var(--radius-lg, 0.5rem));\n background-color: var(--dialog-bg, var(--surface-page, #ffffff));\n padding: var(--dialog-padding, var(--spacing-6, 1.5rem));\n box-shadow: var(--dialog-shadow, var(--shadow-xl));\n -webkit-backdrop-filter: var(--dialog-backdrop-filter, none);\n backdrop-filter: var(--dialog-backdrop-filter, none);\n transition: opacity var(--motion-duration-normal, 200ms) var(--motion-easing-default, ease-in-out), transform var(--motion-duration-normal, 200ms) var(--motion-easing-default, ease-in-out);\n}\n\n:global([data-density=\"editorial\"]) .content {\n /* Floating modal — opaque. --surface-card may be translucent glass per theme\n * (blackout: rgba(255,255,255,0.04)); over the backdrop it reads see-through.\n * --surface-popover is the opaque floating token (== --surface-card on solid\n * themes, so no visual change there). VI-623. */\n background-color: var(--dialog-bg, var(--surface-popover, var(--surface-page, #ffffff)));\n max-width: var(--dialog-max-width, 480px);\n border-radius: var(--dialog-radius, var(--radius-xl));\n padding: var(--dialog-padding, var(--spacing-8));\n box-shadow: var(--dialog-shadow, var(--shadow-lg));\n}\n\n.content[data-state=\"open\"] {\n animation: contentShow var(--motion-duration-normal, 200ms) var(--motion-easing-enter, ease-out);\n}\n\n.content[data-state=\"closed\"] {\n animation: contentHide var(--motion-duration-150, 150ms) var(--motion-easing-exit, ease-in);\n}\n\n/* Bottom-sheet presentation (VI-667): same content, anchored to the bottom edge.\n * Sized by dvh and the visual viewport so the on-screen keyboard never covers it;\n * the --dialog-* vars are written by DialogContent from the browser's visual viewport API.\n * No border — the sheet reads against the scrim by surface and shadow alone. */\n.presentationSheet {\n top: auto;\n right: 0;\n bottom: var(--dialog-keyboard-inset, 0px);\n left: 0;\n max-width: none;\n max-height: min(85dvh, calc(var(--dialog-viewport-height, 100dvh) - var(--spacing-4, 1rem)));\n overflow-y: auto;\n overscroll-behavior: contain;\n transform: none;\n border-radius: var(--dialog-radius, var(--radius-lg, 0.5rem)) var(--dialog-radius, var(--radius-lg, 0.5rem)) 0 0;\n padding-bottom: calc(var(--spacing-6, 1.5rem) + env(safe-area-inset-bottom, 0px));\n}\n\n:global([data-density=\"editorial\"]) .presentationSheet {\n max-width: none;\n border-radius: var(--dialog-radius, var(--radius-xl)) var(--dialog-radius, var(--radius-xl)) 0 0;\n padding-bottom: calc(var(--spacing-8) + env(safe-area-inset-bottom, 0px));\n}\n\n.presentationSheet[data-state=\"open\"] {\n animation: sheetShow var(--motion-duration-normal, 200ms) var(--motion-easing-enter, ease-out);\n}\n\n.presentationSheet[data-state=\"closed\"] {\n animation: sheetHide var(--motion-duration-150, 150ms) var(--motion-easing-exit, ease-in);\n}\n\n/* Scoped (container) presentation: covers only the container, not the window. */\n.scrim,\n.scoped {\n position: absolute;\n}\n\n.scoped {\n max-height: calc(100% - var(--spacing-8, 2rem));\n overflow-y: auto;\n}\n\n.scoped.presentationSheet {\n bottom: 0;\n max-height: 85%;\n}\n\n/* Drag handle */\n.handle {\n width: 2.5rem;\n height: var(--spacing-1, 0.25rem);\n margin: calc(var(--spacing-3, 0.75rem) * -1) auto var(--spacing-4, 1rem);\n border-radius: var(--radius-full, 9999px);\n background-color: var(--text-tertiary, #9ca3af);\n opacity: var(--opacity-40, 0.4);\n cursor: grab;\n touch-action: none;\n}\n\n/* Close button */\n.closeButton {\n position: absolute;\n top: 1rem;\n right: 1rem;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n border-radius: var(--radius-sm, 0.25rem);\n border: none;\n background: transparent;\n cursor: pointer;\n opacity: 0.7;\n transition: opacity var(--motion-duration-150, 150ms) var(--motion-easing-default, ease-in-out);\n padding: var(--spacing-1, 0.25rem);\n color: var(--text-primary, #111827);\n}\n\n.closeButton:hover {\n opacity: 1;\n}\n\n.closeButton:focus-visible {\n outline: var(--focus-ring-width, 2px) solid var(--border-focus, currentColor);\n outline-offset: var(--focus-ring-offset, 2px);\n}\n\n.closeIcon {\n width: 1rem;\n height: 1rem;\n}\n\n/* Back action: leading counterpart of the close button */\n.backButton {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n border-radius: var(--radius-sm, 0.25rem);\n border: none;\n background: transparent;\n cursor: pointer;\n opacity: 0.7;\n transition: opacity var(--motion-duration-150, 150ms) var(--motion-easing-default, ease-in-out);\n padding: var(--spacing-1, 0.25rem);\n color: var(--text-primary, #111827);\n}\n\n.backButton:hover {\n opacity: 1;\n}\n\n.backButton:focus-visible {\n outline: var(--focus-ring-width, 2px) solid var(--border-focus, currentColor);\n outline-offset: var(--focus-ring-offset, 2px);\n}\n\n/* Header */\n.header {\n display: flex;\n flex-direction: column;\n gap: calc(var(--spacing-1, 0.25rem) * 1.5);\n margin-bottom: var(--spacing-4, 1rem);\n}\n\n.headerWithBack {\n flex-direction: row;\n align-items: flex-start;\n gap: var(--spacing-2, 0.5rem);\n}\n\n.backSlot {\n flex: none;\n /* Align the 24px control with the first title line (line-height lg ~1.75rem). */\n margin-block: calc(var(--spacing-1, 0.25rem) * 0.5);\n}\n\n.headerBody {\n display: flex;\n flex-direction: column;\n gap: calc(var(--spacing-1, 0.25rem) * 1.5);\n min-width: 0;\n}\n\n/* Title\n * Default: font-size-lg / semibold. Density axis: editorial uses font-size-2xl / 700. */\n.title {\n font-size: var(--font-size-lg, 1.125rem);\n font-weight: var(--font-weight-semibold, 600);\n color: var(--text-primary, #111827);\n margin: 0;\n}\n\n:global([data-density=\"editorial\"]) .title {\n font-size: var(--font-size-2xl);\n font-weight: var(--font-weight-bold, 700);\n}\n\n/* Description\n * Default: text-secondary. Density axis: editorial uses text-tertiary. */\n.description {\n font-size: var(--font-size-sm, 0.875rem);\n color: var(--text-secondary, #6b7280);\n margin: 0;\n}\n\n:global([data-density=\"editorial\"]) .description {\n color: var(--text-tertiary);\n}\n\n/* Footer */\n.footer {\n display: flex;\n justify-content: flex-end;\n align-items: center;\n gap: var(--spacing-3, 0.75rem);\n padding-top: var(--spacing-3, 0.75rem);\n margin-top: var(--spacing-2, 0.5rem);\n border-top: 1px solid transparent;\n border-image: linear-gradient(var(--hairline, var(--border-subtle, rgba(0, 0, 0, 0.06))), var(--hairline, var(--border-subtle, rgba(0, 0, 0, 0.06)))) 1 / var(--hairline-width, 1px) 0 0 0;\n}\n\n/* Screen reader only */\n.srOnly {\n position: absolute;\n width: 1px;\n height: 1px;\n padding: 0;\n margin: -1px;\n overflow: hidden;\n clip: rect(0, 0, 0, 0);\n white-space: nowrap;\n border-width: 0;\n}\n\n@keyframes fadeIn {\n from { opacity: 0; }\n to { opacity: 1; }\n}\n\n@keyframes fadeOut {\n from { opacity: 1; }\n to { opacity: 0; }\n}\n\n@keyframes contentShow {\n from {\n opacity: 0;\n transform: translate(-50%, calc(-50% + 8px));\n }\n to {\n opacity: 1;\n transform: translate(-50%, -50%);\n }\n}\n\n@keyframes contentHide {\n from {\n opacity: 1;\n transform: translate(-50%, -50%);\n }\n to {\n opacity: 0;\n transform: translate(-50%, calc(-50% + 8px));\n }\n}\n\n@keyframes sheetShow {\n from { transform: translateY(100%); }\n to { transform: translateY(0); }\n}\n\n@keyframes sheetHide {\n from { transform: translateY(0); }\n to { transform: translateY(100%); }\n}\n\n/* Reduced motion: the dialog and the sheet appear without moving. */\n@media (prefers-reduced-motion: reduce) {\n .content,\n .presentationSheet,\n .backButton,\n .closeButton {\n transition: none;\n }\n\n .content[data-state=\"open\"],\n .presentationSheet[data-state=\"open\"] {\n animation: fadeIn var(--motion-duration-150, 150ms) var(--motion-easing-default, ease-in-out);\n }\n\n .content[data-state=\"closed\"],\n .presentationSheet[data-state=\"closed\"] {\n animation: fadeOut var(--motion-duration-150, 150ms) var(--motion-easing-default, ease-in-out);\n }\n}\n"
|
|
924
924
|
}
|
|
925
925
|
]
|
|
926
926
|
},
|
|
@@ -1930,7 +1930,7 @@
|
|
|
1930
1930
|
{
|
|
1931
1931
|
"path": "components/ui/lightbox/lightbox.tsx",
|
|
1932
1932
|
"type": "registry:ui",
|
|
1933
|
-
"content": "\"use client\"\n\nimport * as React from \"react\"\nimport * as DialogPrimitive from \"@radix-ui/react-dialog\"\nimport { CaretLeft, CaretRight, X } from \"@phosphor-icons/react\"\nimport { cn } from \"../../../lib/utils\"\nimport styles from \"./lightbox.module.css\"\n\nexport interface LightboxImage {\n src: string\n alt: string\n}\n\nexport interface LightboxProps {\n /** Array of images to display */\n images: LightboxImage[]\n /** Initially selected image index */\n initialIndex?: number\n /** Controlled open state */\n open?: boolean\n /** Called when open state changes */\n onOpenChange?: (open: boolean) => void\n children?: React.ReactNode\n}\n\ninterface LightboxContextValue {\n images: LightboxImage[]\n currentIndex: number\n setCurrentIndex: React.Dispatch<React.SetStateAction<number>>\n goToPrevious: () => void\n goToNext: () => void\n /** Side the current photo came from; unset for the photo shown on open */\n direction?: \"previous\" | \"next\"\n}\n\nconst LightboxContext = React.createContext<LightboxContextValue | null>(null)\n\nfunction useLightbox() {\n const ctx = React.useContext(LightboxContext)\n if (!ctx) throw new Error(\"useLightbox must be used within <Lightbox />\")\n return ctx\n}\n\nfunction Lightbox({\n images,\n initialIndex = 0,\n open,\n onOpenChange,\n children,\n}: LightboxProps) {\n const [currentIndex, setCurrentIndex] = React.useState(initialIndex)\n const [direction, setDirection] =\n React.useState<LightboxContextValue[\"direction\"]>()\n\n // Reset currentIndex when opened\n React.useEffect(() => {\n if (open) {\n setCurrentIndex(initialIndex)\n setDirection(undefined)\n }\n }, [open, initialIndex])\n\n const handleOpenChange = React.useCallback(\n (next: boolean) => {\n if (next) setDirection(undefined)\n onOpenChange?.(next)\n },\n [onOpenChange]\n )\n\n const goToPrevious = React.useCallback(() => {\n setDirection(\"previous\")\n setCurrentIndex((prev) =>\n prev <= 0 ? images.length - 1 : prev - 1\n )\n }, [images.length])\n\n const goToNext = React.useCallback(() => {\n setDirection(\"next\")\n setCurrentIndex((prev) =>\n prev >= images.length - 1 ? 0 : prev + 1\n )\n }, [images.length])\n\n return (\n <LightboxContext.Provider\n value={{\n images,\n currentIndex,\n setCurrentIndex,\n goToPrevious,\n goToNext,\n direction,\n }}\n >\n <DialogPrimitive.Root\n data-slot=\"lightbox-root\"\n open={open}\n onOpenChange={handleOpenChange}\n >\n {children}\n </DialogPrimitive.Root>\n </LightboxContext.Provider>\n )\n}\nLightbox.displayName = \"Lightbox\"\n\nfunction LightboxTrigger({\n ...props\n}: React.ComponentProps<typeof DialogPrimitive.Trigger>) {\n return <DialogPrimitive.Trigger data-slot=\"lightbox-trigger\" {...props} />\n}\nLightboxTrigger.displayName = \"LightboxTrigger\"\n\nfunction markLoaded(event: React.SyntheticEvent<HTMLImageElement>) {\n event.currentTarget.dataset.loaded = \"\"\n}\n\nconst LightboxContent = React.forwardRef<\n React.ComponentRef<typeof DialogPrimitive.Content>,\n Omit<React.ComponentProps<typeof DialogPrimitive.Content>, \"children\"> & {\n className?: string\n }\n>(({ className, ...props }, ref) => {\n const { images, currentIndex, goToPrevious, goToNext, direction } =\n useLightbox()\n\n const touchStartX = React.useRef<number>(0)\n const touchEndX = React.useRef<number>(0)\n\n const handleKeyDown = React.useCallback(\n (event: React.KeyboardEvent) => {\n if (event.key === \"ArrowLeft\") {\n event.preventDefault()\n goToPrevious()\n } else if (event.key === \"ArrowRight\") {\n event.preventDefault()\n goToNext()\n }\n },\n [goToPrevious, goToNext]\n )\n\n const handleTouchStart = React.useCallback(\n (event: React.TouchEvent) => {\n
|
|
1933
|
+
"content": "\"use client\"\n\nimport * as React from \"react\"\nimport * as DialogPrimitive from \"@radix-ui/react-dialog\"\nimport { CaretLeft, CaretRight, X } from \"@phosphor-icons/react\"\nimport { cn } from \"../../../lib/utils\"\nimport styles from \"./lightbox.module.css\"\n\nexport interface LightboxImage {\n src: string\n alt: string\n}\n\nexport interface LightboxProps {\n /** Array of images to display */\n images: LightboxImage[]\n /** Initially selected image index */\n initialIndex?: number\n /** Controlled open state */\n open?: boolean\n /** Called when open state changes */\n onOpenChange?: (open: boolean) => void\n children?: React.ReactNode\n}\n\ninterface LightboxContextValue {\n images: LightboxImage[]\n currentIndex: number\n setCurrentIndex: React.Dispatch<React.SetStateAction<number>>\n goToPrevious: () => void\n goToNext: () => void\n /** Side the current photo came from; unset for the photo shown on open */\n direction?: \"previous\" | \"next\"\n}\n\nconst LightboxContext = React.createContext<LightboxContextValue | null>(null)\n\nfunction useLightbox() {\n const ctx = React.useContext(LightboxContext)\n if (!ctx) throw new Error(\"useLightbox must be used within <Lightbox />\")\n return ctx\n}\n\nfunction Lightbox({\n images,\n initialIndex = 0,\n open,\n onOpenChange,\n children,\n}: LightboxProps) {\n const [currentIndex, setCurrentIndex] = React.useState(initialIndex)\n const [direction, setDirection] =\n React.useState<LightboxContextValue[\"direction\"]>()\n\n // Reset currentIndex when opened\n React.useEffect(() => {\n if (open) {\n setCurrentIndex(initialIndex)\n setDirection(undefined)\n }\n }, [open, initialIndex])\n\n const handleOpenChange = React.useCallback(\n (next: boolean) => {\n if (next) setDirection(undefined)\n onOpenChange?.(next)\n },\n [onOpenChange]\n )\n\n const goToPrevious = React.useCallback(() => {\n setDirection(\"previous\")\n setCurrentIndex((prev) =>\n prev <= 0 ? images.length - 1 : prev - 1\n )\n }, [images.length])\n\n const goToNext = React.useCallback(() => {\n setDirection(\"next\")\n setCurrentIndex((prev) =>\n prev >= images.length - 1 ? 0 : prev + 1\n )\n }, [images.length])\n\n return (\n <LightboxContext.Provider\n value={{\n images,\n currentIndex,\n setCurrentIndex,\n goToPrevious,\n goToNext,\n direction,\n }}\n >\n <DialogPrimitive.Root\n data-slot=\"lightbox-root\"\n open={open}\n onOpenChange={handleOpenChange}\n >\n {children}\n </DialogPrimitive.Root>\n </LightboxContext.Provider>\n )\n}\nLightbox.displayName = \"Lightbox\"\n\nfunction LightboxTrigger({\n ...props\n}: React.ComponentProps<typeof DialogPrimitive.Trigger>) {\n return <DialogPrimitive.Trigger data-slot=\"lightbox-trigger\" {...props} />\n}\nLightboxTrigger.displayName = \"LightboxTrigger\"\n\nfunction markLoaded(event: React.SyntheticEvent<HTMLImageElement>) {\n event.currentTarget.dataset.loaded = \"\"\n}\n\nconst LightboxContent = React.forwardRef<\n React.ComponentRef<typeof DialogPrimitive.Content>,\n Omit<React.ComponentProps<typeof DialogPrimitive.Content>, \"children\"> & {\n className?: string\n }\n>(({ className, ...props }, ref) => {\n const { images, currentIndex, goToPrevious, goToNext, direction } =\n useLightbox()\n\n const touchStartX = React.useRef<number>(0)\n const touchEndX = React.useRef<number>(0)\n\n const handleKeyDown = React.useCallback(\n (event: React.KeyboardEvent) => {\n if (event.key === \"ArrowLeft\") {\n event.preventDefault()\n goToPrevious()\n } else if (event.key === \"ArrowRight\") {\n event.preventDefault()\n goToNext()\n }\n },\n [goToPrevious, goToNext]\n )\n\n const handleTouchStart = React.useCallback(\n (event: React.TouchEvent) => {\n const touch = event.touches[0]\n if (!touch) return\n touchStartX.current = touch.clientX\n touchEndX.current = touch.clientX\n },\n []\n )\n\n const handleTouchMove = React.useCallback(\n (event: React.TouchEvent) => {\n const touch = event.touches[0]\n if (touch) touchEndX.current = touch.clientX\n },\n []\n )\n\n const handleTouchEnd = React.useCallback(() => {\n const diff = touchStartX.current - touchEndX.current\n const threshold = 50\n\n if (Math.abs(diff) >= threshold) {\n if (diff > 0) {\n goToNext()\n } else {\n goToPrevious()\n }\n }\n }, [goToNext, goToPrevious])\n\n // Preload adjacent images\n React.useEffect(() => {\n if (images.length <= 1) return\n\n const preloadIndexes = [\n (currentIndex - 1 + images.length) % images.length,\n (currentIndex + 1) % images.length,\n ]\n\n preloadIndexes.forEach((idx) => {\n const image = images[idx]\n if (!image) return\n const img = new Image()\n img.src = image.src\n })\n }, [currentIndex, images])\n\n const currentImage = images[currentIndex]\n\n return (\n <DialogPrimitive.Portal>\n <DialogPrimitive.Overlay className={styles.overlay} />\n <DialogPrimitive.Content\n ref={ref}\n data-slot=\"lightbox\"\n className={cn(styles.content, className)}\n onKeyDown={handleKeyDown}\n onTouchStart={handleTouchStart}\n onTouchMove={handleTouchMove}\n onTouchEnd={handleTouchEnd}\n aria-label={`Image viewer: ${currentImage?.alt ?? \"\"}`}\n {...props}\n >\n {/* Visually hidden title for accessibility */}\n <DialogPrimitive.Title className={styles.srOnly}>\n Image viewer\n </DialogPrimitive.Title>\n <DialogPrimitive.Description className={styles.srOnly}>\n Viewing image {currentIndex + 1} of {images.length}\n </DialogPrimitive.Description>\n\n {/* Counter */}\n {images.length > 1 && (\n <span data-slot=\"lightbox-counter\" className={styles.counter}>\n {currentIndex + 1} / {images.length}\n </span>\n )}\n\n {/* Close button */}\n <DialogPrimitive.Close\n data-slot=\"lightbox-close\"\n className={styles.close}\n >\n <X weight=\"bold\" />\n <span className={styles.srOnly}>Close</span>\n </DialogPrimitive.Close>\n\n {/* Navigation buttons */}\n {images.length > 1 && (\n <>\n <button\n data-slot=\"lightbox-previous\"\n className={cn(styles.navButton, styles.navPrevious)}\n onClick={goToPrevious}\n type=\"button\"\n >\n <CaretLeft weight=\"bold\" />\n <span className={styles.srOnly}>Previous image</span>\n </button>\n <button\n data-slot=\"lightbox-next\"\n className={cn(styles.navButton, styles.navNext)}\n onClick={goToNext}\n type=\"button\"\n >\n <CaretRight weight=\"bold\" />\n <span className={styles.srOnly}>Next image</span>\n </button>\n </>\n )}\n\n {/* Main image */}\n {currentImage && (\n <div className={styles.imageContainer}>\n <img\n key={currentIndex}\n src={currentImage.src}\n alt={currentImage.alt}\n className={styles.image}\n draggable={false}\n data-direction={direction}\n // The photo eases in once it has loaded (see lightbox.module.css)\n onLoad={markLoaded}\n onError={markLoaded}\n />\n </div>\n )}\n </DialogPrimitive.Content>\n </DialogPrimitive.Portal>\n )\n})\nLightboxContent.displayName = \"LightboxContent\"\n\nexport {\n Lightbox,\n LightboxTrigger,\n LightboxContent,\n}\n"
|
|
1934
1934
|
},
|
|
1935
1935
|
{
|
|
1936
1936
|
"path": "components/ui/lightbox/lightbox.module.css",
|
|
@@ -2214,7 +2214,7 @@
|
|
|
2214
2214
|
{
|
|
2215
2215
|
"path": "components/ui/phone-input/phone-input.tsx",
|
|
2216
2216
|
"type": "registry:ui",
|
|
2217
|
-
"content": "\"use client\"\n\nimport * as React from \"react\"\nimport IntlTelInput from \"@intl-tel-input/react\"\nimport type { IntlTelInputRef } from \"@intl-tel-input/react\"\nimport type { CountrySelectorMode, Iso2, ValidationError } from \"intl-tel-input\"\nimport \"intl-tel-input/styles\"\nimport { cn } from \"../../../lib/utils\"\n\n// Password managers mangle tel fields. Typed through `input` props because the\n// library's `inputProps` surface does not model arbitrary data attributes.\nconst PASSWORD_MANAGER_OPT_OUT = {\n \"data-1p-ignore\": true,\n \"data-lpignore\": \"true\",\n \"data-bwignore\": true,\n \"data-form-type\": \"other\",\n} as React.ComponentPropsWithoutRef<\"input\">\n\nexport interface PhoneInputPortal {\n /** Element the country selector is portaled into. */\n container: HTMLElement\n /**\n * Theme-scoping class applied to the portaled country selector. Required —\n * a selector portaled out of the tree escapes the consumer's theme class,\n * so the scope has to travel with it.\n */\n scopeClassName: string\n}\n\nexport interface PhoneInputProps {\n /** HTML id attribute */\n id?: string\n /** HTML name attribute */\n name?: string\n /** Phone number in E.164 (e.g. \"+14155551234\"). Displayed formatted for the detected country. */\n value?: string | null\n /** Placeholder text */\n placeholder?: string\n /** Whether the field is required */\n required?: boolean\n /** Whether the field is disabled */\n disabled?: boolean\n /** Whether the field is read-only. Pair with `countrySelectorMode=\"OFF\"` to also close off the country dropdown. */\n readOnly?: boolean\n /** Country selector behaviour. `\"OFF\"` renders the selected country as a non-interactive element. */\n countrySelectorMode?: CountrySelectorMode\n /** ISO 3166-1 alpha-2 country selected on mount. */\n initialCountry?: Iso2\n /** Size variant — matches Input component sizes */\n size?: \"sm\" | \"md\" | \"lg\"\n /** Additional CSS classes applied to the wrapper */\n className?: string\n /**\n * Portal the country selector out of the input's DOM position. All-or-nothing:\n * the scoping class is not separable from the container, so the selector can\n * never escape its theme. Omit for the default inline selector.\n */\n portal?: PhoneInputPortal\n /**\n * Called with the E.164 number and its validity. `e164` is `null` for anything\n * that is not a complete, valid number — a partial is never emitted.\n */\n onChange?: (e164: string | null, isValid: boolean) => void\n /** Called on blur with the validation error for a non-empty, invalid number (otherwise `null`). */\n onBlur?: (error: ValidationError | null) => void\n}\n\nconst PhoneInput = React.forwardRef<IntlTelInputRef, PhoneInputProps>(\n (\n {\n id,\n name,\n value,\n placeholder,\n required = false,\n disabled = false,\n readOnly = false,\n countrySelectorMode,\n initialCountry = \"us\",\n size = \"md\",\n className,\n portal,\n onChange,\n onBlur,\n },\n ref\n ) => {\n const itiRef = React.useRef<IntlTelInputRef>(null)\n // `undefined` until the first emission — an initial `{ null, false }` would be\n // indistinguishable from the first partial the user types and would swallow it.\n const lastEmitted = React.useRef<\n { e164: string | null; isValid: boolean } | undefined\n >(undefined)\n\n React.useImperativeHandle(ref, () => ({\n getInstance: () => itiRef.current?.getInstance() ?? null,\n getInput: () => itiRef.current?.getInput() ?? null,\n }))\n\n // `emit` must be identity-stable. The wrapper derives its internal `update`\n // from the onChange* props and keys its value-writeback effect on\n // `[value, update]`; a new `emit` each render re-runs that effect, and while\n // the field is unfocused and holding a partial (so the controlled value is\n // null) it calls setNumber(\"\") and erases what the user typed. Reading the\n // consumer's callback from a ref keeps the effect keyed on `value` alone.\n const onChangeRef = React.useRef(onChange)\n onChangeRef.current = onChange\n\n // The library's own `onChangeNumber` emits `getNumber()` verbatim, which for a\n // partial is a `+<dial code>` prefix glued to the formatted national string\n // (typing \"21337\" yields \"+1213-37\"). Derive the value at emit time instead so\n // a malformed number can never reach the consumer.\n const emit = React.useCallback(() => {\n const iti = itiRef.current?.getInstance()\n const isValid = iti?.isValidNumber() ?? false\n const e164 = isValid ? iti!.getNumber() : null\n const last = lastEmitted.current\n if (last && last.e164 === e164 && last.isValid === isValid) return\n lastEmitted.current = { e164, isValid }\n onChangeRef.current?.(e164, isValid)\n }, [])\n\n const handleBlur = React.useCallback(() => {\n const iti = itiRef.current?.getInstance()\n const input = itiRef.current?.getInput()\n // The error callback never fires while a number is still partial, so read the\n // error directly — a visibly-present partial that saves as nothing is silent\n // data loss. Gate on validity: getValidationError() reports \"IS_POSSIBLE\" for\n // a number that is fine, which is not an error.\n const error =\n iti && input?.value && !iti.isValidNumber()\n ? (iti.getValidationError() ?? null)\n : null\n onBlur?.(error)\n }, [onBlur])\n\n // The library validates every option key it is handed, and a key explicitly\n // set to `undefined` is still an own key — so spreading an unset optional\n // prop makes it warn (\"must be ...; got undefined. Ignoring.\") on every\n // mount. Carry each key only when the consumer actually set one; there is no\n // correct default to invent for either.\n const optional = {\n ...(countrySelectorMode !== undefined && { countrySelectorMode }),\n ...(portal && {\n classNames: { countrySelectorContainer: portal.scopeClassName },\n }),\n }\n\n return (\n <div data-slot=\"phone-input\" data-size={size} className={cn(className)}>\n <IntlTelInput\n ref={itiRef}\n {...optional}\n value={value}\n disabled={disabled}\n readOnly={readOnly}\n onChangeNumber={emit}\n onChangeCountry={emit}\n onChangeValidity={emit}\n initialCountry={initialCountry}\n initialCountryLookup={null}\n separateDialCode\n formatAsYouType\n strictMode\n countrySearch\n loadUtils={() => import(\"intl-tel-input/utils\")}\n dropdownParent={portal?.container ?? null}\n inputProps={{\n id,\n name,\n placeholder,\n required,\n autoComplete: \"tel\",\n onBlur: handleBlur,\n ...PASSWORD_MANAGER_OPT_OUT,\n }}\n />\n </div>\n )\n }\n)\nPhoneInput.displayName = \"PhoneInput\"\n\nexport { PhoneInput }\n"
|
|
2217
|
+
"content": "\"use client\"\n\nimport * as React from \"react\"\nimport IntlTelInput from \"@intl-tel-input/react\"\nimport type { IntlTelInputRef } from \"@intl-tel-input/react\"\nimport type { CountrySelectorMode, Iso2, ValidationError } from \"intl-tel-input\"\nimport \"intl-tel-input/styles\"\nimport { cn } from \"../../../lib/utils\"\n\n// Password managers mangle tel fields. Typed through `input` props because the\n// library's `inputProps` surface does not model arbitrary data attributes.\nconst PASSWORD_MANAGER_OPT_OUT = {\n \"data-1p-ignore\": true,\n \"data-lpignore\": \"true\",\n \"data-bwignore\": true,\n \"data-form-type\": \"other\",\n} as React.ComponentPropsWithoutRef<\"input\">\n\nexport interface PhoneInputPortal {\n /** Element the country selector is portaled into. */\n container: HTMLElement\n /**\n * Theme-scoping class applied to the portaled country selector. Required —\n * a selector portaled out of the tree escapes the consumer's theme class,\n * so the scope has to travel with it.\n */\n scopeClassName: string\n}\n\nexport interface PhoneInputProps {\n /** HTML id attribute */\n id?: string\n /** HTML name attribute */\n name?: string\n /** Phone number in E.164 (e.g. \"+14155551234\"). Displayed formatted for the detected country. */\n value?: string | null\n /** Placeholder text */\n placeholder?: string\n /** Whether the field is required */\n required?: boolean\n /** Whether the field is disabled */\n disabled?: boolean\n /** Whether the field is read-only. Pair with `countrySelectorMode=\"OFF\"` to also close off the country dropdown. */\n readOnly?: boolean\n /** Country selector behaviour. `\"OFF\"` renders the selected country as a non-interactive element. */\n countrySelectorMode?: CountrySelectorMode\n /** ISO 3166-1 alpha-2 country selected on mount. */\n initialCountry?: Iso2\n /** Size variant — matches Input component sizes */\n size?: \"sm\" | \"md\" | \"lg\"\n /** Additional CSS classes applied to the wrapper */\n className?: string\n /**\n * Portal the country selector out of the input's DOM position. All-or-nothing:\n * the scoping class is not separable from the container, so the selector can\n * never escape its theme. Omit for the default inline selector.\n */\n portal?: PhoneInputPortal\n /**\n * Called with the E.164 number and its validity. `e164` is `null` for anything\n * that is not a complete, valid number — a partial is never emitted.\n */\n onChange?: (e164: string | null, isValid: boolean) => void\n /** Called on blur with the validation error for a non-empty, invalid number (otherwise `null`). */\n onBlur?: (error: ValidationError | null) => void\n}\n\nconst PhoneInput = React.forwardRef<IntlTelInputRef, PhoneInputProps>(\n (\n {\n id,\n name,\n value,\n placeholder,\n required = false,\n disabled = false,\n readOnly = false,\n countrySelectorMode,\n initialCountry = \"us\",\n size = \"md\",\n className,\n portal,\n onChange,\n onBlur,\n },\n ref\n ) => {\n const itiRef = React.useRef<IntlTelInputRef>(null)\n // `undefined` until the first emission — an initial `{ null, false }` would be\n // indistinguishable from the first partial the user types and would swallow it.\n const lastEmitted = React.useRef<\n { e164: string | null; isValid: boolean } | undefined\n >(undefined)\n\n React.useImperativeHandle(ref, () => ({\n getInstance: () => itiRef.current?.getInstance() ?? null,\n getInput: () => itiRef.current?.getInput() ?? null,\n }))\n\n // `emit` must be identity-stable. The wrapper derives its internal `update`\n // from the onChange* props and keys its value-writeback effect on\n // `[value, update]`; a new `emit` each render re-runs that effect, and while\n // the field is unfocused and holding a partial (so the controlled value is\n // null) it calls setNumber(\"\") and erases what the user typed. Reading the\n // consumer's callback from a ref keeps the effect keyed on `value` alone.\n const onChangeRef = React.useRef(onChange)\n onChangeRef.current = onChange\n\n // The library's own `onChangeNumber` emits `getNumber()` verbatim, which for a\n // partial is a `+<dial code>` prefix glued to the formatted national string\n // (typing \"21337\" yields \"+1213-37\"). Derive the value at emit time instead so\n // a malformed number can never reach the consumer.\n const emit = React.useCallback(() => {\n const iti = itiRef.current?.getInstance()\n const isValid = iti?.isValidNumber() ?? false\n const e164 = isValid ? iti!.getNumber() : null\n const last = lastEmitted.current\n if (last && last.e164 === e164 && last.isValid === isValid) return\n lastEmitted.current = { e164, isValid }\n onChangeRef.current?.(e164, isValid)\n }, [])\n\n const handleBlur = React.useCallback(() => {\n const iti = itiRef.current?.getInstance()\n const input = itiRef.current?.getInput()\n // The error callback never fires while a number is still partial, so read the\n // error directly — a visibly-present partial that saves as nothing is silent\n // data loss. Gate on validity: getValidationError() reports \"IS_POSSIBLE\" for\n // a number that is fine, which is not an error.\n const error =\n iti && input?.value && !iti.isValidNumber()\n ? (iti.getValidationError() ?? null)\n : null\n onBlur?.(error)\n }, [onBlur])\n\n // The library validates every option key it is handed, and a key explicitly\n // set to `undefined` is still an own key — so spreading an unset optional\n // prop makes it warn (\"must be ...; got undefined. Ignoring.\") on every\n // mount. Carry each key only when the consumer actually set one; there is no\n // correct default to invent for either.\n const optional = {\n ...(countrySelectorMode !== undefined && { countrySelectorMode }),\n ...(portal && {\n classNames: { countrySelectorContainer: portal.scopeClassName },\n // Below 500px the library swaps to its full-screen picker, which ignores\n // dropdownParent and would otherwise land on document.body.\n fullscreenParent: portal.container,\n }),\n }\n\n return (\n <div data-slot=\"phone-input\" data-size={size} className={cn(className)}>\n <IntlTelInput\n ref={itiRef}\n {...optional}\n value={value}\n disabled={disabled}\n readOnly={readOnly}\n onChangeNumber={emit}\n onChangeCountry={emit}\n onChangeValidity={emit}\n initialCountry={initialCountry}\n initialCountryLookup={null}\n separateDialCode\n formatAsYouType\n strictMode\n countrySearch\n loadUtils={() => import(\"intl-tel-input/utils\")}\n dropdownParent={portal?.container ?? null}\n inputProps={{\n id,\n name,\n placeholder,\n required,\n autoComplete: \"tel\",\n onBlur: handleBlur,\n ...PASSWORD_MANAGER_OPT_OUT,\n }}\n />\n </div>\n )\n }\n)\nPhoneInput.displayName = \"PhoneInput\"\n\nexport { PhoneInput }\n"
|
|
2218
2218
|
},
|
|
2219
2219
|
{
|
|
2220
2220
|
"path": "components/ui/phone-input/phone-input.css",
|
package/dist/visor-manifest.json
CHANGED