feat: Add tag badge in filter window (#1038)

* feat: Add tag badge in filter window

* fix: validate Tag color attribute as hex format and increase transparency mix in border color

* fix: use fallback for tag color
This commit is contained in:
Alessio Cappa
2026-02-23 23:43:00 +01:00
committed by GitHub
parent 98df0d301a
commit 430c95e278
2 changed files with 10 additions and 9 deletions

View File

@@ -5,6 +5,7 @@ class Tag < ApplicationRecord
has_many :import_mappings, as: :mappable, dependent: :destroy, class_name: "Import::Mapping"
validates :name, presence: true, uniqueness: { scope: :family }
validates :color, format: { with: /\A#[0-9A-Fa-f]{6}\z/ }, allow_nil: true
scope :alphabetically, -> { order(:name) }

View File

@@ -16,15 +16,15 @@
tag.name,
nil %>
<%= form.label :tags, value: tag.name, class: "text-sm text-primary flex items-center gap-2" do %>
<%= render DS::FilledIcon.new(
variant: :text,
hex_color: tag.color || Tag::UNCATEGORIZED_COLOR,
text: tag.name,
size: "sm",
rounded: true
) %>
<%= tag.name %>
<% tag_color = tag.color.presence || Tag::UNCATEGORIZED_COLOR %>
<span class="border text-sm font-medium px-3 py-1 rounded-full inline-flex items-center gap-2"
style="
background-color: color-mix(in oklab, <%= tag_color %> 10%, transparent);
border-color: color-mix(in oklab, <%= tag_color%> 20%, transparent);
color: <%= tag_color %>;">
<span class="size-1.5 rounded-full" style="background-color: <%= tag_color %>;"></span>
<%= tag.name %>
</span>
<% end %>
</div>
<% end %>