@@ -3,7 +3,7 @@ import styles from "./switch.module.scss";
33import { useStore } from "../../utils" ;
44import { modes } from "../../constants" ;
55
6- export interface SwitchProps extends HTMLProps < HTMLElement > {
6+ export interface SwitchProps extends HTMLProps < HTMLButtonElement > {
77 /** html tag @defaultValue 'button' */
88 tag ?: "button" | "div" ;
99 /** Diameter of the color switch */
@@ -22,7 +22,13 @@ export interface SwitchProps extends HTMLProps<HTMLElement> {
2222 *
2323 * @source - Source code
2424 */
25- export const Switch = ( { tag : Tag = "button" , size = 24 , skipSystem, ...props } : SwitchProps ) => {
25+ export const Switch = ( {
26+ tag : Tag = "button" ,
27+ size = 24 ,
28+ skipSystem,
29+ children,
30+ ...props
31+ } : SwitchProps ) => {
2632 const [ state , setState ] = useStore ( ) ;
2733 /** toggle mode */
2834 const handleModeSwitch = ( ) => {
@@ -34,11 +40,27 @@ export const Switch = ({ tag: Tag = "button", size = 24, skipSystem, ...props }:
3440 m : modes [ ( index + 1 ) % n ] ,
3541 } ) ;
3642 } ;
37- const className = [ props . className , styles [ "switch" ] ] . filter ( Boolean ) . join ( " " ) ;
43+ if ( children ) {
44+ return (
45+ // @ts -expect-error -- too complex types
46+ < Tag
47+ suppressHydrationWarning
48+ { ...props }
49+ data-testid = "switch"
50+ // skipcq: JS-0417
51+ onClick = { handleModeSwitch } >
52+ { /* @ts -expect-error -> we are setting the CSS variable */ }
53+ < div className = { styles . switch } style = { { "--size" : `${ size } px` } } />
54+ { children }
55+ </ Tag >
56+ ) ;
57+ }
3858 return (
3959 < Tag
60+ // Hydration warning is caused when the data from localStorage differs from the default data provided while rendering on server
61+ suppressHydrationWarning
4062 { ...props }
41- className = { className }
63+ className = { [ props . className , styles . switch ] . join ( " " ) }
4264 // @ts -expect-error -> we are setting the CSS variable
4365 style = { { "--size" : `${ size } px` } }
4466 data-testid = "switch"
0 commit comments