登录是每个产品都有的页面。这个区块是一张卡片,包含标题、快捷登录方式、分隔线、表单字段和切换到另一张卡片的入口。这张面板本身也是一个表单,内容自动纵向排列,字段间距一致。
登录
<form class="sheet form w-full max-w(380) p-xl"> <header class="flex flex-col items-center gap-xs text-center"> <span class="fg-text-strong"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="8" cy="8" r="6" /><path d="M8 4.3333A3.6667 3.6667 0 0 1 8 11.6667Z" fill="currentColor" stroke="none" /> </svg> </span> <h1 class="heading heading-lg">Sign in to Atlas</h1> <p class="m(0) fg-text-muted">Welcome back. Pick up where you left off.</p> </header> <div class="flex flex-col gap-xs"> <button type="button" class="btn"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="4" cy="3.6667" r="1.6667" /><circle cx="4" cy="12.3333" r="1.6667" /><circle cx="12" cy="3.6667" r="1.6667" /><path d="M4 5.3333L4 10.6667" /><path d="M12 5.3333C12 9.6667 4 7.3333 4 10.6667" /> </svg>Continue with GitHub </button> <button type="button" class="btn"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="10.6667" cy="5" r="3" /><path d="M8.5467 7.12L2.3333 13.3333" /><path d="M4 11.6667L5.3333 13" /><path d="M6 9.6667L7.3333 11" /> </svg>Continue with a passkey </button> </div> <div class="divider divider-label" role="separator">or</div> <label class="field"> Email<input class="input" type="email" name="email" autocomplete="username" placeholder="you@example.com" required> </label> <div class="field"> <div class="flex items-baseline justify-between gap-sm"> <label for="signin-password">Password</label> <a class="link link-quiet text-xs fg-text-muted" href="#">Forgot it?</a> </div> <input class="input" id="signin-password" type="password" name="password" autocomplete="current-password" required> </div> <label class="check"> <input type="checkbox" class="checkbox" name="remember" checked> Keep me signed in on this device </label> <button class="btn btn-primary">Sign in</button> <p class="m(0) text-center fg-text-muted"> New here? <a class="link" href="#">Create an account</a> </p></form>import ContrastIcon from '@master/icons-react/native/16/soft/contrast'import GitBranchIcon from '@master/icons-react/native/16/soft/git-branch'import KeyIcon from '@master/icons-react/native/16/soft/key'<form className="sheet form w-full max-w(380) p-xl"> <header className="flex flex-col items-center gap-xs text-center"> <span className="fg-text-strong"><ContrastIcon className="icon" /></span> <h1 className="heading heading-lg">Sign in to Atlas</h1> <p className="m(0) fg-text-muted">Welcome back. Pick up where you left off.</p> </header> <div className="flex flex-col gap-xs"> <button type="button" className="btn"> <GitBranchIcon className="icon" />Continue with GitHub </button> <button type="button" className="btn"> <KeyIcon className="icon" />Continue with a passkey </button> </div> <div className="divider divider-label" role="separator">or</div> <label className="field"> Email<input className="input" type="email" name="email" autoComplete="username" placeholder="you@example.com" required /> </label> <div className="field"> <div className="flex items-baseline justify-between gap-sm"> <label htmlFor="signin-password">Password</label> <a className="link link-quiet text-xs fg-text-muted" href="#">Forgot it?</a> </div> <input className="input" id="signin-password" type="password" name="password" autoComplete="current-password" required /> </div> <label className="check"> <input type="checkbox" className="checkbox" name="remember" defaultChecked /> Keep me signed in on this device </label> <button className="btn btn-primary">Sign in</button> <p className="m(0) text-center fg-text-muted"> New here? <a className="link" href="#">Create an account</a> </p></form><script> import ContrastIcon from '@master/icons-svelte/native/16/soft/contrast' import GitBranchIcon from '@master/icons-svelte/native/16/soft/git-branch' import KeyIcon from '@master/icons-svelte/native/16/soft/key'</script><form class="sheet form w-full max-w(380) p-xl"> <header class="flex flex-col items-center gap-xs text-center"> <span class="fg-text-strong"><ContrastIcon class="icon" /></span> <h1 class="heading heading-lg">Sign in to Atlas</h1> <p class="m(0) fg-text-muted">Welcome back. Pick up where you left off.</p> </header> <div class="flex flex-col gap-xs"> <button type="button" class="btn"><GitBranchIcon class="icon" />Continue with GitHub</button> <button type="button" class="btn"><KeyIcon class="icon" />Continue with a passkey</button> </div> <div class="divider divider-label" role="separator">or</div> <label class="field"> Email<input class="input" type="email" name="email" autocomplete="username" placeholder="you@example.com" required> </label> <div class="field"> <div class="flex items-baseline justify-between gap-sm"> <label for="signin-password">Password</label> <a class="link link-quiet text-xs fg-text-muted" href="#">Forgot it?</a> </div> <input class="input" id="signin-password" type="password" name="password" autocomplete="current-password" required> </div> <label class="check"> <input type="checkbox" class="checkbox" name="remember" checked> Keep me signed in on this device </label> <button class="btn btn-primary">Sign in</button> <p class="m(0) text-center fg-text-muted"> New here? <a class="link" href="#">Create an account</a> </p></form><script setup>import ContrastIcon from '@master/icons-vue/native/16/soft/contrast'import GitBranchIcon from '@master/icons-vue/native/16/soft/git-branch'import KeyIcon from '@master/icons-vue/native/16/soft/key'</script><template> <form class="sheet form w-full max-w(380) p-xl"> <header class="flex flex-col items-center gap-xs text-center"> <span class="fg-text-strong"><ContrastIcon class="icon" /></span> <h1 class="heading heading-lg">Sign in to Atlas</h1> <p class="m(0) fg-text-muted">Welcome back. Pick up where you left off.</p> </header> <div class="flex flex-col gap-xs"> <button type="button" class="btn"><GitBranchIcon class="icon" />Continue with GitHub</button> <button type="button" class="btn"><KeyIcon class="icon" />Continue with a passkey</button> </div> <div class="divider divider-label" role="separator">or</div> <label class="field"> Email<input class="input" type="email" name="email" autocomplete="username" placeholder="you@example.com" required> </label> <div class="field"> <div class="flex items-baseline justify-between gap-sm"> <label for="signin-password">Password</label> <a class="link link-quiet text-xs fg-text-muted" href="#">Forgot it?</a> </div> <input class="input" id="signin-password" type="password" name="password" autocomplete="current-password" required> </div> <label class="check"> <input type="checkbox" class="checkbox" name="remember" checked> Keep me signed in on this device </label> <button class="btn btn-primary">Sign in</button> <p class="m(0) text-center fg-text-muted"> New here? <a class="link" href="#">Create an account</a> </p> </form></template>区块提供可直接复制的标记,沿用页面的文字颜色和字号。预览在 body 上设置 fg-text-body text-sm。每个区块都是尺寸容器,无论放在宽页面、只有侧边栏那么宽的区域,还是对话框中,都会按自身宽度重排。使用居中布局将卡片放在页面中央。
#卡片组成
sheet form w-full max-w(380) p-xl。 卡片在手机上占满可用宽度,最大宽度为 380px。form设置卡片内各项之间的间距。- 快捷登录方式放在前面。 通过身份提供商登录和使用通行密钥登录都只需点击一次,密码作为回退方案。用标有“或”的分隔线将两类方式分开。
- 将“忘记密码?”放在标签旁,避免放在字段下方。它是一个
link-quiet,以弱化的前景色显示在标签行末尾,既容易找到,也不会分散用户对主按钮的注意力。字段移出标签后,用for将标签关联到对应字段。 - 只放一个主按钮,作为最后一个控件,宽度与字段一致。
- 切换到另一张卡片的入口放在按钮下方,一行文字,一个链接。
字段的 autocomplete 值分别为 username 和 current-password,以便密码管理器自动填充。
#注册
注册沿用同一张卡片,并增加了几个字段。用 grid grid-cols(2) gap-sm 将姓氏和名字排在同一行,两个短字段合起来填写一个姓名。form-row 在这里不会分栏,因为表单宽度达到 28rem 才会分栏,而这张卡片只有 22rem。用 field-hint 显示密码规则,通过 aria-describedby 将它关联到输入框,让用户在输错前就能看到要求。
注册
<form class="sheet form w-full max-w(420) p-xl"> <header class="flex flex-col gap-xs"> <h1 class="heading heading-lg">Create your account</h1> <p class="m(0) fg-text-muted">Free for personal projects. No card needed.</p> </header> <div class="grid grid-cols(2) gap-sm"> <label class="field"> First name<input class="input" name="given-name" autocomplete="given-name" required> </label> <label class="field"> Last name<input class="input" name="family-name" autocomplete="family-name" required> </label> </div> <label class="field"> Work email<input class="input" type="email" name="email" autocomplete="email" placeholder="you@company.com" required> </label> <div class="field"> <label for="signup-password">Password</label> <input class="input" id="signup-password" type="password" name="password" autocomplete="new-password" minlength="12" required aria-describedby="signup-hint"> <span class="field-hint" id="signup-hint">At least 12 characters. A sentence works well.</span> </div> <label class="check"> <input type="checkbox" class="checkbox" name="terms" required><span> I agree to the <a class="link" href="#">terms</a> and the <a class="link" href="#">privacy policy</a> </span> </label> <button class="btn btn-primary">Create account</button> <p class="m(0) text-center fg-text-muted"> Already have one? <a class="link" href="#">Sign in</a> </p></form><form className="sheet form w-full max-w(420) p-xl"> <header className="flex flex-col gap-xs"> <h1 className="heading heading-lg">Create your account</h1> <p className="m(0) fg-text-muted">Free for personal projects. No card needed.</p> </header> <div className="grid grid-cols(2) gap-sm"> <label className="field"> First name<input className="input" name="given-name" autoComplete="given-name" required /> </label> <label className="field"> Last name<input className="input" name="family-name" autoComplete="family-name" required /> </label> </div> <label className="field"> Work email<input className="input" type="email" name="email" autoComplete="email" placeholder="you@company.com" required /> </label> <div className="field"> <label htmlFor="signup-password">Password</label> <input className="input" id="signup-password" type="password" name="password" autoComplete="new-password" minLength={12} required aria-describedby="signup-hint" /> <span className="field-hint" id="signup-hint"> At least 12 characters. A sentence works well. </span> </div> <label className="check"> <input type="checkbox" className="checkbox" name="terms" required /><span> I agree to the <a className="link" href="#">terms</a> and the <a className="link" href="#">privacy policy</a> </span> </label> <button className="btn btn-primary">Create account</button> <p className="m(0) text-center fg-text-muted"> Already have one? <a className="link" href="#">Sign in</a> </p></form><form class="sheet form w-full max-w(420) p-xl"> <header class="flex flex-col gap-xs"> <h1 class="heading heading-lg">Create your account</h1> <p class="m(0) fg-text-muted">Free for personal projects. No card needed.</p> </header> <div class="grid grid-cols(2) gap-sm"> <label class="field"> First name<input class="input" name="given-name" autocomplete="given-name" required> </label> <label class="field"> Last name<input class="input" name="family-name" autocomplete="family-name" required> </label> </div> <label class="field"> Work email<input class="input" type="email" name="email" autocomplete="email" placeholder="you@company.com" required> </label> <div class="field"> <label for="signup-password">Password</label> <input class="input" id="signup-password" type="password" name="password" autocomplete="new-password" minlength="12" required aria-describedby="signup-hint"> <span class="field-hint" id="signup-hint">At least 12 characters. A sentence works well.</span> </div> <label class="check"> <input type="checkbox" class="checkbox" name="terms" required><span> I agree to the <a class="link" href="#">terms</a> and the <a class="link" href="#">privacy policy</a> </span> </label> <button class="btn btn-primary">Create account</button> <p class="m(0) text-center fg-text-muted"> Already have one? <a class="link" href="#">Sign in</a> </p></form><template> <form class="sheet form w-full max-w(420) p-xl"> <header class="flex flex-col gap-xs"> <h1 class="heading heading-lg">Create your account</h1> <p class="m(0) fg-text-muted">Free for personal projects. No card needed.</p> </header> <div class="grid grid-cols(2) gap-sm"> <label class="field"> First name<input class="input" name="given-name" autocomplete="given-name" required> </label> <label class="field"> Last name<input class="input" name="family-name" autocomplete="family-name" required> </label> </div> <label class="field"> Work email<input class="input" type="email" name="email" autocomplete="email" placeholder="you@company.com" required> </label> <div class="field"> <label for="signup-password">Password</label> <input class="input" id="signup-password" type="password" name="password" autocomplete="new-password" minlength="12" required aria-describedby="signup-hint"> <span class="field-hint" id="signup-hint"> At least 12 characters. A sentence works well. </span> </div> <label class="check"> <input type="checkbox" class="checkbox" name="terms" required><span> I agree to the <a class="link" href="#">terms</a> and the <a class="link" href="#">privacy policy</a> </span> </label> <button class="btn btn-primary">Create account</button> <p class="m(0) text-center fg-text-muted"> Already have one? <a class="link" href="#">Sign in</a> </p> </form></template>只收集首屏所需的信息。每多一个字段,就会有一些已经开始填写的用户放弃。
#验证
验证码发出后,用户只需输入验证码。将验证码输入框放在中间,用页面前景色显示接收验证码的地址,再提供一个低调的重发入口。
验证
<form class="sheet form w-full max-w(380) p-xl"> <header class="flex flex-col items-center gap-xs text-center"> <span class="icon-frame" aria-hidden="true"> <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <rect x="2.5" y="5" width="15" height="10" rx="1.25" /><path d="M3 6.5L9.8918 10.9305A0.2 0.2 0 0 0 10.1082 10.9305L17 6.5" /> </svg> </span> <h1 class="heading heading-lg mt-xs">Check your email</h1> <p class="m(0) fg-text-muted"> We sent a six-digit code to <span class="fg-text-strong">yiching@atlaslabs.dev</span>. It works for ten minutes. </p> </header> <fieldset class="otp mx-auto" aria-label="Verification code"> <input class="otp-slot" inputmode="numeric" pattern="[0-9]" maxlength="1" autocomplete="one-time-code" aria-label="Digit 1" value="4"> <input class="otp-slot" inputmode="numeric" pattern="[0-9]" maxlength="1" aria-label="Digit 2" value="2"> <input class="otp-slot" inputmode="numeric" pattern="[0-9]" maxlength="1" aria-label="Digit 3"> <span class="otp-separator" aria-hidden="true"></span> <input class="otp-slot" inputmode="numeric" pattern="[0-9]" maxlength="1" aria-label="Digit 4"> <input class="otp-slot" inputmode="numeric" pattern="[0-9]" maxlength="1" aria-label="Digit 5"> <input class="otp-slot" inputmode="numeric" pattern="[0-9]" maxlength="1" aria-label="Digit 6"> </fieldset> <button class="btn btn-primary">Verify</button> <p class="m(0) text-center fg-text-muted"> Nothing arrived? <button type="button" class="link">Send it again</button> </p></form><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'import MailIcon from '@master/icons-react/native/20/soft/mail'export function Example() { const root = useRef<HTMLFormElement>(null) useEffect(() => attach(root.current!), []) return ( <form ref={root} className="sheet form w-full max-w(380) p-xl"> <header className="flex flex-col items-center gap-xs text-center"> <span className="icon-frame" aria-hidden="true"><MailIcon className="icon" /></span> <h1 className="heading heading-lg mt-xs">Check your email</h1> <p className="m(0) fg-text-muted"> We sent a six-digit code to <span className="fg-text-strong">yiching@atlaslabs.dev</span>. It works for ten minutes. </p> </header> <fieldset className="otp mx-auto" aria-label="Verification code"> <input className="otp-slot" inputMode="numeric" pattern="[0-9]" maxLength={1} autoComplete="one-time-code" aria-label="Digit 1" defaultValue="4" /> <input className="otp-slot" inputMode="numeric" pattern="[0-9]" maxLength={1} aria-label="Digit 2" defaultValue="2" /> <input className="otp-slot" inputMode="numeric" pattern="[0-9]" maxLength={1} aria-label="Digit 3" /> <span className="otp-separator" aria-hidden="true"></span> <input className="otp-slot" inputMode="numeric" pattern="[0-9]" maxLength={1} aria-label="Digit 4" /> <input className="otp-slot" inputMode="numeric" pattern="[0-9]" maxLength={1} aria-label="Digit 5" /> <input className="otp-slot" inputMode="numeric" pattern="[0-9]" maxLength={1} aria-label="Digit 6" /> </fieldset> <button className="btn btn-primary">Verify</button> <p className="m(0) text-center fg-text-muted"> Nothing arrived? <button type="button" className="link">Send it again</button> </p> </form> )}<script> import { attach } from '@master/ui/behaviors' import MailIcon from '@master/icons-svelte/native/20/soft/mail'</script><form class="sheet form w-full max-w(380) p-xl" {@attach attach}> <header class="flex flex-col items-center gap-xs text-center"> <span class="icon-frame" aria-hidden="true"><MailIcon class="icon" /></span> <h1 class="heading heading-lg mt-xs">Check your email</h1> <p class="m(0) fg-text-muted"> We sent a six-digit code to <span class="fg-text-strong">yiching@atlaslabs.dev</span>. It works for ten minutes. </p> </header> <fieldset class="otp mx-auto" aria-label="Verification code"> <input class="otp-slot" inputmode="numeric" pattern="[0-9]" maxlength="1" autocomplete="one-time-code" aria-label="Digit 1" value="4"> <input class="otp-slot" inputmode="numeric" pattern="[0-9]" maxlength="1" aria-label="Digit 2" value="2"> <input class="otp-slot" inputmode="numeric" pattern="[0-9]" maxlength="1" aria-label="Digit 3"> <span class="otp-separator" aria-hidden="true"></span> <input class="otp-slot" inputmode="numeric" pattern="[0-9]" maxlength="1" aria-label="Digit 4"> <input class="otp-slot" inputmode="numeric" pattern="[0-9]" maxlength="1" aria-label="Digit 5"> <input class="otp-slot" inputmode="numeric" pattern="[0-9]" maxlength="1" aria-label="Digit 6"> </fieldset> <button class="btn btn-primary">Verify</button> <p class="m(0) text-center fg-text-muted"> Nothing arrived? <button type="button" class="link">Send it again</button> </p></form><script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'import MailIcon from '@master/icons-vue/native/20/soft/mail'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template> <form ref="root" class="sheet form w-full max-w(380) p-xl"> <header class="flex flex-col items-center gap-xs text-center"> <span class="icon-frame" aria-hidden="true"><MailIcon class="icon" /></span> <h1 class="heading heading-lg mt-xs">Check your email</h1> <p class="m(0) fg-text-muted"> We sent a six-digit code to <span class="fg-text-strong">yiching@atlaslabs.dev</span>. It works for ten minutes. </p> </header> <fieldset class="otp mx-auto" aria-label="Verification code"> <input class="otp-slot" inputmode="numeric" pattern="[0-9]" maxlength="1" autocomplete="one-time-code" aria-label="Digit 1" value="4"> <input class="otp-slot" inputmode="numeric" pattern="[0-9]" maxlength="1" aria-label="Digit 2" value="2"> <input class="otp-slot" inputmode="numeric" pattern="[0-9]" maxlength="1" aria-label="Digit 3"> <span class="otp-separator" aria-hidden="true"></span> <input class="otp-slot" inputmode="numeric" pattern="[0-9]" maxlength="1" aria-label="Digit 4"> <input class="otp-slot" inputmode="numeric" pattern="[0-9]" maxlength="1" aria-label="Digit 5"> <input class="otp-slot" inputmode="numeric" pattern="[0-9]" maxlength="1" aria-label="Digit 6"> </fieldset> <button class="btn btn-primary">Verify</button> <p class="m(0) text-center fg-text-muted"> Nothing arrived? <button type="button" class="link">Send it again</button> </p> </form></template>otp 行为会把焦点移到下一格,并将粘贴的验证码逐位填入各格。没有脚本时,每格仍是一个可输入一位数字的字段。“重新发送”是一个采用链接样式的 <button>,在当前页面触发重发,无需跳转。
#无障碍
- 卡片标题就是页面的
<h1>。 - 每个字段都要有可见标签。占位符用于提供示例,不能充当字段名称。
- 在对应字段旁显示错误提示。添加
field-error后,字段无效时就会显示提示。参见输入框。 - 表单尚未通过验证时,保持提交按钮可用。用户提交后,表单可以提示缺少哪些信息,禁用的按钮无法提供这种反馈。
- 对于较长的密码,可以在输入框组内放一个低调的“显示密码”按钮,用于切换字段的
type。