defmodule SigmaKit.Components.Buttons do use Phoenix.LiveComponent import SigmaKit.Components.Icons @doc """ Renders a simple button component. ## Attributes * `:class` - Additional CSS classes to apply to the button. Defaults to `nil`. * `:primary` - A boolean indicating if the button should use the primary style. Defaults to `false`. * `:light` - A boolean indicating if the button should use the light style. Defaults to `false`. * `:danger` - A boolean indicating if the button should use the danger style. Defaults to `false`. * `:inline` - A boolean indicating if the button should use the inline style. Defaults to `false`. * `:rest` - A map of additional global attributes (e.g., `disabled`, `form`, `name`, `value`, `type`) to apply to the button. ## Slots * `:inner_block` (required) - The content to render inside the button. ## Styles The button supports multiple styles based on the attributes provided: * `:primary`: A blue button with a hover effect. * `:light`: A light gray button with a hover effect. * `:danger`: A red button for destructive actions. * `:inline`: A white button with a border and hover effects, suitable for inline usage. """ attr :class, :any, default: nil attr :primary, :boolean, default: false attr :light, :boolean, default: false attr :danger, :boolean, default: false attr :inline, :boolean, default: false attr :rest, :global, include: ~w(type disabled form name value) slot :inner_block, required: true def button(assigns) do ~H""" """ end @doc """ Renders a toggle switch with icons on the left and right sides. ## Attributes - `:left_icon` (string, required): The name of the icon to display on the left side of the toggle switch. - `:right_icon` (string, required): The name of the icon to display on the right side of the toggle switch. - `:event` (string, required): The event name triggered when the toggle switch is clicked. - `:target` (optional): The target for the `phx-click` event. - `:left` (boolean, required): Determines if the toggle is in the "left" position. - `:right` (boolean, required): Determines if the toggle is in the "right" position. """ attr :left_icon, :string, required: true attr :right_icon, :string, required: true attr :event, :string, required: true attr :target, :any, default: nil attr :left, :boolean, required: true attr :right, :boolean, required: true 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. ## Attributes - `:label` (string, optional): The label displayed on the dropdown button. - `:id` (string, required): A unique identifier for the dropdown component. ## Slots - `:action`: Defines the actions available in the dropdown menu. Each action can have the following attributes: - `:label` (string, optional): The label for the action. - `:icon` (string, optional): The name of the icon to display next to the action. - `:event` (string, optional): The event triggered when the action is clicked. - `:target` (any, optional): The target for the `phx-click` event. - `:value` (any, optional): The value passed with the `phx-click` event. """ attr :label, :string attr :id, :string, required: true slot :action do attr :label, :string attr :icon, :string attr :event, :string attr :target, :any attr :value, :any end def dropdown(assigns) do ~H""" <.button inline type="button" data-dropdown-toggle={"dropdown-#{@id}"} data-dropdown-trigger="hover" data-dropdown-delay={0} data-dropdown-offset-distance={0} data-dropdown-placement="bottom" > {@label} <.icon name="hero-chevron-down" class="ms-2 h-3 w-3" /> """ end end