| 
									
										
										
										
											2025-08-14 17:36:11 +03:00
										 |  |  | import type { ComponentChildren } from "preact"; | 
					
						
							| 
									
										
										
										
											2025-08-14 17:53:24 +03:00
										 |  |  | import { useUniqueName } from "./hooks"; | 
					
						
							| 
									
										
										
										
											2025-08-14 17:36:11 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-03 21:18:18 +03:00
										 |  |  | interface FormRadioProps { | 
					
						
							|  |  |  |     name: string; | 
					
						
							|  |  |  |     currentValue?: string; | 
					
						
							|  |  |  |     values: { | 
					
						
							|  |  |  |         value: string; | 
					
						
							| 
									
										
										
										
											2025-08-14 17:36:11 +03:00
										 |  |  |         label: string | ComponentChildren; | 
					
						
							| 
									
										
										
										
											2025-08-03 21:18:18 +03:00
										 |  |  |     }[]; | 
					
						
							|  |  |  |     onChange(newValue: string): void; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default function FormRadioGroup({ name, values, currentValue, onChange }: FormRadioProps) { | 
					
						
							|  |  |  |     return ( | 
					
						
							|  |  |  |         <> | 
					
						
							|  |  |  |             {(values || []).map(({ value, label }) => ( | 
					
						
							|  |  |  |                 <div className="form-check"> | 
					
						
							|  |  |  |                     <label className="form-check-label tn-radio"> | 
					
						
							|  |  |  |                         <input | 
					
						
							|  |  |  |                             className="form-check-input" | 
					
						
							|  |  |  |                             type="radio" | 
					
						
							| 
									
										
										
										
											2025-08-14 17:53:24 +03:00
										 |  |  |                             name={useUniqueName(name)} | 
					
						
							| 
									
										
										
										
											2025-08-03 21:18:18 +03:00
										 |  |  |                             value={value} | 
					
						
							|  |  |  |                             checked={value === currentValue} | 
					
						
							|  |  |  |                         onChange={e => onChange((e.target as HTMLInputElement).value)} /> | 
					
						
							|  |  |  |                         {label} | 
					
						
							|  |  |  |                     </label> | 
					
						
							|  |  |  |                 </div> | 
					
						
							|  |  |  |             ))} | 
					
						
							|  |  |  |         </> | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | } |