聯絡區塊是訪客寫信給公司的地方:在面板上放幾個欄位,由表單排版,旁邊則列出不填表單也能聯絡團隊的方式。它所承諾的事和欄位一樣是區塊的一部分:誰會讀這則訊息,以及多久之內回覆。
聯絡我們
<section class="container-inline px-lg py-4xl" data-example="contact" aria-labelledby="contact-title"> <div class="grid gap-2xl items-start max-w(960) mx-auto grid-cols(2)@container(--4xl)"> <div class="flex flex-col gap-xl"> <header class="flex flex-col gap-sm"> <p class="eyebrow">Contact</p> <h2 class="heading heading-2xl" id="contact-title">Talk to the people who run Atlas.</h2> <p class="lead">Tell us what you are deploying. Someone on the team reads every message and answers within one business day.</p> </header> <dl class="data-list"> <div class="data-list-item"> <dt class="data-list-term">Email</dt> <dd class="data-list-value"> <a class="link" href="mailto:hello@atlas.dev">hello@atlas.dev</a> </dd> </div> <div class="data-list-item"> <dt class="data-list-term">Hours</dt> <dd class="data-list-value">Monday to Friday, 09:00 to 18:00 (UTC+8)</dd> </div> <div class="data-list-item"> <dt class="data-list-term">Outages</dt> <dd class="data-list-value"> <a class="link" href="#contact-title">status.atlas.dev</a>, updated within minutes</dd> </div> </dl> </div> <div class="sheet p-xl"> <div data-contact-ask> <form class="form"> <div class="form-row"> <div class="field"> <label for="contact-name">Name</label> <input class="input" id="contact-name" name="name" autocomplete="name" required data-error="contact-name-error"> <span class="field-error" id="contact-name-error">Enter your name.</span> </div> <div class="field"> <label for="contact-email">Email</label> <input class="input" id="contact-email" type="email" name="email" autocomplete="email" placeholder="you@company.com" required data-error="contact-email-error"> <span class="field-error" id="contact-email-error">Enter an email address, such as you@company.com.</span> </div> </div> <div class="field"> <label for="contact-topic">Topic</label> <select class="select" id="contact-topic" name="topic"> <option class="select-option" value="General question">General question</option> <option class="select-option" value="Sales">Sales</option> <option class="select-option" value="Support">Support</option> </select> </div> <div class="field"> <label for="contact-message">Message</label> <textarea class="input input-auto" id="contact-message" name="message" required aria-describedby="contact-message-hint" data-error="contact-message-error"></textarea> <span class="field-hint" id="contact-message-hint">What you are deploying, and where it is stuck.</span> <span class="field-error" id="contact-message-error">Write a message, even a short one.</span> </div> <noscript> <p class="m(0) fg-text-muted">This form needs JavaScript to send. Write to <a class="link" href="mailto:hello@atlas.dev">hello@atlas.dev</a>instead.</p> </noscript> <div class="form-actions"> <button class="btn btn-primary" disabled>Send message</button> </div> </form> </div> <div data-contact-result hidden> <div class="flex flex-col gap-lg"> <div class="alert alert-success"> <svg class="icon alert-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="M5 8L7.1041 9.8703A0.2 0.2 0 0 0 7.3832 9.8573L10.75 6.25" /> </svg> <div class="alert-body"> <h3 class="alert-title" tabindex="-1" data-contact-result-title>Message sent</h3> <p class="alert-description">Thanks, <span data-contact-value="name"></span>. We reply to <span data-contact-value="email"></span>within one business day.</p> </div> </div> <dl class="data-list"> <div class="data-list-item"> <dt class="data-list-term">Topic</dt> <dd class="data-list-value" data-contact-value="topic"></dd> </div> <div class="data-list-item"> <dt class="data-list-term">Message</dt> <dd class="data-list-value whitespace-pre-line" data-contact-value="message"></dd> </div> </dl> <div class="flex"> <button type="button" class="btn" data-contact-edit>Edit message</button> </div> </div> </div> </div> </div></section>/** * A contact form with nowhere to send to. The browser checks the fields: `required` and `type="email"` are the * rules, and the stylesheet shows a field's error once the reader has tried. This module turns the button on, * names each error from its field while it shows, and on a valid submit swaps the form for what was written, * with a way back to change it. Nothing leaves the page: sending is the application's. * Returns the function that stops it and puts the form back. */export function mount(root) { const controller = new AbortController() const { signal } = controller const ask = root.querySelector('[data-contact-ask]') const form = ask.querySelector('.form') const send = form.querySelector('.form-actions .btn') const result = root.querySelector('[data-contact-result]') const title = result.querySelector('[data-contact-result-title]') /** * A field's error is read with the field only while it shows: its id joins aria-describedby, after the hint, * when the browser reports the field, and leaves when the value is valid again. */ const describe = (control, invalid) => { const ids = (control.getAttribute('aria-describedby') ?? '').split(' ').filter(id => id && id !== control.dataset.error) if (invalid) ids.push(control.dataset.error) if (ids.length) control.setAttribute('aria-describedby', ids.join(' ')) else control.removeAttribute('aria-describedby') } for (const control of form.querySelectorAll('[data-error]')) { control.addEventListener('invalid', () => describe(control, true), { signal }) for (const type of ['input', 'change', 'blur']) { control.addEventListener(type, () => describe(control, !control.validity.valid && control.matches(':user-invalid')), { signal }) } } /** `required` is satisfied by a space: a name or a message of spaces alone is refused in the browser's own words. */ for (const control of [form.elements.name, form.elements.message]) { control.addEventListener('input', () => control.setCustomValidity(control.value && !control.value.trim() ? 'Fill in this field.' : ''), { signal }) } const show = (sent) => { ask.hidden = sent result.hidden = !sent } // A submit event means every constraint passed; an invalid form never gets here. form.addEventListener('submit', (event) => { event.preventDefault() const written = new FormData(form) // What was typed is set as text, never as markup. for (const slot of result.querySelectorAll('[data-contact-value]')) slot.textContent = String(written.get(slot.dataset.contactValue)).trim() show(true) title.focus() }, { signal }) result.querySelector('[data-contact-edit]').addEventListener('click', () => { show(false) form.elements.message.focus() }, { signal }) send.disabled = false return () => { controller.abort() send.disabled = true show(false) }}區塊提供可直接複製的標記,沿用頁面的文字顏色和字級。預覽在 body 上設定 fg-text-body text-sm。每個區塊都是尺寸容器,會依自身寬度重新排列。
#組成
- 區塊寬度達 56rem 後排成兩欄。
grid-cols(2)@container(--4xl)讓文字與表單並排,items-start讓每一欄的高度只隨自己的內容而定。未達這個寬度時文字排在前面,因為它說明了表單的用途。 - 導言中的承諾。 「within one business day」(一個工作天內)正是訪客在找的那句話。寫下你的團隊做得到的那一句。
- 其他聯絡方式是一個資料清單:電子郵件地址、服務時間,以及服務中斷時在哪裡公告。寧可寫電子郵件也不想填表單的訪客,並沒有因此離開。
- 四個欄位。 姓名、電子郵件、主題和訊息。姓名和電子郵件放在同一個
form-row中,表單寬度達 28rem 後共用一行,未達時上下堆疊。主題是一個下拉選單,第一個選項適用於大多數訊息,因此從來不必動手選。 - 每個欄位都是一個
field,裡面放<label for>和它的控制項,提示和錯誤訊息接在後面。提示以aria-describedby連到欄位;field-error只在所屬欄位無效時顯示。 - 一個按鈕,放在最後,位於
form-actions中。它在標記中是disabled,由腳本啟用,因此背後沒有伺服器的表單不會被送到它所在的頁面。 - 結果取代表單的位置:一則說明接下來會發生什麼事的提示訊息、以第二個資料清單列出的填寫內容,以及一個回去修改的按鈕。
#哪些功能需要腳本
驗證規則由瀏覽器負責:三個欄位設有 required,一個欄位設有 type="email"。樣式表依 :user-invalid 將欄位畫成無效狀態,而它只在讀者編輯過欄位或嘗試送出之後才會符合,因此頁面載入時不會有任何欄位變紅,值一旦有效,錯誤訊息也隨即消失。
main.js 做四件事。它啟用按鈕。錯誤訊息顯示時,它把該欄位的錯誤訊息加入 aria-describedby,之後再移除,因此訊息會隨欄位一起讀出,而不會提前讀出。表單有效並送出時,它把各欄位的值以純文字寫進結果、顯示結果,並將焦點移到結果的標題。「Edit message」(編輯訊息)會把表單原樣帶回來,焦點落在訊息欄位。
它不會送出任何內容。在應用程式中,submit 處理常式會提交表單,並在伺服器回應時顯示結果;伺服器沒有回應時,則顯示帶有 role="alert" 的 alert alert-danger。沒有腳本時,欄位、標籤和提示都還在,按鈕維持停用,並由一行 <noscript> 提供可寫信的地址。
#聯絡管道
當頁面用不到一份表單時,就列出電子郵件地址。資料清單的每一列是一個團隊:它的地址、適合寫信給它的事項,以及多快回覆。清單下方的中性提示訊息會把服務中斷的問題引導到狀態頁面,那比任何信箱都快。
聯絡管道
<section class="container-inline px-lg py-4xl" aria-labelledby="contact-channels-title"> <div class="flex flex-col gap-xl max-w(720) mx-auto"> <header class="flex flex-col gap-sm"> <p class="eyebrow">Contact</p> <h2 class="heading heading-2xl" id="contact-channels-title"> Write to the team that can help. </h2> <p class="lead max-w(560)"> Every address is read by the people who do that work, Monday to Friday, 09:00 to 18:00 (UTC+8). </p> </header> <div class="sheet px-lg py-xs"> <dl class="data-list"> <div class="data-list-item"> <dt class="data-list-term">Sales</dt> <dd class="data-list-value"> <a class="link" href="mailto:sales@atlas.dev">sales@atlas.dev</a><span class="block font-regular fg-text-muted"> Plans, seats and invoices. Answered within one business day. </span> </dd> </div> <div class="data-list-item"> <dt class="data-list-term">Support</dt> <dd class="data-list-value"> <a class="link" href="mailto:support@atlas.dev">support@atlas.dev</a><span class="block font-regular fg-text-muted"> A build, a domain or a deployment that misbehaves. Pro workspaces hear back by the next day. </span> </dd> </div> <div class="data-list-item"> <dt class="data-list-term">Security</dt> <dd class="data-list-value"> <a class="link" href="mailto:security@atlas.dev">security@atlas.dev</a><span class="block font-regular fg-text-muted"> Report a vulnerability. Acknowledged within 24 hours, every day of the week. </span> </dd> </div> <div class="data-list-item"> <dt class="data-list-term">Press</dt> <dd class="data-list-value"> <a class="link" href="mailto:press@atlas.dev">press@atlas.dev</a><span class="block font-regular fg-text-muted"> Interviews, logos and facts about the company. </span> </dd> </div> </dl> </div> <div class="alert"> <svg class="icon alert-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" /><circle cx="8" cy="5" r="0.5" fill="currentColor" stroke="none" /><path d="M8 8L8 11" /> </svg> <div class="alert-body"> <p class="alert-title">Is something down?</p> <p class="alert-description"> Incidents are posted on the status page within minutes, before anyone reads an inbox. </p> </div> <a class="btn btn-sm" href="#contact-channels-title">Open status</a> </div> </div></section>import InfoCircleIcon from '@master/icons-react/native/16/soft/info-circle'<section className="container-inline px-lg py-4xl" aria-labelledby="contact-channels-title"> <div className="flex flex-col gap-xl max-w(720) mx-auto"> <header className="flex flex-col gap-sm"> <p className="eyebrow">Contact</p> <h2 className="heading heading-2xl" id="contact-channels-title"> Write to the team that can help. </h2> <p className="lead max-w(560)"> Every address is read by the people who do that work, Monday to Friday, 09:00 to 18:00 (UTC+8). </p> </header> <div className="sheet px-lg py-xs"> <dl className="data-list"> <div className="data-list-item"> <dt className="data-list-term">Sales</dt> <dd className="data-list-value"> <a className="link" href="mailto:sales@atlas.dev">sales@atlas.dev</a><span className="block font-regular fg-text-muted"> Plans, seats and invoices. Answered within one business day. </span> </dd> </div> <div className="data-list-item"> <dt className="data-list-term">Support</dt> <dd className="data-list-value"> <a className="link" href="mailto:support@atlas.dev">support@atlas.dev</a><span className="block font-regular fg-text-muted"> A build, a domain or a deployment that misbehaves. Pro workspaces hear back by the next day. </span> </dd> </div> <div className="data-list-item"> <dt className="data-list-term">Security</dt> <dd className="data-list-value"> <a className="link" href="mailto:security@atlas.dev">security@atlas.dev</a><span className="block font-regular fg-text-muted"> Report a vulnerability. Acknowledged within 24 hours, every day of the week. </span> </dd> </div> <div className="data-list-item"> <dt className="data-list-term">Press</dt> <dd className="data-list-value"> <a className="link" href="mailto:press@atlas.dev">press@atlas.dev</a><span className="block font-regular fg-text-muted"> Interviews, logos and facts about the company. </span> </dd> </div> </dl> </div> <div className="alert"> <InfoCircleIcon className="icon alert-icon" /> <div className="alert-body"> <p className="alert-title">Is something down?</p> <p className="alert-description"> Incidents are posted on the status page within minutes, before anyone reads an inbox. </p> </div> <a className="btn btn-sm" href="#contact-channels-title">Open status</a> </div> </div></section><script> import InfoCircleIcon from '@master/icons-svelte/native/16/soft/info-circle'</script><section class="container-inline px-lg py-4xl" aria-labelledby="contact-channels-title"> <div class="flex flex-col gap-xl max-w(720) mx-auto"> <header class="flex flex-col gap-sm"> <p class="eyebrow">Contact</p> <h2 class="heading heading-2xl" id="contact-channels-title"> Write to the team that can help. </h2> <p class="lead max-w(560)"> Every address is read by the people who do that work, Monday to Friday, 09:00 to 18:00 (UTC+8). </p> </header> <div class="sheet px-lg py-xs"> <dl class="data-list"> <div class="data-list-item"> <dt class="data-list-term">Sales</dt> <dd class="data-list-value"> <a class="link" href="mailto:sales@atlas.dev">sales@atlas.dev</a><span class="block font-regular fg-text-muted"> Plans, seats and invoices. Answered within one business day. </span> </dd> </div> <div class="data-list-item"> <dt class="data-list-term">Support</dt> <dd class="data-list-value"> <a class="link" href="mailto:support@atlas.dev">support@atlas.dev</a><span class="block font-regular fg-text-muted"> A build, a domain or a deployment that misbehaves. Pro workspaces hear back by the next day. </span> </dd> </div> <div class="data-list-item"> <dt class="data-list-term">Security</dt> <dd class="data-list-value"> <a class="link" href="mailto:security@atlas.dev">security@atlas.dev</a><span class="block font-regular fg-text-muted"> Report a vulnerability. Acknowledged within 24 hours, every day of the week. </span> </dd> </div> <div class="data-list-item"> <dt class="data-list-term">Press</dt> <dd class="data-list-value"> <a class="link" href="mailto:press@atlas.dev">press@atlas.dev</a><span class="block font-regular fg-text-muted"> Interviews, logos and facts about the company. </span> </dd> </div> </dl> </div> <div class="alert"> <InfoCircleIcon class="icon alert-icon" /> <div class="alert-body"> <p class="alert-title">Is something down?</p> <p class="alert-description"> Incidents are posted on the status page within minutes, before anyone reads an inbox. </p> </div> <a class="btn btn-sm" href="#contact-channels-title">Open status</a> </div> </div></section><script setup>import InfoCircleIcon from '@master/icons-vue/native/16/soft/info-circle'</script><template> <section class="container-inline px-lg py-4xl" aria-labelledby="contact-channels-title"> <div class="flex flex-col gap-xl max-w(720) mx-auto"> <header class="flex flex-col gap-sm"> <p class="eyebrow">Contact</p> <h2 class="heading heading-2xl" id="contact-channels-title"> Write to the team that can help. </h2> <p class="lead max-w(560)"> Every address is read by the people who do that work, Monday to Friday, 09:00 to 18:00 (UTC+8). </p> </header> <div class="sheet px-lg py-xs"> <dl class="data-list"> <div class="data-list-item"> <dt class="data-list-term">Sales</dt> <dd class="data-list-value"> <a class="link" href="mailto:sales@atlas.dev">sales@atlas.dev</a><span class="block font-regular fg-text-muted"> Plans, seats and invoices. Answered within one business day. </span> </dd> </div> <div class="data-list-item"> <dt class="data-list-term">Support</dt> <dd class="data-list-value"> <a class="link" href="mailto:support@atlas.dev">support@atlas.dev</a><span class="block font-regular fg-text-muted"> A build, a domain or a deployment that misbehaves. Pro workspaces hear back by the next day. </span> </dd> </div> <div class="data-list-item"> <dt class="data-list-term">Security</dt> <dd class="data-list-value"> <a class="link" href="mailto:security@atlas.dev">security@atlas.dev</a><span class="block font-regular fg-text-muted"> Report a vulnerability. Acknowledged within 24 hours, every day of the week. </span> </dd> </div> <div class="data-list-item"> <dt class="data-list-term">Press</dt> <dd class="data-list-value"> <a class="link" href="mailto:press@atlas.dev">press@atlas.dev</a><span class="block font-regular fg-text-muted"> Interviews, logos and facts about the company. </span> </dd> </div> </dl> </div> <div class="alert"> <InfoCircleIcon class="icon alert-icon" /> <div class="alert-body"> <p class="alert-title">Is something down?</p> <p class="alert-description"> Incidents are posted on the status page within minutes, before anyone reads an inbox. </p> </div> <a class="btn btn-sm" href="#contact-channels-title">Open status</a> </div> </div> </section></template>清單維持一欄閱讀的寬度 max-w(720)。清單寬度不足 20rem 時,各團隊的名稱會移到地址上方,這是資料清單本身的行為。
#無障礙
- 區塊是一個
<section>,以其<h2>命名。結果的標題是帶有tabindex="-1"的<h3>:結果出現時焦點會移到它上面,因此螢幕閱讀器從答覆開始讀,鍵盤操作也從那裡接續。 - 每個欄位都有可見的標籤和
autocomplete值:name和email讓瀏覽器得以自動填入。 - 錯誤訊息是欄位旁的文字,顯示期間會列在該欄位的
aria-describedby中。每一則都說明該怎麼做:「Enter an email address, such as [email protected].」(請輸入電子郵件地址,例如 [email protected]。) - 送出失敗時保留瀏覽器本身的行為:焦點移到第一個有誤的欄位。
- 按鈕只在腳本就緒之前停用,絕不因為表單尚未填完而停用。停用的按鈕無法說明缺了什麼;送出的表單可以。
- 地址是一個
mailto:連結,連結文字就是地址本身,因此可以閱讀、複製,也可以直接點開。