@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.
@@ -1,7 +1,7 @@
1
1
  # Project information for documentation publishing
2
2
  projectName: "Payment Kit UI (React)"
3
- projectDesc: "@blocklet/payment-react is a React component library for building payment systems in blocklets, integrated with Payment Kit."
4
- projectLogo: https://store.blocklet.dev/assets/z2qaCNvKMv5GjouKdcDWexv6WqtHbpNPQDnAk/logo.png
3
+ projectDesc: "@blocklet/payment-react is a React library for blocklet payment systems with Payment Kit."
4
+ projectLogo: https://store.blocklet.dev/assets/z2qaCNvKMv5GjouKdcDWexv6WqtHbpNPQDnAk/logo.png?imageFilter=convert&f=png&w=64
5
5
 
6
6
  # =============================================================================
7
7
  # Documentation Configuration
@@ -3,10 +3,14 @@ import type { CountryIso2 } from 'react-international-phone';
3
3
  export type CountrySelectProps = {
4
4
  value: CountryIso2;
5
5
  onChange: (value: CountryIso2) => void;
6
- name: string;
6
+ name?: string;
7
7
  sx?: SxProps;
8
8
  showDialCode?: boolean;
9
+ label?: string;
10
+ allowClear?: boolean;
11
+ bordered?: boolean;
12
+ disabled?: boolean;
9
13
  };
10
- export default function CountrySelect({ ref, value, onChange, name, sx, showDialCode, }: CountrySelectProps & {
14
+ export default function CountrySelect({ ref, value, onChange, name, sx, showDialCode, label, bordered, allowClear, disabled, }: CountrySelectProps & {
11
15
  ref?: React.RefObject<HTMLDivElement | null>;
12
16
  }): import("react").JSX.Element;
@@ -1,9 +1,28 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useMemo, useState, useEffect, useRef } from "react";
3
- import { Box, MenuItem, Typography, TextField, Dialog, DialogContent, IconButton, Select, Slide } from "@mui/material";
3
+ import {
4
+ Box,
5
+ MenuItem,
6
+ Typography,
7
+ TextField,
8
+ Dialog,
9
+ DialogContent,
10
+ IconButton,
11
+ Select,
12
+ Slide,
13
+ Stack
14
+ } from "@mui/material";
15
+ import { Clear as ClearIcon } from "@mui/icons-material";
4
16
  import { useFormContext } from "react-hook-form";
5
17
  import { FlagEmoji, defaultCountries, parseCountry } from "react-international-phone";
6
18
  import { useMobile } from "../hooks/mobile.js";
19
+ function useFormContextSafe() {
20
+ try {
21
+ return useFormContext();
22
+ } catch {
23
+ return null;
24
+ }
25
+ }
7
26
  function Transition({ ref, ...props }) {
8
27
  return /* @__PURE__ */ jsx(Slide, { direction: "up", ref, timeout: 200, ...props });
9
28
  }
@@ -11,11 +30,15 @@ export default function CountrySelect({
11
30
  ref = void 0,
12
31
  value,
13
32
  onChange,
14
- name,
33
+ name = "",
15
34
  sx = {},
16
- showDialCode = false
35
+ showDialCode = false,
36
+ label = "",
37
+ bordered = false,
38
+ allowClear = false,
39
+ disabled = false
17
40
  }) {
18
- const { setValue } = useFormContext();
41
+ const formContext = useFormContextSafe();
19
42
  const [open, setOpen] = useState(false);
20
43
  const [searchText, setSearchText] = useState("");
21
44
  const inputRef = useRef(null);
@@ -117,9 +140,19 @@ export default function CountrySelect({
117
140
  }, [value]);
118
141
  const handleCountryClick = (code) => {
119
142
  onChange(code);
120
- setValue(name, code);
143
+ if (formContext && name) {
144
+ formContext.setValue(name, code);
145
+ }
121
146
  setOpen(false);
122
147
  };
148
+ const handleClear = (e) => {
149
+ e.preventDefault();
150
+ e.stopPropagation();
151
+ onChange("");
152
+ if (formContext && name) {
153
+ formContext.setValue(name, "");
154
+ }
155
+ };
123
156
  const handleSearchChange = (e) => {
124
157
  e.stopPropagation();
125
158
  setSearchText(e.target.value);
@@ -179,13 +212,14 @@ export default function CountrySelect({
179
212
  inputRef,
180
213
  autoFocus: !isMobile,
181
214
  fullWidth: true,
182
- placeholder: "Search country...",
215
+ placeholder: label || "Search country...",
183
216
  value: searchText,
184
217
  onChange: handleSearchChange,
185
218
  onKeyDown: handleKeyDown,
186
219
  onClick: (e) => e.stopPropagation(),
187
220
  size: "small",
188
- variant: "outlined"
221
+ variant: "outlined",
222
+ disabled
189
223
  }
190
224
  )
191
225
  }
@@ -282,7 +316,8 @@ export default function CountrySelect({
282
316
  pt: 0,
283
317
  display: "flex",
284
318
  flexDirection: "column",
285
- overflowY: "hidden"
319
+ overflowY: "hidden",
320
+ width: "100%"
286
321
  }
287
322
  }
288
323
  }
@@ -300,7 +335,7 @@ export default function CountrySelect({
300
335
  },
301
336
  ".MuiSelect-select": {
302
337
  padding: "8px",
303
- paddingRight: "24px !important"
338
+ paddingRight: allowClear && value ? "48px !important" : "24px !important"
304
339
  },
305
340
  svg: {
306
341
  right: 0
@@ -313,9 +348,12 @@ export default function CountrySelect({
313
348
  value,
314
349
  onChange: (e) => {
315
350
  onChange(e.target.value);
316
- setValue(name, e.target.value);
351
+ if (formContext && name) {
352
+ formContext.setValue(name, e.target.value);
353
+ }
317
354
  },
318
- renderValue: (code) => /* @__PURE__ */ jsxs(
355
+ disabled,
356
+ renderValue: (code) => /* @__PURE__ */ jsx(
319
357
  Box,
320
358
  {
321
359
  sx: {
@@ -323,12 +361,65 @@ export default function CountrySelect({
323
361
  alignItems: "center",
324
362
  flexWrap: "nowrap",
325
363
  gap: 0.5,
326
- cursor: "pointer"
364
+ cursor: "pointer",
365
+ width: "100%"
327
366
  },
328
- children: [
329
- /* @__PURE__ */ jsx(FlagEmoji, { iso2: code, style: { display: "flex" } }),
330
- /* @__PURE__ */ jsx(Typography, { children: countryDetail?.name })
331
- ]
367
+ children: code ? /* @__PURE__ */ jsxs(
368
+ Stack,
369
+ {
370
+ direction: "row",
371
+ sx: {
372
+ alignItems: "center",
373
+ gap: 0.5,
374
+ justifyContent: "space-between",
375
+ width: "100%"
376
+ },
377
+ children: [
378
+ /* @__PURE__ */ jsxs(
379
+ Stack,
380
+ {
381
+ direction: "row",
382
+ sx: {
383
+ alignItems: "center",
384
+ gap: 0.5
385
+ },
386
+ children: [
387
+ /* @__PURE__ */ jsx(FlagEmoji, { iso2: code, style: { display: "flex" } }),
388
+ /* @__PURE__ */ jsx(Typography, { sx: { flex: 1 }, children: countryDetail?.name })
389
+ ]
390
+ }
391
+ ),
392
+ allowClear && value && /* @__PURE__ */ jsx(
393
+ Box,
394
+ {
395
+ onClick: handleClear,
396
+ onMouseDown: (event) => {
397
+ event.stopPropagation();
398
+ event.preventDefault();
399
+ },
400
+ onTouchStart: (event) => {
401
+ event.stopPropagation();
402
+ },
403
+ sx: {
404
+ display: "flex",
405
+ alignItems: "center",
406
+ cursor: "pointer",
407
+ p: 0,
408
+ borderRadius: "50%",
409
+ border: "none",
410
+ background: "transparent",
411
+ zIndex: 2,
412
+ marginRight: "-28px",
413
+ "&:hover": {
414
+ backgroundColor: "action.hover"
415
+ }
416
+ },
417
+ children: /* @__PURE__ */ jsx(ClearIcon, { fontSize: "small" })
418
+ }
419
+ )
420
+ ]
421
+ }
422
+ ) : /* @__PURE__ */ jsx(Typography, { sx: { color: "text.secondary", flex: 1 }, children: label || "Select country..." })
332
423
  }
333
424
  ),
334
425
  children: countryListContent
@@ -339,7 +430,10 @@ export default function CountrySelect({
339
430
  /* @__PURE__ */ jsxs(
340
431
  Box,
341
432
  {
342
- onClick: () => setOpen(true),
433
+ onClick: () => {
434
+ if (disabled) return;
435
+ setOpen(true);
436
+ },
343
437
  sx: {
344
438
  display: "flex",
345
439
  alignItems: "center",
@@ -349,7 +443,9 @@ export default function CountrySelect({
349
443
  padding: "8px",
350
444
  paddingRight: "24px",
351
445
  position: "relative",
352
- border: "none",
446
+ ...!bordered ? {
447
+ border: "none"
448
+ } : {},
353
449
  "-webkit-tap-highlight-color": "transparent",
354
450
  userSelect: "none",
355
451
  background: "none",
@@ -357,11 +453,51 @@ export default function CountrySelect({
357
453
  backgroundColor: "transparent",
358
454
  outline: "none"
359
455
  },
456
+ ...disabled ? {
457
+ backgroundColor: "grey.100",
458
+ cursor: "not-allowed",
459
+ color: "text.disabled",
460
+ "&:hover, &:focus, &:active": {
461
+ backgroundColor: "grey.100",
462
+ color: "text.disabled"
463
+ }
464
+ } : {},
360
465
  touchAction: "manipulation"
361
466
  },
362
467
  children: [
363
- /* @__PURE__ */ jsx(FlagEmoji, { iso2: value, style: { display: "flex" } }),
364
- /* @__PURE__ */ jsx(Typography, { children: countryDetail?.name }),
468
+ value ? /* @__PURE__ */ jsxs(Fragment, { children: [
469
+ /* @__PURE__ */ jsx(FlagEmoji, { iso2: value, style: { display: "flex" } }),
470
+ /* @__PURE__ */ jsx(Typography, { sx: { flex: 1 }, children: countryDetail?.name }),
471
+ allowClear && /* @__PURE__ */ jsx(
472
+ Box,
473
+ {
474
+ component: "button",
475
+ type: "button",
476
+ onClick: handleClear,
477
+ onMouseDown: (event) => {
478
+ event.stopPropagation();
479
+ event.preventDefault();
480
+ },
481
+ onTouchStart: (event) => {
482
+ event.stopPropagation();
483
+ },
484
+ sx: {
485
+ display: "flex",
486
+ alignItems: "center",
487
+ cursor: "pointer",
488
+ p: 0.5,
489
+ mr: 1,
490
+ borderRadius: "50%",
491
+ border: "none",
492
+ background: "transparent",
493
+ "&:hover": {
494
+ backgroundColor: "action.hover"
495
+ }
496
+ },
497
+ children: /* @__PURE__ */ jsx(ClearIcon, { fontSize: "small" })
498
+ }
499
+ )
500
+ ] }) : /* @__PURE__ */ jsx(Typography, { sx: { color: "text.secondary", flex: 1 }, children: label || "Select country..." }),
365
501
  /* @__PURE__ */ jsx(
366
502
  Box,
367
503
  {
@@ -386,18 +522,22 @@ export default function CountrySelect({
386
522
  onClose: () => setOpen(false),
387
523
  fullWidth: true,
388
524
  maxWidth: "xs",
389
- TransitionComponent: Transition,
390
- PaperProps: {
391
- sx: {
392
- position: "absolute",
393
- bottom: 0,
394
- m: 0,
395
- p: 0,
396
- borderBottomLeftRadius: 0,
397
- borderBottomRightRadius: 0,
398
- width: "100%"
525
+ slotProps: {
526
+ paper: {
527
+ sx: {
528
+ position: "absolute",
529
+ bottom: 0,
530
+ m: 0,
531
+ p: 0,
532
+ borderBottomLeftRadius: 0,
533
+ borderBottomRightRadius: 0,
534
+ width: "100%"
535
+ }
399
536
  }
400
537
  },
538
+ slots: {
539
+ transition: Transition
540
+ },
401
541
  children: [
402
542
  /* @__PURE__ */ jsxs(Box, { sx: { p: 2, display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [
403
543
  /* @__PURE__ */ jsx(Typography, { variant: "h6", children: "Select Country" }),
@@ -121,19 +121,30 @@ function SourceDataViewer({
121
121
  const normalizedData = normalizeData(data);
122
122
  const displayItems = maxItems ? normalizedData.slice(0, maxItems) : normalizedData;
123
123
  if (compact) {
124
- return /* @__PURE__ */ jsxs(Stack, { direction: "row", spacing: 1, flexWrap: "wrap", useFlexGap: true, children: [
125
- displayItems.map((field) => /* @__PURE__ */ jsx(
126
- Chip,
127
- {
128
- label: `${getLocalizedText(field.label)}: ${field.value}`,
129
- size: "small",
130
- variant: "outlined",
131
- sx: { maxWidth: 200 }
124
+ return /* @__PURE__ */ jsxs(
125
+ Stack,
126
+ {
127
+ direction: "row",
128
+ spacing: 1,
129
+ useFlexGap: true,
130
+ sx: {
131
+ flexWrap: "wrap"
132
132
  },
133
- field.key
134
- )),
135
- maxItems && normalizedData.length > maxItems && /* @__PURE__ */ jsx(Chip, { label: `+${normalizedData.length - maxItems} more`, size: "small", color: "primary", variant: "outlined" })
136
- ] });
133
+ children: [
134
+ displayItems.map((field) => /* @__PURE__ */ jsx(
135
+ Chip,
136
+ {
137
+ label: `${getLocalizedText(field.label)}: ${field.value}`,
138
+ size: "small",
139
+ variant: "outlined",
140
+ sx: { maxWidth: 200 }
141
+ },
142
+ field.key
143
+ )),
144
+ maxItems && normalizedData.length > maxItems && /* @__PURE__ */ jsx(Chip, { label: `+${normalizedData.length - maxItems} more`, size: "small", color: "primary", variant: "outlined" })
145
+ ]
146
+ }
147
+ );
137
148
  }
138
149
  if (showGroups) {
139
150
  const groupedData = displayItems.reduce(
@@ -177,8 +188,8 @@ function SourceDataViewer({
177
188
  Typography,
178
189
  {
179
190
  variant: "body2",
180
- color: "text.secondary",
181
191
  sx: {
192
+ color: "text.secondary",
182
193
  fontSize: "0.8rem",
183
194
  minWidth: 100,
184
195
  fontWeight: 600,
@@ -209,8 +220,8 @@ function SourceDataViewer({
209
220
  Typography,
210
221
  {
211
222
  variant: "body2",
212
- color: "text.secondary",
213
223
  sx: {
224
+ color: "text.secondary",
214
225
  fontSize: "0.8rem",
215
226
  minWidth: 100,
216
227
  fontWeight: 600,
@@ -202,7 +202,17 @@ const TransactionsTable = React.memo((props) => {
202
202
  options: {
203
203
  customBodyRenderLite: (_, index) => {
204
204
  const item = data?.list[index];
205
- return /* @__PURE__ */ jsx(Typography, { variant: "body2", color: "text.secondary", sx: { fontSize: "0.875rem" }, children: formatToDate(item.created_at, locale, "YYYY-MM-DD HH:mm") });
205
+ return /* @__PURE__ */ jsx(
206
+ Typography,
207
+ {
208
+ variant: "body2",
209
+ sx: {
210
+ color: "text.secondary",
211
+ fontSize: "0.875rem"
212
+ },
213
+ children: formatToDate(item.created_at, locale, "YYYY-MM-DD HH:mm")
214
+ }
215
+ );
206
216
  }
207
217
  }
208
218
  },
package/es/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>;