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