esewa-ui-library 1.10.11 → 1.10.12

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,2164 +1,2167 @@
1
- # esewa-ui-library
2
- > UI Library for eSewa Mini App
3
-
4
- [![NPM](https://img.shields.io/npm/v/esewa-ui-library.svg)](https://www.npmjs.com/package/esewa-ui-library) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
5
-
6
- ## Install
7
-
8
- ```bash
9
- npm install --save esewa-ui-library
10
- ```
11
-
12
- ## Usage
13
-
14
- Import style file in your project:
15
- ```bash
16
- import 'esewa-ui-library/dist/index.css';
17
- ```
18
-
19
- ### Components
20
-
21
- Import and use components in your project:
22
-
23
- ```tsx
24
- import { ESewaButton } from 'esewa-ui-library';
25
- const App = () => {
26
- return <ESewaButton>Click Me</ESewaButton>;
27
- };
28
- export default App;
29
- ```
30
-
31
- ### Available Components
32
-
33
- - **AlertCard**: `ESewaAlertCard`
34
- - **AppBar**: `ESewaAppBar`
35
- - **Button**: `ESewaButton`
36
- - **Card**: `ESewaCard`
37
- - **Carousel**: `ESewaCarousel`
38
- - **Checkbox**: `ESewaCheckbox`
39
- - **Chipgroup**: `ESewaChipGroup`
40
- - **Datepicker**: `ESewaDatepicker`
41
- - **Dialog**: `ESewaDialog`
42
- - **Divider**: `ESewaDivider`
43
- - **FullPageLoadingScreen**: `EsewaFullPageLoadingScreen`
44
- - **Grid**: `ESewaGrid`, `ESewaGridItem`
45
- - **Icon**: `ESIcon`
46
- - **Image**: `ESewaImage`
47
- - **InputField**: `ESewaInputField`
48
- - **InputFieldTextArea**: `ESewaInputFeildTextArea`
49
- - **MultiSelect**: `ESewaMultiSelect`
50
- - **NepaliDatepicker**: `ESewaNepaliDatepicker`
51
- - **Radio**: `ESewaRadio`
52
- - **Select**: `ESewaSelectNative`
53
- - **Skeleton**: `ESewaSkeleton`
54
- - **Tag**: `ESewaTag`
55
- - **Tooltip**: `ESewaTooltip`
56
- ---
57
-
58
- ## ESewaAlertCard
59
-
60
- The `ESewaAlertCard` component is used to display alert messages with different variants, optional icons, dismiss buttons, and action buttons.
61
-
62
- ### Usage:
63
-
64
- ```tsx
65
- import { ESewaAlertCard } from 'esewa-ui-library';
66
-
67
- const App = () => {
68
- return (
69
- <ESewaAlertCard
70
- variant="warning"
71
- title="Warning Alert"
72
- description="This is a warning alert"
73
- titleIcon="fa fa-exclamation-circle"
74
- showDismissIcon={true}
75
- dismissIcon="fa fa-times"
76
- onDismiss={() => alert('Dismiss clicked')}
77
- showCardFooter={true}
78
- buttonLabel="Action"
79
- buttonOnClick={() => alert('Action clicked')}
80
- />
81
- );
82
- };
83
-
84
- export default App;
85
- ```
86
-
87
- ### Props:
88
-
89
- | Prop Name | Type | Default | Description |
90
- |----------------------|--------------------------------------------------|-------------|-------------|
91
- | `alertCardClass` | `string` | `''` | Additional class for custom styling |
92
- | `variant` | `'primary' | 'warning' | 'danger' | 'info'` | `'primary'` | Determines the alert style |
93
- | `title` | `string` | `undefined` | Title of the alert |
94
- | `description` | `string` | `undefined` | Alert description text |
95
- | `descriptionIcon` | `string` | `React.ReactNode` | `undefined` | Icon class for the description |
96
- | `showDescriptionIcon` | `boolean` | `false` | Whether to show the description icon |
97
- | `titleIcon` | `string` | `React.ReactNode` | `undefined` | Icon class for the title |
98
- | `dismissIcon` | `string` | `React.ReactNode` | `undefined` | Icon class for the dismiss button |
99
- | `showDismissIcon` | `boolean` | `false` | Whether to show the dismiss button |
100
- | `onDismiss` | `() => void` | `undefined` | Callback function when dismiss button is clicked |
101
- | `showCardFooter` | `boolean` | `false` | Whether to show the footer section |
102
- | `buttonLabel` | `string` | `undefined` | Label for the action button |
103
- | `buttonOnClick` | `() => void` | `undefined` | Callback function when the action button is clicked |
104
-
105
- ---
106
-
107
-
108
- ## ESewaAppBar
109
-
110
- The `ESewaAlertCard` component is customizable app bar for your eSewa Mini App with support for back, title, and action icons, making navigation and interactions seamless.
111
-
112
- Use useESewaDataProvider to set title for appbar.
113
-
114
- ### Usage:
115
-
116
- ```tsx
117
- import { ESewaAppBar, useESewaDataProvider } from 'esewa-ui-library';
118
-
119
- const App = () => {
120
- const { updateData } = useESewaDataProvider();
121
-
122
- useEffect(() => {
123
- updateData({
124
- title: "Merchant Product Form",
125
- });
126
- }, []);
127
-
128
- return (
129
- <ESewaAppBar
130
- icon="icon-es-arrow-left"
131
- titleposition="left"
132
- onBackIconClick={() => console.log('Back icon clicked')}
133
- onTitleClick={() => console.log('Title clicked')}
134
- onActionIconClick={() => console.log('Action icon clicked')}
135
- actionIcon="icon-settings"
136
- />
137
- );
138
- };
139
-
140
- export default App;
141
- ```
142
-
143
- ### Props:
144
-
145
- | Prop Name | Type | Default | Description |
146
- |-----------------------|---------------------------|----------|-------------|
147
- | `title` | `string | any` | `undefined` | Title to display in the app bar |
148
- | `icon` | `string`| `React.ReactNode`| `'icon-back'` | Icon to display as the back button |
149
- | `imageUrl` | `string` | `undefined` | Image URL to display next to the title |
150
- | `onBackIconClick` | `() => void` | `() => {}` | Callback for the back icon click event |
151
- | `onTitleClick` | `() => void` | `() => {}` | Callback for the title click event |
152
- | `onActionIconClick` | `() => void` | `() => {}` | Callback for the action icon click event |
153
- | `onClick` | `() => void` | `() => {}` | Callback for the entire app bar click event |
154
- | `className` | `string` | `undefined` | Additional class for custom styling |
155
- | `titleposition` | `'left' | 'center' | 'right'` | `'center'` | Position of the title within the app bar |
156
- | `actionIcon` | `string`| `React.ReactNode`| `undefined` | Icon for the action button on the right side of the app bar |
157
-
158
-
159
- # ESewaButton
160
-
161
- `ESewaButton` is a highly customizable button component built with React and styled using `styled-components`. It supports multiple variants, sizes, icon placement, and other button properties for flexible UI design.
162
-
163
- ### Usage:
164
-
165
- ```tsx
166
- import { ESewaButton } from 'esewa-ui-library';
167
-
168
- const App = () => {
169
- return (
170
- <ESewaButton
171
- type="button"
172
- variant="primary"
173
- onClick={handleClick}
174
- disabled={false}
175
- outlined={false}
176
- fullwidth={true}
177
- icon="icon-class"
178
- iconPlacement="start"
179
- size="large"
180
- textTransform="uppercase"
181
- >
182
- Click Me
183
- </ESewaButton>
184
- );
185
- };
186
-
187
- export default App;
188
- ```
189
-
190
-
191
- ### Props:
192
- | Name | Type | Default | Description |
193
- |----------------|---------------------------|-------------|--------------------------------------------------------------------------------------------------------------|
194
- | `type` | `'button' | 'submit' | 'reset'` | `'button'` | Specifies the type of the button. Options include `button`, `submit`, or `reset`. |
195
- | `variant` | `'primary' | 'secondary' | 'danger' | 'success' | 'warning' | 'info' | 'text'` | `'default'` | Specifies the variant style of the button. Choose from `primary`, `secondary`, `danger`, `success`, `warning`, `info`, or `text`. |
196
- | `onClick` | `(e: any) => void` | `undefined` | The function to execute when the button is clicked. |
197
- | `children` | `React.ReactNode` | `undefined` | The content of the button, typically text or icons. |
198
- | `disabled` | `boolean` | `false` | Disables the button if set to `true`. |
199
- | `outlined` | `boolean` | `false` | If `true`, the button will have an outline style. |
200
- | `className` | `string` | `''` | Additional CSS class(es) to apply to the button. |
201
- | `fullwidth` | `boolean` | `false` | If `true`, the button will span the full width of its container. |
202
- | `icon` | `string`| `React.ReactNode`| `
203
-
204
-
205
- ## Styling and Customization
206
-
207
- ### Button Size
208
-
209
- You can customize the button size using the `size` prop. The available sizes are:
210
-
211
- - `large`: Large button with more padding.
212
- - `medium`: Default button size.
213
- - `small`: Compact button with smaller padding.
214
-
215
- ### Button Variants
216
-
217
- The button supports various color variants that you can use by specifying the `variant` prop:
218
-
219
- - `primary`: The main action button style.
220
- - `secondary`: A secondary action style.
221
- - `danger`: A button to signify danger or warning actions.
222
- - `success`: For success actions.
223
- - `warning`: For warning actions.
224
- - `info`: A button for informational actions.
225
- - `text`: A text-only button with no background.
226
-
227
- ### Icon Customization
228
-
229
- You can add icons to your button using the `icon` prop. The icon will be displayed inside the button either before or after the button text, depending on the `iconPlacement` prop.
230
-
231
- - `iconPlacement` can be set to `start` (icon before text) or `end` (icon after text).
232
- - Use the `iconClass` prop to apply a custom class to the icon for further customization.
233
-
234
- ### Full Width Button
235
-
236
- To make the button span the full width of its container, set the `fullwidth` prop to `true`.
237
-
238
- ### Disabled Button
239
-
240
- If you want to disable the button, set the `disabled` prop to `true`. The button will appear grayed out and will not be clickable.
241
-
242
- ### Text Transform
243
-
244
- You can control the text transformation of the button text using the `textTransform` prop. Available options are:
245
-
246
- - `uppercase`: Converts the button text to uppercase.
247
- - `capitalized`: Capitalizes the first letter of each word.
248
-
249
- ## Example Usage
250
-
251
- ### Basic Example
252
-
253
- ```tsx
254
- import React from 'react';
255
- import { ESewaButton } from 'esewa-ui-library';
256
-
257
- const App = () => {
258
- return (
259
- <div>
260
- <ESewaButton variant="primary" onClick={() => alert('Button clicked!')}>
261
- Primary Button
262
- </ESewaButton>
263
- </div>
264
- );
265
- }
266
-
267
- export default App;
268
- ```
269
-
270
- # ESewaCard Component
271
-
272
- The `ESewaCard` component is a flexible and customizable card wrapper built with `styled-components` in React. It provides a container with background color, padding, and customizable border radius styles. You can use it to wrap content such as text, images, or other components to create a card-like layout.
273
-
274
- The card supports various border radius values through the `className` prop. The `ESewaCard` component is lightweight and can be customized with different CSS variables.
275
-
276
- ## Props
277
- | Name | Type | Default | Description |
278
- |-------------|---------------------|-------------|--------------------------------------------------------------------------------------|
279
- | `children` | `React.ReactNode` | `''` | The content inside the card. |
280
- | `className` | `string` | `''` | Additional CSS class(es) to apply to the card. |
281
-
282
- ## Styling and Customization
283
-
284
- The `ESewaCard` component uses CSS variables for styling, which allows for easy customization of the card's background, padding, border radius, and more.
285
-
286
- ### Border Radius Customization
287
-
288
- You can customize the card's border radius by adding the appropriate `className`:
289
-
290
- - `border-radius-0`: Border radius of `var(--values-value-0)`
291
- - `border-radius-2`: Border radius of `var(--values-value-2)`
292
- - `border-radius-4`: Border radius of `var(--values-value-4)`
293
- - `border-radius-6`: Border radius of `var(--values-value-6)`
294
- - `border-radius-8`: Border radius of `var(--values-value-8)`
295
- - `border-radius-10`: Border radius of `var(--values-value-10)`
296
- - `border-radius-12`: Border radius of `var(--values-value-12)`
297
- - `border-radius-14`: Border radius of `var(--values-value-14)`
298
- - `border-radius-16`: Border radius of `var(--values-value-16)`
299
- - `border-radius-round`: Border radius of `50%` (perfectly round card)
300
-
301
- ### Default Styling
302
-
303
- - **Background color**: `var(--card-bg)`
304
- - **Box-shadow**: `var(--shadow--1--umbra)`
305
- - **Text color**: `var(--text-dark)`
306
- - **Padding**: `var(--values-value-16)`
307
-
308
- ## Example Usage
309
-
310
- ### Basic Example
311
-
312
- ```tsx
313
- import React from 'react';
314
- import { ESewaCard } from 'esewa-ui-library';
315
-
316
- const App = () => {
317
- return (
318
- <div>
319
- <ESewaCard>
320
- <h3>Card Content</h3>
321
- <p>This is a simple card with content inside.</p>
322
- </ESewaCard>
323
- </div>
324
- );
325
- }
326
-
327
- export default App;
328
- ```
329
-
330
- ### Custom Border Radius Example
331
-
332
- You can customize the border radius of the `ESewaCard` component by using different `className` values. Below is an example of how to apply a custom border radius to the card.
333
-
334
- #### Example: Card with Border Radius 8
335
-
336
- ```tsx
337
- import React from 'react';
338
- import { ESewaCard } from 'esewa-ui-library';
339
-
340
- const App = () => {
341
- return (
342
- <div>
343
- <ESewaCard className="border-radius-8">
344
- <h3>Card with Border Radius 8</h3>
345
- <p>This card has a border radius of 8px.</p>
346
- </ESewaCard>
347
- </div>
348
- );
349
- }
350
-
351
- export default App;
352
- ```
353
-
354
- ## ESewaCarousel
355
-
356
- `ESewaCarousel` is a flexible and customizable carousel component built with React and styled-components. It supports both horizontal and vertical scrolling, customizable item sizes, and various features such as autoplay, navigation, and indicators.
357
-
358
- ### Features
359
- - Supports **horizontal** and **vertical** directions.
360
- - Ability to display **scrollbars** and customize their visibility.
361
- - **Navigation buttons** to scroll through items.
362
- - **Autoplay** functionality with configurable intervals.
363
- - **Indicators** to show the active item.
364
- - Customizable **width** and **height** for carousel items.
365
- - **Responsive** adjustments for smaller screens.
366
-
367
- ### Props
368
- | Prop | Type | Default Value | Description |
369
- |---------------------|--------------------------------|----------------|---------------------------------------------------------------------------------------------------|
370
- | `items` | `React.ReactNode[]` | `[]` | Array of items to display in the carousel. |
371
- | `direction` | `'horizontal' \| 'vertical'` | `'horizontal'` | Defines the direction of scrolling (horizontal or vertical). |
372
- | `itemWidth` | `string` | `'200px'` | Custom width of each item in the carousel. |
373
- | `itemHeight` | `string` | `'200px'` | Custom height of each item in the carousel. |
374
- | `showScrollbar` | `boolean` | `false` | Whether to display the scrollbar in the carousel. |
375
- | `showIndicator` | `boolean` | `true` | Whether to display the carousel indicators. |
376
- | `visibleItems` | `number` | `undefined` | Number of items to display at once in the carousel. |
377
- | `showNav` | `boolean` | `false` | Whether to show left and right navigation buttons. |
378
- | `autoplay` | `boolean` | `false` | Whether the carousel should autoplay. |
379
- | `autoplayInterval` | `number` | `3000` | Interval for autoplay in milliseconds (default 3000ms). |
380
- ### Styling
381
-
382
- The `ESewaCarousel` component is styled using `styled-components`. The component is fully customizable, and you can adjust the appearance by modifying the following properties in the CSS:
383
-
384
- - `background-color` for items (`--card-bg`)
385
- - `color` for text (`--body-color`)
386
- - Customizable scrollbar styles (`.carousel-wrapper.show-scrollbar`).
387
-
388
- ### Example Usage
389
-
390
- #### Horizontal Carousel
391
-
392
- ```tsx
393
- import React from 'react';
394
- import { ESewaCarousel } from 'esewa-ui-library';
395
-
396
- const items = [
397
- <div>Item 1</div>,
398
- <div>Item 2</div>,
399
- <div>Item 3</div>
400
- ];
401
-
402
- const App = () => {
403
- return (
404
- <ESewaCarousel
405
- items={items}
406
- direction="horizontal"
407
- itemWidth="250px"
408
- itemHeight="200px"
409
- showScrollbar
410
- showNav
411
- showIndicator
412
- autoplay
413
- autoplayInterval={4000}
414
- />
415
- );
416
- }
417
-
418
- export default App;
419
- ```
420
-
421
- # ESewaCheckbox Component
422
-
423
- The `ESewaCheckbox` component is a fully customizable checkbox built with React and styled using `styled-components`. It provides support for labels, disabled states, custom change handling, and additional styling flexibility through props.
424
-
425
- ## Features
426
-
427
- - **Customizable checkbox**: Allows the user to easily customize the checkbox with a label.
428
- - **Change handling**: Provides an `onChange` callback to handle state changes.
429
- - **Disabled state**: Supports disabling the checkbox.
430
- - **Custom styling**: Supports custom class names and additional styling flexibility via props.
431
-
432
- ## Usage
433
-
434
- ### Basic Usage
435
-
436
- To use the `ESewaCheckbox` component, import it and pass the necessary props to it.
437
-
438
- ```tsx
439
- import { ESewaCheckbox } from 'esewa-ui-library';
440
-
441
- const MyComponent = () => {
442
- const [isChecked, setIsChecked] = useState(false);
443
-
444
- const handleChange = (checked: boolean) => {
445
- setIsChecked(checked);
446
- };
447
-
448
- return (
449
- <ESewaCheckbox
450
- label="I agree to the terms"
451
- checked={isChecked}
452
- onChange={handleChange}
453
- />
454
- );
455
- };
456
- ```
457
-
458
- ## Props
459
- | Prop | Type | Default Value | Description |
460
- |---------------|-------------|---------------|---------------------------------------------------|
461
- | `label` | `string?` | `undefined` | The label text for the checkbox. |
462
- | `onChange` | `(checked: boolean) => void?` | `undefined` | Callback function to handle checkbox state change. |
463
- | `checked` | `boolean?` | `false` | The checked state of the checkbox. |
464
- | `labelClass` | `string?` | `''` | Class name for styling the label. |
465
- | `className` | `string?` | `''` | Custom class name for the checkbox container. |
466
- | `disabled` | `boolean?` | `false` | If true, disables the checkbox.
467
-
468
- # ESewaChipGroup Component
469
-
470
- ## Overview
471
-
472
- The `ESewaChipGroup` component is a customizable chip group component built with React and styled-components. It allows you to display a set of chips with selectable options. You can choose between single or multiple selection modes, with customizable styles and optional icons.
473
-
474
- ## Props
475
- | Prop | Type | Default Value | Description |
476
- |-----------------|---------------------------------|---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
477
- | `selection` | `'single' \| 'multiple'` | Required | Specifies the selection mode: `'single'` for single selection, `'multiple'` for multiple selection. |
478
- | `required` | `boolean?` | `false` | If true, ensures that at least one chip is selected when the selection mode is `'multiple'`. |
479
- | `chips` | `ChipProps[]` | Required | An array of chips to display. Each chip includes a text label, an optional icon, and an ID. |
480
- | `className` | `string?` | `''` | Optional custom class name for styling the chip container. |
481
- | `onChange` | `(selected: number[] | number) => void?` | `undefined` | Callback function to handle chip state change. |
482
-
483
- # ESewaDatePicker
484
-
485
- A customizable and accessible date picker component for React, built using **styled-components**.
486
-
487
- ## Features
488
-
489
- - Customizable label with a required indicator.
490
- - Supports `min` and `max` date restrictions.
491
- - Supports `readOnly` and `disabled` states.
492
- - Displays validation messages when needed.
493
- - Automatically focuses on the input when `autoFocus` is enabled.
494
- - Styled using `styled-components`.
495
-
496
-
497
- ## Usage
498
-
499
- ### Basic Example
500
-
501
- ```tsx
502
- import React, { useState } from "react";
503
- import { ESewaDatePicker } from 'esewa-ui-library';
504
-
505
- const App = () => {
506
- const [date, setDate] = useState("");
507
-
508
- return (
509
- <div>
510
- <ESewaDatePicker
511
- label="Select Date"
512
- name="date"
513
- value={date}
514
- onChange={(e) => setDate(e.target.value)}
515
- required
516
- />
517
- </div>
518
- );
519
- };
520
-
521
- export default App
522
- ```
523
-
524
- ## Example with Validation, Min & Max Dates
525
-
526
- ```tsx
527
- import React, { useState } from "react";
528
- import { ESewaDatePicker } from 'esewa-ui-library';
529
-
530
- const App = () => {
531
- const [date, setDate] = useState("");
532
-
533
- return (
534
- <div>
535
- <ESewaDatePicker
536
- label="Start Date"
537
- name="startDate"
538
- value={date}
539
- onChange={(e) => setDate(e.target.value)}
540
- min="2023-12-01"
541
- max="2024-12-31"
542
- validationMessage="Please select a valid date."
543
- required
544
- />
545
- </div>
546
- );
547
- };
548
-
549
- export default App;
550
- ```
551
-
552
- ## Props
553
-
554
- | Prop Name | Type | Default | Description |
555
- |--------------------|-------------------------------------------|-----------|-------------|
556
- | `id` | `string` | `undefined` | ID for the input field. |
557
- | `name` | `string` | `undefined` | Name attribute for the input field. |
558
- | `label` | `string` | `undefined` | Label text displayed above the input field. |
559
- | `value` | `string` | `undefined` | Selected date value (in `YYYY-MM-DD` format). |
560
- | `min` | `string` | `undefined` | Minimum selectable date (in `YYYY-MM-DD` format). |
561
- | `max` | `string` | `undefined` | Maximum selectable date (in `YYYY-MM-DD` format). |
562
- | `required` | `boolean` | `false` | Marks the field as required. |
563
- | `readOnly` | `boolean` | `false` | Makes the input read-only. |
564
- | `disabled` | `boolean` | `false` | Disables the input field. |
565
- | `className` | `string` | `""` | Additional class names for styling. |
566
- | `validationMessage`| `string` | `undefined` | Displays an error message below the input. |
567
- | `autoFocus` | `boolean` | `false` | Automatically focuses on the input when mounted. |
568
- | `onChange` | `(event: React.ChangeEvent<HTMLInputElement>) => void` | `undefined` | Callback function triggered on date change. |
569
-
570
-
571
- # ESewaDialog Component
572
-
573
- ## Usage
574
-
575
- The `ESewaDialog` component is a modal dialog used to display content with options like OK and Cancel actions. You can customize the dialog's appearance, positioning, and button texts.
576
-
577
- ### Example:
578
-
579
- ```tsx
580
- import React, { useState } from 'react';
581
- import { ESewaDialog } from 'esewa-ui-library';
582
-
583
- const App = () => {
584
- const [isOpen, setIsOpen] = useState(false);
585
-
586
- const openDialog = () => setIsOpen(true);
587
- const closeDialog = () => setIsOpen(false);
588
- const handleOk = () => {
589
- console.log('OK button clicked');
590
- closeDialog();
591
- };
592
-
593
- return (
594
- <div>
595
- <button onClick={openDialog}>Open Dialog</button>
596
-
597
- {
598
- isOpen && (<ESewaDialog
599
- isOpen={isOpen}
600
- title="Sample Dialog"
601
- okText="Confirm"
602
- cancelText="Cancel"
603
- onOk={handleOk}
604
- onCancel={closeDialog}
605
- position="center"
606
- >
607
- <p>Dialog content goes here.</p>
608
- </ESewaDialog>)
609
- }
610
- </div>
611
- );
612
- };
613
-
614
- export default App;
615
- ```
616
-
617
- ## Props
618
-
619
- | Prop Name | Type | Default | Description |
620
- |----------------------|------------------------------------------------------------|------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
621
- | `isOpen` | `boolean` | `false` | Controls the visibility of the dialog. |
622
- | `showLeftIcon` | `boolean` | `false` | Whether to show the left icon in the dialog header. |
623
- | `leftIcon` | `string` | `React.ReactNode` | `'icon-es-check'` | The icon class to be displayed in the left side of the dialog header. |
624
- | `showCloseIcon` | `boolean` | `false` | Whether to show the close icon in the dialog header. |
625
- | `closeIcon` | `string` | `'icon-es-close'` | The icon class for the close button. |
626
- | `okText` | `string` | `'OK'` | The text to be displayed on the OK button. |
627
- | `cancelText` | `string` | `'Cancel'` | The text to be displayed on the Cancel button. |
628
- | `title` | `string` | `undefined` | The title of the dialog. |
629
- | `children` | `React.ReactNode` | `undefined` | The content to be displayed in the body of the dialog. |
630
- | `onOk` | `() => void` | `undefined` | The callback function for the OK button click event. |
631
- | `onCancel` | `() => void` | `() => {}` | The callback function for the Cancel button click event or clicking outside the dialog. |
632
- | `position` | `'center' | 'top' | 'bottom'` | `'bottom'` | The position of the dialog on the screen. Can be `center`, `top`, or `bottom`. |
633
- | `disableSubmitButton`| `boolean` | `false` | Whether the OK button should be disabled.
634
- |
635
- # ESewaDivider Component
636
-
637
- The `ESewaDivider` component is a customizable divider line that can be used to separate content in your React application. You can customize the color, thickness, width, margin, and style (dotted or solid) of the divider.
638
-
639
- ## Usage
640
-
641
- To use the `ESewaDivider`, simply import it into your React component and include it in your JSX. You can customize the divider's appearance using the available props.
642
-
643
- ### Basic Usage
644
-
645
- ```tsx
646
- import React from 'react'
647
- import { ESewaDivider } from 'esewa-ui-library';
648
-
649
- const MyComponent = () => {
650
- return (
651
- <div>
652
- <p>Content above the divider</p>
653
- <ESewaDivider />
654
- <p>Content below the divider</p>
655
- </div>
656
- )
657
- }
658
- ```
659
-
660
- ## Props
661
-
662
- The `ESewaDivider` component accepts the following props to customize its appearance:
663
-
664
- | Prop | Type | Default Value | Description |
665
- |--------------|----------|------------------|---------------------------------------------------------------------------------------------------|
666
- | `color` | `string` | `'var(--border)'` | The color of the divider. You can specify any valid CSS color value. |
667
- | `thickness` | `string` | `'1px'` | The thickness of the divider. You can specify the value in `px`, `em`, `rem`, etc. |
668
- | `width` | `string` | `'100%'` | The width of the divider. You can specify a percentage, `px`, `em`, `rem`, etc. |
669
- | `margin` | `string` | `'8px 0'` | The margin around the divider. You can specify the margin in `px`, `em`, `rem`, etc. |
670
- | `className` | `string` | `''` (optional) | A custom CSS class for additional styling. |
671
- | `dotted` | `boolean`| `false` | If `true`, the divider will be styled with a dotted line (`dashed` style). Otherwise, it is solid. |
672
-
673
- ### Example
674
-
675
- ```tsx
676
- <ESewaDivider
677
- color="blue"
678
- thickness="2px"
679
- width="50%"
680
- margin="10px 0"
681
- dotted
682
- />
683
- ```
684
-
685
- In this example, the divider will be blue, 2px thick, 50% wide, with 10px margin on top and bottom, and have a dotted line style.
686
-
687
- # Full Page Loading Component
688
-
689
- The `EsewaFullPageLoadingScreen` component provides a full-page loading screen with a loading animation consisting of animated dots and an optional text message.
690
-
691
- ## Usage
692
-
693
- You can use the `EsewaFullPageLoadingScreen` component to show a loading screen with animated dots.
694
-
695
- ### Example Usage
696
-
697
- ```tsx
698
- import React from 'react';
699
- import { EsewaFullPageLoadingScreen } from 'esewa-ui-library';
700
-
701
- const App = () => {
702
- return (
703
- <div>
704
- {/* Display loading screen with a custom message */}
705
- <EsewaFullPageLoadingScreen text="Loading, please wait..." />
706
- </div>
707
- );
708
- };
709
-
710
- export default App;
711
- ```
712
-
713
- ## Props
714
-
715
- | Prop | Type | Default Value | Description |
716
- |--------|---------|---------------|-------------------------------------------------------------------------------------------------------|
717
- | `text` | `string` | `undefined` | Custom loading text that will be displayed next to the animated dots. If not provided, no text will be shown. |
718
-
719
-
720
- # `ESewaGrid` & `ESewaGridItem` Component
721
-
722
- ## Overview
723
-
724
- The `ESewaGrid` and `ESewaGridItem` components are used to create flexible grid layouts with a 12-column grid system. The `ESewaGrid` serves as the container for the grid, and the `ESewaGridItem` allows you to define the column span for individual items within the grid.
725
-
726
-
727
- ## Usage
728
-
729
- The `ESewaGrid` component is used to create a 12-column grid layout. You can use `ESewaGridItem` to define the number of columns an item will span within the grid.
730
-
731
- ### Example
732
-
733
- ```tsx
734
- import { ESewaGrid, ESewaGridItem } from './esewa-ui-library';
735
-
736
- const Example = () => {
737
- return (
738
- <ESewaGrid>
739
- <ESewaGridItem colSpan={4}>Item 1</ESewaGridItem>
740
- <ESewaGridItem colSpan={8}>Item 2</ESewaGridItem>
741
- <ESewaGridItem colSpan={12}>Item 3</ESewaGridItem>
742
- </ESewaGrid>
743
- );
744
- };
745
- ```
746
-
747
- In the example above:
748
- Item 1 spans 4 columns.
749
-
750
- Item 2 spans 8 columns.
751
-
752
- Item 3 spans all 12 columns.
753
-
754
- ## Props
755
-
756
- ### `ESewaGrid` Props
757
-
758
- | Prop | Type | Default Value | Description |
759
- |-----------|------------------|---------------|----------------------------------------------------------------------------|
760
- | `children`| `React.ReactNode` | Required | The content inside the grid container. |
761
- | `className`| `string` | `''` | Custom class name for styling the grid container. |
762
-
763
- ### `ESewaGridItem` Props
764
-
765
- | Prop | Type | Default Value | Description |
766
- |-----------|--------------------------------------------------------|---------------|-----------------------------------------------------------------------------|
767
- | `colSpan` | `1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12` | Required | Defines the number of columns the grid item will span (from 1 to 12). |
768
- | `children`| `React.ReactNode` | Required | The content inside the grid item. |
769
- | `className`| `string` | `''` | Custom class name for styling the grid item. |
770
-
771
- ## Example: ESewaGrid with All Column Spans
772
-
773
- ### Example: Usage of All Column Spans
774
-
775
- In this example, we use all possible column spans (from 1 to 12) to demonstrate how `ESewaGrid` and `ESewaGridItem` work:
776
-
777
- ```tsx
778
- import { ESewaGrid, ESewaGridItem } from './esewa-ui-library'
779
-
780
- const Example = () => {
781
- return (
782
- <ESewaGrid>
783
- <ESewaGridItem colSpan={1}>Item 1 (1 Column)</ESewaGridItem>
784
- <ESewaGridItem colSpan={2}>Item 2 (2 Columns)</ESewaGridItem>
785
- <ESewaGridItem colSpan={3}>Item 3 (3 Columns)</ESewaGridItem>
786
- <ESewaGridItem colSpan={4}>Item 4 (4 Columns)</ESewaGridItem>
787
- <ESewaGridItem colSpan={5}>Item 5 (5 Columns)</ESewaGridItem>
788
- <ESewaGridItem colSpan={6}>Item 6 (6 Columns)</ESewaGridItem>
789
- <ESewaGridItem colSpan={7}>Item 7 (7 Columns)</ESewaGridItem>
790
- <ESewaGridItem colSpan={8}>Item 8 (8 Columns)</ESewaGridItem>
791
- <ESewaGridItem colSpan={9}>Item 9 (9 Columns)</ESewaGridItem>
792
- <ESewaGridItem colSpan={10}>Item 10 (10 Columns)</ESewaGridItem>
793
- <ESewaGridItem colSpan={11}>Item 11 (11 Columns)</ESewaGridItem>
794
- <ESewaGridItem colSpan={12}>Item 12 (12 Columns)</ESewaGridItem>
795
- </ESewaGrid>
796
- )
797
- }
798
- ```
799
-
800
- # ESIcon Component
801
-
802
- The `ESIcon` component is a customizable icon component built using `styled-components` and CSS variables. It allows you to display an icon from a font icon set and customize its size and colors.
803
-
804
- ### Basic Example
805
-
806
- ```tsx
807
- import React from "react";
808
- import { ESIcon } from './esewa-ui-library'
809
-
810
- const App = () => {
811
- return (
812
- <div>
813
- <ESIcon icon="home" size={40} iconPrimaryColor="blue" iconSecondaryColor="gray" />
814
- <ESIcon icon="settings" size={30} iconPrimaryColor="green" />
815
- </div>
816
- );
817
- };
818
-
819
- export default App;
820
- ```
821
-
822
- ### Example with Custom Colors and Size, Multiple Icons
823
-
824
- In this example, we render multiple icons with custom sizes and colors.
825
-
826
- ```tsx
827
- import React from "react";
828
- import { ESIcon } from './esewa-ui-library'
829
-
830
- const App = () => {
831
- return (
832
- <div>
833
- <ESIcon icon="search" size={50} iconPrimaryColor="red" iconSecondaryColor="yellow" />
834
- <ESIcon icon="user" size={32} iconPrimaryColor="purple" />
835
- <ESIcon icon="cart" size={48} iconPrimaryColor="orange" iconSecondaryColor="black" />
836
- </div>
837
- );
838
- };
839
-
840
- export default App;
841
-
842
- ```
843
-
844
- ### ESIcon Component Props
845
-
846
- | Prop | Type | Default | Description |
847
- |---------------------|----------------------------------|-----------|--------------------------------------------------------------------|
848
- | `icon` | `string` | - | The name of the icon to display. This should be the icon class name (e.g., `search`, `user`, etc.). |
849
- | `size` | `number` | `28` | The size of the icon in pixels. |
850
- | `iconPrimaryColor` | `string` | `undefined` | The primary color of the icon. If not provided, the default color is used. |
851
- | `iconSecondaryColor`| `string` | `undefined` | The secondary color of the icon. If not provided, the default color is used. |
852
-
853
- ### Usage Example:
854
-
855
- ```tsx
856
- <ESIcon icon="search" size={50} iconPrimaryColor="red" iconSecondaryColor="yellow" />
857
- ```
858
-
859
- # ESewaImage Component
860
-
861
- `ESewaImage` is a React component that handles lazy-loading, error handling, and image preview in a modal. It provides functionality for images to be lazy-loaded when they enter the viewport, with a fallback image in case of error. It also allows the user to click on the image to open a larger preview in a modal.
862
-
863
- ## Features:
864
- - **Lazy Loading**: Image is loaded only when it is about to enter the viewport.
865
- - **Error Handling**: If the image fails to load, a fallback image is used.
866
- - **Image Preview**: Clicking the image opens it in a modal view.
867
- - **Customizable Styles**: Customize the width, height, and className of the image.
868
-
869
- ```tsx
870
- import { ESewaImage } from './esewa-ui-library'
871
-
872
- <ESewaImage
873
- src="https://example.com/image.jpg" // The source URL for the image
874
- alt="Description of the image" // Alt text for accessibility
875
- width="300" // Image width (can be string or number)
876
- height="200" // Image height (can be string or number)
877
- loading="lazy" // Lazy loading option (default is 'lazy')
878
- className="custom-class" // Optional custom class for styling
879
- fallbackSrc="https://example.com/fallback.jpg" // Fallback image URL
880
- />
881
- ```
882
-
883
- ## Props
884
-
885
- The `ESewaImage` component accepts the following props:
886
-
887
- | Prop | Type | Default Value | Description |
888
- |-----------------|---------------------------------------|-------------------|-----------------------------------------------------------------------------|
889
- | `src` | `string` | `fallbackImage` | The URL of the image to be displayed. |
890
- | `alt` | `string` | `https://` | The alt text for the image (for accessibility). |
891
- | `width` | `string | number` | - | The width of the image (can be a string like `'300px'` or a number like `300`). |
892
- | `height` | `string | number` | - | The height of the image (can be a string like `'200px'` or a number like `200`). |
893
- | `className` | `string` | - | Optional custom CSS class for styling the image. |
894
- | `fallbackSrc` | `string` | `fallbackImage` | The URL for the fallback image if the primary image fails to load. |
895
- | `loading` | `'lazy' | 'eager'` | `'lazy'` | Determines the image loading strategy: `'lazy'` or `'eager'`. |
896
-
897
-
898
- # ESewaInputField Component
899
-
900
- `ESewaInputField` is a customizable and reusable input field component for React. It supports various types of input fields (text, password, number, email, etc.) and comes with built-in validation messaging, styling, and accessibility features.
901
-
902
- ## Usage
903
-
904
- You can use the `ESewaInputField` component in your React application by following the steps below.
905
-
906
- ### Basic Usage
907
-
908
- ```tsx
909
- import React, { useState } from 'react';
910
- import { ESewaInputField } from './esewa-ui-library'
911
-
912
- const MyComponent = () => {
913
- const [inputValue, setInputValue] = useState('');
914
-
915
- const handleChange = (e) => {
916
- setInputValue(e.target.value);
917
- };
918
-
919
- return (
920
- <ESewaInputField
921
- type="text"
922
- label="Username"
923
- name="username"
924
- value={inputValue}
925
- onChange={handleChange}
926
- placeholder="Enter your username"
927
- required
928
- validationMessage="Username is required"
929
- />
930
- );
931
- };
932
-
933
- export default MyComponent;
934
- ```
935
-
936
- ## Props
937
-
938
- The `ESewaInputField` component accepts the following props:
939
-
940
- | Prop | Type | Default | Description |
941
- |--------------------|-----------------------------------------------------------|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
942
- | `id` | `string` | `undefined` | A unique identifier for the input field. |
943
- | `type` | `'text' | 'password' | 'number' | 'email' | 'date' | 'checkbox' | 'radio' | 'select' | 'textarea'` | `'text'` | The type of the input field. |
944
- | `name` | `string` | `undefined` | The name of the input field, used for form submissions. |
945
- | `label` | `string` | `undefined` | The label to display next to the input field. |
946
- | `placeholder` | `string` | `undefined` | The placeholder text displayed in the input field when it is empty. |
947
- | `value` | `string | number` | `undefined` | The current value of the input field. |
948
- | `checked` | `boolean` | `undefined` | Specifies whether the checkbox or radio button is checked (only applicable for `checkbox` and `radio` types). |
949
- | `pattern` | `string` | `undefined` | A regular expression that the input value must match (useful for email, password, etc.). |
950
- | `min` | `number` | `undefined` | The minimum value for `number`, `date`, or `range` input types. |
951
- | `max` | `number` | `undefined` | The maximum value for `number`, `date`, or `range` input types. |
952
- | `step` | `number` | `undefined` | The step value for `number`, `date`, or `range` input types. |
953
- | `required` | `boolean` | `false` | If `true`, the input field is required to be filled out before form submission. |
954
- | `readOnly` | `boolean` | `false` | If `true`, the input field is read-only, meaning the user cannot modify the value. |
955
- | `disabled` | `boolean` | `false` | If `true`, the input field is disabled, preventing user interaction. |
956
- | `className` | `string` | `''` | A custom class name to apply to the input field's container. |
957
- | `validationMessage`| `string` | `undefined` | A validation message that is displayed when the input is invalid or doesn't meet the specified requirements. |
958
- | `autoFocus` | `boolean` | `false` | If `true`, the input field will automatically receive focus when the component is rendered. |
959
- | `onChange` | `(e: React.ChangeEvent<HTMLInputElement>) => void` | `undefined` | A callback function that is called when the input value changes. The `onChange` function receives the change event as an argument. |
960
-
961
- ### Notes:
962
- - Some props are type-dependent. For example, `min`, `max`, and `step` are only relevant for `number`, `range`, or `date` input types.
963
- - The `required`, `readOnly`, and `disabled` props affect user interaction with the input field.
964
- - You can pass any additional attributes via the `rest` prop, which will be spread onto the underlying `<input>` element.
965
-
966
-
967
- # ESewaInputFeildTextArea Component
968
-
969
- The `ESewaInputFeildTextArea` component is a styled text area input field with customizable properties for labels, validation, and more. It provides a clean and consistent design for text area fields in React applications.
970
-
971
- ## Usage
972
-
973
- ### Basic Example
974
-
975
- ```tsx
976
- import { ESewaInputFeildTextArea } from './esewa-ui-library'
977
-
978
- const Example = () => {
979
- const [value, setValue] = useState('');
980
-
981
- const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
982
- setValue(e.target.value);
983
- };
984
-
985
- return (
986
- <ESewaInputFeildTextArea
987
- label="Your Message"
988
- value={value}
989
- onChange={handleChange}
990
- placeholder="Enter your message here"
991
- required
992
- validationMessage="Message is required"
993
- />
994
- );
995
- };
996
- ```
997
-
998
- With maxLength and rows
999
-
1000
- ```tsx
1001
- import { ESewaInputFeildTextArea } from './esewa-ui-library'
1002
-
1003
- const Example = () => {
1004
- const [value, setValue] = useState('');
1005
-
1006
- const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
1007
- setValue(e.target.value);
1008
- };
1009
-
1010
- return (
1011
- <ESewaInputFeildTextArea
1012
- label="Your Feedback"
1013
- value={value}
1014
- onChange={handleChange}
1015
- placeholder="Enter your feedback here"
1016
- maxLength={200}
1017
- rows={5}
1018
- required
1019
- validationMessage="Feedback is required"
1020
- />
1021
- );
1022
- };
1023
- ```
1024
-
1025
- In this example, the ESewaInputFeildTextArea is used with a label, value, onChange, placeholder, and optional maxLength and rows properties. You can customize the component further as needed based on the provided props.
1026
-
1027
- ## Props
1028
-
1029
- | Name | Type | Default | Description |
1030
- |-------------------|-----------------------------------|-------------|-----------------------------------------------------------------------------|
1031
- | `name` | `string` | - | The name of the textarea element. |
1032
- | `label` | `string` | - | The label text that is displayed above the textarea. |
1033
- | `placeholder` | `string` | - | The placeholder text that appears when the textarea is empty. |
1034
- | `value` | `string \| number` | - | The current value of the textarea. |
1035
- | `maxLength` | `number` | - | The maximum number of characters allowed in the textarea. |
1036
- | `required` | `boolean` | `false` | If `true`, the textarea becomes required when submitting the form. |
1037
- | `readOnly` | `boolean` | `false` | If `true`, the textarea is set to read-only. |
1038
- | `disabled` | `boolean` | `false` | If `true`, the textarea is disabled and cannot be interacted with. |
1039
- | `className` | `string` | - | Additional CSS class name(s) for custom styling. |
1040
- | `rows` | `number` | `3` | Defines the number of visible rows for the textarea. |
1041
- | `validationMessage`| `string` | - | An optional message to display when validation fails. |
1042
- | `onChange` | `(e: ChangeEvent<HTMLTextAreaElement>) => void` | - | Event handler function for handling text input changes. |
1043
-
1044
-
1045
- # ESewaMultiSelect Component
1046
-
1047
- The `ESewaMultiSelect` component is a customizable multi-select dropdown component built using React and styled-components. It allows users to select multiple options from a list, with a search feature and customizable styles.
1048
-
1049
- ## Usage
1050
-
1051
- To use the `ESewaMultiSelect` component in your React project, follow these steps:
1052
-
1053
- ### 1. Import the Component
1054
-
1055
- First, import the `ESewaMultiSelect` component in your React file:
1056
-
1057
- ### 2.Define Options and State
1058
- Create an array of options that will be displayed in the multi-select dropdown. You also need to set up state to handle the selected items.
1059
-
1060
- ```tsx
1061
- const [selectedItems, setSelectedItems] = useState([])
1062
-
1063
- const options = [
1064
- { value: '1', label: 'Option 1' },
1065
- { value: '2', label: 'Option 2' },
1066
- { value: '3', label: 'Option 3' },
1067
- { value: '4', label: 'Option 4' }
1068
- ]
1069
- ```
1070
-
1071
- ### 3. Handle Selection Changes
1072
- Define a handler function that will be called whenever the selection changes.
1073
-
1074
- const handleChange = (selected: Option[]) => {
1075
- setSelectedItems(selected)
1076
- }
1077
-
1078
- ### 4. Render the Component
1079
- Now you can render the ESewaMultiSelect component and pass in the necessary props:
1080
-
1081
- ```tsx
1082
- <ESewaMultiSelect
1083
- options={options}
1084
- onChange={handleChange}
1085
- placeholder="Select options"
1086
- />
1087
- ```
1088
-
1089
- ### 5. Display Selected Items
1090
- ```tsx
1091
- <div>
1092
- <h3>Selected Items</h3>
1093
- <ul>
1094
- {selectedItems.map(item => (
1095
- <li key={item.value}>{item.label}</li>
1096
- ))}
1097
- </ul>
1098
- </div>
1099
- ```
1100
-
1101
- ### Full Example
1102
-
1103
- ```tsx
1104
- import React, { useState } from 'react'
1105
- import { ESewaMultiSelect } from './esewa-ui-library'
1106
-
1107
- const MyComponent = () => {
1108
- const [selectedItems, setSelectedItems] = useState([])
1109
-
1110
- const options = [
1111
- { value: '1', label: 'Option 1' },
1112
- { value: '2', label: 'Option 2' },
1113
- { value: '3', label: 'Option 3' },
1114
- { value: '4', label: 'Option 4' }
1115
- ]
1116
-
1117
- const handleChange = (selected: Option[]) => {
1118
- setSelectedItems(selected)
1119
- }
1120
-
1121
- return (
1122
- <div>
1123
- <ESewaMultiSelect
1124
- options={options}
1125
- onChange={handleChange}
1126
- placeholder="Select options"
1127
- />
1128
- <div>
1129
- <h3>Selected Items</h3>
1130
- <ul>
1131
- {selectedItems.map(item => (
1132
- <li key={item.value}>{item.label}</li>
1133
- ))}
1134
- </ul>
1135
- </div>
1136
- </div>
1137
- )
1138
- }
1139
- ```
1140
-
1141
- # ESewaSelectNative Component
1142
-
1143
- The `ESewaSelectNative` is a customizable `select` dropdown component built with React and styled using `styled-components`. It provides a native `select` element with additional features such as labels, validation messages, and optional full-width styling.
1144
-
1145
- ## Usage
1146
-
1147
- Here is an example of how to use the `ESewaSelectNative` component in your React application:
1148
-
1149
- ```tsx
1150
- import React, { useState } from 'react';
1151
- import { ESewaSelectNative } from './esewa-ui-library'
1152
-
1153
- const ExampleComponent = () => {
1154
- const [selectedValue, setSelectedValue] = useState<string>('');
1155
-
1156
- const handleSelectChange = (value: string) => {
1157
- setSelectedValue(value);
1158
- };
1159
-
1160
- const options = [
1161
- { label: 'Option 1', value: '1' },
1162
- { label: 'Option 2', value: '2' },
1163
- { label: 'Option 3', value: '3' }
1164
- ];
1165
-
1166
- return (
1167
- <div>
1168
- <ESewaSelectNative
1169
- label="Select an Option"
1170
- placeholder="Choose an option"
1171
- options={options}
1172
- value={selectedValue}
1173
- onChange={handleSelectChange}
1174
- required
1175
- fullwidth
1176
- />
1177
- </div>
1178
- );
1179
- };
1180
- ```
1181
-
1182
- ## Props
1183
-
1184
- | Name | Type | Default | Description |
1185
- |---------------------|--------------------|-----------|-----------------------------------------------------------------------------|
1186
- | `options` | `Options[]` | `[]` | An array of objects representing the available options in the dropdown. |
1187
- | `placeholder` | `string` | `''` | Placeholder text shown when no option is selected. |
1188
- | `onChange` | `(value: string) => void` | `() => {}` | A callback function triggered when an option is selected. |
1189
- | `label` | `string` | `undefined` | The label displayed above the dropdown. |
1190
- | `value` | `string` | `undefined` | The currently selected value in the dropdown. |
1191
- | `disabled` | `boolean` | `false` | If `true`, disables the dropdown. |
1192
- | `validationMessage` | `string` | `undefined` | A validation message that is displayed below the select field. |
1193
- | `required` | `boolean` | `false` | If `true`, marks the field as required with an asterisk. |
1194
- | `fullwidth` | `boolean` | `false` | If `true`, the dropdown will take the full width of its container. |
1195
-
1196
- ### `Options` Type
1197
-
1198
- Each option is represented by an object with the following properties:
1199
-
1200
- | Name | Type | Description |
1201
- |---------|--------|--------------------------------------------------------|
1202
- | `label` | `string` | The label text displayed for the option. |
1203
- | `value` | `any` | The unique value associated with the option. |
1204
-
1205
- # ESewaNepaliDatepicker Component
1206
-
1207
- The `ESewaNepaliDatepicker` component is a React component for selecting a Nepali date using the `nepali-datepicker-reactjs` library. It allows users to select a date in Nepali format, and it also supports custom styling and locales.
1208
-
1209
- ## Usage
1210
-
1211
- Here is an example of how to use the `ESewaNepaliDatepicker` component in your React application:
1212
-
1213
- ```tsx
1214
- import React, { useState } from 'react'
1215
- import { ESewaNepaliDatepicker } from './esewa-ui-library'
1216
-
1217
- const App = () => {
1218
- const [date, setDate] = useState<string>('')
1219
-
1220
- const handleDateChange = (newDate: string) => {
1221
- setDate(newDate)
1222
- }
1223
-
1224
- return (
1225
- <div>
1226
- <ESewaNepaliDatepicker
1227
- label="Select Nepali Date"
1228
- value={date}
1229
- onChange={handleDateChange}
1230
- calenderLocale="ne" // You can use 'en' for English or 'ne' for Nepali locale
1231
- />
1232
- </div>
1233
- )
1234
- }
1235
-
1236
- export default App
1237
- ```
1238
-
1239
- ### Props
1240
-
1241
- The `ESewaNepaliDatepicker` component accepts the following props:
1242
-
1243
- | Prop Name | Type | Description | Default Value |
1244
- |------------------|------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|----------------|
1245
- | `label` | `string` | The label text to display above the date picker. | `undefined` |
1246
- | `className` | `string` | Custom class name to apply custom styles to the date picker component. | `undefined` |
1247
- | `value` | `string` | The current date value in the form of a string. | `undefined` |
1248
- | `onChange` | `(val: string) => void` | Callback function that is triggered when the selected date changes. It receives the selected date as a string. | `undefined` |
1249
- | `calenderLocale` | `'en' | 'ne'` | The locale of the calendar. Use `'en'` for the English calendar or `'ne'` for the Nepali calendar. | `'en'` |
1250
-
1251
- ### Example
1252
-
1253
- ```tsx
1254
- <ESewaNepaliDatepicker
1255
- label="Select Nepali Date"
1256
- value={date}
1257
- onChange={handleDateChange}
1258
- calenderLocale="ne"
1259
- />
1260
- ```
1261
-
1262
- # ESewaRadio Component
1263
-
1264
- The `ESewaRadio` component is a customizable radio button with a label, styled using `styled-components`. It supports the necessary props for usage in forms and customizable styling.
1265
-
1266
- ## 2. Using the Component
1267
-
1268
- After importing the `ESewaRadio` component, you can use it in your React components by passing the necessary props. Below is an example of how to use the radio button:
1269
-
1270
- ### Example Usage
1271
-
1272
- ```tsx
1273
- import React, { useState } from 'react';
1274
- import { ESewaRadio } from './esewa-ui-library'
1275
-
1276
- const MyComponent = () => {
1277
- const [isChecked, setChecked] = useState(false);
1278
-
1279
- return (
1280
- <div>
1281
- <ESewaRadio
1282
- label="Accept Terms and Conditions"
1283
- name="terms"
1284
- checked={isChecked}
1285
- onChange={(checked) => setChecked(checked)}
1286
- />
1287
- </div>
1288
- );
1289
- };
1290
-
1291
- export default MyComponent;
1292
- ```
1293
-
1294
- ## Explanation of Props
1295
-
1296
- The `ESewaRadio` component accepts the following props:
1297
-
1298
- ### `label`
1299
- - **Type:** `string`
1300
- - **Required:** No
1301
- - **Description:** This prop is used to display the label next to the radio button. It is an optional prop and can be omitted if no label is needed.
1302
-
1303
- ```tsx
1304
- <ESewaRadio label="Accept Terms and Conditions" ... />
1305
- ```
1306
- ## Props
1307
-
1308
- The `ESewaRadio` component accepts the following props:
1309
-
1310
- | Prop | Type | Required | Default Value | Description |
1311
- |-------------|-------------------------------|----------|---------------|--------------------------------------------------------------------------------------------------|
1312
- | `label` | `string` | No | `undefined` | The label displayed next to the radio button. |
1313
- | `name` | `string` | Yes | N/A | The name of the radio button, which groups it together with other radio buttons. |
1314
- | `onChange` | `(checked: boolean) => void` | No | `undefined` | Callback function that is triggered when the radio button's checked state changes. |
1315
- | `checked` | `boolean` | Yes | false | Determines whether the radio button is selected (`true`) or not (`false`). |
1316
- | `labelClass`| `string` | No | `''` | A custom class applied to the label element for styling. |
1317
- | `className` | `string` | No | `''` | A custom class applied to the root wrapper element of the radio button component. |
1318
- | `disabled` | `boolean` | No | false | Used to disable radio state |
1319
-
1320
- # ESewaSanitizeHtml Component
1321
-
1322
- The `ESewaSanitizeHtml` component sanitizes HTML content before rendering it in a React component. It ensures that the HTML content is safe and free from malicious code by using the `DOMPurify` library.
1323
-
1324
- ## Usage
1325
-
1326
- To use the `ESewaSanitizeHtml` component, simply pass the raw HTML content as the `html` prop. The component will sanitize the content to ensure it is safe for rendering.
1327
-
1328
- ### Example:
1329
-
1330
- ```tsx
1331
- import React from 'react'
1332
- import { ESewaSanitizeHtml } from './esewa-ui-library'
1333
-
1334
- const MyComponent = () => {
1335
- const rawHtml = '<p style="color:red">This is <b>sanitized</b> HTML content.</p>'
1336
-
1337
- return (
1338
- <div>
1339
- <h1>Sanitized HTML Example</h1>
1340
- <ESewaSanitizeHtml html={rawHtml} />
1341
- </div>
1342
- )
1343
- }
1344
-
1345
- export default MyComponent
1346
- ```
1347
-
1348
- ### In this example:
1349
-
1350
- - **rawHtml**: A string containing raw HTML content, including styles and tags such as `<p>` and `<b>`.
1351
- - **ESewaSanitizeHtml component**: The component receives the `html` prop (in this case, `rawHtml`) and sanitizes it using `DOMPurify`.
1352
- - **Sanitized HTML**: The sanitized HTML content is rendered inside a `div` element, using the `dangerouslySetInnerHTML` property.
1353
-
1354
- By passing the raw HTML to the component, it ensures that any potentially harmful content (like JavaScript or malicious code) is removed, making the content safe to render on the page.
1355
-
1356
- ### Props
1357
-
1358
- | Prop | Type | Description |
1359
- |---------|-----------------------|-----------------------------------------------------------------------------|
1360
- | `html` | `string | undefined` | The raw HTML string that needs to be sanitized. It can be `undefined` as well. |
1361
-
1362
- #### Prop Descriptions
1363
-
1364
- - **html**: This is the raw HTML content that you want to sanitize before rendering. It should be a string, and you can optionally pass `undefined` if no HTML is available to render.
1365
-
1366
- # ESewaSkeleton Component
1367
-
1368
- The `ESewaSkeleton` component provides a customizable skeleton loader UI. It is often used as a placeholder while content is loading or being fetched asynchronously. The skeleton loader can be customized to appear as a rectangle or a circle and can be styled with different dimensions.
1369
-
1370
- ### Example Usage
1371
-
1372
- ```tsx
1373
- import React, { useState, useEffect } from 'react'
1374
- import { ESewaSkeleton } from './esewa-ui-library'
1375
-
1376
- const YourComponent = () => {
1377
- const [loading, setLoading] = useState(true)
1378
-
1379
- useEffect(() => {
1380
- setTimeout(() => {
1381
- setLoading(false)
1382
- }, 2000) // Simulating an API call
1383
- }, [])
1384
-
1385
- return (
1386
- <div>
1387
- <ESewaSkeleton loading={loading} width="200px" height="20px">
1388
- <div>Content is loaded</div>
1389
- </ESewaSkeleton>
1390
- </div>
1391
- )
1392
- }
1393
- ```
1394
-
1395
- ### Props
1396
-
1397
- | Name | Type | Default | Description |
1398
- |-----------|--------------|--------------|---------------------------------------------------------|
1399
- | `loading` | `boolean` | `false` | Determines if the skeleton should be shown. |
1400
- | `width` | `string` | `100%` | Defines the width of the skeleton. |
1401
- | `height` | `string` | `20px` | Defines the height of the skeleton. |
1402
- | `circle` | `boolean` | `false` | Makes the skeleton circular (applies border-radius 50%). |
1403
- | `className` | `string` | `''` | Additional class names for styling. |
1404
- | `children` | `React.ReactNode` | `undefined` | Content to render when `loading` is false. |
1405
-
1406
-
1407
- ## ESewaTag Component
1408
-
1409
- The `ESewaTag` component is a flexible and customizable tag component used to display status labels, notifications, or simple tags with optional icons.
1410
-
1411
- ### Usage
1412
-
1413
- ```tsx
1414
- import React from 'react'
1415
- import { ESewaTag } from './esewa-ui-library'
1416
- import { FaCheckCircle } from 'react-icons/fa'
1417
-
1418
- const YourComponent = () => {
1419
- const handleTagClick = () => {
1420
- console.log('Tag clicked!')
1421
- }
1422
-
1423
- return (
1424
- <div>
1425
- <ESewaTag
1426
- text="Success Tag"
1427
- icon={<FaCheckCircle />}
1428
- variant="success"
1429
- iconPosition="start"
1430
- size="normal"
1431
- onClick={handleTagClick}
1432
- />
1433
-
1434
- <ESewaTag
1435
- text="Warning Tag"
1436
- variant="warning"
1437
- size="small"
1438
- onClick={handleTagClick}
1439
- />
1440
- </div>
1441
- )
1442
- }
1443
- ```
1444
-
1445
-
1446
- ### Props
1447
-
1448
- | Name | Type | Default | Description |
1449
- |----------------|----------------------|---------------|-----------------------------------------------------------------------------|
1450
- | `text` | `string` | - | The text content to display inside the tag. |
1451
- | `icon` | `string` | `React.ReactNode` | `undefined` | An optional icon to display alongside the text. |
1452
- | `variant` | `'primary' | 'secondary' | 'danger' | 'success' | 'warning' | 'info'` | `'primary'` | Defines the tag's color scheme. Available variants: `primary`, `secondary`, `danger`, `success`, `warning`, `info`. |
1453
- | `iconPosition` | `'start' | 'end'` | `'start'` | Defines the position of the icon. Choose between `start` (before text) or `end` (after text). |
1454
- | `size` | `'normal' | 'small'` | `'normal'` | Defines the size of the tag. Available sizes: `normal`, `small`. |
1455
- | `onClick` | `() => void` | `undefined` | A function to be triggered when the tag is clicked. |
1456
-
1457
-
1458
- ## Tooltip Component
1459
-
1460
- The `Tooltip` component provides an interactive tool-tip feature, displaying additional information when hovering over a target element. It is highly customizable, allowing the user to control the position of the tooltip and its appearance.
1461
-
1462
- ### Features
1463
-
1464
- - **Positioning**: Tooltips can be displayed on the top, bottom, left, or right of the target element.
1465
- - **Transitions**: Smooth fade-in and fade-out effect with controlled visibility and opacity transitions.
1466
- - **Customization**: Easily customizable styles with CSS variables and positioning options.
1467
-
1468
- ### Example Usage
1469
-
1470
- ```tsx
1471
- import React, { useState } from 'react'
1472
- import { ESewaTooltip } from './esewa-ui-library'
1473
-
1474
- const TooltipExample = () => {
1475
-
1476
- return (
1477
- <ESewaTooltip content='Tooltip on click' position='bottom'>
1478
- <button>Click Me</button>
1479
- </ESewaTooltip>
1480
- )
1481
- }
1482
-
1483
- export default TooltipExample
1484
- ```
1485
-
1486
- ### Props
1487
-
1488
- | Name | Type | Default | Description |
1489
- |------------------|-------------|------------|--------------------------------------------------------------------|
1490
- | `position` | `'top' | 'bottom' | 'left' | 'right'` | `'top'` | Determines where the tooltip will appear in relation to the target element. Available positions: `top`, `bottom`, `left`, `right`. |
1491
- | `content` | `string` | - | The content/text to display inside the tooltip. |
1492
- | `target` | `React.ReactNode` | - | The target element which will trigger the tooltip. |
1493
- | `delay` | `number` | `0` | The delay in milliseconds before the tooltip becomes visible. |
1494
- | `className` | `string` | `''` | Additional class names for styling or overriding default styles. |
1495
-
1496
- ### CSS Custom Variables
1497
-
1498
- - `--secondary`: Defines the background color of the tooltip.
1499
- - `--white`: Defines the text color of the tooltip.
1500
-
1501
-
1502
- ### Providers
1503
-
1504
- - **ThemeProvider**: `ThemeProvider`
1505
-
1506
- Wrap your component with this provider to apply theme.
1507
-
1508
- ```tsx
1509
- import { StrictMode } from 'react'
1510
- import { createRoot } from 'react-dom/client'
1511
- import { ESewaThemeProvider } from 'esewa-ui-library'
1512
- import App from './App.tsx'
1513
-
1514
- createRoot(document.getElementById('root')!).render(
1515
- <StrictMode>
1516
- <ESewaThemeProvider>
1517
- <App />
1518
- </ESewaThemeProvider>
1519
- </StrictMode>,
1520
- )
1521
-
1522
- ```
1523
-
1524
- In your page
1525
-
1526
- ```tsx
1527
- import { useEffect, useState } from "react";
1528
- import {
1529
- MoonIcon,
1530
- SunIcon,
1531
- } from "@heroicons/react/24/outline";
1532
-
1533
- const [darkMode, setDarkMode] = useState<boolean>(
1534
- window.matchMedia('(prefers-color-scheme: dark)').matches
1535
- );
1536
-
1537
- const handleThemeToggle = () => {
1538
- setDarkMode((prevMode) => !prevMode);
1539
- };
1540
-
1541
- useEffect(() => {
1542
- const theme = darkMode ? 'dark' : 'light';
1543
- document.documentElement.setAttribute('data-theme', theme);
1544
- }, [darkMode]);
1545
-
1546
- <button
1547
- onClick={handleThemeToggle}
1548
- >
1549
- {darkMode ? (
1550
- <SunIcon className="h-6 w-6" />
1551
- ) : (
1552
- <MoonIcon className="h-6 w-6" />
1553
- )}
1554
- </button>
1555
-
1556
- ```
1557
-
1558
- - **ESewaProvider**: `ESewaProvider`
1559
-
1560
- Wrap your component with this provider.
1561
-
1562
- ```tsx
1563
- import { StrictMode } from 'react'
1564
- import { createRoot } from 'react-dom/client'
1565
- import { ESewaProvider } from 'esewa-ui-library'
1566
- import App from './App.tsx'
1567
-
1568
- createRoot(document.getElementById('root')!).render(
1569
- <StrictMode>
1570
- <ESewaProvider>
1571
- <App />
1572
- </ESewaProvider>
1573
- </StrictMode>,
1574
- )
1575
-
1576
- ```
1577
-
1578
- then you can use useESewaDataProvider
1579
-
1580
- ```tsx
1581
- import { ESewaAppBar, useESewaDataProvider } from 'esewa-ui-library';
1582
-
1583
- const App = () => {
1584
- const { updateData } = useESewaDataProvider();
1585
-
1586
- useEffect(() => {
1587
- updateData({
1588
- title: "Merchant Product Form",
1589
- });
1590
- }, []);
1591
-
1592
- return (
1593
- <ESewaAppBar
1594
- icon="icon-es-arrow-left"
1595
- titleposition="left"
1596
- onBackIconClick={() => console.log('Back icon clicked')}
1597
- onTitleClick={() => console.log('Title clicked')}
1598
- onActionIconClick={() => console.log('Action icon clicked')}
1599
- actionIcon="icon-settings"
1600
- />
1601
- );
1602
- };
1603
-
1604
- export default App;
1605
-
1606
- ```
1607
-
1608
-
1609
- - **ESewaPaymentProvider**: `ESewaPaymentProvider`
1610
-
1611
- # Services
1612
-
1613
- ## Overview
1614
-
1615
- This library provides a set of services that allow interaction between the merchant app and the host application. These services include authentication, location access, user detail retrieval, media access, and transaction validation.
1616
-
1617
- ## Table of Contents
1618
-
1619
- - [Initialization](#initialization)
1620
- - [Service Requests](#service-requests)
1621
- - [Location Request](#location-request)
1622
- - [User Detail Request](#user-detail-request)
1623
- - [Media Access Request](#media-access-request)
1624
- - [Validate Payment](#validate-payment)
1625
- - [Request Payment](#request-payment)
1626
- - [Close App](#close-app)
1627
- - [Get Product](#get-product)
1628
- - [Validate User](#validate-user)
1629
- - [Merchant Detail](#merchant-detail)
1630
- - [QR Scanner Request](#qr-scanner-request)
1631
- - [Request File Download](#request-file-download)
1632
- - [Error Handling](#error-handling)
1633
-
1634
- ## Initialization
1635
-
1636
- Before the app loads, it must be initialized to obtain authentication credentials.
1637
-
1638
- ### Usage
1639
-
1640
- ```tsx
1641
- useEffect(() => {
1642
- const saveAuthData = (res: { token?: string; scope?: any }): void => {
1643
- if (!res?.token) {
1644
- console.warn('Token is missing, skipping storage');
1645
- return;
1646
- }
1647
- sessionStorage.setItem('miniAppAuthToken', res.token);
1648
- sessionStorage.setItem('miniAppAuthScope', JSON.stringify(res.scope || {}));
1649
- };
1650
-
1651
- const initAppCallback = (data: any) => {
1652
- try {
1653
- if (!data) {
1654
- throw new Error('Received null or undefined response');
1655
- }
1656
- const res = JSON.parse(data);
1657
- if (!res || typeof res !== 'object') {
1658
- throw new Error('Parsed response is not a valid object');
1659
- }
1660
- if (res?.error_message) {
1661
- return;
1662
- }
1663
- saveAuthData(res);
1664
- } catch (error) {
1665
- console.error('Error parsing response:', error);
1666
- }
1667
- };
1668
-
1669
- const requestData = {
1670
- merchant_identifier: 'IAAAAABTOBAbFhAXHhEHAgoXX0FRR1FJJiw3LCwkJzE=', //your identifier key
1671
- requestType: REQUEST_TYPE_ENUM.INIT_APP,
1672
- callbackKey: CALLBACK_TYPE_ENUM.INIT_APP_CALLBACK
1673
- };
1674
-
1675
- requestFromMiniApp(requestData, initAppCallback);
1676
- }, []);
1677
- ```
1678
-
1679
- ### Response Examples
1680
-
1681
- #### Success
1682
-
1683
- ```json
1684
- {
1685
- "token": "SEdcRFVePhYfCRtQJhEiATA8DyVWFFA7Dw8UBEAKH1IkLFwYJAUxPgI%3D",
1686
- "scope": [
1687
- "USER_DETAIL_ACCESS",
1688
- "LOCATION_ACCESS",
1689
- "MEDIA_ACCESS"
1690
- ]
1691
- }
1692
- ```
1693
-
1694
- #### Error
1695
-
1696
- ```json
1697
- {
1698
- "error_message": "Service is currently unavailable."
1699
- }
1700
- ```
1701
-
1702
- ## Service Requests
1703
- Merchants can only request services that are included in their granted scope. Before making a request, ensure the service type exists in scope.
1704
-
1705
- #### Location Request
1706
-
1707
- Pass the token received from initialization to request location access.
1708
-
1709
- ```tsx
1710
- const onLocationRequestClick = () => {
1711
- const obj: REQUEST_DATA_TYPE = {
1712
- requestType: REQUEST_TYPE_ENUM.LOCATION_ACCESS,
1713
- token: sessionStorage.getItem('miniAppAuthToken'),
1714
- callbackKey: CALLBACK_TYPE_ENUM.LOCATION_ACCESS_CALLBACK
1715
- }
1716
-
1717
- const locationAccessCallBack: any = (data: any) => {
1718
- console.log('Location Access Response:', data)
1719
-
1720
- try {
1721
- if (!data) {
1722
- throw new Error('Received null or undefined response')
1723
- }
1724
- const res = JSON.parse(data)
1725
- if (!res || typeof res !== 'object') {
1726
- throw new Error('Parsed response is not a valid object')
1727
- }
1728
- if (res?.error_message) {
1729
- throw new Error('Error res', res.error_message)
1730
- }
1731
- setLocationDetail(res) //use this response as needed
1732
- } catch (error) {
1733
- console.error('Error parsing response:', error)
1734
- }
1735
- }
1736
-
1737
- requestFromMiniApp(
1738
- obj,
1739
- locationAccessCallBack
1740
- )
1741
- }
1742
- ```
1743
-
1744
- #### User Detail Request
1745
-
1746
- ```tsx
1747
- const onUserDetailRequestClick = () => {
1748
- const obj = {
1749
- requestType: REQUEST_TYPE_ENUM.USER_DETAIL_ACCESS,
1750
- token: sessionStorage.getItem('miniAppAuthToken'),
1751
- merchant_identifier: 'IAAAAABTOBAbFhAXHhEHAgoXX0FRR1FJJiw3LCwkJzE=',
1752
- callbackKey: CALLBACK_TYPE_ENUM.USER_DETAIL_ACCESS_CALLBACK
1753
- };
1754
-
1755
- const userDetailAccessCallBack = (data: any) => {
1756
- try {
1757
- if (!data) throw new Error('Received null or undefined response');
1758
- const res = JSON.parse(data);
1759
- if (res?.error_message) throw new Error(res.error_message);
1760
- setUserDetail(res);
1761
- } catch (error) {
1762
- console.error('Error parsing response:', error);
1763
- }
1764
- };
1765
-
1766
- requestFromMiniApp(obj, userDetailAccessCallBack);
1767
- };
1768
- ```
1769
-
1770
- #### Media Access Request
1771
-
1772
- ```tsx
1773
- const onMediaAccessRequestClick = () => {
1774
- const obj = {
1775
- requestType: REQUEST_TYPE_ENUM.MEDIA_ACCESS,
1776
- token: sessionStorage.getItem('miniAppAuthToken'),
1777
- callbackKey: CALLBACK_TYPE_ENUM.MEDIA_ACCESS_CALLBACK
1778
- };
1779
-
1780
- const mediaAccessCallBack = (data: any) => {
1781
- try {
1782
- if (!data) throw new Error('Received null or undefined response');
1783
- const res = data;
1784
- if (res?.error_message) throw new Error(res.error_message);
1785
- setMediaDetail(res);
1786
- } catch (error) {
1787
- console.error('Error parsing response:', error);
1788
- }
1789
- };
1790
-
1791
- requestFromMiniApp(obj, mediaAccessCallBack);
1792
- };
1793
- ```
1794
-
1795
- #### Validate Payment
1796
- Pass token received from initialize request call with respective request type and callback key
1797
-
1798
- ```tsx
1799
- const onValidateTransactionClick = () => {
1800
- const obj = {
1801
- requestType: REQUEST_TYPE_ENUM.VALIDATE_TRANSACTION,
1802
- token: sessionStorage.getItem('miniAppAuthToken'),
1803
- callbackKey: CALLBACK_TYPE_ENUM.VALIDATE_TRANSACTION_CALLBACK
1804
- };
1805
-
1806
- const validateTransactionCallBack = (data: any) => {
1807
- try {
1808
- if (!data) throw new Error('Received null or undefined response');
1809
- const res = JSON.parse(data);
1810
- if (res?.error_message) throw new Error(res.error_message);
1811
- setTransactionValidateRes(res);
1812
- } catch (error) {
1813
- console.error('Error parsing response:', error);
1814
- }
1815
- };
1816
-
1817
- requestFromMiniApp(obj, validateTransactionCallBack);
1818
- };
1819
- ```
1820
- #### Request Payment
1821
- Pass token received from initialize request call with respective request type, callback key , your merchant identifier and request payload
1822
-
1823
- ```tsx
1824
- const onRequestPaymentClick = () => {
1825
- const productPayload = {
1826
- "product_code": "NP-ES-VIANET",
1827
- "amount": 28.48,
1828
- "properties": {
1829
- "productId": "3299",
1830
- "payment_id": "1613103_PP",
1831
- "refId": "400005",
1832
- "customer_id": "48707",
1833
- "payer": "CUSTOMER"
1834
- },
1835
- "channel": "WEB_USER"
1836
- };
1837
-
1838
- const obj = {
1839
- requestType: REQUEST_TYPE_ENUM.REQUEST_PAYMENT,
1840
- merchant_identifier: 'IAAAAABTOBAbFhAXHhEHAgoXX0FRR1FJJiw3LCwkJzE=',
1841
- token: sessionStorage.getItem('miniAppAuthToken'),
1842
- data: productPayload,
1843
- callbackKey: CALLBACK_TYPE_ENUM.REQUEST_PAYMENT_CALLBACK
1844
- };
1845
-
1846
- const requestPaymentCallBack: any = (data:any) => {
1847
- console.log("Make payment Response:", data);
1848
-
1849
- try {
1850
- if (!data) {
1851
- throw new Error('Received null or undefined response');
1852
- }
1853
- const res = JSON.parse(data);
1854
-
1855
- if (!res || typeof res !== 'object') {
1856
- throw new Error('Parsed response is not a valid object');
1857
- }
1858
-
1859
- if (res?.error_message) {
1860
- throw new Error('Error res', res.error_message);
1861
- }
1862
-
1863
- setMakePaymentRes(res);
1864
- } catch (error) {
1865
- console.error('Error parsing response:', error);
1866
- }
1867
- };
1868
-
1869
- requestFromMiniApp(obj, requestPaymentCallBack);
1870
- };
1871
- ```
1872
-
1873
- #### Close App
1874
-
1875
- Pass the following to close the app.
1876
-
1877
- ```tsx
1878
- const onCloseRequestClick = () => {
1879
- const obj: REQUEST_DATA_TYPE = {
1880
- requestType: REQUEST_TYPE_ENUM.CLOSE_APP,
1881
- callbackKey: CALLBACK_TYPE_ENUM.CLOSE_APP_CALLBACK
1882
- }
1883
-
1884
- requestFromMiniApp(
1885
- obj
1886
- )
1887
- }
1888
- ```
1889
-
1890
- #### Get Product Request
1891
-
1892
- ```tsx
1893
- const onGetProductClick = () => {
1894
- const obj = {
1895
- requestType: REQUEST_TYPE_ENUM.GET_PRODUCT,
1896
- token: sessionStorage.getItem('miniAppAuthToken'),
1897
- callbackKey: CALLBACK_TYPE_ENUM.GET_PRODUCT_CALLBACK
1898
- };
1899
-
1900
- const getProductCallBack = (data: any) => {
1901
- try {
1902
- if (!data) throw new Error('Received null or undefined response');
1903
- const res = JSON.parse(data);
1904
- if (res?.error_message) throw new Error(res.error_message);
1905
- setProduct(res);
1906
- } catch (error) {
1907
- console.error('Error parsing response:', error);
1908
- }
1909
- };
1910
-
1911
- requestFromMiniApp(obj, getProductCallBack);
1912
- };
1913
- ```
1914
-
1915
- #### Validate User Request
1916
-
1917
- ```tsx
1918
- const onValidateUserClick = () => {
1919
- const obj = {
1920
- requestType: REQUEST_TYPE_ENUM.VALIDATE_USER,
1921
- token: sessionStorage.getItem('miniAppAuthToken'),
1922
- callbackKey: CALLBACK_TYPE_ENUM.VALIDATE_USER_CALLBACK
1923
- };
1924
-
1925
- const validateUserCallBack = (data: any) => {
1926
- try {
1927
- if (!data) throw new Error('Received null or undefined response');
1928
- const res = JSON.parse(data);
1929
- if (res?.error_message) throw new Error(res.error_message);
1930
- setProduct(res);
1931
- } catch (error) {
1932
- console.error('Error parsing response:', error);
1933
- }
1934
- };
1935
-
1936
- requestFromMiniApp(obj, validateUserCallBack);
1937
- };
1938
- ```
1939
-
1940
- #### Merchant Detail Request
1941
-
1942
- ```tsx
1943
- const onMerchantDetailClick = () => {
1944
- const obj = {
1945
- requestType: REQUEST_TYPE_ENUM.MERCHANT_DETAIL,
1946
- token: sessionStorage.getItem('miniAppAuthToken'),
1947
- callbackKey: CALLBACK_TYPE_ENUM.MERCHANT_DETAIL_CALLBACK
1948
- };
1949
-
1950
- const merchantDetailCallBack = (data: any) => {
1951
- try {
1952
- if (!data) throw new Error('Received null or undefined response');
1953
- const res = JSON.parse(data);
1954
- if (res?.error_message) throw new Error(res.error_message);
1955
- setProduct(res);
1956
- } catch (error) {
1957
- console.error('Error parsing response:', error);
1958
- }
1959
- };
1960
-
1961
- requestFromMiniApp(obj, merchantDetailCallBack);
1962
- };
1963
- ```
1964
-
1965
- #### QR Scanner Request
1966
-
1967
- ```tsx
1968
- const onQrScannerClick = () => {
1969
- const obj = {
1970
- requestType: REQUEST_TYPE_ENUM.QR_SCANNER_ACCESS,
1971
- token: sessionStorage.getItem('miniAppAuthToken'),
1972
- callbackKey: CALLBACK_TYPE_ENUM.QR_SCANNER_ACCESS_CALLBACK
1973
- };
1974
-
1975
- const qrScannerCallBack = (data: any) => {
1976
- try {
1977
- if (!data) throw new Error('Received null or undefined response');
1978
- const res = JSON.parse(data);
1979
- if (res?.error_message) throw new Error(res.error_message);
1980
- setProduct(res);
1981
- } catch (error) {
1982
- console.error('Error parsing response:', error);
1983
- }
1984
- };
1985
-
1986
- requestFromMiniApp(obj, qrScannerCallBack);
1987
- };
1988
- ```
1989
-
1990
- #### Request File Download
1991
-
1992
- Pass the following to request file download.
1993
-
1994
- **1. Link Type file download request**
1995
-
1996
- const onPdfDownloadRequestClick = () => {
1997
- const obj: REQUEST_DATA_TYPE = {
1998
- requestType: REQUEST_TYPE_ENUM.FILE_DOWNLOAD_ACCESS,
1999
- callbackKey: CALLBACK_TYPE_ENUM.FILE_DOWNLOAD_ACCESS_CALLBACK,
2000
- data: {
2001
- fileName: 'Statement-2025.pdf',
2002
- type: 'url',
2003
- content: 'https://www.aeee.in/wp-content/uploads/2020/08/Sample-pdf.pdf' //pass file url
2004
- }
2005
- }
2006
-
2007
- const fileDownloadCallBack: any = (data: any) => {
2008
- try{
2009
- if (!data) {
2010
- throw new Error('Received null or undefined response')
2011
- }
2012
- const res = data
2013
- if (res?.error_message) { //fail case
2014
- throw new Error('Error res', res.error_message)
2015
- }
2016
- else{
2017
- console.log(res.message) //success case
2018
- }
2019
- }
2020
- catch (error) {
2021
- console.error('Error parsing response:', error)
2022
- }
2023
- }
2024
-
2025
- requestFromMiniApp(
2026
- obj,
2027
- fileDownloadCallBack
2028
- )
2029
- }
2030
-
2031
- **2. Base64 Encoded Type file download request**
2032
-
2033
- const onPdfDownloadRequestClick = () => {
2034
- const response = await fetch('/base64.txt');
2035
- const content = await response.text(); //encoded pdf content/response from api
2036
- let base64Content = content.includes(',')
2037
- ? content
2038
- : `data:application/pdf;base64,${content}`;
2039
- const obj: REQUEST_DATA_TYPE = {
2040
- requestType: REQUEST_TYPE_ENUM.FILE_DOWNLOAD_ACCESS,
2041
- callbackKey: CALLBACK_TYPE_ENUM.FILE_DOWNLOAD_ACCESS_CALLBACK,
2042
- data: {
2043
- fileName: 'Statement-base64-2025.pdf',
2044
- type: 'base64',
2045
- content: base64Content
2046
- }
2047
- }
2048
-
2049
- const fileDownloadCallBack: any = (data: any) => {
2050
- try{
2051
- if (!data) {
2052
- throw new Error('Received null or undefined response')
2053
- }
2054
- const res = data
2055
- if (res?.error_message) { //fail case
2056
- throw new Error('Error res', res.error_message)
2057
- }
2058
- else{
2059
- console.log(res.message) //success case
2060
- }
2061
- }
2062
- catch (error) {
2063
- console.error('Error parsing response:', error)
2064
- }
2065
- }
2066
-
2067
- requestFromMiniApp(
2068
- obj,
2069
- fileDownloadCallBack
2070
- )
2071
- }
2072
-
2073
- ## Error Handling
2074
-
2075
- Errors are returned as JSON responses with an `error_message` field.
2076
-
2077
- #### Example
2078
-
2079
- ```json
2080
- {
2081
- "error_message": "Service is currently unavailable"
2082
- }
2083
- ```
2084
-
2085
- ```json
2086
- {
2087
- "error_message": "Merchant scope not found"
2088
- }
2089
- ```
2090
- ---
2091
-
2092
- This document provides a structured approach to interacting with the MiniApp services, ensuring proper initialization and error handling for seamless integration.
2093
-
2094
- ### Utilities
2095
-
2096
- - `titleCase`
2097
- - `revertIgnoredCase`
2098
- - `formatText`
2099
- - `formatAmount`
2100
- - `debounce`
2101
- - `reverseCamelCase`
2102
- - `reverseSnakeCase`
2103
-
2104
- ### Types
2105
-
2106
- - `REQUEST_TYPE_ENUM`
2107
-
2108
- ```tsx
2109
- import {REQUEST_TYPE_ENUM} from 'esewa-ui-library'
2110
- ```
2111
-
2112
- ```json
2113
- enum REQUEST_TYPE_ENUM {
2114
- INIT_APP = 'INIT_APP',
2115
- REQUEST_PAYMENT = 'REQUEST_PAYMENT',
2116
- USER_DETAIL_ACCESS = 'USER_DETAIL_ACCESS',
2117
- MEDIA_ACCESS = 'MEDIA_ACCESS',
2118
- LOCATION_ACCESS = 'LOCATION_ACCESS',
2119
- VALIDATE_TRANSACTION = 'VALIDATE_TRANSACTION',
2120
- CLOSE_APP = 'CLOSE_APP',
2121
- FILE_DOWNLOAD_ACCESS = 'FILE_DOWNLOAD_ACCESS'
2122
- GET_PRODUCT = 'GET_PRODUCT',
2123
- VALIDATE_USER = 'VALIDATE_USER',
2124
- MERCHANT_DETAIL = 'MERCHANT_DETAIL',
2125
- QR_SCANNER_ACCESS = 'QR_SCANNER_ACCESS'
2126
- }
2127
- ```
2128
-
2129
- - `CALLBACK_TYPE_ENUM`
2130
-
2131
- ```tsx
2132
- import {CALLBACK_TYPE_ENUM} from 'esewa-ui-library'
2133
- ```
2134
-
2135
- ```json
2136
- enum CALLBACK_TYPE_ENUM{
2137
- INIT_APP_CALLBACK = 'INIT_APP_CALLBACK',
2138
- REQUEST_PAYMENT_CALLBACK = 'REQUEST_PAYMENT_CALLBACK',
2139
- USER_DETAIL_ACCESS_CALLBACK = 'USER_DETAIL_ACCESS_CALLBACK',
2140
- MEDIA_ACCESS_CALLBACK = 'MEDIA_ACCESS_CALLBACK',
2141
- LOCATION_ACCESS_CALLBACK = 'LOCATION_ACCESS_CALLBACK',
2142
- VALIDATE_TRANSACTION_CALLBACK = 'VALIDATE_TRANSACTION_CALLBACK',
2143
- CLOSE_APP_CALLBACK = 'CLOSE_APP_CALLBACK',
2144
- FILE_DOWNLOAD_ACCESS_CALLBACK = 'FILE_DOWNLOAD_ACCESS_CALLBACK',
2145
- GET_PRODUCT_CALLBACK = 'GET_PRODUCT_CALLBACK',
2146
- VALIDATE_USER_CALLBACK = 'VALIDATE_USER_CALLBACK',
2147
- MERCHANT_DETAIL_CALLBACK = 'MERCHANT_DETAIL_CALLBACK',
2148
- QR_SCANNER_ACCESS_CALLBACK = 'QR_SCANNER_ACCESS_CALLBACK'
2149
- }
2150
- ```
2151
-
2152
- <!-- ### Hooks
2153
-
2154
- - `useMessage`
2155
- - `useSessionStorage`
2156
- - `useDebounce` -->
2157
-
2158
- ## Contributing
2159
-
2160
- Feel free to submit issues and pull requests. Make sure to follow the coding guidelines and write tests where applicable.
2161
-
2162
- ## License
2163
-
2164
- This project is licensed under the MIT License.
1
+ # esewa-ui-library
2
+ > UI Library for eSewa Mini App
3
+
4
+ [![NPM](https://img.shields.io/npm/v/esewa-ui-library.svg)](https://www.npmjs.com/package/esewa-ui-library) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
5
+
6
+ ## Install
7
+
8
+ ```bash
9
+ npm install --save esewa-ui-library
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ Import style file in your project:
15
+ ```bash
16
+ import 'esewa-ui-library/dist/index.css';
17
+ ```
18
+
19
+ ### Components
20
+
21
+ Import and use components in your project:
22
+
23
+ ```tsx
24
+ import { ESewaButton } from 'esewa-ui-library';
25
+ const App = () => {
26
+ return <ESewaButton>Click Me</ESewaButton>;
27
+ };
28
+ export default App;
29
+ ```
30
+
31
+ ### Available Components
32
+
33
+ - **AlertCard**: `ESewaAlertCard`
34
+ - **AppBar**: `ESewaAppBar`
35
+ - **Button**: `ESewaButton`
36
+ - **Card**: `ESewaCard`
37
+ - **Carousel**: `ESewaCarousel`
38
+ - **Checkbox**: `ESewaCheckbox`
39
+ - **Chipgroup**: `ESewaChipGroup`
40
+ - **Datepicker**: `ESewaDatepicker`
41
+ - **Dialog**: `ESewaDialog`
42
+ - **Divider**: `ESewaDivider`
43
+ - **FullPageLoadingScreen**: `EsewaFullPageLoadingScreen`
44
+ - **Grid**: `ESewaGrid`, `ESewaGridItem`
45
+ - **Icon**: `ESIcon`
46
+ - **Image**: `ESewaImage`
47
+ - **InputField**: `ESewaInputField`
48
+ - **InputFieldTextArea**: `ESewaInputFeildTextArea`
49
+ - **MultiSelect**: `ESewaMultiSelect`
50
+ - **NepaliDatepicker**: `ESewaNepaliDatepicker`
51
+ - **Radio**: `ESewaRadio`
52
+ - **Select**: `ESewaSelectNative`
53
+ - **Skeleton**: `ESewaSkeleton`
54
+ - **Tag**: `ESewaTag`
55
+ - **Tooltip**: `ESewaTooltip`
56
+ ---
57
+
58
+ ## ESewaAlertCard
59
+
60
+ The `ESewaAlertCard` component is used to display alert messages with different variants, optional icons, dismiss buttons, and action buttons.
61
+
62
+ ### Usage:
63
+
64
+ ```tsx
65
+ import { ESewaAlertCard } from 'esewa-ui-library';
66
+
67
+ const App = () => {
68
+ return (
69
+ <ESewaAlertCard
70
+ variant="warning"
71
+ title="Warning Alert"
72
+ description="This is a warning alert"
73
+ titleIcon="fa fa-exclamation-circle"
74
+ showDismissIcon={true}
75
+ dismissIcon="fa fa-times"
76
+ onDismiss={() => alert('Dismiss clicked')}
77
+ showCardFooter={true}
78
+ buttonLabel="Action"
79
+ buttonOnClick={() => alert('Action clicked')}
80
+ />
81
+ );
82
+ };
83
+
84
+ export default App;
85
+ ```
86
+
87
+ ### Props:
88
+
89
+ | Prop Name | Type | Default | Description |
90
+ |----------------------|--------------------------------------------------|-------------|-------------|
91
+ | `alertCardClass` | `string` | `''` | Additional class for custom styling |
92
+ | `variant` | `'primary' | 'warning' | 'danger' | 'info'` | `'primary'` | Determines the alert style |
93
+ | `title` | `string` | `undefined` | Title of the alert |
94
+ | `description` | `string` | `undefined` | Alert description text |
95
+ | `descriptionIcon` | `string` | `React.ReactNode` | `undefined` | Icon class for the description |
96
+ | `showDescriptionIcon` | `boolean` | `false` | Whether to show the description icon |
97
+ | `titleIcon` | `string` | `React.ReactNode` | `undefined` | Icon class for the title |
98
+ | `dismissIcon` | `string` | `React.ReactNode` | `undefined` | Icon class for the dismiss button |
99
+ | `showDismissIcon` | `boolean` | `false` | Whether to show the dismiss button |
100
+ | `onDismiss` | `() => void` | `undefined` | Callback function when dismiss button is clicked |
101
+ | `showCardFooter` | `boolean` | `false` | Whether to show the footer section |
102
+ | `buttonLabel` | `string` | `undefined` | Label for the action button |
103
+ | `buttonOnClick` | `() => void` | `undefined` | Callback function when the action button is clicked |
104
+
105
+ ---
106
+
107
+
108
+ ## ESewaAppBar
109
+
110
+ The `ESewaAlertCard` component is customizable app bar for your eSewa Mini App with support for back, title, and action icons, making navigation and interactions seamless.
111
+
112
+ Use useESewaDataProvider to set title for appbar.
113
+
114
+ ### Usage:
115
+
116
+ ```tsx
117
+ import { ESewaAppBar, useESewaDataProvider } from 'esewa-ui-library';
118
+
119
+ const App = () => {
120
+ const { updateData } = useESewaDataProvider();
121
+
122
+ useEffect(() => {
123
+ updateData({
124
+ title: "Merchant Product Form",
125
+ });
126
+ }, []);
127
+
128
+ return (
129
+ <ESewaAppBar
130
+ icon="icon-es-arrow-left"
131
+ titleposition="left"
132
+ onBackIconClick={() => console.log('Back icon clicked')}
133
+ onTitleClick={() => console.log('Title clicked')}
134
+ onActionIconClick={() => console.log('Action icon clicked')}
135
+ actionIcon="icon-settings"
136
+ />
137
+ );
138
+ };
139
+
140
+ export default App;
141
+ ```
142
+
143
+ ### Props:
144
+
145
+ | Prop Name | Type | Default | Description |
146
+ |-----------------------|---------------------------|----------|-------------|
147
+ | `title` | `string | any` | `undefined` | Title to display in the app bar |
148
+ | `icon` | `string`| `React.ReactNode`| `'icon-back'` | Icon to display as the back button |
149
+ | `imageUrl` | `string` | `undefined` | Image URL to display next to the title |
150
+ | `onBackIconClick` | `() => void` | `() => {}` | Callback for the back icon click event |
151
+ | `onTitleClick` | `() => void` | `() => {}` | Callback for the title click event |
152
+ | `onActionIconClick` | `() => void` | `() => {}` | Callback for the action icon click event |
153
+ | `onClick` | `() => void` | `() => {}` | Callback for the entire app bar click event |
154
+ | `className` | `string` | `undefined` | Additional class for custom styling |
155
+ | `titleposition` | `'left' | 'center' | 'right'` | `'center'` | Position of the title within the app bar |
156
+ | `actionIcon` | `string`| `React.ReactNode`| `undefined` | Icon for the action button on the right side of the app bar |
157
+
158
+
159
+ # ESewaButton
160
+
161
+ `ESewaButton` is a highly customizable button component built with React and styled using `styled-components`. It supports multiple variants, sizes, icon placement, and other button properties for flexible UI design.
162
+
163
+ ### Usage:
164
+
165
+ ```tsx
166
+ import { ESewaButton } from 'esewa-ui-library';
167
+
168
+ const App = () => {
169
+ return (
170
+ <ESewaButton
171
+ type="button"
172
+ variant="primary"
173
+ onClick={handleClick}
174
+ disabled={false}
175
+ outlined={false}
176
+ fullwidth={true}
177
+ icon="icon-class"
178
+ iconPlacement="start"
179
+ size="large"
180
+ textTransform="uppercase"
181
+ >
182
+ Click Me
183
+ </ESewaButton>
184
+ );
185
+ };
186
+
187
+ export default App;
188
+ ```
189
+
190
+
191
+ ### Props:
192
+ | Name | Type | Default | Description |
193
+ |----------------|---------------------------|-------------|--------------------------------------------------------------------------------------------------------------|
194
+ | `type` | `'button' | 'submit' | 'reset'` | `'button'` | Specifies the type of the button. Options include `button`, `submit`, or `reset`. |
195
+ | `variant` | `'primary' | 'secondary' | 'danger' | 'success' | 'warning' | 'info' | 'text'` | `'default'` | Specifies the variant style of the button. Choose from `primary`, `secondary`, `danger`, `success`, `warning`, `info`, or `text`. |
196
+ | `onClick` | `(e: any) => void` | `undefined` | The function to execute when the button is clicked. |
197
+ | `children` | `React.ReactNode` | `undefined` | The content of the button, typically text or icons. |
198
+ | `disabled` | `boolean` | `false` | Disables the button if set to `true`. |
199
+ | `outlined` | `boolean` | `false` | If `true`, the button will have an outline style. |
200
+ | `className` | `string` | `''` | Additional CSS class(es) to apply to the button. |
201
+ | `fullwidth` | `boolean` | `false` | If `true`, the button will span the full width of its container. |
202
+ | `icon` | `string`| `React.ReactNode`| `
203
+
204
+
205
+ ## Styling and Customization
206
+
207
+ ### Button Size
208
+
209
+ You can customize the button size using the `size` prop. The available sizes are:
210
+
211
+ - `large`: Large button with more padding.
212
+ - `medium`: Default button size.
213
+ - `small`: Compact button with smaller padding.
214
+
215
+ ### Button Variants
216
+
217
+ The button supports various color variants that you can use by specifying the `variant` prop:
218
+
219
+ - `primary`: The main action button style.
220
+ - `secondary`: A secondary action style.
221
+ - `danger`: A button to signify danger or warning actions.
222
+ - `success`: For success actions.
223
+ - `warning`: For warning actions.
224
+ - `info`: A button for informational actions.
225
+ - `text`: A text-only button with no background.
226
+
227
+ ### Icon Customization
228
+
229
+ You can add icons to your button using the `icon` prop. The icon will be displayed inside the button either before or after the button text, depending on the `iconPlacement` prop.
230
+
231
+ - `iconPlacement` can be set to `start` (icon before text) or `end` (icon after text).
232
+ - Use the `iconClass` prop to apply a custom class to the icon for further customization.
233
+
234
+ ### Full Width Button
235
+
236
+ To make the button span the full width of its container, set the `fullwidth` prop to `true`.
237
+
238
+ ### Disabled Button
239
+
240
+ If you want to disable the button, set the `disabled` prop to `true`. The button will appear grayed out and will not be clickable.
241
+
242
+ ### Text Transform
243
+
244
+ You can control the text transformation of the button text using the `textTransform` prop. Available options are:
245
+
246
+ - `uppercase`: Converts the button text to uppercase.
247
+ - `capitalized`: Capitalizes the first letter of each word.
248
+
249
+ ## Example Usage
250
+
251
+ ### Basic Example
252
+
253
+ ```tsx
254
+ import React from 'react';
255
+ import { ESewaButton } from 'esewa-ui-library';
256
+
257
+ const App = () => {
258
+ return (
259
+ <div>
260
+ <ESewaButton variant="primary" onClick={() => alert('Button clicked!')}>
261
+ Primary Button
262
+ </ESewaButton>
263
+ </div>
264
+ );
265
+ }
266
+
267
+ export default App;
268
+ ```
269
+
270
+ # ESewaCard Component
271
+
272
+ The `ESewaCard` component is a flexible and customizable card wrapper built with `styled-components` in React. It provides a container with background color, padding, and customizable border radius styles. You can use it to wrap content such as text, images, or other components to create a card-like layout.
273
+
274
+ The card supports various border radius values through the `className` prop. The `ESewaCard` component is lightweight and can be customized with different CSS variables.
275
+
276
+ ## Props
277
+ | Name | Type | Default | Description |
278
+ |-------------|---------------------|-------------|--------------------------------------------------------------------------------------|
279
+ | `children` | `React.ReactNode` | `''` | The content inside the card. |
280
+ | `className` | `string` | `''` | Additional CSS class(es) to apply to the card. |
281
+
282
+ ## Styling and Customization
283
+
284
+ The `ESewaCard` component uses CSS variables for styling, which allows for easy customization of the card's background, padding, border radius, and more.
285
+
286
+ ### Border Radius Customization
287
+
288
+ You can customize the card's border radius by adding the appropriate `className`:
289
+
290
+ - `border-radius-0`: Border radius of `var(--values-value-0)`
291
+ - `border-radius-2`: Border radius of `var(--values-value-2)`
292
+ - `border-radius-4`: Border radius of `var(--values-value-4)`
293
+ - `border-radius-6`: Border radius of `var(--values-value-6)`
294
+ - `border-radius-8`: Border radius of `var(--values-value-8)`
295
+ - `border-radius-10`: Border radius of `var(--values-value-10)`
296
+ - `border-radius-12`: Border radius of `var(--values-value-12)`
297
+ - `border-radius-14`: Border radius of `var(--values-value-14)`
298
+ - `border-radius-16`: Border radius of `var(--values-value-16)`
299
+ - `border-radius-round`: Border radius of `50%` (perfectly round card)
300
+
301
+ ### Default Styling
302
+
303
+ - **Background color**: `var(--card-bg)`
304
+ - **Box-shadow**: `var(--shadow--1--umbra)`
305
+ - **Text color**: `var(--text-dark)`
306
+ - **Padding**: `var(--values-value-16)`
307
+
308
+ ## Example Usage
309
+
310
+ ### Basic Example
311
+
312
+ ```tsx
313
+ import React from 'react';
314
+ import { ESewaCard } from 'esewa-ui-library';
315
+
316
+ const App = () => {
317
+ return (
318
+ <div>
319
+ <ESewaCard>
320
+ <h3>Card Content</h3>
321
+ <p>This is a simple card with content inside.</p>
322
+ </ESewaCard>
323
+ </div>
324
+ );
325
+ }
326
+
327
+ export default App;
328
+ ```
329
+
330
+ ### Custom Border Radius Example
331
+
332
+ You can customize the border radius of the `ESewaCard` component by using different `className` values. Below is an example of how to apply a custom border radius to the card.
333
+
334
+ #### Example: Card with Border Radius 8
335
+
336
+ ```tsx
337
+ import React from 'react';
338
+ import { ESewaCard } from 'esewa-ui-library';
339
+
340
+ const App = () => {
341
+ return (
342
+ <div>
343
+ <ESewaCard className="border-radius-8">
344
+ <h3>Card with Border Radius 8</h3>
345
+ <p>This card has a border radius of 8px.</p>
346
+ </ESewaCard>
347
+ </div>
348
+ );
349
+ }
350
+
351
+ export default App;
352
+ ```
353
+
354
+ ## ESewaCarousel
355
+
356
+ `ESewaCarousel` is a flexible and customizable carousel component built with React and styled-components. It supports both horizontal and vertical scrolling, customizable item sizes, and various features such as autoplay, navigation, and indicators.
357
+
358
+ ### Features
359
+ - Supports **horizontal** and **vertical** directions.
360
+ - Ability to display **scrollbars** and customize their visibility.
361
+ - **Navigation buttons** to scroll through items.
362
+ - **Autoplay** functionality with configurable intervals.
363
+ - **Indicators** to show the active item.
364
+ - Customizable **width** and **height** for carousel items.
365
+ - **Responsive** adjustments for smaller screens.
366
+
367
+ ### Props
368
+ | Prop | Type | Default Value | Description |
369
+ |---------------------|--------------------------------|----------------|---------------------------------------------------------------------------------------------------|
370
+ | `items` | `React.ReactNode[]` | `[]` | Array of items to display in the carousel. |
371
+ | `direction` | `'horizontal' \| 'vertical'` | `'horizontal'` | Defines the direction of scrolling (horizontal or vertical). |
372
+ | `itemWidth` | `string` | `'200px'` | Custom width of each item in the carousel. |
373
+ | `itemHeight` | `string` | `'200px'` | Custom height of each item in the carousel. |
374
+ | `showScrollbar` | `boolean` | `false` | Whether to display the scrollbar in the carousel. |
375
+ | `showIndicator` | `boolean` | `true` | Whether to display the carousel indicators. |
376
+ | `visibleItems` | `number` | `undefined` | Number of items to display at once in the carousel. |
377
+ | `showNav` | `boolean` | `false` | Whether to show left and right navigation buttons. |
378
+ | `autoplay` | `boolean` | `false` | Whether the carousel should autoplay. |
379
+ | `autoplayInterval` | `number` | `3000` | Interval for autoplay in milliseconds (default 3000ms). |
380
+ ### Styling
381
+
382
+ The `ESewaCarousel` component is styled using `styled-components`. The component is fully customizable, and you can adjust the appearance by modifying the following properties in the CSS:
383
+
384
+ - `background-color` for items (`--card-bg`)
385
+ - `color` for text (`--body-color`)
386
+ - Customizable scrollbar styles (`.carousel-wrapper.show-scrollbar`).
387
+
388
+ ### Example Usage
389
+
390
+ #### Horizontal Carousel
391
+
392
+ ```tsx
393
+ import React from 'react';
394
+ import { ESewaCarousel } from 'esewa-ui-library';
395
+
396
+ const items = [
397
+ <div>Item 1</div>,
398
+ <div>Item 2</div>,
399
+ <div>Item 3</div>
400
+ ];
401
+
402
+ const App = () => {
403
+ return (
404
+ <ESewaCarousel
405
+ items={items}
406
+ direction="horizontal"
407
+ itemWidth="250px"
408
+ itemHeight="200px"
409
+ showScrollbar
410
+ showNav
411
+ showIndicator
412
+ autoplay
413
+ autoplayInterval={4000}
414
+ />
415
+ );
416
+ }
417
+
418
+ export default App;
419
+ ```
420
+
421
+ # ESewaCheckbox Component
422
+
423
+ The `ESewaCheckbox` component is a fully customizable checkbox built with React and styled using `styled-components`. It provides support for labels, disabled states, custom change handling, and additional styling flexibility through props.
424
+
425
+ ## Features
426
+
427
+ - **Customizable checkbox**: Allows the user to easily customize the checkbox with a label.
428
+ - **Change handling**: Provides an `onChange` callback to handle state changes.
429
+ - **Disabled state**: Supports disabling the checkbox.
430
+ - **Custom styling**: Supports custom class names and additional styling flexibility via props.
431
+
432
+ ## Usage
433
+
434
+ ### Basic Usage
435
+
436
+ To use the `ESewaCheckbox` component, import it and pass the necessary props to it.
437
+
438
+ ```tsx
439
+ import { ESewaCheckbox } from 'esewa-ui-library';
440
+
441
+ const MyComponent = () => {
442
+ const [isChecked, setIsChecked] = useState(false);
443
+
444
+ const handleChange = (checked: boolean) => {
445
+ setIsChecked(checked);
446
+ };
447
+
448
+ return (
449
+ <ESewaCheckbox
450
+ label="I agree to the terms"
451
+ checked={isChecked}
452
+ onChange={handleChange}
453
+ />
454
+ );
455
+ };
456
+ ```
457
+
458
+ ## Props
459
+ | Prop | Type | Default Value | Description |
460
+ |---------------|-------------|---------------|---------------------------------------------------|
461
+ | `label` | `string?` | `undefined` | The label text for the checkbox. |
462
+ | `onChange` | `(checked: boolean) => void?` | `undefined` | Callback function to handle checkbox state change. |
463
+ | `checked` | `boolean?` | `false` | The checked state of the checkbox. |
464
+ | `labelClass` | `string?` | `''` | Class name for styling the label. |
465
+ | `className` | `string?` | `''` | Custom class name for the checkbox container. |
466
+ | `disabled` | `boolean?` | `false` | If true, disables the checkbox.
467
+
468
+ # ESewaChipGroup Component
469
+
470
+ ## Overview
471
+
472
+ The `ESewaChipGroup` component is a customizable chip group component built with React and styled-components. It allows you to display a set of chips with selectable options. You can choose between single or multiple selection modes, with customizable styles and optional icons.
473
+
474
+ ## Props
475
+ | Prop | Type | Default Value | Description |
476
+ |-----------------|---------------------------------|---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
477
+ | `selection` | `'single' \| 'multiple'` | Required | Specifies the selection mode: `'single'` for single selection, `'multiple'` for multiple selection. |
478
+ | `required` | `boolean?` | `false` | If true, ensures that at least one chip is selected when the selection mode is `'multiple'`. |
479
+ | `chips` | `ChipProps[]` | Required | An array of chips to display. Each chip includes a text label, an optional icon, and an ID. |
480
+ | `className` | `string?` | `''` | Optional custom class name for styling the chip container. |
481
+ | `onChange` | `(selected: number[] | number) => void?` | `undefined` | Callback function to handle chip state change. |
482
+
483
+ # ESewaDatePicker
484
+
485
+ A customizable and accessible date picker component for React, built using **styled-components**.
486
+
487
+ ## Features
488
+
489
+ - Customizable label with a required indicator.
490
+ - Supports `min` and `max` date restrictions.
491
+ - Supports `readOnly` and `disabled` states.
492
+ - Displays validation messages when needed.
493
+ - Automatically focuses on the input when `autoFocus` is enabled.
494
+ - Styled using `styled-components`.
495
+
496
+
497
+ ## Usage
498
+
499
+ ### Basic Example
500
+
501
+ ```tsx
502
+ import React, { useState } from "react";
503
+ import { ESewaDatePicker } from 'esewa-ui-library';
504
+
505
+ const App = () => {
506
+ const [date, setDate] = useState("");
507
+
508
+ return (
509
+ <div>
510
+ <ESewaDatePicker
511
+ label="Select Date"
512
+ name="date"
513
+ value={date}
514
+ onChange={(e) => setDate(e.target.value)}
515
+ required
516
+ />
517
+ </div>
518
+ );
519
+ };
520
+
521
+ export default App
522
+ ```
523
+
524
+ ## Example with Validation, Min & Max Dates
525
+
526
+ ```tsx
527
+ import React, { useState } from "react";
528
+ import { ESewaDatePicker } from 'esewa-ui-library';
529
+
530
+ const App = () => {
531
+ const [date, setDate] = useState("");
532
+
533
+ return (
534
+ <div>
535
+ <ESewaDatePicker
536
+ label="Start Date"
537
+ name="startDate"
538
+ value={date}
539
+ onChange={(e) => setDate(e.target.value)}
540
+ min="2023-12-01"
541
+ max="2024-12-31"
542
+ validationMessage="Please select a valid date."
543
+ required
544
+ />
545
+ </div>
546
+ );
547
+ };
548
+
549
+ export default App;
550
+ ```
551
+
552
+ ## Props
553
+
554
+ | Prop Name | Type | Default | Description |
555
+ |--------------------|-------------------------------------------|-----------|-------------|
556
+ | `id` | `string` | `undefined` | ID for the input field. |
557
+ | `name` | `string` | `undefined` | Name attribute for the input field. |
558
+ | `label` | `string` | `undefined` | Label text displayed above the input field. |
559
+ | `value` | `string` | `undefined` | Selected date value (in `YYYY-MM-DD` format). |
560
+ | `min` | `string` | `undefined` | Minimum selectable date (in `YYYY-MM-DD` format). |
561
+ | `max` | `string` | `undefined` | Maximum selectable date (in `YYYY-MM-DD` format). |
562
+ | `required` | `boolean` | `false` | Marks the field as required. |
563
+ | `readOnly` | `boolean` | `false` | Makes the input read-only. |
564
+ | `disabled` | `boolean` | `false` | Disables the input field. |
565
+ | `className` | `string` | `""` | Additional class names for styling. |
566
+ | `validationMessage`| `string` | `undefined` | Displays an error message below the input. |
567
+ | `autoFocus` | `boolean` | `false` | Automatically focuses on the input when mounted. |
568
+ | `onChange` | `(event: React.ChangeEvent<HTMLInputElement>) => void` | `undefined` | Callback function triggered on date change. |
569
+
570
+
571
+ # ESewaDialog Component
572
+
573
+ ## Usage
574
+
575
+ The `ESewaDialog` component is a modal dialog used to display content with options like OK and Cancel actions. You can customize the dialog's appearance, positioning, and button texts.
576
+
577
+ ### Example:
578
+
579
+ ```tsx
580
+ import React, { useState } from 'react';
581
+ import { ESewaDialog } from 'esewa-ui-library';
582
+
583
+ const App = () => {
584
+ const [isOpen, setIsOpen] = useState(false);
585
+
586
+ const openDialog = () => setIsOpen(true);
587
+ const closeDialog = () => setIsOpen(false);
588
+ const handleOk = () => {
589
+ console.log('OK button clicked');
590
+ closeDialog();
591
+ };
592
+
593
+ return (
594
+ <div>
595
+ <button onClick={openDialog}>Open Dialog</button>
596
+
597
+ {
598
+ isOpen && (<ESewaDialog
599
+ isOpen={isOpen}
600
+ title="Sample Dialog"
601
+ okText="Confirm"
602
+ cancelText="Cancel"
603
+ onOk={handleOk}
604
+ onCancel={closeDialog}
605
+ position="center"
606
+ >
607
+ <p>Dialog content goes here.</p>
608
+ </ESewaDialog>)
609
+ }
610
+ </div>
611
+ );
612
+ };
613
+
614
+ export default App;
615
+ ```
616
+
617
+ ## Props
618
+
619
+ | Prop Name | Type | Default | Description |
620
+ |----------------------|------------------------------------------------------------|------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
621
+ | `isOpen` | `boolean` | `false` | Controls the visibility of the dialog. |
622
+ | `showLeftIcon` | `boolean` | `false` | Whether to show the left icon in the dialog header. |
623
+ | `leftIcon` | `string` | `React.ReactNode` | `'icon-es-check'` | The icon class to be displayed in the left side of the dialog header. |
624
+ | `showCloseIcon` | `boolean` | `false` | Whether to show the close icon in the dialog header. |
625
+ | `closeIcon` | `string` | `'icon-es-close'` | The icon class for the close button. |
626
+ | `okText` | `string` | `'OK'` | The text to be displayed on the OK button. |
627
+ | `cancelText` | `string` | `'Cancel'` | The text to be displayed on the Cancel button. |
628
+ | `title` | `string` | `undefined` | The title of the dialog. |
629
+ | `children` | `React.ReactNode` | `undefined` | The content to be displayed in the body of the dialog. |
630
+ | `onOk` | `() => void` | `undefined` | The callback function for the OK button click event. |
631
+ | `onCancel` | `() => void` | `() => {}` | The callback function for the Cancel button click event or clicking outside the dialog. |
632
+ | `position` | `'center' | 'top' | 'bottom'` | `'bottom'` | The position of the dialog on the screen. Can be `center`, `top`, or `bottom`. |
633
+ | `disableSubmitButton`| `boolean` | `false` | Whether the OK button should be disabled.
634
+ |
635
+ # ESewaDivider Component
636
+
637
+ The `ESewaDivider` component is a customizable divider line that can be used to separate content in your React application. You can customize the color, thickness, width, margin, and style (dotted or solid) of the divider.
638
+
639
+ ## Usage
640
+
641
+ To use the `ESewaDivider`, simply import it into your React component and include it in your JSX. You can customize the divider's appearance using the available props.
642
+
643
+ ### Basic Usage
644
+
645
+ ```tsx
646
+ import React from 'react'
647
+ import { ESewaDivider } from 'esewa-ui-library';
648
+
649
+ const MyComponent = () => {
650
+ return (
651
+ <div>
652
+ <p>Content above the divider</p>
653
+ <ESewaDivider />
654
+ <p>Content below the divider</p>
655
+ </div>
656
+ )
657
+ }
658
+ ```
659
+
660
+ ## Props
661
+
662
+ The `ESewaDivider` component accepts the following props to customize its appearance:
663
+
664
+ | Prop | Type | Default Value | Description |
665
+ |--------------|----------|------------------|---------------------------------------------------------------------------------------------------|
666
+ | `color` | `string` | `'var(--border)'` | The color of the divider. You can specify any valid CSS color value. |
667
+ | `thickness` | `string` | `'1px'` | The thickness of the divider. You can specify the value in `px`, `em`, `rem`, etc. |
668
+ | `width` | `string` | `'100%'` | The width of the divider. You can specify a percentage, `px`, `em`, `rem`, etc. |
669
+ | `margin` | `string` | `'8px 0'` | The margin around the divider. You can specify the margin in `px`, `em`, `rem`, etc. |
670
+ | `className` | `string` | `''` (optional) | A custom CSS class for additional styling. |
671
+ | `dotted` | `boolean`| `false` | If `true`, the divider will be styled with a dotted line (`dashed` style). Otherwise, it is solid. |
672
+
673
+ ### Example
674
+
675
+ ```tsx
676
+ <ESewaDivider
677
+ color="blue"
678
+ thickness="2px"
679
+ width="50%"
680
+ margin="10px 0"
681
+ dotted
682
+ />
683
+ ```
684
+
685
+ In this example, the divider will be blue, 2px thick, 50% wide, with 10px margin on top and bottom, and have a dotted line style.
686
+
687
+ # Full Page Loading Component
688
+
689
+ The `EsewaFullPageLoadingScreen` component provides a full-page loading screen with a loading animation consisting of animated dots and an optional text message.
690
+
691
+ ## Usage
692
+
693
+ You can use the `EsewaFullPageLoadingScreen` component to show a loading screen with animated dots.
694
+
695
+ ### Example Usage
696
+
697
+ ```tsx
698
+ import React from 'react';
699
+ import { EsewaFullPageLoadingScreen } from 'esewa-ui-library';
700
+
701
+ const App = () => {
702
+ return (
703
+ <div>
704
+ {/* Display loading screen with a custom message */}
705
+ <EsewaFullPageLoadingScreen text="Loading, please wait..." />
706
+ </div>
707
+ );
708
+ };
709
+
710
+ export default App;
711
+ ```
712
+
713
+ ## Props
714
+
715
+ | Prop | Type | Default Value | Description |
716
+ |--------|---------|---------------|-------------------------------------------------------------------------------------------------------|
717
+ | `text` | `string` | `undefined` | Custom loading text that will be displayed next to the animated dots. If not provided, no text will be shown. |
718
+
719
+
720
+ # `ESewaGrid` & `ESewaGridItem` Component
721
+
722
+ ## Overview
723
+
724
+ The `ESewaGrid` and `ESewaGridItem` components are used to create flexible grid layouts with a 12-column grid system. The `ESewaGrid` serves as the container for the grid, and the `ESewaGridItem` allows you to define the column span for individual items within the grid.
725
+
726
+
727
+ ## Usage
728
+
729
+ The `ESewaGrid` component is used to create a 12-column grid layout. You can use `ESewaGridItem` to define the number of columns an item will span within the grid.
730
+
731
+ ### Example
732
+
733
+ ```tsx
734
+ import { ESewaGrid, ESewaGridItem } from './esewa-ui-library';
735
+
736
+ const Example = () => {
737
+ return (
738
+ <ESewaGrid>
739
+ <ESewaGridItem colSpan={4}>Item 1</ESewaGridItem>
740
+ <ESewaGridItem colSpan={8}>Item 2</ESewaGridItem>
741
+ <ESewaGridItem colSpan={12}>Item 3</ESewaGridItem>
742
+ </ESewaGrid>
743
+ );
744
+ };
745
+ ```
746
+
747
+ In the example above:
748
+ Item 1 spans 4 columns.
749
+
750
+ Item 2 spans 8 columns.
751
+
752
+ Item 3 spans all 12 columns.
753
+
754
+ ## Props
755
+
756
+ ### `ESewaGrid` Props
757
+
758
+ | Prop | Type | Default Value | Description |
759
+ |-----------|------------------|---------------|----------------------------------------------------------------------------|
760
+ | `children`| `React.ReactNode` | Required | The content inside the grid container. |
761
+ | `className`| `string` | `''` | Custom class name for styling the grid container. |
762
+
763
+ ### `ESewaGridItem` Props
764
+
765
+ | Prop | Type | Default Value | Description |
766
+ |-----------|--------------------------------------------------------|---------------|-----------------------------------------------------------------------------|
767
+ | `colSpan` | `1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12` | Required | Defines the number of columns the grid item will span (from 1 to 12). |
768
+ | `children`| `React.ReactNode` | Required | The content inside the grid item. |
769
+ | `className`| `string` | `''` | Custom class name for styling the grid item. |
770
+
771
+ ## Example: ESewaGrid with All Column Spans
772
+
773
+ ### Example: Usage of All Column Spans
774
+
775
+ In this example, we use all possible column spans (from 1 to 12) to demonstrate how `ESewaGrid` and `ESewaGridItem` work:
776
+
777
+ ```tsx
778
+ import { ESewaGrid, ESewaGridItem } from './esewa-ui-library'
779
+
780
+ const Example = () => {
781
+ return (
782
+ <ESewaGrid>
783
+ <ESewaGridItem colSpan={1}>Item 1 (1 Column)</ESewaGridItem>
784
+ <ESewaGridItem colSpan={2}>Item 2 (2 Columns)</ESewaGridItem>
785
+ <ESewaGridItem colSpan={3}>Item 3 (3 Columns)</ESewaGridItem>
786
+ <ESewaGridItem colSpan={4}>Item 4 (4 Columns)</ESewaGridItem>
787
+ <ESewaGridItem colSpan={5}>Item 5 (5 Columns)</ESewaGridItem>
788
+ <ESewaGridItem colSpan={6}>Item 6 (6 Columns)</ESewaGridItem>
789
+ <ESewaGridItem colSpan={7}>Item 7 (7 Columns)</ESewaGridItem>
790
+ <ESewaGridItem colSpan={8}>Item 8 (8 Columns)</ESewaGridItem>
791
+ <ESewaGridItem colSpan={9}>Item 9 (9 Columns)</ESewaGridItem>
792
+ <ESewaGridItem colSpan={10}>Item 10 (10 Columns)</ESewaGridItem>
793
+ <ESewaGridItem colSpan={11}>Item 11 (11 Columns)</ESewaGridItem>
794
+ <ESewaGridItem colSpan={12}>Item 12 (12 Columns)</ESewaGridItem>
795
+ </ESewaGrid>
796
+ )
797
+ }
798
+ ```
799
+
800
+ # ESIcon Component
801
+
802
+ The `ESIcon` component is a customizable icon component built using `styled-components` and CSS variables. It allows you to display an icon from a font icon set and customize its size and colors.
803
+
804
+ ### Basic Example
805
+
806
+ ```tsx
807
+ import React from "react";
808
+ import { ESIcon } from './esewa-ui-library'
809
+
810
+ const App = () => {
811
+ return (
812
+ <div>
813
+ <ESIcon icon="home" size={40} iconPrimaryColor="blue" iconSecondaryColor="gray" />
814
+ <ESIcon icon="settings" size={30} iconPrimaryColor="green" />
815
+ </div>
816
+ );
817
+ };
818
+
819
+ export default App;
820
+ ```
821
+
822
+ ### Example with Custom Colors and Size, Multiple Icons
823
+
824
+ In this example, we render multiple icons with custom sizes and colors.
825
+
826
+ ```tsx
827
+ import React from "react";
828
+ import { ESIcon } from './esewa-ui-library'
829
+
830
+ const App = () => {
831
+ return (
832
+ <div>
833
+ <ESIcon icon="search" size={50} iconPrimaryColor="red" iconSecondaryColor="yellow" />
834
+ <ESIcon icon="user" size={32} iconPrimaryColor="purple" />
835
+ <ESIcon icon="cart" size={48} iconPrimaryColor="orange" iconSecondaryColor="black" />
836
+ </div>
837
+ );
838
+ };
839
+
840
+ export default App;
841
+
842
+ ```
843
+
844
+ ### ESIcon Component Props
845
+
846
+ | Prop | Type | Default | Description |
847
+ |---------------------|----------------------------------|-----------|--------------------------------------------------------------------|
848
+ | `icon` | `string` | - | The name of the icon to display. This should be the icon class name (e.g., `search`, `user`, etc.). |
849
+ | `size` | `number` | `28` | The size of the icon in pixels. |
850
+ | `iconPrimaryColor` | `string` | `undefined` | The primary color of the icon. If not provided, the default color is used. |
851
+ | `iconSecondaryColor`| `string` | `undefined` | The secondary color of the icon. If not provided, the default color is used. |
852
+
853
+ ### Usage Example:
854
+
855
+ ```tsx
856
+ <ESIcon icon="search" size={50} iconPrimaryColor="red" iconSecondaryColor="yellow" />
857
+ ```
858
+
859
+ # ESewaImage Component
860
+
861
+ `ESewaImage` is a React component that handles lazy-loading, error handling, and image preview in a modal. It provides functionality for images to be lazy-loaded when they enter the viewport, with a fallback image in case of error. It also allows the user to click on the image to open a larger preview in a modal.
862
+
863
+ ## Features:
864
+ - **Lazy Loading**: Image is loaded only when it is about to enter the viewport.
865
+ - **Error Handling**: If the image fails to load, a fallback image is used.
866
+ - **Image Preview**: Clicking the image opens it in a modal view.
867
+ - **Customizable Styles**: Customize the width, height, and className of the image.
868
+
869
+ ```tsx
870
+ import { ESewaImage } from './esewa-ui-library'
871
+
872
+ <ESewaImage
873
+ src="https://example.com/image.jpg" // The source URL for the image
874
+ alt="Description of the image" // Alt text for accessibility
875
+ width="300" // Image width (can be string or number)
876
+ height="200" // Image height (can be string or number)
877
+ loading="lazy" // Lazy loading option (default is 'lazy')
878
+ className="custom-class" // Optional custom class for styling
879
+ fallbackSrc="https://example.com/fallback.jpg" // Fallback image URL
880
+ />
881
+ ```
882
+
883
+ ## Props
884
+
885
+ The `ESewaImage` component accepts the following props:
886
+
887
+ | Prop | Type | Default Value | Description |
888
+ |-----------------|---------------------------------------|-------------------|-----------------------------------------------------------------------------|
889
+ | `src` | `string` | `fallbackImage` | The URL of the image to be displayed. |
890
+ | `alt` | `string` | `https://` | The alt text for the image (for accessibility). |
891
+ | `width` | `string | number` | - | The width of the image (can be a string like `'300px'` or a number like `300`). |
892
+ | `height` | `string | number` | - | The height of the image (can be a string like `'200px'` or a number like `200`). |
893
+ | `className` | `string` | - | Optional custom CSS class for styling the image. |
894
+ | `fallbackSrc` | `string` | `fallbackImage` | The URL for the fallback image if the primary image fails to load. |
895
+ | `loading` | `'lazy' | 'eager'` | `'lazy'` | Determines the image loading strategy: `'lazy'` or `'eager'`. |
896
+
897
+
898
+ # ESewaInputField Component
899
+
900
+ `ESewaInputField` is a customizable and reusable input field component for React. It supports various types of input fields (text, password, number, email, etc.) and comes with built-in validation messaging, styling, and accessibility features.
901
+
902
+ ## Usage
903
+
904
+ You can use the `ESewaInputField` component in your React application by following the steps below.
905
+
906
+ ### Basic Usage
907
+
908
+ ```tsx
909
+ import React, { useState } from 'react';
910
+ import { ESewaInputField } from './esewa-ui-library'
911
+
912
+ const MyComponent = () => {
913
+ const [inputValue, setInputValue] = useState('');
914
+
915
+ const handleChange = (e) => {
916
+ setInputValue(e.target.value);
917
+ };
918
+
919
+ return (
920
+ <ESewaInputField
921
+ type="text"
922
+ label="Username"
923
+ name="username"
924
+ value={inputValue}
925
+ onChange={handleChange}
926
+ placeholder="Enter your username"
927
+ required
928
+ validationMessage="Username is required"
929
+ />
930
+ );
931
+ };
932
+
933
+ export default MyComponent;
934
+ ```
935
+
936
+ ## Props
937
+
938
+ The `ESewaInputField` component accepts the following props:
939
+
940
+ | Prop | Type | Default | Description |
941
+ |--------------------|-----------------------------------------------------------|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
942
+ | `id` | `string` | `undefined` | A unique identifier for the input field. |
943
+ | `type` | `'text' | 'password' | 'number' | 'email' | 'date' | 'checkbox' | 'radio' | 'select' | 'textarea'` | `'text'` | The type of the input field. |
944
+ | `name` | `string` | `undefined` | The name of the input field, used for form submissions. |
945
+ | `label` | `string` | `undefined` | The label to display next to the input field. |
946
+ | `placeholder` | `string` | `undefined` | The placeholder text displayed in the input field when it is empty. |
947
+ | `value` | `string | number` | `undefined` | The current value of the input field. |
948
+ | `checked` | `boolean` | `undefined` | Specifies whether the checkbox or radio button is checked (only applicable for `checkbox` and `radio` types). |
949
+ | `pattern` | `string` | `undefined` | A regular expression that the input value must match (useful for email, password, etc.). |
950
+ | `min` | `number` | `undefined` | The minimum value for `number`, `date`, or `range` input types. |
951
+ | `max` | `number` | `undefined` | The maximum value for `number`, `date`, or `range` input types. |
952
+ | `step` | `number` | `undefined` | The step value for `number`, `date`, or `range` input types. |
953
+ | `required` | `boolean` | `false` | If `true`, the input field is required to be filled out before form submission. |
954
+ | `readOnly` | `boolean` | `false` | If `true`, the input field is read-only, meaning the user cannot modify the value. |
955
+ | `disabled` | `boolean` | `false` | If `true`, the input field is disabled, preventing user interaction. |
956
+ | `className` | `string` | `''` | A custom class name to apply to the input field's container. |
957
+ | `validationMessage`| `string` | `undefined` | A validation message that is displayed when the input is invalid or doesn't meet the specified requirements. |
958
+ | `autoFocus` | `boolean` | `false` | If `true`, the input field will automatically receive focus when the component is rendered. |
959
+ | `onChange` | `(e: React.ChangeEvent<HTMLInputElement>) => void` | `undefined` | A callback function that is called when the input value changes. The `onChange` function receives the change event as an argument. |
960
+
961
+ ### Notes:
962
+ - Some props are type-dependent. For example, `min`, `max`, and `step` are only relevant for `number`, `range`, or `date` input types.
963
+ - The `required`, `readOnly`, and `disabled` props affect user interaction with the input field.
964
+ - You can pass any additional attributes via the `rest` prop, which will be spread onto the underlying `<input>` element.
965
+
966
+
967
+ # ESewaInputFeildTextArea Component
968
+
969
+ The `ESewaInputFeildTextArea` component is a styled text area input field with customizable properties for labels, validation, and more. It provides a clean and consistent design for text area fields in React applications.
970
+
971
+ ## Usage
972
+
973
+ ### Basic Example
974
+
975
+ ```tsx
976
+ import { ESewaInputFeildTextArea } from './esewa-ui-library'
977
+
978
+ const Example = () => {
979
+ const [value, setValue] = useState('');
980
+
981
+ const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
982
+ setValue(e.target.value);
983
+ };
984
+
985
+ return (
986
+ <ESewaInputFeildTextArea
987
+ label="Your Message"
988
+ value={value}
989
+ onChange={handleChange}
990
+ placeholder="Enter your message here"
991
+ required
992
+ validationMessage="Message is required"
993
+ />
994
+ );
995
+ };
996
+ ```
997
+
998
+ With maxLength and rows
999
+
1000
+ ```tsx
1001
+ import { ESewaInputFeildTextArea } from './esewa-ui-library'
1002
+
1003
+ const Example = () => {
1004
+ const [value, setValue] = useState('');
1005
+
1006
+ const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
1007
+ setValue(e.target.value);
1008
+ };
1009
+
1010
+ return (
1011
+ <ESewaInputFeildTextArea
1012
+ label="Your Feedback"
1013
+ value={value}
1014
+ onChange={handleChange}
1015
+ placeholder="Enter your feedback here"
1016
+ maxLength={200}
1017
+ rows={5}
1018
+ required
1019
+ validationMessage="Feedback is required"
1020
+ />
1021
+ );
1022
+ };
1023
+ ```
1024
+
1025
+ In this example, the ESewaInputFeildTextArea is used with a label, value, onChange, placeholder, and optional maxLength and rows properties. You can customize the component further as needed based on the provided props.
1026
+
1027
+ ## Props
1028
+
1029
+ | Name | Type | Default | Description |
1030
+ |-------------------|-----------------------------------|-------------|-----------------------------------------------------------------------------|
1031
+ | `name` | `string` | - | The name of the textarea element. |
1032
+ | `label` | `string` | - | The label text that is displayed above the textarea. |
1033
+ | `placeholder` | `string` | - | The placeholder text that appears when the textarea is empty. |
1034
+ | `value` | `string \| number` | - | The current value of the textarea. |
1035
+ | `maxLength` | `number` | - | The maximum number of characters allowed in the textarea. |
1036
+ | `required` | `boolean` | `false` | If `true`, the textarea becomes required when submitting the form. |
1037
+ | `readOnly` | `boolean` | `false` | If `true`, the textarea is set to read-only. |
1038
+ | `disabled` | `boolean` | `false` | If `true`, the textarea is disabled and cannot be interacted with. |
1039
+ | `className` | `string` | - | Additional CSS class name(s) for custom styling. |
1040
+ | `rows` | `number` | `3` | Defines the number of visible rows for the textarea. |
1041
+ | `validationMessage`| `string` | - | An optional message to display when validation fails. |
1042
+ | `onChange` | `(e: ChangeEvent<HTMLTextAreaElement>) => void` | - | Event handler function for handling text input changes. |
1043
+
1044
+
1045
+ # ESewaMultiSelect Component
1046
+
1047
+ The `ESewaMultiSelect` component is a customizable multi-select dropdown component built using React and styled-components. It allows users to select multiple options from a list, with a search feature and customizable styles.
1048
+
1049
+ ## Usage
1050
+
1051
+ To use the `ESewaMultiSelect` component in your React project, follow these steps:
1052
+
1053
+ ### 1. Import the Component
1054
+
1055
+ First, import the `ESewaMultiSelect` component in your React file:
1056
+
1057
+ ### 2.Define Options and State
1058
+ Create an array of options that will be displayed in the multi-select dropdown. You also need to set up state to handle the selected items.
1059
+
1060
+ ```tsx
1061
+ const [selectedItems, setSelectedItems] = useState([])
1062
+
1063
+ const options = [
1064
+ { value: '1', label: 'Option 1' },
1065
+ { value: '2', label: 'Option 2' },
1066
+ { value: '3', label: 'Option 3' },
1067
+ { value: '4', label: 'Option 4' }
1068
+ ]
1069
+ ```
1070
+
1071
+ ### 3. Handle Selection Changes
1072
+ Define a handler function that will be called whenever the selection changes.
1073
+
1074
+ const handleChange = (selected: Option[]) => {
1075
+ setSelectedItems(selected)
1076
+ }
1077
+
1078
+ ### 4. Render the Component
1079
+ Now you can render the ESewaMultiSelect component and pass in the necessary props:
1080
+
1081
+ ```tsx
1082
+ <ESewaMultiSelect
1083
+ options={options}
1084
+ onChange={handleChange}
1085
+ placeholder="Select options"
1086
+ />
1087
+ ```
1088
+
1089
+ ### 5. Display Selected Items
1090
+ ```tsx
1091
+ <div>
1092
+ <h3>Selected Items</h3>
1093
+ <ul>
1094
+ {selectedItems.map(item => (
1095
+ <li key={item.value}>{item.label}</li>
1096
+ ))}
1097
+ </ul>
1098
+ </div>
1099
+ ```
1100
+
1101
+ ### Full Example
1102
+
1103
+ ```tsx
1104
+ import React, { useState } from 'react'
1105
+ import { ESewaMultiSelect } from './esewa-ui-library'
1106
+
1107
+ const MyComponent = () => {
1108
+ const [selectedItems, setSelectedItems] = useState([])
1109
+
1110
+ const options = [
1111
+ { value: '1', label: 'Option 1' },
1112
+ { value: '2', label: 'Option 2' },
1113
+ { value: '3', label: 'Option 3' },
1114
+ { value: '4', label: 'Option 4' }
1115
+ ]
1116
+
1117
+ const handleChange = (selected: Option[]) => {
1118
+ setSelectedItems(selected)
1119
+ }
1120
+
1121
+ return (
1122
+ <div>
1123
+ <ESewaMultiSelect
1124
+ options={options}
1125
+ onChange={handleChange}
1126
+ placeholder="Select options"
1127
+ />
1128
+ <div>
1129
+ <h3>Selected Items</h3>
1130
+ <ul>
1131
+ {selectedItems.map(item => (
1132
+ <li key={item.value}>{item.label}</li>
1133
+ ))}
1134
+ </ul>
1135
+ </div>
1136
+ </div>
1137
+ )
1138
+ }
1139
+ ```
1140
+
1141
+ # ESewaSelectNative Component
1142
+
1143
+ The `ESewaSelectNative` is a customizable `select` dropdown component built with React and styled using `styled-components`. It provides a native `select` element with additional features such as labels, validation messages, and optional full-width styling.
1144
+
1145
+ ## Usage
1146
+
1147
+ Here is an example of how to use the `ESewaSelectNative` component in your React application:
1148
+
1149
+ ```tsx
1150
+ import React, { useState } from 'react';
1151
+ import { ESewaSelectNative } from './esewa-ui-library'
1152
+
1153
+ const ExampleComponent = () => {
1154
+ const [selectedValue, setSelectedValue] = useState<string>('');
1155
+
1156
+ const handleSelectChange = (value: string) => {
1157
+ setSelectedValue(value);
1158
+ };
1159
+
1160
+ const options = [
1161
+ { label: 'Option 1', value: '1' },
1162
+ { label: 'Option 2', value: '2' },
1163
+ { label: 'Option 3', value: '3' }
1164
+ ];
1165
+
1166
+ return (
1167
+ <div>
1168
+ <ESewaSelectNative
1169
+ label="Select an Option"
1170
+ placeholder="Choose an option"
1171
+ options={options}
1172
+ value={selectedValue}
1173
+ onChange={handleSelectChange}
1174
+ required
1175
+ fullwidth
1176
+ />
1177
+ </div>
1178
+ );
1179
+ };
1180
+ ```
1181
+
1182
+ ## Props
1183
+
1184
+ | Name | Type | Default | Description |
1185
+ |---------------------|--------------------|-----------|-----------------------------------------------------------------------------|
1186
+ | `options` | `Options[]` | `[]` | An array of objects representing the available options in the dropdown. |
1187
+ | `placeholder` | `string` | `''` | Placeholder text shown when no option is selected. |
1188
+ | `onChange` | `(value: string) => void` | `() => {}` | A callback function triggered when an option is selected. |
1189
+ | `label` | `string` | `undefined` | The label displayed above the dropdown. |
1190
+ | `value` | `string` | `undefined` | The currently selected value in the dropdown. |
1191
+ | `disabled` | `boolean` | `false` | If `true`, disables the dropdown. |
1192
+ | `validationMessage` | `string` | `undefined` | A validation message that is displayed below the select field. |
1193
+ | `required` | `boolean` | `false` | If `true`, marks the field as required with an asterisk. |
1194
+ | `fullwidth` | `boolean` | `false` | If `true`, the dropdown will take the full width of its container. |
1195
+
1196
+ ### `Options` Type
1197
+
1198
+ Each option is represented by an object with the following properties:
1199
+
1200
+ | Name | Type | Description |
1201
+ |---------|--------|--------------------------------------------------------|
1202
+ | `label` | `string` | The label text displayed for the option. |
1203
+ | `value` | `any` | The unique value associated with the option. |
1204
+
1205
+ # ESewaNepaliDatepicker Component
1206
+
1207
+ The `ESewaNepaliDatepicker` component is a React component for selecting a Nepali date using the `nepali-datepicker-reactjs` library. It allows users to select a date in Nepali format, and it also supports custom styling and locales.
1208
+
1209
+ ## Usage
1210
+
1211
+ Here is an example of how to use the `ESewaNepaliDatepicker` component in your React application:
1212
+
1213
+ ```tsx
1214
+ import React, { useState } from 'react'
1215
+ import { ESewaNepaliDatepicker } from './esewa-ui-library'
1216
+
1217
+ const App = () => {
1218
+ const [date, setDate] = useState<string>('')
1219
+
1220
+ const handleDateChange = (newDate: string) => {
1221
+ setDate(newDate)
1222
+ }
1223
+
1224
+ return (
1225
+ <div>
1226
+ <ESewaNepaliDatepicker
1227
+ label="Select Nepali Date"
1228
+ value={date}
1229
+ onChange={handleDateChange}
1230
+ calenderLocale="ne" // You can use 'en' for English or 'ne' for Nepali locale
1231
+ />
1232
+ </div>
1233
+ )
1234
+ }
1235
+
1236
+ export default App
1237
+ ```
1238
+
1239
+ ### Props
1240
+
1241
+ The `ESewaNepaliDatepicker` component accepts the following props:
1242
+
1243
+ | Prop Name | Type | Description | Default Value |
1244
+ |------------------|------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|----------------|
1245
+ | `label` | `string` | The label text to display above the date picker. | `undefined` |
1246
+ | `className` | `string` | Custom class name to apply custom styles to the date picker component. | `undefined` |
1247
+ | `value` | `string` | The current date value in the form of a string. | `undefined` |
1248
+ | `onChange` | `(val: string) => void` | Callback function that is triggered when the selected date changes. It receives the selected date as a string. | `undefined` |
1249
+ | `calenderLocale` | `'en' | 'ne'` | The locale of the calendar. Use `'en'` for the English calendar or `'ne'` for the Nepali calendar. | `'en'` |
1250
+
1251
+ ### Example
1252
+
1253
+ ```tsx
1254
+ <ESewaNepaliDatepicker
1255
+ label="Select Nepali Date"
1256
+ value={date}
1257
+ onChange={handleDateChange}
1258
+ calenderLocale="ne"
1259
+ />
1260
+ ```
1261
+
1262
+ # ESewaRadio Component
1263
+
1264
+ The `ESewaRadio` component is a customizable radio button with a label, styled using `styled-components`. It supports the necessary props for usage in forms and customizable styling.
1265
+
1266
+ ## 2. Using the Component
1267
+
1268
+ After importing the `ESewaRadio` component, you can use it in your React components by passing the necessary props. Below is an example of how to use the radio button:
1269
+
1270
+ ### Example Usage
1271
+
1272
+ ```tsx
1273
+ import React, { useState } from 'react';
1274
+ import { ESewaRadio } from './esewa-ui-library'
1275
+
1276
+ const MyComponent = () => {
1277
+ const [isChecked, setChecked] = useState(false);
1278
+
1279
+ return (
1280
+ <div>
1281
+ <ESewaRadio
1282
+ label="Accept Terms and Conditions"
1283
+ name="terms"
1284
+ checked={isChecked}
1285
+ onChange={(checked) => setChecked(checked)}
1286
+ />
1287
+ </div>
1288
+ );
1289
+ };
1290
+
1291
+ export default MyComponent;
1292
+ ```
1293
+
1294
+ ## Explanation of Props
1295
+
1296
+ The `ESewaRadio` component accepts the following props:
1297
+
1298
+ ### `label`
1299
+ - **Type:** `string`
1300
+ - **Required:** No
1301
+ - **Description:** This prop is used to display the label next to the radio button. It is an optional prop and can be omitted if no label is needed.
1302
+
1303
+ ```tsx
1304
+ <ESewaRadio label="Accept Terms and Conditions" ... />
1305
+ ```
1306
+ ## Props
1307
+
1308
+ The `ESewaRadio` component accepts the following props:
1309
+
1310
+ | Prop | Type | Required | Default Value | Description |
1311
+ |-------------|-------------------------------|----------|---------------|--------------------------------------------------------------------------------------------------|
1312
+ | `label` | `string` | No | `undefined` | The label displayed next to the radio button. |
1313
+ | `name` | `string` | Yes | N/A | The name of the radio button, which groups it together with other radio buttons. |
1314
+ | `onChange` | `(checked: boolean) => void` | No | `undefined` | Callback function that is triggered when the radio button's checked state changes. |
1315
+ | `checked` | `boolean` | Yes | false | Determines whether the radio button is selected (`true`) or not (`false`). |
1316
+ | `labelClass`| `string` | No | `''` | A custom class applied to the label element for styling. |
1317
+ | `className` | `string` | No | `''` | A custom class applied to the root wrapper element of the radio button component. |
1318
+ | `disabled` | `boolean` | No | false | Used to disable radio state |
1319
+
1320
+ # ESewaSanitizeHtml Component
1321
+
1322
+ The `ESewaSanitizeHtml` component sanitizes HTML content before rendering it in a React component. It ensures that the HTML content is safe and free from malicious code by using the `DOMPurify` library.
1323
+
1324
+ ## Usage
1325
+
1326
+ To use the `ESewaSanitizeHtml` component, simply pass the raw HTML content as the `html` prop. The component will sanitize the content to ensure it is safe for rendering.
1327
+
1328
+ ### Example:
1329
+
1330
+ ```tsx
1331
+ import React from 'react'
1332
+ import { ESewaSanitizeHtml } from './esewa-ui-library'
1333
+
1334
+ const MyComponent = () => {
1335
+ const rawHtml = '<p style="color:red">This is <b>sanitized</b> HTML content.</p>'
1336
+
1337
+ return (
1338
+ <div>
1339
+ <h1>Sanitized HTML Example</h1>
1340
+ <ESewaSanitizeHtml html={rawHtml} />
1341
+ </div>
1342
+ )
1343
+ }
1344
+
1345
+ export default MyComponent
1346
+ ```
1347
+
1348
+ ### In this example:
1349
+
1350
+ - **rawHtml**: A string containing raw HTML content, including styles and tags such as `<p>` and `<b>`.
1351
+ - **ESewaSanitizeHtml component**: The component receives the `html` prop (in this case, `rawHtml`) and sanitizes it using `DOMPurify`.
1352
+ - **Sanitized HTML**: The sanitized HTML content is rendered inside a `div` element, using the `dangerouslySetInnerHTML` property.
1353
+
1354
+ By passing the raw HTML to the component, it ensures that any potentially harmful content (like JavaScript or malicious code) is removed, making the content safe to render on the page.
1355
+
1356
+ ### Props
1357
+
1358
+ | Prop | Type | Description |
1359
+ |---------|-----------------------|-----------------------------------------------------------------------------|
1360
+ | `html` | `string | undefined` | The raw HTML string that needs to be sanitized. It can be `undefined` as well. |
1361
+
1362
+ #### Prop Descriptions
1363
+
1364
+ - **html**: This is the raw HTML content that you want to sanitize before rendering. It should be a string, and you can optionally pass `undefined` if no HTML is available to render.
1365
+
1366
+ # ESewaSkeleton Component
1367
+
1368
+ The `ESewaSkeleton` component provides a customizable skeleton loader UI. It is often used as a placeholder while content is loading or being fetched asynchronously. The skeleton loader can be customized to appear as a rectangle or a circle and can be styled with different dimensions.
1369
+
1370
+ ### Example Usage
1371
+
1372
+ ```tsx
1373
+ import React, { useState, useEffect } from 'react'
1374
+ import { ESewaSkeleton } from './esewa-ui-library'
1375
+
1376
+ const YourComponent = () => {
1377
+ const [loading, setLoading] = useState(true)
1378
+
1379
+ useEffect(() => {
1380
+ setTimeout(() => {
1381
+ setLoading(false)
1382
+ }, 2000) // Simulating an API call
1383
+ }, [])
1384
+
1385
+ return (
1386
+ <div>
1387
+ <ESewaSkeleton loading={loading} width="200px" height="20px">
1388
+ <div>Content is loaded</div>
1389
+ </ESewaSkeleton>
1390
+ </div>
1391
+ )
1392
+ }
1393
+ ```
1394
+
1395
+ ### Props
1396
+
1397
+ | Name | Type | Default | Description |
1398
+ |-----------|--------------|--------------|---------------------------------------------------------|
1399
+ | `loading` | `boolean` | `false` | Determines if the skeleton should be shown. |
1400
+ | `width` | `string` | `100%` | Defines the width of the skeleton. |
1401
+ | `height` | `string` | `20px` | Defines the height of the skeleton. |
1402
+ | `circle` | `boolean` | `false` | Makes the skeleton circular (applies border-radius 50%). |
1403
+ | `className` | `string` | `''` | Additional class names for styling. |
1404
+ | `children` | `React.ReactNode` | `undefined` | Content to render when `loading` is false. |
1405
+
1406
+
1407
+ ## ESewaTag Component
1408
+
1409
+ The `ESewaTag` component is a flexible and customizable tag component used to display status labels, notifications, or simple tags with optional icons.
1410
+
1411
+ ### Usage
1412
+
1413
+ ```tsx
1414
+ import React from 'react'
1415
+ import { ESewaTag } from './esewa-ui-library'
1416
+ import { FaCheckCircle } from 'react-icons/fa'
1417
+
1418
+ const YourComponent = () => {
1419
+ const handleTagClick = () => {
1420
+ console.log('Tag clicked!')
1421
+ }
1422
+
1423
+ return (
1424
+ <div>
1425
+ <ESewaTag
1426
+ text="Success Tag"
1427
+ icon={<FaCheckCircle />}
1428
+ variant="success"
1429
+ iconPosition="start"
1430
+ size="normal"
1431
+ onClick={handleTagClick}
1432
+ />
1433
+
1434
+ <ESewaTag
1435
+ text="Warning Tag"
1436
+ variant="warning"
1437
+ size="small"
1438
+ onClick={handleTagClick}
1439
+ />
1440
+ </div>
1441
+ )
1442
+ }
1443
+ ```
1444
+
1445
+
1446
+ ### Props
1447
+
1448
+ | Name | Type | Default | Description |
1449
+ |----------------|----------------------|---------------|-----------------------------------------------------------------------------|
1450
+ | `text` | `string` | - | The text content to display inside the tag. |
1451
+ | `icon` | `string` | `React.ReactNode` | `undefined` | An optional icon to display alongside the text. |
1452
+ | `variant` | `'primary' | 'secondary' | 'danger' | 'success' | 'warning' | 'info'` | `'primary'` | Defines the tag's color scheme. Available variants: `primary`, `secondary`, `danger`, `success`, `warning`, `info`. |
1453
+ | `iconPosition` | `'start' | 'end'` | `'start'` | Defines the position of the icon. Choose between `start` (before text) or `end` (after text). |
1454
+ | `size` | `'normal' | 'small'` | `'normal'` | Defines the size of the tag. Available sizes: `normal`, `small`. |
1455
+ | `onClick` | `() => void` | `undefined` | A function to be triggered when the tag is clicked. |
1456
+
1457
+
1458
+ ## Tooltip Component
1459
+
1460
+ The `Tooltip` component provides an interactive tool-tip feature, displaying additional information when hovering over a target element. It is highly customizable, allowing the user to control the position of the tooltip and its appearance.
1461
+
1462
+ ### Features
1463
+
1464
+ - **Positioning**: Tooltips can be displayed on the top, bottom, left, or right of the target element.
1465
+ - **Transitions**: Smooth fade-in and fade-out effect with controlled visibility and opacity transitions.
1466
+ - **Customization**: Easily customizable styles with CSS variables and positioning options.
1467
+
1468
+ ### Example Usage
1469
+
1470
+ ```tsx
1471
+ import React, { useState } from 'react'
1472
+ import { ESewaTooltip } from './esewa-ui-library'
1473
+
1474
+ const TooltipExample = () => {
1475
+
1476
+ return (
1477
+ <ESewaTooltip content='Tooltip on click' position='bottom'>
1478
+ <button>Click Me</button>
1479
+ </ESewaTooltip>
1480
+ )
1481
+ }
1482
+
1483
+ export default TooltipExample
1484
+ ```
1485
+
1486
+ ### Props
1487
+
1488
+ | Name | Type | Default | Description |
1489
+ |------------------|-------------|------------|--------------------------------------------------------------------|
1490
+ | `position` | `'top' | 'bottom' | 'left' | 'right'` | `'top'` | Determines where the tooltip will appear in relation to the target element. Available positions: `top`, `bottom`, `left`, `right`. |
1491
+ | `content` | `string` | - | The content/text to display inside the tooltip. |
1492
+ | `target` | `React.ReactNode` | - | The target element which will trigger the tooltip. |
1493
+ | `delay` | `number` | `0` | The delay in milliseconds before the tooltip becomes visible. |
1494
+ | `className` | `string` | `''` | Additional class names for styling or overriding default styles. |
1495
+
1496
+ ### CSS Custom Variables
1497
+
1498
+ - `--secondary`: Defines the background color of the tooltip.
1499
+ - `--white`: Defines the text color of the tooltip.
1500
+
1501
+
1502
+ ### Providers
1503
+
1504
+ - **ThemeProvider**: `ThemeProvider`
1505
+
1506
+ Wrap your component with this provider to apply theme.
1507
+
1508
+ ```tsx
1509
+ import { StrictMode } from 'react'
1510
+ import { createRoot } from 'react-dom/client'
1511
+ import { ESewaThemeProvider } from 'esewa-ui-library'
1512
+ import App from './App.tsx'
1513
+
1514
+ createRoot(document.getElementById('root')!).render(
1515
+ <StrictMode>
1516
+ <ESewaThemeProvider>
1517
+ <App />
1518
+ </ESewaThemeProvider>
1519
+ </StrictMode>,
1520
+ )
1521
+
1522
+ ```
1523
+
1524
+ In your page
1525
+
1526
+ ```tsx
1527
+ import { useEffect, useState } from "react";
1528
+ import {
1529
+ MoonIcon,
1530
+ SunIcon,
1531
+ } from "@heroicons/react/24/outline";
1532
+
1533
+ const [darkMode, setDarkMode] = useState<boolean>(
1534
+ window.matchMedia('(prefers-color-scheme: dark)').matches
1535
+ );
1536
+
1537
+ const handleThemeToggle = () => {
1538
+ setDarkMode((prevMode) => !prevMode);
1539
+ };
1540
+
1541
+ useEffect(() => {
1542
+ const theme = darkMode ? 'dark' : 'light';
1543
+ document.documentElement.setAttribute('data-theme', theme);
1544
+ }, [darkMode]);
1545
+
1546
+ <button
1547
+ onClick={handleThemeToggle}
1548
+ >
1549
+ {darkMode ? (
1550
+ <SunIcon className="h-6 w-6" />
1551
+ ) : (
1552
+ <MoonIcon className="h-6 w-6" />
1553
+ )}
1554
+ </button>
1555
+
1556
+ ```
1557
+
1558
+ - **ESewaProvider**: `ESewaProvider`
1559
+
1560
+ Wrap your component with this provider.
1561
+
1562
+ ```tsx
1563
+ import { StrictMode } from 'react'
1564
+ import { createRoot } from 'react-dom/client'
1565
+ import { ESewaProvider } from 'esewa-ui-library'
1566
+ import App from './App.tsx'
1567
+
1568
+ createRoot(document.getElementById('root')!).render(
1569
+ <StrictMode>
1570
+ <ESewaProvider>
1571
+ <App />
1572
+ </ESewaProvider>
1573
+ </StrictMode>,
1574
+ )
1575
+
1576
+ ```
1577
+
1578
+ then you can use useESewaDataProvider
1579
+
1580
+ ```tsx
1581
+ import { ESewaAppBar, useESewaDataProvider } from 'esewa-ui-library';
1582
+
1583
+ const App = () => {
1584
+ const { updateData } = useESewaDataProvider();
1585
+
1586
+ useEffect(() => {
1587
+ updateData({
1588
+ title: "Merchant Product Form",
1589
+ });
1590
+ }, []);
1591
+
1592
+ return (
1593
+ <ESewaAppBar
1594
+ icon="icon-es-arrow-left"
1595
+ titleposition="left"
1596
+ onBackIconClick={() => console.log('Back icon clicked')}
1597
+ onTitleClick={() => console.log('Title clicked')}
1598
+ onActionIconClick={() => console.log('Action icon clicked')}
1599
+ actionIcon="icon-settings"
1600
+ />
1601
+ );
1602
+ };
1603
+
1604
+ export default App;
1605
+
1606
+ ```
1607
+
1608
+
1609
+ - **ESewaPaymentProvider**: `ESewaPaymentProvider`
1610
+
1611
+ # Services
1612
+
1613
+ ## Overview
1614
+
1615
+ This library provides a set of services that allow interaction between the merchant app and the host application. These services include authentication, location access, user detail retrieval, media access, and transaction validation.
1616
+
1617
+ ## Table of Contents
1618
+
1619
+ - [Initialization](#initialization)
1620
+ - [Service Requests](#service-requests)
1621
+ - [Location Request](#location-request)
1622
+ - [User Detail Request](#user-detail-request)
1623
+ - [Media Access Request](#media-access-request)
1624
+ - [Validate Payment](#validate-payment)
1625
+ - [Request Payment](#request-payment)
1626
+ - [Close App](#close-app)
1627
+ - [Get Product](#get-product)
1628
+ - [Validate User](#validate-user)
1629
+ - [Merchant Detail](#merchant-detail)
1630
+ - [QR Scanner Request](#qr-scanner-request)
1631
+ - [Request File Download](#request-file-download)
1632
+ - [Error Handling](#error-handling)
1633
+
1634
+ ## Initialization
1635
+
1636
+ Before the app loads, it must be initialized to obtain authentication credentials.
1637
+
1638
+ ### Usage
1639
+
1640
+ ```tsx
1641
+ useEffect(() => {
1642
+ const saveAuthData = (res: { token?: string; scope?: any }): void => {
1643
+ if (!res?.token) {
1644
+ console.warn('Token is missing, skipping storage');
1645
+ return;
1646
+ }
1647
+ sessionStorage.setItem('miniAppAuthToken', res.token);
1648
+ sessionStorage.setItem('miniAppAuthScope', JSON.stringify(res.scope || {}));
1649
+ };
1650
+
1651
+ const initAppCallback = (data: any) => {
1652
+ try {
1653
+ if (!data) {
1654
+ throw new Error('Received null or undefined response');
1655
+ }
1656
+ const res = JSON.parse(data);
1657
+ if (!res || typeof res !== 'object') {
1658
+ throw new Error('Parsed response is not a valid object');
1659
+ }
1660
+ if (res?.error_message) {
1661
+ return;
1662
+ }
1663
+ saveAuthData(res);
1664
+ } catch (error) {
1665
+ console.error('Error parsing response:', error);
1666
+ }
1667
+ };
1668
+
1669
+ const requestData = {
1670
+ merchant_identifier: 'IAAAAABTOBAbFhAXHhEHAgoXX0FRR1FJJiw3LCwkJzE=', //your identifier key
1671
+ requestType: REQUEST_TYPE_ENUM.INIT_APP,
1672
+ callbackKey: CALLBACK_TYPE_ENUM.INIT_APP_CALLBACK
1673
+ };
1674
+
1675
+ requestFromMiniApp(requestData, initAppCallback);
1676
+ }, []);
1677
+ ```
1678
+
1679
+ ### Response Examples
1680
+
1681
+ #### Success
1682
+
1683
+ ```json
1684
+ {
1685
+ "token": "SEdcRFVePhYfCRtQJhEiATA8DyVWFFA7Dw8UBEAKH1IkLFwYJAUxPgI%3D",
1686
+ "scope": [
1687
+ "USER_DETAIL_ACCESS",
1688
+ "LOCATION_ACCESS",
1689
+ "MEDIA_ACCESS"
1690
+ ]
1691
+ }
1692
+ ```
1693
+
1694
+ #### Error
1695
+
1696
+ ```json
1697
+ {
1698
+ "error_message": "Service is currently unavailable."
1699
+ }
1700
+ ```
1701
+
1702
+ ## Service Requests
1703
+ Merchants can only request services that are included in their granted scope. Before making a request, ensure the service type exists in scope.
1704
+
1705
+ #### Location Request
1706
+
1707
+ Pass the token received from initialization to request location access.
1708
+
1709
+ ```tsx
1710
+ const onLocationRequestClick = () => {
1711
+ const obj: REQUEST_DATA_TYPE = {
1712
+ requestType: REQUEST_TYPE_ENUM.LOCATION_ACCESS,
1713
+ token: sessionStorage.getItem('miniAppAuthToken'),
1714
+ callbackKey: CALLBACK_TYPE_ENUM.LOCATION_ACCESS_CALLBACK
1715
+ }
1716
+
1717
+ const locationAccessCallBack: any = (data: any) => {
1718
+ console.log('Location Access Response:', data)
1719
+
1720
+ try {
1721
+ if (!data) {
1722
+ throw new Error('Received null or undefined response')
1723
+ }
1724
+ const res = JSON.parse(data)
1725
+ if (!res || typeof res !== 'object') {
1726
+ throw new Error('Parsed response is not a valid object')
1727
+ }
1728
+ if (res?.error_message) {
1729
+ throw new Error('Error res', res.error_message)
1730
+ }
1731
+ setLocationDetail(res) //use this response as needed
1732
+ } catch (error) {
1733
+ console.error('Error parsing response:', error)
1734
+ }
1735
+ }
1736
+
1737
+ requestFromMiniApp(
1738
+ obj,
1739
+ locationAccessCallBack
1740
+ )
1741
+ }
1742
+ ```
1743
+
1744
+ #### User Detail Request
1745
+
1746
+ ```tsx
1747
+ const onUserDetailRequestClick = () => {
1748
+ const obj = {
1749
+ requestType: REQUEST_TYPE_ENUM.USER_DETAIL_ACCESS,
1750
+ token: sessionStorage.getItem('miniAppAuthToken'),
1751
+ merchant_identifier: 'IAAAAABTOBAbFhAXHhEHAgoXX0FRR1FJJiw3LCwkJzE=',
1752
+ callbackKey: CALLBACK_TYPE_ENUM.USER_DETAIL_ACCESS_CALLBACK
1753
+ };
1754
+
1755
+ const userDetailAccessCallBack = (data: any) => {
1756
+ try {
1757
+ if (!data) throw new Error('Received null or undefined response');
1758
+ const res = JSON.parse(data);
1759
+ if (res?.error_message) throw new Error(res.error_message);
1760
+ setUserDetail(res);
1761
+ } catch (error) {
1762
+ console.error('Error parsing response:', error);
1763
+ }
1764
+ };
1765
+
1766
+ requestFromMiniApp(obj, userDetailAccessCallBack);
1767
+ };
1768
+ ```
1769
+
1770
+ #### Media Access Request
1771
+
1772
+ ```tsx
1773
+ const onMediaAccessRequestClick = () => {
1774
+ const obj = {
1775
+ requestType: REQUEST_TYPE_ENUM.MEDIA_ACCESS,
1776
+ token: sessionStorage.getItem('miniAppAuthToken'),
1777
+ callbackKey: CALLBACK_TYPE_ENUM.MEDIA_ACCESS_CALLBACK
1778
+ };
1779
+
1780
+ const mediaAccessCallBack = (data: any) => {
1781
+ try {
1782
+ if (!data) throw new Error('Received null or undefined response');
1783
+ const res = data;
1784
+ if (res?.error_message) throw new Error(res.error_message);
1785
+ setMediaDetail(res);
1786
+ } catch (error) {
1787
+ console.error('Error parsing response:', error);
1788
+ }
1789
+ };
1790
+
1791
+ requestFromMiniApp(obj, mediaAccessCallBack);
1792
+ };
1793
+ ```
1794
+
1795
+ #### Validate Payment
1796
+ Pass token received from initialize request call with respective request type and callback key
1797
+
1798
+ ```tsx
1799
+ const onValidateTransactionClick = () => {
1800
+ const obj = {
1801
+ requestType: REQUEST_TYPE_ENUM.VALIDATE_TRANSACTION,
1802
+ token: sessionStorage.getItem('miniAppAuthToken'),
1803
+ callbackKey: CALLBACK_TYPE_ENUM.VALIDATE_TRANSACTION_CALLBACK
1804
+ };
1805
+
1806
+ const validateTransactionCallBack = (data: any) => {
1807
+ try {
1808
+ if (!data) throw new Error('Received null or undefined response');
1809
+ const res = JSON.parse(data);
1810
+ if (res?.error_message) throw new Error(res.error_message);
1811
+ setTransactionValidateRes(res);
1812
+ } catch (error) {
1813
+ console.error('Error parsing response:', error);
1814
+ }
1815
+ };
1816
+
1817
+ requestFromMiniApp(obj, validateTransactionCallBack);
1818
+ };
1819
+ ```
1820
+ #### Request Payment
1821
+ Pass token received from initialize request call with respective request type, callback key , your merchant identifier and request payload
1822
+
1823
+ ```tsx
1824
+ const onRequestPaymentClick = () => {
1825
+ const productPayload = {
1826
+ "product_code": "NP-ES-VIANET",
1827
+ "amount": 28.48,
1828
+ "properties": {
1829
+ "productId": "3299",
1830
+ "payment_id": "1613103_PP",
1831
+ "refId": "400005",
1832
+ "customer_id": "48707",
1833
+ "payer": "CUSTOMER"
1834
+ },
1835
+ "channel": "WEB_USER"
1836
+ };
1837
+
1838
+ const obj = {
1839
+ requestType: REQUEST_TYPE_ENUM.REQUEST_PAYMENT,
1840
+ merchant_identifier: 'IAAAAABTOBAbFhAXHhEHAgoXX0FRR1FJJiw3LCwkJzE=',
1841
+ token: sessionStorage.getItem('miniAppAuthToken'),
1842
+ data: productPayload,
1843
+ callbackKey: CALLBACK_TYPE_ENUM.REQUEST_PAYMENT_CALLBACK
1844
+ };
1845
+
1846
+ const requestPaymentCallBack: any = (data:any) => {
1847
+ console.log("Make payment Response:", data);
1848
+
1849
+ try {
1850
+ if (!data) {
1851
+ throw new Error('Received null or undefined response');
1852
+ }
1853
+ const res = JSON.parse(data);
1854
+
1855
+ if (!res || typeof res !== 'object') {
1856
+ throw new Error('Parsed response is not a valid object');
1857
+ }
1858
+
1859
+ if (res?.error_message) {
1860
+ throw new Error('Error res', res.error_message);
1861
+ }
1862
+
1863
+ setMakePaymentRes(res);
1864
+ } catch (error) {
1865
+ console.error('Error parsing response:', error);
1866
+ }
1867
+ };
1868
+
1869
+ requestFromMiniApp(obj, requestPaymentCallBack);
1870
+ };
1871
+ ```
1872
+
1873
+ #### Close App
1874
+
1875
+ Pass the following to close the app.
1876
+
1877
+ ```tsx
1878
+ const onCloseRequestClick = () => {
1879
+ const obj: REQUEST_DATA_TYPE = {
1880
+ requestType: REQUEST_TYPE_ENUM.CLOSE_APP,
1881
+ callbackKey: CALLBACK_TYPE_ENUM.CLOSE_APP_CALLBACK
1882
+ }
1883
+
1884
+ requestFromMiniApp(
1885
+ obj
1886
+ )
1887
+ }
1888
+ ```
1889
+
1890
+ #### Get Product Request
1891
+
1892
+ ```tsx
1893
+ const onGetProductClick = () => {
1894
+ const obj = {
1895
+ requestType: REQUEST_TYPE_ENUM.GET_PRODUCT,
1896
+ token: sessionStorage.getItem('miniAppAuthToken'),
1897
+ callbackKey: CALLBACK_TYPE_ENUM.GET_PRODUCT_CALLBACK
1898
+ };
1899
+
1900
+ const getProductCallBack = (data: any) => {
1901
+ try {
1902
+ if (!data) throw new Error('Received null or undefined response');
1903
+ const res = JSON.parse(data);
1904
+ if (res?.error_message) throw new Error(res.error_message);
1905
+ setProduct(res);
1906
+ } catch (error) {
1907
+ console.error('Error parsing response:', error);
1908
+ }
1909
+ };
1910
+
1911
+ requestFromMiniApp(obj, getProductCallBack);
1912
+ };
1913
+ ```
1914
+
1915
+ #### Validate User Request
1916
+
1917
+ ```tsx
1918
+ const onValidateUserClick = () => {
1919
+ const obj = {
1920
+ requestType: REQUEST_TYPE_ENUM.VALIDATE_USER,
1921
+ token: sessionStorage.getItem('miniAppAuthToken'),
1922
+ callbackKey: CALLBACK_TYPE_ENUM.VALIDATE_USER_CALLBACK,
1923
+ data: {
1924
+ esewa_id: 9847474747
1925
+ }
1926
+ };
1927
+
1928
+ const validateUserCallBack = (data: any) => {
1929
+ try {
1930
+ if (!data) throw new Error('Received null or undefined response');
1931
+ const res = JSON.parse(data);
1932
+ if (res?.error_message) throw new Error(res.error_message);
1933
+ setProduct(res);
1934
+ } catch (error) {
1935
+ console.error('Error parsing response:', error);
1936
+ }
1937
+ };
1938
+
1939
+ requestFromMiniApp(obj, validateUserCallBack);
1940
+ };
1941
+ ```
1942
+
1943
+ #### Merchant Detail Request
1944
+
1945
+ ```tsx
1946
+ const onMerchantDetailClick = () => {
1947
+ const obj = {
1948
+ requestType: REQUEST_TYPE_ENUM.MERCHANT_DETAIL,
1949
+ token: sessionStorage.getItem('miniAppAuthToken'),
1950
+ callbackKey: CALLBACK_TYPE_ENUM.MERCHANT_DETAIL_CALLBACK
1951
+ };
1952
+
1953
+ const merchantDetailCallBack = (data: any) => {
1954
+ try {
1955
+ if (!data) throw new Error('Received null or undefined response');
1956
+ const res = JSON.parse(data);
1957
+ if (res?.error_message) throw new Error(res.error_message);
1958
+ setProduct(res);
1959
+ } catch (error) {
1960
+ console.error('Error parsing response:', error);
1961
+ }
1962
+ };
1963
+
1964
+ requestFromMiniApp(obj, merchantDetailCallBack);
1965
+ };
1966
+ ```
1967
+
1968
+ #### QR Scanner Request
1969
+
1970
+ ```tsx
1971
+ const onQrScannerClick = () => {
1972
+ const obj = {
1973
+ requestType: REQUEST_TYPE_ENUM.QR_SCANNER_ACCESS,
1974
+ token: sessionStorage.getItem('miniAppAuthToken'),
1975
+ callbackKey: CALLBACK_TYPE_ENUM.QR_SCANNER_ACCESS_CALLBACK
1976
+ };
1977
+
1978
+ const qrScannerCallBack = (data: any) => {
1979
+ try {
1980
+ if (!data) throw new Error('Received null or undefined response');
1981
+ const res = JSON.parse(data);
1982
+ if (res?.error_message) throw new Error(res.error_message);
1983
+ setProduct(res);
1984
+ } catch (error) {
1985
+ console.error('Error parsing response:', error);
1986
+ }
1987
+ };
1988
+
1989
+ requestFromMiniApp(obj, qrScannerCallBack);
1990
+ };
1991
+ ```
1992
+
1993
+ #### Request File Download
1994
+
1995
+ Pass the following to request file download.
1996
+
1997
+ **1. Link Type file download request**
1998
+
1999
+ const onPdfDownloadRequestClick = () => {
2000
+ const obj: REQUEST_DATA_TYPE = {
2001
+ requestType: REQUEST_TYPE_ENUM.FILE_DOWNLOAD_ACCESS,
2002
+ callbackKey: CALLBACK_TYPE_ENUM.FILE_DOWNLOAD_ACCESS_CALLBACK,
2003
+ data: {
2004
+ fileName: 'Statement-2025.pdf',
2005
+ type: 'url',
2006
+ content: 'https://www.aeee.in/wp-content/uploads/2020/08/Sample-pdf.pdf' //pass file url
2007
+ }
2008
+ }
2009
+
2010
+ const fileDownloadCallBack: any = (data: any) => {
2011
+ try{
2012
+ if (!data) {
2013
+ throw new Error('Received null or undefined response')
2014
+ }
2015
+ const res = data
2016
+ if (res?.error_message) { //fail case
2017
+ throw new Error('Error res', res.error_message)
2018
+ }
2019
+ else{
2020
+ console.log(res.message) //success case
2021
+ }
2022
+ }
2023
+ catch (error) {
2024
+ console.error('Error parsing response:', error)
2025
+ }
2026
+ }
2027
+
2028
+ requestFromMiniApp(
2029
+ obj,
2030
+ fileDownloadCallBack
2031
+ )
2032
+ }
2033
+
2034
+ **2. Base64 Encoded Type file download request**
2035
+
2036
+ const onPdfDownloadRequestClick = () => {
2037
+ const response = await fetch('/base64.txt');
2038
+ const content = await response.text(); //encoded pdf content/response from api
2039
+ let base64Content = content.includes(',')
2040
+ ? content
2041
+ : `data:application/pdf;base64,${content}`;
2042
+ const obj: REQUEST_DATA_TYPE = {
2043
+ requestType: REQUEST_TYPE_ENUM.FILE_DOWNLOAD_ACCESS,
2044
+ callbackKey: CALLBACK_TYPE_ENUM.FILE_DOWNLOAD_ACCESS_CALLBACK,
2045
+ data: {
2046
+ fileName: 'Statement-base64-2025.pdf',
2047
+ type: 'base64',
2048
+ content: base64Content
2049
+ }
2050
+ }
2051
+
2052
+ const fileDownloadCallBack: any = (data: any) => {
2053
+ try{
2054
+ if (!data) {
2055
+ throw new Error('Received null or undefined response')
2056
+ }
2057
+ const res = data
2058
+ if (res?.error_message) { //fail case
2059
+ throw new Error('Error res', res.error_message)
2060
+ }
2061
+ else{
2062
+ console.log(res.message) //success case
2063
+ }
2064
+ }
2065
+ catch (error) {
2066
+ console.error('Error parsing response:', error)
2067
+ }
2068
+ }
2069
+
2070
+ requestFromMiniApp(
2071
+ obj,
2072
+ fileDownloadCallBack
2073
+ )
2074
+ }
2075
+
2076
+ ## Error Handling
2077
+
2078
+ Errors are returned as JSON responses with an `error_message` field.
2079
+
2080
+ #### Example
2081
+
2082
+ ```json
2083
+ {
2084
+ "error_message": "Service is currently unavailable"
2085
+ }
2086
+ ```
2087
+
2088
+ ```json
2089
+ {
2090
+ "error_message": "Merchant scope not found"
2091
+ }
2092
+ ```
2093
+ ---
2094
+
2095
+ This document provides a structured approach to interacting with the MiniApp services, ensuring proper initialization and error handling for seamless integration.
2096
+
2097
+ ### Utilities
2098
+
2099
+ - `titleCase`
2100
+ - `revertIgnoredCase`
2101
+ - `formatText`
2102
+ - `formatAmount`
2103
+ - `debounce`
2104
+ - `reverseCamelCase`
2105
+ - `reverseSnakeCase`
2106
+
2107
+ ### Types
2108
+
2109
+ - `REQUEST_TYPE_ENUM`
2110
+
2111
+ ```tsx
2112
+ import {REQUEST_TYPE_ENUM} from 'esewa-ui-library'
2113
+ ```
2114
+
2115
+ ```json
2116
+ enum REQUEST_TYPE_ENUM {
2117
+ INIT_APP = 'INIT_APP',
2118
+ REQUEST_PAYMENT = 'REQUEST_PAYMENT',
2119
+ USER_DETAIL_ACCESS = 'USER_DETAIL_ACCESS',
2120
+ MEDIA_ACCESS = 'MEDIA_ACCESS',
2121
+ LOCATION_ACCESS = 'LOCATION_ACCESS',
2122
+ VALIDATE_TRANSACTION = 'VALIDATE_TRANSACTION',
2123
+ CLOSE_APP = 'CLOSE_APP',
2124
+ FILE_DOWNLOAD_ACCESS = 'FILE_DOWNLOAD_ACCESS'
2125
+ GET_PRODUCT = 'GET_PRODUCT',
2126
+ VALIDATE_USER = 'VALIDATE_USER',
2127
+ MERCHANT_DETAIL = 'MERCHANT_DETAIL',
2128
+ QR_SCANNER_ACCESS = 'QR_SCANNER_ACCESS'
2129
+ }
2130
+ ```
2131
+
2132
+ - `CALLBACK_TYPE_ENUM`
2133
+
2134
+ ```tsx
2135
+ import {CALLBACK_TYPE_ENUM} from 'esewa-ui-library'
2136
+ ```
2137
+
2138
+ ```json
2139
+ enum CALLBACK_TYPE_ENUM{
2140
+ INIT_APP_CALLBACK = 'INIT_APP_CALLBACK',
2141
+ REQUEST_PAYMENT_CALLBACK = 'REQUEST_PAYMENT_CALLBACK',
2142
+ USER_DETAIL_ACCESS_CALLBACK = 'USER_DETAIL_ACCESS_CALLBACK',
2143
+ MEDIA_ACCESS_CALLBACK = 'MEDIA_ACCESS_CALLBACK',
2144
+ LOCATION_ACCESS_CALLBACK = 'LOCATION_ACCESS_CALLBACK',
2145
+ VALIDATE_TRANSACTION_CALLBACK = 'VALIDATE_TRANSACTION_CALLBACK',
2146
+ CLOSE_APP_CALLBACK = 'CLOSE_APP_CALLBACK',
2147
+ FILE_DOWNLOAD_ACCESS_CALLBACK = 'FILE_DOWNLOAD_ACCESS_CALLBACK',
2148
+ GET_PRODUCT_CALLBACK = 'GET_PRODUCT_CALLBACK',
2149
+ VALIDATE_USER_CALLBACK = 'VALIDATE_USER_CALLBACK',
2150
+ MERCHANT_DETAIL_CALLBACK = 'MERCHANT_DETAIL_CALLBACK',
2151
+ QR_SCANNER_ACCESS_CALLBACK = 'QR_SCANNER_ACCESS_CALLBACK'
2152
+ }
2153
+ ```
2154
+
2155
+ <!-- ### Hooks
2156
+
2157
+ - `useMessage`
2158
+ - `useSessionStorage`
2159
+ - `useDebounce` -->
2160
+
2161
+ ## Contributing
2162
+
2163
+ Feel free to submit issues and pull requests. Make sure to follow the coding guidelines and write tests where applicable.
2164
+
2165
+ ## License
2166
+
2167
+ This project is licensed under the MIT License.