From a1cc0551a517e89820fa91534415c0a19ef70b81 Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Mon, 8 Apr 2024 12:27:49 -0400 Subject: [PATCH] improvement: support `color_classes` config --- README.md | 19 +++++++++++++++++-- lib/custom.ex | 4 +++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e110860..cfc7bb7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Tails -Tails is a small set of utilities around working with tailwind class lists in Elixir. +Tails is a small set of utilities around working with tailwind class lists in Elixir. # Utilities @@ -54,7 +54,22 @@ We use custom defined colors for two things: If you *don't* do this, there are certain cases that we are currently unable to disambiguate. For example, if you have a custom font size utility, i.e `text-really-big` and a custom color utility, used like `text-really-red`, we can't tell which is which. We don't guarantee the behavior of that combination, but as of the writing of this paragraph, they will both override the font size. -I highly suggest that you configure your colors file statically if you want to use tails *or* help us figure out a way to make it unnecessary, because I can't think of one :) +I highly suggest that you configure your colors file statically, or configure your colors by hand as explained below if you want to use tails *or* help us figure out a way to make it unnecessary, because I can't think of one :) + +## Configuring custom colors without a colors file + +You can configure custom colors without a colors file by setting the following configuration: + +```elixir +config :tails, :color_classes, ["primary", "secondary", ...] +``` + +or if using a custom tails module + +```elixir +config :my_app, Tails, + color_classes: ["primary", "secondary", ...] +``` ## Merging Custom Colors diff --git a/lib/custom.ex b/lib/custom.ex index e5e9979..7ca2286 100644 --- a/lib/custom.ex +++ b/lib/custom.ex @@ -28,6 +28,7 @@ defmodule Tails.Custom do if otp_app == :tails do @colors_file Application.compile_env(otp_app, :colors_file) + @color_classes Application.compile_env(otp_app, :color_classes) || [] @no_merge_classes Application.compile_env(otp_app, :no_merge_classes) || [] @dark_themes dark_themes || Application.compile_env(otp_app, :dark_themes) @themes themes || Application.compile_env(otp_app, :themes) @@ -35,6 +36,7 @@ defmodule Tails.Custom do @fallback_to_colors Application.compile_env(otp_app, :fallback_to_colors) || false else @colors_file Application.compile_env(otp_app, __MODULE__)[:colors_file] + @color_classes Application.compile_env(otp_app, __MODULE__)[:color_classes] || [] @no_merge_classes Application.compile_env(otp_app, __MODULE__)[:no_merge_classes] || [] @dark_themes dark_themes || Application.compile_env(otp_app, __MODULE__)[:dark_themes] @themes themes || Application.compile_env(otp_app, __MODULE__)[:themes] @@ -57,7 +59,7 @@ defmodule Tails.Custom do Tails.Colors.builtin_colors() end) - @all_colors Tails.Colors.all_color_classes(@colors) + @all_colors Tails.Colors.all_color_classes(@colors) ++ @color_classes @colors_by_size @all_colors |> Enum.group_by(&byte_size/1)