メインコンテンツへスキップ

テーマ設定

最終更新日:

Frutjam の CSS のみのテーマ システムは、CSS 変数と単一のデータ属性を使用します。 JavaScript を使用せずに、明るいテーマ、暗いテーマ、カスタム テーマを切り替えます。 WCAG AA カラー トークンが組み込まれており、Django、HTMX、Laravel、およびあらゆる Tailwind CSS v4 プロジェクトで動作します。

Frutjam には、Berry テーマ システム (OKLCH カラー値に基づいて構築された一連の名前付きテーマ) が付属しています。 data-theme 属性を使用して、アプリ全体にテーマを適用するか、特定のセクション内にテーマをネストします。 CSS のみ、JavaScript は不要、WCAG AA にアクセス可能 — Django、HTMX、Laravel、React、およびあらゆる Tailwind CSS v4 プロジェクトで動作します。

内蔵テーマ

Frutjam には、すぐに使える 2 つの組み込みテーマが含まれています。

スノーベリー(光)

デフォルトのライトテーマ。 data-theme が設定されていない場合に自動的に適用されます。

html
1
2
3
4
5
6
7
<html data-theme="snowberry">
  <!-- or use the alias -->
</html>

<html data-theme="light">
  <!-- same as snowberry -->
</html>

ダークベリー(ダーク)

組み込みのダークテーマ。

html
1
2
3
4
5
6
7
<html data-theme="darkberry">
  <!-- or use the alias -->
</html>

<html data-theme="dark">
  <!-- same as darkberry -->
</html>

テーマの適用

data-theme を任意の HTML 要素に追加します。このテーマはすべての子供たちに伝わります。

html
1
2
3
4
5
6
<!-- Apply globally -->
<html data-theme="snowberry">
  <body>
    <!-- All components use snowberry theme -->
  </body>
</html>

ネストされたテーマ

テーマは入れ子にすることができます。子要素は、そのサブツリーの親テーマをオーバーライドします。

html
1
2
3
4
5
6
7
8
9
<html data-theme="snowberry">
  <section data-theme="darkberry">
    <!-- This section uses the dark theme -->
    <button class="btn btn-primary">Dark Button</button>
  </section>

  <!-- Back to light theme here -->
  <button class="btn btn-primary">Light Button</button>
</html>

ダークモードのバリアント

Tailwind の dark: プレフィックスを使用します。これは、data-theme="dark"data-theme="darkberry" の両方でアクティブになります。

html
1
2
3
<p class="text-on-base dark:text-primary">
  Adapts to the active theme automatically.
</p>

カスタムテーマ

[data-theme] セレクター内で CSS 変数を定義して、独自のテーマを作成します。完全な変数リファレンスについては、設定ページを参照してください。

css
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
@layer theme {
  :is([data-theme="myberry"]) {
    --scheme-color: light;
    --border-radius: 0.5rem;
    --color-base: oklch(1 0 0);
    --color-primary: oklch(55% 0.22 142);
    --color-secondary: oklch(60% 0.18 280);
    --color-accent: oklch(70% 0.20 60);
  }
}
html
1
2
3
<html data-theme="myberry">
  <!-- Your custom theme is active -->
</html>