import clsx from "clsx"; import { useMemo } from "react"; import { EngineButtons } from "./EngineButtons"; import { SurveyElement } from "./engineTypes"; interface FeatureSelectionProps { element: SurveyElement; field: any; register: any; control: any; onSubmit: () => void; disabled: boolean; allowSkip: boolean; skipAction: () => void; autoSubmit: boolean; loading: boolean; } export default function FeatureSelection({ element, field, register, allowSkip, skipAction, autoSubmit, loading, }: FeatureSelectionProps) { const shuffledOptions = useMemo( () => (element.options ? getShuffledArray(element.options) : []), [element.options] ); return (
{element.label}
{shuffledOptions.map((option) => ( ))}
); } function getShuffledArray(array: any[]) { const shuffledArray = [...array]; for (let i = shuffledArray.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]]; } return shuffledArray; }