@yhgale/ui 0.1.3 → 0.1.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/dist/index.d.ts CHANGED
@@ -137,6 +137,12 @@ interface SignInProps {
137
137
  afterSignInUrl?: string;
138
138
  onComplete?: () => void;
139
139
  className?: string;
140
+ /** 初始登录步骤标题;不传则使用本地化默认标题。 */
141
+ title?: ReactNode;
142
+ /** 初始登录步骤的可选简介。 */
143
+ description?: ReactNode;
144
+ /** card 显示独立卡片;plain 由宿主页面提供卡片容器。 */
145
+ variant?: 'card' | 'plain';
140
146
  linkComponent?: LinkComponent;
141
147
  /** 忘记密码页面 URL;不传则不显示链接 */
142
148
  forgotPasswordUrl?: string;
@@ -146,7 +152,7 @@ interface SignInProps {
146
152
  ssoCallbackUrl?: string;
147
153
  /** 社交按钮排列方式:'full' 图标+文字纵向(默认),'icons' 纯图标横向 flex-wrap */
148
154
  socialLayout?: SocialLayout;
149
- /** Captcha site key(从 environment 端点获取);不传则不启用 captcha */
155
+ /** Captcha site key 覆盖值;不传则读取 Provider 的 environment 配置。 */
150
156
  captchaSiteKey?: string;
151
157
  /** Captcha invisible site key(从 environment 端点获取) */
152
158
  captchaInvisibleSiteKey?: string;
@@ -155,13 +161,19 @@ interface SignInProps {
155
161
  /** 是否显示 passkey 登录(Instance authConfig.firstFactor 含 'passkey')。不传则自动从 environment 检测。 */
156
162
  passkeyFirstFactorEnabled?: boolean;
157
163
  }
158
- declare function SignIn({ signUpUrl, afterSignInUrl, onComplete, className, linkComponent, forgotPasswordUrl, oauthProviders, ssoCallbackUrl, socialLayout, captchaSiteKey, captchaInvisibleSiteKey, captchaWidgetType, passkeyFirstFactorEnabled, }: SignInProps): _emotion_react_jsx_runtime.JSX.Element;
164
+ declare function SignIn({ signUpUrl, afterSignInUrl, onComplete, className, title, description, variant, linkComponent, forgotPasswordUrl, oauthProviders, ssoCallbackUrl, socialLayout, captchaSiteKey: captchaSiteKeyProp, captchaInvisibleSiteKey: captchaInvisibleSiteKeyProp, captchaWidgetType: captchaWidgetTypeProp, passkeyFirstFactorEnabled, }: SignInProps): _emotion_react_jsx_runtime.JSX.Element;
159
165
 
160
166
  interface SignUpProps {
161
167
  signInUrl?: string;
162
168
  afterSignUpUrl?: string;
163
169
  onComplete?: () => void;
164
170
  className?: string;
171
+ /** 初始注册步骤标题;不传则使用本地化默认标题。 */
172
+ title?: ReactNode;
173
+ /** 初始注册步骤的可选简介。 */
174
+ description?: ReactNode;
175
+ /** card 显示独立卡片;plain 由宿主页面提供卡片容器。 */
176
+ variant?: 'card' | 'plain';
165
177
  linkComponent?: LinkComponent;
166
178
  /** 启用的 OAuth provider key 列表(不含 oauth_ 前缀),如 ['github']。不传则自动从 /v1/environment 获取 */
167
179
  oauthProviders?: string[];
@@ -169,14 +181,14 @@ interface SignUpProps {
169
181
  ssoCallbackUrl?: string;
170
182
  /** 社交按钮排列方式:'full' 图标+文字纵向(默认),'icons' 纯图标横向 flex-wrap */
171
183
  socialLayout?: SocialLayout;
172
- /** Captcha site key(从 environment 端点获取);不传则不启用 captcha */
184
+ /** Captcha site key 覆盖值;不传则读取 Provider 的 environment 配置。 */
173
185
  captchaSiteKey?: string;
174
186
  /** Captcha invisible site key(从 environment 端点获取) */
175
187
  captchaInvisibleSiteKey?: string;
176
188
  /** Captcha widget 类型:smart 可见 / invisible 静默 */
177
189
  captchaWidgetType?: 'smart' | 'invisible';
178
190
  }
179
- declare function SignUp({ signInUrl, afterSignUpUrl, onComplete, className, linkComponent, oauthProviders, ssoCallbackUrl, socialLayout, captchaSiteKey, captchaInvisibleSiteKey, captchaWidgetType, }: SignUpProps): _emotion_react_jsx_runtime.JSX.Element;
191
+ declare function SignUp({ signInUrl, afterSignUpUrl, onComplete, className, title, description, variant, linkComponent, oauthProviders, ssoCallbackUrl, socialLayout, captchaSiteKey: captchaSiteKeyProp, captchaInvisibleSiteKey: captchaInvisibleSiteKeyProp, captchaWidgetType: captchaWidgetTypeProp, }: SignUpProps): _emotion_react_jsx_runtime.JSX.Element;
180
192
 
181
193
  /** @jsxImportSource @emotion/react */
182
194
  declare const PHONE_COUNTRY_CODES: readonly ["+86", "+852", "+853", "+886", "+1", "+81", "+82", "+65"];
package/dist/index.js CHANGED
@@ -2719,14 +2719,20 @@ import {
2719
2719
  useRef as useRef3,
2720
2720
  useState as useState2
2721
2721
  } from "react";
2722
- import { useSignIn, useUser, useEnvironment, useAuth, useLocalization as useLocalization3 } from "@yhgale/gale-js/react";
2722
+ import {
2723
+ useSignIn,
2724
+ useUser,
2725
+ useEnvironment,
2726
+ useAuth,
2727
+ useLocalization as useLocalization3
2728
+ } from "@yhgale/gale-js/react";
2723
2729
 
2724
2730
  // src/styledSystem/StyleCacheProvider.tsx
2725
2731
  import { createContext as createContext3, useContext as useContext5 } from "react";
2726
2732
  var KEY = "au";
2727
2733
  var _cache;
2728
2734
  function getCache() {
2729
- if (!_cache) _cache = createCache({ key: KEY, prepend: true, speedy: false });
2735
+ if (!_cache) _cache = createCache({ key: KEY, speedy: false });
2730
2736
  return _cache;
2731
2737
  }
2732
2738
  var CacheCtx = createContext3(getCache());
@@ -3334,6 +3340,14 @@ var cardSx = {
3334
3340
  padding: space["6"],
3335
3341
  boxShadow: shadows.card
3336
3342
  };
3343
+ var plainCardSx = {
3344
+ ...cardSx,
3345
+ maxWidth: "none",
3346
+ border: "none",
3347
+ background: "transparent",
3348
+ padding: 0,
3349
+ boxShadow: "none"
3350
+ };
3337
3351
  var errorBannerSx = {
3338
3352
  marginTop: space["4"],
3339
3353
  borderRadius: radii.md,
@@ -3453,14 +3467,17 @@ function SignIn({
3453
3467
  afterSignInUrl,
3454
3468
  onComplete,
3455
3469
  className,
3470
+ title,
3471
+ description,
3472
+ variant = "card",
3456
3473
  linkComponent,
3457
3474
  forgotPasswordUrl,
3458
3475
  oauthProviders,
3459
3476
  ssoCallbackUrl = "/sso-callback",
3460
3477
  socialLayout = "full",
3461
- captchaSiteKey,
3462
- captchaInvisibleSiteKey,
3463
- captchaWidgetType,
3478
+ captchaSiteKey: captchaSiteKeyProp,
3479
+ captchaInvisibleSiteKey: captchaInvisibleSiteKeyProp,
3480
+ captchaWidgetType: captchaWidgetTypeProp,
3464
3481
  passkeyFirstFactorEnabled
3465
3482
  }) {
3466
3483
  const { t: t2 } = useLocalization3();
@@ -3484,6 +3501,10 @@ function SignIn({
3484
3501
  }
3485
3502
  }, [sign.status, afterSignInUrl, onComplete]);
3486
3503
  const env = useEnvironment();
3504
+ const rootSx = variant === "plain" ? plainCardSx : cardSx;
3505
+ const captchaSiteKey = captchaSiteKeyProp ?? env.captcha.siteKey ?? void 0;
3506
+ const captchaInvisibleSiteKey = captchaInvisibleSiteKeyProp ?? env.captcha.invisibleSiteKey ?? void 0;
3507
+ const captchaWidgetType = captchaWidgetTypeProp ?? env.captcha.widgetType ?? void 0;
3487
3508
  const passkeyEnabled = passkeyFirstFactorEnabled ?? env.firstFactor.includes("passkey");
3488
3509
  useEffect3(() => {
3489
3510
  if (!passkeyEnabled) return;
@@ -3543,7 +3564,8 @@ function SignIn({
3543
3564
  const enabledProviderMetas = resolvedProviders.map((key) => getOauthProviderMeta(key)).filter((m) => m !== void 0);
3544
3565
  const showDivider = enabledProviderMetas.length > 0 || passkeyEnabled;
3545
3566
  content = /* @__PURE__ */ jsxs2(Fragment3, { children: [
3546
- /* @__PURE__ */ jsx2(Box, { as: "h2", sx: h2Sx, children: t2("signIn.title") }),
3567
+ /* @__PURE__ */ jsx2(Box, { as: "h2", sx: h2Sx, children: title ?? t2("signIn.title") }),
3568
+ description ? /* @__PURE__ */ jsx2(Box, { sx: mutedPSx, children: description }) : null,
3547
3569
  sign.error ? /* @__PURE__ */ jsx2(ErrorBanner, { message: sign.error.message, code: sign.error.code }) : null,
3548
3570
  auth.error ? /* @__PURE__ */ jsx2(AuthErrorHint, { message: auth.error.message }) : null,
3549
3571
  sign.status === "idle" || sign.status === "submitting_identifier" || sign.status === "failed" ? /* @__PURE__ */ jsxs2(Fragment3, { children: [
@@ -3590,7 +3612,7 @@ function SignIn({
3590
3612
  )
3591
3613
  ] });
3592
3614
  }
3593
- return /* @__PURE__ */ jsx2(StyleCacheProvider, { children: /* @__PURE__ */ jsx2(InternalThemeProvider, { children: /* @__PURE__ */ jsxs2(Box, { sx: cardSx, className, "data-gale-component": "sign-in", children: [
3615
+ return /* @__PURE__ */ jsx2(StyleCacheProvider, { children: /* @__PURE__ */ jsx2(InternalThemeProvider, { children: /* @__PURE__ */ jsxs2(Box, { sx: rootSx, className, "data-gale-component": "sign-in", children: [
3594
3616
  captchaActive && /* @__PURE__ */ jsx2(
3595
3617
  CaptchaElement,
3596
3618
  {
@@ -4202,26 +4224,20 @@ function AuthErrorHint({ message }) {
4202
4224
  );
4203
4225
  }
4204
4226
  function ErrorBanner({ message, code }) {
4205
- return /* @__PURE__ */ jsxs2(Box, { role: "alert", sx: errorBannerSx, children: [
4206
- /* @__PURE__ */ jsx2(Box, { sx: { fontWeight: fontWeights.medium }, children: message }),
4207
- /* @__PURE__ */ jsx2(
4208
- Box,
4209
- {
4210
- sx: {
4211
- marginTop: space["0_5"],
4212
- fontFamily: fonts.mono,
4213
- fontSize: "11px",
4214
- color: colors.danger400
4215
- },
4216
- children: code
4217
- }
4218
- )
4219
- ] });
4227
+ const { t: t2 } = useLocalization3();
4228
+ const localized = t2(`unstable__errors.${code}`, message);
4229
+ return /* @__PURE__ */ jsx2(Box, { role: "alert", sx: errorBannerSx, children: /* @__PURE__ */ jsx2(Box, { sx: { fontWeight: fontWeights.medium }, children: localized }) });
4220
4230
  }
4221
4231
 
4222
4232
  // src/components/SignUp.tsx
4223
4233
  import { useEffect as useEffect4, useRef as useRef4, useState as useState3 } from "react";
4224
- import { useSignUp, useUser as useUser2, useEnvironment as useEnvironment2, useAuth as useAuth2, useLocalization as useLocalization4 } from "@yhgale/gale-js/react";
4234
+ import {
4235
+ useSignUp,
4236
+ useUser as useUser2,
4237
+ useEnvironment as useEnvironment2,
4238
+ useAuth as useAuth2,
4239
+ useLocalization as useLocalization4
4240
+ } from "@yhgale/gale-js/react";
4225
4241
  var cardSx2 = {
4226
4242
  width: "100%",
4227
4243
  maxWidth: 400,
@@ -4231,6 +4247,14 @@ var cardSx2 = {
4231
4247
  padding: space["6"],
4232
4248
  boxShadow: shadows.card
4233
4249
  };
4250
+ var plainCardSx2 = {
4251
+ ...cardSx2,
4252
+ maxWidth: "none",
4253
+ border: "none",
4254
+ background: "transparent",
4255
+ padding: 0,
4256
+ boxShadow: "none"
4257
+ };
4234
4258
  var errorBannerSx2 = {
4235
4259
  marginTop: space["4"],
4236
4260
  borderRadius: radii.md,
@@ -4294,13 +4318,16 @@ function SignUp({
4294
4318
  afterSignUpUrl,
4295
4319
  onComplete,
4296
4320
  className,
4321
+ title,
4322
+ description,
4323
+ variant = "card",
4297
4324
  linkComponent,
4298
4325
  oauthProviders,
4299
4326
  ssoCallbackUrl = "/sso-callback",
4300
4327
  socialLayout = "full",
4301
- captchaSiteKey,
4302
- captchaInvisibleSiteKey,
4303
- captchaWidgetType
4328
+ captchaSiteKey: captchaSiteKeyProp,
4329
+ captchaInvisibleSiteKey: captchaInvisibleSiteKeyProp,
4330
+ captchaWidgetType: captchaWidgetTypeProp
4304
4331
  }) {
4305
4332
  const { t: t2 } = useLocalization4();
4306
4333
  const auth = useAuth2();
@@ -4320,6 +4347,10 @@ function SignUp({
4320
4347
  onComplete?.();
4321
4348
  }, [sign.status, afterSignUpUrl, onComplete]);
4322
4349
  const env = useEnvironment2();
4350
+ const rootSx = variant === "plain" ? plainCardSx2 : cardSx2;
4351
+ const captchaSiteKey = captchaSiteKeyProp ?? env.captcha.siteKey ?? void 0;
4352
+ const captchaInvisibleSiteKey = captchaInvisibleSiteKeyProp ?? env.captcha.invisibleSiteKey ?? void 0;
4353
+ const captchaWidgetType = captchaWidgetTypeProp ?? env.captcha.widgetType ?? void 0;
4323
4354
  const [captchaToken, setCaptchaToken] = useState3();
4324
4355
  const [captchaWidgetTypeState, setCaptchaWidgetTypeState] = useState3();
4325
4356
  const [captchaError, setCaptchaError] = useState3();
@@ -4337,13 +4368,13 @@ function SignUp({
4337
4368
  const captcha = { ready: captchaReady, take: takeCaptchaFields };
4338
4369
  const captchaActive = hasCaptcha && (sign.status === "idle" || sign.status === "submitting_signup" || sign.status === "failed");
4339
4370
  if (sign.status === "complete") {
4340
- return /* @__PURE__ */ jsx2(StyleCacheProvider, { children: /* @__PURE__ */ jsx2(InternalThemeProvider, { children: /* @__PURE__ */ jsxs2(Box, { sx: cardSx2, className, "data-gale-component": "sign-up", children: [
4371
+ return /* @__PURE__ */ jsx2(StyleCacheProvider, { children: /* @__PURE__ */ jsx2(InternalThemeProvider, { children: /* @__PURE__ */ jsxs2(Box, { sx: rootSx, className, "data-gale-component": "sign-up", children: [
4341
4372
  /* @__PURE__ */ jsx2(Box, { as: "h2", sx: h2Sx2, children: t2("signUp.welcomeTitle") }),
4342
4373
  /* @__PURE__ */ jsx2(Box, { as: "p", sx: mutedPSx2, children: t2("signUp.welcomeMessage") })
4343
4374
  ] }) }) });
4344
4375
  }
4345
4376
  if (userLoaded && user) {
4346
- return /* @__PURE__ */ jsx2(StyleCacheProvider, { children: /* @__PURE__ */ jsx2(InternalThemeProvider, { children: /* @__PURE__ */ jsxs2(Box, { sx: cardSx2, className, "data-gale-component": "sign-up", children: [
4377
+ return /* @__PURE__ */ jsx2(StyleCacheProvider, { children: /* @__PURE__ */ jsx2(InternalThemeProvider, { children: /* @__PURE__ */ jsxs2(Box, { sx: rootSx, className, "data-gale-component": "sign-up", children: [
4347
4378
  /* @__PURE__ */ jsx2(Box, { as: "h2", sx: h2Sx2, children: t2("signUp.alreadySignedInTitle") }),
4348
4379
  /* @__PURE__ */ jsx2(Box, { as: "p", sx: mutedPSx2, children: t2("signUp.alreadySignedInMessage", {
4349
4380
  name: user.primaryEmail ?? user.displayName ?? user.id
@@ -4351,7 +4382,7 @@ function SignUp({
4351
4382
  ] }) }) });
4352
4383
  }
4353
4384
  if (sign.status === "awaiting_external_verification") {
4354
- return /* @__PURE__ */ jsx2(StyleCacheProvider, { children: /* @__PURE__ */ jsx2(InternalThemeProvider, { children: /* @__PURE__ */ jsxs2(Box, { sx: cardSx2, className, "data-gale-component": "sign-up", children: [
4385
+ return /* @__PURE__ */ jsx2(StyleCacheProvider, { children: /* @__PURE__ */ jsx2(InternalThemeProvider, { children: /* @__PURE__ */ jsxs2(Box, { sx: rootSx, className, "data-gale-component": "sign-up", children: [
4355
4386
  /* @__PURE__ */ jsx2(Box, { as: "h2", sx: h2Sx2, children: t2("signUp.createAccountTitle") }),
4356
4387
  /* @__PURE__ */ jsx2(Box, { as: "p", sx: { ...mutedPSx2, marginTop: space["4"] }, children: t2("signUp.redirectingOauth") })
4357
4388
  ] }) }) });
@@ -4360,7 +4391,7 @@ function SignUp({
4360
4391
  const enabledProviderMetas = resolvedProviders.map((key) => getOauthProviderMeta(key)).filter((m) => m !== void 0);
4361
4392
  const showDivider = enabledProviderMetas.length > 0;
4362
4393
  const inVerification = sign.status === "needs_email_verification" || sign.status === "submitting_verification";
4363
- return /* @__PURE__ */ jsx2(StyleCacheProvider, { children: /* @__PURE__ */ jsx2(InternalThemeProvider, { children: /* @__PURE__ */ jsxs2(Box, { sx: cardSx2, className, "data-gale-component": "sign-up", children: [
4394
+ return /* @__PURE__ */ jsx2(StyleCacheProvider, { children: /* @__PURE__ */ jsx2(InternalThemeProvider, { children: /* @__PURE__ */ jsxs2(Box, { sx: rootSx, className, "data-gale-component": "sign-up", children: [
4364
4395
  captchaActive && /* @__PURE__ */ jsx2(
4365
4396
  CaptchaElement,
4366
4397
  {
@@ -4418,7 +4449,8 @@ function SignUp({
4418
4449
  ]
4419
4450
  }
4420
4451
  ),
4421
- /* @__PURE__ */ jsx2(Box, { as: "h2", sx: h2Sx2, children: inVerification && sign.phoneNumber ? t2("signUp.phoneCodeTitle") : t2("signUp.title") }),
4452
+ /* @__PURE__ */ jsx2(Box, { as: "h2", sx: h2Sx2, children: inVerification ? sign.phoneNumber ? t2("signUp.phoneCodeTitle") : t2("signUp.title") : title ?? t2("signUp.title") }),
4453
+ !inVerification && description ? /* @__PURE__ */ jsx2(Box, { sx: mutedPSx2, children: description }) : null,
4422
4454
  sign.error ? /* @__PURE__ */ jsx2(ErrorBanner2, { message: sign.error.message, code: sign.error.code }) : null,
4423
4455
  auth.error ? /* @__PURE__ */ jsx2(AuthErrorHint2, { message: auth.error.message }) : null,
4424
4456
  sign.status === "idle" || sign.status === "submitting_signup" || sign.status === "failed" ? /* @__PURE__ */ jsxs2(Fragment3, { children: [
@@ -4672,21 +4704,9 @@ function AuthErrorHint2({ message }) {
4672
4704
  );
4673
4705
  }
4674
4706
  function ErrorBanner2({ message, code }) {
4675
- return /* @__PURE__ */ jsxs2(Box, { role: "alert", sx: errorBannerSx2, children: [
4676
- /* @__PURE__ */ jsx2(Box, { sx: { fontWeight: fontWeights.medium }, children: message }),
4677
- /* @__PURE__ */ jsx2(
4678
- Box,
4679
- {
4680
- sx: {
4681
- marginTop: space["0_5"],
4682
- fontFamily: fonts.mono,
4683
- fontSize: "11px",
4684
- color: colors.danger400
4685
- },
4686
- children: code
4687
- }
4688
- )
4689
- ] });
4707
+ const { t: t2 } = useLocalization4();
4708
+ const localized = t2(`unstable__errors.${code}`, message);
4709
+ return /* @__PURE__ */ jsx2(Box, { role: "alert", sx: errorBannerSx2, children: /* @__PURE__ */ jsx2(Box, { sx: { fontWeight: fontWeights.medium }, children: localized }) });
4690
4710
  }
4691
4711
 
4692
4712
  // src/components/UserButton.tsx
@@ -5407,7 +5427,7 @@ function PasskeyManager({ className, emptyState, embedded }) {
5407
5427
  }
5408
5428
  )
5409
5429
  ] }),
5410
- error ? /* @__PURE__ */ jsxs2(
5430
+ error ? /* @__PURE__ */ jsx2(
5411
5431
  Flex,
5412
5432
  {
5413
5433
  role: "alert",
@@ -5421,22 +5441,7 @@ function PasskeyManager({ className, emptyState, embedded }) {
5421
5441
  fontSize: fontSizes.sm,
5422
5442
  color: colors.danger600
5423
5443
  },
5424
- children: [
5425
- /* @__PURE__ */ jsx2(Flex, { as: "div", css: { fontWeight: fontWeights.medium }, children: error.message }),
5426
- /* @__PURE__ */ jsx2(
5427
- Flex,
5428
- {
5429
- as: "div",
5430
- css: {
5431
- marginTop: space["0_5"],
5432
- fontFamily: fonts.mono,
5433
- fontSize: "11px",
5434
- color: colors.danger400
5435
- },
5436
- children: error.code
5437
- }
5438
- )
5439
- ]
5444
+ children: /* @__PURE__ */ jsx2(Flex, { as: "div", css: { fontWeight: fontWeights.medium }, children: t2(`unstable__errors.${error.code}`, error.message) })
5440
5445
  }
5441
5446
  ) : null,
5442
5447
  !passkeys || passkeys.length === 0 ? /* @__PURE__ */ jsx2(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yhgale/ui",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Headless UI components for gale (SignIn, UserButton, OrganizationSwitcher)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -24,7 +24,7 @@
24
24
  "dependencies": {
25
25
  "@emotion/cache": "^11.14.0",
26
26
  "@emotion/react": "^11.14.0",
27
- "@yhgale/gale-js": "^0.1.6"
27
+ "@yhgale/gale-js": "^0.1.9"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/node": "^22.10.2",