@blocklet/payment-react 1.21.13 → 1.21.14

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.
@@ -7,9 +7,17 @@ module.exports = CountrySelect;
7
7
  var _jsxRuntime = require("react/jsx-runtime");
8
8
  var _react = require("react");
9
9
  var _material = require("@mui/material");
10
+ var _iconsMaterial = require("@mui/icons-material");
10
11
  var _reactHookForm = require("react-hook-form");
11
12
  var _reactInternationalPhone = require("react-international-phone");
12
13
  var _mobile = require("../hooks/mobile");
14
+ function useFormContextSafe() {
15
+ try {
16
+ return (0, _reactHookForm.useFormContext)();
17
+ } catch {
18
+ return null;
19
+ }
20
+ }
13
21
  function Transition({
14
22
  ref,
15
23
  ...props
@@ -25,13 +33,15 @@ function CountrySelect({
25
33
  ref = void 0,
26
34
  value,
27
35
  onChange,
28
- name,
36
+ name = "",
29
37
  sx = {},
30
- showDialCode = false
38
+ showDialCode = false,
39
+ label = "",
40
+ bordered = false,
41
+ allowClear = false,
42
+ disabled = false
31
43
  }) {
32
- const {
33
- setValue
34
- } = (0, _reactHookForm.useFormContext)();
44
+ const formContext = useFormContextSafe();
35
45
  const [open, setOpen] = (0, _react.useState)(false);
36
46
  const [searchText, setSearchText] = (0, _react.useState)("");
37
47
  const inputRef = (0, _react.useRef)(null);
@@ -136,9 +146,19 @@ function CountrySelect({
136
146
  }, [value]);
137
147
  const handleCountryClick = code => {
138
148
  onChange(code);
139
- setValue(name, code);
149
+ if (formContext && name) {
150
+ formContext.setValue(name, code);
151
+ }
140
152
  setOpen(false);
141
153
  };
154
+ const handleClear = e => {
155
+ e.preventDefault();
156
+ e.stopPropagation();
157
+ onChange("");
158
+ if (formContext && name) {
159
+ formContext.setValue(name, "");
160
+ }
161
+ };
142
162
  const handleSearchChange = e => {
143
163
  e.stopPropagation();
144
164
  setSearchText(e.target.value);
@@ -194,13 +214,14 @@ function CountrySelect({
194
214
  inputRef,
195
215
  autoFocus: !isMobile,
196
216
  fullWidth: true,
197
- placeholder: "Search country...",
217
+ placeholder: label || "Search country...",
198
218
  value: searchText,
199
219
  onChange: handleSearchChange,
200
220
  onKeyDown: handleKeyDown,
201
221
  onClick: e => e.stopPropagation(),
202
222
  size: "small",
203
- variant: "outlined"
223
+ variant: "outlined",
224
+ disabled
204
225
  })
205
226
  }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
206
227
  ref: listRef,
@@ -285,7 +306,8 @@ function CountrySelect({
285
306
  pt: 0,
286
307
  display: "flex",
287
308
  flexDirection: "column",
288
- overflowY: "hidden"
309
+ overflowY: "hidden",
310
+ width: "100%"
289
311
  }
290
312
  }
291
313
  }
@@ -303,7 +325,7 @@ function CountrySelect({
303
325
  },
304
326
  ".MuiSelect-select": {
305
327
  padding: "8px",
306
- paddingRight: "24px !important"
328
+ paddingRight: allowClear && value ? "48px !important" : "24px !important"
307
329
  },
308
330
  svg: {
309
331
  right: 0
@@ -316,24 +338,79 @@ function CountrySelect({
316
338
  value,
317
339
  onChange: e => {
318
340
  onChange(e.target.value);
319
- setValue(name, e.target.value);
341
+ if (formContext && name) {
342
+ formContext.setValue(name, e.target.value);
343
+ }
320
344
  },
321
- renderValue: code => /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
345
+ disabled,
346
+ renderValue: code => /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
322
347
  sx: {
323
348
  display: "flex",
324
349
  alignItems: "center",
325
350
  flexWrap: "nowrap",
326
351
  gap: 0.5,
327
- cursor: "pointer"
352
+ cursor: "pointer",
353
+ width: "100%"
328
354
  },
329
- children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_reactInternationalPhone.FlagEmoji, {
330
- iso2: code,
331
- style: {
332
- display: "flex"
333
- }
334
- }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
335
- children: countryDetail?.name
336
- })]
355
+ children: code ? /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
356
+ direction: "row",
357
+ sx: {
358
+ alignItems: "center",
359
+ gap: 0.5,
360
+ justifyContent: "space-between",
361
+ width: "100%"
362
+ },
363
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
364
+ direction: "row",
365
+ sx: {
366
+ alignItems: "center",
367
+ gap: 0.5
368
+ },
369
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_reactInternationalPhone.FlagEmoji, {
370
+ iso2: code,
371
+ style: {
372
+ display: "flex"
373
+ }
374
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
375
+ sx: {
376
+ flex: 1
377
+ },
378
+ children: countryDetail?.name
379
+ })]
380
+ }), allowClear && value && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
381
+ onClick: handleClear,
382
+ onMouseDown: event => {
383
+ event.stopPropagation();
384
+ event.preventDefault();
385
+ },
386
+ onTouchStart: event => {
387
+ event.stopPropagation();
388
+ },
389
+ sx: {
390
+ display: "flex",
391
+ alignItems: "center",
392
+ cursor: "pointer",
393
+ p: 0,
394
+ borderRadius: "50%",
395
+ border: "none",
396
+ background: "transparent",
397
+ zIndex: 2,
398
+ marginRight: "-28px",
399
+ "&:hover": {
400
+ backgroundColor: "action.hover"
401
+ }
402
+ },
403
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_iconsMaterial.Clear, {
404
+ fontSize: "small"
405
+ })
406
+ })]
407
+ }) : /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
408
+ sx: {
409
+ color: "text.secondary",
410
+ flex: 1
411
+ },
412
+ children: label || "Select country..."
413
+ })
337
414
  }),
338
415
  children: countryListContent
339
416
  });
@@ -344,7 +421,10 @@ function CountrySelect({
344
421
  ...sx
345
422
  },
346
423
  children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
347
- onClick: () => setOpen(true),
424
+ onClick: () => {
425
+ if (disabled) return;
426
+ setOpen(true);
427
+ },
348
428
  sx: {
349
429
  display: "flex",
350
430
  alignItems: "center",
@@ -354,7 +434,9 @@ function CountrySelect({
354
434
  padding: "8px",
355
435
  paddingRight: "24px",
356
436
  position: "relative",
357
- border: "none",
437
+ ...(!bordered ? {
438
+ border: "none"
439
+ } : {}),
358
440
  "-webkit-tap-highlight-color": "transparent",
359
441
  userSelect: "none",
360
442
  background: "none",
@@ -362,15 +444,62 @@ function CountrySelect({
362
444
  backgroundColor: "transparent",
363
445
  outline: "none"
364
446
  },
447
+ ...(disabled ? {
448
+ backgroundColor: "grey.100",
449
+ cursor: "not-allowed",
450
+ color: "text.disabled",
451
+ "&:hover, &:focus, &:active": {
452
+ backgroundColor: "grey.100",
453
+ color: "text.disabled"
454
+ }
455
+ } : {}),
365
456
  touchAction: "manipulation"
366
457
  },
367
- children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_reactInternationalPhone.FlagEmoji, {
368
- iso2: value,
369
- style: {
370
- display: "flex"
371
- }
372
- }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
373
- children: countryDetail?.name
458
+ children: [value ? /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
459
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_reactInternationalPhone.FlagEmoji, {
460
+ iso2: value,
461
+ style: {
462
+ display: "flex"
463
+ }
464
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
465
+ sx: {
466
+ flex: 1
467
+ },
468
+ children: countryDetail?.name
469
+ }), allowClear && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
470
+ component: "button",
471
+ type: "button",
472
+ onClick: handleClear,
473
+ onMouseDown: event => {
474
+ event.stopPropagation();
475
+ event.preventDefault();
476
+ },
477
+ onTouchStart: event => {
478
+ event.stopPropagation();
479
+ },
480
+ sx: {
481
+ display: "flex",
482
+ alignItems: "center",
483
+ cursor: "pointer",
484
+ p: 0.5,
485
+ mr: 1,
486
+ borderRadius: "50%",
487
+ border: "none",
488
+ background: "transparent",
489
+ "&:hover": {
490
+ backgroundColor: "action.hover"
491
+ }
492
+ },
493
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_iconsMaterial.Clear, {
494
+ fontSize: "small"
495
+ })
496
+ })]
497
+ }) : /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
498
+ sx: {
499
+ color: "text.secondary",
500
+ flex: 1
501
+ },
502
+ children: label || "Select country..."
374
503
  }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
375
504
  sx: {
376
505
  position: "absolute",
@@ -387,18 +516,22 @@ function CountrySelect({
387
516
  onClose: () => setOpen(false),
388
517
  fullWidth: true,
389
518
  maxWidth: "xs",
390
- TransitionComponent: Transition,
391
- PaperProps: {
392
- sx: {
393
- position: "absolute",
394
- bottom: 0,
395
- m: 0,
396
- p: 0,
397
- borderBottomLeftRadius: 0,
398
- borderBottomRightRadius: 0,
399
- width: "100%"
519
+ slotProps: {
520
+ paper: {
521
+ sx: {
522
+ position: "absolute",
523
+ bottom: 0,
524
+ m: 0,
525
+ p: 0,
526
+ borderBottomLeftRadius: 0,
527
+ borderBottomRightRadius: 0,
528
+ width: "100%"
529
+ }
400
530
  }
401
531
  },
532
+ slots: {
533
+ transition: Transition
534
+ },
402
535
  children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
403
536
  sx: {
404
537
  p: 2,
@@ -127,8 +127,10 @@ function SourceDataViewer({
127
127
  return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
128
128
  direction: "row",
129
129
  spacing: 1,
130
- flexWrap: "wrap",
131
130
  useFlexGap: true,
131
+ sx: {
132
+ flexWrap: "wrap"
133
+ },
132
134
  children: [displayItems.map(field => /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Chip, {
133
135
  label: `${getLocalizedText(field.label)}: ${field.value}`,
134
136
  size: "small",
@@ -181,8 +183,8 @@ function SourceDataViewer({
181
183
  },
182
184
  children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
183
185
  variant: "body2",
184
- color: "text.secondary",
185
186
  sx: {
187
+ color: "text.secondary",
186
188
  fontSize: "0.8rem",
187
189
  minWidth: 100,
188
190
  fontWeight: 600,
@@ -215,8 +217,8 @@ function SourceDataViewer({
215
217
  },
216
218
  children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
217
219
  variant: "body2",
218
- color: "text.secondary",
219
220
  sx: {
221
+ color: "text.secondary",
220
222
  fontSize: "0.8rem",
221
223
  minWidth: 100,
222
224
  fontWeight: 600,
@@ -227,8 +227,8 @@ const TransactionsTable = _react.default.memo(props => {
227
227
  const item = data?.list[index];
228
228
  return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
229
229
  variant: "body2",
230
- color: "text.secondary",
231
230
  sx: {
231
+ color: "text.secondary",
232
232
  fontSize: "0.875rem"
233
233
  },
234
234
  children: (0, _util.formatToDate)(item.created_at, locale, "YYYY-MM-DD HH:mm")
package/lib/index.d.ts CHANGED
@@ -56,3 +56,4 @@ export * from './hooks/keyboard';
56
56
  export * from './libs/validator';
57
57
  export { translations, createTranslator } from './locales';
58
58
  export { createLazyComponent, api, dayjs, FormInput, FormLabel, PhoneInput, AddressForm, StripeForm, Status, Livemode, Switch, ConfirmDialog, CheckoutForm, CheckoutTable, CheckoutDonate, CurrencySelector, Payment, PaymentSummary, PricingTable, ProductSkeleton, Amount, CustomerInvoiceList, CustomerPaymentList, TxLink, TxGas, SafeGuard, PricingItem, CountrySelect, Table, TruncatedText, Link, OverdueInvoicePayment, PaymentBeneficiaries, LoadingButton, DonateDetails, ResumeSubscription, CreditGrantsList, CreditTransactionsList, DateRangePicker, CreditStatusChip, AutoTopupModal, AutoTopup, Collapse, PromotionCode, SourceDataViewer, };
59
+ export type { CountrySelectProps } from './components/country-select';
@@ -1,2 +1,163 @@
1
+ export declare const postalCodePatterns: {
2
+ GB: RegExp;
3
+ JE: RegExp;
4
+ GG: RegExp;
5
+ IM: RegExp;
6
+ US: RegExp;
7
+ CA: RegExp;
8
+ DE: RegExp;
9
+ JP: RegExp;
10
+ FR: RegExp;
11
+ AU: RegExp;
12
+ IT: RegExp;
13
+ CH: RegExp;
14
+ AT: RegExp;
15
+ ES: RegExp;
16
+ NL: RegExp;
17
+ BE: RegExp;
18
+ DK: RegExp;
19
+ SE: RegExp;
20
+ NO: RegExp;
21
+ BR: RegExp;
22
+ PT: RegExp;
23
+ FI: RegExp;
24
+ AX: RegExp;
25
+ KR: RegExp;
26
+ CN: RegExp;
27
+ TW: RegExp;
28
+ SG: RegExp;
29
+ DZ: RegExp;
30
+ AD: RegExp;
31
+ AR: RegExp;
32
+ AM: RegExp;
33
+ AZ: RegExp;
34
+ BH: RegExp;
35
+ BD: RegExp;
36
+ BB: RegExp;
37
+ BY: RegExp;
38
+ BM: RegExp;
39
+ BA: RegExp;
40
+ IO: RegExp;
41
+ BN: RegExp;
42
+ BG: RegExp;
43
+ KH: RegExp;
44
+ CV: RegExp;
45
+ CL: RegExp;
46
+ CR: RegExp;
47
+ HR: RegExp;
48
+ CY: RegExp;
49
+ CZ: RegExp;
50
+ DO: RegExp;
51
+ EC: RegExp;
52
+ EG: RegExp;
53
+ EE: RegExp;
54
+ FO: RegExp;
55
+ GE: RegExp;
56
+ GR: RegExp;
57
+ GL: RegExp;
58
+ GT: RegExp;
59
+ HT: RegExp;
60
+ HN: RegExp;
61
+ HU: RegExp;
62
+ IS: RegExp;
63
+ IN: RegExp;
64
+ ID: RegExp;
65
+ IL: RegExp;
66
+ JO: RegExp;
67
+ KZ: RegExp;
68
+ KE: RegExp;
69
+ KW: RegExp;
70
+ LA: RegExp;
71
+ LV: RegExp;
72
+ LB: RegExp;
73
+ LI: RegExp;
74
+ LT: RegExp;
75
+ LU: RegExp;
76
+ MK: RegExp;
77
+ MY: RegExp;
78
+ MV: RegExp;
79
+ MT: RegExp;
80
+ MU: RegExp;
81
+ MX: RegExp;
82
+ MD: RegExp;
83
+ MC: RegExp;
84
+ MA: RegExp;
85
+ NP: RegExp;
86
+ NZ: RegExp;
87
+ NI: RegExp;
88
+ NG: RegExp;
89
+ OM: RegExp;
90
+ PK: RegExp;
91
+ PY: RegExp;
92
+ PH: RegExp;
93
+ PL: RegExp;
94
+ PR: RegExp;
95
+ RO: RegExp;
96
+ RU: RegExp;
97
+ SM: RegExp;
98
+ SA: RegExp;
99
+ SN: RegExp;
100
+ SK: RegExp;
101
+ SI: RegExp;
102
+ ZA: RegExp;
103
+ LK: RegExp;
104
+ TJ: RegExp;
105
+ TH: RegExp;
106
+ TN: RegExp;
107
+ TR: RegExp;
108
+ TM: RegExp;
109
+ UA: RegExp;
110
+ UY: RegExp;
111
+ UZ: RegExp;
112
+ VA: RegExp;
113
+ VE: RegExp;
114
+ ZM: RegExp;
115
+ AS: RegExp;
116
+ CC: RegExp;
117
+ CK: RegExp;
118
+ RS: RegExp;
119
+ ME: RegExp;
120
+ CS: RegExp;
121
+ YU: RegExp;
122
+ CX: RegExp;
123
+ ET: RegExp;
124
+ FK: RegExp;
125
+ NF: RegExp;
126
+ FM: RegExp;
127
+ GF: RegExp;
128
+ GN: RegExp;
129
+ GP: RegExp;
130
+ GS: RegExp;
131
+ GU: RegExp;
132
+ GW: RegExp;
133
+ HM: RegExp;
134
+ IQ: RegExp;
135
+ KG: RegExp;
136
+ LR: RegExp;
137
+ LS: RegExp;
138
+ MG: RegExp;
139
+ MH: RegExp;
140
+ MN: RegExp;
141
+ MP: RegExp;
142
+ MQ: RegExp;
143
+ NC: RegExp;
144
+ NE: RegExp;
145
+ VI: RegExp;
146
+ VN: RegExp;
147
+ PF: RegExp;
148
+ PG: RegExp;
149
+ PM: RegExp;
150
+ PN: RegExp;
151
+ PW: RegExp;
152
+ RE: RegExp;
153
+ SH: RegExp;
154
+ SJ: RegExp;
155
+ SO: RegExp;
156
+ SZ: RegExp;
157
+ TC: RegExp;
158
+ WF: RegExp;
159
+ XK: RegExp;
160
+ YT: RegExp;
161
+ };
1
162
  export declare function validatePostalCode(postalCode: string, country?: string): boolean;
2
163
  export declare function getFieldValidation(fieldName: string, validations?: Record<string, any>, locale?: string): Record<string, any>;