import type { SyntheticEvent } from 'react'; import { useCallback, useMemo } from 'react'; import type { IChangeEvent } from '@rjsf/core'; import Form from '@rjsf/core'; import type { RJSFSchema, UiSchema } from '@rjsf/utils'; import localValidator from '@rjsf/validator-ajv8'; const uiSchema: UiSchema = { 'ui:placeholder': 'Select subtheme', }; export interface SubthemeType { stylesheet?: string | string[]; dataTheme?: string; } export type SubthemesType = Record; interface SubthemeSelectorProps { subtheme: string | null; subthemes: SubthemesType; select: (subthemeName: string, subtheme: SubthemeType) => void; } export default function SubthemeSelector({ subtheme, subthemes, select }: SubthemeSelectorProps) { const schema: RJSFSchema = useMemo( () => ({ type: 'string', title: 'Subtheme', enum: Object.keys(subthemes), }), [subthemes], ); const handleChange = useCallback( ({ formData }: IChangeEvent) => { if (typeof formData !== 'string') { return; } select(formData, subthemes[formData]); }, [select, subthemes], ); const cancelBubble = (event: SyntheticEvent) => { event.preventDefault(); event.stopPropagation(); }; return (
); }