@aster-ui/prefixed 0.12.54 → 0.12.56
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/components/Button.js +22 -22
- package/dist/components/Button.js.map +1 -1
- package/dist/components/Card.d.ts +1 -3
- package/dist/components/Card.js +74 -75
- package/dist/components/Card.js.map +1 -1
- package/dist/components/Chart.js +57 -88
- package/dist/components/Chart.js.map +1 -1
- package/dist/components/CopyButton.js +76 -77
- package/dist/components/CopyButton.js.map +1 -1
- package/dist/components/Drawer.js +9 -9
- package/dist/components/Drawer.js.map +1 -1
- package/dist/components/ThemeController.js +102 -88
- package/dist/components/ThemeController.js.map +1 -1
- package/dist/components/ThemeProvider.d.ts +50 -0
- package/dist/components/ThemeProvider.js +130 -0
- package/dist/components/ThemeProvider.js.map +1 -0
- package/dist/components/Watermark.js +86 -94
- package/dist/components/Watermark.js.map +1 -1
- package/dist/contexts/SizeContext.d.ts +22 -0
- package/dist/contexts/SizeContext.js +15 -0
- package/dist/contexts/SizeContext.js.map +1 -0
- package/dist/hooks/useTheme.d.ts +26 -16
- package/dist/hooks/useTheme.js +103 -40
- package/dist/hooks/useTheme.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +235 -229
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/contexts/IconSizeContext.d.ts +0 -2
- package/dist/contexts/IconSizeContext.js +0 -6
- package/dist/contexts/IconSizeContext.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Drawer.js","sources":["../../src/components/Drawer.tsx"],"sourcesContent":["import React, {\n useEffect,\n useRef,\n useId,\n useCallback,\n useState,\n forwardRef,\n useImperativeHandle,\n createContext,\n useContext,\n} from 'react'\nimport { createPortal } from 'react-dom'\nimport { Skeleton } from './Skeleton'\n\n// DaisyUI classes\nconst dBtn = 'd-btn'\nconst dBtnGhost = 'd-btn-ghost'\nconst dBtnSm = 'd-btn-sm'\nconst dBtnSquare = 'd-btn-square'\n\nexport type DrawerPlacement = 'top' | 'right' | 'bottom' | 'left'\nexport type DrawerSize = 'default' | 'large' | number\n\nexport interface DrawerPushConfig {\n /** Distance to push parent drawer (default: 180) */\n distance?: number\n}\n\nexport interface DrawerProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'title'> {\n /** Drawer content */\n children: React.ReactNode\n /** Whether the drawer is visible */\n open?: boolean\n /** Callback when drawer is closed */\n onClose?: (e?: React.MouseEvent | React.KeyboardEvent) => void\n /** Callback after open/close animation completes */\n afterOpenChange?: (open: boolean) => void\n /** Drawer title */\n title?: React.ReactNode\n /** Direction drawer slides from */\n placement?: DrawerPlacement\n /** Preset size or custom width/height in pixels */\n size?: DrawerSize\n /** Custom width (overrides size for left/right placement) */\n width?: number | string\n /** Custom height (overrides size for top/bottom placement) */\n height?: number | string\n /** Whether to show close button */\n closable?: boolean\n /** Whether to show mask/backdrop */\n mask?: boolean\n /** Whether clicking mask closes drawer */\n maskClosable?: boolean\n /** Whether ESC closes drawer */\n keyboard?: boolean\n /** Footer content */\n footer?: React.ReactNode\n /** Extra content in header (right side) */\n extra?: React.ReactNode\n /** CSS class for drawer panel */\n className?: string\n /** CSS class for drawer wrapper */\n rootClassName?: string\n /** Style for drawer panel */\n style?: React.CSSProperties\n /** Style for drawer header */\n headerStyle?: React.CSSProperties\n /** Style for drawer body/content area */\n bodyStyle?: React.CSSProperties\n /** Style for drawer footer */\n footerStyle?: React.CSSProperties\n /** Style for drawer wrapper (includes mask) */\n rootStyle?: React.CSSProperties\n /** Style for mask/backdrop */\n maskStyle?: React.CSSProperties\n /** z-index of drawer */\n zIndex?: number\n /** Destroy content when closed */\n destroyOnClose?: boolean\n /** Pre-render drawer content (keep in DOM even when closed) */\n forceRender?: boolean\n /** Where to place initial focus */\n initialFocus?: 'close' | 'content'\n /** Show loading skeleton */\n loading?: boolean\n /** Custom container for portal (false to disable portal) */\n getContainer?: HTMLElement | (() => HTMLElement) | false\n /** Nested drawer push behavior */\n push?: boolean | DrawerPushConfig\n /** Test ID for testing */\n 'data-testid'?: string\n}\n\nexport interface DrawerRef {\n /** The drawer panel element */\n nativeElement: HTMLDivElement | null\n}\n\n// Context for nested drawer push behavior\ninterface DrawerContextValue {\n push: boolean | DrawerPushConfig\n pushDistance: number\n}\n\nconst DrawerContext = createContext<DrawerContextValue | null>(null)\n\nfunction useDrawerContext() {\n return useContext(DrawerContext)\n}\n\n/**\n * Drawer - A panel that slides in from the edge of the screen.\n * Use for forms, details, or task panels.\n * For responsive sidebar navigation, use ResponsiveDrawer instead.\n */\nexport const Drawer = forwardRef<DrawerRef, DrawerProps>(\n (\n {\n children,\n open = false,\n onClose,\n afterOpenChange,\n title,\n placement = 'right',\n size = 'default',\n width,\n height,\n closable = true,\n mask = true,\n maskClosable = true,\n keyboard = true,\n footer,\n extra,\n className = '',\n rootClassName = '',\n style,\n headerStyle,\n bodyStyle,\n footerStyle,\n rootStyle,\n maskStyle,\n zIndex = 1000,\n destroyOnClose = false,\n forceRender = false,\n initialFocus = 'close',\n loading = false,\n getContainer,\n push = { distance: 180 },\n 'data-testid': testId,\n ...rest\n },\n ref\n ) => {\n const drawerRef = useRef<HTMLDivElement>(null)\n const closeButtonRef = useRef<HTMLButtonElement>(null)\n const contentRef = useRef<HTMLDivElement>(null)\n const previousActiveElement = useRef<HTMLElement | null>(null)\n const titleId = useId()\n const contentId = useId()\n const [mounted, setMounted] = useState(false)\n const [shouldRender, setShouldRender] = useState(open || forceRender)\n const [isAnimating, setIsAnimating] = useState(false)\n\n // Get parent drawer context for nested push behavior\n const parentDrawer = useDrawerContext()\n\n // Expose ref\n useImperativeHandle(ref, () => ({\n nativeElement: drawerRef.current,\n }))\n\n // Handle SSR - only render portal after mounting in browser\n useEffect(() => {\n setMounted(true)\n }, [])\n\n // Calculate dimensions\n const getSizeValue = (): number => {\n if (typeof size === 'number') return size\n return size === 'large' ? 736 : 378\n }\n\n const getDimension = (): { width?: string; height?: string } => {\n const isHorizontal = placement === 'left' || placement === 'right'\n const sizeValue = getSizeValue()\n\n if (isHorizontal) {\n const w = width ?? sizeValue\n return { width: typeof w === 'number' ? `${w}px` : w }\n } else {\n const h = height ?? sizeValue\n return { height: typeof h === 'number' ? `${h}px` : h }\n }\n }\n\n // Calculate push distance for nested drawers\n const getPushDistance = (): number => {\n if (!push) return 0\n if (typeof push === 'boolean') return push ? 180 : 0\n return push.distance ?? 180\n }\n\n // Focus trap\n const trapFocus = useCallback((e: KeyboardEvent) => {\n if (!drawerRef.current || e.key !== 'Tab' || typeof document === 'undefined') return\n\n const focusableElements = drawerRef.current.querySelectorAll<HTMLElement>(\n 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])'\n )\n const firstElement = focusableElements[0]\n const lastElement = focusableElements[focusableElements.length - 1]\n\n if (e.shiftKey && document.activeElement === firstElement) {\n e.preventDefault()\n lastElement?.focus()\n } else if (!e.shiftKey && document.activeElement === lastElement) {\n e.preventDefault()\n firstElement?.focus()\n }\n }, [])\n\n // Handle ESC key\n const handleKeyDown = useCallback(\n (e: KeyboardEvent) => {\n if (keyboard && e.key === 'Escape' && onClose) {\n e.preventDefault()\n onClose()\n }\n },\n [keyboard, onClose]\n )\n\n // Handle animation end\n const handleTransitionEnd = useCallback(() => {\n setIsAnimating(false)\n afterOpenChange?.(open)\n\n if (!open && destroyOnClose) {\n setShouldRender(false)\n }\n }, [open, afterOpenChange, destroyOnClose])\n\n // Open/close effects\n useEffect(() => {\n if (typeof document === 'undefined') return\n\n if (open) {\n setShouldRender(true)\n setIsAnimating(true)\n previousActiveElement.current = document.activeElement as HTMLElement\n document.body.style.overflow = 'hidden'\n\n // Set initial focus\n const focusTimeout = setTimeout(() => {\n if (initialFocus === 'close' && closeButtonRef.current) {\n closeButtonRef.current.focus()\n } else if (contentRef.current) {\n const firstFocusable = contentRef.current.querySelector<HTMLElement>(\n 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])'\n )\n firstFocusable?.focus()\n }\n }, 0)\n\n // Add event listeners\n document.addEventListener('keydown', handleKeyDown)\n document.addEventListener('keydown', trapFocus)\n\n return () => {\n clearTimeout(focusTimeout)\n document.body.style.overflow = ''\n document.removeEventListener('keydown', handleKeyDown)\n document.removeEventListener('keydown', trapFocus)\n }\n } else {\n setIsAnimating(true)\n // Restore focus to previously focused element if it's still in the DOM\n const prevElement = previousActiveElement.current\n if (prevElement && document.body.contains(prevElement)) {\n prevElement.focus()\n }\n }\n }, [open, handleKeyDown, trapFocus, initialFocus])\n\n const handleMaskClick = (e: React.MouseEvent) => {\n if (maskClosable && onClose) {\n onClose(e)\n }\n }\n\n // Position classes\n const placementClasses: Record<DrawerPlacement, string> = {\n top: 'inset-x-0 top-0',\n right: 'inset-y-0 right-0',\n bottom: 'inset-x-0 bottom-0',\n left: 'inset-y-0 left-0',\n }\n\n // Transform for animation\n const getTransform = (isOpen: boolean): string => {\n // Apply push offset from child drawer\n const pushOffset = parentDrawer && open ? parentDrawer.pushDistance : 0\n\n if (isOpen) {\n if (pushOffset === 0) return 'translate(0, 0)'\n switch (placement) {\n case 'right':\n return `translateX(-${pushOffset}px)`\n case 'left':\n return `translateX(${pushOffset}px)`\n case 'top':\n return `translateY(${pushOffset}px)`\n case 'bottom':\n return `translateY(-${pushOffset}px)`\n }\n }\n\n switch (placement) {\n case 'top':\n return 'translateY(-100%)'\n case 'right':\n return 'translateX(100%)'\n case 'bottom':\n return 'translateY(100%)'\n case 'left':\n return 'translateX(-100%)'\n }\n }\n\n const dimension = getDimension()\n\n // Get container element\n const getContainerElement = (): HTMLElement | null => {\n if (getContainer === false) return null\n if (typeof getContainer === 'function') return getContainer()\n if (getContainer) return getContainer\n return typeof document !== 'undefined' ? document.body : null\n }\n\n // Generate test IDs\n const getTestId = (suffix: string) => (testId ? `${testId}-${suffix}` : undefined)\n\n const drawerContent = (\n <DrawerContext.Provider value={{ push, pushDistance: getPushDistance() }}>\n <div\n className={`fixed inset-0 ${open ? '' : 'pointer-events-none'} ${rootClassName}`}\n style={{ zIndex, ...rootStyle }}\n role=\"presentation\"\n data-state={open ? 'open' : 'closed'}\n data-testid={testId}\n {...rest}\n >\n {/* Backdrop/Mask */}\n {mask && (\n <div\n className={`absolute inset-0 bg-black transition-opacity duration-300 ${\n open ? 'opacity-50' : 'opacity-0'\n }`}\n style={maskStyle}\n onClick={handleMaskClick}\n aria-hidden=\"true\"\n data-testid={getTestId('mask')}\n />\n )}\n\n {/* Drawer Panel */}\n <div\n ref={drawerRef}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-labelledby={title ? titleId : undefined}\n aria-describedby={contentId}\n className={`fixed flex flex-col bg-base-100 shadow-xl transition-transform duration-300 ease-in-out ${placementClasses[placement]} ${className}`}\n style={{\n ...dimension,\n transform: getTransform(open),\n ...style,\n }}\n onTransitionEnd={handleTransitionEnd}\n data-testid={getTestId('panel')}\n >\n {/* Header */}\n {(title || closable || extra) && (\n <div\n className=\"flex items-center justify-between px-6 py-4 border-b border-base-300\"\n style={headerStyle}\n data-testid={getTestId('header')}\n >\n {title && (\n <h2 id={titleId} className=\"text-lg font-semibold\">\n {title}\n </h2>\n )}\n <div className=\"flex items-center gap-2 ml-auto\">\n {extra}\n {closable && (\n <button\n ref={closeButtonRef}\n type=\"button\"\n className={`${dBtn} ${dBtnGhost} ${dBtnSm} ${dBtnSquare}`}\n onClick={onClose}\n aria-label=\"Close drawer\"\n data-testid={getTestId('close')}\n >\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n className=\"h-5 w-5\"\n fill=\"none\"\n viewBox=\"0 0 24 24\"\n stroke=\"currentColor\"\n aria-hidden=\"true\"\n >\n <path\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth={2}\n d=\"M6 18L18 6M6 6l12 12\"\n />\n </svg>\n </button>\n )}\n </div>\n </div>\n )}\n\n {/* Content */}\n <div\n ref={contentRef}\n id={contentId}\n className=\"flex-1 overflow-auto p-6\"\n style={bodyStyle}\n data-testid={getTestId('body')}\n >\n {loading ? (\n <div className=\"space-y-4\" data-testid={getTestId('skeleton')}>\n <Skeleton className=\"h-4 w-3/4\" />\n <Skeleton className=\"h-4 w-full\" />\n <Skeleton className=\"h-4 w-5/6\" />\n <Skeleton className=\"h-4 w-2/3\" />\n <Skeleton className=\"h-32 w-full\" />\n </div>\n ) : (\n children\n )}\n </div>\n\n {/* Footer */}\n {footer && (\n <div\n className=\"px-6 py-4 border-t border-base-300\"\n style={footerStyle}\n data-testid={getTestId('footer')}\n >\n {footer}\n </div>\n )}\n </div>\n </div>\n </DrawerContext.Provider>\n )\n\n // Don't render during SSR or when not needed\n if (!mounted) return null\n if (!shouldRender && !open && !forceRender) return null\n\n // Render without portal if getContainer is false\n const container = getContainerElement()\n if (container === null) return drawerContent\n\n return createPortal(drawerContent, container)\n }\n)\n\nDrawer.displayName = 'Drawer'\n"],"names":["dBtn","dBtnGhost","dBtnSm","dBtnSquare","DrawerContext","createContext","useDrawerContext","useContext","Drawer","forwardRef","children","open","onClose","afterOpenChange","title","placement","size","width","height","closable","mask","maskClosable","keyboard","footer","extra","className","rootClassName","style","headerStyle","bodyStyle","footerStyle","rootStyle","maskStyle","zIndex","destroyOnClose","forceRender","initialFocus","loading","getContainer","push","testId","rest","ref","drawerRef","useRef","closeButtonRef","contentRef","previousActiveElement","titleId","useId","contentId","mounted","setMounted","useState","shouldRender","setShouldRender","isAnimating","setIsAnimating","parentDrawer","useImperativeHandle","useEffect","getSizeValue","getDimension","isHorizontal","sizeValue","w","h","getPushDistance","trapFocus","useCallback","focusableElements","firstElement","lastElement","handleKeyDown","handleTransitionEnd","focusTimeout","prevElement","handleMaskClick","placementClasses","getTransform","isOpen","pushOffset","dimension","getContainerElement","getTestId","suffix","drawerContent","jsx","jsxs","Skeleton","container","createPortal"],"mappings":";;;;AAeA,MAAMA,KAAO,SACPC,KAAY,eACZC,KAAS,YACTC,KAAa,gBAsFbC,IAAgBC,GAAyC,IAAI;AAEnE,SAASC,KAAmB;AAC1B,SAAOC,G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AA;AAAA,gBAAA;AAAA,gBAKJ,gBAAAA;AAAA,kBAAC;AAAA,kBAAA;AAAA,oBACC,KAAKzC;AAAA,oBACL,IAAII;AAAA,oBACJ,WAAU;AAAA,oBACV,OAAOrB;AAAA,oBACP,eAAauD,EAAU,MAAM;AAAA,oBAE5B,UAAA/C,uBACE,OAAA,EAAI,WAAU,aAAY,eAAa+C,EAAU,UAAU,GAC1D,UAAA;AAAA,sBAAA,gBAAAG,EAACE,GAAA,EAAS,WAAU,YAAA,CAAY;AAAA,sBAChC,gBAAAF,EAACE,GAAA,EAAS,WAAU,aAAA,CAAa;AAAA,sBACjC,gBAAAF,EAACE,GAAA,EAAS,WAAU,YAAA,CAAY;AAAA,sBAChC,gBAAAF,EAACE,GAAA,EAAS,WAAU,YAAA,CAAY;AAAA,sBAChC,gBAAAF,EAACE,GAAA,EAAS,WAAU,cAAA,CAAc;AAAA,oBAAA,EAAA,CACpC,IAEA/E;AAAA,kBAAA;AAAA,gBAAA;AAAA,gBAKHa,KACC,gBAAAgE;AAAA,kBAAC;AAAA,kBAAA;AAAA,oBACC,WAAU;AAAA,oBACV,OAAOzD;AAAA,oBACP,eAAasD,EAAU,QAAQ;AAAA,oBAE9B,UAAA7D;AAAA,kBAAA;AAAA,gBAAA;AAAA,cACH;AAAA,YAAA;AAAA,UAAA;AAAA,QAEJ;AAAA,MAAA;AAAA,IAAA,GAEJ;AAKF,QADI,CAAC4B,MACD,CAACG,MAAgB,CAAC3C,KAAQ,CAACwB,EAAa,QAAO;AAGnD,UAAMuD,IAAYP,GAAA;AAClB,WAAIO,MAAc,OAAaJ,IAExBK,GAAaL,GAAeI,CAAS;AAAA,EAC9C;AACF;AAEAlF,GAAO,cAAc;"}
|
|
1
|
+
{"version":3,"file":"Drawer.js","sources":["../../src/components/Drawer.tsx"],"sourcesContent":["import React, {\n useEffect,\n useRef,\n useId,\n useCallback,\n useState,\n forwardRef,\n useImperativeHandle,\n createContext,\n useContext,\n} from 'react'\nimport { createPortal } from 'react-dom'\nimport { Skeleton } from './Skeleton'\n\n// DaisyUI classes\nconst dBtn = 'd-btn'\nconst dBtnGhost = 'd-btn-ghost'\nconst dBtnSm = 'd-btn-sm'\nconst dBtnSquare = 'd-btn-square'\n\nexport type DrawerPlacement = 'top' | 'right' | 'bottom' | 'left'\nexport type DrawerSize = 'default' | 'large' | number\n\nexport interface DrawerPushConfig {\n /** Distance to push parent drawer (default: 180) */\n distance?: number\n}\n\nexport interface DrawerProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'title'> {\n /** Drawer content */\n children: React.ReactNode\n /** Whether the drawer is visible */\n open?: boolean\n /** Callback when drawer is closed */\n onClose?: (e?: React.MouseEvent | React.KeyboardEvent) => void\n /** Callback after open/close animation completes */\n afterOpenChange?: (open: boolean) => void\n /** Drawer title */\n title?: React.ReactNode\n /** Direction drawer slides from */\n placement?: DrawerPlacement\n /** Preset size or custom width/height in pixels */\n size?: DrawerSize\n /** Custom width (overrides size for left/right placement) */\n width?: number | string\n /** Custom height (overrides size for top/bottom placement) */\n height?: number | string\n /** Whether to show close button */\n closable?: boolean\n /** Whether to show mask/backdrop */\n mask?: boolean\n /** Whether clicking mask closes drawer */\n maskClosable?: boolean\n /** Whether ESC closes drawer */\n keyboard?: boolean\n /** Footer content */\n footer?: React.ReactNode\n /** Extra content in header (right side) */\n extra?: React.ReactNode\n /** CSS class for drawer panel */\n className?: string\n /** CSS class for drawer wrapper */\n rootClassName?: string\n /** Style for drawer panel */\n style?: React.CSSProperties\n /** Style for drawer header */\n headerStyle?: React.CSSProperties\n /** Style for drawer body/content area */\n bodyStyle?: React.CSSProperties\n /** Style for drawer footer */\n footerStyle?: React.CSSProperties\n /** Style for drawer wrapper (includes mask) */\n rootStyle?: React.CSSProperties\n /** Style for mask/backdrop */\n maskStyle?: React.CSSProperties\n /** z-index of drawer */\n zIndex?: number\n /** Destroy content when closed */\n destroyOnClose?: boolean\n /** Pre-render drawer content (keep in DOM even when closed) */\n forceRender?: boolean\n /** Where to place initial focus */\n initialFocus?: 'close' | 'content'\n /** Show loading skeleton */\n loading?: boolean\n /** Custom container for portal (false to disable portal) */\n getContainer?: HTMLElement | (() => HTMLElement) | false\n /** Nested drawer push behavior */\n push?: boolean | DrawerPushConfig\n /** Test ID for testing */\n 'data-testid'?: string\n}\n\nexport interface DrawerRef {\n /** The drawer panel element */\n nativeElement: HTMLDivElement | null\n}\n\n// Context for nested drawer push behavior\ninterface DrawerContextValue {\n push: boolean | DrawerPushConfig\n pushDistance: number\n}\n\nconst DrawerContext = createContext<DrawerContextValue | null>(null)\n\nfunction useDrawerContext() {\n return useContext(DrawerContext)\n}\n\n/**\n * Drawer - A panel that slides in from the edge of the screen.\n * Use for forms, details, or task panels.\n * For responsive sidebar navigation, use ResponsiveDrawer instead.\n */\nexport const Drawer = forwardRef<DrawerRef, DrawerProps>(\n (\n {\n children,\n open = false,\n onClose,\n afterOpenChange,\n title,\n placement = 'right',\n size = 'default',\n width,\n height,\n closable = true,\n mask = true,\n maskClosable = true,\n keyboard = true,\n footer,\n extra,\n className = '',\n rootClassName = '',\n style,\n headerStyle,\n bodyStyle,\n footerStyle,\n rootStyle,\n maskStyle,\n zIndex = 1000,\n destroyOnClose = false,\n forceRender = false,\n initialFocus = 'close',\n loading = false,\n getContainer,\n push = { distance: 180 },\n 'data-testid': testId,\n ...rest\n },\n ref\n ) => {\n const drawerRef = useRef<HTMLDivElement>(null)\n const closeButtonRef = useRef<HTMLButtonElement>(null)\n const contentRef = useRef<HTMLDivElement>(null)\n const previousActiveElement = useRef<HTMLElement | null>(null)\n const titleId = useId()\n const contentId = useId()\n const [mounted, setMounted] = useState(false)\n const [shouldRender, setShouldRender] = useState(open || forceRender)\n const [, setIsAnimating] = useState(false)\n\n // Get parent drawer context for nested push behavior\n const parentDrawer = useDrawerContext()\n\n // Expose ref\n useImperativeHandle(ref, () => ({\n nativeElement: drawerRef.current,\n }))\n\n // Handle SSR - only render portal after mounting in browser\n useEffect(() => {\n setMounted(true)\n }, [])\n\n // Calculate dimensions\n const getSizeValue = (): number => {\n if (typeof size === 'number') return size\n return size === 'large' ? 736 : 378\n }\n\n const getDimension = (): { width?: string; height?: string } => {\n const isHorizontal = placement === 'left' || placement === 'right'\n const sizeValue = getSizeValue()\n\n if (isHorizontal) {\n const w = width ?? sizeValue\n return { width: typeof w === 'number' ? `${w}px` : w }\n } else {\n const h = height ?? sizeValue\n return { height: typeof h === 'number' ? `${h}px` : h }\n }\n }\n\n // Calculate push distance for nested drawers\n const getPushDistance = (): number => {\n if (!push) return 0\n if (typeof push === 'boolean') return push ? 180 : 0\n return push.distance ?? 180\n }\n\n // Focus trap\n const trapFocus = useCallback((e: KeyboardEvent) => {\n if (!drawerRef.current || e.key !== 'Tab' || typeof document === 'undefined') return\n\n const focusableElements = drawerRef.current.querySelectorAll<HTMLElement>(\n 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])'\n )\n const firstElement = focusableElements[0]\n const lastElement = focusableElements[focusableElements.length - 1]\n\n if (e.shiftKey && document.activeElement === firstElement) {\n e.preventDefault()\n lastElement?.focus()\n } else if (!e.shiftKey && document.activeElement === lastElement) {\n e.preventDefault()\n firstElement?.focus()\n }\n }, [])\n\n // Handle ESC key\n const handleKeyDown = useCallback(\n (e: KeyboardEvent) => {\n if (keyboard && e.key === 'Escape' && onClose) {\n e.preventDefault()\n onClose()\n }\n },\n [keyboard, onClose]\n )\n\n // Handle animation end\n const handleTransitionEnd = useCallback(() => {\n setIsAnimating(false)\n afterOpenChange?.(open)\n\n if (!open && destroyOnClose) {\n setShouldRender(false)\n }\n }, [open, afterOpenChange, destroyOnClose])\n\n // Open/close effects\n useEffect(() => {\n if (typeof document === 'undefined') return\n\n if (open) {\n setShouldRender(true)\n setIsAnimating(true)\n previousActiveElement.current = document.activeElement as HTMLElement\n document.body.style.overflow = 'hidden'\n\n // Set initial focus\n const focusTimeout = setTimeout(() => {\n if (initialFocus === 'close' && closeButtonRef.current) {\n closeButtonRef.current.focus()\n } else if (contentRef.current) {\n const firstFocusable = contentRef.current.querySelector<HTMLElement>(\n 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])'\n )\n firstFocusable?.focus()\n }\n }, 0)\n\n // Add event listeners\n document.addEventListener('keydown', handleKeyDown)\n document.addEventListener('keydown', trapFocus)\n\n return () => {\n clearTimeout(focusTimeout)\n document.body.style.overflow = ''\n document.removeEventListener('keydown', handleKeyDown)\n document.removeEventListener('keydown', trapFocus)\n }\n } else {\n setIsAnimating(true)\n // Restore focus to previously focused element if it's still in the DOM\n const prevElement = previousActiveElement.current\n if (prevElement && document.body.contains(prevElement)) {\n prevElement.focus()\n }\n }\n }, [open, handleKeyDown, trapFocus, initialFocus])\n\n const handleMaskClick = (e: React.MouseEvent) => {\n if (maskClosable && onClose) {\n onClose(e)\n }\n }\n\n // Position classes\n const placementClasses: Record<DrawerPlacement, string> = {\n top: 'inset-x-0 top-0',\n right: 'inset-y-0 right-0',\n bottom: 'inset-x-0 bottom-0',\n left: 'inset-y-0 left-0',\n }\n\n // Transform for animation\n const getTransform = (isOpen: boolean): string => {\n // Apply push offset from child drawer\n const pushOffset = parentDrawer && open ? parentDrawer.pushDistance : 0\n\n if (isOpen) {\n if (pushOffset === 0) return 'translate(0, 0)'\n switch (placement) {\n case 'right':\n return `translateX(-${pushOffset}px)`\n case 'left':\n return `translateX(${pushOffset}px)`\n case 'top':\n return `translateY(${pushOffset}px)`\n case 'bottom':\n return `translateY(-${pushOffset}px)`\n }\n }\n\n switch (placement) {\n case 'top':\n return 'translateY(-100%)'\n case 'right':\n return 'translateX(100%)'\n case 'bottom':\n return 'translateY(100%)'\n case 'left':\n return 'translateX(-100%)'\n }\n }\n\n const dimension = getDimension()\n\n // Get container element\n const getContainerElement = (): HTMLElement | null => {\n if (getContainer === false) return null\n if (typeof getContainer === 'function') return getContainer()\n if (getContainer) return getContainer\n return typeof document !== 'undefined' ? document.body : null\n }\n\n // Generate test IDs\n const getTestId = (suffix: string) => (testId ? `${testId}-${suffix}` : undefined)\n\n const drawerContent = (\n <DrawerContext.Provider value={{ push, pushDistance: getPushDistance() }}>\n <div\n className={`fixed inset-0 ${open ? '' : 'pointer-events-none'} ${rootClassName}`}\n style={{ zIndex, ...rootStyle }}\n role=\"presentation\"\n data-state={open ? 'open' : 'closed'}\n data-testid={testId}\n {...rest}\n >\n {/* Backdrop/Mask */}\n {mask && (\n <div\n className={`absolute inset-0 bg-black transition-opacity duration-300 ${\n open ? 'opacity-50' : 'opacity-0'\n }`}\n style={maskStyle}\n onClick={handleMaskClick}\n aria-hidden=\"true\"\n data-testid={getTestId('mask')}\n />\n )}\n\n {/* Drawer Panel */}\n <div\n ref={drawerRef}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-labelledby={title ? titleId : undefined}\n aria-describedby={contentId}\n className={`fixed flex flex-col bg-base-100 shadow-xl transition-transform duration-300 ease-in-out ${placementClasses[placement]} ${className}`}\n style={{\n ...dimension,\n transform: getTransform(open),\n ...style,\n }}\n onTransitionEnd={handleTransitionEnd}\n data-testid={getTestId('panel')}\n >\n {/* Header */}\n {(title || closable || extra) && (\n <div\n className=\"flex items-center justify-between px-6 py-4 border-b border-base-300\"\n style={headerStyle}\n data-testid={getTestId('header')}\n >\n {title && (\n <h2 id={titleId} className=\"text-lg font-semibold\">\n {title}\n </h2>\n )}\n <div className=\"flex items-center gap-2 ml-auto\">\n {extra}\n {closable && (\n <button\n ref={closeButtonRef}\n type=\"button\"\n className={`${dBtn} ${dBtnGhost} ${dBtnSm} ${dBtnSquare}`}\n onClick={onClose}\n aria-label=\"Close drawer\"\n data-testid={getTestId('close')}\n >\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n className=\"h-5 w-5\"\n fill=\"none\"\n viewBox=\"0 0 24 24\"\n stroke=\"currentColor\"\n aria-hidden=\"true\"\n >\n <path\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth={2}\n d=\"M6 18L18 6M6 6l12 12\"\n />\n </svg>\n </button>\n )}\n </div>\n </div>\n )}\n\n {/* Content */}\n <div\n ref={contentRef}\n id={contentId}\n className=\"flex-1 overflow-auto p-6\"\n style={bodyStyle}\n data-testid={getTestId('body')}\n >\n {loading ? (\n <div className=\"space-y-4\" data-testid={getTestId('skeleton')}>\n <Skeleton className=\"h-4 w-3/4\" />\n <Skeleton className=\"h-4 w-full\" />\n <Skeleton className=\"h-4 w-5/6\" />\n <Skeleton className=\"h-4 w-2/3\" />\n <Skeleton className=\"h-32 w-full\" />\n </div>\n ) : (\n children\n )}\n </div>\n\n {/* Footer */}\n {footer && (\n <div\n className=\"px-6 py-4 border-t border-base-300\"\n style={footerStyle}\n data-testid={getTestId('footer')}\n >\n {footer}\n </div>\n )}\n </div>\n </div>\n </DrawerContext.Provider>\n )\n\n // Don't render during SSR or when not needed\n if (!mounted) return null\n if (!shouldRender && !open && !forceRender) return null\n\n // Render without portal if getContainer is false\n const container = getContainerElement()\n if (container === null) return drawerContent\n\n return createPortal(drawerContent, container)\n }\n)\n\nDrawer.displayName = 'Drawer'\n"],"names":["dBtn","dBtnGhost","dBtnSm","dBtnSquare","DrawerContext","createContext","useDrawerContext","useContext","Drawer","forwardRef","children","open","onClose","afterOpenChange","title","placement","size","width","height","closable","mask","maskClosable","keyboard","footer","extra","className","rootClassName","style","headerStyle","bodyStyle","footerStyle","rootStyle","maskStyle","zIndex","destroyOnClose","forceRender","initialFocus","loading","getContainer","push","testId","rest","ref","drawerRef","useRef","closeButtonRef","contentRef","previousActiveElement","titleId","useId","contentId","mounted","setMounted","useState","shouldRender","setShouldRender","setIsAnimating","parentDrawer","useImperativeHandle","useEffect","getSizeValue","getDimension","isHorizontal","sizeValue","w","h","getPushDistance","trapFocus","useCallback","focusableElements","firstElement","lastElement","handleKeyDown","handleTransitionEnd","focusTimeout","prevElement","handleMaskClick","placementClasses","getTransform","isOpen","pushOffset","dimension","getContainerElement","getTestId","suffix","drawerContent","jsx","jsxs","Skeleton","container","createPortal"],"mappings":";;;;AAeA,MAAM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State as
|
|
3
|
-
import { useConfig as
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { jsx as r, jsxs as p } from "react/jsx-runtime";
|
|
2
|
+
import { useState as b, useEffect as f, useId as $ } from "react";
|
|
3
|
+
import { useConfig as S } from "./ConfigProvider.js";
|
|
4
|
+
import { useTheme as v } from "../hooks/useTheme.js";
|
|
5
|
+
const C = "d-swap", D = "d-swap-rotate", M = "d-swap-off", Z = "d-swap-on", N = "d-dropdown", B = "d-dropdown-end", y = "d-dropdown-content", A = "d-btn", E = "d-btn-sm", I = "d-btn-block", O = "d-btn-ghost", z = "d-toggle", j = "d-toggle-xs", F = "d-toggle-sm", H = "d-toggle-md", L = "d-toggle-lg", V = "d-toggle-xl";
|
|
6
|
+
function i() {
|
|
6
7
|
return document.documentElement.getAttribute("data-theme");
|
|
7
8
|
}
|
|
8
|
-
function
|
|
9
|
-
document.documentElement.setAttribute("data-theme",
|
|
9
|
+
function x(n) {
|
|
10
|
+
document.documentElement.setAttribute("data-theme", n);
|
|
10
11
|
}
|
|
11
|
-
function
|
|
12
|
-
lightTheme:
|
|
13
|
-
darkTheme:
|
|
14
|
-
onChange:
|
|
15
|
-
className:
|
|
12
|
+
function X({
|
|
13
|
+
lightTheme: n = "light",
|
|
14
|
+
darkTheme: o = "dark",
|
|
15
|
+
onChange: u,
|
|
16
|
+
className: m = ""
|
|
16
17
|
}) {
|
|
17
|
-
const [
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
const { setTheme: g, isDark: t } = v(), h = g ?? x, [c, l] = b(() => t !== void 0 ? t : i() === o);
|
|
19
|
+
f(() => {
|
|
20
|
+
if (t !== void 0) {
|
|
21
|
+
l(t);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const s = new MutationObserver(() => {
|
|
25
|
+
const e = i();
|
|
26
|
+
l(e === o);
|
|
22
27
|
});
|
|
23
|
-
return
|
|
24
|
-
}, [
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
+
return s.observe(document.documentElement, { attributes: !0, attributeFilter: ["data-theme"] }), () => s.disconnect();
|
|
29
|
+
}, [o, t]);
|
|
30
|
+
const a = (s) => {
|
|
31
|
+
const d = s.target.checked ? o : n;
|
|
32
|
+
h(d), u?.(d);
|
|
28
33
|
};
|
|
29
|
-
return /* @__PURE__ */
|
|
30
|
-
/* @__PURE__ */
|
|
34
|
+
return /* @__PURE__ */ p("label", { className: `${C} ${D} ${m}`, children: [
|
|
35
|
+
/* @__PURE__ */ r(
|
|
31
36
|
"input",
|
|
32
37
|
{
|
|
33
38
|
type: "checkbox",
|
|
34
|
-
checked:
|
|
35
|
-
onChange:
|
|
39
|
+
checked: c,
|
|
40
|
+
onChange: a
|
|
36
41
|
}
|
|
37
42
|
),
|
|
38
|
-
/* @__PURE__ */
|
|
43
|
+
/* @__PURE__ */ r(
|
|
39
44
|
"svg",
|
|
40
45
|
{
|
|
41
|
-
className: `${
|
|
46
|
+
className: `${M} h-8 w-8 fill-current`,
|
|
42
47
|
xmlns: "http://www.w3.org/2000/svg",
|
|
43
48
|
viewBox: "0 0 24 24",
|
|
44
|
-
children: /* @__PURE__ */
|
|
49
|
+
children: /* @__PURE__ */ r("path", { d: "M5.64,17l-.71.71a1,1,0,0,0,0,1.41,1,1,0,0,0,1.41,0l.71-.71A1,1,0,0,0,5.64,17ZM5,12a1,1,0,0,0-1-1H3a1,1,0,0,0,0,2H4A1,1,0,0,0,5,12Zm7-7a1,1,0,0,0,1-1V3a1,1,0,0,0-2,0V4A1,1,0,0,0,12,5ZM5.64,7.05a1,1,0,0,0,.7.29,1,1,0,0,0,.71-.29,1,1,0,0,0,0-1.41l-.71-.71A1,1,0,0,0,4.93,6.34Zm12,.29a1,1,0,0,0,.7-.29l.71-.71a1,1,0,1,0-1.41-1.41L17,5.64a1,1,0,0,0,0,1.41A1,1,0,0,0,17.66,7.34ZM21,11H20a1,1,0,0,0,0,2h1a1,1,0,0,0,0-2Zm-9,8a1,1,0,0,0-1,1v1a1,1,0,0,0,2,0V20A1,1,0,0,0,12,19ZM18.36,17A1,1,0,0,0,17,18.36l.71.71a1,1,0,0,0,1.41,0,1,1,0,0,0,0-1.41ZM12,6.5A5.5,5.5,0,1,0,17.5,12,5.51,5.51,0,0,0,12,6.5Zm0,9A3.5,3.5,0,1,1,15.5,12,3.5,3.5,0,0,1,12,15.5Z" })
|
|
45
50
|
}
|
|
46
51
|
),
|
|
47
|
-
/* @__PURE__ */
|
|
52
|
+
/* @__PURE__ */ r(
|
|
48
53
|
"svg",
|
|
49
54
|
{
|
|
50
|
-
className: `${
|
|
55
|
+
className: `${Z} h-8 w-8 fill-current`,
|
|
51
56
|
xmlns: "http://www.w3.org/2000/svg",
|
|
52
57
|
viewBox: "0 0 24 24",
|
|
53
|
-
children: /* @__PURE__ */
|
|
58
|
+
children: /* @__PURE__ */ r("path", { d: "M21.64,13a1,1,0,0,0-1.05-.14,8.05,8.05,0,0,1-3.37.73A8.15,8.15,0,0,1,9.08,5.49a8.59,8.59,0,0,1,.25-2A1,1,0,0,0,8,2.36,10.14,10.14,0,1,0,22,14.05,1,1,0,0,0,21.64,13Zm-9.5,6.69A8.14,8.14,0,0,1,7.08,5.22v.27A10.15,10.15,0,0,0,17.22,15.63a9.79,9.79,0,0,0,2.1-.22A8.11,8.11,0,0,1,12.14,19.73Z" })
|
|
54
59
|
}
|
|
55
60
|
)
|
|
56
61
|
] });
|
|
57
62
|
}
|
|
58
|
-
function
|
|
59
|
-
themes:
|
|
60
|
-
defaultTheme:
|
|
61
|
-
onChange:
|
|
62
|
-
className:
|
|
63
|
+
function G({
|
|
64
|
+
themes: n,
|
|
65
|
+
defaultTheme: o,
|
|
66
|
+
onChange: u,
|
|
67
|
+
className: m = ""
|
|
63
68
|
}) {
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
const { setTheme: g, resolvedTheme: t } = v(), h = g ?? x, c = $(), [l, a] = b(() => {
|
|
70
|
+
if (t && n.includes(t)) return t;
|
|
71
|
+
const e = i();
|
|
72
|
+
return e && n.includes(e) ? e : o || n[0] || "light";
|
|
67
73
|
});
|
|
68
|
-
|
|
74
|
+
f(() => {
|
|
75
|
+
if (t && n.includes(t)) {
|
|
76
|
+
a(t);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
69
79
|
const e = new MutationObserver(() => {
|
|
70
|
-
const
|
|
71
|
-
|
|
80
|
+
const d = i();
|
|
81
|
+
d && n.includes(d) && a(d);
|
|
72
82
|
});
|
|
73
83
|
return e.observe(document.documentElement, { attributes: !0, attributeFilter: ["data-theme"] }), () => e.disconnect();
|
|
74
|
-
}, [t]);
|
|
75
|
-
const
|
|
76
|
-
|
|
84
|
+
}, [n, t]);
|
|
85
|
+
const s = (e) => {
|
|
86
|
+
a(e), h(e), u?.(e);
|
|
77
87
|
};
|
|
78
|
-
return /* @__PURE__ */
|
|
79
|
-
/* @__PURE__ */
|
|
88
|
+
return /* @__PURE__ */ p("div", { className: `${N} ${B} ${m}`, children: [
|
|
89
|
+
/* @__PURE__ */ p("div", { tabIndex: 0, role: "button", className: A, children: [
|
|
80
90
|
"Theme",
|
|
81
|
-
/* @__PURE__ */
|
|
91
|
+
/* @__PURE__ */ r(
|
|
82
92
|
"svg",
|
|
83
93
|
{
|
|
84
94
|
width: "12px",
|
|
@@ -86,77 +96,81 @@ function H({
|
|
|
86
96
|
className: "inline-block h-2 w-2 fill-current opacity-60",
|
|
87
97
|
xmlns: "http://www.w3.org/2000/svg",
|
|
88
98
|
viewBox: "0 0 2048 2048",
|
|
89
|
-
children: /* @__PURE__ */
|
|
99
|
+
children: /* @__PURE__ */ r("path", { d: "M1799 349l242 241-1017 1017L7 590l242-241 775 775 775-775z" })
|
|
90
100
|
}
|
|
91
101
|
)
|
|
92
102
|
] }),
|
|
93
|
-
/* @__PURE__ */
|
|
103
|
+
/* @__PURE__ */ r(
|
|
94
104
|
"ul",
|
|
95
105
|
{
|
|
96
106
|
tabIndex: 0,
|
|
97
|
-
className: `${
|
|
98
|
-
children:
|
|
107
|
+
className: `${y} bg-base-300 rounded-box z-[1] w-52 p-2 shadow-2xl max-h-96 overflow-y-auto`,
|
|
108
|
+
children: n.map((e) => /* @__PURE__ */ r("li", { children: /* @__PURE__ */ r(
|
|
99
109
|
"input",
|
|
100
110
|
{
|
|
101
111
|
type: "radio",
|
|
102
|
-
name:
|
|
103
|
-
className: `${
|
|
112
|
+
name: c,
|
|
113
|
+
className: `${A} ${E} ${I} ${O} justify-start`,
|
|
104
114
|
"aria-label": e,
|
|
105
115
|
value: e,
|
|
106
|
-
checked:
|
|
107
|
-
onChange: () =>
|
|
116
|
+
checked: l === e,
|
|
117
|
+
onChange: () => s(e)
|
|
108
118
|
}
|
|
109
119
|
) }, e))
|
|
110
120
|
}
|
|
111
121
|
)
|
|
112
122
|
] });
|
|
113
123
|
}
|
|
114
|
-
const
|
|
115
|
-
xs:
|
|
116
|
-
sm:
|
|
117
|
-
md:
|
|
118
|
-
lg:
|
|
119
|
-
xl:
|
|
124
|
+
const R = {
|
|
125
|
+
xs: j,
|
|
126
|
+
sm: F,
|
|
127
|
+
md: H,
|
|
128
|
+
lg: L,
|
|
129
|
+
xl: V
|
|
120
130
|
};
|
|
121
|
-
function
|
|
122
|
-
lightTheme:
|
|
123
|
-
darkTheme:
|
|
124
|
-
onChange:
|
|
125
|
-
size:
|
|
126
|
-
className:
|
|
131
|
+
function q({
|
|
132
|
+
lightTheme: n = "light",
|
|
133
|
+
darkTheme: o = "dark",
|
|
134
|
+
onChange: u,
|
|
135
|
+
size: m,
|
|
136
|
+
className: g = ""
|
|
127
137
|
}) {
|
|
128
|
-
const { componentSize:
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
138
|
+
const { componentSize: t } = S(), { setTheme: h, isDark: c } = v(), l = h ?? x, a = m ?? t ?? "md", [s, e] = b(() => c !== void 0 ? c : i() === o);
|
|
139
|
+
f(() => {
|
|
140
|
+
if (c !== void 0) {
|
|
141
|
+
e(c);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const w = new MutationObserver(() => {
|
|
145
|
+
const T = i();
|
|
146
|
+
e(T === o);
|
|
133
147
|
});
|
|
134
|
-
return
|
|
135
|
-
}, [
|
|
136
|
-
const
|
|
137
|
-
const
|
|
138
|
-
|
|
148
|
+
return w.observe(document.documentElement, { attributes: !0, attributeFilter: ["data-theme"] }), () => w.disconnect();
|
|
149
|
+
}, [o, c]);
|
|
150
|
+
const d = (w) => {
|
|
151
|
+
const k = w.target.checked ? o : n;
|
|
152
|
+
l(k), u?.(k);
|
|
139
153
|
};
|
|
140
|
-
return /* @__PURE__ */
|
|
154
|
+
return /* @__PURE__ */ r(
|
|
141
155
|
"input",
|
|
142
156
|
{
|
|
143
157
|
type: "checkbox",
|
|
144
|
-
className: `${
|
|
145
|
-
checked:
|
|
146
|
-
onChange:
|
|
158
|
+
className: `${z} ${R[a]} ${g}`,
|
|
159
|
+
checked: s,
|
|
160
|
+
onChange: d,
|
|
147
161
|
"aria-label": "Toggle theme"
|
|
148
162
|
}
|
|
149
163
|
);
|
|
150
164
|
}
|
|
151
|
-
const
|
|
165
|
+
const U = Object.assign(
|
|
152
166
|
{},
|
|
153
167
|
{
|
|
154
|
-
Swap:
|
|
155
|
-
Dropdown:
|
|
156
|
-
Toggle:
|
|
168
|
+
Swap: X,
|
|
169
|
+
Dropdown: G,
|
|
170
|
+
Toggle: q
|
|
157
171
|
}
|
|
158
172
|
);
|
|
159
173
|
export {
|
|
160
|
-
|
|
174
|
+
U as ThemeController
|
|
161
175
|
};
|
|
162
176
|
//# sourceMappingURL=ThemeController.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeController.js","sources":["../../src/components/ThemeController.tsx"],"sourcesContent":["import React, { useState, useEffect, useId } from 'react'\nimport { useConfig } from './ConfigProvider'\n\n// DaisyUI classes\nconst dSwap = 'd-swap'\nconst dSwapRotate = 'd-swap-rotate'\nconst dSwapOff = 'd-swap-off'\nconst dSwapOn = 'd-swap-on'\nconst dDropdown = 'd-dropdown'\nconst dDropdownEnd = 'd-dropdown-end'\nconst dDropdownContent = 'd-dropdown-content'\nconst dBtn = 'd-btn'\nconst dBtnSm = 'd-btn-sm'\nconst dBtnBlock = 'd-btn-block'\nconst dBtnGhost = 'd-btn-ghost'\nconst dToggle = 'd-toggle'\nconst dToggleXs = 'd-toggle-xs'\nconst dToggleSm = 'd-toggle-sm'\nconst dToggleMd = 'd-toggle-md'\nconst dToggleLg = 'd-toggle-lg'\nconst dToggleXl = 'd-toggle-xl'\n\nexport interface ThemeControllerSwapProps {\n lightTheme?: string\n darkTheme?: string\n onChange?: (theme: string) => void\n className?: string\n}\n\nexport interface ThemeControllerDropdownProps {\n themes: string[]\n defaultTheme?: string\n onChange?: (theme: string) => void\n className?: string\n}\n\nexport interface ThemeControllerToggleProps {\n lightTheme?: string\n darkTheme?: string\n onChange?: (theme: string) => void\n size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl'\n className?: string\n}\n\n// Get current theme from document\nfunction getCurrentTheme(): string | null {\n return document.documentElement.getAttribute('data-theme')\n}\n\n// Set theme on document\nfunction setTheme(theme: string) {\n document.documentElement.setAttribute('data-theme', theme)\n}\n\nfunction ThemeControllerSwap({\n lightTheme = 'light',\n darkTheme = 'dark',\n onChange,\n className = '',\n}: ThemeControllerSwapProps) {\n const [isDark, setIsDark] = useState(() => {\n const current = getCurrentTheme()\n return current === darkTheme\n })\n\n // Sync with external theme changes\n useEffect(() => {\n const observer = new MutationObserver(() => {\n const current = getCurrentTheme()\n setIsDark(current === darkTheme)\n })\n observer.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme'] })\n return () => observer.disconnect()\n }, [darkTheme])\n\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n const checked = e.target.checked\n const theme = checked ? darkTheme : lightTheme\n setTheme(theme)\n onChange?.(theme)\n }\n\n return (\n <label className={`${dSwap} ${dSwapRotate} ${className}`}>\n <input\n type=\"checkbox\"\n checked={isDark}\n onChange={handleChange}\n />\n {/* sun icon */}\n <svg\n className={`${dSwapOff} h-8 w-8 fill-current`}\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n >\n <path d=\"M5.64,17l-.71.71a1,1,0,0,0,0,1.41,1,1,0,0,0,1.41,0l.71-.71A1,1,0,0,0,5.64,17ZM5,12a1,1,0,0,0-1-1H3a1,1,0,0,0,0,2H4A1,1,0,0,0,5,12Zm7-7a1,1,0,0,0,1-1V3a1,1,0,0,0-2,0V4A1,1,0,0,0,12,5ZM5.64,7.05a1,1,0,0,0,.7.29,1,1,0,0,0,.71-.29,1,1,0,0,0,0-1.41l-.71-.71A1,1,0,0,0,4.93,6.34Zm12,.29a1,1,0,0,0,.7-.29l.71-.71a1,1,0,1,0-1.41-1.41L17,5.64a1,1,0,0,0,0,1.41A1,1,0,0,0,17.66,7.34ZM21,11H20a1,1,0,0,0,0,2h1a1,1,0,0,0,0-2Zm-9,8a1,1,0,0,0-1,1v1a1,1,0,0,0,2,0V20A1,1,0,0,0,12,19ZM18.36,17A1,1,0,0,0,17,18.36l.71.71a1,1,0,0,0,1.41,0,1,1,0,0,0,0-1.41ZM12,6.5A5.5,5.5,0,1,0,17.5,12,5.51,5.51,0,0,0,12,6.5Zm0,9A3.5,3.5,0,1,1,15.5,12,3.5,3.5,0,0,1,12,15.5Z\" />\n </svg>\n {/* moon icon */}\n <svg\n className={`${dSwapOn} h-8 w-8 fill-current`}\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n >\n <path d=\"M21.64,13a1,1,0,0,0-1.05-.14,8.05,8.05,0,0,1-3.37.73A8.15,8.15,0,0,1,9.08,5.49a8.59,8.59,0,0,1,.25-2A1,1,0,0,0,8,2.36,10.14,10.14,0,1,0,22,14.05,1,1,0,0,0,21.64,13Zm-9.5,6.69A8.14,8.14,0,0,1,7.08,5.22v.27A10.15,10.15,0,0,0,17.22,15.63a9.79,9.79,0,0,0,2.1-.22A8.11,8.11,0,0,1,12.14,19.73Z\" />\n </svg>\n </label>\n )\n}\n\nfunction ThemeControllerDropdown({\n themes,\n defaultTheme,\n onChange,\n className = '',\n}: ThemeControllerDropdownProps) {\n const radioName = useId()\n const [selectedTheme, setSelectedTheme] = useState(() => {\n const current = getCurrentTheme()\n if (current && themes.includes(current)) return current\n return defaultTheme || themes[0] || 'light'\n })\n\n // Sync with external theme changes\n useEffect(() => {\n const observer = new MutationObserver(() => {\n const current = getCurrentTheme()\n if (current && themes.includes(current)) {\n setSelectedTheme(current)\n }\n })\n observer.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme'] })\n return () => observer.disconnect()\n }, [themes])\n\n const handleChange = (theme: string) => {\n setSelectedTheme(theme)\n setTheme(theme)\n onChange?.(theme)\n }\n\n return (\n <div className={`${dDropdown} ${dDropdownEnd} ${className}`}>\n <div tabIndex={0} role=\"button\" className={dBtn}>\n Theme\n <svg\n width=\"12px\"\n height=\"12px\"\n className=\"inline-block h-2 w-2 fill-current opacity-60\"\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 2048 2048\"\n >\n <path d=\"M1799 349l242 241-1017 1017L7 590l242-241 775 775 775-775z\"></path>\n </svg>\n </div>\n <ul\n tabIndex={0}\n className={`${dDropdownContent} bg-base-300 rounded-box z-[1] w-52 p-2 shadow-2xl max-h-96 overflow-y-auto`}\n >\n {themes.map((theme) => (\n <li key={theme}>\n <input\n type=\"radio\"\n name={radioName}\n className={`${dBtn} ${dBtnSm} ${dBtnBlock} ${dBtnGhost} justify-start`}\n aria-label={theme}\n value={theme}\n checked={selectedTheme === theme}\n onChange={() => handleChange(theme)}\n />\n </li>\n ))}\n </ul>\n </div>\n )\n}\n\nconst sizeClasses: Record<string, string> = {\n xs: dToggleXs,\n sm: dToggleSm,\n md: dToggleMd,\n lg: dToggleLg,\n xl: dToggleXl,\n}\n\nfunction ThemeControllerToggle({\n lightTheme = 'light',\n darkTheme = 'dark',\n onChange,\n size,\n className = '',\n}: ThemeControllerToggleProps) {\n const { componentSize } = useConfig()\n const effectiveSize = size ?? componentSize ?? 'md'\n\n const [isDark, setIsDark] = useState(() => {\n const current = getCurrentTheme()\n return current === darkTheme\n })\n\n // Sync with external theme changes\n useEffect(() => {\n const observer = new MutationObserver(() => {\n const current = getCurrentTheme()\n setIsDark(current === darkTheme)\n })\n observer.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme'] })\n return () => observer.disconnect()\n }, [darkTheme])\n\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n const checked = e.target.checked\n const theme = checked ? darkTheme : lightTheme\n setTheme(theme)\n onChange?.(theme)\n }\n\n return (\n <input\n type=\"checkbox\"\n className={`${dToggle} ${sizeClasses[effectiveSize]} ${className}`}\n checked={isDark}\n onChange={handleChange}\n aria-label=\"Toggle theme\"\n />\n )\n}\n\nexport const ThemeController = Object.assign(\n {},\n {\n Swap: ThemeControllerSwap,\n Dropdown: ThemeControllerDropdown,\n Toggle: ThemeControllerToggle,\n }\n)\n"],"names":["dSwap","dSwapRotate","dSwapOff","dSwapOn","dDropdown","dDropdownEnd","dDropdownContent","dBtn","dBtnSm","dBtnBlock","dBtnGhost","dToggle","dToggleXs","dToggleSm","dToggleMd","dToggleLg","dToggleXl","getCurrentTheme","setTheme","theme","ThemeControllerSwap","lightTheme","darkTheme","onChange","className","isDark","setIsDark","useState","useEffect","observer","current","handleChange","e","jsxs","jsx","ThemeControllerDropdown","themes","defaultTheme","radioName","useId","selectedTheme","setSelectedTheme","sizeClasses","ThemeControllerToggle","size","componentSize","useConfig","effectiveSize","ThemeController"],"mappings":";;;AAIA,MAAMA,IAAQ,UACRC,IAAc,iBACdC,IAAW,cACXC,IAAU,aACVC,IAAY,cACZC,IAAe,kBACfC,IAAmB,sBACnBC,IAAO,SACPC,IAAS,YACTC,IAAY,eACZC,IAAY,eACZC,IAAU,YACVC,IAAY,eACZC,IAAY,eACZC,IAAY,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M,iBAAiB,CAAC,YAAY,GAAG,GACzF,MAAMA,EAAS,WAAA;AAAA,EACxB,GAAG,CAACP,CAAS,CAAC;AAEd,QAAMS,IAAe,CAACC,MAA2C;AAE/D,UAAMb,IADUa,EAAE,OAAO,UACDV,IAAYD;AACpC,IAAAH,EAASC,CAAK,GACdI,IAAWJ,CAAK;AAAA,EAClB;AAEA,SACE,gBAAAe;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,MAAK;AAAA,MACL,WAAW,GAAGvB,CAAO,IAAI+B,EAAYK,CAAa,CAAC,IAAIvB,CAAS;AAAA,MAChE,SAASC;AAAA,MACT,UAAUM;AAAA,MACV,cAAW;AAAA,IAAA;AAAA,EAAA;AAGjB;AAEO,MAAMiB,IAAkB,OAAO;AAAA,EACpC,CAAA;AAAA,EACA;AAAA,IACE,MAAM5B;AAAA,IACN,UAAUe;AAAA,IACV,QAAQQ;AAAA,EAAA;AAEZ;"}
|
|
1
|
+
{"version":3,"file":"ThemeController.js","sources":["../../src/components/ThemeController.tsx"],"sourcesContent":["import React, { useState, useEffect, useId } from 'react'\nimport { useConfig } from './ConfigProvider'\nimport { useTheme } from '../hooks/useTheme'\n\n// DaisyUI classes\nconst dSwap = 'd-swap'\nconst dSwapRotate = 'd-swap-rotate'\nconst dSwapOff = 'd-swap-off'\nconst dSwapOn = 'd-swap-on'\nconst dDropdown = 'd-dropdown'\nconst dDropdownEnd = 'd-dropdown-end'\nconst dDropdownContent = 'd-dropdown-content'\nconst dBtn = 'd-btn'\nconst dBtnSm = 'd-btn-sm'\nconst dBtnBlock = 'd-btn-block'\nconst dBtnGhost = 'd-btn-ghost'\nconst dToggle = 'd-toggle'\nconst dToggleXs = 'd-toggle-xs'\nconst dToggleSm = 'd-toggle-sm'\nconst dToggleMd = 'd-toggle-md'\nconst dToggleLg = 'd-toggle-lg'\nconst dToggleXl = 'd-toggle-xl'\n\nexport interface ThemeControllerSwapProps {\n lightTheme?: string\n darkTheme?: string\n onChange?: (theme: string) => void\n className?: string\n}\n\nexport interface ThemeControllerDropdownProps {\n themes: string[]\n defaultTheme?: string\n onChange?: (theme: string) => void\n className?: string\n}\n\nexport interface ThemeControllerToggleProps {\n lightTheme?: string\n darkTheme?: string\n onChange?: (theme: string) => void\n size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl'\n className?: string\n}\n\n// Get current theme from document\nfunction getCurrentTheme(): string | null {\n return document.documentElement.getAttribute('data-theme')\n}\n\n// Set theme directly on document (fallback when no ThemeProvider)\nfunction setThemeDirectly(theme: string) {\n document.documentElement.setAttribute('data-theme', theme)\n}\n\nfunction ThemeControllerSwap({\n lightTheme = 'light',\n darkTheme = 'dark',\n onChange,\n className = '',\n}: ThemeControllerSwapProps) {\n const { setTheme: contextSetTheme, isDark: contextIsDark } = useTheme()\n const setTheme = contextSetTheme ?? setThemeDirectly\n\n const [isDark, setIsDark] = useState(() => {\n if (contextIsDark !== undefined) return contextIsDark\n const current = getCurrentTheme()\n return current === darkTheme\n })\n\n // Sync with context or external theme changes\n useEffect(() => {\n if (contextIsDark !== undefined) {\n setIsDark(contextIsDark)\n return\n }\n const observer = new MutationObserver(() => {\n const current = getCurrentTheme()\n setIsDark(current === darkTheme)\n })\n observer.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme'] })\n return () => observer.disconnect()\n }, [darkTheme, contextIsDark])\n\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n const checked = e.target.checked\n const theme = checked ? darkTheme : lightTheme\n setTheme(theme)\n onChange?.(theme)\n }\n\n return (\n <label className={`${dSwap} ${dSwapRotate} ${className}`}>\n <input\n type=\"checkbox\"\n checked={isDark}\n onChange={handleChange}\n />\n {/* sun icon */}\n <svg\n className={`${dSwapOff} h-8 w-8 fill-current`}\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n >\n <path d=\"M5.64,17l-.71.71a1,1,0,0,0,0,1.41,1,1,0,0,0,1.41,0l.71-.71A1,1,0,0,0,5.64,17ZM5,12a1,1,0,0,0-1-1H3a1,1,0,0,0,0,2H4A1,1,0,0,0,5,12Zm7-7a1,1,0,0,0,1-1V3a1,1,0,0,0-2,0V4A1,1,0,0,0,12,5ZM5.64,7.05a1,1,0,0,0,.7.29,1,1,0,0,0,.71-.29,1,1,0,0,0,0-1.41l-.71-.71A1,1,0,0,0,4.93,6.34Zm12,.29a1,1,0,0,0,.7-.29l.71-.71a1,1,0,1,0-1.41-1.41L17,5.64a1,1,0,0,0,0,1.41A1,1,0,0,0,17.66,7.34ZM21,11H20a1,1,0,0,0,0,2h1a1,1,0,0,0,0-2Zm-9,8a1,1,0,0,0-1,1v1a1,1,0,0,0,2,0V20A1,1,0,0,0,12,19ZM18.36,17A1,1,0,0,0,17,18.36l.71.71a1,1,0,0,0,1.41,0,1,1,0,0,0,0-1.41ZM12,6.5A5.5,5.5,0,1,0,17.5,12,5.51,5.51,0,0,0,12,6.5Zm0,9A3.5,3.5,0,1,1,15.5,12,3.5,3.5,0,0,1,12,15.5Z\" />\n </svg>\n {/* moon icon */}\n <svg\n className={`${dSwapOn} h-8 w-8 fill-current`}\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n >\n <path d=\"M21.64,13a1,1,0,0,0-1.05-.14,8.05,8.05,0,0,1-3.37.73A8.15,8.15,0,0,1,9.08,5.49a8.59,8.59,0,0,1,.25-2A1,1,0,0,0,8,2.36,10.14,10.14,0,1,0,22,14.05,1,1,0,0,0,21.64,13Zm-9.5,6.69A8.14,8.14,0,0,1,7.08,5.22v.27A10.15,10.15,0,0,0,17.22,15.63a9.79,9.79,0,0,0,2.1-.22A8.11,8.11,0,0,1,12.14,19.73Z\" />\n </svg>\n </label>\n )\n}\n\nfunction ThemeControllerDropdown({\n themes,\n defaultTheme,\n onChange,\n className = '',\n}: ThemeControllerDropdownProps) {\n const { setTheme: contextSetTheme, resolvedTheme } = useTheme()\n const setTheme = contextSetTheme ?? setThemeDirectly\n const radioName = useId()\n\n const [selectedTheme, setSelectedTheme] = useState(() => {\n if (resolvedTheme && themes.includes(resolvedTheme)) return resolvedTheme\n const current = getCurrentTheme()\n if (current && themes.includes(current)) return current\n return defaultTheme || themes[0] || 'light'\n })\n\n // Sync with context or external theme changes\n useEffect(() => {\n if (resolvedTheme && themes.includes(resolvedTheme)) {\n setSelectedTheme(resolvedTheme)\n return\n }\n const observer = new MutationObserver(() => {\n const current = getCurrentTheme()\n if (current && themes.includes(current)) {\n setSelectedTheme(current)\n }\n })\n observer.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme'] })\n return () => observer.disconnect()\n }, [themes, resolvedTheme])\n\n const handleChange = (theme: string) => {\n setSelectedTheme(theme)\n setTheme(theme)\n onChange?.(theme)\n }\n\n return (\n <div className={`${dDropdown} ${dDropdownEnd} ${className}`}>\n <div tabIndex={0} role=\"button\" className={dBtn}>\n Theme\n <svg\n width=\"12px\"\n height=\"12px\"\n className=\"inline-block h-2 w-2 fill-current opacity-60\"\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 2048 2048\"\n >\n <path d=\"M1799 349l242 241-1017 1017L7 590l242-241 775 775 775-775z\"></path>\n </svg>\n </div>\n <ul\n tabIndex={0}\n className={`${dDropdownContent} bg-base-300 rounded-box z-[1] w-52 p-2 shadow-2xl max-h-96 overflow-y-auto`}\n >\n {themes.map((theme) => (\n <li key={theme}>\n <input\n type=\"radio\"\n name={radioName}\n className={`${dBtn} ${dBtnSm} ${dBtnBlock} ${dBtnGhost} justify-start`}\n aria-label={theme}\n value={theme}\n checked={selectedTheme === theme}\n onChange={() => handleChange(theme)}\n />\n </li>\n ))}\n </ul>\n </div>\n )\n}\n\nconst sizeClasses: Record<string, string> = {\n xs: dToggleXs,\n sm: dToggleSm,\n md: dToggleMd,\n lg: dToggleLg,\n xl: dToggleXl,\n}\n\nfunction ThemeControllerToggle({\n lightTheme = 'light',\n darkTheme = 'dark',\n onChange,\n size,\n className = '',\n}: ThemeControllerToggleProps) {\n const { componentSize } = useConfig()\n const { setTheme: contextSetTheme, isDark: contextIsDark } = useTheme()\n const setTheme = contextSetTheme ?? setThemeDirectly\n const effectiveSize = size ?? componentSize ?? 'md'\n\n const [isDark, setIsDark] = useState(() => {\n if (contextIsDark !== undefined) return contextIsDark\n const current = getCurrentTheme()\n return current === darkTheme\n })\n\n // Sync with context or external theme changes\n useEffect(() => {\n if (contextIsDark !== undefined) {\n setIsDark(contextIsDark)\n return\n }\n const observer = new MutationObserver(() => {\n const current = getCurrentTheme()\n setIsDark(current === darkTheme)\n })\n observer.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme'] })\n return () => observer.disconnect()\n }, [darkTheme, contextIsDark])\n\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n const checked = e.target.checked\n const theme = checked ? darkTheme : lightTheme\n setTheme(theme)\n onChange?.(theme)\n }\n\n return (\n <input\n type=\"checkbox\"\n className={`${dToggle} ${sizeClasses[effectiveSize]} ${className}`}\n checked={isDark}\n onChange={handleChange}\n aria-label=\"Toggle theme\"\n />\n )\n}\n\nexport const ThemeController = Object.assign(\n {},\n {\n Swap: ThemeControllerSwap,\n Dropdown: ThemeControllerDropdown,\n Toggle: ThemeControllerToggle,\n }\n)\n"],"names":["dSwap","dSwapRotate","dSwapOff","dSwapOn","dDropdown","dDropdownEnd","dDropdownContent","dBtn","dBtnSm","dBtnBlock","dBtnGhost","dToggle","dToggleXs","dToggleSm","dToggleMd","dToggleLg","dToggleXl","getCurrentTheme","setThemeDirectly","theme","ThemeControllerSwap","lightTheme","darkTheme","onChange","className","contextSetTheme","contextIsDark","useTheme","setTheme","isDark","setIsDark","useState","useEffect","observer","current","handleChange","e","jsxs","jsx","ThemeControllerDropdown","themes","defaultTheme","resolvedTheme","radioName","useId","selectedTheme","setSelectedTheme","sizeClasses","ThemeControllerToggle","size","componentSize","useConfig","effectiveSize","ThemeController"],"mappings":";;;;AAKA,MAAMA,IAAQ,UACRC,IAAc,iBACdC,IAAW,cACXC,IAAU,aACVC,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AAA,EACpC,CAAA;AAAA,EACA;AAAA,IACE,MAAMjC;AAAA,IACN,UAAUmB;AAAA,IACV,QAAQS;AAAA,EAAA;AAEZ;"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
export interface ThemeProviderProps {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
/** Default theme. Use "system" to follow browser preference. */
|
|
5
|
+
defaultTheme?: string;
|
|
6
|
+
/** localStorage key for persisting theme. Set to false to disable persistence. */
|
|
7
|
+
storageKey?: string | false;
|
|
8
|
+
/** Light theme to use when system preference is light */
|
|
9
|
+
lightTheme?: string;
|
|
10
|
+
/** Dark theme to use when system preference is dark */
|
|
11
|
+
darkTheme?: string;
|
|
12
|
+
/** Custom function to determine if a theme is dark */
|
|
13
|
+
isDarkTheme?: (theme: string) => boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface ThemeColors {
|
|
16
|
+
background: string;
|
|
17
|
+
foreground: string;
|
|
18
|
+
primary: string;
|
|
19
|
+
primaryContent: string;
|
|
20
|
+
secondary: string;
|
|
21
|
+
accent: string;
|
|
22
|
+
info: string;
|
|
23
|
+
success: string;
|
|
24
|
+
warning: string;
|
|
25
|
+
error: string;
|
|
26
|
+
}
|
|
27
|
+
export interface ThemeContextValue {
|
|
28
|
+
/** The theme setting (what user selected: "system", "light", "dark", etc.) */
|
|
29
|
+
theme: string;
|
|
30
|
+
/** The actual applied theme after resolving "system" */
|
|
31
|
+
resolvedTheme: string;
|
|
32
|
+
/** Whether the resolved theme is dark */
|
|
33
|
+
isDark: boolean;
|
|
34
|
+
/** Set the theme */
|
|
35
|
+
setTheme: (theme: string) => void;
|
|
36
|
+
/** Computed theme colors as hex values (for canvas/non-CSS contexts) */
|
|
37
|
+
colors: ThemeColors;
|
|
38
|
+
/** The system preference ("light" or "dark") */
|
|
39
|
+
systemTheme: 'light' | 'dark';
|
|
40
|
+
}
|
|
41
|
+
export declare function ThemeProvider({ children, defaultTheme, storageKey, lightTheme, darkTheme, isDarkTheme, }: ThemeProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
42
|
+
/**
|
|
43
|
+
* Hook to access theme context.
|
|
44
|
+
* Must be used within a ThemeProvider.
|
|
45
|
+
*/
|
|
46
|
+
export declare function useThemeContext(): ThemeContextValue;
|
|
47
|
+
/**
|
|
48
|
+
* Check if ThemeProvider is present in the tree.
|
|
49
|
+
*/
|
|
50
|
+
export declare function useHasThemeProvider(): boolean;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { jsx as E } from "react/jsx-runtime";
|
|
2
|
+
import { useState as d, useMemo as m, useCallback as k, useEffect as l, createContext as P, useContext as v } from "react";
|
|
3
|
+
const A = /* @__PURE__ */ new Set([
|
|
4
|
+
"dark",
|
|
5
|
+
"synthwave",
|
|
6
|
+
"halloween",
|
|
7
|
+
"forest",
|
|
8
|
+
"black",
|
|
9
|
+
"luxury",
|
|
10
|
+
"dracula",
|
|
11
|
+
"business",
|
|
12
|
+
"night",
|
|
13
|
+
"coffee",
|
|
14
|
+
"dim",
|
|
15
|
+
"sunset"
|
|
16
|
+
]), h = P(void 0);
|
|
17
|
+
function L(t) {
|
|
18
|
+
if (typeof document > "u") return "#000000";
|
|
19
|
+
const e = document.createElement("canvas");
|
|
20
|
+
e.width = e.height = 1;
|
|
21
|
+
const n = e.getContext("2d");
|
|
22
|
+
if (!n) return "#000000";
|
|
23
|
+
n.fillStyle = t, n.fillRect(0, 0, 1, 1);
|
|
24
|
+
const [f, o, i] = n.getImageData(0, 0, 1, 1).data;
|
|
25
|
+
return `#${((1 << 24) + (f << 16) + (o << 8) + i).toString(16).slice(1)}`;
|
|
26
|
+
}
|
|
27
|
+
function b() {
|
|
28
|
+
if (typeof document > "u")
|
|
29
|
+
return {
|
|
30
|
+
background: "#ffffff",
|
|
31
|
+
foreground: "#000000",
|
|
32
|
+
primary: "#6366f1",
|
|
33
|
+
primaryContent: "#ffffff",
|
|
34
|
+
secondary: "#f000b8",
|
|
35
|
+
accent: "#37cdbe",
|
|
36
|
+
info: "#3abff8",
|
|
37
|
+
success: "#36d399",
|
|
38
|
+
warning: "#fbbd23",
|
|
39
|
+
error: "#f87272"
|
|
40
|
+
};
|
|
41
|
+
const t = getComputedStyle(document.documentElement), e = (n, f) => {
|
|
42
|
+
const o = t.getPropertyValue(n).trim();
|
|
43
|
+
return o ? L(o) : f;
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
background: e("--color-base-100", "#ffffff"),
|
|
47
|
+
foreground: e("--color-base-content", "#000000"),
|
|
48
|
+
primary: e("--color-primary", "#6366f1"),
|
|
49
|
+
primaryContent: e("--color-primary-content", "#ffffff"),
|
|
50
|
+
secondary: e("--color-secondary", "#f000b8"),
|
|
51
|
+
accent: e("--color-accent", "#37cdbe"),
|
|
52
|
+
info: e("--color-info", "#3abff8"),
|
|
53
|
+
success: e("--color-success", "#36d399"),
|
|
54
|
+
warning: e("--color-warning", "#fbbd23"),
|
|
55
|
+
error: e("--color-error", "#f87272")
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function M() {
|
|
59
|
+
return typeof window > "u" ? "light" : window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
60
|
+
}
|
|
61
|
+
function H(t) {
|
|
62
|
+
if (!t || typeof window > "u") return null;
|
|
63
|
+
try {
|
|
64
|
+
return localStorage.getItem(t);
|
|
65
|
+
} catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function I(t, e) {
|
|
70
|
+
if (!(!t || typeof window > "u"))
|
|
71
|
+
try {
|
|
72
|
+
localStorage.setItem(t, e);
|
|
73
|
+
} catch {
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function F({
|
|
77
|
+
children: t,
|
|
78
|
+
defaultTheme: e = "system",
|
|
79
|
+
storageKey: n = "asterui-theme",
|
|
80
|
+
lightTheme: f = "light",
|
|
81
|
+
darkTheme: o = "dark",
|
|
82
|
+
isDarkTheme: i
|
|
83
|
+
}) {
|
|
84
|
+
const [u, w] = d(() => H(n) || e), [a, C] = d(M), c = m(() => u === "system" ? a === "dark" ? o : f : u, [u, a, f, o]), g = m(() => i ? i(c) : A.has(c), [c, i]), [y, S] = d(b), p = k((r) => {
|
|
85
|
+
w(r), I(n, r);
|
|
86
|
+
}, [n]);
|
|
87
|
+
l(() => {
|
|
88
|
+
typeof document > "u" || (document.documentElement.setAttribute("data-theme", c), requestAnimationFrame(() => {
|
|
89
|
+
requestAnimationFrame(() => {
|
|
90
|
+
S(b());
|
|
91
|
+
});
|
|
92
|
+
}));
|
|
93
|
+
}, [c]), l(() => {
|
|
94
|
+
if (typeof window > "u") return;
|
|
95
|
+
const r = window.matchMedia("(prefers-color-scheme: dark)"), s = (T) => {
|
|
96
|
+
C(T.matches ? "dark" : "light");
|
|
97
|
+
};
|
|
98
|
+
return r.addEventListener("change", s), () => r.removeEventListener("change", s);
|
|
99
|
+
}, []), l(() => {
|
|
100
|
+
if (!n || typeof window > "u") return;
|
|
101
|
+
const r = (s) => {
|
|
102
|
+
s.key === n && s.newValue && w(s.newValue);
|
|
103
|
+
};
|
|
104
|
+
return window.addEventListener("storage", r), () => window.removeEventListener("storage", r);
|
|
105
|
+
}, [n]);
|
|
106
|
+
const x = m(() => ({
|
|
107
|
+
theme: u,
|
|
108
|
+
resolvedTheme: c,
|
|
109
|
+
isDark: g,
|
|
110
|
+
setTheme: p,
|
|
111
|
+
colors: y,
|
|
112
|
+
systemTheme: a
|
|
113
|
+
}), [u, c, g, p, y, a]);
|
|
114
|
+
return /* @__PURE__ */ E(h.Provider, { value: x, children: t });
|
|
115
|
+
}
|
|
116
|
+
function R() {
|
|
117
|
+
const t = v(h);
|
|
118
|
+
if (!t)
|
|
119
|
+
throw new Error("useThemeContext must be used within a ThemeProvider");
|
|
120
|
+
return t;
|
|
121
|
+
}
|
|
122
|
+
function j() {
|
|
123
|
+
return v(h) !== void 0;
|
|
124
|
+
}
|
|
125
|
+
export {
|
|
126
|
+
F as ThemeProvider,
|
|
127
|
+
j as useHasThemeProvider,
|
|
128
|
+
R as useThemeContext
|
|
129
|
+
};
|
|
130
|
+
//# sourceMappingURL=ThemeProvider.js.map
|