/* ============================================================================ * Copyright (c) Palo Alto Networks * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * ========================================================================== */ import React from "react"; import { translate } from "@docusaurus/Translate"; import { ErrorMessage } from "@hookform/error-message"; import FormSelect from "@theme/ApiExplorer/FormSelect"; import { Param, setParam } from "@theme/ApiExplorer/ParamOptions/slice"; import { useTypedDispatch } from "@theme/ApiItem/hooks"; import { OPENAPI_FORM } from "@theme/translationIds"; import { Controller, useFormContext } from "react-hook-form"; export interface ParamProps { param: Param; label?: string; type?: string; required?: boolean; } export default function ParamBooleanFormItem({ param, label, type, required, }: ParamProps) { const dispatch = useTypedDispatch(); const { control, formState: { errors }, } = useFormContext(); const showErrorMessage = errors?.paramBoolean; return ( <> ( ) => { const val = e.target.value; dispatch( setParam({ ...param, value: val === "---" ? undefined : val, }) ); onChange(val); }} /> )} /> {showErrorMessage && ( (
{message}
)} /> )} ); }