Registro y elevación de componentes base (ADN, Scripts, Servicios)

This commit is contained in:
Ricardo Monla
2026-02-15 20:37:53 -03:00
parent 9e9bf62c68
commit c865a7772b
25279 changed files with 3354766 additions and 0 deletions
@@ -0,0 +1,71 @@
import React, { createContext, useContext, useState, useEffect, ReactNode } from 'react'
type Theme = 'light' | 'dark'
interface ThemeContextType {
theme: Theme
toggleTheme: () => void
}
const ThemeContext = createContext<ThemeContextType | undefined>(undefined)
interface ThemeProviderProps {
children: ReactNode
}
export const ThemeProvider: React.FC<ThemeProviderProps> = ({ children }) => {
const [theme, setTheme] = useState<Theme>('dark')
// Load theme from localStorage on mount
useEffect(() => {
const savedTheme = localStorage.getItem('theme') as Theme
if (savedTheme && (savedTheme === 'light' || savedTheme === 'dark')) {
setTheme(savedTheme)
}
}, [])
// Apply theme to document and update CSS variables
useEffect(() => {
const root = document.documentElement
// Remove existing theme classes
root.classList.remove('dark-theme')
// Add current theme class if dark
if (theme === 'dark') {
root.classList.add('dark-theme')
}
// Save to localStorage
localStorage.setItem('theme', theme)
// Update meta theme-color for mobile browsers
const metaThemeColor = document.querySelector('meta[name="theme-color"]')
if (metaThemeColor) {
metaThemeColor.setAttribute('content', theme === 'dark' ? '#0a0a0a' : '#ffffff')
}
}, [theme])
const toggleTheme = () => {
setTheme(prevTheme => prevTheme === 'light' ? 'dark' : 'light')
}
const value: ThemeContextType = {
theme,
toggleTheme
}
return (
<ThemeContext.Provider value={value}>
{children}
</ThemeContext.Provider>
)
}
export const useTheme = (): ThemeContextType => {
const context = useContext(ThemeContext)
if (context === undefined) {
throw new Error('useTheme must be used within a ThemeProvider')
}
return context
}