-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added range component and minor refactors on function names in Utils
module
- Loading branch information
Showing
17 changed files
with
232 additions
and
35 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
52 changes: 52 additions & 0 deletions
52
daisy_ui_components_site/storybook/components/range.story.exs
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,52 @@ | ||
defmodule Storybook.Components.Range do | ||
use PhoenixStorybook.Story, :component | ||
|
||
alias DaisyUIComponents.Utils | ||
|
||
def function, do: &DaisyUIComponents.Range.range/1 | ||
|
||
def imports, do: [] | ||
|
||
def variations do | ||
[ | ||
%Variation{ | ||
id: :range, | ||
attributes: %{ | ||
min: 0, | ||
max: 100, | ||
value: 40 | ||
} | ||
}, | ||
%VariationGroup{ | ||
id: :colors, | ||
variations: | ||
for {color, index} <- Enum.with_index(Utils.colors()) do | ||
%Variation{ | ||
id: String.to_atom(color), | ||
attributes: %{ | ||
color: color, | ||
min: 0, | ||
max: 100, | ||
value: 30 + 10 * index | ||
} | ||
} | ||
end | ||
}, | ||
%VariationGroup{ | ||
id: :sizes, | ||
variations: | ||
for {size, index} <- Enum.with_index(Utils.sizes()) do | ||
%Variation{ | ||
id: String.to_atom(size), | ||
attributes: %{ | ||
size: size, | ||
min: 0, | ||
max: 100, | ||
value: 40 + 10 * index | ||
} | ||
} | ||
end | ||
} | ||
] | ||
end | ||
end |
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
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,54 @@ | ||
defmodule DaisyUIComponents.Range do | ||
@moduledoc """ | ||
Select component | ||
https://daisyui.com/components/range | ||
""" | ||
|
||
use DaisyUIComponents.Component | ||
|
||
attr :class, :any, default: nil | ||
attr :color, :string, values: colors() | ||
attr :size, :string, values: sizes() | ||
attr :min, :integer, default: nil | ||
attr :max, :integer, default: nil | ||
attr :step, :integer, default: nil | ||
attr :rest, :global, include: ~w(name) | ||
|
||
def range(assigns) do | ||
assigns = | ||
assigns | ||
|> assign(:color_class, range_color(assigns[:color])) | ||
|> assign(:size_class, range_size(assigns[:size])) | ||
|
||
~H""" | ||
<input | ||
type="range" | ||
class={classes(["range", @color_class, @size_class, @class])} | ||
min={@min} | ||
max={@max} | ||
step={@step} | ||
{@rest} | ||
/> | ||
""" | ||
end | ||
|
||
# Color | ||
defp range_color("primary"), do: "range-primary" | ||
defp range_color("secondary"), do: "range-secondary" | ||
defp range_color("accent"), do: "range-accent" | ||
defp range_color("info"), do: "range-info" | ||
defp range_color("success"), do: "range-success" | ||
defp range_color("warning"), do: "range-warning" | ||
defp range_color("error"), do: "range-error" | ||
defp range_color(_color), do: nil | ||
|
||
# Size | ||
defp range_size("xs"), do: "range-xs" | ||
defp range_size("sm"), do: "range-sm" | ||
defp range_size("md"), do: "range-md" | ||
defp range_size("lg"), do: "range-lg" | ||
defp range_size(_size), do: nil | ||
end |
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
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,53 @@ | ||
defmodule DaisyUIComponents.RangeTest do | ||
use ExUnit.Case | ||
|
||
import Phoenix.Component | ||
import Phoenix.LiveViewTest | ||
import DaisyUIComponents.Range | ||
|
||
alias DaisyUIComponents.Utils | ||
|
||
test "range" do | ||
assigns = %{} | ||
|
||
range = | ||
rendered_to_string(~H""" | ||
<.range /> | ||
""") | ||
|
||
assert range =~ ~s(<input) | ||
assert range =~ ~s(class="range") | ||
assert range =~ ~s(type="range") | ||
|
||
range = | ||
rendered_to_string(~H""" | ||
<.range min={0} max={100} value={10} step={25} /> | ||
""") | ||
|
||
assert range =~ ~s(<input) | ||
assert range =~ ~s(min="0") | ||
assert range =~ ~s(max="100") | ||
assert range =~ ~s(step="25") | ||
assert range =~ ~s(value="10") | ||
end | ||
|
||
test "range colors" do | ||
for color <- Utils.colors() do | ||
assigns = %{color: color} | ||
|
||
assert rendered_to_string(~H""" | ||
<.range color={@color} /> | ||
""") =~ ~s(<input type="range" class="range range-#{color}">) | ||
end | ||
end | ||
|
||
test "range sizes" do | ||
for size <- Utils.sizes() do | ||
assigns = %{size: size} | ||
|
||
assert rendered_to_string(~H""" | ||
<.range size={@size} /> | ||
""") =~ ~s(<input type="range" class="range range-#{size}">) | ||
end | ||
end | ||
end |
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