shadcn_phlexcomponents 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/tailwind/choices.css +324 -0
  3. data/app/assets/tailwind/vanilla-calendar-pro.css +5 -0
  4. data/app/javascript/controllers/combobox_controller.js +19 -276
  5. data/app/javascript/controllers/date_picker_controller.js +118 -0
  6. data/app/javascript/controllers/date_range_picker_controller.js +231 -0
  7. data/app/javascript/controllers/dropdown_menu_controller.js +1 -1
  8. data/app/javascript/controllers/hover_card_controller.js +33 -126
  9. data/app/javascript/controllers/sidebar_controller.js +0 -1
  10. data/app/javascript/controllers/tooltip_controller.js +32 -126
  11. data/lib/components/accordion.rb +3 -3
  12. data/lib/components/accordion_content.rb +12 -10
  13. data/lib/components/accordion_item.rb +3 -3
  14. data/lib/components/accordion_trigger.rb +3 -3
  15. data/lib/components/alert_description.rb +1 -1
  16. data/lib/components/alert_dialog.rb +2 -2
  17. data/lib/components/alert_dialog_action.rb +2 -2
  18. data/lib/components/alert_dialog_action_to.rb +5 -2
  19. data/lib/components/alert_dialog_cancel.rb +1 -1
  20. data/lib/components/alert_dialog_content.rb +1 -1
  21. data/lib/components/alert_dialog_description.rb +1 -1
  22. data/lib/components/alert_dialog_footer.rb +1 -1
  23. data/lib/components/alert_dialog_header.rb +1 -1
  24. data/lib/components/alert_dialog_title.rb +1 -1
  25. data/lib/components/alert_dialog_trigger.rb +2 -2
  26. data/lib/components/aspect_ratio.rb +1 -1
  27. data/lib/components/avatar.rb +1 -1
  28. data/lib/components/avatar_fallback.rb +1 -1
  29. data/lib/components/avatar_image.rb +1 -2
  30. data/lib/components/badge.rb +2 -8
  31. data/lib/components/base.rb +5 -5
  32. data/lib/components/breadcrumb.rb +1 -1
  33. data/lib/components/breadcrumb_ellipsis.rb +1 -1
  34. data/lib/components/breadcrumb_item.rb +1 -1
  35. data/lib/components/breadcrumb_link.rb +1 -1
  36. data/lib/components/breadcrumb_page.rb +1 -1
  37. data/lib/components/breadcrumb_separator.rb +1 -1
  38. data/lib/components/button.rb +1 -1
  39. data/lib/components/card.rb +1 -1
  40. data/lib/components/card_content.rb +1 -1
  41. data/lib/components/card_description.rb +1 -1
  42. data/lib/components/card_footer.rb +1 -1
  43. data/lib/components/card_header.rb +1 -1
  44. data/lib/components/card_title.rb +1 -1
  45. data/lib/components/checkbox.rb +14 -10
  46. data/lib/components/checkbox_group.rb +9 -8
  47. data/lib/components/collapsible.rb +2 -3
  48. data/lib/components/collapsible_content.rb +2 -3
  49. data/lib/components/collapsible_trigger.rb +5 -5
  50. data/lib/components/combobox.rb +57 -0
  51. data/lib/components/combobox_item.rb +9 -0
  52. data/lib/components/date_picker.rb +94 -0
  53. data/lib/components/date_range_picker.rb +113 -0
  54. data/lib/components/dialog.rb +1 -1
  55. data/lib/components/dialog_close.rb +1 -1
  56. data/lib/components/dialog_content.rb +2 -2
  57. data/lib/components/dialog_description.rb +1 -1
  58. data/lib/components/dialog_footer.rb +1 -1
  59. data/lib/components/dialog_header.rb +1 -1
  60. data/lib/components/dialog_title.rb +1 -1
  61. data/lib/components/dialog_trigger.rb +2 -2
  62. data/lib/components/dropdown_menu.rb +5 -5
  63. data/lib/components/dropdown_menu_content.rb +12 -9
  64. data/lib/components/dropdown_menu_item.rb +5 -6
  65. data/lib/components/dropdown_menu_item_to.rb +6 -3
  66. data/lib/components/dropdown_menu_label.rb +2 -3
  67. data/lib/components/dropdown_menu_separator.rb +5 -5
  68. data/lib/components/dropdown_menu_trigger.rb +9 -10
  69. data/lib/components/hover_card.rb +6 -6
  70. data/lib/components/hover_card_content.rb +8 -12
  71. data/lib/components/hover_card_trigger.rb +5 -11
  72. data/lib/components/input.rb +1 -1
  73. data/lib/components/label.rb +1 -2
  74. data/lib/components/link.rb +5 -2
  75. data/lib/components/loading_button.rb +1 -1
  76. data/lib/components/pagination.rb +4 -4
  77. data/lib/components/pagination_ellipsis.rb +3 -3
  78. data/lib/components/pagination_link.rb +5 -5
  79. data/lib/components/pagination_next.rb +5 -5
  80. data/lib/components/pagination_previous.rb +4 -4
  81. data/lib/components/popover.rb +6 -7
  82. data/lib/components/popover_content.rb +13 -10
  83. data/lib/components/popover_trigger.rb +5 -6
  84. data/lib/components/progress.rb +7 -7
  85. data/lib/components/radio_group.rb +4 -4
  86. data/lib/components/radio_group_item.rb +8 -8
  87. data/lib/components/select.rb +67 -72
  88. data/lib/components/select_content.rb +12 -7
  89. data/lib/components/select_group.rb +3 -3
  90. data/lib/components/select_item.rb +9 -8
  91. data/lib/components/select_label.rb +6 -5
  92. data/lib/components/select_trigger.rb +12 -10
  93. data/lib/components/separator.rb +3 -3
  94. data/lib/components/sheet.rb +9 -9
  95. data/lib/components/sheet_close.rb +4 -4
  96. data/lib/components/sheet_content.rb +13 -15
  97. data/lib/components/sheet_description.rb +3 -3
  98. data/lib/components/sheet_footer.rb +2 -2
  99. data/lib/components/sheet_header.rb +2 -2
  100. data/lib/components/sheet_title.rb +3 -3
  101. data/lib/components/sheet_trigger.rb +6 -6
  102. data/lib/components/sidebar.rb +30 -25
  103. data/lib/components/sidebar_container.rb +1 -1
  104. data/lib/components/sidebar_content.rb +1 -1
  105. data/lib/components/sidebar_footer.rb +2 -2
  106. data/lib/components/sidebar_group.rb +1 -1
  107. data/lib/components/sidebar_group_content.rb +1 -1
  108. data/lib/components/sidebar_group_label.rb +2 -2
  109. data/lib/components/sidebar_header.rb +2 -2
  110. data/lib/components/sidebar_inset.rb +1 -1
  111. data/lib/components/sidebar_menu.rb +2 -2
  112. data/lib/components/sidebar_menu_button.rb +5 -5
  113. data/lib/components/sidebar_menu_item.rb +1 -1
  114. data/lib/components/sidebar_menu_sub.rb +2 -2
  115. data/lib/components/sidebar_menu_sub_button.rb +7 -7
  116. data/lib/components/sidebar_menu_sub_item.rb +1 -1
  117. data/lib/components/sidebar_trigger.rb +5 -5
  118. data/lib/components/skeleton.rb +2 -2
  119. data/lib/components/switch.rb +10 -9
  120. data/lib/components/table.rb +7 -5
  121. data/lib/components/table_body.rb +2 -2
  122. data/lib/components/table_caption.rb +2 -2
  123. data/lib/components/table_cell.rb +2 -2
  124. data/lib/components/table_footer.rb +2 -2
  125. data/lib/components/table_head.rb +3 -3
  126. data/lib/components/table_header.rb +2 -2
  127. data/lib/components/table_row.rb +2 -2
  128. data/lib/components/tabs.rb +3 -3
  129. data/lib/components/tabs_content.rb +5 -5
  130. data/lib/components/tabs_list.rb +4 -4
  131. data/lib/components/tabs_trigger.rb +3 -3
  132. data/lib/components/textarea.rb +1 -1
  133. data/lib/components/theme_switcher.rb +2 -2
  134. data/lib/components/toast.rb +15 -14
  135. data/lib/components/toast_action.rb +5 -4
  136. data/lib/components/toast_action_to.rb +5 -2
  137. data/lib/components/toast_container.rb +5 -5
  138. data/lib/components/toast_content.rb +1 -1
  139. data/lib/components/toast_description.rb +1 -1
  140. data/lib/components/toast_title.rb +1 -1
  141. data/lib/components/tooltip.rb +8 -8
  142. data/lib/components/tooltip_content.rb +8 -11
  143. data/lib/components/tooltip_trigger.rb +9 -11
  144. data/lib/shadcn_phlexcomponents/alias.rb +3 -1
  145. data/lib/shadcn_phlexcomponents/version.rb +1 -1
  146. metadata +9 -4
  147. data/app/javascript/controllers/datepicker_controller.js +0 -47
  148. data/lib/components/datepicker.rb +0 -38
@@ -4,7 +4,7 @@ module ShadcnPhlexcomponents
4
4
  class Accordion < Base
5
5
  def initialize(value: nil, multiple: false, aria_id: "accordion-#{SecureRandom.hex(5)}", **attributes)
6
6
  @multiple = multiple
7
- @value = value && value.is_a?(String) ? [ value ] : value
7
+ @value = value&.is_a?(String) ? [value] : value
8
8
  @aria_id = aria_id
9
9
  super(**attributes)
10
10
  end
@@ -26,8 +26,8 @@ module ShadcnPhlexcomponents
26
26
  data: {
27
27
  value: (@value || []).to_json,
28
28
  multiple: @multiple.to_s,
29
- controller: "shadcn-phlexcomponents--accordion"
30
- }
29
+ controller: "shadcn-phlexcomponents--accordion",
30
+ },
31
31
  }
32
32
  end
33
33
 
@@ -10,17 +10,19 @@ module ShadcnPhlexcomponents
10
10
  end
11
11
 
12
12
  def view_template(&)
13
- div(class: "overflow-hidden text-sm data-[state=closed]:animate-accordion-up
13
+ div(
14
+ class: "overflow-hidden text-sm data-[state=closed]:animate-accordion-up
14
15
  data-[state=open]:animate-accordion-down hidden",
15
- id: "#{@aria_id}-content",
16
- role: "region",
17
- aria: {
18
- labelledby: "#{@aria_id}-trigger"
19
- },
20
- data: {
21
- state: "closed",
22
- "shadcn-phlexcomponents--accordion-target": "content"
23
- }) do
16
+ id: "#{@aria_id}-content",
17
+ role: "region",
18
+ aria: {
19
+ labelledby: "#{@aria_id}-trigger",
20
+ },
21
+ data: {
22
+ state: "closed",
23
+ "shadcn-phlexcomponents--accordion-target": "content",
24
+ },
25
+ ) do
24
26
  div(**@attributes, &)
25
27
  end
26
28
  end
@@ -4,7 +4,7 @@ module ShadcnPhlexcomponents
4
4
  class AccordionItem < Base
5
5
  STYLES = "border-b"
6
6
 
7
- def initialize(value:, **attributes)
7
+ def initialize(value:, **attributes)
8
8
  @value = value
9
9
  super(**attributes)
10
10
  end
@@ -14,8 +14,8 @@ module ShadcnPhlexcomponents
14
14
  data: {
15
15
  state: "closed",
16
16
  value: @value,
17
- "shadcn-phlexcomponents--accordion-target": "item"
18
- }
17
+ "shadcn-phlexcomponents--accordion-target": "item",
18
+ },
19
19
  }
20
20
  end
21
21
 
@@ -18,17 +18,17 @@ module ShadcnPhlexcomponents
18
18
  id: "#{@aria_id}-trigger",
19
19
  aria: {
20
20
  controls: "#{@aria_id}-content",
21
- expanded: "false"
21
+ expanded: "false",
22
22
  },
23
23
  data: {
24
24
  state: "closed",
25
25
  "shadcn-phlexcomponents--accordion-target": "trigger",
26
- action: <<~HEREDOC
26
+ action: <<~HEREDOC,
27
27
  click->shadcn-phlexcomponents--accordion#toggleItem
28
28
  keydown.up->shadcn-phlexcomponents--accordion#focusPrev:prevent
29
29
  keydown.down->shadcn-phlexcomponents--accordion#focusNext:prevent
30
30
  HEREDOC
31
- }
31
+ },
32
32
  }
33
33
  end
34
34
 
@@ -8,4 +8,4 @@ module ShadcnPhlexcomponents
8
8
  div(**@attributes, &)
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -36,7 +36,7 @@ module ShadcnPhlexcomponents
36
36
  def cancel(**attributes, &)
37
37
  AlertDialogCancel(**attributes, &)
38
38
  end
39
-
39
+
40
40
  def action(**attributes, &)
41
41
  AlertDialogAction(**attributes, &)
42
42
  end
@@ -57,4 +57,4 @@ module ShadcnPhlexcomponents
57
57
  div(**@attributes, &)
58
58
  end
59
59
  end
60
- end
60
+ end
@@ -14,9 +14,9 @@ module ShadcnPhlexcomponents
14
14
  },
15
15
  }
16
16
  end
17
-
17
+
18
18
  def view_template(&)
19
19
  Button(variant: @variant, **@attributes, &)
20
20
  end
21
21
  end
22
- end
22
+ end
@@ -21,7 +21,10 @@ module ShadcnPhlexcomponents
21
21
  end
22
22
 
23
23
  def view_template(&)
24
- @html_options, @options = @options, @name if block_given?
24
+ if block_given?
25
+ @html_options = @options
26
+ @options = @name
27
+ end
25
28
  @html_options ||= {}
26
29
  @variant = @html_options.delete(:variant) || :primary
27
30
  @html_options = mix(default_attributes, @html_options)
@@ -34,4 +37,4 @@ module ShadcnPhlexcomponents
34
37
  end
35
38
  end
36
39
  end
37
- end
40
+ end
@@ -19,4 +19,4 @@ module ShadcnPhlexcomponents
19
19
  Button(variant: @variant, **@attributes, &)
20
20
  end
21
21
  end
22
- end
22
+ end
@@ -37,4 +37,4 @@ module ShadcnPhlexcomponents
37
37
  div(class: "#{@class} hidden", **@attributes, &)
38
38
  end
39
39
  end
40
- end
40
+ end
@@ -19,4 +19,4 @@ module ShadcnPhlexcomponents
19
19
  p(**@attributes, &)
20
20
  end
21
21
  end
22
- end
22
+ end
@@ -8,4 +8,4 @@ module ShadcnPhlexcomponents
8
8
  div(**@attributes, &)
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -8,4 +8,4 @@ module ShadcnPhlexcomponents
8
8
  div(**@attributes, &)
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -19,4 +19,4 @@ module ShadcnPhlexcomponents
19
19
  h2(**@attributes, &)
20
20
  end
21
21
  end
22
- end
22
+ end
@@ -19,7 +19,7 @@ module ShadcnPhlexcomponents
19
19
  data: {
20
20
  action: "click->shadcn-phlexcomponents--alert-dialog#open",
21
21
  "shadcn-phlexcomponents--alert-dialog-target": "trigger",
22
- as_child: @as_child.to_s
22
+ as_child: @as_child.to_s,
23
23
  },
24
24
  }
25
25
  end
@@ -47,4 +47,4 @@ module ShadcnPhlexcomponents
47
47
  end
48
48
  end
49
49
  end
50
- end
50
+ end
@@ -16,4 +16,4 @@ module ShadcnPhlexcomponents
16
16
  end
17
17
  end
18
18
  end
19
- end
19
+ end
@@ -28,4 +28,4 @@ module ShadcnPhlexcomponents
28
28
  span(**@attributes, &)
29
29
  end
30
30
  end
31
- end
31
+ end
@@ -18,4 +18,4 @@ module ShadcnPhlexcomponents
18
18
  span(class: "#{@class} hidden", **@attributes, &)
19
19
  end
20
20
  end
21
- end
21
+ end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ShadcnPhlexcomponents
4
-
5
4
  class AvatarImage < Base
6
5
  STYLES = "aspect-square h-full w-full"
7
6
 
@@ -17,4 +16,4 @@ module ShadcnPhlexcomponents
17
16
  img(**@attributes, &)
18
17
  end
19
18
  end
20
- end
19
+ end
@@ -14,23 +14,17 @@ module ShadcnPhlexcomponents
14
14
  outline: "text-foreground",
15
15
  }.freeze
16
16
 
17
- class << self
18
- def default_styles(variant)
19
- "#{STYLES} #{VARIANTS[variant]}"
20
- end
21
- end
22
-
23
17
  def initialize(variant: :primary, **attributes)
24
18
  @variant = variant
25
19
  super(**attributes)
26
20
  end
27
21
 
28
22
  def default_styles
29
- self.class.default_styles(@variant)
23
+ "#{STYLES} #{VARIANTS[@variant]}"
30
24
  end
31
25
 
32
26
  def view_template(&)
33
27
  div(**@attributes, &)
34
28
  end
35
29
  end
36
- end
30
+ end
@@ -11,7 +11,7 @@ module ShadcnPhlexcomponents
11
11
  STYLES = ""
12
12
 
13
13
  SANITIZER_ALLOWED_TAGS = (Rails::HTML::SafeListSanitizer.allowed_tags.to_a +
14
- [ "svg", "path", "polygon", "polyline", "circle", "ellipse", "rect", "line", "use", "defs", "g" ]).freeze
14
+ ["svg", "path", "polygon", "polyline", "circle", "ellipse", "rect", "line", "use", "defs", "g"]).freeze
15
15
 
16
16
  SANITIZER_ALLOWED_ATTRIBUTES = (Rails::HTML::SafeListSanitizer.allowed_attributes.to_a +
17
17
  [
@@ -32,7 +32,7 @@ module ShadcnPhlexcomponents
32
32
  "stroke-width",
33
33
  "stroke-linecap",
34
34
  "aria-hidden",
35
- "class"
35
+ "class",
36
36
  ]).freeze
37
37
 
38
38
  def initialize(**attributes)
@@ -90,15 +90,15 @@ module ShadcnPhlexcomponents
90
90
  def icon(named, **options)
91
91
  options = options.with_indifferent_access
92
92
  size = options.delete(:size)
93
- options = options.merge width: size, height: size if size
93
+ options = options.merge(width: size, height: size) if size
94
94
 
95
95
  svg(**LucideRails.default_options.merge(**options)) { LucideRails::IconProvider.icon(named).html_safe }
96
96
  end
97
97
 
98
98
  def convert_collection_hash_to_struct(collection, value_method:, text_method:)
99
- structConstructor = Struct.new(value_method, text_method)
99
+ struct_constructor = Struct.new(value_method, text_method)
100
100
  collection.map do |item|
101
- struct = structConstructor.new
101
+ struct = struct_constructor.new
102
102
  struct[value_method] = item[value_method]
103
103
  struct[text_method] = item[text_method]
104
104
  struct
@@ -48,4 +48,4 @@ module ShadcnPhlexcomponents
48
48
  end
49
49
  end
50
50
  end
51
- end
51
+ end
@@ -20,4 +20,4 @@ module ShadcnPhlexcomponents
20
20
  end
21
21
  end
22
22
  end
23
- end
23
+ end
@@ -8,4 +8,4 @@ module ShadcnPhlexcomponents
8
8
  li(**@attributes, &)
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -4,4 +4,4 @@ module ShadcnPhlexcomponents
4
4
  class BreadcrumbLink < Link
5
5
  STYLES = "transition-colors hover:text-foreground"
6
6
  end
7
- end
7
+ end
@@ -18,4 +18,4 @@ module ShadcnPhlexcomponents
18
18
  span(**@attributes, &)
19
19
  end
20
20
  end
21
- end
21
+ end
@@ -23,4 +23,4 @@ module ShadcnPhlexcomponents
23
23
  end
24
24
  end
25
25
  end
26
- end
26
+ end
@@ -50,4 +50,4 @@ module ShadcnPhlexcomponents
50
50
  button(**@attributes, &)
51
51
  end
52
52
  end
53
- end
53
+ end
@@ -28,4 +28,4 @@ module ShadcnPhlexcomponents
28
28
  div(**@attributes, &)
29
29
  end
30
30
  end
31
- end
31
+ end
@@ -8,4 +8,4 @@ module ShadcnPhlexcomponents
8
8
  div(**@attributes, &)
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -8,4 +8,4 @@ module ShadcnPhlexcomponents
8
8
  div(**@attributes, &)
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -8,4 +8,4 @@ module ShadcnPhlexcomponents
8
8
  div(**@attributes, &)
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -8,4 +8,4 @@ module ShadcnPhlexcomponents
8
8
  div(**@attributes, &)
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -8,4 +8,4 @@ module ShadcnPhlexcomponents
8
8
  div(**@attributes, &)
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -2,14 +2,15 @@
2
2
 
3
3
  module ShadcnPhlexcomponents
4
4
  class Checkbox < Base
5
- STYLES = <<~HEREDOC.freeze
5
+ STYLES = <<~HEREDOC
6
6
  peer size-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none
7
7
  focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50
8
8
  data-[checked=true]:bg-primary data-[checked=true]:text-primary-foreground relative
9
9
  cursor-pointer group/checkbox
10
10
  HEREDOC
11
11
 
12
- def initialize(name: nil, value: "1", unchecked_value: "0", checked: false, id: nil, include_hidden: true, **attributes)
12
+ def initialize(name: nil, value: "1", unchecked_value: "0", checked: false, id: nil, include_hidden: true,
13
+ **attributes)
13
14
  @name = name
14
15
  @value = value
15
16
  @unchecked_value = unchecked_value
@@ -21,7 +22,7 @@ module ShadcnPhlexcomponents
21
22
 
22
23
  def view_template(&)
23
24
  button(**@attributes) do
24
- span(class: "absolute inset-0 items-center justify-center text-current
25
+ span(class: "absolute inset-0 items-center justify-center text-current
25
26
  pointer-events-none hidden group-data-[checked=true]/checkbox:flex") do
26
27
  icon("check", class: "size-4")
27
28
  end
@@ -31,7 +32,7 @@ module ShadcnPhlexcomponents
31
32
  end
32
33
 
33
34
  input(
34
- type: "checkbox",
35
+ type: "checkbox",
35
36
  value: @value,
36
37
  class: "-translate-x-full pointer-events-none absolute top-0 left-0 size-4 opacity-0",
37
38
  name: @name,
@@ -39,14 +40,14 @@ module ShadcnPhlexcomponents
39
40
  checked: @checked,
40
41
  aria: { hidden: true },
41
42
  data: {
42
- "shadcn-phlexcomponents--checkbox-target": "input"
43
- }
43
+ "shadcn-phlexcomponents--checkbox-target": "input",
44
+ },
44
45
  )
45
46
  end
46
47
  end
47
48
 
48
49
  def default_attributes
49
- {
50
+ {
50
51
  id: @id,
51
52
  type: "button",
52
53
  role: "checkbox",
@@ -56,10 +57,13 @@ module ShadcnPhlexcomponents
56
57
  data: {
57
58
  checked: @checked.to_s,
58
59
  controller: "shadcn-phlexcomponents--checkbox",
59
- action: "click->shadcn-phlexcomponents--checkbox#toggle keydown.enter->shadcn-phlexcomponents--checkbox#preventDefault",
60
+ action: <<~HEREDOC,
61
+ click->shadcn-phlexcomponents--checkbox#toggle
62
+ keydown.enter->shadcn-phlexcomponents--checkbox#preventDefault
63
+ HEREDOC
60
64
  "shadcn-phlexcomponents--checkbox-checked-value": @checked,
61
- }
65
+ },
62
66
  }
63
67
  end
64
68
  end
65
- end
69
+ end
@@ -14,7 +14,7 @@ module ShadcnPhlexcomponents
14
14
  def items(collection, value_method:, text_method:, wrapper_class: nil)
15
15
  wrapper_class = TAILWIND_MERGER.merge("flex items-center space-x-2 #{wrapper_class}")
16
16
 
17
- if collection.first && collection.first.is_a?(Hash)
17
+ if collection.first&.is_a?(Hash)
18
18
  collection = convert_collection_hash_to_struct(collection, value_method: value_method, text_method: text_method)
19
19
  end
20
20
 
@@ -24,12 +24,13 @@ module ShadcnPhlexcomponents
24
24
  id = "#{@name.parameterize.underscore}_#{value}"
25
25
 
26
26
  div(class: wrapper_class) do
27
- Checkbox(name: "#{@name}[]",
28
- id: id,
29
- value: value,
30
- checked: @value.include?(value),
31
- include_hidden: false
32
- )
27
+ Checkbox(
28
+ name: "#{@name}[]",
29
+ id: id,
30
+ value: value,
31
+ checked: @value.include?(value),
32
+ include_hidden: false,
33
+ )
33
34
  Label(for: id) { text }
34
35
  end
35
36
  end
@@ -45,4 +46,4 @@ module ShadcnPhlexcomponents
45
46
  end
46
47
  end
47
48
  end
48
- end
49
+ end
@@ -2,7 +2,6 @@
2
2
 
3
3
  module ShadcnPhlexcomponents
4
4
  class Collapsible < Base
5
-
6
5
  def initialize(open: false, aria_id: "collapsible-#{SecureRandom.hex(5)}", **attributes)
7
6
  @open = open
8
7
  @aria_id = aria_id
@@ -20,8 +19,8 @@ module ShadcnPhlexcomponents
20
19
  def default_attributes
21
20
  {
22
21
  data: {
23
- controller: "shadcn-phlexcomponents--collapsible"
24
- }
22
+ controller: "shadcn-phlexcomponents--collapsible",
23
+ },
25
24
  }
26
25
  end
27
26
 
@@ -2,7 +2,6 @@
2
2
 
3
3
  module ShadcnPhlexcomponents
4
4
  class CollapsibleContent < Base
5
-
6
5
  def initialize(aria_id: :nil, **attributes)
7
6
  @aria_id = aria_id
8
7
  super(**attributes)
@@ -12,8 +11,8 @@ module ShadcnPhlexcomponents
12
11
  {
13
12
  id: "#{@aria_id}-content",
14
13
  data: {
15
- "shadcn-phlexcomponents--collapsible-target": "content"
16
- }
14
+ "shadcn-phlexcomponents--collapsible-target": "content",
15
+ },
17
16
  }
18
17
  end
19
18
 
@@ -14,13 +14,13 @@ module ShadcnPhlexcomponents
14
14
  role: "button",
15
15
  aria: {
16
16
  expanded: @open.to_s,
17
- controls: "#{@aria_id}-content"
17
+ controls: "#{@aria_id}-content",
18
18
  },
19
19
  data: {
20
- state: @open ? "open" : 'closed',
20
+ state: @open ? "open" : "closed",
21
21
  action: "click->shadcn-phlexcomponents--collapsible#toggle",
22
- "shadcn-phlexcomponents--collapsible-target": "trigger"
23
- }
22
+ "shadcn-phlexcomponents--collapsible-target": "trigger",
23
+ },
24
24
  }
25
25
  end
26
26
 
@@ -39,7 +39,7 @@ module ShadcnPhlexcomponents
39
39
  merged_attributes.delete(:role)
40
40
  end
41
41
 
42
- send(element.name, **merged_attributes) do
42
+ send(element.name, **merged_attributes) do
43
43
  sanitize_as_child(element.children.to_s)
44
44
  end
45
45
  else
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShadcnPhlexcomponents
4
+ class Combobox < Base
5
+ def initialize(id: nil,
6
+ name: nil,
7
+ value: nil,
8
+ placeholder: nil,
9
+ disabled: false,
10
+ include_blank: false,
11
+ **attributes)
12
+ @id = id || name
13
+ @name = name
14
+ @value = value
15
+ @placeholder = placeholder
16
+ @include_blank = include_blank
17
+ @disabled = disabled
18
+ super(**attributes)
19
+ end
20
+
21
+ def item(**attributes, &)
22
+ ComboboxItem(**attributes, &)
23
+ end
24
+
25
+ def items(collection)
26
+ collection.each do |option|
27
+ ComboboxItem(value: option[:value], disabled: option[:disabled]) { option[:name] }
28
+ end
29
+ end
30
+
31
+ def view_template(&)
32
+ div(**@attributes) do
33
+ select(
34
+ id: @id,
35
+ name: @name,
36
+ disabled: @disabled,
37
+ data: { "shadcn-phlexcomponents--combobox-target": "select" },
38
+ ) do
39
+ option(value: "")
40
+
41
+ yield
42
+ end
43
+ end
44
+ end
45
+
46
+ def default_attributes
47
+ {
48
+ data: {
49
+ controller: "shadcn-phlexcomponents--combobox",
50
+ placeholder: @placeholder,
51
+ include_blank: @include_blank.to_s,
52
+ value: @value,
53
+ },
54
+ }
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShadcnPhlexcomponents
4
+ class ComboboxItem < Base
5
+ def view_template(&)
6
+ option(**@attributes, &)
7
+ end
8
+ end
9
+ end