All files / src/components/Inputs HandleInputRender.tsx

0% Statements 0/32
0% Branches 0/21
0% Functions 0/1
0% Lines 0/32

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114                                                                                                                                                                                                                                   
import React, { HTMLInputTypeAttribute } from "react";
import { InputType, InputTypes } from "../../types/inputs/inputTypes.ts";
import Text from "./InputTypes/Text.tsx";
import Multiline from "./InputTypes/Multiline.tsx";
import CustomButton from "../common/CustomButton/index.tsx";
import IframeRender from "../Playbooks/options/IframeRender.tsx";
import TypingDropdownInput from "./InputTypes/TypingDropdownInput.tsx";
import TypingDropdownMultipleInput from "./InputTypes/TypingDropdownMultipleInput.tsx";
import DropdownInput from "./InputTypes/DropdownInput.tsx";
import Wysiwyg from "./InputTypes/Wysiwyg.tsx";
import CompositeField from "./InputTypes/CompositeField.tsx";
import DateInput from "./InputTypes/Date.tsx";
import StringArrayInput from "./InputTypes/StringArrayInput.tsx";
import TypingDropdownMultipleSelectionInput from "./InputTypes/TypingDropdownMultipleSelectionInput.tsx";
import TextButton from "./InputTypes/TextButton.tsx";
import CronInput from "../common/CronInput/index.tsx";
 
export type HandleInputRenderType = {
  inputType: InputType;
  value: any;
  type?: HTMLInputTypeAttribute;
  label?: string;
  handleChange?: (val: string) => void;
  handleClick?: React.MouseEventHandler<HTMLButtonElement>;
  handleAddClick?: () => void;
  error?: string;
  disabled?: boolean;
  helpText?: string;
  placeholder?: string;
  options?: any[];
  searchable?: boolean;
  length?: number;
  className?: string;
  compositeFields?: HandleInputRenderType[];
  key?: string;
  isOptional?: boolean;
  default?: string;
  format?: string;
  disabledDate?: (date: Date) => boolean;
  typingContainerClassname?: string;
  buttonText?: string;
  buttonClickValue?: string;
} & React.InputHTMLAttributes<HTMLInputElement | HTMLButtonElement>;
 
function HandleInputRender({ inputType, ...props }: HandleInputRenderType) {
  switch (inputType) {
    case InputTypes.TEXT:
      return <Text {...props} handleChange={props.handleChange!} />;
    case InputTypes.MULTILINE:
      return <Multiline handleChange={props.handleChange!} {...props} />;
    case InputTypes.BUTTON:
      return (
        <CustomButton onClick={props.handleClick!}>{props.label}</CustomButton>
      );
    case InputTypes.IFRAME_RENDER:
      return <IframeRender url={props.value} />;
    case InputTypes.DROPDOWN:
      return (
        <DropdownInput
          {...props}
          handleChange={props.handleChange!}
          options={props.options ?? []}
        />
      );
    case InputTypes.TYPING_DROPDOWN:
      return (
        <TypingDropdownInput
          {...props}
          handleChange={props.handleChange!}
          options={props.options ?? []}
        />
      );
    case InputTypes.TYPING_DROPDOWN_MULTIPLE:
      return (
        <TypingDropdownMultipleInput
          {...props}
          handleChange={props.handleChange!}
          options={props.options ?? []}
          handleAddClick={props.handleAddClick!}
        />
      );
    case InputTypes.WYISWYG:
      return <Wysiwyg handleChange={props.handleChange!} {...props} />;
    case InputTypes.COMPOSITE:
      return <CompositeField handleChange={props.handleChange} {...props} />;
    case InputTypes.DATE:
      return <DateInput handleChange={props.handleChange!} {...props} />;
    case InputTypes.STRING_ARRAY:
      return <StringArrayInput handleChange={props.handleChange!} {...props} />;
    case InputTypes.TYPING_DROPDOWN_MULTIPLE_SELECTION:
      return (
        <TypingDropdownMultipleSelectionInput
          handleChange={props.handleChange!}
          {...props}
        />
      );
    case InputTypes.TEXT_BUTTON:
      return (
        <TextButton
          {...props}
          handleChange={props.handleChange!}
          buttonText={props.buttonText!}
          buttonClickValue={props.buttonClickValue!}
        />
      );
    case InputTypes.CRON:
      return <CronInput {...props} handleChange={props.handleChange!} />;
    default:
      return <p className="text-xs font-semibold">Unsupported Input Type</p>;
  }
}
 
export default HandleInputRender;