react-luminus-components 1.0.1 → 1.0.2

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.
package/README.md CHANGED
@@ -1,3 +1,351 @@
1
- ## React Bnf Components
1
+ # React Luminus Components
2
2
 
3
- Library of React Components reusable in bnf projects (Fleetman, CAFM)
3
+ Library of React Components reusable in Luminus projects (Fleetman, CAFM)
4
+
5
+ ---
6
+
7
+ ## Some Documentation
8
+
9
+ ### Components
10
+
11
+ - **Typography**\
12
+ Encapsulated text styles
13
+ - variant: 'h1' | 'h3' | 'h6' | 'subtitle' | 'body' | 'body2' | 'caption'
14
+ ***
15
+ - **Loading**\
16
+ Loading indicator
17
+ ***
18
+ - **MonthPicker**\
19
+ Month picker, gives you the first day of the picked month
20
+ - month: Date
21
+ - onChangeMonth: (month: Date) => void
22
+ ***
23
+ - **HomeDashboard**\
24
+ Dashboard which renders widgets, user can pick his own widgets, reorder them, make some of them full-width...
25
+ - availableWidgets: DashboardWidget[]
26
+ - _set of the widgets available for the specific app/user_
27
+ ***
28
+ - **ApiFileDownloadButton**\
29
+ Button which downloads the file from the API and saves it on the device
30
+ - fileLoader: () => Promise<Blob | null>
31
+ - fileName: string
32
+ ***
33
+ - **SimpleTooltip**\
34
+ Renders text in a basic tooltip
35
+ - text: string
36
+ - placement: 'top' | 'bottom' | 'left' | 'right'
37
+ ***
38
+ - **HtmlTooltip**\
39
+ More advanced tooltip, renders whatever you send as the content, you can also specify the action triggering the tooltip and the header of the tooltip
40
+ - heading: string
41
+ - content: ReactElement
42
+ - placement: 'top' | 'bottom' | 'left' | 'right'
43
+ - trigger?: 'click' | 'hover' | 'focus'
44
+ ***
45
+ - **AvatarIcon**\
46
+ Avatar icon with person's initials, generates custom background color based on the person's name
47
+ - name: string
48
+ - fontSize?: number
49
+ - size?: number
50
+ ***
51
+ - **UserAvatarDropdown**\
52
+ Renders the AvatarIcon which opens a dropdown of actions on click (suitable for Logout button for example), you send the items as the children
53
+ - userName: string
54
+ ***
55
+ - **EmployeeSearch**\
56
+ Searches employees based on the input query, fires onEmployeeSelected on employee click
57
+ - onEmployeeSelected: (employee: EmployeeIndexModel) => void
58
+ ***
59
+ - **EmployeeSearchModal**\
60
+ Renders the EmployeeSearch inside of a modal
61
+ - show: boolean
62
+ - onCancel: () => void
63
+ - onEmployeeSelected: (employee: EmployeeIndexModel) => void
64
+ ***
65
+ - **EmployeePicker**\
66
+ Renders an input select element with custom logic which opens the EmployeeSearchModal to pick an employee
67
+ - defaultSelection: NameIdIntModel | null
68
+ - onSelect?: (employee: NameIdIntModel | null) => void
69
+ - label?: string
70
+ - withoutLabel?: boolean
71
+ - _doesn't render the floating label when set_
72
+ - size?: 'sm' | 'lg'
73
+ - hidden?: boolean
74
+ - disabled?: boolean
75
+ ***
76
+ - **CheckInput**\
77
+ Just a check input
78
+ - value: boolean
79
+ - onChange?: (value: boolean) => void
80
+ - label?: string
81
+ - hidden?: boolean
82
+ - disabled?: boolean
83
+ - type?: 'switch' | 'checkbox'
84
+ ***
85
+ - **TextInput**\
86
+ Just a text input
87
+ - type: 'text' | 'number' | 'password' | 'date' | 'datetime-local'
88
+ - value: string | number | null
89
+ - onChange?: (value: string | number | null) => void
90
+ - label?: string
91
+ - withoutLabel?: boolean
92
+ - _doesn't render the floating label when set_
93
+ - placeholder?: string
94
+ - size?: 'sm' | 'lg'
95
+ - hidden?: boolean
96
+ - disabled?: boolean
97
+ - showClearIcon?: boolean
98
+ - _renders an icon which clears the value on click_
99
+ - clearValue?: string | number
100
+ - _clear icon sets this value insted of a default one if specified_
101
+ ***
102
+ - **SelectInput**\
103
+ Just a select input
104
+ - value: string | number | null
105
+ - options?: FormSelectOption[]
106
+ - _the options for the selection (dropdown list)_
107
+ - onChange?: (value: string | number | null) => void
108
+ - label?: string
109
+ - withoutLabel?: boolean
110
+ - _doesn't render the floating label when set_
111
+ - isNumber?: boolean
112
+ - _you must set this if the input value is numeric, it handles the parsing and sets null if the value is not a valid number_
113
+ - size?: 'sm' | 'lg'
114
+ - hidden?: boolean
115
+ - disabled?: boolean
116
+ - showClearIcon?: boolean
117
+ - _renders an icon which clears the value on click_
118
+ - clearValue?: string | number
119
+ - _clear icon sets this value insted of a default one if specified_
120
+ ***
121
+
122
+ ### Hook Form Inputs
123
+
124
+ Input elements to be used in the react-hook-form, they handle some additional logic.\
125
+ Each requires a hookFormProps prop which is of type HookFormInputProps and contains all the react-hook-form methods neccessary.
126
+
127
+ _register: UseFormRegister<FieldValues>_\
128
+ _formState: FormState<FieldValues>_\
129
+ _getValues: UseFormGetValues<FieldValues>_\
130
+ _setValue: UseFormSetValue<FieldValues>_\
131
+ _watch: UseFormWatch<FieldValues>_
132
+
133
+ Then each component also specifies it's own inputProps (similar to normal input components), listed below
134
+
135
+ - **HookFormEmployeePicker**\
136
+ Just like the EmployeePicker
137
+ - formField: string
138
+ - _the react-hook-form field you register the input to_
139
+ - label: string
140
+ - defaultSelection: NameIdIntModel | null
141
+ - size?: 'sm' | 'lg'
142
+ - resetsFields?: string[]
143
+ - _list of form fields you want to reset when this input's value is changed_
144
+ - hidden?: boolean
145
+ - disabled?: boolean
146
+ ***
147
+ - **HookFormCheckInput**\
148
+ Just a check input
149
+ - formField: string
150
+ - _the react-hook-form field you register the input to_
151
+ - label: string
152
+ - resetsFields?: string[]
153
+ - _list of form fields you want to reset when this input's value is changed_
154
+ - type?: 'switch' | 'checkbox'
155
+ - hidden?: boolean
156
+ - disabled?: boolean
157
+ ***
158
+ - **HookFormRadioInput**\
159
+ Just a radio input
160
+ - formField: string
161
+ - _the react-hook-form field you register the input to_
162
+ - options: NameIdStringModel[]
163
+ - _the radio options_
164
+ - resetsFields?: string[]
165
+ - _list of form fields you want to reset when this input's value is changed_
166
+ - hidden?: boolean
167
+ - disabled?: boolean
168
+ ***
169
+ - **HookFormSelectInput**\
170
+ Just a select input
171
+ - formField: string
172
+ - _the react-hook-form field you register the input to_
173
+ - label: string
174
+ - options: FormSelectOption[]
175
+ - _the options for the selection (dropdown list)_
176
+ - isNumber?: boolean
177
+ - _you must set this if the input value is numeric, it handles the parsing and sets null if the value is not a valid number_
178
+ - size?: 'sm' | 'lg'
179
+ - resetsFields?: string[]
180
+ - _list of form fields you want to reset when this input's value is changed_
181
+ - showClearIcon?: boolean
182
+ - _renders an icon which clears the value on click_
183
+ - clearValue?: string | number
184
+ - _clear icon sets this value insted of a default one if specified_
185
+ - hidden?: boolean
186
+ - disabled?: boolean
187
+ ***
188
+ - **HookFormTextInput**\
189
+ Just a text input
190
+ - formField: string
191
+ - _the react-hook-form field you register the input to_
192
+ - type: 'text' | 'number' | 'password' | 'date' | 'datetime-local'
193
+ - label: string
194
+ - placeholder?: string
195
+ - size?: 'sm' | 'lg'
196
+ - resetsFields?: string[]
197
+ - _list of form fields you want to reset when this input's value is changed_
198
+ - showClearIcon?: boolean
199
+ - _renders an icon which clears the value on click_
200
+ - clearValue?: string | number
201
+ - _clear icon sets this value insted of a default one if specified_
202
+ - hidden?: boolean
203
+ - disabled?: boolean
204
+ ***
205
+ - **HookFormTextAreaInput**\
206
+ Just a text area input
207
+ - formField: string
208
+ - _the react-hook-form field you register the input to_
209
+ - label: string
210
+ - size?: 'sm' | 'lg'
211
+ - resetsFields?: string[]
212
+ - _list of form fields you want to reset when this input's value is changed_
213
+ - showClearIcon?: boolean
214
+ - _renders an icon which clears the value on click_
215
+ - clearValue?: string | number
216
+ - _clear icon sets this value insted of a default one if specified_
217
+ - hidden?: boolean
218
+ - disabled?: boolean
219
+ ***
220
+
221
+ ### Layout
222
+
223
+ Common layout components
224
+
225
+ - **SideMenu**\
226
+ Renders the side menu with navigation items
227
+ - mainItems: MenuItemType[]
228
+ - secondaryItems: MenuItemType[]
229
+ - expanded: boolean
230
+ - onExpand: () => void
231
+ ***
232
+ - **TopBar**\
233
+ Renders the top bar with the application name and child items
234
+ - appName: string
235
+ ***
236
+ - **SideContentBar**\
237
+ Renders the side content bar on the right side, content is sent as children
238
+ - width: number
239
+ ***
240
+ - **MainContainer**\
241
+ The main container for each page
242
+ - sideContent?: React.ReactNode
243
+ - _renders the SideContentBar with this content if specified_
244
+ ***
245
+ - **FullScreenContainer**\
246
+ Container which always spans the whole screen with overflow hidden (you control the scrollbars in your content)
247
+ ***
248
+
249
+ ### Contexts
250
+
251
+ - **LuminusComponentsContext**\
252
+ The app context for this Luminus Components package, you need to include this in your application to work with the Luminus Components.\
253
+ You set all of the text variables displayed by the Luminus Components here, as well as the axiosInstance to enable communication between the API and the Luminus Components
254
+ - axiosInstance: AxiosInstance
255
+ - LinkComponent: React.ForwardRefExoticComponent<LinkProps & React.RefAttributes<HTMLAnchorElement>>
256
+ - language: string
257
+ - axiosTexts: AxiosTexts
258
+ - confirmTexts: ConfirmTexts
259
+ - formValidationTexts: FormValidationTexts
260
+ - employeePickerModalTexts: EmployeeSearchModalTexts
261
+ - homeDashboardTexts: HomeDashboardTexts
262
+ ***
263
+ - **LoadingContext**\
264
+ This context help you with the loading state visualisation, it keeps track of all of the loadings happening in the app and displays the Loading indicator whenever there's a loading running
265
+ - isLoading: boolean
266
+ - startLoading: (key: string) => void
267
+ - _you call this whenever you want some loading to start (key is the unique identifier for the loading in question (e.g. loadingVehicleDetail))_
268
+ - stopLoading: (key: string) => void
269
+ - _you call this whenever the loading you triggered previously ends to clear the loading state (you send the same key)_
270
+ ***
271
+ - **UserContext**\
272
+ Keeps track of the currently logged-in user
273
+ - user: UserModel | null
274
+ - loginUser: () => Promise<boolean>
275
+ - logoutUser: () => void
276
+ ***
277
+
278
+ ### Hooks
279
+
280
+ - **useAuth**\
281
+ The authentication process
282
+ - isAuthenticated: () => boolean
283
+ - getToken: () => string | null
284
+ - authenticate: (kid: string, password: string): Promise<boolean>
285
+ - logout: () => void
286
+ ***
287
+ - **useAxios**\
288
+ Sets the axios instance up with some logic (e.g. displaying toasts whenever there's an error response)
289
+ - axiosInstance
290
+ - cancelToken: CancelTokenStatic
291
+ ***
292
+ - **useConfirm**\
293
+ Custom confirm pop-up
294
+ - confirm: (t: string) => Promise<boolean>
295
+ ***
296
+ - **useNotifications**\
297
+ Creates and shows custom toast notifications
298
+ - addNotification: (message: string, type: 'success' | 'warning' | 'danger') => void
299
+ ***
300
+ - **useZodSchemaTypes**\
301
+ Common types for the zod schema you use with the react-hook-form for fluent validation
302
+ - zString
303
+ - _the field is any string_
304
+ - zStringRequired
305
+ - _the field is a required string_
306
+ - zNumber
307
+ - _the field is any number_
308
+ - zNumberRequired
309
+ - _the field is a required number_
310
+ - zBool
311
+ - _the field is a boolean_
312
+ - zDate
313
+ - _the field is a date-string in ISO format_
314
+ - zDateRequired
315
+ - _the field is a required date-string in ISO format_
316
+ - zEnum
317
+ - _the field is an enum value_
318
+ - zEnumRequired
319
+ - _the field is a required enum value_
320
+ - zObjectIdInt
321
+ - _the field is a numeric id of an object (most commonly NameIdIntModel)_
322
+ - zObjectIdIntRequired
323
+ - _the field is a required numeric id of an object (most commonly NameIdIntModel)_
324
+ - zObjectIdStr
325
+ - _the field is a string id of an object (most commonly NameIdStringModel)_
326
+ - zObjectIdStrRequired
327
+ - _the field is a required string id of an object (most commonly NameIdStringModel)_
328
+ ***
329
+
330
+ ### Utils
331
+
332
+ - **Text Utils**
333
+ - **truncateText**: (str: string) => string
334
+ - _truncates text to the first 300 characters_
335
+ ***
336
+ - **Date Utils**
337
+ - **isISODate**: (dateString: string) => boolean
338
+ - _checks if the string is a valid ISO date-string_
339
+ ***
340
+ - **Object Utils**
341
+ - **isPrimitive**: (val: any) => boolean
342
+ - _checks if the value is a primitive (is not object or a function)_
343
+ - **fixNameIdNulls**: (obj: any) => void
344
+ - _modifies the object, sets null where the value is { id = null }_
345
+ ***
346
+ - **Api Error Fields Utils**
347
+ - **extractErrorsFromResponse**: (error: any): ErrorField[]
348
+ - _takes the error api response and return the validation errors as ErrorField[] (if any)_
349
+ - **hookFormSetServerErrors**: (formMethods: any, error: any) => void
350
+ - _sets manual errors to react-hook-form from the error api response_
351
+ ***
@@ -3,9 +3,10 @@ type Props = {
3
3
  value: boolean;
4
4
  onChange?: (value: boolean) => void;
5
5
  label?: string;
6
+ hidden?: boolean;
6
7
  disabled?: boolean;
7
8
  className?: string;
8
9
  type?: 'switch' | 'checkbox';
9
10
  };
10
- declare const CheckInput: ({ label, value, onChange, disabled, className, type }: Props) => import("react").JSX.Element;
11
+ declare const CheckInput: ({ label, value, onChange, hidden, disabled, className, type }: Props) => import("react").JSX.Element;
11
12
  export default CheckInput;
@@ -2,7 +2,8 @@
2
2
  type InputContainerProps = {
3
3
  withoutLabel: boolean;
4
4
  label: string;
5
+ hidden?: boolean;
5
6
  children: React.ReactNode;
6
7
  };
7
- declare const InputContainer: ({ withoutLabel, label, children }: InputContainerProps) => import("react").JSX.Element;
8
+ declare const InputContainer: ({ withoutLabel, label, hidden, children }: InputContainerProps) => import("react").JSX.Element;
8
9
  export default InputContainer;
@@ -6,7 +6,8 @@ type Props = {
6
6
  label?: string;
7
7
  withoutLabel?: boolean;
8
8
  size?: 'sm' | 'lg';
9
+ hidden?: boolean;
9
10
  disabled?: boolean;
10
11
  };
11
- declare const EmployeePicker: ({ defaultSelection, onSelect, label, withoutLabel, size, disabled, }: Props) => import("react").JSX.Element;
12
+ declare const EmployeePicker: ({ defaultSelection, onSelect, label, withoutLabel, size, hidden, disabled, }: Props) => import("react").JSX.Element;
12
13
  export default EmployeePicker;
@@ -8,10 +8,11 @@ type Props = {
8
8
  withoutLabel?: boolean;
9
9
  isNumber?: boolean;
10
10
  size?: 'sm' | 'lg';
11
+ hidden?: boolean;
11
12
  disabled?: boolean;
12
13
  showClearIcon?: boolean;
13
14
  clearValue?: string | number;
14
15
  className?: string;
15
16
  };
16
- declare const SelectInput: ({ value, options, onChange, label, withoutLabel, isNumber, size, disabled, showClearIcon, clearValue, className, }: Props) => import("react").JSX.Element;
17
+ declare const SelectInput: ({ value, options, onChange, label, withoutLabel, isNumber, size, hidden, disabled, showClearIcon, clearValue, className, }: Props) => import("react").JSX.Element;
17
18
  export default SelectInput;
@@ -7,10 +7,11 @@ type Props = {
7
7
  withoutLabel?: boolean;
8
8
  placeholder?: string;
9
9
  size?: 'sm' | 'lg';
10
+ hidden?: boolean;
10
11
  disabled?: boolean;
11
12
  showClearIcon?: boolean;
12
13
  clearValue?: string | number;
13
14
  className?: string;
14
15
  };
15
- declare const TextInput: ({ type, value, onChange, label, withoutLabel, placeholder, size, disabled, showClearIcon, clearValue, className, }: Props) => import("react").JSX.Element;
16
+ declare const TextInput: ({ type, value, onChange, label, withoutLabel, placeholder, size, hidden, disabled, showClearIcon, clearValue, className, }: Props) => import("react").JSX.Element;
16
17
  export default TextInput;