esewa-ui-library 1.0.3 → 1.0.4

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
@@ -108,15 +108,25 @@ export default App;
108
108
 
109
109
  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.
110
110
 
111
+ Use useESewaDataProvider to set title for appbar.
112
+
111
113
  ### Usage:
112
114
 
113
115
  ```tsx
114
- import { ESewaAppBar } from 'esewa-ui-library';
116
+ import { ESewaAppBar, useESewaDataProvider } from 'esewa-ui-library';
115
117
 
116
118
  const App = () => {
119
+ const { updateData } = useESewaDataProvider();
120
+
121
+ useEffect(() => {
122
+ updateData({
123
+ title: "Merchant Product Form",
124
+ });
125
+ }, []);
126
+
117
127
  return (
118
128
  <ESewaAppBar
119
- title="App Bar Title"
129
+ icon="icon-es-arrow-left"
120
130
  titleposition="left"
121
131
  onBackIconClick={() => console.log('Back icon clicked')}
122
132
  onTitleClick={() => console.log('Title clicked')}
@@ -582,17 +592,19 @@ const App = () => {
582
592
  <div>
583
593
  <button onClick={openDialog}>Open Dialog</button>
584
594
 
585
- <ESewaDialog
586
- isOpen={isOpen}
587
- title="Sample Dialog"
588
- okText="Confirm"
589
- cancelText="Cancel"
590
- onOk={handleOk}
591
- onCancel={closeDialog}
592
- position="center"
593
- >
594
- <p>Dialog content goes here.</p>
595
- </ESewaDialog>
595
+ {
596
+ isOpen && (<ESewaDialog
597
+ isOpen={isOpen}
598
+ title="Sample Dialog"
599
+ okText="Confirm"
600
+ cancelText="Cancel"
601
+ onOk={handleOk}
602
+ onCancel={closeDialog}
603
+ position="center"
604
+ >
605
+ <p>Dialog content goes here.</p>
606
+ </ESewaDialog>)
607
+ }
596
608
  </div>
597
609
  );
598
610
  };
@@ -1487,7 +1499,110 @@ export default TooltipExample
1487
1499
  ### Providers
1488
1500
 
1489
1501
  - **ThemeProvider**: `ThemeProvider`
1502
+
1503
+ Wrap your component with this provider to apply theme.
1504
+
1505
+ ```tsx
1506
+ import { StrictMode } from 'react'
1507
+ import { createRoot } from 'react-dom/client'
1508
+ import { ESewaThemeProvider } from 'esewa-ui-library'
1509
+ import App from './App.tsx'
1510
+
1511
+ createRoot(document.getElementById('root')!).render(
1512
+ <StrictMode>
1513
+ <ESewaThemeProvider>
1514
+ <App />
1515
+ </ESewaThemeProvider>
1516
+ </StrictMode>,
1517
+ )
1518
+
1519
+ ```
1520
+
1521
+ In your page
1522
+
1523
+ ```tsx
1524
+ import { useEffect, useState } from "react";
1525
+ import {
1526
+ MoonIcon,
1527
+ SunIcon,
1528
+ } from "@heroicons/react/24/outline";
1529
+
1530
+ const [darkMode, setDarkMode] = useState<boolean>(
1531
+ window.matchMedia('(prefers-color-scheme: dark)').matches
1532
+ );
1533
+
1534
+ const handleThemeToggle = () => {
1535
+ setDarkMode((prevMode) => !prevMode);
1536
+ };
1537
+
1538
+ useEffect(() => {
1539
+ const theme = darkMode ? 'dark' : 'light';
1540
+ document.documentElement.setAttribute('data-theme', theme);
1541
+ }, [darkMode]);
1542
+
1543
+ <button
1544
+ onClick={handleThemeToggle}
1545
+ >
1546
+ {darkMode ? (
1547
+ <SunIcon className="h-6 w-6" />
1548
+ ) : (
1549
+ <MoonIcon className="h-6 w-6" />
1550
+ )}
1551
+ </button>
1552
+
1553
+ ```
1554
+
1490
1555
  - **ESewaProvider**: `ESewaProvider`
1556
+
1557
+ Wrap your component with this provider.
1558
+
1559
+ ```tsx
1560
+ import { StrictMode } from 'react'
1561
+ import { createRoot } from 'react-dom/client'
1562
+ import { ESewaProvider } from 'esewa-ui-library'
1563
+ import App from './App.tsx'
1564
+
1565
+ createRoot(document.getElementById('root')!).render(
1566
+ <StrictMode>
1567
+ <ESewaProvider>
1568
+ <App />
1569
+ </ESewaProvider>
1570
+ </StrictMode>,
1571
+ )
1572
+
1573
+ ```
1574
+
1575
+ then you can use useESewaDataProvider
1576
+
1577
+ ```tsx
1578
+ import { ESewaAppBar, useESewaDataProvider } from 'esewa-ui-library';
1579
+
1580
+ const App = () => {
1581
+ const { updateData } = useESewaDataProvider();
1582
+
1583
+ useEffect(() => {
1584
+ updateData({
1585
+ title: "Merchant Product Form",
1586
+ });
1587
+ }, []);
1588
+
1589
+ return (
1590
+ <ESewaAppBar
1591
+ icon="icon-es-arrow-left"
1592
+ titleposition="left"
1593
+ onBackIconClick={() => console.log('Back icon clicked')}
1594
+ onTitleClick={() => console.log('Title clicked')}
1595
+ onActionIconClick={() => console.log('Action icon clicked')}
1596
+ actionIcon="icon-settings"
1597
+ />
1598
+ );
1599
+ };
1600
+
1601
+ export default App;
1602
+
1603
+ ```
1604
+
1605
+
1491
1606
  - **ESewaPaymentProvider**: `ESewaPaymentProvider`
1492
1607
 
1493
1608
  # Services
@@ -46,16 +46,19 @@ declare global {
46
46
  VALIDATE_TRANSACTION_CALLBACK?: Callback | null;
47
47
  };
48
48
  webkit: {
49
- requestApp: (data: any) => void;
50
- receiveFromApp: (data: any) => void;
51
49
  messageHandlers: {
52
50
  iOSNative: {
53
- requestApp: (data: any) => void;
51
+ postMessage: (data: any) => void;
52
+ INIT_APP_CALLBACK?: Callback | null;
53
+ REQUEST_PAYMENT_CALLBACK?: Callback | null;
54
+ USER_DETAIL_ACCESS_CALLBACK?: Callback | null;
55
+ MEDIA_ACCESS_CALLBACK?: Callback | null;
56
+ LOCATION_ACCESS_CALLBACK?: Callback | null;
57
+ VALIDATE_TRANSACTION_CALLBACK?: Callback | null;
54
58
  };
55
59
  };
56
- receiveDataFromWeb: (data: any) => void;
57
- receiveDataFromApp: (data: any) => void;
58
60
  };
59
61
  }
60
62
  function getDataFromMiniApp(e: any): void;
61
63
  }
64
+ export declare type CallbackKey = keyof Window['Android'] | 'INIT_APP_CALLBACK' | 'REQUEST_PAYMENT_CALLBACK' | 'USER_DETAIL_ACCESS_CALLBACK' | 'MEDIA_ACCESS_CALLBACK' | 'LOCATION_ACCESS_CALLBACK' | 'VALIDATE_TRANSACTION_CALLBACK';
package/dist/index.js CHANGED
@@ -186,7 +186,7 @@ var StyledAppBar = styled__default.header.attrs(function (_ref) {
186
186
  return {
187
187
  titleposition: titleposition
188
188
  };
189
- })(_templateObject$3 || (_templateObject$3 = _taggedTemplateLiteralLoose(["\n .e-app-bar {\n display: flex;\n justify-content: space-between;\n flex-direction: row;\n align-items: center;\n background-color: var(--appbar-bg-top);\n padding: 7px 12px;\n position: fixed;\n height: 42px;\n left: 0;\n right: 0;\n gap: var(--values-value-8);\n\n &--nav-icon, &--close-icon {\n padding: 7px;\n color: var(--white);\n display: flex;\n align-items: center;\n justify-content: center;\n }\n\n /* Title section */\n &--title-wrapper {\n display: flex;\n justify-content: ", ";\n align-items: center;\n width: 100%; // Ensures the title section takes full width to apply the alignment\n }\n\n &--title {\n display: flex;\n align-items: center;\n gap: 12px;\n overflow: hidden;\n // display: -webkit-box;\n // -webkit-line-clamp: 1;\n // line-clamp: 1;\n // -webkit-box-orient: vertical;\n }\n\n &--title-image img {\n width: 32px;\n object-fit: cover;\n // margin-left: -32px;\n background: var(--white);\n border: 1px solid var(--border);\n border-radius: var(--grid-borderradius-border-radius-xs);\n }\n\n &--title-label {\n color: var(--white);\n letter-spacing: 0.4px;\n font-size: var(--values-value-16);\n font-weight: 500;\n }\n }\n"])), function (props) {
189
+ })(_templateObject$3 || (_templateObject$3 = _taggedTemplateLiteralLoose(["\n width: 100%;\n\n .e-app-bar {\n display: flex;\n justify-content: space-between;\n flex-direction: row;\n align-items: center;\n background-color: var(--appbar-bg-top);\n padding: 7px 12px;\n position: relative;\n height: 42px;\n // left: 0;\n // right: 0;\n gap: var(--values-value-8);\n\n &--nav-icon, &--close-icon {\n padding: 7px;\n color: var(--white);\n display: flex;\n align-items: center;\n justify-content: center;\n }\n\n /* Title section */\n &--title-wrapper {\n display: flex;\n justify-content: ", ";\n align-items: center;\n width: 100%; // Ensures the title section takes full width to apply the alignment\n }\n\n &--title {\n display: flex;\n align-items: center;\n gap: 12px;\n overflow: hidden;\n // display: -webkit-box;\n // -webkit-line-clamp: 1;\n // line-clamp: 1;\n // -webkit-box-orient: vertical;\n }\n\n &--title-image img {\n width: 32px;\n object-fit: cover;\n // margin-left: -32px;\n background: var(--white);\n border: 1px solid var(--border);\n border-radius: var(--grid-borderradius-border-radius-xs);\n }\n\n &--title-label {\n color: var(--white);\n letter-spacing: 0.4px;\n font-size: var(--values-value-16);\n font-weight: 500;\n }\n }\n"])), function (props) {
190
190
  return props.titleposition === 'left' ? 'flex-start' : props.titleposition === 'right' ? 'flex-end' : 'center';
191
191
  });
192
192
  var ESewaAppBar = function ESewaAppBar(_ref2) {
@@ -7683,7 +7683,7 @@ var CONNECT_APP = function CONNECT_APP(data) {
7683
7683
  if (isiOS) {
7684
7684
  var _window$webkit;
7685
7685
  if ((_window$webkit = window.webkit) !== null && _window$webkit !== void 0 && _window$webkit.messageHandlers.iOSNative) {
7686
- window.webkit.messageHandlers.iOSNative.requestApp(data);
7686
+ window.webkit.messageHandlers.iOSNative.postMessage(data);
7687
7687
  } else {
7688
7688
  console.warn('iOS interface not available');
7689
7689
  }
@@ -7691,11 +7691,10 @@ var CONNECT_APP = function CONNECT_APP(data) {
7691
7691
  };
7692
7692
  var requestFromMiniApp = function requestFromMiniApp(data, callbackKey, callback) {
7693
7693
  var _window$webkit2, _window$webkit2$messa;
7694
- if (window.Android) {
7694
+ if (window.Android && callbackKey in window.Android) {
7695
7695
  window.Android[callbackKey] = callback;
7696
- } else if ((_window$webkit2 = window.webkit) !== null && _window$webkit2 !== void 0 && (_window$webkit2$messa = _window$webkit2.messageHandlers) !== null && _window$webkit2$messa !== void 0 && _window$webkit2$messa.iOSNative) {
7697
- window.miniAppResponse = window.miniAppResponse || {};
7698
- window.miniAppResponse[callbackKey] = callback;
7696
+ } else if ((_window$webkit2 = window.webkit) !== null && _window$webkit2 !== void 0 && (_window$webkit2$messa = _window$webkit2.messageHandlers) !== null && _window$webkit2$messa !== void 0 && _window$webkit2$messa.iOSNative && callbackKey in window.webkit.messageHandlers.iOSNative) {
7697
+ window.webkit.messageHandlers.iOSNative[callbackKey] = callback;
7699
7698
  }
7700
7699
  CONNECT_APP(JSON.stringify(data));
7701
7700
  };