defmodule SigmaKit.Components.Buttons do use Phoenix.LiveComponent import SigmaKit.Components.Icons import SigmaKit.Components.Popups, only: [popover: 1] @doc """ Renders a simple button component. """ attr :class, :any, default: nil, doc: "Additional CSS classes to apply to the button." attr :primary, :boolean, default: false, doc: "Apply the primary style to the button." attr :dark, :boolean, default: false, doc: "Apply a dark style to the button." attr :light, :boolean, default: false, doc: "Apply the light style to the button." attr :danger, :boolean, default: false, doc: "Apply the danger style to the button." attr :inline, :boolean, default: false, doc: "Apply the inline style to the button." attr :plain, :boolean, default: false, doc: "Apply no border or shadow to the button." attr :rest, :global, include: ~w(type disabled form name value), doc: "Additional attributes to apply to the button." slot :inner_block, required: true, doc: "The content to render inside the button." def button(assigns) do ~H""" """ end @doc """ Renders a toggle switch with icons on the left and right sides. """ attr :left_icon, :string, required: true, doc: "The name of the icon to display on the left side of the toggle switch." attr :right_icon, :string, required: true, doc: "The name of the icon to display on the right side of the toggle switch." attr :event, :string, required: true, doc: "The event name triggered when the toggle switch is clicked." attr :target, :any, default: nil, doc: "The target for the `phx-click` event." attr :left, :boolean, required: true, doc: "Determines if the toggle is in the 'left' position." attr :right, :boolean, required: true, doc: "Determines if the toggle is in the 'right' position." def icon_toggle_switch(assigns) do ~H"""
<.icon name={@left_icon} class={["w-5 h-5", !@left && "text-zinc-300"]} />
<.icon name={@right_icon} class={["w-5 h-5", !@right && "text-zinc-300"]} />
""" end @doc """ Renders a dropdown button with a customizable label and a list of actions. """ attr :label, :string, doc: "The label displayed on the dropdown button.", default: nil attr :id, :string, required: true, doc: "A unique identifier for the dropdown component." attr :inline, :boolean, default: true, doc: "Apply the inline style to the dropdown button." attr :plain, :boolean, default: false, doc: "Applies no border or color to the button" attr :icon, :string, doc: "The name of the icon to display on the button." attr :class, :any, default: nil slot :action, doc: "A dropdwn menu item" do attr :divider, :boolean, doc: "This item will create a dividing line" attr :label, :string, doc: "The label for the menu item." attr :icon, :string, doc: "The name of the icon to display" attr :event, :string, doc: "The event triggered when the menu item is clicked." attr :target, :any, doc: "The target for the `phx-click` event." attr :value, :any, doc: "The value passed with the `phx-click` event." attr :value_id, :string, doc: "The phx-value-id for the menu item" attr :danger, :boolean end def dropdown(assigns) do ~H""" <.popover id={@id} placement="bottom" trigger_click nopad minwidth> <:trigger> <.button :if={@label} inline={@inline} type="button" plain={@plain} class={["flex items-center", @class]} > <.icon :if={assigns[:icon]} name={@icon} class="w-4 h-4 me-2" /> {@label} <.icon name="hero-chevron-down" class="ms-2 h-3 w-3" /> """ end attr :label, :string, default: nil, doc: "The label displayed on the dropdown button." attr :id, :string, required: true, doc: "A unique identifier for the dropdown component." attr :inline, :boolean, default: true, doc: "Apply the inline style to the dropdown button." attr :plain, :boolean, default: false, doc: "Applies no border or color to the button" attr :icon, :string, default: nil, doc: "The name of the icon to display on the button." attr :options, :list, default: [], doc: "A list of dropdown options in the form of a label/value tuples" attr :event, :any, default: nil, doc: "The event to fire when an item is selected" attr :value, :any, default: nil, doc: "The currently selected value" attr :target, :any, default: nil, doc: "The target for the selection event" def dropdown_select(assigns) do ~H"""
<.icon :if={@icon} name={@icon} class="h-4 w-4 me-0 pe-0" /> {@label}
<.popover id={@id} placement="bottom" trigger_click nopad minwidth> <:trigger>
""" end attr :date, :any, required: true, doc: "The currently selected date value" attr :id, :string, required: true attr :target, :any, default: nil, doc: "The target for the selection event" def date_select(assigns) do assigns = assign(assigns, day_count: Timex.diff( Timex.end_of_month(assigns.date), Timex.beginning_of_month(assigns.date), :days ), start_offset: Timex.weekday(Timex.beginning_of_month(assigns.date)) - 1 ) ~H""" <.popover trigger_click placement="bottom"> <:trigger> <.button inline> <.icon name="hero-calendar" class="w-4 h-4 me-2 mb-1" /> {Timex.format!(@date, "{0M}/{0D}/{YY}")}
{Timex.format!(@date, "{Mshort}, {YYYY}")}
S
M
T
W
T
F
S
{d + 1}
""" end defp active_label(options, value) do Enum.find_value(options, fn {label, v} -> if value == v, do: label, else: nil end) end end