本文へ移動
メニュー
言語、現在は日本語
EnglishGaeilge简体中文Españolहिन्दीPortuguêsবাংলাРусский日本語廣東話Tiếng Việtالعربية

rastrillo デザインシステム

デザインシステムが提供するものの概要。テーマ: signal。言語: 日本語

フォーム

実際のフォームが取らせる状態で、すべてのコントロールを並べています。どれも余白のある rst-box の中に入っています。これらの部品がそう前提しているからです。

あらかじめ作られ、互いに揃った UI 部品を、サーバー側で描画。

フレームワーク自身の語彙では、これらは partial です。ui.Templates() は partial を返し、docs/site/templates.md もその名前で説明しています。このページの言葉は変わりましたが、コードの言葉は変わっていません。

ここのリンクは動きません

リンクは動きません。サンプルのソースは別に用意しています。

下の各サンプルは、それぞれ自分のフレームの中にあります。

サンプルの中身は英語のままです。サンプルのシェルは翻訳されています。

field

ラベル、入力欄、任意のヒント、補足、エラー。ID を明示した、一般的なテキスト系のコントロールです。

素のまま

プレビュー
<section rst-box><form rst-form method="post" action="#"><div rst-field><label rst-field-label for="f_bare">Title</label>
<input rst-input type="text" id="f_bare" name="f_bare">
</div></form></section>

ヒントつき

プレビュー
<section rst-box><form rst-form method="post" action="#"><div rst-field><label rst-field-label for="f_hint">Slug <span rst-field-hint>(lowercase, no spaces)</span></label>
<input rst-input type="text" id="f_hint" name="f_hint">
</div></form></section>

コントロールの下にヘルプつき

プレビュー
<section rst-box><form rst-form method="post" action="#"><div rst-field><label rst-field-label for="f_help">Email</label>
<input rst-input type="email" id="f_help" name="f_help" autocomplete="email" aria-describedby="f_help-help">
<p rst-field-help id="f_help-help">We only use this to send you replies.</p>
</div></form></section>

必須

プレビュー
<section rst-box><form rst-form method="post" action="#"><div rst-field><label rst-field-label for="f_required">Full name</label>
<input rst-input type="text" id="f_required" name="f_required" required>
</div></form></section>

エラーつき

プレビュー
<section rst-box><form rst-form method="post" action="#"><div rst-field><label rst-field-label for="f_error">Email</label>
<input rst-input type="email" id="f_error" name="f_error" value="grace@" aria-invalid="true" aria-describedby="f_error-error">
<p rst-field-error id="f_error-error" role="alert">That does not look like an email address.</p>
</div></form></section>

短い

プレビュー
<section rst-box><form rst-form method="post" action="#"><div rst-field><label rst-field-label for="f_short">Postcode</label>
<input rst-input="short" type="text" id="f_short" name="f_short" value="D02 XY45">
</div></form></section>

見出しの項目

プレビュー
<section rst-box><form rst-form method="post" action="#"><div rst-field><label rst-field-label for="f_primary">Title</label>
<input rst-input="primary" type="text" id="f_primary" name="f_primary" value="Quarterly board meeting">
</div></form></section>

field-text

ラベル付きのテキスト入力がひとつ。id は Name から作られます。必須マークの星は aria-hidden で、プログラムに伝わる合図は入力欄の required 属性です。

素のまま

プレビュー
<section rst-box><form rst-form method="post" action="#"><div rst-field>
  <label rst-field-label for="ft_bare">Title</label>
  <input rst-input id="ft_bare" name="ft_bare" type="text">
</div></form></section>

ヒントつき

プレビュー
<section rst-box><form rst-form method="post" action="#"><div rst-field>
  <label rst-field-label for="ft_hint">Headline</label>
  <input rst-input id="ft_hint" name="ft_hint" type="text" aria-describedby="ft_hint-hint">
  <small rst-field-hint id="ft_hint-hint">Shown in the list.</small>
</div></form></section>

必須

プレビュー
<section rst-box><form rst-form method="post" action="#"><div rst-field>
  <label rst-field-label for="ft_required">Display name <span rst-field-required aria-hidden="true">*</span></label>
  <input rst-input id="ft_required" name="ft_required" type="text" autocomplete="nickname" required>
</div></form></section>

エラーつき

プレビュー
<section rst-box><form rst-form method="post" action="#"><div rst-field>
  <label rst-field-label for="ft_error">Title</label>
  <input rst-input id="ft_error" name="ft_error" type="text" value="Release notes" aria-invalid="true" aria-describedby="ft_error-error">
  <small rst-field-error id="ft_error-error">A post with that title already exists.</small>
</div></form></section>

見出しの項目

プレビュー
<section rst-box><form rst-form method="post" action="#"><div rst-field>
  <label rst-field-label for="ft_primary">What is it?</label>
  <input rst-input="primary" id="ft_primary" name="ft_primary" type="text" value="Quarterly board meeting">
</div></form></section>

フォームの主要な項目、たとえばタイトルや名前に Primary を付けると、入力欄がより目立ちます。

field-textarea

textarea を field-text で包んだものです。

素のまま

プレビュー
<section rst-box><form rst-form method="post" action="#"><div rst-field>
  <label rst-field-label for="ta_bare">Notes</label>
  <textarea rst-textarea id="ta_bare" name="ta_bare" rows="3"></textarea>
</div></form></section>

ヒントつき

プレビュー
<section rst-box><form rst-form method="post" action="#"><div rst-field>
  <label rst-field-label for="ta_hint">Bio</label>
  <textarea rst-textarea id="ta_hint" name="ta_hint" rows="3" aria-describedby="ta_hint-hint"></textarea>
  <small rst-field-hint id="ta_hint-hint">Shown on your profile.</small>
</div></form></section>

エラーつき

プレビュー
<section rst-box><form rst-form method="post" action="#"><div rst-field>
  <label rst-field-label for="ta_error">Summary</label>
  <textarea rst-textarea id="ta_error" name="ta_error" rows="3" aria-invalid="true" aria-describedby="ta_error-error">…</textarea>
  <small rst-field-error id="ta_error-error">A summary needs at least twenty characters.</small>
</div></form></section>

必須

プレビュー
<section rst-box><form rst-form method="post" action="#"><div rst-field>
  <label rst-field-label for="ta_required">Reason for refund <span rst-field-required aria-hidden="true">*</span></label>
  <textarea rst-textarea id="ta_required" name="ta_required" rows="3" required></textarea>
</div></form></section>

field-select

ネイティブの select を field で包んだものです。選択肢が十を超えると select は select.js の絞り込みコンボボックスを有効にしますが、フォームが送信するのは変わらずネイティブの select です。

3つの選択肢:ネイティブの select

プレビュー
<section rst-box><form rst-form method="post" action="#"><div rst-field><label rst-field-label for="sel_few">Role</label>
<select rst-input id="sel_few" name="sel_few"><option value="Admin" selected>Admin</option><option value="Editor">Editor</option><option value="Member">Member</option></select>
</div></form></section>

12個の選択肢:絞り込みできるコンボボックス

プレビュー
<section rst-box><form rst-form method="post" action="#"><div rst-field><label rst-field-label for="sel_many">City</label>
<select rst-input id="sel_many" name="sel_many" data-rst-select data-rst-select-filter="入力して絞り込む" data-rst-select-results="{n} 件" data-rst-select-result-one="1 件" aria-describedby="sel_many-help"><option value="Dublin" selected>Dublin</option><option value="Lisbon">Lisbon</option><option value="Madrid">Madrid</option><option value="Berlin">Berlin</option><option value="Rome">Rome</option><option value="Athens">Athens</option><option value="Helsinki">Helsinki</option><option value="Reykjavík">Reykjavík</option><option value="Warsaw">Warsaw</option><option value="Zagreb">Zagreb</option><option value="Tallinn">Tallinn</option><option value="Valletta">Valletta</option></select>
<p rst-field-help id="sel_many-help">Start typing to filter.</p>
</div></form></section>

選択肢が十を超えると、部品は select.js を有効にします。十未満では有効にしません。ひと握りの項目を検索させるのは、助けではなく家具だからです。

選択肢が 12、Plain — 拡張を断った場合

プレビュー
<section rst-box><form rst-form method="post" action="#"><div rst-field><label rst-field-label for="sel_plain">City</label>
<select rst-input id="sel_plain" name="sel_plain"><option value="Dublin" selected>Dublin</option><option value="Lisbon">Lisbon</option><option value="Madrid">Madrid</option><option value="Berlin">Berlin</option><option value="Rome">Rome</option><option value="Athens">Athens</option><option value="Helsinki">Helsinki</option><option value="Reykjavík">Reykjavík</option><option value="Warsaw">Warsaw</option><option value="Zagreb">Zagreb</option><option value="Tallinn">Tallinn</option><option value="Valletta">Valletta</option></select>
</div></form></section>

必須、エラーつき

プレビュー
<section rst-box><form rst-form method="post" action="#"><div rst-field><label rst-field-label for="sel_error">Role</label>
<select rst-input id="sel_error" name="sel_error" required aria-invalid="true" aria-describedby="sel_error-error"><option value="Admin" selected>Admin</option><option value="Editor">Editor</option><option value="Member">Member</option></select>
<p rst-field-error id="sel_error-error" role="alert">Pick a role for this person.</p>
</div></form></section>

手書き、optgroup つき

プレビュー
<section rst-box><form rst-form method="post" action="#"><div rst-field><label rst-field-label for="sel_grouped">Region</label>
<select rst-input id="sel_grouped" name="sel_grouped" data-rst-select data-rst-select-filter="入力して絞り込む" data-rst-select-results="{n} 件" data-rst-select-result-one="1 件">
<optgroup label="Europe"><option value="dublin" selected>Dublin</option><option value="lisbon">Lisbon</option><option value="warsaw">Warsaw</option></optgroup>
<optgroup label="Americas"><option value="montreal">Montréal</option><option value="lima">Lima</option><option value="austin">Austin</option></optgroup>
<optgroup label="Asia"><option value="osaka">Osaka</option><option value="hanoi">Hanoi</option><option value="dhaka">Dhaka</option></optgroup>
<optgroup label="Africa"><option value="accra">Accra</option><option value="nairobi">Nairobi</option><option value="tunis">Tunis</option></optgroup>
</select>
</div></form></section>

ここでの Options は平坦なリストなので、グループ化した選択肢はアプリ側が書くマークアップです。select.js はグループを捨てずに描画します。手書きの select は data-rst-select="false" で拡張そのものを断ることもできます。

field-check

切り替えの仕組みはこれひとつ。見た目をスイッチにした本物のチェックボックスで、キーボードもスクリーンリーダーもそのまま使えます。

オン

プレビュー
<section rst-box><form rst-form method="post" action="#"><label rst-switch><input type="checkbox" name="notify_on" checked><span rst-switch-track aria-hidden="true"></span> Email me about replies</label></form></section>

オフ

プレビュー
<section rst-box><form rst-form method="post" action="#"><label rst-switch><input type="checkbox" name="notify_off"><span rst-switch-track aria-hidden="true"></span> Email me about mentions</label></form></section>

無効

プレビュー
<section rst-box><form rst-form method="post" action="#"><label rst-switch><input type="checkbox" name="notify_disabled" disabled><span rst-switch-track aria-hidden="true"></span> Email me a weekly digest</label></form></section>

choice-field

選択肢カード。ラジオやチェックボックスの group として推奨される形です。Title は短く保ち、説明は Desc に任せます。

ひとつだけ選ぶ

プレビュー
<section rst-box><form rst-form method="post" action="#"><fieldset rst-choice><legend>Plan</legend><div rst-choice-cards><label><input type="radio" name="plan" value="free"><span><span rst-choice-title>Free</span><span rst-choice-desc>One project, community support.</span></span></label><label><input type="radio" name="plan" value="pro" checked><span><span rst-choice-title>Pro</span><span rst-choice-desc>Unlimited projects and a support inbox.</span></span></label></div></fieldset></form></section>

いくつでも選べる

プレビュー
<section rst-box><form rst-form method="post" action="#"><fieldset rst-choice><legend>Send me</legend><div rst-choice-cards><label><input type="checkbox" name="digest" value="replies" checked><span><span rst-choice-title>Replies</span><span rst-choice-desc>As they happen.</span></span></label><label><input type="checkbox" name="digest" value="weekly"><span><span rst-choice-title>Weekly digest</span><span rst-choice-desc>Monday mornings.</span></span></label></div></fieldset></form></section>

form-foot

フォームを締めくくる行です。主となる送信ボタンひとつと、任意のキャンセルリンク。キャンセルがリンクなのは、フォームを離れることが画面移動だからです。

保存とキャンセル

プレビュー
<section rst-box><form rst-form method="post" action="#"><div rst-form-foot>
  <button rst-btn="primary" type="submit">Save post</button>
  <a rst-btn href="/posts">Back to posts</a>
</div></form></section>

送信のみ

プレビュー
<section rst-box><form rst-form method="post" action="#"><div rst-form-foot>
  <button rst-btn="primary" type="submit">Send invitation</button>
</div></form></section>

待機中 — 何も起きていないときのボタン

プレビュー
<section rst-box><form rst-form method="post" action="#"><div rst-form-foot>
  <button rst-btn="primary" type="submit">Publish</button>
  <a rst-btn href="/posts">Back to posts</a>
</div></form></section>

何かを変えるボタンには読み込み状態が付き、何かを開くだけのボタン(開閉、ドロップダウン、タブなど)には付きません。rastrillo.js はこの規則をすべてのフォームのすべての送信ボタンに適用します。有効にする設定はありません。

処理中 — フォームが出ていくときに rastrillo.js が書くもの

プレビュー
<section rst-box><form rst-form method="post" action="#"><div rst-form-foot>
<button rst-btn="primary" type="submit" aria-busy="true" data-idle-label="Publish" disabled><span rst-spin aria-hidden="true"></span>Publishing…</button>
<a rst-btn href="/posts">Back to posts</a>
</div></form></section>

押されたボタンだけです。フォーム内のほかの送信ボタンは name と value をそのまま保ち、フォーム自体は二重送信から守られます。data-busy="false" でこの規則を外せます(フォームにも、ボタン一つにも)。data-busy-label は文言を差し替えます。スクリプトを切ると何も起こらず、フォームはこれまでどおり送信されるので、冪等性は変わらずサーバーの仕事です。

confirm-form

確認ページの操作行です。取り消せない操作にはダイアログではなく専用のルートがあるので、書くべきスクリプトがありません。

取り消せない操作

プレビュー
<section rst-box><form rst-form-actions method="post" action="/posts/1/delete"><input type="hidden" name="csrf" value="tok-123"><input type="hidden" name="id" value="1"><a rst-btn="ghost" href="/posts/1">キャンセル</a><button type="submit" rst-btn="danger">Delete this post</button></form></section>

通常の場合、キャンセルの文言は既定

プレビュー
<section rst-box><form rst-form-actions method="post" action="/posts/1/publish"><a rst-btn="ghost" href="/posts/1">キャンセル</a><button type="submit" rst-btn="primary">Publish</button></form></section>

CancelLabel がないので、キャンセルリンクの文言はカタログから来ます。