@willphan1712000/frontend 1.0.3 → 1.2.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/dist/index.d.ts CHANGED
@@ -1,27 +1,25 @@
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;
12
- width?: string;
13
12
  }
14
13
  /**
15
14
  * Dropdown Select component, allowing users to select options from dropdown menu
16
15
  * @param options - list of options, which is an array of object [{ label: string, value: string }]
17
16
  * @param value - a chosen value
18
17
  * @param onChange - a function to set a value
19
- * @param width - specify the width of the component
20
18
  * @returns
21
19
  */
22
- declare const DropdownSelect: ({ options, value, onChange, width }: Props$5) => react_jsx_runtime.JSX.Element;
20
+ declare const DropdownSelect: ({ options, value, onChange }: Props$b) => react_jsx_runtime.JSX.Element;
23
21
 
24
- interface Props$4 {
22
+ interface Props$a {
25
23
  value: string;
26
24
  onChange: (value: string) => void;
27
25
  min?: string;
@@ -39,13 +37,13 @@ interface Props$4 {
39
37
  * @param onChange - to set a value
40
38
  * @returns
41
39
  */
42
- declare const RangeSlider: ({ min, max, color, width, value, onChange }: Props$4) => react_jsx_runtime.JSX.Element;
40
+ declare const RangeSlider: ({ min, max, color, width, value, onChange, }: Props$a) => react_jsx_runtime.JSX.Element;
43
41
 
44
42
  type Options$1 = {
45
43
  label: ReactNode;
46
44
  value: string;
47
45
  }[];
48
- interface Props$3 {
46
+ interface Props$9 {
49
47
  value: string;
50
48
  onChange: (value: string) => void;
51
49
  width?: string;
@@ -59,9 +57,9 @@ interface Props$3 {
59
57
  * @options - list of options, format [{ label: React Node Syntax, value: string }]
60
58
  * @returns
61
59
  */
62
- declare const OptionSlider: ({ value, onChange, width, options, color }: Props$3) => react_jsx_runtime.JSX.Element;
60
+ declare const OptionSlider: ({ value, onChange, width, options, color, }: Props$9) => react_jsx_runtime.JSX.Element;
63
61
 
64
- interface Props$2 {
62
+ interface Props$8 {
65
63
  value: string;
66
64
  onChange: (value: string) => void;
67
65
  width?: string;
@@ -73,13 +71,13 @@ interface Props$2 {
73
71
  * @param width
74
72
  * @returns
75
73
  */
76
- declare const ColorPickerSlider: ({ value, onChange, width }: Props$2) => react_jsx_runtime.JSX.Element;
74
+ declare const ColorPickerSlider: ({ value, onChange, width }: Props$8) => react_jsx_runtime.JSX.Element;
77
75
 
78
76
  type Options = {
79
77
  label: string;
80
78
  value: string;
81
79
  }[];
82
- interface Props$1 {
80
+ interface Props$7 {
83
81
  options: Options;
84
82
  value: string[];
85
83
  onChange: React.Dispatch<React.SetStateAction<string[]>>;
@@ -93,19 +91,22 @@ interface Props$1 {
93
91
  * @param width - specify the width of the component
94
92
  * @returns
95
93
  */
96
- declare const MultiSelect: ({ options, value, onChange, width }: Props$1) => react_jsx_runtime.JSX.Element;
94
+ declare const MultiSelect: ({ options, value, onChange, width }: Props$7) => react_jsx_runtime.JSX.Element;
97
95
 
98
- interface Props {
99
- buttonType: "gradient" | "solid" | "normal";
96
+ interface Props$6 {
97
+ buttonType?: 'gradient' | 'solid' | 'normal';
100
98
  }
101
99
  interface Data {
102
- content: string;
100
+ content?: string;
103
101
  main?: string;
104
102
  text?: string;
105
103
  first?: string;
106
104
  second?: string;
107
105
  isLoading?: boolean;
108
106
  }
107
+ interface Children {
108
+ children?: ReactNode;
109
+ }
109
110
  /**
110
111
  *
111
112
  * @param buttonType type of button, default is normal button
@@ -116,6 +117,262 @@ interface Data {
116
117
  * @param second second color when using gradient button, default is #aa6392
117
118
  * @returns button UI component
118
119
  */
119
- declare const Button: ({ buttonType, content, main, first, second, text, isLoading, ...props }: Props & Data & React.ComponentProps<"button">) => react_jsx_runtime.JSX.Element;
120
+ declare const Button: ({ buttonType, content, main, first, second, text, isLoading, children, ...props }: Props$6 & Data & Children & React.ComponentProps<"button">) => react_jsx_runtime.JSX.Element;
121
+
122
+ interface Props$5 {
123
+ src?: string;
124
+ setValue: (src?: string) => void;
125
+ }
126
+ /**
127
+ * Avatar component. Combination of
128
+ * - ImageEditor
129
+ * - Image
130
+ * - UploadImage
131
+ * - Button
132
+ *
133
+ * These components work together to provide smooth image editing process
134
+ *
135
+ * @param src source of an image which will be converted to base64 format automatically
136
+ * @param setValue set state function for src
137
+ *
138
+ * @example
139
+ * ... component declaration
140
+ * const [src, setValue] = useState<string|undefined>(initialImageStringUrl)
141
+ *
142
+ * return (
143
+ * <Avatar src={src} setValue={setValue} />
144
+ * )
145
+ */
146
+ declare const Avatar: ({ src, setValue }: Props$5) => react_jsx_runtime.JSX.Element;
147
+
148
+ interface Props$4 {
149
+ value?: string;
150
+ setValue?: (value?: string) => void;
151
+ label?: string;
152
+ options?: {
153
+ focusColor: string;
154
+ };
155
+ }
156
+ /**
157
+ * Input component shadows input box implemented by Google
158
+ *
159
+ * @link
160
+ * https://accounts.google.com
161
+ *
162
+ * @param value value of input
163
+ * @param setValue set value function
164
+ * @param options options object containing focusColor property -> color when input is focused
165
+ *
166
+ * @example
167
+ * ... component declaration
168
+ * const [value, setValue] = useState<string|undefined>('')
169
+ *
170
+ * return (
171
+ * <InputGoogle value={value} setValue={setValue} label="Input Google Component Label" options={{ focusColor: "yellow" }}/>
172
+ * )
173
+ */
174
+ declare const InputGoogle: ({ value, setValue, label, options, ...props }: Props$4 & React.ComponentProps<"input">) => react_jsx_runtime.JSX.Element;
175
+
176
+ interface Props$3 {
177
+ value?: string;
178
+ setValue?: (value?: string) => void;
179
+ label?: string;
180
+ options?: {
181
+ focusColor: string;
182
+ };
183
+ }
184
+ /**
185
+ * Textarea component
186
+ *
187
+ * @param value value of input
188
+ * @param setValue set value function
189
+ * @param options options object containing focusColor property -> color when input is focused
190
+ *
191
+ * @example
192
+ * ... component declaration
193
+ * const [value, setValue] = useState<string|undefined>('')
194
+ *
195
+ * return (
196
+ * <TextArea value={value} setValue={setValue} label="Text Component Label" options={{ focusColor: "yellow" }}/>
197
+ * )
198
+ */
199
+ declare const TextArea: ({ value, setValue, label, options, ...props }: Props$3 & React.ComponentProps<"textarea">) => react_jsx_runtime.JSX.Element;
200
+
201
+ 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';
202
+ interface Props$2 {
203
+ file?: File;
204
+ onChoose: (file: File) => void;
205
+ onCancel?: () => void;
206
+ acceptType?: FileType;
207
+ }
208
+ /**
209
+ * InputFile component
210
+ * @param file file object -> binary information
211
+ * @param onChoose if a file is chosen
212
+ * @param onCancel if a popup is closed without any chosen data
213
+ * @param acceptType accepted file type
214
+ */
215
+ declare const InputFile: ({ file, onChoose, onCancel, acceptType, ...props }: Props$2 & React$1.ComponentProps<"input">) => react_jsx_runtime.JSX.Element;
216
+
217
+ interface Props$1 {
218
+ setSrc?: (src?: string) => void;
219
+ }
220
+ /**
221
+ * Upload Image component
222
+ * - Upload image binary and convert it to base 64 format
223
+ * @param setSrc
224
+ * @returns
225
+ */
226
+ declare const UploadImage: ({ setSrc, ...props }: Props$1 & React.ComponentProps<"input">) => react_jsx_runtime.JSX.Element;
227
+
228
+ /**
229
+ * A wrap around HTML Image Element
230
+ * - Add default alt text
231
+ * - Add false draggable
232
+ */
233
+ declare const Image$1: ({ ...props }: React.ComponentProps<"img">) => react_jsx_runtime.JSX.Element;
234
+
235
+ interface Props {
236
+ src?: string;
237
+ setSrc?: (src?: string) => void;
238
+ isOpen?: boolean;
239
+ setOpen?: (open: boolean) => void;
240
+ isNew: boolean;
241
+ }
242
+ /**
243
+ * Image Editor component. This provides
244
+ * - Image transformation such as dragging, scaling, rotating
245
+ * - Color editing, contrast, ...
246
+ * - ...
247
+ *
248
+ * @param src source of an image to edit
249
+ * @param setSrc modify source state
250
+ * @param isOpen boolean open state of edit pannel
251
+ * @param setSrc modify open state
252
+ * @param isNew boolean - a random state that signals whether there is a new image that has been chosen. Toggle between true and false
253
+ *
254
+ * HOW IT WORKS
255
+ * - 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
256
+ * - 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.
257
+ * - 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
258
+ * - When hitting cancel button, it changes isOpen state
259
+ * - When hitting reset button, it runs reset method on transform object state
260
+ */
261
+ declare const ImageEditor: ({ src, setSrc, isOpen, setOpen, isNew, }: Props) => react_jsx_runtime.JSX.Element | undefined;
262
+
263
+ interface CanvasInterface {
264
+ /**
265
+ * Create a canvas
266
+ * @param number width of canvas
267
+ * @param number height of canvas
268
+ */
269
+ createCanvas(width: number, height: number): {
270
+ canvas: HTMLCanvasElement;
271
+ context: CanvasRenderingContext2D;
272
+ };
273
+ /**
274
+ * draw an image on canvas
275
+ */
276
+ drawImage(e: any, ctx: CanvasRenderingContext2D, x: number, y: number, scale: number, angle: number, canvas: HTMLCanvasElement, containerWidth: number, containerHeight: number): {
277
+ context: CanvasRenderingContext2D;
278
+ src: string;
279
+ };
280
+ /**
281
+ * Draw a color on canvas
282
+ */
283
+ drawColor(type: string, color: string, ctx: CanvasRenderingContext2D, width: number, ratio: number): [CanvasRenderingContext2D, string];
284
+ }
285
+ declare class Canvas implements CanvasInterface {
286
+ createCanvas(width: number, height: number): {
287
+ canvas: HTMLCanvasElement;
288
+ context: CanvasRenderingContext2D;
289
+ };
290
+ drawImage(e: HTMLImageElement, ctx: CanvasRenderingContext2D, x: number, y: number, scale: number, angle: number, canvas: HTMLCanvasElement, containerWidth: number, containerHeight: number): {
291
+ context: CanvasRenderingContext2D;
292
+ src: string;
293
+ };
294
+ drawColor(type: string, color: string, ctx: CanvasRenderingContext2D, width: number, ratio: number): [CanvasRenderingContext2D, string];
295
+ }
296
+
297
+ declare const Image: {
298
+ /**
299
+ * Convert file (blob) to base64 string format
300
+ * @param file
301
+ * @returns
302
+ */
303
+ FromFileToImageSrc(file?: File | Blob): Promise<string | null>;
304
+ /**
305
+ * Convert urlst
306
+ * @param url
307
+ * @returns
308
+ */
309
+ FromStringToImageSrc(url?: string): Promise<string | null>;
310
+ /**
311
+ * Check if the url is base64 format
312
+ * @param url
313
+ * @deprecated Using a weak condition and might be changed later. Use checkBase64 instead
314
+ */
315
+ checkBase64(url?: string): boolean;
316
+ isBase64(url?: string): boolean;
317
+ };
318
+
319
+ /**
320
+ * Element 1 : Image Wrapper
321
+ *
322
+ * Element 2 : Image Frame
323
+ *
324
+ * Element 3 : Image element
325
+ *
326
+ * Element 4 : Controller
327
+ *
328
+ * @example
329
+ * ```ts
330
+ * <div class="frame"> (2)
331
+ * <div class="wrapper"> (1)
332
+ * <img class="img__preview" /> (3)
333
+ * </div>
334
+ * </div>
335
+ * ```
336
+ */
337
+ declare class Transform {
338
+ private ele1;
339
+ private ele2;
340
+ private x;
341
+ private y;
342
+ private angle;
343
+ private w;
344
+ private h;
345
+ private wrapperClass;
346
+ private imgFrame;
347
+ private controllerClassName;
348
+ private frameClass;
349
+ private isRotateOffScreen;
350
+ private img;
351
+ private ratio;
352
+ private controllerContainer;
353
+ private controller;
354
+ constructor(ele1: HTMLElement, ele2?: HTMLElement, ele3?: string);
355
+ initialize(): Promise<void>;
356
+ reset(): void;
357
+ setState({ x, y, angle, w, }: {
358
+ x: number;
359
+ y: number;
360
+ angle: number;
361
+ w: number;
362
+ }): void;
363
+ private setValue;
364
+ exportData(): {
365
+ x: number;
366
+ y: number;
367
+ angle: number;
368
+ w: number;
369
+ h: number;
370
+ };
371
+ private repositionElement;
372
+ private resize;
373
+ private rotateBox;
374
+ private handleElementGoOffScreen;
375
+ private transform;
376
+ }
120
377
 
121
- export { Button, ColorPickerSlider, DropdownSelect, MultiSelect, OptionSlider, type Options$2 as Options, RangeSlider, type Options$1 as SliderOptions };
378
+ 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 };