@hanwenbo/x-taro-ui 0.0.1 → 0.0.3

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.
Files changed (57) hide show
  1. package/es/adapters/miniapp/overlayHost.js +14 -8
  2. package/es/auth/components.d.ts +17 -15
  3. package/es/auth/components.js +253 -133
  4. package/es/auth/entries/locales.d.ts +2 -0
  5. package/es/auth/entries/locales.js +1 -0
  6. package/es/auth/index.d.ts +1 -0
  7. package/es/auth/index.js +2 -1
  8. package/es/auth/internal.d.ts +17 -11
  9. package/es/auth/internal.js +107 -42
  10. package/es/auth/phoneNumberInput.d.ts +4 -2
  11. package/es/auth/phoneNumberInput.js +27 -8
  12. package/es/auth/provider.d.ts +2 -2
  13. package/es/auth/styles.css +161 -99
  14. package/es/auth/theme.js +20 -4
  15. package/es/components/_shared/render.d.ts +1 -1
  16. package/es/components/button/button.js +23 -3
  17. package/es/components/button/types.d.ts +6 -0
  18. package/es/components/capsuleTabs/capsuleTabs.js +4 -0
  19. package/es/components/icon/lucide.generated.d.ts +10 -0
  20. package/es/components/icon/lucide.generated.js +10 -0
  21. package/es/components/inputItem/inputItem.js +5 -2
  22. package/es/components/list/list.d.ts +1 -1
  23. package/es/components/pagination/pagination.js +18 -5
  24. package/es/components/searchBar/searchBar.js +4 -0
  25. package/es/components/sectionList/sectionList.d.ts +1 -2
  26. package/es/components/segmented/segmented.js +10 -2
  27. package/es/components/touchableOpacity/touchableOpacity.js +1 -0
  28. package/es/taro-components.d.ts +6 -0
  29. package/lib/adapters/miniapp/overlayHost.js +13 -6
  30. package/lib/auth/components.d.ts +17 -15
  31. package/lib/auth/components.js +257 -125
  32. package/lib/auth/entries/locales.d.ts +2 -0
  33. package/lib/auth/entries/locales.js +33 -0
  34. package/lib/auth/index.d.ts +1 -0
  35. package/lib/auth/index.js +13 -0
  36. package/lib/auth/internal.d.ts +17 -11
  37. package/lib/auth/internal.js +76 -31
  38. package/lib/auth/phoneNumberInput.d.ts +4 -2
  39. package/lib/auth/phoneNumberInput.js +65 -45
  40. package/lib/auth/provider.d.ts +2 -2
  41. package/lib/auth/styles.css +161 -99
  42. package/lib/auth/theme.js +7 -4
  43. package/lib/components/_shared/render.d.ts +1 -1
  44. package/lib/components/button/button.js +7 -0
  45. package/lib/components/button/types.d.ts +6 -0
  46. package/lib/components/capsuleTabs/capsuleTabs.js +1 -0
  47. package/lib/components/icon/lucide.generated.d.ts +10 -0
  48. package/lib/components/icon/lucide.generated.js +24 -0
  49. package/lib/components/inputItem/inputItem.js +3 -0
  50. package/lib/components/list/list.d.ts +1 -1
  51. package/lib/components/pagination/pagination.js +19 -5
  52. package/lib/components/searchBar/searchBar.js +4 -0
  53. package/lib/components/sectionList/sectionList.d.ts +1 -2
  54. package/lib/components/segmented/segmented.js +6 -1
  55. package/lib/components/touchableOpacity/touchableOpacity.js +1 -0
  56. package/lib/taro-components.d.ts +6 -0
  57. package/package.json +4 -4
@@ -0,0 +1,2 @@
1
+ export { authLocales, authZhCN, authEnUS, type AuthMessageKey } from '@hanwenbo/x-auth-core/locales';
2
+ //# sourceMappingURL=locales.d.ts.map
@@ -0,0 +1,33 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/auth/entries/locales.ts
20
+ var locales_exports = {};
21
+ __export(locales_exports, {
22
+ authEnUS: () => import_locales.authEnUS,
23
+ authLocales: () => import_locales.authLocales,
24
+ authZhCN: () => import_locales.authZhCN
25
+ });
26
+ module.exports = __toCommonJS(locales_exports);
27
+ var import_locales = require("@hanwenbo/x-auth-core/locales");
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ authEnUS,
31
+ authLocales,
32
+ authZhCN
33
+ });
@@ -4,4 +4,5 @@ export * from './phoneNumberInput';
4
4
  export * from './provider';
5
5
  export * from './theme';
6
6
  export * from './types';
7
+ export { authLocales, authZhCN, authEnUS, type AuthMessageKey } from '@hanwenbo/x-auth-core/locales';
7
8
  //# sourceMappingURL=index.d.ts.map
package/lib/auth/index.js CHANGED
@@ -2,6 +2,10 @@ var __defProp = Object.defineProperty;
2
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
5
9
  var __copyProps = (to, from, except, desc) => {
6
10
  if (from && typeof from === "object" || typeof from === "function") {
7
11
  for (let key of __getOwnPropNames(from))
@@ -15,6 +19,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
15
19
 
16
20
  // src/auth/index.ts
17
21
  var index_exports = {};
22
+ __export(index_exports, {
23
+ authEnUS: () => import_locales.authEnUS,
24
+ authLocales: () => import_locales.authLocales,
25
+ authZhCN: () => import_locales.authZhCN
26
+ });
18
27
  module.exports = __toCommonJS(index_exports);
19
28
  var import_styles = require("./styles.css");
20
29
  __reExport(index_exports, require("./components"), module.exports);
@@ -22,8 +31,12 @@ __reExport(index_exports, require("./phoneNumberInput"), module.exports);
22
31
  __reExport(index_exports, require("./provider"), module.exports);
23
32
  __reExport(index_exports, require("./theme"), module.exports);
24
33
  __reExport(index_exports, require("./types"), module.exports);
34
+ var import_locales = require("@hanwenbo/x-auth-core/locales");
25
35
  // Annotate the CommonJS export names for ESM import in node:
26
36
  0 && (module.exports = {
37
+ authEnUS,
38
+ authLocales,
39
+ authZhCN,
27
40
  ...require("./components"),
28
41
  ...require("./phoneNumberInput"),
29
42
  ...require("./provider"),
@@ -1,34 +1,38 @@
1
- import React, { type CSSProperties, type ReactNode } from 'react';
1
+ import { type CSSProperties, type ReactNode } from 'react';
2
2
  import type { ContactIdentifierType, IdentifierType, ResolvedAuthConfig } from '@hanwenbo/x-auth-core/types';
3
3
  export declare type AuthSurface = 'card' | 'plain';
4
- export declare function AuthPanel({ children, className, description, footer, logo, style, surface, testID, title }: {
4
+ export declare type AuthHeaderAlign = 'left' | 'center';
5
+ export declare function AuthPanel({ children, className, description, footer, headerAlign, logo, style, surface, testID, title }: {
5
6
  children: ReactNode;
6
7
  className?: string;
7
8
  description?: ReactNode;
8
9
  footer?: ReactNode;
10
+ headerAlign?: AuthHeaderAlign;
9
11
  logo?: ReactNode;
10
12
  style?: CSSProperties;
11
13
  surface?: AuthSurface;
12
14
  testID?: string;
13
15
  title?: ReactNode;
14
- }): React.JSX.Element;
16
+ }): import("react/jsx-runtime").JSX.Element;
15
17
  export declare function AuthField({ children, error, hint, label }: {
16
18
  children: ReactNode;
17
19
  error?: string;
18
20
  hint?: ReactNode;
19
21
  label?: ReactNode;
20
- }): React.JSX.Element;
22
+ }): import("react/jsx-runtime").JSX.Element;
21
23
  export declare function AuthError({ children }: {
22
24
  children?: ReactNode;
23
- }): React.JSX.Element | null;
24
- export declare function AuthSelector<Value extends string>({ onChange, options, value }: {
25
+ }): import("react/jsx-runtime").JSX.Element | null;
26
+ interface AuthSelectorProps<Value extends string> {
25
27
  onChange: (value: Value) => void;
26
28
  options: Array<{
27
29
  label: ReactNode;
28
30
  value: Value;
29
31
  }>;
30
32
  value?: Value;
31
- }): React.JSX.Element | null;
33
+ }
34
+ export declare function AuthSelector<Value extends string>({ onChange, options, value }: AuthSelectorProps<Value>): import("react/jsx-runtime").JSX.Element | null;
35
+ export declare function CredentialSelector<Value extends string>({ onChange, options, value }: AuthSelectorProps<Value>): import("react/jsx-runtime").JSX.Element | null;
32
36
  export declare function IdentifierInput({ config, error, onChange, showLabel, type, value }: {
33
37
  config: ResolvedAuthConfig;
34
38
  error?: string;
@@ -36,8 +40,9 @@ export declare function IdentifierInput({ config, error, onChange, showLabel, ty
36
40
  showLabel?: boolean;
37
41
  type: IdentifierType;
38
42
  value: string;
39
- }): React.JSX.Element;
40
- export declare function VerificationCodeInput({ codeLength, countdown, disabled, error, onChange, onSend, sending, showLabel, value }: {
43
+ }): import("react/jsx-runtime").JSX.Element;
44
+ export declare function VerificationCodeInput({ config, codeLength, countdown, disabled, error, onChange, onSend, sending, showLabel, value }: {
45
+ config?: ResolvedAuthConfig;
41
46
  codeLength: number;
42
47
  countdown: number;
43
48
  disabled?: boolean;
@@ -47,9 +52,10 @@ export declare function VerificationCodeInput({ codeLength, countdown, disabled,
47
52
  sending?: boolean;
48
53
  showLabel?: boolean;
49
54
  value: string;
50
- }): React.JSX.Element;
51
- export declare function contactOptions(types: ContactIdentifierType[]): {
55
+ }): import("react/jsx-runtime").JSX.Element;
56
+ export declare function contactOptions(types: ContactIdentifierType[], config?: ResolvedAuthConfig): {
52
57
  label: any;
53
58
  value: ContactIdentifierType;
54
59
  }[];
60
+ export {};
55
61
  //# sourceMappingURL=internal.d.ts.map
@@ -33,42 +33,47 @@ __export(internal_exports, {
33
33
  AuthField: () => AuthField,
34
34
  AuthPanel: () => AuthPanel,
35
35
  AuthSelector: () => AuthSelector,
36
+ CredentialSelector: () => CredentialSelector,
36
37
  IdentifierInput: () => IdentifierInput,
37
38
  VerificationCodeInput: () => VerificationCodeInput,
38
39
  contactOptions: () => contactOptions
39
40
  });
40
41
  module.exports = __toCommonJS(internal_exports);
41
- var import_react = __toESM(require("react"));
42
+ var import_react = require("@hanwenbo/x-auth-core/react");
43
+ var import_react2 = __toESM(require("react"));
42
44
  var import_components = require("@tarojs/components");
43
45
  var import_identifier = require("@hanwenbo/x-auth-core/identifier");
44
46
  var import_button = require("../components/button");
45
47
  var import_icon = require("../components/icon");
48
+ var import_segmented = require("../components/segmented");
49
+ var import_tabs = require("../components/tabs");
46
50
  var import_inputItem = require("../components/inputItem/index");
47
51
  var import_phoneNumberInput = require("./phoneNumberInput");
48
52
  function renderText(node, className) {
49
- return typeof node === "string" || typeof node === "number" ? /* @__PURE__ */ import_react.default.createElement(import_components.Text, { className }, node) : node;
53
+ return typeof node === "string" || typeof node === "number" ? /* @__PURE__ */ import_react2.default.createElement(import_components.Text, { className }, node) : node;
50
54
  }
51
55
  function AuthPanel({
52
56
  children,
53
57
  className,
54
58
  description,
55
59
  footer,
60
+ headerAlign = "left",
56
61
  logo,
57
62
  style,
58
63
  surface = "card",
59
64
  testID,
60
65
  title
61
66
  }) {
62
- return /* @__PURE__ */ import_react.default.createElement(
67
+ return /* @__PURE__ */ import_react2.default.createElement(
63
68
  import_components.View,
64
69
  {
65
70
  className: `x-taro-auth-panel x-taro-auth-panel--${surface} ${className ?? ""}`,
66
71
  "data-testid": testID,
67
72
  style
68
73
  },
69
- logo || title || description ? /* @__PURE__ */ import_react.default.createElement(import_components.View, { className: "x-taro-auth-panel__header" }, logo ? /* @__PURE__ */ import_react.default.createElement(import_components.View, { className: "x-taro-auth-panel__logo" }, logo) : null, title ? renderText(title, "x-taro-auth-panel__title") : null, description ? renderText(description, "x-taro-auth-panel__description") : null) : null,
74
+ logo || title || description ? /* @__PURE__ */ import_react2.default.createElement(import_components.View, { className: `x-taro-auth-panel__header x-taro-auth-panel__header--${headerAlign}` }, logo ? /* @__PURE__ */ import_react2.default.createElement(import_components.View, { className: "x-taro-auth-panel__logo" }, logo) : null, title ? renderText(title, "x-taro-auth-panel__title") : null, description ? renderText(description, "x-taro-auth-panel__description") : null) : null,
70
75
  children,
71
- footer ? /* @__PURE__ */ import_react.default.createElement(import_components.View, { className: "x-taro-auth-panel__footer" }, footer) : null
76
+ footer ? /* @__PURE__ */ import_react2.default.createElement(import_components.View, { className: "x-taro-auth-panel__footer" }, footer) : null
72
77
  );
73
78
  }
74
79
  function AuthField({
@@ -77,10 +82,10 @@ function AuthField({
77
82
  hint,
78
83
  label
79
84
  }) {
80
- return /* @__PURE__ */ import_react.default.createElement(import_components.View, { className: "x-taro-auth-field" }, label ? renderText(label, "x-taro-auth-field__label") : null, children, error ? /* @__PURE__ */ import_react.default.createElement(import_components.Text, { className: "x-taro-auth-field__error" }, error) : null, !error && hint ? renderText(hint, "x-taro-auth-field__hint") : null);
85
+ return /* @__PURE__ */ import_react2.default.createElement(import_components.View, { className: "x-taro-auth-field" }, label ? renderText(label, "x-taro-auth-field__label") : null, children, error ? /* @__PURE__ */ import_react2.default.createElement(import_components.Text, { className: "x-taro-auth-field__error" }, error) : null, !error && hint ? renderText(hint, "x-taro-auth-field__hint") : null);
81
86
  }
82
87
  function AuthError({ children }) {
83
- return children ? /* @__PURE__ */ import_react.default.createElement(import_components.View, { className: "x-taro-auth-error", role: "alert" }, renderText(children, "x-taro-auth-error__text")) : null;
88
+ return children ? /* @__PURE__ */ import_react2.default.createElement(import_components.View, { className: "x-taro-auth-error", role: "alert" }, renderText(children, "x-taro-auth-error__text")) : null;
84
89
  }
85
90
  function AuthSelector({
86
91
  onChange,
@@ -88,17 +93,50 @@ function AuthSelector({
88
93
  value
89
94
  }) {
90
95
  if (options.length < 2) return null;
91
- return /* @__PURE__ */ import_react.default.createElement(import_components.View, { className: "x-taro-auth-selector", role: "tablist" }, options.map((option) => /* @__PURE__ */ import_react.default.createElement(
92
- import_button.Button,
96
+ return /* @__PURE__ */ import_react2.default.createElement(
97
+ import_segmented.Segmented,
93
98
  {
94
- ariaLabel: typeof option.label === "string" ? option.label : void 0,
95
- key: option.value,
96
- onClick: () => onChange(option.value),
97
- size: "small",
98
- type: option.value === value ? "outline" : "ghost"
99
- },
100
- option.label
101
- )));
99
+ block: true,
100
+ className: "x-taro-auth-selector",
101
+ onChange: (next) => onChange(next),
102
+ options: options.map((option) => ({
103
+ ...option,
104
+ icon: /* @__PURE__ */ import_react2.default.createElement(
105
+ import_icon.Icon,
106
+ {
107
+ name: option.value === "account" ? "UserRound" : option.value === "phone" ? "Phone" : "Mail",
108
+ size: 16
109
+ }
110
+ )
111
+ })),
112
+ value
113
+ }
114
+ );
115
+ }
116
+ function CredentialSelector({
117
+ onChange,
118
+ options,
119
+ value
120
+ }) {
121
+ if (options.length < 2) return null;
122
+ return /* @__PURE__ */ import_react2.default.createElement(
123
+ import_tabs.Tabs,
124
+ {
125
+ className: "x-taro-auth-method-tabs",
126
+ activeKey: value,
127
+ items: options.map((option) => ({ key: option.value, title: option.label })),
128
+ onChange: (next) => onChange(next),
129
+ variant: "outline",
130
+ size: "large",
131
+ stretch: false,
132
+ indicatorVisible: false,
133
+ headerStyle: { gap: 28 },
134
+ tabBarStyle: { borderWidth: 0 },
135
+ tabStyle: { paddingLeft: 0, paddingRight: 0 },
136
+ textStyle: { fontSize: 16 },
137
+ activeTextStyle: { fontWeight: 650 }
138
+ }
139
+ );
102
140
  }
103
141
  function IdentifierInput({
104
142
  config,
@@ -108,10 +146,13 @@ function IdentifierInput({
108
146
  type,
109
147
  value
110
148
  }) {
149
+ const t = config.t;
111
150
  const label = (0, import_identifier.identifierLabel)(type, config);
112
- return /* @__PURE__ */ import_react.default.createElement(AuthField, { error, label: showLabel ? label : void 0 }, type === "phone" ? /* @__PURE__ */ import_react.default.createElement(
151
+ return /* @__PURE__ */ import_react2.default.createElement(AuthField, { error, label: showLabel ? label : void 0 }, type === "phone" ? /* @__PURE__ */ import_react2.default.createElement(
113
152
  import_phoneNumberInput.PhoneNumberInput,
114
153
  {
154
+ placeholder: t("auth.enter", { label }),
155
+ config,
115
156
  countries: config.phone.countries,
116
157
  countryCallingCodeEditable: config.phone.countryCallingCodeEditable,
117
158
  defaultCountry: config.phone.defaultCountry,
@@ -122,14 +163,14 @@ function IdentifierInput({
122
163
  size: "large",
123
164
  value
124
165
  }
125
- ) : /* @__PURE__ */ import_react.default.createElement(
166
+ ) : /* @__PURE__ */ import_react2.default.createElement(
126
167
  import_inputItem.InputItem,
127
168
  {
128
- error,
169
+ error: Boolean(error),
129
170
  maxLength: type === "account" ? config.account.maxLength : void 0,
130
171
  onChange,
131
- placeholder: type === "account" ? config.account.placeholder : `请输入${label}`,
132
- prefix: /* @__PURE__ */ import_react.default.createElement(import_icon.Icon, { name: type === "account" ? "User" : "Mail", size: 18 }),
172
+ placeholder: type === "account" ? config.account.placeholder : t("auth.enter", { label }),
173
+ prefix: /* @__PURE__ */ import_react2.default.createElement(import_icon.Icon, { name: type === "account" ? "User" : "Mail", size: 18 }),
133
174
  size: "large",
134
175
  type: type === "email" ? "email" : "text",
135
176
  value
@@ -137,6 +178,7 @@ function IdentifierInput({
137
178
  ));
138
179
  }
139
180
  function VerificationCodeInput({
181
+ config,
140
182
  codeLength,
141
183
  countdown,
142
184
  disabled,
@@ -147,32 +189,34 @@ function VerificationCodeInput({
147
189
  showLabel = true,
148
190
  value
149
191
  }) {
150
- return /* @__PURE__ */ import_react.default.createElement(AuthField, { error, label: showLabel ? "验证码" : void 0 }, /* @__PURE__ */ import_react.default.createElement(
192
+ const t = (0, import_react.useAuthTranslation)(config);
193
+ return /* @__PURE__ */ import_react2.default.createElement(AuthField, { error, label: showLabel ? t("auth.code") : void 0 }, /* @__PURE__ */ import_react2.default.createElement(
151
194
  import_inputItem.InputItem,
152
195
  {
153
- error,
196
+ error: Boolean(error),
154
197
  maxLength: codeLength,
155
198
  onChange: (next) => onChange(next.replace(/\D/g, "").slice(0, codeLength)),
156
- placeholder: `请输入 ${codeLength} 位验证码`,
157
- prefix: /* @__PURE__ */ import_react.default.createElement(import_icon.Icon, { name: "CircleCheck", size: 18 }),
199
+ placeholder: t("auth.codeLength", { length: codeLength }),
200
+ prefix: /* @__PURE__ */ import_react2.default.createElement(import_icon.Icon, { name: "CircleCheck", size: 18 }),
158
201
  size: "large",
159
- suffix: /* @__PURE__ */ import_react.default.createElement(
202
+ suffix: /* @__PURE__ */ import_react2.default.createElement(
160
203
  import_button.Button,
161
204
  {
162
205
  disabled: disabled || sending || countdown > 0,
163
206
  onClick: onSend,
164
207
  size: "small",
165
- type: "link"
208
+ type: "link",
209
+ compact: true
166
210
  },
167
- sending ? "发送中" : countdown > 0 ? `${countdown}s` : "获取验证码"
211
+ sending ? t("auth.sending") : countdown > 0 ? t("auth.resendCountdown", { seconds: countdown }) : t("auth.getCode")
168
212
  ),
169
213
  type: "tel",
170
214
  value
171
215
  }
172
216
  ));
173
217
  }
174
- function contactOptions(types) {
175
- return types.map((type) => ({ label: (0, import_identifier.identifierLabel)(type), value: type }));
218
+ function contactOptions(types, config) {
219
+ return types.map((type) => ({ label: (0, import_identifier.identifierLabel)(type, config), value: type }));
176
220
  }
177
221
  // Annotate the CommonJS export names for ESM import in node:
178
222
  0 && (module.exports = {
@@ -180,6 +224,7 @@ function contactOptions(types) {
180
224
  AuthField,
181
225
  AuthPanel,
182
226
  AuthSelector,
227
+ CredentialSelector,
183
228
  IdentifierInput,
184
229
  VerificationCodeInput,
185
230
  contactOptions
@@ -1,7 +1,9 @@
1
- import React, { type CSSProperties } from 'react';
1
+ import type { AuthConfig } from '@hanwenbo/x-auth-core/types';
2
+ import { type CSSProperties } from 'react';
2
3
  import type { PhoneCountryCode, PhoneCountryLabels } from '@hanwenbo/x-auth-core/types';
3
4
  import './styles.css';
4
5
  export interface PhoneNumberInputProps {
6
+ config?: AuthConfig;
5
7
  className?: string;
6
8
  countries?: PhoneCountryCode[];
7
9
  countryCallingCodeEditable?: boolean;
@@ -18,5 +20,5 @@ export interface PhoneNumberInputProps {
18
20
  testID?: string;
19
21
  value?: string;
20
22
  }
21
- export declare function PhoneNumberInput({ className, countries, defaultCountry, disabled, error, labels, limitMaxLength, onChange, placeholder, readOnly, size, style, testID, value }: PhoneNumberInputProps): React.JSX.Element;
23
+ export declare function PhoneNumberInput({ config, className, countries, defaultCountry, disabled, error, labels, limitMaxLength, onChange, placeholder, readOnly, size, style, testID, value }: PhoneNumberInputProps): import("react/jsx-runtime").JSX.Element;
22
24
  //# sourceMappingURL=phoneNumberInput.d.ts.map
@@ -32,13 +32,16 @@ __export(phoneNumberInput_exports, {
32
32
  PhoneNumberInput: () => PhoneNumberInput
33
33
  });
34
34
  module.exports = __toCommonJS(phoneNumberInput_exports);
35
- var import_react = __toESM(require("react"));
35
+ var import_react = require("@hanwenbo/x-auth-core/react");
36
+ var import_react2 = __toESM(require("react"));
36
37
  var import_components = require("@tarojs/components");
37
38
  var import_phone = require("@hanwenbo/x-auth-core/phone");
38
39
  var import_inputItem = require("../components/inputItem/index");
39
40
  var import_picker = require("../components/picker");
41
+ var import_tokens = require("../components/inputItem/tokens");
40
42
  var import_styles = require("./styles.css");
41
43
  function PhoneNumberInput({
44
+ config,
42
45
  className,
43
46
  countries,
44
47
  defaultCountry = "CN",
@@ -47,72 +50,89 @@ function PhoneNumberInput({
47
50
  labels,
48
51
  limitMaxLength = true,
49
52
  onChange,
50
- placeholder = "请输入手机号",
53
+ placeholder,
51
54
  readOnly,
52
55
  size,
53
56
  style,
54
57
  testID = "auth-phone-number",
55
58
  value
56
59
  }) {
60
+ const t = (0, import_react.useAuthTranslation)(config);
61
+ const inputTokens = (0, import_tokens.useInputItemTokens)(size);
62
+ if (placeholder === void 0) placeholder = t("auth.enter", { label: t("auth.phone") });
57
63
  const parsed = (0, import_phone.splitPhoneNumber)(value, defaultCountry);
58
- const [country, setCountry] = (0, import_react.useState)(parsed.countryCode);
59
- const options = (0, import_react.useMemo)(() => (0, import_phone.getPhoneCountryOptions)(countries), [countries]);
64
+ const [country, setCountry] = (0, import_react2.useState)(parsed.countryCode);
65
+ const options = (0, import_react2.useMemo)(() => (0, import_phone.getPhoneCountryOptions)(countries), [countries]);
60
66
  const selected = options.find((option) => option.countryCode === country) ?? options[0];
61
67
  const nationalNumber = (0, import_phone.splitPhoneNumber)(
62
68
  value,
63
69
  (selected == null ? void 0 : selected.countryCode) ?? defaultCountry
64
70
  ).nationalNumber;
65
- (0, import_react.useEffect)(() => {
71
+ (0, import_react2.useEffect)(() => {
66
72
  if (options.some((option) => option.countryCode === parsed.countryCode)) {
67
73
  setCountry(parsed.countryCode);
68
74
  }
69
75
  }, [options, parsed.countryCode]);
70
- return /* @__PURE__ */ import_react.default.createElement(import_components.View, { className: `x-taro-auth-phone ${className ?? ""}`, "data-testid": testID, style }, /* @__PURE__ */ import_react.default.createElement(
71
- import_picker.Picker,
76
+ return /* @__PURE__ */ import_react2.default.createElement(
77
+ import_components.View,
72
78
  {
73
- ariaLabel: "选择国家或地区",
74
- columns: options.map((option) => ({
75
- label: `${option.flag} ${(labels == null ? void 0 : labels[option.countryCode]) ?? option.countryCode} ${option.callingCode}`,
76
- value: option.countryCode
77
- })),
78
- disabled: disabled || readOnly,
79
- title: "选择国家或地区",
80
- value: [(selected == null ? void 0 : selected.countryCode) ?? defaultCountry],
81
- onConfirm: (nextValue) => {
82
- const next = options.find((option) => option.countryCode === nextValue[0]);
83
- if (!next) return;
84
- setCountry(next.countryCode);
85
- onChange((0, import_phone.composePhoneNumber)(next.countryCode, nationalNumber));
79
+ className: `x-taro-auth-phone ${className ?? ""}`,
80
+ "data-testid": testID,
81
+ style: {
82
+ "--x-taro-auth-phone-height": `${inputTokens.height}px`,
83
+ "--x-taro-auth-phone-font-size": `${inputTokens.fontSize}px`,
84
+ ...style
86
85
  }
87
86
  },
88
- (_items, actions) => /* @__PURE__ */ import_react.default.createElement(
89
- import_components.View,
87
+ /* @__PURE__ */ import_react2.default.createElement(
88
+ import_picker.Picker,
90
89
  {
91
- ariaLabel: "选择国家或地区",
92
- className: "x-taro-auth-phone__country",
93
- role: "button",
94
- onClick: actions.open
90
+ ariaLabel: t("auth.chooseCountry"),
91
+ columns: options.map((option) => ({
92
+ label: `${option.flag} ${(labels == null ? void 0 : labels[option.countryCode]) ?? option.countryCode} ${option.callingCode}`,
93
+ value: option.countryCode
94
+ })),
95
+ disabled: disabled || readOnly,
96
+ title: t("auth.chooseCountry"),
97
+ value: [(selected == null ? void 0 : selected.countryCode) ?? defaultCountry],
98
+ onConfirm: (nextValue) => {
99
+ const next = options.find((option) => option.countryCode === nextValue[0]);
100
+ if (!next) return;
101
+ setCountry(next.countryCode);
102
+ onChange((0, import_phone.composePhoneNumber)(next.countryCode, nationalNumber));
103
+ }
95
104
  },
96
- /* @__PURE__ */ import_react.default.createElement(import_components.Text, null, selected == null ? void 0 : selected.flag),
97
- /* @__PURE__ */ import_react.default.createElement(import_components.Text, null, selected == null ? void 0 : selected.callingCode),
98
- /* @__PURE__ */ import_react.default.createElement(import_components.Text, { "aria-hidden": true }, "⌄")
105
+ (_items, actions) => /* @__PURE__ */ import_react2.default.createElement(
106
+ import_components.View,
107
+ {
108
+ ariaLabel: t("auth.chooseCountry"),
109
+ className: "x-taro-auth-phone__country",
110
+ role: "button",
111
+ onClick: actions.open
112
+ },
113
+ /* @__PURE__ */ import_react2.default.createElement(import_components.Text, null, selected == null ? void 0 : selected.flag),
114
+ /* @__PURE__ */ import_react2.default.createElement(import_components.Text, null, selected == null ? void 0 : selected.callingCode),
115
+ /* @__PURE__ */ import_react2.default.createElement(import_components.Text, { "aria-hidden": true }, "⌄")
116
+ )
117
+ ),
118
+ /* @__PURE__ */ import_react2.default.createElement(
119
+ import_inputItem.InputItem,
120
+ {
121
+ ariaLabel: t("auth.phone"),
122
+ className: "x-taro-auth-phone__input",
123
+ disabled,
124
+ error,
125
+ maxLength: limitMaxLength ? 15 : void 0,
126
+ onChange: (next) => onChange((0, import_phone.composePhoneNumber)(country, next.replace(/\D/g, ""))),
127
+ placeholder,
128
+ readOnly,
129
+ size,
130
+ style: { minHeight: inputTokens.height - 2 },
131
+ type: "tel",
132
+ value: nationalNumber
133
+ }
99
134
  )
100
- ), /* @__PURE__ */ import_react.default.createElement(
101
- import_inputItem.InputItem,
102
- {
103
- ariaLabel: "手机号",
104
- className: "x-taro-auth-phone__input",
105
- disabled,
106
- error,
107
- maxLength: limitMaxLength ? 15 : void 0,
108
- onChange: (next) => onChange((0, import_phone.composePhoneNumber)(country, next.replace(/\D/g, ""))),
109
- placeholder,
110
- readOnly,
111
- size,
112
- type: "tel",
113
- value: nationalNumber
114
- }
115
- ));
135
+ );
116
136
  }
117
137
  // Annotate the CommonJS export names for ESM import in node:
118
138
  0 && (module.exports = {
@@ -1,4 +1,4 @@
1
- import React, { type PropsWithChildren } from 'react';
1
+ import { type PropsWithChildren } from 'react';
2
2
  import type { AuthConfig, AuthFailureHandler, AuthServices, AuthSession, ReauthenticationRequiredHandler } from '@hanwenbo/x-auth-core/types';
3
3
  import { type AuthThemeTokens } from './theme';
4
4
  export interface AuthProviderProps<Session extends AuthSession = AuthSession> extends PropsWithChildren {
@@ -8,6 +8,6 @@ export interface AuthProviderProps<Session extends AuthSession = AuthSession> ex
8
8
  services?: AuthServices<Session>;
9
9
  tokens?: AuthThemeTokens;
10
10
  }
11
- export declare function AuthProvider<Session extends AuthSession = AuthSession>({ children, config, onAuthError, onReauthenticationRequired, services, tokens }: AuthProviderProps<Session>): React.JSX.Element;
11
+ export declare function AuthProvider<Session extends AuthSession = AuthSession>({ children, config, onAuthError, onReauthenticationRequired, services, tokens }: AuthProviderProps<Session>): import("react/jsx-runtime").JSX.Element;
12
12
  export declare function useAuthTheme(tokens?: AuthThemeTokens): AuthThemeTokens;
13
13
  //# sourceMappingURL=provider.d.ts.map