網站導覽

v2.1.0
應用程式區塊

登入

提供第三方登入、表單欄位與切換連結的登入及註冊卡片。

登入是每個產品都有的畫面。這個區塊提供一張卡片,依序放入標題、快速登入方式、分隔線、欄位,以及前往另一張卡片的連結。卡片同時是面板和表單,欄位會自動排成直欄並維持一致間距。

登入

<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。