@springmicro/forms 0.7.5 → 0.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,273 +1,273 @@
1
- import { FieldArrayType, FormNodeType } from "../../types/form-builder";
2
- import {
3
- Checkbox,
4
- FormControlLabel,
5
- IconButton,
6
- TextField,
7
- Tooltip,
8
- } from "@mui/material";
9
- import { Box, SxProps } from "@mui/material";
10
- import CloseIcon from "@mui/icons-material/Close";
11
- import React from "react";
12
- import { formatTitle } from "../../utils/form-builder";
13
- import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline";
14
-
15
- /**
16
- * ---------------------- NODE CHILD BASE ----------------------
17
- */
18
-
19
- export type NodeChildBaseProps = {
20
- children?: React.ReactNode;
21
- };
22
-
23
- export function NodeChildBase({ children }: NodeChildBaseProps) {
24
- return (
25
- <Box sx={{ display: "flex", flexDirection: "column", width: "100%" }}>
26
- {children}
27
- </Box>
28
- );
29
- }
30
-
31
- /**
32
- * ---------------------- NODE ACCORDIAN ----------------------
33
- */
34
-
35
- export type NodeAccordianProps = {
36
- open?: boolean;
37
- children?: React.ReactNode;
38
- close: () => void;
39
- deleteNode: () => void;
40
- };
41
-
42
- export function NodeAccordian({
43
- open,
44
- children,
45
- close,
46
- deleteNode,
47
- }: NodeAccordianProps) {
48
- return (
49
- <Box
50
- className={open ? "open" : ""}
51
- sx={{
52
- overflow: "hidden",
53
- transition: "max-height .45s cubic-bezier(0, 1, 0, 1) -.1s",
54
- maxHeight: 0,
55
- "&.open": {
56
- maxHeight: 9999,
57
- transitionTimingFunction: "cubic-bezier(0.5, 0, 1, 0)",
58
- transitionDelay: "0s",
59
- },
60
- width: "100%",
61
- }}
62
- >
63
- <Box
64
- sx={{
65
- pt: 2,
66
- display: "flex",
67
- flexDirection: "column",
68
- }}
69
- >
70
- {children}
71
- </Box>
72
- <Box sx={{ pt: 1 }}>
73
- <BottomSection close={close} deleteNode={deleteNode} />
74
- </Box>
75
- </Box>
76
- );
77
- }
78
-
79
- /**
80
- * ---------------------- NODE TITLE ----------------------
81
- */
82
-
83
- export function NodeTitle({
84
- children,
85
- isPropname,
86
- isEditing,
87
- onClick,
88
- }: {
89
- children: React.ReactNode;
90
- isPropname?: boolean;
91
- isEditing?: boolean;
92
- onClick: () => void;
93
- }) {
94
- return (
95
- <Box
96
- sx={{
97
- width: "100%",
98
- pt: 2,
99
- cursor: "pointer",
100
- transition: "background-color 0.5s",
101
- borderBottomLeftRadius: 10,
102
- borderBottomRightRadius: 10,
103
- ":hover": {
104
- backgroundColor: isEditing ? "#dddddd" : "transparent",
105
- },
106
- }}
107
- onClick={isEditing ? onClick : () => {}}
108
- >
109
- <Box
110
- sx={{
111
- fontWeight: 400,
112
- fontSize: 18,
113
- backgroundColor: !isPropname ? "transparent" : "#d5d5d5",
114
- borderRadius: 2,
115
- px: 1,
116
- display: "inline-block",
117
- }}
118
- >
119
- {children}
120
- </Box>
121
- </Box>
122
- );
123
- }
124
-
125
- /**
126
- * ---------------------- STYLED TEXT FIELD ----------------------
127
- */
128
-
129
- export const textfieldStyle = (sx?: SxProps) => ({
130
- minWidth: 250,
131
- flexGrow: 1,
132
- ...{
133
- "& .MuiOutlinedInput-root": {
134
- "& fieldset": {
135
- borderColor: "#C0C3C7",
136
- },
137
- "&:hover fieldset": {
138
- borderColor: "#A2AAB2",
139
- },
140
- "&.Mui-focused fieldset": {
141
- borderColor: "#6F7E8C",
142
- },
143
- },
144
- },
145
- ...(sx ?? {}),
146
- });
147
-
148
- export function StyledTextField(props?: any, children?: React.ReactNode) {
149
- return (
150
- <TextField {...props} sx={textfieldStyle(props.sx)}>
151
- {children}
152
- </TextField>
153
- );
154
- }
155
-
156
- /**
157
- * ---------------------- BOTTOM SECTION ----------------------
158
- */
159
-
160
- export function BottomSection({
161
- close,
162
- deleteNode,
163
- }: {
164
- close: () => void;
165
- deleteNode: () => void;
166
- }) {
167
- return (
168
- <Box
169
- sx={{
170
- width: "100%",
171
- display: "flex",
172
- justifyContent: "space-between",
173
- backgroundColor: "#00000009",
174
- borderRadius: 1,
175
- py: 0.5,
176
- }}
177
- >
178
- <Box>
179
- <IconButton onClick={deleteNode}>
180
- <DeleteOutlineIcon sx={{ color: "red" }} />
181
- </IconButton>
182
- </Box>
183
- <Box>
184
- <IconButton onClick={close}>
185
- <CloseIcon />
186
- </IconButton>
187
- </Box>
188
- </Box>
189
- );
190
- }
191
-
192
- /**
193
- * ---------------------- FIELD INPUTS ----------------------
194
- */
195
-
196
- export function NodeField({
197
- field,
198
- node,
199
- update,
200
- }: {
201
- field: FieldArrayType<any>[0];
202
- node: FormNodeType;
203
- update: (
204
- key: string,
205
- e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
206
- type?: string
207
- ) => void;
208
- }) {
209
- const prop = field.prop as keyof FormNodeType;
210
- const textfield = (
211
- <StyledTextField
212
- label={field.title ?? formatTitle(prop)}
213
- value={node[prop] as string}
214
- onChange={(e: any) => update(prop, e)}
215
- {...field.props}
216
- />
217
- );
218
- if (!field.tooltip) return textfield;
219
- return (
220
- <Tooltip title={field.tooltip} arrow>
221
- {textfield}
222
- </Tooltip>
223
- );
224
- }
225
-
226
- export function NodeCheckbox({
227
- field,
228
- node,
229
- update,
230
- }: {
231
- field: FieldArrayType<any>[0];
232
- node: FormNodeType;
233
- update: (
234
- key: string,
235
- e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
236
- type?: string
237
- ) => void;
238
- }) {
239
- const prop = field.prop as keyof FormNodeType;
240
- const checkbox = (
241
- <FormControlLabel
242
- control={
243
- <Checkbox
244
- checked={node[prop] as boolean}
245
- onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
246
- update(prop, e, "check");
247
- }}
248
- />
249
- }
250
- label={field.title ?? formatTitle(prop)}
251
- />
252
- );
253
- if (!field.tooltip) return checkbox;
254
- return (
255
- <Tooltip title={field.tooltip} arrow>
256
- {checkbox}
257
- </Tooltip>
258
- );
259
- }
260
-
261
- /**
262
- * ---------------------- FIELD CONTAINERS ----------------------
263
- */
264
-
265
- export function FieldContainer({ children }: { children?: React.ReactNode }) {
266
- return (
267
- <Box
268
- sx={{ display: "flex", flexDirection: "row", gap: 2, flexWrap: "wrap" }}
269
- >
270
- {children}
271
- </Box>
272
- );
273
- }
1
+ import { FieldArrayType, FormNodeType } from "../../types/form-builder";
2
+ import {
3
+ Checkbox,
4
+ FormControlLabel,
5
+ IconButton,
6
+ TextField,
7
+ Tooltip,
8
+ } from "@mui/material";
9
+ import { Box, SxProps } from "@mui/material";
10
+ import CloseIcon from "@mui/icons-material/Close";
11
+ import React from "react";
12
+ import { formatTitle } from "../../utils/form-builder";
13
+ import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline";
14
+
15
+ /**
16
+ * ---------------------- NODE CHILD BASE ----------------------
17
+ */
18
+
19
+ export type NodeChildBaseProps = {
20
+ children?: React.ReactNode;
21
+ };
22
+
23
+ export function NodeChildBase({ children }: NodeChildBaseProps) {
24
+ return (
25
+ <Box sx={{ display: "flex", flexDirection: "column", width: "100%" }}>
26
+ {children}
27
+ </Box>
28
+ );
29
+ }
30
+
31
+ /**
32
+ * ---------------------- NODE ACCORDIAN ----------------------
33
+ */
34
+
35
+ export type NodeAccordianProps = {
36
+ open?: boolean;
37
+ children?: React.ReactNode;
38
+ close: () => void;
39
+ deleteNode: () => void;
40
+ };
41
+
42
+ export function NodeAccordian({
43
+ open,
44
+ children,
45
+ close,
46
+ deleteNode,
47
+ }: NodeAccordianProps) {
48
+ return (
49
+ <Box
50
+ className={open ? "open" : ""}
51
+ sx={{
52
+ overflow: "hidden",
53
+ transition: "max-height .45s cubic-bezier(0, 1, 0, 1) -.1s",
54
+ maxHeight: 0,
55
+ "&.open": {
56
+ maxHeight: 9999,
57
+ transitionTimingFunction: "cubic-bezier(0.5, 0, 1, 0)",
58
+ transitionDelay: "0s",
59
+ },
60
+ width: "100%",
61
+ }}
62
+ >
63
+ <Box
64
+ sx={{
65
+ pt: 2,
66
+ display: "flex",
67
+ flexDirection: "column",
68
+ }}
69
+ >
70
+ {children}
71
+ </Box>
72
+ <Box sx={{ pt: 1 }}>
73
+ <BottomSection close={close} deleteNode={deleteNode} />
74
+ </Box>
75
+ </Box>
76
+ );
77
+ }
78
+
79
+ /**
80
+ * ---------------------- NODE TITLE ----------------------
81
+ */
82
+
83
+ export function NodeTitle({
84
+ children,
85
+ isPropname,
86
+ isEditing,
87
+ onClick,
88
+ }: {
89
+ children: React.ReactNode;
90
+ isPropname?: boolean;
91
+ isEditing?: boolean;
92
+ onClick: () => void;
93
+ }) {
94
+ return (
95
+ <Box
96
+ sx={{
97
+ width: "100%",
98
+ pt: 2,
99
+ cursor: "pointer",
100
+ transition: "background-color 0.5s",
101
+ borderBottomLeftRadius: 10,
102
+ borderBottomRightRadius: 10,
103
+ ":hover": {
104
+ backgroundColor: isEditing ? "#dddddd" : "transparent",
105
+ },
106
+ }}
107
+ onClick={isEditing ? onClick : () => {}}
108
+ >
109
+ <Box
110
+ sx={{
111
+ fontWeight: 400,
112
+ fontSize: 18,
113
+ backgroundColor: !isPropname ? "transparent" : "#d5d5d5",
114
+ borderRadius: 2,
115
+ px: 1,
116
+ display: "inline-block",
117
+ }}
118
+ >
119
+ {children}
120
+ </Box>
121
+ </Box>
122
+ );
123
+ }
124
+
125
+ /**
126
+ * ---------------------- STYLED TEXT FIELD ----------------------
127
+ */
128
+
129
+ export const textfieldStyle = (sx?: SxProps) => ({
130
+ minWidth: 250,
131
+ flexGrow: 1,
132
+ ...{
133
+ "& .MuiOutlinedInput-root": {
134
+ "& fieldset": {
135
+ borderColor: "#C0C3C7",
136
+ },
137
+ "&:hover fieldset": {
138
+ borderColor: "#A2AAB2",
139
+ },
140
+ "&.Mui-focused fieldset": {
141
+ borderColor: "#6F7E8C",
142
+ },
143
+ },
144
+ },
145
+ ...(sx ?? {}),
146
+ });
147
+
148
+ export function StyledTextField(props?: any, children?: React.ReactNode) {
149
+ return (
150
+ <TextField {...props} sx={textfieldStyle(props.sx)}>
151
+ {children}
152
+ </TextField>
153
+ );
154
+ }
155
+
156
+ /**
157
+ * ---------------------- BOTTOM SECTION ----------------------
158
+ */
159
+
160
+ export function BottomSection({
161
+ close,
162
+ deleteNode,
163
+ }: {
164
+ close: () => void;
165
+ deleteNode: () => void;
166
+ }) {
167
+ return (
168
+ <Box
169
+ sx={{
170
+ width: "100%",
171
+ display: "flex",
172
+ justifyContent: "space-between",
173
+ backgroundColor: "#00000009",
174
+ borderRadius: 1,
175
+ py: 0.5,
176
+ }}
177
+ >
178
+ <Box>
179
+ <IconButton onClick={deleteNode}>
180
+ <DeleteOutlineIcon sx={{ color: "red" }} />
181
+ </IconButton>
182
+ </Box>
183
+ <Box>
184
+ <IconButton onClick={close}>
185
+ <CloseIcon />
186
+ </IconButton>
187
+ </Box>
188
+ </Box>
189
+ );
190
+ }
191
+
192
+ /**
193
+ * ---------------------- FIELD INPUTS ----------------------
194
+ */
195
+
196
+ export function NodeField({
197
+ field,
198
+ node,
199
+ update,
200
+ }: {
201
+ field: FieldArrayType<any>[0];
202
+ node: FormNodeType;
203
+ update: (
204
+ key: string,
205
+ e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
206
+ type?: string
207
+ ) => void;
208
+ }) {
209
+ const prop = field.prop as keyof FormNodeType;
210
+ const textfield = (
211
+ <StyledTextField
212
+ label={field.title ?? formatTitle(prop)}
213
+ value={node[prop] as string}
214
+ onChange={(e: any) => update(prop, e)}
215
+ {...field.props}
216
+ />
217
+ );
218
+ if (!field.tooltip) return textfield;
219
+ return (
220
+ <Tooltip title={field.tooltip} arrow>
221
+ {textfield}
222
+ </Tooltip>
223
+ );
224
+ }
225
+
226
+ export function NodeCheckbox({
227
+ field,
228
+ node,
229
+ update,
230
+ }: {
231
+ field: FieldArrayType<any>[0];
232
+ node: FormNodeType;
233
+ update: (
234
+ key: string,
235
+ e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
236
+ type?: string
237
+ ) => void;
238
+ }) {
239
+ const prop = field.prop as keyof FormNodeType;
240
+ const checkbox = (
241
+ <FormControlLabel
242
+ control={
243
+ <Checkbox
244
+ checked={node[prop] as boolean}
245
+ onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
246
+ update(prop, e, "check");
247
+ }}
248
+ />
249
+ }
250
+ label={field.title ?? formatTitle(prop)}
251
+ />
252
+ );
253
+ if (!field.tooltip) return checkbox;
254
+ return (
255
+ <Tooltip title={field.tooltip} arrow>
256
+ {checkbox}
257
+ </Tooltip>
258
+ );
259
+ }
260
+
261
+ /**
262
+ * ---------------------- FIELD CONTAINERS ----------------------
263
+ */
264
+
265
+ export function FieldContainer({ children }: { children?: React.ReactNode }) {
266
+ return (
267
+ <Box
268
+ sx={{ display: "flex", flexDirection: "row", gap: 2, flexWrap: "wrap" }}
269
+ >
270
+ {children}
271
+ </Box>
272
+ );
273
+ }