-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathComponentTemplate.tsx
More file actions
334 lines (272 loc) · 8.55 KB
/
ComponentTemplate.tsx
File metadata and controls
334 lines (272 loc) · 8.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/**
* Add component description
* @author Add Your Name
*/
// Import React
import React, { useReducer, useEffect, useRef } from 'react';
// Import FontAwesome
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faCheck } from '@fortawesome/free-solid-svg-icons';
// Import shared helpers
import addHelperName from './addHelperFilename';
// Import shared constants
import ADD_CONSTANT_NAME from './addConstantFilename';
// Import shared types
import AddSharedTypeName from './AddSharedTypeFilename';
// Import shared components
import AddSharedComponentName from './AddSharedComponentFilename';
// Import helpers
import addHelperName from './addHelperFilename';
// Import constants
import ADD_CONSTANT_NAME from './addConstantFilename';
// Import types
import AddTypeName from './AddSharedTypeFilename';
// Import components
import AddComponentName from './AddComponentFilename';
// Import style
import './AddNameOfStylesheet.scss';
/*------------------------------------------------------------------------*/
/* -------------------------------- Types ------------------------------- */
/*------------------------------------------------------------------------*/
// Props definition
type Props = {
// Add description of required prop
addPropName: addPropType,
// Add description of optional prop
addPropName?: addPropType,
};
// Add description of custom type
type AddCustomTypeName = {
// Add description of property
addCustomPropName: addCustomPropType,
};
/*------------------------------------------------------------------------*/
/* ------------------------------ Constants ----------------------------- */
/*------------------------------------------------------------------------*/
// Add description of constant
const ADD_CONSTANT_NAME = 'add constant value';
/*------------------------------------------------------------------------*/
/* -------------------------------- State ------------------------------- */
/*------------------------------------------------------------------------*/
/* -------------- Views ------------- */
enum View {
// Add description of view
AddViewName = 'AddViewName',
}
/* -------- State Definition -------- */
type State = (
| {
// Current view
view: View.AddViewName,
// Add description of require state variable
addStateVariableName: addStateVariableValue,
// Add description of optional state variable
addStateVariableName?: addStateVariableValue,
}
| {
// Current view
view: View.AddViewName,
// Add description of require state variable
addStateVariableName: addStateVariableValue,
// Add description of optional state variable
addStateVariableName?: addStateVariableValue,
}
);
/* ------------- Actions ------------ */
// Types of actions
enum ActionType {
// Add description of action type
AddActionTypeName = 'AddActionTypeName',
}
// Action definitions
type Action = (
| {
// Action type
type: ActionType.AddActionTypeName,
// Add description of required payload property
addPayloadPropertyName: addPayloadPropertyType,
// Add description of optional payload property
addPayloadPropertyName?: addPayloadPropertyType,
}
| {
// Action type
type: (
| ActionType.AddActionTypeWithNoPayload
| ActionType.AddActionTypeWithNoPayload
),
}
);
/**
* Reducer that executes actions
* @author Add Your Name
* @param state current state
* @param action action to execute
*/
const reducer = (state: State, action: Action): State => {
switch (action.type) {
case ActionType.AddActionType: {
return {
...state,
addStateVariableName: addStateVariableNewValue,
};
}
default: {
return state;
}
}
};
/*------------------------------------------------------------------------*/
/* --------------------------- Static Helpers --------------------------- */
/*------------------------------------------------------------------------*/
/**
* Add description of helper
* @author Add Your Name
* @param addArgName add arg description
* @param addArgName add arg description
* @returns add return description
*/
const addHelperName = (
addRequiredArgName: addRequiredArgType,
addOptionalArgName?: addOptionalArgType,
addOptionalArgWithDefaultName?: addOptionalArgType = addArgDefault,
): addReturnType => {
// TODO: implement
};
/*------------------------------------------------------------------------*/
/* ------------------------------ Component ----------------------------- */
/*------------------------------------------------------------------------*/
const AddComponentName: React.FC<Props> = (props) => {
/*------------------------------------------------------------------------*/
/* -------------------------------- Setup ------------------------------- */
/*------------------------------------------------------------------------*/
/* -------------- Props ------------- */
// Destructure all props
const {
addRequiredPropName,
addOptionalPropName = 'add default value of prop',
} = props;
/* -------------- State ------------- */
// Initial state
const initialState: State = {
addStateVariableName: 'add state variable initial value',
};
// Initialize state
const [state, dispatch] = useReducer(reducer, initialState);
// Destructure common state
const {
addStateVariableName,
addStateVariableName,
} = state;
/* -------------- Refs -------------- */
// Initialize refs
const addRefName = useRef<AddRefType>(null);
/*------------------------------------------------------------------------*/
/* ------------------------- Component Functions ------------------------ */
/*------------------------------------------------------------------------*/
/**
* Add component helper function description
* @author Add Your Name
* @param addArgName add description of argument
* @param [addOptionalArgName] add description of optional argument
* @returns add description of return
*/
const addComponentHelperFunctionName = (
addArgName: addArgType,
addOptionalArgName?: addOptionalArgType,
): addReturnType => {
// TODO: implement
};
/*------------------------------------------------------------------------*/
/* ------------------------- Lifecycle Functions ------------------------ */
/*------------------------------------------------------------------------*/
/**
* Mount
* @author Add Your Name
*/
useEffect(
() => {
(async () => {
// TODO: implement
})();
},
[],
);
/**
* Update (also called on mount)
* @author Add Your Name
*/
useEffect(
() => {
// TODO: implement
},
[addTriggerVariable],
);
/**
* Unmount
* @author Add Your Name
*/
useEffect(
() => {
return () => {
// TODO: implement
};
},
[],
);
/*------------------------------------------------------------------------*/
/* ------------------------------- Render ------------------------------- */
/*------------------------------------------------------------------------*/
/*----------------------------------------*/
/* ---------------- Modal --------------- */
/*----------------------------------------*/
// Modal that may be defined
let modal: React.ReactNode;
/* ------- AddFirstTypeOfModal ------ */
if (addLogicToDetermineIfModalIsVisible) {
// TODO: implement
// Create modal
modal = (
<Modal
key="unique-modal-key"
...
/>
);
}
/*----------------------------------------*/
/* ---------------- Views --------------- */
/*----------------------------------------*/
// Body that will be filled with the current view
let body: React.ReactNode;
/* -------- AddFirstViewName -------- */
if (view === View.AddViewName) {
// TODO: implement
// Create body
body = (
<addJSXOfBody />
);
}
/* -------- AddSecondViewName -------- */
if (view === View.AddViewName) {
// TODO: implement
// Create body
body = (
<addJSXOfBody />
);
}
/*----------------------------------------*/
/* --------------- Main UI -------------- */
/*----------------------------------------*/
return (
<addContainersForBody>
{/* Add Modal */}
{modal}
{/* Add Body */}
{body}
</addContainersForBody>
);
};
/*------------------------------------------------------------------------*/
/* ------------------------------- Wrap Up ------------------------------ */
/*------------------------------------------------------------------------*/
// Export component
export default AddComponentName;