Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
bluzky committed Nov 16, 2024
1 parent aac3177 commit 9098465
Show file tree
Hide file tree
Showing 22 changed files with 170 additions and 74 deletions.
21 changes: 11 additions & 10 deletions lib/salad_ui.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule SaladUI do

# alias OrangeCmsWeb.Components.LadUI.LadJS
alias Phoenix.LiveView.JS

defp classes(input) do
SaladUI.Merge.merge(input)
end
Expand All @@ -23,44 +24,44 @@ defmodule SaladUI do

defmacro __using__(_) do
quote do
import SaladUI.Helpers
import SaladUI.Accordion
import SaladUI.Alert
import SaladUI.AlertDialog
import SaladUI.Avatar
import SaladUI.Badge
import SaladUI.Breadcrumb
import SaladUI.Button
import SaladUI.Card
import SaladUI.Chart
import SaladUI.Checkbox
import SaladUI.Collapsible
import SaladUI.Dialog
import SaladUI.DropdownMenu
import SaladUI.Form
import SaladUI.Helpers
import SaladUI.HoverCard
import SaladUI.Icon
import SaladUI.Input
import SaladUI.Label
import SaladUI.Menu
import SaladUI.Pagination
import SaladUI.Popover
import SaladUI.Progress
import SaladUI.RadioGroup
import SaladUI.ScrollArea
import SaladUI.Select
import SaladUI.Separator
import SaladUI.Sheet
import SaladUI.Sidebar
import SaladUI.Skeleton
import SaladUI.Slider
import SaladUI.Switch
import SaladUI.Table
import SaladUI.Tabs
import SaladUI.Textarea
import SaladUI.Tooltip
import SaladUI.Collapsible
import SaladUI.Chart
import SaladUI.AlertDialog
import SaladUI.Popover
import SaladUI.Accordion
import SaladUI.RadioGroup
import SaladUI.ToggleGroup
import SaladUI.Toggle
import SaladUI.Sidebar
import SaladUI.ToggleGroup
import SaladUI.Tooltip
end
end
end
3 changes: 2 additions & 1 deletion lib/salad_ui/alert.ex
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ defmodule SaladUI.Alert do
@variants %{
variant: %{
"default" => "bg-background text-foreground",
"destructive" => "bg-background border-destructive/50 text-destructive dark:border-destructive [&>span]:text-destructive"
"destructive" =>
"bg-background border-destructive/50 text-destructive dark:border-destructive [&>span]:text-destructive"
}
}

Expand Down
13 changes: 8 additions & 5 deletions lib/salad_ui/collapsible.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ defmodule SaladUI.Collapsible do

def collapsible(assigns) do
assigns =
assigns
|> assign(:open, normalize_boolean(assigns[:open]))
assign(assigns, :open, normalize_boolean(assigns[:open]))

~H"""
<div
Expand All @@ -52,8 +51,11 @@ defmodule SaladUI.Collapsible do

def collapsible_trigger(assigns) do
~H"""
<.dynamic tag="button"
onclick={exec_closest("phx-toggle-collapsible", ".collapsible-root")} class={@class}>
<.dynamic
tag="button"
onclick={exec_closest("phx-toggle-collapsible", ".collapsible-root")}
class={@class}
>
<%= render_slot(@inner_block) %>
</.dynamic>
"""
Expand Down Expand Up @@ -86,7 +88,8 @@ defmodule SaladUI.Collapsible do
Show collapsible content.
"""
def toggle_collapsible(js \\ %JS{}, id) do
JS.toggle(js,
js
|> JS.toggle(
to: "##{id} .collapsible-content",
in: {"ease-out duration-200", "opacity-0", "opacity-100"},
out: {"ease-out", "opacity-100", "opacity-70"},
Expand Down
16 changes: 11 additions & 5 deletions lib/salad_ui/sidebar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ defmodule SaladUI.Sidebar do
~H"""
<div
style={
style(Map.merge(%{
"--sidebar-width": @sidebar_width,
"--sidebar-width-icon": @sidebar_width_icon
}, @style))
style(
Map.merge(
%{
"--sidebar-width": @sidebar_width,
"--sidebar-width-icon": @sidebar_width_icon
},
@style
)
)
}
class={
classes([
Expand Down Expand Up @@ -154,7 +159,8 @@ defmodule SaladUI.Sidebar do

def sidebar_trigger(assigns) do
~H"""
<.dynamic tag="button"
<.dynamic
tag="button"
data-sidebar="trigger"
variant="ghost"
size="icon"
Expand Down
3 changes: 2 additions & 1 deletion lib/utils/merge.ex
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ defmodule SaladUI.Merge do
|> Enum.join(" ")
end

defp handle_class(%{raw: raw, tailwind?: false}, acc, _config), do: Map.update!(acc, :classes, fn classes -> [raw | classes] end)
defp handle_class(%{raw: raw, tailwind?: false}, acc, _config),
do: Map.update!(acc, :classes, fn classes -> [raw | classes] end)

defp handle_class(%{conflict_id: conflict_id} = class, acc, config) do
if Enum.member?(acc.groups, conflict_id), do: acc, else: add_class(acc, class, config)
Expand Down
20 changes: 15 additions & 5 deletions lib/utils/merge/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,15 @@ defmodule SaladUI.Merge.Config do
"shrink" => %{"shrink" => zero_and_empty()},
"order" => %{"order" => ["first", "last", "none", &integer?/1, &arbitrary_value?/1]},
"grid-cols" => %{"grid-cols" => [&any?/1]},
"col-start-end" => %{"col" => ["auto", %{"span" => ["full", &integer?/1, &arbitrary_value?/1]}, &arbitrary_value?/1]},
"col-start-end" => %{
"col" => ["auto", %{"span" => ["full", &integer?/1, &arbitrary_value?/1]}, &arbitrary_value?/1]
},
"col-start" => %{"col-start" => number_with_auto_and_arbitrary()},
"col-end" => %{"col-end" => number_with_auto_and_arbitrary()},
"grid-rows" => %{"grid-rows" => [&any?/1]},
"row-start-end" => %{"row" => ["auto", %{"span" => ["full", &integer?/1, &arbitrary_value?/1]}, &arbitrary_value?/1]},
"row-start-end" => %{
"row" => ["auto", %{"span" => ["full", &integer?/1, &arbitrary_value?/1]}, &arbitrary_value?/1]
},
"row-start" => %{"row-start" => number_with_auto_and_arbitrary()},
"row-end" => %{"row-end" => number_with_auto_and_arbitrary()},
"grid-flow" => %{"grid-flow" => ["row", "col", "dense", "row-dense", "col-dense"]},
Expand Down Expand Up @@ -150,7 +154,9 @@ defmodule SaladUI.Merge.Config do
"space-x-reverse" => ["space-x-reverse"],
"space-y" => %{"space-y" => [&from_theme(&1, "space")]},
"space-y-reverse" => ["space-y-reverse"],
"w" => %{"w" => ["auto", "min", "max", "fit", "svw", "lvw", "dvw", &from_theme(&1, "spacing"), &arbitrary_value?/1]},
"w" => %{
"w" => ["auto", "min", "max", "fit", "svw", "lvw", "dvw", &from_theme(&1, "spacing"), &arbitrary_value?/1]
},
"min-w" => %{"min-w" => ["min", "max", "fit", &from_theme(&1, "spacing"), &arbitrary_value?/1]},
"max-w" => %{
"max-w" => [
Expand Down Expand Up @@ -179,8 +185,12 @@ defmodule SaladUI.Merge.Config do
&arbitrary_value?/1
]
},
"min-h" => %{"min-h" => ["min", "max", "fit", "svh", "lvh", "dvh", &from_theme(&1, "spacing"), &arbitrary_value?/1]},
"max-h" => %{"max-h" => ["min", "max", "fit", "svh", "lvh", "dvh", &from_theme(&1, "spacing"), &arbitrary_value?/1]},
"min-h" => %{
"min-h" => ["min", "max", "fit", "svh", "lvh", "dvh", &from_theme(&1, "spacing"), &arbitrary_value?/1]
},
"max-h" => %{
"max-h" => ["min", "max", "fit", "svh", "lvh", "dvh", &from_theme(&1, "spacing"), &arbitrary_value?/1]
},
"size" => %{"size" => ["auto", "min", "max", "fit", &from_theme(&1, "spacing"), &arbitrary_value?/1]},
"font-size" => %{"text" => ["base", &tshirt_size?/1, &arbitrary_length?/1]},
"font-smoothing" => ["antialiased", "subpixel-antialiased"],
Expand Down
28 changes: 16 additions & 12 deletions lib/utils/merge/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,20 @@ defmodule SaladUI.Merge.Parser do
|> ascii_string([?a..?z, ?0..?9], min: 1)
|> unwrap_and_tag(:postfix)

defparsec :arbitrary,
"["
|> string()
|> concat(times(choice([parsec(:arbitrary), ascii_string(@chars ++ [?:, ?/], min: 1)]), min: 1))
|> concat(string("]"))

defparsec :class,
modifier
|> optional()
|> concat(optional(important))
|> concat(base)
|> concat(optional(postfix))
defparsec(
:arbitrary,
"["
|> string()
|> concat(times(choice([parsec(:arbitrary), ascii_string(@chars ++ [?:, ?/], min: 1)]), min: 1))
|> concat(string("]"))
)

defparsec(
:class,
modifier
|> optional()
|> concat(optional(important))
|> concat(base)
|> concat(optional(postfix))
)
end
6 changes: 4 additions & 2 deletions test/salad_ui/accordion_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ defmodule SaladUI.AccordionTest do

assert html =~ ~s(name="my-group")

for class <- ~w(flex py-4 transition-all items-center justify-between flex-1 font-medium hover:underline custom-class) do
for class <-
~w(flex py-4 transition-all items-center justify-between flex-1 font-medium hover:underline custom-class) do
assert html =~ class
end
end
Expand All @@ -115,7 +116,8 @@ defmodule SaladUI.AccordionTest do
inner_block: []
})

for class <- ~w(text-sm overflow-hidden grid grid-rows-[0fr] transition-[grid-template-rows] duration-300 peer-open/accordion:grid-rows-[1fr]) do
for class <-
~w(text-sm overflow-hidden grid grid-rows-[0fr] transition-[grid-template-rows] duration-300 peer-open/accordion:grid-rows-[1fr]) do
assert html =~ class
end

Expand Down
1 change: 1 addition & 0 deletions test/salad_ui/alert_dialog_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule SaladUI.AlertDialogTest do
use ComponentCase

import SaladUI.AlertDialog

# Helper function to set up assigns
Expand Down
1 change: 1 addition & 0 deletions test/salad_ui/alert_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ defmodule SaladUI.AlertTest do
for class <- ~w(mb-1 tracking-tight font-medium leading-none) do
assert html =~ class
end

assert html =~ "Heads up!"
assert html =~ "Alert Descriptions"

Expand Down
5 changes: 4 additions & 1 deletion test/salad_ui/avatar_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ defmodule SaladUI.AvatarTest do
for class <- ~w(aspect-square w-full h-full) do
assert html =~ class
end

assert html =~ "src=\"https:\/\/github.com\/shadcn.png\" "
end

Expand All @@ -29,6 +30,7 @@ defmodule SaladUI.AvatarTest do
for class <- ~w(flex rounded-full bg-primary text-white items-center justify-center w-full h-full) do
assert html =~ class
end

assert html =~ "CN"
end

Expand All @@ -43,9 +45,10 @@ defmodule SaladUI.AvatarTest do
</.avatar>
""")

for class <- ~w(flex rounded-full bg-primary text-white items-center justify-center w-full h-full) do
for class <- ~w(flex rounded-full bg-primary text-white items-center justify-center w-full h-full) do
assert html =~ class
end

assert html =~ "CN"
end
end
Expand Down
1 change: 1 addition & 0 deletions test/salad_ui/badge_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ defmodule SaladUI.BadgeTest do
~w(inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 border-transparent bg-primary text-primary-foreground hover:bg-primary/80) do
assert html =~ class
end

assert html =~ "Badge"
end

Expand Down
1 change: 1 addition & 0 deletions test/salad_ui/collapsible_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule SaladUI.CollapsibleTest do
use ComponentCase

import SaladUI.Collapsible

describe "collapsible/1" do
Expand Down
1 change: 1 addition & 0 deletions test/salad_ui/dialog_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ defmodule SaladUI.DialogTest do
for class <- ~w(flex text-center flex-col space-y-1.5 sm:text-left) do
assert html =~ class
end

assert html =~ "This is the content of the header"

for css_class <- ~w(flex flex-col space-y-1.5 text-center sm:text-left) do
Expand Down
4 changes: 3 additions & 1 deletion test/salad_ui/form_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ defmodule SaladUI.FormTest do
for class <- ~w(font-medium leading-none text-sm peer-disabled:cursor-not-allowed peer-disabled:opacity-70) do
assert html =~ class
end

assert html =~ "This is a label"
end

Expand Down Expand Up @@ -74,6 +75,7 @@ defmodule SaladUI.FormTest do
for class <- ~w(text-destructive font-medium text-sm) do
assert html =~ class
end

assert html =~ "This is a form message"
end

Expand Down Expand Up @@ -111,13 +113,13 @@ defmodule SaladUI.FormTest do
|> rendered_to_string()
|> clean_string()


assert html =~
"<form class=\"space-y-6\" id=\"project-form\" phx-change=\"validate\" phx-submit=\"save\" phx-target=\"test-string\""

for class <- ~w(font-medium leading-none text-sm peer-disabled:cursor-not-allowed peer-disabled:opacity-70) do
assert html =~ class
end

assert html =~ "What is your project's name?"

assert html =~ "<p class=\"text-muted-foreground text-sm\">This is your public display name.</p>"
Expand Down
12 changes: 9 additions & 3 deletions test/salad_ui/hover_card_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ defmodule SaladUI.HoverCardTest do
|> rendered_to_string()
|> clean_string()

for class <- ~w(absolute hidden p-4 mb-2 rounded-md bg-popover text-popover-foreground outline-none shadow-md z-50 left-1/2 bottom-full w-64 -translate-x-1/2 animate-in border data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 fade-in-0 group-hover/hover-card:block slide-in-from-left-1/2 zoom-in-95) do
for class <-
~w(absolute hidden p-4 mb-2 rounded-md bg-popover text-popover-foreground outline-none shadow-md z-50 left-1/2 bottom-full w-64 -translate-x-1/2 animate-in border data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 fade-in-0 group-hover/hover-card:block slide-in-from-left-1/2 zoom-in-95) do
assert html =~ class
end

assert html =~ "Hover Card Content"
end

Expand All @@ -43,9 +45,11 @@ defmodule SaladUI.HoverCardTest do
|> rendered_to_string()
|> clean_string()

for class <- ~w(absolute hidden p-4 mt-2 rounded-md bg-popover text-popover-foreground outline-none shadow-md z-50 left-1/2 top-full w-64 -translate-x-1/2 animate-in border data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 fade-in-0 group-hover/hover-card:block slide-in-from-left-1/2 zoom-in-95) do
for class <-
~w(absolute hidden p-4 mt-2 rounded-md bg-popover text-popover-foreground outline-none shadow-md z-50 left-1/2 top-full w-64 -translate-x-1/2 animate-in border data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 fade-in-0 group-hover/hover-card:block slide-in-from-left-1/2 zoom-in-95) do
assert html =~ class
end

assert html =~ "Hover Card Content"
assert html =~ "data-side=\"bottom\""
end
Expand All @@ -60,9 +64,11 @@ defmodule SaladUI.HoverCardTest do
|> rendered_to_string()
|> clean_string()

for class <- ~w(absolute hidden p-4 ml-2 rounded-md bg-popover text-popover-foreground outline-none shadow-md z-50 left-full top-1/2 w-64 -translate-y-1/2 animate-in border data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 fade-in-0 group-hover/hover-card:block slide-in-from-top-1/2 zoom-in-95) do
for class <-
~w(absolute hidden p-4 ml-2 rounded-md bg-popover text-popover-foreground outline-none shadow-md z-50 left-full top-1/2 w-64 -translate-y-1/2 animate-in border data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 fade-in-0 group-hover/hover-card:block slide-in-from-top-1/2 zoom-in-95) do
assert html =~ class
end

assert html =~ "Hover Card Content"
end
end
Expand Down
Loading

0 comments on commit 9098465

Please sign in to comment.