@willphan1712000/frontend 1.0.3 → 1.1.0

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
@@ -33,10 +33,13 @@ You can connect to me at [Facebook](https://www.facebook.com/phanthanhnha123200/
33
33
  You can make contributions to this project by adding new UI ideas that stand out so we can compete ones generated by AI.
34
34
 
35
35
  To test a package, run
36
+
36
37
  ```npm
37
38
  npm link
38
39
  ```
39
- On the other frontend environment, run
40
+
41
+ On the other frontend environment, run
42
+
40
43
  ```npm
41
44
  npm link @willphan1712000/frontend
42
45
  ```
@@ -45,6 +48,7 @@ npm link @willphan1712000/frontend
45
48
  > if you encounter the problem "3. You might have more than one copy of React in the same app?"
46
49
  > it means your application has loaded two different React instances. This breaks React Hooks, which rely on a single, shared state.
47
50
  > Run this to connect to react in your testing project
51
+
48
52
  ```npm
49
53
  npm link <path_to_your_testing_project>/node_modules/react
50
- ```
54
+ ```
package/dist/index.d.mts CHANGED
@@ -1,11 +1,11 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ReactNode } from 'react';
2
+ import React$1, { ReactNode } from 'react';
3
3
 
4
4
  type Options$2 = {
5
5
  label: string;
6
6
  value: string;
7
7
  }[];
8
- interface Props$5 {
8
+ interface Props$b {
9
9
  options: Options$2;
10
10
  value: string;
11
11
  onChange: (value: string) => void;
@@ -19,9 +19,9 @@ interface Props$5 {
19
19
  * @param width - specify the width of the component
20
20
  * @returns
21
21
  */
22
- declare const DropdownSelect: ({ options, value, onChange, width }: Props$5) => react_jsx_runtime.JSX.Element;
22
+ declare const DropdownSelect: ({ options, value, onChange, width }: Props$b) => react_jsx_runtime.JSX.Element;
23
23
 
24
- interface Props$4 {
24
+ interface Props$a {
25
25
  value: string;
26
26
  onChange: (value: string) => void;
27
27
  min?: string;
@@ -39,13 +39,13 @@ interface Props$4 {
39
39
  * @param onChange - to set a value
40
40
  * @returns
41
41
  */
42
- declare const RangeSlider: ({ min, max, color, width, value, onChange }: Props$4) => react_jsx_runtime.JSX.Element;
42
+ declare const RangeSlider: ({ min, max, color, width, value, onChange, }: Props$a) => react_jsx_runtime.JSX.Element;
43
43
 
44
44
  type Options$1 = {
45
45
  label: ReactNode;
46
46
  value: string;
47
47
  }[];
48
- interface Props$3 {
48
+ interface Props$9 {
49
49
  value: string;
50
50
  onChange: (value: string) => void;
51
51
  width?: string;
@@ -59,9 +59,9 @@ interface Props$3 {
59
59
  * @options - list of options, format [{ label: React Node Syntax, value: string }]
60
60
  * @returns
61
61
  */
62
- declare const OptionSlider: ({ value, onChange, width, options, color }: Props$3) => react_jsx_runtime.JSX.Element;
62
+ declare const OptionSlider: ({ value, onChange, width, options, color, }: Props$9) => react_jsx_runtime.JSX.Element;
63
63
 
64
- interface Props$2 {
64
+ interface Props$8 {
65
65
  value: string;
66
66
  onChange: (value: string) => void;
67
67
  width?: string;
@@ -73,13 +73,13 @@ interface Props$2 {
73
73
  * @param width
74
74
  * @returns
75
75
  */
76
- declare const ColorPickerSlider: ({ value, onChange, width }: Props$2) => react_jsx_runtime.JSX.Element;
76
+ declare const ColorPickerSlider: ({ value, onChange, width }: Props$8) => react_jsx_runtime.JSX.Element;
77
77
 
78
78
  type Options = {
79
79
  label: string;
80
80
  value: string;
81
81
  }[];
82
- interface Props$1 {
82
+ interface Props$7 {
83
83
  options: Options;
84
84
  value: string[];
85
85
  onChange: React.Dispatch<React.SetStateAction<string[]>>;
@@ -93,19 +93,22 @@ interface Props$1 {
93
93
  * @param width - specify the width of the component
94
94
  * @returns
95
95
  */
96
- declare const MultiSelect: ({ options, value, onChange, width }: Props$1) => react_jsx_runtime.JSX.Element;
96
+ declare const MultiSelect: ({ options, value, onChange, width }: Props$7) => react_jsx_runtime.JSX.Element;
97
97
 
98
- interface Props {
99
- buttonType: "gradient" | "solid" | "normal";
98
+ interface Props$6 {
99
+ buttonType?: 'gradient' | 'solid' | 'normal';
100
100
  }
101
101
  interface Data {
102
- content: string;
102
+ content?: string;
103
103
  main?: string;
104
104
  text?: string;
105
105
  first?: string;
106
106
  second?: string;
107
107
  isLoading?: boolean;
108
108
  }
109
+ interface Children {
110
+ children?: ReactNode;
111
+ }
109
112
  /**
110
113
  *
111
114
  * @param buttonType type of button, default is normal button
@@ -116,6 +119,262 @@ interface Data {
116
119
  * @param second second color when using gradient button, default is #aa6392
117
120
  * @returns button UI component
118
121
  */
119
- declare const Button: ({ buttonType, content, main, first, second, text, isLoading, ...props }: Props & Data & React.ComponentProps<"button">) => react_jsx_runtime.JSX.Element;
122
+ declare const Button: ({ buttonType, content, main, first, second, text, isLoading, children, ...props }: Props$6 & Data & Children & React.ComponentProps<"button">) => react_jsx_runtime.JSX.Element;
123
+
124
+ interface Props$5 {
125
+ src?: string;
126
+ setValue: (src?: string) => void;
127
+ }
128
+ /**
129
+ * Avatar component. Combination of
130
+ * - ImageEditor
131
+ * - Image
132
+ * - UploadImage
133
+ * - Button
134
+ *
135
+ * These components work together to provide smooth image editing process
136
+ *
137
+ * @param src source of an image which will be converted to base64 format automatically
138
+ * @param setValue set state function for src
139
+ *
140
+ * @example
141
+ * ... component declaration
142
+ * const [src, setValue] = useState<string|undefined>(initialImageStringUrl)
143
+ *
144
+ * return (
145
+ * <Avatar src={src} setValue={setValue} />
146
+ * )
147
+ */
148
+ declare const Avatar: ({ src, setValue }: Props$5) => react_jsx_runtime.JSX.Element;
149
+
150
+ interface Props$4 {
151
+ value?: string;
152
+ setValue?: (value?: string) => void;
153
+ label?: string;
154
+ options?: {
155
+ focusColor: string;
156
+ };
157
+ }
158
+ /**
159
+ * Input component shadows input box implemented by Google
160
+ *
161
+ * @link
162
+ * https://accounts.google.com
163
+ *
164
+ * @param value value of input
165
+ * @param setValue set value function
166
+ * @param options options object containing focusColor property -> color when input is focused
167
+ *
168
+ * @example
169
+ * ... component declaration
170
+ * const [value, setValue] = useState<string|undefined>('')
171
+ *
172
+ * return (
173
+ * <InputGoogle value={value} setValue={setValue} label="Input Google Component Label" options={{ focusColor: "yellow" }}/>
174
+ * )
175
+ */
176
+ declare const InputGoogle: ({ value, setValue, label, options, ...props }: Props$4 & React.ComponentProps<"input">) => react_jsx_runtime.JSX.Element;
177
+
178
+ interface Props$3 {
179
+ value?: string;
180
+ setValue?: (value?: string) => void;
181
+ label?: string;
182
+ options?: {
183
+ focusColor: string;
184
+ };
185
+ }
186
+ /**
187
+ * Textarea component
188
+ *
189
+ * @param value value of input
190
+ * @param setValue set value function
191
+ * @param options options object containing focusColor property -> color when input is focused
192
+ *
193
+ * @example
194
+ * ... component declaration
195
+ * const [value, setValue] = useState<string|undefined>('')
196
+ *
197
+ * return (
198
+ * <TextArea value={value} setValue={setValue} label="Text Component Label" options={{ focusColor: "yellow" }}/>
199
+ * )
200
+ */
201
+ declare const TextArea: ({ value, setValue, label, options, ...props }: Props$3 & React.ComponentProps<"textarea">) => react_jsx_runtime.JSX.Element;
202
+
203
+ type FileType = 'image/*' | 'image/jpeg' | 'image/png' | 'image/gif' | 'image/webp' | 'image/svg+xml' | 'image/bmp' | 'image/tiff' | 'video/*' | 'video/mp4' | 'video/mpeg' | 'video/quicktime' | 'video/x-msvideo' | 'video/x-ms-wmv' | 'video/webm' | 'video/ogg' | 'audito/*' | 'audio/mpeg' | 'audio/wav' | 'audio/ogg' | 'audio/aac' | 'audio/flac' | 'audio/x-wav' | 'application/*' | 'application/pdf' | 'application/msword' | 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' | 'application/vnd.ms-excel' | 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' | 'application/vnd.ms-powerpoint' | 'application/vnd.openxmlformats-officedocument.presentationml.presentation' | 'text/plain' | 'text/csv' | 'application/json' | 'application/zip' | 'application/octet-stream' | 'application/x-tar' | 'application/x-rar-compressed';
204
+ interface Props$2 {
205
+ file?: File;
206
+ onChoose: (file: File) => void;
207
+ onCancel?: () => void;
208
+ acceptType?: FileType;
209
+ }
210
+ /**
211
+ * InputFile component
212
+ * @param file file object -> binary information
213
+ * @param onChoose if a file is chosen
214
+ * @param onCancel if a popup is closed without any chosen data
215
+ * @param acceptType accepted file type
216
+ */
217
+ declare const InputFile: ({ file, onChoose, onCancel, acceptType, ...props }: Props$2 & React$1.ComponentProps<"input">) => react_jsx_runtime.JSX.Element;
218
+
219
+ interface Props$1 {
220
+ setSrc?: (src?: string) => void;
221
+ }
222
+ /**
223
+ * Upload Image component
224
+ * - Upload image binary and convert it to base 64 format
225
+ * @param setSrc
226
+ * @returns
227
+ */
228
+ declare const UploadImage: ({ setSrc, ...props }: Props$1 & React.ComponentProps<"input">) => react_jsx_runtime.JSX.Element;
229
+
230
+ /**
231
+ * A wrap around HTML Image Element
232
+ * - Add default alt text
233
+ * - Add false draggable
234
+ */
235
+ declare const Image$1: ({ ...props }: React.ComponentProps<"img">) => react_jsx_runtime.JSX.Element;
236
+
237
+ interface Props {
238
+ src?: string;
239
+ setSrc?: (src?: string) => void;
240
+ isOpen?: boolean;
241
+ setOpen?: (open: boolean) => void;
242
+ isNew: boolean;
243
+ }
244
+ /**
245
+ * Image Editor component. This provides
246
+ * - Image transformation such as dragging, scaling, rotating
247
+ * - Color editing, contrast, ...
248
+ * - ...
249
+ *
250
+ * @param src source of an image to edit
251
+ * @param setSrc modify source state
252
+ * @param isOpen boolean open state of edit pannel
253
+ * @param setSrc modify open state
254
+ * @param isNew boolean - a random state that signals whether there is a new image that has been chosen. Toggle between true and false
255
+ *
256
+ * HOW IT WORKS
257
+ * - Use useMemo to memorize src value across renders until isNew changes. Also reset transformState to undefined, telling there is a new image that needs to be edited as new
258
+ * - When isOpen changes, it can either initialize a transform object on already rendered elements (that can either receive its previous state if exists or be reset as new) or set transform object to undefined.
259
+ * - When hitting Accept button, it uses handleCanvasToSrc function to draw current image src along with current transform state on a canvas, ready to extract a new image url from it. Then new src state value will be set and component re-renders
260
+ * - When hitting cancel button, it changes isOpen state
261
+ * - When hitting reset button, it runs reset method on transform object state
262
+ */
263
+ declare const ImageEditor: ({ src, setSrc, isOpen, setOpen, isNew, }: Props) => react_jsx_runtime.JSX.Element | undefined;
264
+
265
+ interface CanvasInterface {
266
+ /**
267
+ * Create a canvas
268
+ * @param number width of canvas
269
+ * @param number height of canvas
270
+ */
271
+ createCanvas(width: number, height: number): {
272
+ canvas: HTMLCanvasElement;
273
+ context: CanvasRenderingContext2D;
274
+ };
275
+ /**
276
+ * draw an image on canvas
277
+ */
278
+ drawImage(e: any, ctx: CanvasRenderingContext2D, x: number, y: number, scale: number, angle: number, canvas: HTMLCanvasElement, containerWidth: number, containerHeight: number): {
279
+ context: CanvasRenderingContext2D;
280
+ src: string;
281
+ };
282
+ /**
283
+ * Draw a color on canvas
284
+ */
285
+ drawColor(type: string, color: string, ctx: CanvasRenderingContext2D, width: number, ratio: number): [CanvasRenderingContext2D, string];
286
+ }
287
+ declare class Canvas implements CanvasInterface {
288
+ createCanvas(width: number, height: number): {
289
+ canvas: HTMLCanvasElement;
290
+ context: CanvasRenderingContext2D;
291
+ };
292
+ drawImage(e: HTMLImageElement, ctx: CanvasRenderingContext2D, x: number, y: number, scale: number, angle: number, canvas: HTMLCanvasElement, containerWidth: number, containerHeight: number): {
293
+ context: CanvasRenderingContext2D;
294
+ src: string;
295
+ };
296
+ drawColor(type: string, color: string, ctx: CanvasRenderingContext2D, width: number, ratio: number): [CanvasRenderingContext2D, string];
297
+ }
298
+
299
+ declare const Image: {
300
+ /**
301
+ * Convert file (blob) to base64 string format
302
+ * @param file
303
+ * @returns
304
+ */
305
+ FromFileToImageSrc(file?: File | Blob): Promise<string | null>;
306
+ /**
307
+ * Convert urlst
308
+ * @param url
309
+ * @returns
310
+ */
311
+ FromStringToImageSrc(url?: string): Promise<string | null>;
312
+ /**
313
+ * Check if the url is base64 format
314
+ * @param url
315
+ * @deprecated Using a weak condition and might be changed later. Use checkBase64 instead
316
+ */
317
+ checkBase64(url?: string): boolean;
318
+ isBase64(url?: string): boolean;
319
+ };
320
+
321
+ /**
322
+ * Element 1 : Image Wrapper
323
+ *
324
+ * Element 2 : Image Frame
325
+ *
326
+ * Element 3 : Image element
327
+ *
328
+ * Element 4 : Controller
329
+ *
330
+ * @example
331
+ * ```ts
332
+ * <div class="frame"> (2)
333
+ * <div class="wrapper"> (1)
334
+ * <img class="img__preview" /> (3)
335
+ * </div>
336
+ * </div>
337
+ * ```
338
+ */
339
+ declare class Transform {
340
+ private ele1;
341
+ private ele2;
342
+ private x;
343
+ private y;
344
+ private angle;
345
+ private w;
346
+ private h;
347
+ private wrapperClass;
348
+ private imgFrame;
349
+ private controllerClassName;
350
+ private frameClass;
351
+ private isRotateOffScreen;
352
+ private img;
353
+ private ratio;
354
+ private controllerContainer;
355
+ private controller;
356
+ constructor(ele1: HTMLElement, ele2?: HTMLElement, ele3?: string);
357
+ initialize(): Promise<void>;
358
+ reset(): void;
359
+ setState({ x, y, angle, w, }: {
360
+ x: number;
361
+ y: number;
362
+ angle: number;
363
+ w: number;
364
+ }): void;
365
+ private setValue;
366
+ exportData(): {
367
+ x: number;
368
+ y: number;
369
+ angle: number;
370
+ w: number;
371
+ h: number;
372
+ };
373
+ private repositionElement;
374
+ private resize;
375
+ private rotateBox;
376
+ private handleElementGoOffScreen;
377
+ private transform;
378
+ }
120
379
 
121
- export { Button, ColorPickerSlider, DropdownSelect, MultiSelect, OptionSlider, type Options$2 as Options, RangeSlider, type Options$1 as SliderOptions };
380
+ export { Avatar, Button, Canvas, ColorPickerSlider, DropdownSelect, Image$1 as Image, ImageEditor, Image as ImageUtilities, InputFile, InputGoogle, MultiSelect, OptionSlider, type Options$2 as Options, RangeSlider, type Options$1 as SliderOptions, TextArea, Transform, UploadImage };