Skip to content

Commit cf02e6d

Browse files
committed
tree-field
1 parent 2d74f9e commit cf02e6d

22 files changed

+280
-23
lines changed

demo/package-lock.json

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"react-native": "0.74.1",
1111
"react-native-svg": "15.2.0",
1212
"react-native-web": "~0.19.6",
13-
"rn-declarative": "^0.0.56",
14-
"rn-declarative-eva": "^0.0.44"
13+
"rn-declarative": "^0.0.57",
14+
"rn-declarative-eva": "^0.0.45"
1515
},
1616
"devDependencies": {
1717
"@babel/core": "^7.19.3",

packages/rn-declarative-eva/package-lock.json

+6-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/rn-declarative-eva/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rn-declarative-eva",
3-
"version": "0.0.44",
3+
"version": "0.0.45",
44
"description": "A responsive layout for the react-native",
55
"private": false,
66
"author": {
@@ -77,7 +77,7 @@
7777
"react-native": "0.71.6",
7878
"react-native-svg": "9.4.0",
7979
"typescript": "4.6.2",
80-
"rn-declarative": "0.0.56"
80+
"rn-declarative": "0.0.57"
8181
},
8282
"dependencies": {
8383
"rimraf": "3.0.2"

packages/rn-declarative/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/rn-declarative/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rn-declarative",
3-
"version": "0.0.56",
3+
"version": "0.0.57",
44
"description": "A responsive layout for the react-native",
55
"private": false,
66
"author": {

packages/rn-declarative/src/components/One/components/SlotFactory/ISlotFactoryContext.ts

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { ISliderSlot } from '../../slots/SliderSlot';
1717
import { ITimeSlot } from '../../slots/TimeSlot';
1818
import { IChooseSlot } from '../../slots/ChooseSlot';
1919
import { ITypographySlot } from '../../slots/TypographySlot';
20+
import { ITreeSlot } from '../../slots/TreeSlot';
2021

2122
/**
2223
* A context object that provides access to various component types used by the slot factory.
@@ -47,6 +48,7 @@ export interface ISlotFactoryContext {
4748
Time: ComponentType<ITimeSlot>;
4849
Choose: ComponentType<IChooseSlot>;
4950
Typography: ComponentType<ITypographySlot>;
51+
Tree: ComponentType<ITreeSlot>;
5052
}
5153

5254
export default ISlotFactoryContext;

packages/rn-declarative/src/components/One/components/SlotFactory/SlotContext.ts

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Slider from './components/Slider';
1717
import Time from './components/Time';
1818
import Choose from './components/Choose';
1919
import Typography from './components/Typography';
20+
import Tree from './components/Tree';
2021

2122
import ISlotFactoryContext from './ISlotFactoryContext';
2223

@@ -48,6 +49,7 @@ export const defaultSlots: ISlotFactoryContext = {
4849
Time,
4950
Choose,
5051
Typography,
52+
Tree,
5153
};
5254

5355
export const SlotContext = createContext<ISlotFactoryContext>(defaultSlots);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as React from 'react';
2+
3+
import { Text } from 'react-native';
4+
5+
import { ITreeSlot } from '../../../slots/TreeSlot';
6+
7+
export const Tree = ({}: ITreeSlot) => (
8+
<Text>
9+
FieldType.Tree is not provided (see OneSlotFactory)
10+
</Text>
11+
)
12+
13+
export default Tree;

packages/rn-declarative/src/components/One/config/createField.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import SliderField from "../fields/SliderField";
2323
import TimeField from "../fields/TimeField";
2424
import ChooseField from "../fields/ChooseField";
2525
import TypographyField from "../fields/TypographyField";
26+
import TreeField from "../fields/TreeField";
2627

2728
const fieldMap: { [key in FieldType]?: React.ComponentType<IEntity> } = Object.create(null);
2829

@@ -60,6 +61,7 @@ Object.assign(fieldMap, {
6061
[FieldType.Time]: TimeField,
6162
[FieldType.Choose]: ChooseField,
6263
[FieldType.Typography]: TypographyField,
64+
[FieldType.Tree]: TreeField,
6365
});
6466

6567
/**

packages/rn-declarative/src/components/One/config/initialValue.ts

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const initialValueMap = {
3232
[FieldType.Time]: null,
3333
[FieldType.Choose]: null,
3434
[FieldType.Typography]: "",
35+
[FieldType.Tree]: null,
3536
};
3637

3738
type InitialValue = typeof initialValueMap;

packages/rn-declarative/src/components/One/config/isBaseline.ts

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const baselineFields = new Set<FieldType>([
2424
FieldType.Time,
2525
FieldType.Choose,
2626
FieldType.Typography,
27+
FieldType.Tree,
2728
]);
2829

2930
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
import * as React from "react";
2+
3+
import Tree from '../../../components/One/slots/TreeSlot';
4+
5+
import makeField from "../components/makeField";
6+
7+
import IManaged, { PickProp } from "../../../model/IManaged";
8+
import IAnything from "../../../model/IAnything";
9+
import IField from "../../../model/IField";
10+
11+
/**
12+
* Interface for the props of the ITreeField component.
13+
*
14+
* @template Data The type of data in the field.
15+
* @template Payload The type of payload in the field.
16+
*/
17+
export interface ITreeFieldProps<Data = IAnything, Payload = IAnything> {
18+
/**
19+
* Validation factory config
20+
*
21+
* @template IField - Type representing the field object.
22+
* @template Data - Type representing the data object.
23+
* @template Payload - Type representing the payload object.
24+
*
25+
* @returns The value of the "validation" property.
26+
*/
27+
validation?: PickProp<IField<Data, Payload>, 'validation'>;
28+
/**
29+
* Returns the "description" property of a given object.
30+
*
31+
* @template T - The type of the object.
32+
* @template K - The literal key type.
33+
*
34+
* @param obj - The object from which to extract the property.
35+
* @param key - The literal key representing the property to extract.
36+
*
37+
* @returns - The value of the specified property.
38+
*/
39+
description?: PickProp<IField<Data, Payload>, "description">;
40+
/**
41+
* Type definition for the "title" property picked from the given object type.
42+
*
43+
* @template IField - The object type that contains the "title" property.
44+
* @template Data - The data type of the "title" property.
45+
* @template Payload - The payload type of the "title" property.
46+
*
47+
* @param - The object from which the "title" property will be picked.
48+
*
49+
* @returns - The resulting object that only contains the "title" property.
50+
*/
51+
title?: PickProp<IField<Data, Payload>, "title">;
52+
/**
53+
* Type definition for the variable placeholder.
54+
*
55+
* @template Data - The type of data for the field.
56+
* @template Payload - The type of payload for the field.
57+
* @typedef placeholder
58+
*/
59+
placeholder?: PickProp<IField<Data, Payload>, "placeholder">;
60+
/**
61+
* Specifies if a field is readOnly.
62+
*
63+
* @typedef Readonly
64+
*
65+
* @typedef IField
66+
* @typedef Payload
67+
* @typedef PickProp
68+
* @typedef Data
69+
*
70+
* @param readonly - The field being checked for readOnly status.
71+
*
72+
* @returns - A boolean value indicating if the field is readOnly.
73+
*/
74+
readonly?: PickProp<IField<Data, Payload>, "readonly">;
75+
/**
76+
* Represents the `disabled` property of a field in a form.
77+
*
78+
* @typedef Disabled
79+
*
80+
* @property disabled - Indicates whether the field is disabled or not.
81+
* @template Data - The type of data stored in the form.
82+
* @template Payload - The type of payload used for form submission.
83+
*/
84+
disabled?: PickProp<IField<Data, Payload>, "disabled">;
85+
/**
86+
* Represents the item tree of a specific field in the data payload.
87+
*
88+
* @typedef ItemTree
89+
*/
90+
itemTree?: PickProp<IField<Data, Payload>, 'itemTree'>;
91+
}
92+
93+
/**
94+
* Represents the private interface for the TreeField component.
95+
*
96+
* @template Data The type of data for the TreeField component.
97+
*/
98+
export interface ITreeFieldPrivate<Data = IAnything> {
99+
onChange: PickProp<IManaged<Data>, "onChange">;
100+
invalid: PickProp<IManaged<Data>, "invalid">;
101+
incorrect: PickProp<IManaged<Data>, "incorrect">;
102+
value: PickProp<IManaged<Data>, "value">;
103+
loading: PickProp<IManaged<Data>, "loading">;
104+
disabled: PickProp<IManaged<Data>, "disabled">;
105+
dirty: PickProp<IManaged<Data>, "dirty">;
106+
name: PickProp<IManaged<Data>, "name">;
107+
}
108+
109+
/**
110+
* Renders a TreeField component.
111+
*
112+
* @param props - The props object containing the necessary data for rendering the TreeField.
113+
* @param props.invalid - Determines if the TreeField is invalid.
114+
* @param props.value - The value of the TreeField.
115+
* @param props.disabled - Determines if the TreeField is disabled.
116+
* @param props.readonly - Determines if the TreeField is readonly.
117+
* @param props.incorrect - Determines if the TreeField is incorrect.
118+
* @param props.description - The description text for the TreeField.
119+
* @param props.outlined - Determines if the TreeField should have an outlined style.
120+
* @param props.title - The title text for the TreeField.
121+
* @param props.placeholder - The placeholder text for the TreeField.
122+
* @param props.itemTree - The itemTree object for rendering the Tree.
123+
* @param props.dirty - Determines if the TreeField has been modified.
124+
* @param props.loading - Determines if the TreeField is currently loading.
125+
* @param props.onChange - The callback function to be called when the value of the TreeField changes.
126+
* @param props.name - The name attribute of the TreeField.
127+
* @param props.withContextMenu - Determines if the TreeField should have a context menu.
128+
*
129+
* @returns The rendered TreeField component.
130+
*/
131+
export const TreeField = ({
132+
invalid,
133+
value,
134+
disabled,
135+
readonly,
136+
incorrect,
137+
description = "",
138+
title = "",
139+
placeholder = "",
140+
itemTree,
141+
dirty,
142+
loading,
143+
onChange,
144+
name,
145+
}: ITreeFieldProps & ITreeFieldPrivate) => (
146+
<Tree
147+
invalid={invalid}
148+
incorrect={incorrect}
149+
value={value}
150+
readonly={readonly}
151+
disabled={disabled}
152+
description={description}
153+
title={title}
154+
placeholder={placeholder}
155+
itemTree={itemTree}
156+
dirty={dirty}
157+
loading={loading}
158+
onChange={onChange}
159+
name={name}
160+
/>
161+
);
162+
163+
TreeField.displayName = 'TreeField';
164+
165+
export default makeField(TreeField, {
166+
withApplyQueue: true,
167+
skipDirtyPressListener: true,
168+
skipFocusReadonly: true,
169+
skipDebounce: true,
170+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { ITreeFieldProps, ITreeFieldPrivate } from "../../fields/TreeField";
2+
3+
type ITreeBase = ITreeFieldProps & ITreeFieldPrivate;
4+
5+
/**
6+
* Represents a slot in a tree structure.
7+
* Extends the interface ITreeBase.
8+
*
9+
* @interface
10+
* @extends ITreeBase
11+
*/
12+
export interface ITreeSlot extends ITreeBase { }
13+
14+
export default ITreeSlot;

0 commit comments

Comments
 (0)