Skip to content

Commit 4567375

Browse files
authored
Feat/factory react default components (#14)
* feat(factory-react): add default components for all form-schema types - Add default input components: InputText, InputSelect, InputCheckbox, InputDate, InputPhone, InputAutocomplete, InputTextarea, InputNumber - Add default container components: FormField, FormSectionContainer, FormSectionTitle, FormSectionGroup, FormSectionGroupContainer - Export *Props and *ComponentType for each for custom implementations - Register all defaults in setFactoryDefaultComponents() - Extend HTML/React attribute types instead of [key: string]: any * refactor(examples): align react examples with factory-react props types - basic-ui, chakra-ui, material-ui: use Input*Props from @schepta/factory-react - Containers: use FormFieldProps, FormSection*Props where applicable - Merge UI-specific props (e.g. CheckboxProps) with factory props in Chakra - Remove empty basic-ui InputPhone (rely on registry default or shared)
1 parent 3abc302 commit 4567375

53 files changed

Lines changed: 1423 additions & 339 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2+
import type { FormFieldProps } from '@schepta/factory-react';
23

3-
export const FormField = ({ children, ...props }: any) => {
4+
export const FormField: React.FC<FormFieldProps> = ({ children, ...props }) => {
45
return <div data-test-id="FormField" {...props}>{children}</div>;
56
};
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2+
import type { FormSectionContainerProps } from '@schepta/factory-react';
23

3-
export const FormSectionContainer = ({ children, ...props }: any) => {
4+
export const FormSectionContainer: React.FC<FormSectionContainerProps> = ({ children, ...props }) => {
45
return <div data-test-id="FormSectionContainer" style={{ marginBottom: '24px' }} {...props}>{children}</div>;
56
};
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
2+
import type { FormSectionGroupProps } from '@schepta/factory-react';
23

3-
export const FormSectionGroup = ({ children, columns, ...props }: any) => {
4-
const gridColumns = columns || 'repeat(auto-fit, minmax(200px, 1fr))';
5-
return <div data-test-id="FormSectionGroup" style={{ display: 'grid', gridTemplateColumns: gridColumns, gap: '16px' }} {...props}>{children}</div>;
4+
export const FormSectionGroup: React.FC<FormSectionGroupProps> = ({ children, ...props }) => {
5+
return <div data-test-id="FormSectionGroup" style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(200px, 1fr))', gap: '16px', ...props.style }} {...props}>{children}</div>;
66
};
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2+
import type { FormSectionGroupContainerProps } from '@schepta/factory-react';
23

3-
export const FormSectionGroupContainer = ({ children, ...props }: any) => {
4+
export const FormSectionGroupContainer: React.FC<FormSectionGroupContainerProps> = ({ children, ...props }) => {
45
return <div data-test-id="FormSectionGroupContainer" {...props}>{children}</div>;
56
};
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2+
import type { FormSectionTitleProps } from '@schepta/factory-react';
23

3-
export const FormSectionTitle = ({ 'x-content': content, children, ...props }: any) => {
4-
return <h2 data-test-id="FormSectionTitle" style={{ marginBottom: '16px', fontSize: '20px', fontWeight: '600', color: '#333' }} {...props}>{content || children}</h2>;
4+
export const FormSectionTitle: React.FC<FormSectionTitleProps> = ({ 'x-content': content, children, ...props }) => {
5+
return <h2 data-test-id="FormSectionTitle" style={{ marginBottom: '16px', fontSize: '20px', fontWeight: '600', color: '#333', ...props.style }} {...props}>{content || children}</h2>;
56
};

examples/react/src/basic-ui/components/Inputs/InputCheckbox.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import React from 'react';
2+
import type { InputCheckboxProps } from '@schepta/factory-react';
23

3-
export const InputCheckbox = React.forwardRef<HTMLInputElement, any>((props, ref) => {
4-
const { label, name, value, onChange, children, ...rest } = props;
4+
export const InputCheckbox: React.FC<InputCheckboxProps> = ({ label, name, value, onChange, children, ...rest }) => {
55
return (
66
<div style={{ marginBottom: "16px" }}>
77
<label style={{ display: "flex", alignItems: "center", gap: "8px" }}>
88
<input
9-
ref={ref}
109
type="checkbox"
1110
name={name}
1211
data-test-id={name}
@@ -19,4 +18,4 @@ export const InputCheckbox = React.forwardRef<HTMLInputElement, any>((props, ref
1918
{children}
2019
</div>
2120
);
22-
});
21+
};

examples/react/src/basic-ui/components/Inputs/InputDate.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
2+
import type { InputDateProps } from '@schepta/factory-react';
23

3-
export const InputDate = React.forwardRef<HTMLInputElement, any>((props, ref) => {
4-
const { label, name, value, onChange, ...rest } = props;
4+
export const InputDate: React.FC<InputDateProps> = ({ label, name, value, onChange, ...rest }) => {
55
return (
66
<div style={{ marginBottom: "16px" }}>
77
{label && (
@@ -13,7 +13,6 @@ export const InputDate = React.forwardRef<HTMLInputElement, any>((props, ref) =>
1313
</label>
1414
)}
1515
<input
16-
ref={ref}
1716
type="date"
1817
id={name}
1918
name={name}
@@ -30,4 +29,4 @@ export const InputDate = React.forwardRef<HTMLInputElement, any>((props, ref) =>
3029
/>
3130
</div>
3231
);
33-
});
32+
};

examples/react/src/basic-ui/components/Inputs/InputNumber.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
import type { InputNumberProps } from '@schepta/factory-react';
12
import React from 'react';
23

3-
export const InputNumber = React.forwardRef<HTMLInputElement, any>((props, ref) => {
4-
const { label, name, value, onChange, placeholder, min, max, step, ...rest } =
5-
props;
4+
export const InputNumber: React.FC<InputNumberProps> = ({ label, name, value, onChange, placeholder, min, max, step, ...rest }) => {
65
return (
76
<div style={{ marginBottom: "16px" }}>
87
{label && (
@@ -14,7 +13,6 @@ export const InputNumber = React.forwardRef<HTMLInputElement, any>((props, ref)
1413
</label>
1514
)}
1615
<input
17-
ref={ref}
1816
type="number"
1917
id={name}
2018
name={name}
@@ -37,4 +35,4 @@ export const InputNumber = React.forwardRef<HTMLInputElement, any>((props, ref)
3735
/>
3836
</div>
3937
);
40-
});
38+
};

examples/react/src/basic-ui/components/Inputs/InputPhone.tsx

Whitespace-only changes.

examples/react/src/basic-ui/components/Inputs/InputSelect.tsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
1+
import type { InputSelectProps } from '@schepta/factory-react';
12
import React from 'react';
23

3-
export const InputSelect = React.forwardRef<HTMLSelectElement, any>((props, ref) => {
4-
const {
5-
label,
6-
name,
7-
value,
8-
onChange,
9-
options = [],
10-
placeholder = "Select...",
11-
children,
12-
...rest
13-
} = props;
4+
export const InputSelect: React.FC<InputSelectProps> = ({ label, name, value, onChange, options = [], placeholder = "Select...", children, ...rest }) => {
145
return (
156
<div style={{ marginBottom: "16px" }}>
167
{label && (
@@ -22,7 +13,6 @@ export const InputSelect = React.forwardRef<HTMLSelectElement, any>((props, ref)
2213
</label>
2314
)}
2415
<select
25-
ref={ref}
2616
id={name}
2717
name={name}
2818
data-test-id={name}
@@ -49,4 +39,4 @@ export const InputSelect = React.forwardRef<HTMLSelectElement, any>((props, ref)
4939
{children}
5040
</div>
5141
);
52-
});
42+
};

0 commit comments

Comments
 (0)