Skip to content

Commit

Permalink
fix: Changed some typing for React.FC in registerInputControl()
Browse files Browse the repository at this point in the history
  • Loading branch information
KasperBaun committed Feb 27, 2024
1 parent d567b7f commit b8805b3
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@ import { useQuickForm } from "../../../../state/QuickFormContext";
import React from "react";
import { InputProps } from "../../../../model/index";

export type MultilineInput = {
readonly placeholder?: string;
readonly className?: string;
readonly value?: string;
readonly onChange?: ChangeEventHandler<HTMLTextAreaElement>;
readonly width?: string;
readonly focus?: boolean;
readonly maxLength?: number;
}


export function MultilineInput({ questionModel, onOutputChange }: InputProps) {
const { isFirstQuestionInCurrentSlide } = useQuickForm();
Expand Down Expand Up @@ -45,9 +37,19 @@ export function MultilineInput({ questionModel, onOutputChange }: InputProps) {
);
}

type MultilineInputProps = {
readonly placeholder?: string;
readonly className?: string;
readonly value?: string;
readonly onChange?: ChangeEventHandler<HTMLTextAreaElement>;
readonly width?: string;
readonly focus?: boolean;
readonly maxLength?: number;
}

const QuestionTextArea = forwardRef(
(
{ placeholder, className, value, onChange, width, focus = true, maxLength }: MultilineInput,
{ placeholder, className, value, onChange, width, focus = true, maxLength }: MultilineInputProps,
passedRef: ForwardedRef<HTMLTextAreaElement>
) => {
const textareaRef = (passedRef as RefObject<HTMLTextAreaElement>) ?? useRef<HTMLTextAreaElement>(null);
Expand Down
15 changes: 9 additions & 6 deletions packages/core/src/services/defaults/DefaultInputTypeResolver.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { FC } from "react";
import { DropDownProperties, RadioProperties, SliderProperties } from "../../model";
import { QuestionJsonModel } from "../../model/json/JsonDataModels";
import { registerQuickFormService } from "../QuickFormServices";
Expand Down Expand Up @@ -51,25 +52,27 @@ function parseInputProperties(questionJsonModel: QuestionJsonModel): DropDownPro

registerQuickFormService("inputTypePropertiesTransformer", parseInputProperties);

import React from "react";
import { TextInput, MultilineInput, DropDownInput } from "../../components/question/input-types/index";
import { InputProps } from "../../model/InputType";

export type InputComponentType = React.ComponentType<InputProps>;
export type InputComponentType = FC<InputProps>;

export type InputComponentDictionary = {
[key: string]: InputComponentType;
};

const inputComponents: InputComponentDictionary = {
"text": TextInput,
// TODO - Create Radio
"radio": TextInput,
// TODO - Create Slider
"slider": TextInput,
"multilinetext": MultilineInput,
// TODO - Create Email
"email": TextInput,
// TODO - Create Toggle
"toggle": TextInput,


"text": TextInput,
"slider": TextInput,
"multilinetext": MultilineInput,
"dropdown": DropDownInput,
"none": TextInput,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/dist/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/playground/dist/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>QuickForm development env</title><script defer="defer" src="bundle.js"></script></head><body><div id="root"></div></body></html>
<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link href="https://fonts.googleapis.com/css?family=Nunito:300,400,600,700&amp;display=swap" rel="stylesheet"/><title>QuickForm development env</title><script defer="defer" src="bundle.js"></script></head><body><div id="root"></div></body></html>
1 change: 0 additions & 1 deletion packages/playground/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { QuickFormProvider } from '../../core/src/state';
import { Editor } from '@monaco-editor/react';
import { Button, QuickForm } from '../../core/src/components';
import "./components/slider/SliderInput";
import "./components/toggle/ToggleInput";

export const App = () => {
const [selectedTemplate, setSelectedTemplate] = useState<QuickFormDefinition>(cleanTestData as QuickFormDefinition);
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/src/components/slider/SliderInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { InputProps, registerInputComponent } from "@eavfw/quickform-core";
import { SliderProperties } from "@eavfw/quickform-core/src/model";
import styles from "./SliderInput.module.css";

export const SliderInput: FC<InputProps> = ({ questionModel, onOutputChange }) => {
export const SliderInput = ({ questionModel, onOutputChange }:InputProps) => {
const min = Number((questionModel.inputProperties as SliderProperties).min) || 0;
const max = Number((questionModel.inputProperties as SliderProperties).max) || 100;
const unit = 'm2';
Expand Down
Empty file.
14 changes: 0 additions & 14 deletions packages/playground/src/components/toggle/ToggleInput.tsx

This file was deleted.

0 comments on commit b8805b3

Please sign in to comment.