{"version":3,"file":"RadioToggleButton.C3ihpDFI.mjs","names":["useRef","useState","shouldBeChecked","_Fragment"],"sources":["https:/framerusercontent.com/modules/vf4gCpzz1ZalFNox0Bz3/7xEijq0rTF2GFVXFS61i/RadioToggleButton.js"],"sourcesContent":["// Erstelle eine Framer-Komponente in React + TypeScript namens \"RadioToggleButton\",\n// die in Framer-Formulare eingebettet werden kann.\n//\n// Ziel: Ein anklickbarer, wieder abwählbarer Radio-Button,\n// dessen gewählter Wert beim Absenden eines Framer-Formulars mitgeschickt wird.\nimport{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from\"react/jsx-runtime\";import{useState,useEffect,useRef,startTransition,createContext}from\"react\";import{motion}from\"framer-motion\";import{addPropertyControls,ControlType}from\"framer\";const RadioGroupContext=/*#__PURE__*/createContext(null);// Globaler State für Radio-Gruppen (außerhalb von React-Komponenten)\nconst radioGroups=new Map;const radioListeners=new Map;function subscribeToGroup(name,callback){if(!radioListeners.has(name)){radioListeners.set(name,new Set);}radioListeners.get(name)?.add(callback);return()=>{radioListeners.get(name)?.delete(callback);};}function setGroupValue(name,value){radioGroups.set(name,value);radioListeners.get(name)?.forEach(callback=>callback(value));}function getGroupValue(name){return radioGroups.get(name)??null;}/**\n * Radio Toggle Button\n *\n * Ein anklickbarer Radio-Button für Framer-Formulare.\n * Buttons mit gleichem Namen schließen sich gegenseitig aus.\n * Erneutes Klicken deaktiviert den Button.\n *\n * @framerSupportedLayoutWidth any\n * @framerSupportedLayoutHeight any\n */export default function RadioToggleButton(props){const{name,value,label,variant=\"button\",required=false,defaultChecked=false,onChange,activeBackground=\"#111111\",activeText=\"#FFFFFF\",inactiveBackground=\"transparent\",inactiveText=\"#111111\",borderColor=\"#CCCCCC\",borderRadius=8,font,links=[],linkColor=\"#0070f3\",errorColor=\"#dd0000\"}=props;const inputRef=useRef(null);const[isChecked,setIsChecked]=useState(defaultChecked);const[hasError,setHasError]=useState(false);// Initialisierung: Wenn defaultChecked, setze diesen Button als aktiv in der Gruppe\nuseEffect(()=>{if(defaultChecked){setGroupValue(name,value);}},[]);// Synchronisiere mit der Gruppe\nuseEffect(()=>{const currentGroupValue=getGroupValue(name);const shouldBeChecked=currentGroupValue===value;if(shouldBeChecked!==isChecked){startTransition(()=>{setIsChecked(shouldBeChecked);if(inputRef.current){inputRef.current.checked=shouldBeChecked;}});}// Abonniere Änderungen in der Gruppe\nconst unsubscribe=subscribeToGroup(name,newValue=>{const shouldBeChecked=newValue===value;startTransition(()=>{setIsChecked(shouldBeChecked);if(inputRef.current){inputRef.current.checked=shouldBeChecked;}});});return unsubscribe;},[name,value,isChecked]);const handleClick=()=>{const newCheckedState=!isChecked;if(newCheckedState){// Aktiviere diesen Button und deaktiviere alle anderen in der Gruppe\nsetGroupValue(name,value);}else{// Deaktiviere diesen Button (kein Button in der Gruppe ist aktiv)\nsetGroupValue(name,null);}startTransition(()=>{setIsChecked(newCheckedState);setHasError(false)// Reset error state on click\n;if(inputRef.current){inputRef.current.checked=newCheckedState;}});onChange?.(newCheckedState);};// Form validation handler\nuseEffect(()=>{const input=inputRef.current;if(!input)return;const handleInvalid=e=>{e.preventDefault();// Nur Fehler anzeigen, wenn das Formular bereits validiert wurde\nconst form=input.form||input.closest(\"form\");const validated=form?.getAttribute(\"data-validated\")===\"true\";if(!validated){// Erste \"stille\" Checks (z.B. beim Laden / Tippen) ignorieren\nreturn;}startTransition(()=>{setHasError(true);});};input.addEventListener(\"invalid\",handleInvalid);return()=>{input.removeEventListener(\"invalid\",handleInvalid);};},[]);const textColor=hasError?errorColor:isChecked?activeText:inactiveText;// Helper function to render label with links\nconst renderLabelWithLinks=()=>{if(!links||links.length===0){return /*#__PURE__*/_jsxs(_Fragment,{children:[label,required&&/*#__PURE__*/_jsx(\"span\",{style:{marginLeft:4},children:\"*\"})]});}let remainingText=label;const parts=[];links.forEach(link=>{const index=remainingText.indexOf(link.word);if(index!==-1){// Add text before the link\nif(index>0){parts.push({text:remainingText.substring(0,index)});}// Add the link\nparts.push({text:link.word,url:link.url});// Update remaining text\nremainingText=remainingText.substring(index+link.word.length);}});// Add any remaining text\nif(remainingText){parts.push({text:remainingText});}return /*#__PURE__*/_jsxs(_Fragment,{children:[parts.map((part,index)=>{if(part.url){return /*#__PURE__*/_jsx(\"a\",{href:part.url,target:\"_blank\",rel:\"noopener noreferrer\",onClick:e=>e.stopPropagation(),style:{color:linkColor,textDecoration:\"underline\"},children:part.text},index);}return /*#__PURE__*/_jsx(\"span\",{children:part.text},index);}),required&&/*#__PURE__*/_jsx(\"span\",{style:{marginLeft:4},children:\"*\"})]});};// Checkbox variant rendering\nif(variant===\"checkbox\"){return /*#__PURE__*/_jsxs(motion.label,{onClick:handleClick,initial:false,animate:hasError?{x:[0,-4,4,-4,4,0],color:textColor}:{color:textColor},transition:{duration:hasError?.4:.3,ease:\"easeInOut\"},style:{width:\"100%\",height:\"100%\",display:\"inline-flex\",alignItems:\"flex-start\",gap:10,cursor:\"pointer\",userSelect:\"none\",...font},children:[/*#__PURE__*/_jsx(\"input\",{ref:inputRef,type:\"checkbox\",name:name,value:value,defaultChecked:defaultChecked,required:required,\"aria-invalid\":hasError,style:{position:\"absolute\",opacity:0,pointerEvents:\"none\",width:0,height:0},tabIndex:-1,\"aria-hidden\":\"true\"}),/*#__PURE__*/_jsx(motion.div,{animate:{backgroundColor:isChecked?activeBackground:inactiveBackground,\"--borderColor\":isChecked?activeBackground:borderColor},transition:{duration:.25,ease:\"easeInOut\"},style:{width:20,height:20,borderRadius:4,borderStyle:\"solid\",borderWidth:2,borderColor:\"var(--borderColor)\",display:\"flex\",alignItems:\"center\",justifyContent:\"center\",flexShrink:0},children:isChecked&&/*#__PURE__*/_jsx(motion.svg,{initial:{scale:0},animate:{scale:1},transition:{duration:.2,ease:\"backOut\"},width:\"12\",height:\"12\",viewBox:\"0 0 12 12\",fill:\"none\",children:/*#__PURE__*/_jsx(\"path\",{d:\"M2 6L5 9L10 3\",stroke:activeText,strokeWidth:\"2\",strokeLinecap:\"round\",strokeLinejoin:\"round\"})})}),/*#__PURE__*/_jsx(\"span\",{style:{width:\"100%\"},children:renderLabelWithLinks()})]});}// Button variant rendering (default)\nreturn /*#__PURE__*/_jsxs(motion.button,{type:\"button\",onClick:handleClick,initial:false,animate:hasError?{backgroundColor:isChecked?activeBackground:inactiveBackground,color:textColor,borderColor:errorColor,x:[0,-4,4,-4,4,0]}:{backgroundColor:isChecked?activeBackground:inactiveBackground,color:textColor,borderColor:isChecked?activeBackground:borderColor},transition:{duration:hasError?.4:.2,ease:\"easeInOut\"},style:{position:\"relative\",width:\"100%\",height:\"100%\",display:\"inline-flex\",alignItems:\"center\",justifyContent:\"center\",padding:\"12px 20px\",borderRadius:borderRadius,border:\"2px solid\",cursor:\"pointer\",outline:\"none\",userSelect:\"none\",overflow:\"visible\",...font},whileTap:{scale:.98},children:[/*#__PURE__*/_jsx(\"input\",{ref:inputRef,type:\"radio\",name:name,value:value,defaultChecked:defaultChecked,required:required,\"aria-invalid\":hasError,style:{position:\"absolute\",opacity:0,pointerEvents:\"none\",width:0,height:0},tabIndex:-1,\"aria-hidden\":\"true\"}),/*#__PURE__*/_jsx(\"span\",{children:renderLabelWithLinks()})]});}addPropertyControls(RadioToggleButton,{name:{type:ControlType.String,title:\"Name\",defaultValue:\"option\",description:\"Formularfeld-Name (Buttons mit gleichem Namen bilden eine Gruppe)\"},value:{type:ControlType.String,title:\"Value\",defaultValue:\"option1\",description:\"Wert, der beim Submit \\xfcbermittelt wird\"},label:{type:ControlType.String,title:\"Label\",defaultValue:\"Option 1\",description:\"Text auf dem Button\"},links:{type:ControlType.Array,title:\"Links\",control:{type:ControlType.Object,controls:{word:{type:ControlType.String,title:\"Word\",defaultValue:\"Datenschutz\"},url:{type:ControlType.String,title:\"URL\",defaultValue:\"https://example.com/privacy\"}}},defaultValue:[]},linkColor:{type:ControlType.Color,title:\"Link Color\",defaultValue:\"#0070f3\"},variant:{type:ControlType.Enum,title:\"Variant\",options:[\"button\",\"checkbox\"],optionTitles:[\"Button\",\"Checkbox\"],defaultValue:\"button\",displaySegmentedControl:true},required:{type:ControlType.Boolean,title:\"Required\",defaultValue:false,enabledTitle:\"Yes\",disabledTitle:\"No\"},defaultChecked:{type:ControlType.Boolean,title:\"Default Checked\",defaultValue:false,enabledTitle:\"Checked\",disabledTitle:\"Unchecked\"},activeBackground:{type:ControlType.Color,title:\"Active Background\",defaultValue:\"#111111\"},activeText:{type:ControlType.Color,title:\"Active Text\",defaultValue:\"#FFFFFF\"},inactiveBackground:{type:ControlType.Color,title:\"Inactive Background\",defaultValue:\"transparent\"},inactiveText:{type:ControlType.Color,title:\"Inactive Text\",defaultValue:\"#111111\"},borderColor:{type:ControlType.Color,title:\"Border Color\",defaultValue:\"#CCCCCC\"},errorColor:{type:ControlType.Color,title:\"Error Color\",defaultValue:\"#dd0000\"},borderRadius:{type:ControlType.Number,title:\"Border Radius\",defaultValue:8,min:0,max:32,step:1,unit:\"px\",hidden:({variant})=>variant===\"checkbox\"},font:{type:ControlType.Font,title:\"Font\",controls:\"extended\",defaultFontType:\"sans-serif\",defaultValue:{fontSize:\"15px\",variant:\"Medium\",letterSpacing:\"-0.01em\",lineHeight:\"1em\"}}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"RadioToggleButton\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"any\",\"framerSupportedLayoutHeight\":\"any\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./RadioToggleButton.map"],"mappings":"8PAMuD,SAAS,EAAiB,EAAK,EAAS,CAAyG,OAApG,EAAe,IAAI,EAAK,EAAE,EAAe,IAAI,EAAK,IAAI,IAAI,CAAE,EAAe,IAAI,EAAK,EAAE,IAAI,EAAS,KAAW,CAAC,EAAe,IAAI,EAAK,EAAE,OAAO,EAAS,EAAI,SAAS,EAAc,EAAK,EAAM,CAAC,EAAY,IAAI,EAAK,EAAM,CAAC,EA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