「Tailwind CSS実践入門 」を読んで雑にまとめる

参考

ユーティリティファースト

ヴァリアントとモディファイア
- ヴァリアントは画面幅の条件づけなどの時に利用する語
- モディファイアはそれを表現する修飾子を表す語。(そのものを表す概念??)

詳細度
Tailwindのクラスを全てimportantをつけられる。
//tailwind.config.js
important: true,

VScode拡張機能

clasxやclassNamesに拡張機能の対象にしたいときtailwind.config.js
に設定。
//config.js
tailwindFunctions: ["classNames"]

真似したい使い方!便利!

z-indexの設定!これも真似したい。
tailwind.config.js
module.exports = {
theme: {
zIndex: {
0: 0,
1: 1,
infinity: "calc(infinity)",
},
},
};

モディファイア

focusとfocus-within
focus:はその要素自身がフォーカス中であるかを見るものでしたが、子孫要素がその状態にあることを見たいケースもあります。たとえば中に<input>を含む、入力欄のコンポーネントルートにあたる<div>要素があるとします。ここで、中の<input>がフォーカス中だったら親である<div>のほうの見た目を変えるというふうにしたい場合、focus-within:を用います

first,last,first-of-type
<div>
<div id="div-1" className="first:bg-red-500">:first-childである(:first-of-typeでもある)</div>
<span id="span-1" className="first-of-type:bg-blue-500">:first-of-typeである(:first-childではない)</span>
<span id="span-2">...</span>
<span id="span-3">...</span>
<div id="div-2" className="last-of-type:bg-blue-500">:last-of-typeである(:last-childではない)</div>
<span id="span-4" className="last:bg-red-500">:last-childである(:last-of-typeでもある)</span>
</div>

has
<div className="has-[dialog[open]]:overflow-hidden">
<dialog open>dialog</dialog>
</div>

placeholder:
<div>
<input type="text" className="placeholder:text-red-500" placeholder="プレイスホルダー" />
<input type="text" className="placeholder-shown:text-blue-500" placeholder="プレイスホルダー" />
</div>

file:
<input
type="file"
className="
file:mr-4 file:py-2 file:px-4
file:rounded-full file:border-0
file:text-sm file:font-semibold
file:bg-violet-50 file:text-violet-700 hover:file:bg-violet-100"
/>

first-letter: 最初の文字の装飾
first-line: 最初の行の装飾
<p className="first-letter:float-left first-letter:mr-3 first-letter:text-7xl first-letter:font-bold first-line:uppercase first-line:tracking-widest">

orientation
ビューポートの向きで条件分岐する。
portrait: 縦
landscape: 横

動的なスタイル
<div className="bg-red-500 h-[200px] lg:h-[var(--parent-height)]" style={{ "--parent-height": el.innerHeight }}>
伸びる
</div>

<div className="bg-red-500 h-[200px] lg:h-[var(--parent-height)]" style={{ ["--parent-height" as string]: "300px" }}>
伸びる
</div>

公式プラグイン

コンポーネントの責務とインターフェース

全てのUIがコンポーネントであるわけではない。
Material UIやAtomic desighn は「ページ内の全ての要素はコンポーネントである」という思想

Tailwind CSSの「ユーティリティファースト」とは、必要に応じてあとから抽象化をする(そうと確信できない箇所はユーティリティで書く)という思想であり、最初からあらゆるUIが「下位のコンポーネント」からできていると決め込まないことです。
やりがち。

バリエーションライブラリー

「シャッドシーエヌ・ユーアイ」と読みます。
読み方がわからなかった。スッキリ。

HeadlessUI

アニメーション

デザインシステムについて

この[]の使い方はよき。例外かどうか即時にわかる。
タブレット以上の画面では、ガイドラインから外れていることが一発でわかるマークアップ
<!-- NOTICE: 高さの合計を4の倍数にしたいので、タブレット以上では例外的に5pxのpaddingを使う -->
<div class="leading-none text-12 py-4 tablet:text-14 tablet:py-[5px]">
タブレット以上の画面では、ガイドラインから外れていることが一発でわかるマークアップ
</div>

トークンの命名
色やスペーシングを命名する際の方針には大きく分けて2つあります。たとえば大きさが8pxのスペーシングに対して、そのまま8と名付けるか、あるいはsmallやsのように名付けるかです。本書では、前者を「リテラル」な命名、後者を「セマンティック」な命名と呼びます。

デザイントークンの参考書

背景素材