@ploykit/ui 0.4.1 → 0.6.0
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.
|
@@ -8,8 +8,13 @@ export interface LoginPageProps {
|
|
|
8
8
|
registerPath?: string;
|
|
9
9
|
oauthProviders?: OAuthProviderOption[];
|
|
10
10
|
enableFedLogin?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* 纯密码形态(企业内部工具):隐藏验证码 Tab,页面直接是密码登录——
|
|
13
|
+
* 不渲染 Tabs 结构,OAuth 槽位照常由 oauthProviders 控制(不传即无)。
|
|
14
|
+
*/
|
|
15
|
+
passwordOnly?: boolean;
|
|
11
16
|
onSuccess?: () => void;
|
|
12
17
|
title?: string;
|
|
13
18
|
description?: string;
|
|
14
19
|
}
|
|
15
|
-
export declare function LoginPage({ resetPath, registerPath, oauthProviders, enableFedLogin, onSuccess, title, description, }: LoginPageProps): import("react").JSX.Element;
|
|
20
|
+
export declare function LoginPage({ resetPath, registerPath, oauthProviders, enableFedLogin, passwordOnly, onSuccess, title, description, }: LoginPageProps): import("react").JSX.Element;
|
package/dist/pages/LoginPage.js
CHANGED
|
@@ -17,7 +17,7 @@ export function loginRedirectTarget(from, fallback = '/app') {
|
|
|
17
17
|
return fallback;
|
|
18
18
|
return from;
|
|
19
19
|
}
|
|
20
|
-
export function LoginPage({ resetPath = '/forgot-password', registerPath = '/register', oauthProviders = [], enableFedLogin = false, onSuccess, title = '登录', description = '登录你的账号', }) {
|
|
20
|
+
export function LoginPage({ resetPath = '/forgot-password', registerPath = '/register', oauthProviders = [], enableFedLogin = false, passwordOnly = false, onSuccess, title = '登录', description = '登录你的账号', }) {
|
|
21
21
|
const { submit, loading, error: codeError } = useLogin();
|
|
22
22
|
const api = useApi();
|
|
23
23
|
const { refresh } = useAuth();
|
|
@@ -77,11 +77,11 @@ export function LoginPage({ resetPath = '/forgot-password', registerPath = '/reg
|
|
|
77
77
|
setPwLoading(false);
|
|
78
78
|
}
|
|
79
79
|
};
|
|
80
|
-
return (_jsx("div", { className: "min-h-screen flex items-center justify-center bg-background", children: _jsxs("div", { className: "w-full max-w-sm space-y-4 p-8 bg-white rounded-lg shadow", children: [_jsxs("div", { className: "text-center", children: [_jsx("h1", { className: "text-2xl font-bold", children: title }), _jsx("p", { className: "mt-1 text-sm text-muted-foreground", children: description })] }), _jsxs(Tabs, { defaultValue: "code", children: [_jsxs(TabsList, { className: "w-full", children: [_jsx(TabsTrigger, { value: "code", children: "\u9A8C\u8BC1\u7801\u767B\u5F55" }), _jsx(TabsTrigger, { value: "password", children: "\u5BC6\u7801\u767B\u5F55" })] }), _jsx(TabsContent, { value: "code", children: _jsxs("form", { onSubmit: handleCodeSubmit, className: "space-y-4 pt-2", children: [_jsxs("div", { className: "space-y-1", children: [_jsx("label", { htmlFor: "login-email", className: "text-sm text-foreground", children: "\u90AE\u7BB1" }), _jsx("input", { id: "login-email", type: "email", value: email, onChange: (e) => setEmail(e.target.value), placeholder: "you@example.com", required: true, autoComplete: "email", className: "w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-ring" })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("label", { htmlFor: "login-code", className: "text-sm text-foreground", children: "\u9A8C\u8BC1\u7801" }), _jsxs("div", { className: "flex gap-2", children: [_jsx("input", { id: "login-code", type: "text", value: code, onChange: (e) => setCode(e.target.value), placeholder: "6\u4F4D\u6570\u5B57", maxLength: 6, required: true, autoComplete: "one-time-code", className: "flex-1 px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-ring" }), _jsx("button", { type: "button", onClick: handleSendCode, disabled: sending || cooldown > 0 || !email, className: "px-4 py-2 text-sm text-primary border border-primary/30 rounded-md hover:bg-primary/10 disabled:opacity-50", children: cooldown > 0
|
|
80
|
+
return (_jsx("div", { className: "min-h-screen flex items-center justify-center bg-background", children: _jsxs("div", { className: "w-full max-w-sm space-y-4 p-8 bg-white rounded-lg shadow", children: [_jsxs("div", { className: "text-center", children: [_jsx("h1", { className: "text-2xl font-bold", children: title }), _jsx("p", { className: "mt-1 text-sm text-muted-foreground", children: description })] }), passwordOnly ? (_jsxs("form", { onSubmit: handlePasswordSubmit, className: "space-y-4 pt-2", children: [_jsx(FormField, { label: "\u90AE\u7BB1", htmlFor: "login-pw-email", children: _jsx(Input, { id: "login-pw-email", type: "email", value: email, required: true, onChange: (e) => setEmail(e.target.value), placeholder: "you@example.com", autoComplete: "email" }) }), _jsx(FormField, { label: "\u5BC6\u7801", htmlFor: "login-pw-password", children: _jsx(Input, { id: "login-pw-password", type: "password", value: password, required: true, onChange: (e) => setPassword(e.target.value), placeholder: "\u8F93\u5165\u5BC6\u7801", autoComplete: "current-password" }) }), pwError && _jsx("p", { role: "alert", className: "text-destructive text-sm", children: pwError }), _jsx(Button, { type: "submit", className: "w-full", disabled: pwLoading || !email || !password, children: pwLoading ? '登录中…' : '登录' })] })) : (_jsxs(Tabs, { defaultValue: "code", children: [_jsxs(TabsList, { className: "w-full", children: [_jsx(TabsTrigger, { value: "code", children: "\u9A8C\u8BC1\u7801\u767B\u5F55" }), _jsx(TabsTrigger, { value: "password", children: "\u5BC6\u7801\u767B\u5F55" })] }), _jsx(TabsContent, { value: "code", children: _jsxs("form", { onSubmit: handleCodeSubmit, className: "space-y-4 pt-2", children: [_jsxs("div", { className: "space-y-1", children: [_jsx("label", { htmlFor: "login-email", className: "text-sm text-foreground", children: "\u90AE\u7BB1" }), _jsx("input", { id: "login-email", type: "email", value: email, onChange: (e) => setEmail(e.target.value), placeholder: "you@example.com", required: true, autoComplete: "email", className: "w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-ring" })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("label", { htmlFor: "login-code", className: "text-sm text-foreground", children: "\u9A8C\u8BC1\u7801" }), _jsxs("div", { className: "flex gap-2", children: [_jsx("input", { id: "login-code", type: "text", value: code, onChange: (e) => setCode(e.target.value), placeholder: "6\u4F4D\u6570\u5B57", maxLength: 6, required: true, autoComplete: "one-time-code", className: "flex-1 px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-ring" }), _jsx("button", { type: "button", onClick: handleSendCode, disabled: sending || cooldown > 0 || !email, className: "px-4 py-2 text-sm text-primary border border-primary/30 rounded-md hover:bg-primary/10 disabled:opacity-50", children: cooldown > 0
|
|
81
81
|
? `重发(${cooldown}s)`
|
|
82
82
|
: codeSent
|
|
83
83
|
? '重新发送'
|
|
84
84
|
: sending
|
|
85
85
|
? '发送中…'
|
|
86
|
-
: '发送' })] })] }), sendError && _jsx("p", { role: "alert", className: "text-destructive text-sm", children: sendError }), codeError && _jsx("p", { role: "alert", className: "text-destructive text-sm", children: codeError }), _jsx("button", { type: "submit", disabled: loading || !email || !code, className: "w-full py-2 px-4 bg-primary text-primary-foreground rounded-md hover:bg-primary/80 disabled:opacity-50", children: loading ? '登录中…' : '登录' })] }) }), _jsx(TabsContent, { value: "password", children: _jsxs("form", { onSubmit: handlePasswordSubmit, className: "space-y-4 pt-2", children: [_jsx(FormField, { label: "\u90AE\u7BB1", htmlFor: "login-pw-email", children: _jsx(Input, { id: "login-pw-email", type: "email", value: email, required: true, onChange: (e) => setEmail(e.target.value), placeholder: "you@example.com", autoComplete: "email" }) }), _jsx(FormField, { label: "\u5BC6\u7801", htmlFor: "login-pw-password", children: _jsx(Input, { id: "login-pw-password", type: "password", value: password, required: true, onChange: (e) => setPassword(e.target.value), placeholder: "\u8F93\u5165\u5BC6\u7801", autoComplete: "current-password" }) }), pwError && _jsx("p", { role: "alert", className: "text-destructive text-sm", children: pwError }), _jsx(Button, { type: "submit", className: "w-full", disabled: pwLoading || !email || !password, children: pwLoading ? '登录中…' : '登录' })] }) })] }), oauthProviders.length > 0 && (_jsxs("div", { className: "space-y-2 pt-1", "data-testid": "oauth-providers", children: [_jsxs("div", { className: "relative py-2 text-center", children: [_jsx("span", { className: "absolute inset-x-0 top-1/2 border-t border-border" }), _jsx("span", { className: "relative z-10 bg-card px-2 text-xs text-muted-foreground", children: "\u6216\u4F7F\u7528\u4EE5\u4E0B\u65B9\u5F0F\u767B\u5F55" })] }), oauthProviders.map((p) => (_jsxs("a", { href: '/auth/oauth/' + p.id + '/start', className: "block w-full py-2 px-4 text-center text-sm border border-input rounded-md hover:bg-background", children: ["\u4F7F\u7528 ", p.label, " \u767B\u5F55"] }, p.id)))] })), enableFedLogin && (_jsxs("details", { className: "pt-1", "data-testid": "fed-login", children: [_jsx("summary", { className: "text-sm text-muted-foreground cursor-pointer select-none", children: "\u4F01\u4E1A\u767B\u5F55" }), _jsxs("form", { method: "get", action: "/auth/fed/start", className: "mt-2 space-y-2", children: [_jsx("input", { type: "text", name: "workspace", placeholder: "\u5DE5\u4F5C\u533A\u6807\u8BC6\uFF08slug\uFF09", required: true, className: "w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-ring" }), _jsx("button", { type: "submit", className: "w-full py-2 px-4 bg-primary text-primary-foreground text-sm rounded-md hover:bg-primary/80", children: "\u901A\u8FC7\u4F01\u4E1A IdP \u767B\u5F55" })] })] })), (resetPath || registerPath) && (_jsxs("div", { className: "flex items-center justify-between text-sm", children: [resetPath && (_jsx("a", { href: resetPath, className: "text-primary hover:underline", children: "\u5FD8\u8BB0\u5BC6\u7801\uFF1F" })), registerPath && (_jsx("a", { href: registerPath, "data-testid": "register-link", className: "text-primary hover:underline", children: "\u521B\u5EFA\u8D26\u53F7" }))] }))] }) }));
|
|
86
|
+
: '发送' })] })] }), sendError && _jsx("p", { role: "alert", className: "text-destructive text-sm", children: sendError }), codeError && _jsx("p", { role: "alert", className: "text-destructive text-sm", children: codeError }), _jsx("button", { type: "submit", disabled: loading || !email || !code, className: "w-full py-2 px-4 bg-primary text-primary-foreground rounded-md hover:bg-primary/80 disabled:opacity-50", children: loading ? '登录中…' : '登录' })] }) }), _jsx(TabsContent, { value: "password", children: _jsxs("form", { onSubmit: handlePasswordSubmit, className: "space-y-4 pt-2", children: [_jsx(FormField, { label: "\u90AE\u7BB1", htmlFor: "login-pw-email", children: _jsx(Input, { id: "login-pw-email", type: "email", value: email, required: true, onChange: (e) => setEmail(e.target.value), placeholder: "you@example.com", autoComplete: "email" }) }), _jsx(FormField, { label: "\u5BC6\u7801", htmlFor: "login-pw-password", children: _jsx(Input, { id: "login-pw-password", type: "password", value: password, required: true, onChange: (e) => setPassword(e.target.value), placeholder: "\u8F93\u5165\u5BC6\u7801", autoComplete: "current-password" }) }), pwError && _jsx("p", { role: "alert", className: "text-destructive text-sm", children: pwError }), _jsx(Button, { type: "submit", className: "w-full", disabled: pwLoading || !email || !password, children: pwLoading ? '登录中…' : '登录' })] }) })] })), oauthProviders.length > 0 && (_jsxs("div", { className: "space-y-2 pt-1", "data-testid": "oauth-providers", children: [_jsxs("div", { className: "relative py-2 text-center", children: [_jsx("span", { className: "absolute inset-x-0 top-1/2 border-t border-border" }), _jsx("span", { className: "relative z-10 bg-card px-2 text-xs text-muted-foreground", children: "\u6216\u4F7F\u7528\u4EE5\u4E0B\u65B9\u5F0F\u767B\u5F55" })] }), oauthProviders.map((p) => (_jsxs("a", { href: '/auth/oauth/' + p.id + '/start', className: "block w-full py-2 px-4 text-center text-sm border border-input rounded-md hover:bg-background", children: ["\u4F7F\u7528 ", p.label, " \u767B\u5F55"] }, p.id)))] })), enableFedLogin && (_jsxs("details", { className: "pt-1", "data-testid": "fed-login", children: [_jsx("summary", { className: "text-sm text-muted-foreground cursor-pointer select-none", children: "\u4F01\u4E1A\u767B\u5F55" }), _jsxs("form", { method: "get", action: "/auth/fed/start", className: "mt-2 space-y-2", children: [_jsx("input", { type: "text", name: "workspace", placeholder: "\u5DE5\u4F5C\u533A\u6807\u8BC6\uFF08slug\uFF09", required: true, className: "w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-ring" }), _jsx("button", { type: "submit", className: "w-full py-2 px-4 bg-primary text-primary-foreground text-sm rounded-md hover:bg-primary/80", children: "\u901A\u8FC7\u4F01\u4E1A IdP \u767B\u5F55" })] })] })), (resetPath || registerPath) && (_jsxs("div", { className: "flex items-center justify-between text-sm", children: [resetPath && (_jsx("a", { href: resetPath, className: "text-primary hover:underline", children: "\u5FD8\u8BB0\u5BC6\u7801\uFF1F" })), registerPath && (_jsx("a", { href: registerPath, "data-testid": "register-link", className: "text-primary hover:underline", children: "\u521B\u5EFA\u8D26\u53F7" }))] }))] }) }));
|
|
87
87
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ploykit/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@base-ui/react": "^1.8.0",
|
|
32
|
-
"@ploykit/client": "^0.
|
|
33
|
-
"@ploykit/hooks": "^0.
|
|
32
|
+
"@ploykit/client": "^0.6.0",
|
|
33
|
+
"@ploykit/hooks": "^0.6.0",
|
|
34
34
|
"class-variance-authority": "^0.7.1",
|
|
35
35
|
"clsx": "^2.1.1",
|
|
36
36
|
"cn": "^0.4.0",
|