Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(spec): add generic for InputProps and LayoutProps into Spec #164

Merged
merged 4 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/lib/core/components/Form/Controller/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,30 @@ export const getRender = <DirtyValue extends FieldValue, SpecType extends Spec>(
const render = (props: FieldRenderProps<DirtyValue>) => {
if (inputEntity && isCorrectSpec(spec) && _.isString(name)) {
if (!spec.viewSpec.hidden) {
const {layoutProps, inputProps} = spec.viewSpec;
if (inputEntity.independent) {
const InputComponent = inputEntity.Component;

return <InputComponent spec={spec} name={name} Layout={Layout} {...props} />;
return (
<InputComponent
spec={spec}
name={name}
Layout={Layout}
inputProps={inputProps}
bocembocem marked this conversation as resolved.
Show resolved Hide resolved
layoutProps={layoutProps}
{...props}
/>
);
}

const InputComponent = inputEntity.Component;
const input = <InputComponent spec={spec} name={name} {...props} />;
const input = (
<InputComponent spec={spec} name={name} inputProps={inputProps} {...props} />
);

if (Layout) {
return (
<Layout spec={spec} name={name} {...props}>
<Layout spec={spec} name={name} layoutProps={layoutProps} {...props}>
{input}
</Layout>
);
Expand Down
38 changes: 32 additions & 6 deletions src/lib/core/components/Form/types/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,39 @@ import {
ValidatorsMap,
} from './';

export type ArrayInputProps = InputProps<FieldArrayValue, ArraySpec>;
export type ArrayIndependentInputProps = IndependentInputProps<FieldArrayValue, ArraySpec>;
export type ArrayLayoutProps = LayoutProps<FieldArrayValue, ArraySpec>;
export type ArrayInputProps<InputComponentProps extends Record<string, any> = {}> = InputProps<
FieldArrayValue,
ArraySpec<undefined, InputComponentProps>
>;
export type ArrayIndependentInputProps<
InputComponentProps extends Record<string, any> = {},
LayoutComponentProps extends Record<string, any> = {},
> = IndependentInputProps<
FieldArrayValue,
ArraySpec<undefined, InputComponentProps, LayoutComponentProps>
>;

export type ArrayLayoutProps<LayoutComponentProps extends Record<string, any> = {}> = LayoutProps<
FieldArrayValue,
ArraySpec<undefined, any, LayoutComponentProps>
bocembocem marked this conversation as resolved.
Show resolved Hide resolved
>;

export type ArrayInput = InputType<FieldArrayValue, ArraySpec>;
export type ArrayIndependentInput = IndependentInputType<FieldArrayValue, ArraySpec>;
export type ArrayLayout = LayoutType<FieldArrayValue, ArraySpec>;
export type ArrayInput<InputComponentProps extends Record<string, any> = {}> = InputType<
FieldArrayValue,
ArraySpec<undefined, InputComponentProps>
>;
export type ArrayIndependentInput<
InputComponentProps extends Record<string, any> = {},
LayoutComponentProps extends Record<string, any> = {},
> = IndependentInputType<
FieldArrayValue,
ArraySpec<undefined, InputComponentProps, LayoutComponentProps>
>;

export type ArrayLayout<LayoutComponentProps extends Record<string, any> = {}> = LayoutType<
FieldArrayValue,
ArraySpec<undefined, any, LayoutComponentProps>
>;

export type ArrayInputEntity = InputEntity<FieldArrayValue, ArraySpec>;
export type ArrayIndependentInputEntity = IndependentInputEntity<FieldArrayValue, ArraySpec>;
Expand Down
40 changes: 34 additions & 6 deletions src/lib/core/components/Form/types/boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,41 @@ import {
ValidatorsMap,
} from './';

export type BooleanInputProps = InputProps<boolean, BooleanSpec>;
export type BooleanIndependentInputProps = IndependentInputProps<boolean, BooleanSpec>;
export type BooleanLayoutProps = LayoutProps<boolean, BooleanSpec>;
export type BooleanInputProps<InputComponentProps extends Record<string, any> = {}> = InputProps<
boolean,
BooleanSpec<undefined, InputComponentProps>
>;

export type BooleanInput = InputType<boolean, BooleanSpec>;
export type BooleanIndependentInput = IndependentInputType<boolean, BooleanSpec>;
export type BooleanLayout = LayoutType<boolean, BooleanSpec>;
export type BooleanIndependentInputProps<
InputComponentProps extends Record<string, any> = {},
LayoutComponentProps extends Record<string, any> = {},
> = IndependentInputProps<
boolean,
BooleanSpec<undefined, InputComponentProps, LayoutComponentProps>
>;

export type BooleanLayoutProps<LayoutComponentProps extends Record<string, any> = {}> = LayoutProps<
boolean,
BooleanSpec<undefined, any, LayoutComponentProps>
>;

export type BooleanInput<InputComponentProps extends Record<string, any> = {}> = InputType<
boolean,
BooleanSpec<undefined, InputComponentProps>
>;

export type BooleanIndependentInput<
InputComponentProps extends Record<string, any> = {},
LayoutComponentProps extends Record<string, any> = {},
> = IndependentInputType<
boolean,
BooleanSpec<undefined, InputComponentProps, LayoutComponentProps>
>;

export type BooleanLayout<LayoutComponentProps extends Record<string, any> = {}> = LayoutType<
boolean,
BooleanSpec<undefined, any, LayoutComponentProps>
>;

export type BooleanInputEntity = InputEntity<boolean, BooleanSpec>;
export type BooleanIndependentInputEntity = IndependentInputEntity<boolean, BooleanSpec>;
Expand Down
2 changes: 2 additions & 0 deletions src/lib/core/components/Form/types/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import {FieldRenderProps, FieldValue, LayoutType} from './';
export type InputProps<Value extends FieldValue, SpecType extends Spec> = {
spec: SpecType;
name: string;
inputProps?: SpecType['viewSpec']['inputProps'];
bocembocem marked this conversation as resolved.
Show resolved Hide resolved
} & FieldRenderProps<Value>;

export type IndependentInputProps<Value extends FieldValue, SpecType extends Spec> = {
Layout: LayoutType<Value, SpecType> | undefined;
layoutProps?: SpecType['viewSpec']['layoutProps'];
} & InputProps<Value, SpecType>;

export type InputType<Value extends FieldValue, SpecType extends Spec> = (
Expand Down
1 change: 1 addition & 0 deletions src/lib/core/components/Form/types/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {FieldValue, InputProps} from './';

export type LayoutProps<Value extends FieldValue, SpecType extends Spec> = {
children: React.ReactElement;
layoutProps?: SpecType['viewSpec']['layoutProps'];
bocembocem marked this conversation as resolved.
Show resolved Hide resolved
} & InputProps<Value, SpecType>;

export type LayoutType<Value extends FieldValue, SpecType extends Spec> = (
Expand Down
34 changes: 28 additions & 6 deletions src/lib/core/components/Form/types/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,35 @@ import {
ValidatorsMap,
} from './';

export type NumberInputProps = InputProps<number, NumberSpec>;
export type NumberIndependentInputProps = IndependentInputProps<number, NumberSpec>;
export type NumberLayoutProps = LayoutProps<number, NumberSpec>;
export type NumberInputProps<InputComponentProps extends Record<string, any> = {}> = InputProps<
number,
NumberSpec<undefined, InputComponentProps>
>;

export type NumberInput = InputType<number, NumberSpec>;
export type NumberIndependentInput = IndependentInputType<number, NumberSpec>;
export type NumberLayout = LayoutType<number, NumberSpec>;
export type NumberIndependentInputProps<
InputComponentProps extends Record<string, any> = {},
LayoutComponentProps extends Record<string, any> = {},
> = IndependentInputProps<number, NumberSpec<undefined, InputComponentProps, LayoutComponentProps>>;

export type NumberLayoutProps<LayoutComponentProps extends Record<string, any> = {}> = LayoutProps<
number,
NumberSpec<undefined, any, LayoutComponentProps>
>;

export type NumberInput<InputComponentProps extends Record<string, any> = {}> = InputType<
number,
NumberSpec<undefined, InputComponentProps>
>;

export type NumberIndependentInput<
InputComponentProps extends Record<string, any> = {},
LayoutComponentProps extends Record<string, any> = {},
> = IndependentInputType<number, NumberSpec<undefined, InputComponentProps, LayoutComponentProps>>;

export type NumberLayout<LayoutComponentProps extends Record<string, any> = {}> = LayoutType<
number,
NumberSpec<undefined, any, LayoutComponentProps>
>;

export type NumberInputEntity = InputEntity<number, NumberSpec>;
export type NumberIndependentInputEntity = IndependentInputEntity<number, NumberSpec>;
Expand Down
39 changes: 33 additions & 6 deletions src/lib/core/components/Form/types/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,40 @@ import {
ValidatorsMap,
} from './';

export type ObjectInputProps = InputProps<FieldObjectValue, ObjectSpec>;
export type ObjectIndependentInputProps = IndependentInputProps<FieldObjectValue, ObjectSpec>;
export type ObjectLayoutProps = LayoutProps<FieldObjectValue, ObjectSpec>;
export type ObjectInputProps<InputComponentProps extends Record<string, any> = {}> = InputProps<
FieldObjectValue,
ObjectSpec<undefined, InputComponentProps>
>;
export type ObjectIndependentInputProps<
InputComponentProps extends Record<string, any> = {},
LayoutComponentProps extends Record<string, any> = {},
> = IndependentInputProps<
FieldObjectValue,
ObjectSpec<undefined, InputComponentProps, LayoutComponentProps>
>;

export type ObjectInput = InputType<FieldObjectValue, ObjectSpec>;
export type ObjectIndependentInput = IndependentInputType<FieldObjectValue, ObjectSpec>;
export type ObjectLayout = LayoutType<FieldObjectValue, ObjectSpec>;
export type ObjectLayoutProps<LayoutComponentProps extends Record<string, any> = {}> = LayoutProps<
FieldObjectValue,
ObjectSpec<undefined, any, LayoutComponentProps>
>;

export type ObjectInput<InputComponentProps extends Record<string, any> = {}> = InputType<
FieldObjectValue,
ObjectSpec<undefined, InputComponentProps>
>;

export type ObjectIndependentInput<
InputComponentProps extends Record<string, any> = {},
LayoutComponentProps extends Record<string, any> = {},
> = IndependentInputType<
FieldObjectValue,
ObjectSpec<undefined, InputComponentProps, LayoutComponentProps>
>;

export type ObjectLayout<LayoutComponentProps extends Record<string, any> = {}> = LayoutType<
FieldObjectValue,
ObjectSpec<undefined, any, LayoutComponentProps>
>;

export type ObjectInputEntity = InputEntity<FieldObjectValue, ObjectSpec>;
export type ObjectIndependentInputEntity = IndependentInputEntity<FieldObjectValue, ObjectSpec>;
Expand Down
34 changes: 28 additions & 6 deletions src/lib/core/components/Form/types/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,35 @@ import {
ValidatorsMap,
} from './';

export type StringInputProps = InputProps<string, StringSpec>;
export type StringIndependentInputProps = IndependentInputProps<string, StringSpec>;
export type StringLayoutProps = LayoutProps<string, StringSpec>;
export type StringInputProps<InputComponentProps extends Record<string, any> = {}> = InputProps<
string,
StringSpec<undefined, InputComponentProps>
>;

export type StringInput = InputType<string, StringSpec>;
export type StringIndependentInput = IndependentInputType<string, StringSpec>;
export type StringLayout = LayoutType<string, StringSpec>;
export type StringIndependentInputProps<
InputComponentProps extends Record<string, any> = {},
LayoutComponentProps extends Record<string, any> = {},
> = IndependentInputProps<string, StringSpec<undefined, InputComponentProps, LayoutComponentProps>>;

export type StringLayoutProps<LayoutComponentProps extends Record<string, any> = {}> = LayoutProps<
string,
StringSpec<undefined, any, LayoutComponentProps>
>;

export type StringInput<InputComponentProps extends Record<string, any> = {}> = InputType<
string,
StringSpec<undefined, InputComponentProps>
>;

export type StringIndependentInput<
InputComponentProps extends Record<string, any> = {},
LayoutComponentProps extends Record<string, any> = {},
> = IndependentInputType<string, StringSpec<undefined, InputComponentProps, LayoutComponentProps>>;

export type StringLayout<LayoutComponentProps extends Record<string, any> = {}> = LayoutType<
string,
StringSpec<undefined, any, LayoutComponentProps>
>;
bocembocem marked this conversation as resolved.
Show resolved Hide resolved

export type StringInputEntity = InputEntity<string, StringSpec>;
export type StringIndependentInputEntity = IndependentInputEntity<string, StringSpec>;
Expand Down
41 changes: 36 additions & 5 deletions src/lib/core/types/specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import {ReadAsMethod, SpecTypes} from '../constants';

import {ArrayValue, ObjectValue} from './';

export interface ArraySpec<LinkType = any> {
//TODO: Need to move on InputComponentProps extends Record<string, any> | undefined = undefined;
export interface ArraySpec<
LinkType = any,
InputComponentProps extends Record<string, any> = {},
LayoutComponentProps extends Record<string, any> = {},
> {
defaultValue?: ArrayValue;
type: SpecTypes.Array;
required?: boolean;
Expand Down Expand Up @@ -36,10 +41,16 @@ export interface ArraySpec<LinkType = any> {
filterPlaceholder?: string;
meta?: Record<string, string>;
};
inputProps?: InputComponentProps;
layoutProps?: LayoutComponentProps;
};
}

export interface BooleanSpec<LinkType = any> {
export interface BooleanSpec<
LinkType = any,
InputComponentProps extends Record<string, any> = {},
LayoutComponentProps extends Record<string, any> = {},
> {
defaultValue?: boolean;
type: SpecTypes.Boolean;
required?: boolean;
Expand All @@ -53,10 +64,16 @@ export interface BooleanSpec<LinkType = any> {
layoutOpen?: boolean;
link?: LinkType;
hidden?: boolean;
inputProps?: InputComponentProps;
layoutProps?: LayoutComponentProps;
};
}

export interface NumberSpec<LinkType = any> {
export interface NumberSpec<
LinkType = any,
InputComponentProps extends Record<string, any> = {},
LayoutComponentProps extends Record<string, any> = {},
> {
defaultValue?: number;
type: SpecTypes.Number;
required?: boolean;
Expand All @@ -75,10 +92,16 @@ export interface NumberSpec<LinkType = any> {
placeholder?: string;
copy?: boolean;
hidden?: boolean;
inputProps?: InputComponentProps;
layoutProps?: LayoutComponentProps;
};
}

export interface ObjectSpec<LinkType = any> {
export interface ObjectSpec<
LinkType = any,
InputComponentProps extends Record<string, any> = {},
LayoutComponentProps extends Record<string, any> = {},
> {
defaultValue?: ObjectValue;
type: SpecTypes.Object;
required?: boolean;
Expand All @@ -99,10 +122,16 @@ export interface ObjectSpec<LinkType = any> {
};
placeholder?: string;
hidden?: boolean;
inputProps?: InputComponentProps;
layoutProps?: LayoutComponentProps;
};
}

export interface StringSpec<LinkType = any> {
export interface StringSpec<
LinkType = any,
InputComponentProps extends Record<string, any> = {},
LayoutComponentProps extends Record<string, any> = {},
> {
defaultValue?: string;
type: SpecTypes.String;
required?: boolean;
Expand Down Expand Up @@ -149,6 +178,8 @@ export interface StringSpec<LinkType = any> {
filterPlaceholder?: string;
meta?: Record<string, string>;
};
inputProps?: InputComponentProps;
layoutProps?: LayoutComponentProps;
generateRandomValueButton?: boolean;
};
}
Expand Down
Loading
Loading