-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #199 from coingaming/LAB-324-select-dropdown-icons
[#LAB-324] Refactor SingleSelect to support icons
- Loading branch information
Showing
15 changed files
with
422 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
defmodule Moon.Components.SelectTrigger do | ||
@moduledoc false | ||
|
||
use Moon.StatelessComponent | ||
alias Moon.Icons.{ControlsChevronDown, ControlsChevronUp} | ||
alias Phoenix.LiveView.JS | ||
|
||
prop id, :string | ||
prop placeholder, :string, default: "Choose" | ||
prop selected_option, :any | ||
prop size, :string, values: ~w(md lg xl), default: "md" | ||
prop state, :string, values: ~w(active error disabled) | ||
prop class, :string | ||
prop on_click, :event | ||
slot default | ||
|
||
def render(assigns) do | ||
~F""" | ||
<button | ||
class={ | ||
"w-full text-left border border-solid rounded border-beerus-100 bg-gohan-100 flex items-center focus:border-piccolo-100 active:border-piccolo-100 #{@class}", | ||
"text-sm h-10 leading-4 px-3": @size == "md", | ||
"text-base h-12 leading-6 px-4": @size == "lg", | ||
"text-base h-14 leading-6 px-4": @size == "xl", | ||
"text-trunks-100": is_nil(@selected_option), | ||
"text-bulma-100": !is_nil(@selected_option) | ||
} | ||
:on-click={@on_click} | ||
> | ||
<div class="grow"> | ||
{#if @selected_option} | ||
<#slot /> | ||
{#else} | ||
{@placeholder} | ||
{/if} | ||
</div> | ||
<div id={"#{@id}-chevron-down"} class="items-center"> | ||
<ControlsChevronDown class="flex-shrink-0 w-6 h-6" color="bulma-100" /> | ||
</div> | ||
<div id={"#{@id}-chevron-up"} class="items-center" style="display: none;"> | ||
<ControlsChevronUp class="flex-shrink-0 w-6 h-6" color="bulma-100" /> | ||
</div> | ||
</button> | ||
""" | ||
end | ||
|
||
def toggle_icons(js, id) do | ||
js | ||
|> JS.toggle(to: "##{id}-trigger-chevron-up", display: "flex") | ||
|> JS.toggle(to: "##{id}-trigger-chevron-down", display: "flex") | ||
end | ||
|
||
def reset_icons(js, id) do | ||
js | ||
|> JS.hide(to: "##{id}-trigger-chevron-up") | ||
|> JS.show(to: "##{id}-trigger-chevron-down", display: "flex") | ||
end | ||
end |
Oops, something went wrong.