Added fieldset create input element
This commit is contained in:
parent
32d2b444bf
commit
1184a44c57
|
|
@ -1,4 +1,6 @@
|
||||||
import {
|
import {
|
||||||
|
Fieldset,
|
||||||
|
FieldsetProps,
|
||||||
MultiSelect,
|
MultiSelect,
|
||||||
MultiSelectProps,
|
MultiSelectProps,
|
||||||
NumberInput,
|
NumberInput,
|
||||||
|
|
@ -36,55 +38,58 @@ type SelectType = {
|
||||||
type: "select";
|
type: "select";
|
||||||
} & SelectProps;
|
} & SelectProps;
|
||||||
|
|
||||||
|
type Group = {
|
||||||
|
type: "group";
|
||||||
|
inputs: AcceptedInput[];
|
||||||
|
} & FieldsetProps;
|
||||||
|
|
||||||
|
type AcceptedInput = (
|
||||||
|
| TextInputType
|
||||||
|
| MultiSelectInputType
|
||||||
|
| PasswordInputType
|
||||||
|
| NumberInputType
|
||||||
|
| SelectType
|
||||||
|
| Group
|
||||||
|
) &
|
||||||
|
GeneralInputProps;
|
||||||
|
|
||||||
interface Options {
|
interface Options {
|
||||||
disableAll?: boolean;
|
disableAll?: boolean;
|
||||||
readonlyAll?: boolean;
|
readonlyAll?: boolean;
|
||||||
inputs: ((
|
inputs: AcceptedInput[];
|
||||||
| TextInputType
|
|
||||||
| MultiSelectInputType
|
|
||||||
| PasswordInputType
|
|
||||||
| NumberInputType
|
|
||||||
| SelectType
|
|
||||||
) &
|
|
||||||
GeneralInputProps)[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function createInputComponents(options: Options) {
|
function createInputComponents(options: Options) {
|
||||||
const components = [] as ReactNode[];
|
const components = [] as ReactNode[];
|
||||||
|
|
||||||
for (const input of options.inputs) {
|
const createComponent = (input: AcceptedInput) => {
|
||||||
if (input.hidden) continue;
|
|
||||||
|
|
||||||
switch (input.type) {
|
switch (input.type) {
|
||||||
case "text":
|
case "text":
|
||||||
components.push(
|
return (
|
||||||
<TextInput
|
<TextInput
|
||||||
{...input}
|
{...input}
|
||||||
readOnly={options.readonlyAll || input.readOnly}
|
readOnly={options.readonlyAll || input.readOnly}
|
||||||
disabled={options.disableAll || input.disabled}
|
disabled={options.disableAll || input.disabled}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
break;
|
|
||||||
case "multi-select":
|
case "multi-select":
|
||||||
components.push(
|
return (
|
||||||
<MultiSelect
|
<MultiSelect
|
||||||
{...input}
|
{...input}
|
||||||
readOnly={options.readonlyAll || input.readOnly}
|
readOnly={options.readonlyAll || input.readOnly}
|
||||||
disabled={options.disableAll || input.disabled}
|
disabled={options.disableAll || input.disabled}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
break;
|
|
||||||
case "password":
|
case "password":
|
||||||
components.push(
|
return (
|
||||||
<PasswordInput
|
<PasswordInput
|
||||||
{...input}
|
{...input}
|
||||||
readOnly={options.readonlyAll || input.readOnly}
|
readOnly={options.readonlyAll || input.readOnly}
|
||||||
disabled={options.disableAll || input.disabled}
|
disabled={options.disableAll || input.disabled}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
break;
|
|
||||||
case "number":
|
case "number":
|
||||||
components.push(
|
return (
|
||||||
<NumberInput
|
<NumberInput
|
||||||
{...input}
|
{...input}
|
||||||
type="text"
|
type="text"
|
||||||
|
|
@ -92,16 +97,33 @@ function createInputComponents(options: Options) {
|
||||||
disabled={options.disableAll || input.disabled}
|
disabled={options.disableAll || input.disabled}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
break;
|
|
||||||
case "select":
|
case "select":
|
||||||
components.push(
|
return (
|
||||||
<Select
|
<Select
|
||||||
{...input}
|
{...input}
|
||||||
readOnly={options.readonlyAll || input.readOnly}
|
readOnly={options.readonlyAll || input.readOnly}
|
||||||
disabled={options.disableAll || input.disabled}
|
disabled={options.disableAll || input.disabled}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
case "group": {
|
||||||
|
const localComponents: ReactNode[] = [];
|
||||||
|
|
||||||
|
for (const child of input.inputs) {
|
||||||
|
if (child.hidden) continue;
|
||||||
|
|
||||||
|
localComponents.push(createComponent(child));
|
||||||
|
}
|
||||||
|
|
||||||
|
return <Fieldset {...input}>{localComponents}</Fieldset>;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const input of options.inputs) {
|
||||||
|
if (input.hidden) continue;
|
||||||
|
|
||||||
|
components.push(createComponent(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
return <>{components}</>;
|
return <>{components}</>;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user