Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve radio input, consistent UI cross browser #44

Merged
merged 1 commit into from
Sep 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions lib/salad_ui/radio_group.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,36 @@ defmodule SaladUI.RadioGroup do

def radio_group_item(assigns) do
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider renaming radio_group_item for consistency

For better consistency with the module name (SaladUI.RadioGroup), consider renaming radio_group_item to just item. This would make the context clearer and improve overall naming consistency in the module.

  def item(assigns) do

~H"""
<input
type="radio"
class={
classes([
"aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background disabled:cursor-not-allowed disabled:opacity-50",
@class
])
}
name={@builder.name}
checked={normalize_boolean(@checked) || @builder.value == @value}
{@rest}
/>
<label class={
classes([
"aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 has-[:disabled]:cursor-not-allowed has-[:disabled]:opacity-50 inline-grid",
@class
])
}>
<input
type="radio"
class="hidden peer/radio"
name={@builder.name}
checked={normalize_boolean(@checked) || @builder.value == @value}
{@rest}
/>
<span class="hidden items-center justify-center peer-checked/radio:flex">
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="lucide lucide-circle h-2.5 w-2.5 fill-current text-current"
>
<circle cx="12" cy="12" r="10"></circle>
</svg>
</span>
</label>
"""
end
end
Loading