{"version":3,"file":"Dark_toggle.Ds2ETK7V.mjs","names":["React.useState"],"sources":["https:/framerusercontent.com/modules/vo9hZPt9hBHFE5phb6YR/GWMe0K8uO81eG8eSnntK/Dark_toggle.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import*as React from\"react\";import{Frame,addPropertyControls,ControlType}from\"framer\";//Stores theme in local storage ⬇︎\nfunction getStoredTheme(){return localStorage.getItem(\"currentToggleState\");}//Detect's system theme automatically ⬇︎\nfunction SystemThemeDetector({onThemeDetected}){const[systemTheme,setSystemTheme]=React.useState(null);const[errorMessage,setErrorMessage]=React.useState(null);React.useEffect(()=>{const darkModeMediaQuery=window.matchMedia(\"(prefers-color-scheme: dark)\");const handleThemeChange=e=>{const theme=e.matches?\"dark\":\"light\";setSystemTheme(theme);setErrorMessage(null);onThemeDetected(theme);};try{if(darkModeMediaQuery.media===\"not all\"){setErrorMessage(\"System theme detection not supported\");onThemeDetected(null);}else{handleThemeChange(darkModeMediaQuery);darkModeMediaQuery.addEventListener(\"change\",handleThemeChange);}}catch(error){setErrorMessage(\"Error detecting system theme\");onThemeDetected(null);}return()=>{darkModeMediaQuery.removeEventListener(\"change\",handleThemeChange);};},[onThemeDetected]);return null;}//Theme Switch Component ⬇︎\nexport function ThemeSwitch({backgroundColor,switchSize,circleColor}){const[isOn,setIsOn]=React.useState(false);const[isThemeSet,setIsThemeSet]=React.useState(false);const[systemTheme,setSystemTheme]=React.useState(null);//When clicked, it toggles between light/dark mode and saves it to local storage ⬇︎\nconst toggle=()=>{const newToggleState=isOn?\"dark\":\"light\";setIsOn(!isOn);localStorage.setItem(\"currentToggleState\",newToggleState);updateTheme(newToggleState);};//Modifies CSS and applies theme style ⬇︎\nconst updateTheme=theme=>{if(typeof document!==\"undefined\"){const styleTag=document.getElementsByTagName(\"style\")[0];const newCSS=styleTag.innerHTML.replace(/prefers-color-scheme: \\w+/,`prefers-color-scheme: ${theme}`);styleTag.innerHTML=newCSS;}window.dispatchEvent(new CustomEvent(\"themeChange\"));};const handleSystemThemeChange=theme=>{setSystemTheme(theme);if(!isThemeSet){setIsOn(theme===\"dark\");updateTheme(theme);setIsThemeSet(true);}};//Checks if the user previously selected a theme and ensures the correct theme is set on initial load ⬇︎\nReact.useEffect(()=>{const storedTheme=getStoredTheme();if(storedTheme){setIsOn(storedTheme===\"light\");updateTheme(storedTheme);setIsThemeSet(true);}else{const systemTheme=window.matchMedia(\"(prefers-color-scheme: dark)\").matches?\"dark\":\"light\";setIsOn(systemTheme===\"dark\");updateTheme(systemTheme);setIsThemeSet(true);}},[]);//This formula dynamically scales the circle's size based on the switchSize to maintain a balanced look ⬇︎\nconst circleSize=switchSize/1.75-switchSize/8;//Renders the switch with a customizable size and background ⬇︎\nreturn /*#__PURE__*/_jsx(Frame,{width:switchSize,height:switchSize/1.75,background:\"rgba(217, 217, 217, 0.2)\",style:{borderRadius:switchSize/3,cursor:\"pointer\",position:\"relative\",display:\"flex\",alignItems:\"center\",justifyContent:\"space-between\",padding:`0 ${switchSize/8}px`},onClick:toggle,children:isThemeSet&&// Uses Framer Motion animation to smoothly move the circle when toggled ⬇︎\n/*#__PURE__*/_jsx(Frame,{width:circleSize,height:circleSize,background:circleColor,style:{borderRadius:\"50%\",position:\"absolute\",left:isOn?`calc(100% - ${circleSize+switchSize/16}px)`:`${switchSize/16}px`,transition:\"left 0.2s\",display:\"flex\",alignItems:\"center\",justifyContent:\"center\",boxShadow:\"2px 2px 4px 0px rgba(0, 0, 0, 0.15)\"},initial:false,animate:{left:isOn?`calc(100% - ${circleSize+switchSize/16}px)`:`${switchSize/16}px`},children:/*#__PURE__*/_jsx(Frame,{background:\"transparent\",style:{overflow:\"hidden\"}})})});}// Sets default colors and sizes if the user doesn't override them ⬇︎\nThemeSwitch.defaultProps={backgroundColor:\"rgba(217, 217, 217, 0.2)\",switchSize:70,circleColor:\"#ffffff\"};//This adds custom controls to Framer UI so designers can tweak bg color, switch size, circle color ⬇︎\naddPropertyControls(ThemeSwitch,{backgroundColor:{title:\"Background Color\",type:ControlType.Color,defaultValue:\"rgba(217, 217, 217, 0.2)\"},switchSize:{title:\"Switch Size\",type:ControlType.Number,defaultValue:67,min:20,max:200,step:1},circleColor:{title:\"Circle Color\",type:ControlType.Color,defaultValue:\"#ffffff\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"ThemeSwitch\":{\"type\":\"reactComponent\",\"name\":\"ThemeSwitch\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Dark_toggle.map"],"mappings":"sMACA,SAAS,GAAgB,CAAC,OAAO,aAAa,QAAQ,oBAAoB,CAAE,CAE5E,SAAgB,EAAY,CAAC,kBAAgB,aAAW,eAAa,CAAC,GAAK,CAAC,EAAK,GAASA,EAAe,EAAK,EAAO,CAAC,EAAW,GAAeA,EAAe,EAAK,EAAO,CAAC,EAAY,GAAgBA,EAAe,IAAI,EACrN,MAAW,CAAC,IAAM,EAAe,EAAK,OAAO,QAAQ,EAAQ,CAAC,CAAI,EAAE,aAAa,QAAQ,qBAAqB,CAAc,EAAE,EAAY,CAAc,CAAE,EAC1J,EAAY,GAAO,CAAC,GAAG,OAAO,SAAW,IAAY,CAAC,IAAM,EAAS,SAAS,qBAAqB,OAAO,CAAC,CAAC,GAAyG,EAAS,UAAlG,EAAS,UAAU,QAAQ,4BAA4B,yBAAyB,GAAiC,CAAE,CAAC,EAAO,cAAc,IAAI,YAAY,aAAa,CAAC,CAAE,EAC3S,MAAoB,CAAC,IAAM,EAAY,EAAe,EAAE,GAAG,EAAa,EAAQ,IAAc,OAAO,EAAE,EAAY,CAAW,EAAE,EAAc,EAAI,MAAO,CAAC,IAAM,EAAY,EAAO,WAAW,8BAA8B,CAAC,CAAC,QAAQ,OAAO,QAAQ,EAAQ,IAAc,MAAM,EAAE,EAAY,CAAW,EAAE,EAAc,EAAI,CAAE,CAAC,EAAE,CAAC,CAAC,EACrU,IAAM,EAAW,EA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