@aziziaziz/react-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/dist/index.d.mts CHANGED
@@ -1,25 +1,343 @@
1
- import { FC } from 'react';
1
+ import { FC, PropsWithChildren } from 'react';
2
2
 
3
+ /**
4
+ * Props for the Input component.
5
+ */
3
6
  interface InputProps {
7
+ /**
8
+ * Unique identifier for the input field.
9
+ * Used by react-hook-form as the field name.
10
+ */
4
11
  id: string;
12
+ /**
13
+ * Label text displayed above the input.
14
+ *
15
+ * @default "Label"
16
+ */
5
17
  label?: string;
18
+ /**
19
+ * Placeholder text shown when the input is empty.
20
+ *
21
+ * @default "Placeholder"
22
+ */
6
23
  placeholder?: string;
24
+ /**
25
+ * Marks the input as required in form validation.
26
+ *
27
+ * When true, react-hook-form will enforce a required rule.
28
+ *
29
+ * @default false
30
+ */
7
31
  required?: boolean;
32
+ /**
33
+ * Hides the label visually while keeping the input functional.
34
+ *
35
+ * Useful for compact layouts or custom label rendering.
36
+ *
37
+ * @default false
38
+ */
8
39
  hideLabel?: boolean;
40
+ /**
41
+ * Displays a loading indicator inside the input.
42
+ *
43
+ * Typically used while fetching or validating data.
44
+ *
45
+ * @default false
46
+ */
9
47
  loading?: boolean;
48
+ /**
49
+ * Disables the input field.
50
+ *
51
+ * Prevents user interaction and applies disabled styles.
52
+ *
53
+ * @default false
54
+ */
10
55
  disabled?: boolean;
11
56
  }
12
57
 
58
+ /** Create an input component including label
59
+ *
60
+ * This component needs to be wrap in FormProvider from react-hook-form
61
+ */
13
62
  declare const Input: FC<InputProps>;
14
63
 
15
64
  interface SkeletonLoadingProps {
16
65
  /** The border radius of the skeleton
17
66
  *
18
- * Default: 10
67
+ * @default 10
19
68
  */
20
69
  radius?: number;
21
70
  }
22
71
 
72
+ /** A skeleton loading with animation
73
+ *
74
+ * This needs to be wrap in a container with position: relative;
75
+ */
23
76
  declare const SkeletonLoading: FC<SkeletonLoadingProps>;
24
77
 
25
- export { Input, type InputProps, SkeletonLoading, type SkeletonLoadingProps };
78
+ /**
79
+ * Props for the Button component.
80
+ */
81
+ interface ButtonProps extends PropsWithChildren {
82
+ /**
83
+ * Callback fired when the button is clicked.
84
+ */
85
+ onClick: () => void;
86
+ /**
87
+ * Additional CSS class names to apply to the button.
88
+ *
89
+ * Useful for custom styling or utility classes.
90
+ */
91
+ className?: string;
92
+ /**
93
+ * Visual style of the button.
94
+ *
95
+ * @default "submit"
96
+ */
97
+ type?: "warning" | "danger" | "submit";
98
+ /**
99
+ * Displays a loading state inside the button.
100
+ *
101
+ * When true, the button may show a spinner and
102
+ * user interaction should be disabled.
103
+ *
104
+ * @default false
105
+ */
106
+ loading?: boolean;
107
+ /**
108
+ * Disables the button.
109
+ *
110
+ * Prevents click events and applies disabled styles.
111
+ *
112
+ * @default false
113
+ */
114
+ disabled?: boolean;
115
+ /**
116
+ * Size variant of the button.
117
+ *
118
+ * @default "default"
119
+ */
120
+ size?: "default" | "medium" | "small";
121
+ /**
122
+ * Removes the minimum width constraint from the button.
123
+ *
124
+ * Useful for icon-only or compact buttons.
125
+ *
126
+ * @default false
127
+ */
128
+ removeMinWidth?: boolean;
129
+ }
130
+
131
+ /** The button component with size and type */
132
+ declare const Button: FC<ButtonProps>;
133
+
134
+ interface DatePickerProps {
135
+ id: string;
136
+ label?: string;
137
+ placeholder?: string;
138
+ loading?: boolean;
139
+ disabled?: boolean;
140
+ }
141
+ declare const DatePicker: React.FC<DatePickerProps>;
142
+
143
+ type SnackbarType = "info" | "danger" | "warning" | "success";
144
+ interface SnackbarReturn {
145
+ /** To show the snackbar */
146
+ showSnackbar: (
147
+ /** Can be in any string format of the message to show */
148
+ message: string,
149
+ /** info, danger, warning or success - default: info */
150
+ type?: SnackbarType) => void;
151
+ }
152
+ /** Init the snackbar container
153
+ *
154
+ * @param id To set the id of the root container of the snackbar - default: snackbarRoot
155
+ * @param timeout To set the timeout on when the snackbar will be auto hide - default: 3000
156
+ */
157
+ declare const useSnackbar: (body?: HTMLElement | null, id?: string, timeout?: number) => SnackbarReturn;
158
+
159
+ /**
160
+ * Available notification types.
161
+ */
162
+ type NotiTypes = "default" | "error" | "warning" | "success";
163
+ /**
164
+ * Notification payload structure sent to the parent window.
165
+ */
166
+ interface NotificationType {
167
+ /**
168
+ * The notification message text.
169
+ */
170
+ message: string;
171
+ /**
172
+ * Notification visual type.
173
+ *
174
+ * @default "default"
175
+ */
176
+ type?: NotiTypes;
177
+ /**
178
+ * Duration (in milliseconds) before the notification auto-dismisses.
179
+ *
180
+ * @default undefined
181
+ */
182
+ duration?: number;
183
+ }
184
+ /**
185
+ * Configuration object for a popup component.
186
+ */
187
+ interface PopupType {
188
+ /**
189
+ * Title or header text displayed at the top of the popup.
190
+ */
191
+ header?: string;
192
+ /**
193
+ * Main content text displayed inside the popup.
194
+ *
195
+ * Can be plain text or formatted content depending on usage.
196
+ */
197
+ content?: string;
198
+ }
199
+ /**
200
+ * Configuration object for a confirmation or question dialog.
201
+ */
202
+ interface QuestionType {
203
+ /**
204
+ * Title or header text of the question dialog.
205
+ */
206
+ header: string;
207
+ /**
208
+ * Main content or message of the question.
209
+ *
210
+ * Typically explains what action the user is being asked to confirm.
211
+ */
212
+ content: string;
213
+ /**
214
+ * Value returned when the user confirms or selects "Yes".
215
+ *
216
+ * @default "Yes"
217
+ */
218
+ yesValue?: string;
219
+ /**
220
+ * Value returned when the user declines or selects "No".
221
+ *
222
+ * @default "No"
223
+ */
224
+ noValue?: string;
225
+ /**
226
+ * Indicates whether the action is destructive.
227
+ *
228
+ * When true, the dialog should visually emphasize caution
229
+ * (e.g. red buttons or warning styles).
230
+ *
231
+ * @default false
232
+ */
233
+ isDestructive?: boolean;
234
+ }
235
+ /**
236
+ * Function signature for posting a message to the parent window.
237
+ */
238
+ interface PostMessage {
239
+ /**
240
+ * Sends a message to the parent window via `window.postMessage`.
241
+ *
242
+ * @param data - The data payload to send to the parent window
243
+ */
244
+ (data: any): void;
245
+ }
246
+ /**
247
+ * Function signature for posting a notification message
248
+ * to the parent window.
249
+ */
250
+ interface PostNotification {
251
+ /**
252
+ * Sends a notification payload to the parent window.
253
+ *
254
+ * @param data - Notification data including message, type and duration
255
+ */
256
+ (data: NotificationType): void;
257
+ }
258
+ /**
259
+ * Function signature for posting a popup payload
260
+ * to the parent window.
261
+ */
262
+ interface PostPopup {
263
+ /**
264
+ * Sends a popup configuration to the parent window.
265
+ *
266
+ * Typically used to trigger modal or popup displays
267
+ * in the parent application.
268
+ *
269
+ * @param data - Popup configuration including header and content
270
+ */
271
+ (data: PopupType): void;
272
+ }
273
+ /**
274
+ * Function signature for posting a question or confirmation dialog
275
+ * to the parent window.
276
+ */
277
+ interface PostQuestion {
278
+ /**
279
+ * Sends a question configuration to the parent window.
280
+ *
281
+ * Typically used to trigger confirmation or decision dialogs
282
+ * in the parent application.
283
+ *
284
+ * @param data - Question configuration including content and response values
285
+ *
286
+ * @returns The yes or no text from the button that the user clicked
287
+ */
288
+ (data: QuestionType): Promise<string>;
289
+ }
290
+ /**
291
+ * Return object of the `usePostMessage` / `useIFrameDimensions` hook.
292
+ */
293
+ interface UsePostMessageReturn {
294
+ /**
295
+ * Sends the current iframe width and height to the parent window.
296
+ *
297
+ * Useful when the iframe content changes size dynamically.
298
+ */
299
+ sendDimension: () => void;
300
+ /**
301
+ * Posts a custom message to the parent window.
302
+ */
303
+ postMessage: PostMessage;
304
+ /**
305
+ * Posts a notification message to the parent window.
306
+ *
307
+ * Typically used to trigger toast/snackbar notifications
308
+ * in the parent application.
309
+ */
310
+ postNotification: PostNotification;
311
+ /**
312
+ * Posts a popup configuration to the parent window.
313
+ *
314
+ * Typically used to trigger modal or popup displays
315
+ * in the parent application.
316
+ */
317
+ postPopup: PostPopup;
318
+ /**
319
+ * Posts a question or confirmation dialog configuration
320
+ * to the parent window.
321
+ *
322
+ * Typically used to prompt the user to confirm or
323
+ * make a decision in the parent application.
324
+ */
325
+ postQuestion: PostQuestion;
326
+ }
327
+
328
+ /**
329
+ * React hook for communicating iframe dimensions and messages
330
+ * to a parent window.
331
+ *
332
+ * This hook automatically:
333
+ * - Sends initial iframe dimensions on mount
334
+ * - Updates dimensions on DOM content load
335
+ * - Updates dimensions on window resize
336
+ *
337
+ * @param url - The target origin for `postMessage`
338
+ *
339
+ * @returns Functions for sending dimensions and posting custom messages
340
+ */
341
+ declare const usePostMessage: (url: string) => UsePostMessageReturn;
342
+
343
+ export { Button, type ButtonProps, DatePicker, Input, type InputProps, type NotificationType, SkeletonLoading, type SkeletonLoadingProps, usePostMessage, useSnackbar };
package/dist/index.d.ts CHANGED
@@ -1,25 +1,343 @@
1
- import { FC } from 'react';
1
+ import { FC, PropsWithChildren } from 'react';
2
2
 
3
+ /**
4
+ * Props for the Input component.
5
+ */
3
6
  interface InputProps {
7
+ /**
8
+ * Unique identifier for the input field.
9
+ * Used by react-hook-form as the field name.
10
+ */
4
11
  id: string;
12
+ /**
13
+ * Label text displayed above the input.
14
+ *
15
+ * @default "Label"
16
+ */
5
17
  label?: string;
18
+ /**
19
+ * Placeholder text shown when the input is empty.
20
+ *
21
+ * @default "Placeholder"
22
+ */
6
23
  placeholder?: string;
24
+ /**
25
+ * Marks the input as required in form validation.
26
+ *
27
+ * When true, react-hook-form will enforce a required rule.
28
+ *
29
+ * @default false
30
+ */
7
31
  required?: boolean;
32
+ /**
33
+ * Hides the label visually while keeping the input functional.
34
+ *
35
+ * Useful for compact layouts or custom label rendering.
36
+ *
37
+ * @default false
38
+ */
8
39
  hideLabel?: boolean;
40
+ /**
41
+ * Displays a loading indicator inside the input.
42
+ *
43
+ * Typically used while fetching or validating data.
44
+ *
45
+ * @default false
46
+ */
9
47
  loading?: boolean;
48
+ /**
49
+ * Disables the input field.
50
+ *
51
+ * Prevents user interaction and applies disabled styles.
52
+ *
53
+ * @default false
54
+ */
10
55
  disabled?: boolean;
11
56
  }
12
57
 
58
+ /** Create an input component including label
59
+ *
60
+ * This component needs to be wrap in FormProvider from react-hook-form
61
+ */
13
62
  declare const Input: FC<InputProps>;
14
63
 
15
64
  interface SkeletonLoadingProps {
16
65
  /** The border radius of the skeleton
17
66
  *
18
- * Default: 10
67
+ * @default 10
19
68
  */
20
69
  radius?: number;
21
70
  }
22
71
 
72
+ /** A skeleton loading with animation
73
+ *
74
+ * This needs to be wrap in a container with position: relative;
75
+ */
23
76
  declare const SkeletonLoading: FC<SkeletonLoadingProps>;
24
77
 
25
- export { Input, type InputProps, SkeletonLoading, type SkeletonLoadingProps };
78
+ /**
79
+ * Props for the Button component.
80
+ */
81
+ interface ButtonProps extends PropsWithChildren {
82
+ /**
83
+ * Callback fired when the button is clicked.
84
+ */
85
+ onClick: () => void;
86
+ /**
87
+ * Additional CSS class names to apply to the button.
88
+ *
89
+ * Useful for custom styling or utility classes.
90
+ */
91
+ className?: string;
92
+ /**
93
+ * Visual style of the button.
94
+ *
95
+ * @default "submit"
96
+ */
97
+ type?: "warning" | "danger" | "submit";
98
+ /**
99
+ * Displays a loading state inside the button.
100
+ *
101
+ * When true, the button may show a spinner and
102
+ * user interaction should be disabled.
103
+ *
104
+ * @default false
105
+ */
106
+ loading?: boolean;
107
+ /**
108
+ * Disables the button.
109
+ *
110
+ * Prevents click events and applies disabled styles.
111
+ *
112
+ * @default false
113
+ */
114
+ disabled?: boolean;
115
+ /**
116
+ * Size variant of the button.
117
+ *
118
+ * @default "default"
119
+ */
120
+ size?: "default" | "medium" | "small";
121
+ /**
122
+ * Removes the minimum width constraint from the button.
123
+ *
124
+ * Useful for icon-only or compact buttons.
125
+ *
126
+ * @default false
127
+ */
128
+ removeMinWidth?: boolean;
129
+ }
130
+
131
+ /** The button component with size and type */
132
+ declare const Button: FC<ButtonProps>;
133
+
134
+ interface DatePickerProps {
135
+ id: string;
136
+ label?: string;
137
+ placeholder?: string;
138
+ loading?: boolean;
139
+ disabled?: boolean;
140
+ }
141
+ declare const DatePicker: React.FC<DatePickerProps>;
142
+
143
+ type SnackbarType = "info" | "danger" | "warning" | "success";
144
+ interface SnackbarReturn {
145
+ /** To show the snackbar */
146
+ showSnackbar: (
147
+ /** Can be in any string format of the message to show */
148
+ message: string,
149
+ /** info, danger, warning or success - default: info */
150
+ type?: SnackbarType) => void;
151
+ }
152
+ /** Init the snackbar container
153
+ *
154
+ * @param id To set the id of the root container of the snackbar - default: snackbarRoot
155
+ * @param timeout To set the timeout on when the snackbar will be auto hide - default: 3000
156
+ */
157
+ declare const useSnackbar: (body?: HTMLElement | null, id?: string, timeout?: number) => SnackbarReturn;
158
+
159
+ /**
160
+ * Available notification types.
161
+ */
162
+ type NotiTypes = "default" | "error" | "warning" | "success";
163
+ /**
164
+ * Notification payload structure sent to the parent window.
165
+ */
166
+ interface NotificationType {
167
+ /**
168
+ * The notification message text.
169
+ */
170
+ message: string;
171
+ /**
172
+ * Notification visual type.
173
+ *
174
+ * @default "default"
175
+ */
176
+ type?: NotiTypes;
177
+ /**
178
+ * Duration (in milliseconds) before the notification auto-dismisses.
179
+ *
180
+ * @default undefined
181
+ */
182
+ duration?: number;
183
+ }
184
+ /**
185
+ * Configuration object for a popup component.
186
+ */
187
+ interface PopupType {
188
+ /**
189
+ * Title or header text displayed at the top of the popup.
190
+ */
191
+ header?: string;
192
+ /**
193
+ * Main content text displayed inside the popup.
194
+ *
195
+ * Can be plain text or formatted content depending on usage.
196
+ */
197
+ content?: string;
198
+ }
199
+ /**
200
+ * Configuration object for a confirmation or question dialog.
201
+ */
202
+ interface QuestionType {
203
+ /**
204
+ * Title or header text of the question dialog.
205
+ */
206
+ header: string;
207
+ /**
208
+ * Main content or message of the question.
209
+ *
210
+ * Typically explains what action the user is being asked to confirm.
211
+ */
212
+ content: string;
213
+ /**
214
+ * Value returned when the user confirms or selects "Yes".
215
+ *
216
+ * @default "Yes"
217
+ */
218
+ yesValue?: string;
219
+ /**
220
+ * Value returned when the user declines or selects "No".
221
+ *
222
+ * @default "No"
223
+ */
224
+ noValue?: string;
225
+ /**
226
+ * Indicates whether the action is destructive.
227
+ *
228
+ * When true, the dialog should visually emphasize caution
229
+ * (e.g. red buttons or warning styles).
230
+ *
231
+ * @default false
232
+ */
233
+ isDestructive?: boolean;
234
+ }
235
+ /**
236
+ * Function signature for posting a message to the parent window.
237
+ */
238
+ interface PostMessage {
239
+ /**
240
+ * Sends a message to the parent window via `window.postMessage`.
241
+ *
242
+ * @param data - The data payload to send to the parent window
243
+ */
244
+ (data: any): void;
245
+ }
246
+ /**
247
+ * Function signature for posting a notification message
248
+ * to the parent window.
249
+ */
250
+ interface PostNotification {
251
+ /**
252
+ * Sends a notification payload to the parent window.
253
+ *
254
+ * @param data - Notification data including message, type and duration
255
+ */
256
+ (data: NotificationType): void;
257
+ }
258
+ /**
259
+ * Function signature for posting a popup payload
260
+ * to the parent window.
261
+ */
262
+ interface PostPopup {
263
+ /**
264
+ * Sends a popup configuration to the parent window.
265
+ *
266
+ * Typically used to trigger modal or popup displays
267
+ * in the parent application.
268
+ *
269
+ * @param data - Popup configuration including header and content
270
+ */
271
+ (data: PopupType): void;
272
+ }
273
+ /**
274
+ * Function signature for posting a question or confirmation dialog
275
+ * to the parent window.
276
+ */
277
+ interface PostQuestion {
278
+ /**
279
+ * Sends a question configuration to the parent window.
280
+ *
281
+ * Typically used to trigger confirmation or decision dialogs
282
+ * in the parent application.
283
+ *
284
+ * @param data - Question configuration including content and response values
285
+ *
286
+ * @returns The yes or no text from the button that the user clicked
287
+ */
288
+ (data: QuestionType): Promise<string>;
289
+ }
290
+ /**
291
+ * Return object of the `usePostMessage` / `useIFrameDimensions` hook.
292
+ */
293
+ interface UsePostMessageReturn {
294
+ /**
295
+ * Sends the current iframe width and height to the parent window.
296
+ *
297
+ * Useful when the iframe content changes size dynamically.
298
+ */
299
+ sendDimension: () => void;
300
+ /**
301
+ * Posts a custom message to the parent window.
302
+ */
303
+ postMessage: PostMessage;
304
+ /**
305
+ * Posts a notification message to the parent window.
306
+ *
307
+ * Typically used to trigger toast/snackbar notifications
308
+ * in the parent application.
309
+ */
310
+ postNotification: PostNotification;
311
+ /**
312
+ * Posts a popup configuration to the parent window.
313
+ *
314
+ * Typically used to trigger modal or popup displays
315
+ * in the parent application.
316
+ */
317
+ postPopup: PostPopup;
318
+ /**
319
+ * Posts a question or confirmation dialog configuration
320
+ * to the parent window.
321
+ *
322
+ * Typically used to prompt the user to confirm or
323
+ * make a decision in the parent application.
324
+ */
325
+ postQuestion: PostQuestion;
326
+ }
327
+
328
+ /**
329
+ * React hook for communicating iframe dimensions and messages
330
+ * to a parent window.
331
+ *
332
+ * This hook automatically:
333
+ * - Sends initial iframe dimensions on mount
334
+ * - Updates dimensions on DOM content load
335
+ * - Updates dimensions on window resize
336
+ *
337
+ * @param url - The target origin for `postMessage`
338
+ *
339
+ * @returns Functions for sending dimensions and posting custom messages
340
+ */
341
+ declare const usePostMessage: (url: string) => UsePostMessageReturn;
342
+
343
+ export { Button, type ButtonProps, DatePicker, Input, type InputProps, type NotificationType, SkeletonLoading, type SkeletonLoadingProps, usePostMessage, useSnackbar };