@@ -9,9 +9,6 @@ export function useThemeHook() {
99 const themeContext = useContext ( ThemeContext ) ;
1010
1111
12- const [ additionalColors , setAdditionalColors ] = useState < Record < string , string > > ( { } ) ;
13-
14-
1512 const {
1613 isDarkTheme = false ,
1714 toggleTheme = ( ) => { } ,
@@ -53,22 +50,27 @@ export function useThemeHook() {
5350
5451
5552 const hexToRgba = useCallback ( ( hex : string , opacity : number ) : string => {
53+ if ( ! hex || typeof hex !== 'string' ) return `rgba(0, 0, 0, ${ opacity } )` ;
5654 hex = hex . replace ( '#' , '' ) ;
55+
56+ if ( ! [ 3 , 6 ] . includes ( hex . length ) ) return `rgba(0, 0, 0, ${ opacity } )` ;
57+
5758 let r = 0 , g = 0 , b = 0 ;
5859
5960 if ( hex . length === 3 ) {
6061 r = parseInt ( hex [ 0 ] + hex [ 0 ] , 16 ) ;
6162 g = parseInt ( hex [ 1 ] + hex [ 1 ] , 16 ) ;
6263 b = parseInt ( hex [ 2 ] + hex [ 2 ] , 16 ) ;
6364 } else if ( hex . length === 6 ) {
64- r = parseInt ( hex . substr ( 0 , 2 ) , 16 ) ;
65- g = parseInt ( hex . substr ( 2 , 2 ) , 16 ) ;
66- b = parseInt ( hex . substr ( 4 , 2 ) , 16 ) ;
65+ r = parseInt ( hex . substring ( 0 , 2 ) , 16 ) ;
66+ g = parseInt ( hex . substring ( 2 , 4 ) , 16 ) ;
67+ b = parseInt ( hex . substring ( 4 , 6 ) , 16 ) ;
6768 }
6869
6970 return `rgba(${ r } , ${ g } , ${ b } , ${ opacity } )` ;
7071 } , [ ] ) ;
7172
73+
7274
7375 const getCustomColor = useCallback ( ( colorName : string , opacity : number = 1 ) : string => {
7476 if ( typeof window === "undefined" ) return '#000000' ;
@@ -84,7 +86,7 @@ export function useThemeHook() {
8486 return hexToRgba ( colorValue , opacity ) ;
8587 } , [ hexToRgba ] ) ;
8688
87- // Função para obter cores de rede com opacity
89+
8890 const getNetworkColorWithOpacity = useCallback ( (
8991 colorType : 'primary' | 'secondary' | 'light' | 'dark' = 'primary' ,
9092 opacity : number = 1
0 commit comments