Chip
Small labeled elements
Preview
Chip Label
Props Editor
Source Code
defmodule FeenixUiWeb.Components.ChipComponent do use Phoenix.Component def render(assigns) do assigns = assign_new(assigns, :text, fn -> "Chip Label" end) assigns = assign_new(assigns, :variant, fn -> "primary" end) assigns = assign_new(assigns, :removable, fn -> false end) assigns = assign(assigns, :chip_classes, get_chip_classes(assigns.variant)) ~H""" <div class={@chip_classes}> <span class="text-sm font-medium"><%= @text %></span> <%= if @removable do %> <button class="ml-1 inline-flex items-center justify-center w-4 h-4 rounded-full hover:bg-black hover:bg-opacity-10"> <svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path> </svg> </button> <% end %> </div> """ end defp get_chip_classes(variant) do base_classes = "inline-flex items-center px-3 py-1 rounded-full text-sm font-medium" variant_classes = case variant do "primary" -> "bg-primary-100 text-primary-800" "secondary" -> "bg-secondary-100 text-secondary-800" "success" -> "bg-success-100 text-success-800" "warning" -> "bg-warning-100 text-warning-800" "danger" -> "bg-danger-100 text-danger-800" "info" -> "bg-info-100 text-info-800" _ -> "bg-gray-100 text-gray-800" end "#{base_classes} #{variant_classes}" end end