diff --git a/app/components/shipwright/checkbox_component.html.erb b/app/components/shipwright/checkbox_component.html.erb new file mode 100644 index 0000000..0805e54 --- /dev/null +++ b/app/components/shipwright/checkbox_component.html.erb @@ -0,0 +1,40 @@ +<%= content_tag :label, + class: label_classes, + for: id, + data: { indeterminate: indeterminate? ? "true" : nil } do %> + + + <%= check_box_tag name, value, checked?, + id: id, + disabled: disabled?, + class: "peer sr-only", + **html_attrs %> + + + <%# Check icon — shown when the label (group) contains a checked input, + and the group is NOT in the indeterminate state. %> + + <%# Dash icon — shown when the label carries data-indeterminate="true". %> + + + + + <% if label_text %> + + <%= label_text %> + <% if caption %> + <%= caption %> + <% end %> + + <% end %> +<% end %> diff --git a/app/components/shipwright/checkbox_component.rb b/app/components/shipwright/checkbox_component.rb new file mode 100644 index 0000000..5181b86 --- /dev/null +++ b/app/components/shipwright/checkbox_component.rb @@ -0,0 +1,116 @@ +module Shipwright + # Checkbox form control with optional label + caption. Tri-state support + # (unchecked / checked / indeterminate) and destructive variant matching + # Shipwright Pro's Checkbox atom. + # + # Usage: + # <%= render Shipwright::CheckboxComponent.new(name: "terms", label: "Accept") %> + # <%= render Shipwright::CheckboxComponent.new(name: "x", label: "Yes", caption: "Opt-in") %> + # <%= render Shipwright::CheckboxComponent.new(name: "danger", label: "Delete", variant: :destructive) %> + # + # Styling strategy: the