rbui 0.0.0 → 1.0.0.pre.alpha.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rbui/accordion/accordion.rb +17 -0
  3. data/lib/rbui/accordion/accordion_content.rb +21 -0
  4. data/lib/rbui/accordion/accordion_default_content.rb +17 -0
  5. data/lib/rbui/accordion/accordion_default_trigger.rb +19 -0
  6. data/lib/rbui/accordion/accordion_icon.rb +38 -0
  7. data/lib/rbui/accordion/accordion_item.rb +28 -0
  8. data/lib/rbui/accordion/accordion_trigger.rb +16 -0
  9. data/lib/rbui/alert/alert.rb +36 -0
  10. data/lib/rbui/alert/alert_description.rb +17 -0
  11. data/lib/rbui/alert/alert_title.rb +17 -0
  12. data/lib/rbui/alert_dialog/alert_dialog.rb +26 -0
  13. data/lib/rbui/alert_dialog/alert_dialog_action.rb +17 -0
  14. data/lib/rbui/alert_dialog/alert_dialog_cancel.rb +21 -0
  15. data/lib/rbui/alert_dialog/alert_dialog_content.rb +45 -0
  16. data/lib/rbui/alert_dialog/alert_dialog_description.rb +17 -0
  17. data/lib/rbui/alert_dialog/alert_dialog_footer.rb +17 -0
  18. data/lib/rbui/alert_dialog/alert_dialog_header.rb +17 -0
  19. data/lib/rbui/alert_dialog/alert_dialog_title.rb +17 -0
  20. data/lib/rbui/alert_dialog/alert_dialog_trigger.rb +18 -0
  21. data/lib/rbui/aspect_ratio/aspect_ratio.rb +33 -0
  22. data/lib/rbui/avatar/avatar.rb +31 -0
  23. data/lib/rbui/avatar/avatar_fallback.rb +17 -0
  24. data/lib/rbui/avatar/avatar_image.rb +26 -0
  25. data/lib/rbui/badge/badge.rb +60 -0
  26. data/lib/rbui/base.rb +27 -0
  27. data/lib/rbui/button/button.rb +97 -0
  28. data/lib/rbui/calendar/calendar.rb +39 -0
  29. data/lib/rbui/calendar/calendar_body.rb +19 -0
  30. data/lib/rbui/calendar/calendar_days.rb +104 -0
  31. data/lib/rbui/calendar/calendar_header.rb +17 -0
  32. data/lib/rbui/calendar/calendar_next.rb +43 -0
  33. data/lib/rbui/calendar/calendar_prev.rb +43 -0
  34. data/lib/rbui/calendar/calendar_title.rb +27 -0
  35. data/lib/rbui/calendar/calendar_weekdays.rb +33 -0
  36. data/lib/rbui/card/card.rb +17 -0
  37. data/lib/rbui/card/card_content.rb +17 -0
  38. data/lib/rbui/card/card_description.rb +17 -0
  39. data/lib/rbui/card/card_footer.rb +17 -0
  40. data/lib/rbui/card/card_header.rb +17 -0
  41. data/lib/rbui/card/card_title.rb +17 -0
  42. data/lib/rbui/chart/chart.rb +23 -0
  43. data/lib/rbui/checkbox/checkbox.rb +23 -0
  44. data/lib/rbui/checkbox/checkbox_group.rb +20 -0
  45. data/lib/rbui/clipboard/clipboard.rb +42 -0
  46. data/lib/rbui/clipboard/clipboard_popover.rb +40 -0
  47. data/lib/rbui/clipboard/clipboard_source.rb +19 -0
  48. data/lib/rbui/clipboard/clipboard_trigger.rb +20 -0
  49. data/lib/rbui/codeblock/codeblock.rb +105 -0
  50. data/lib/rbui/collapsible/collapsible.rb +25 -0
  51. data/lib/rbui/collapsible/collapsible_content.rb +18 -0
  52. data/lib/rbui/collapsible/collapsible_trigger.rb +19 -0
  53. data/lib/rbui/combobox/combobox.rb +24 -0
  54. data/lib/rbui/combobox/combobox_content.rb +31 -0
  55. data/lib/rbui/combobox/combobox_empty.rb +21 -0
  56. data/lib/rbui/combobox/combobox_group.rb +38 -0
  57. data/lib/rbui/combobox/combobox_input.rb +22 -0
  58. data/lib/rbui/combobox/combobox_item.rb +53 -0
  59. data/lib/rbui/combobox/combobox_list.rb +29 -0
  60. data/lib/rbui/combobox/combobox_search_input.rb +56 -0
  61. data/lib/rbui/combobox/combobox_separator.rb +15 -0
  62. data/lib/rbui/combobox/combobox_trigger.rb +52 -0
  63. data/lib/rbui/combobox/combobox_value.rb +27 -0
  64. data/lib/rbui/command/command.rb +9 -0
  65. data/lib/rbui/command/command_dialog.rb +17 -0
  66. data/lib/rbui/command/command_dialog_content.rb +48 -0
  67. data/lib/rbui/command/command_dialog_trigger.rb +29 -0
  68. data/lib/rbui/command/command_empty.rb +19 -0
  69. data/lib/rbui/command/command_group.rb +40 -0
  70. data/lib/rbui/command/command_input.rb +56 -0
  71. data/lib/rbui/command/command_item.rb +32 -0
  72. data/lib/rbui/command/command_list.rb +17 -0
  73. data/lib/rbui/context_menu/context_menu.rb +26 -0
  74. data/lib/rbui/context_menu/context_menu_content.rb +25 -0
  75. data/lib/rbui/context_menu/context_menu_item.rb +66 -0
  76. data/lib/rbui/context_menu/context_menu_label.rb +24 -0
  77. data/lib/rbui/context_menu/context_menu_separator.rb +19 -0
  78. data/lib/rbui/context_menu/context_menu_trigger.rb +20 -0
  79. data/lib/rbui/dialog/dialog.rb +25 -0
  80. data/lib/rbui/dialog/dialog_content.rb +78 -0
  81. data/lib/rbui/dialog/dialog_description.rb +17 -0
  82. data/lib/rbui/dialog/dialog_footer.rb +17 -0
  83. data/lib/rbui/dialog/dialog_header.rb +17 -0
  84. data/lib/rbui/dialog/dialog_middle.rb +17 -0
  85. data/lib/rbui/dialog/dialog_title.rb +17 -0
  86. data/lib/rbui/dialog/dialog_trigger.rb +20 -0
  87. data/lib/rbui/dropdown_menu/dropdown_menu.rb +26 -0
  88. data/lib/rbui/dropdown_menu/dropdown_menu_content.rb +22 -0
  89. data/lib/rbui/dropdown_menu/dropdown_menu_item.rb +28 -0
  90. data/lib/rbui/dropdown_menu/dropdown_menu_label.rb +17 -0
  91. data/lib/rbui/dropdown_menu/dropdown_menu_separator.rb +19 -0
  92. data/lib/rbui/dropdown_menu/dropdown_menu_trigger.rb +18 -0
  93. data/lib/rbui/form/form.rb +15 -0
  94. data/lib/rbui/form/form_field.rb +20 -0
  95. data/lib/rbui/form/form_field_error.rb +20 -0
  96. data/lib/rbui/form/form_field_hint.rb +15 -0
  97. data/lib/rbui/form/form_field_label.rb +15 -0
  98. data/lib/rbui/hover_card/hover_card.rb +27 -0
  99. data/lib/rbui/hover_card/hover_card_content.rb +22 -0
  100. data/lib/rbui/hover_card/hover_card_trigger.rb +20 -0
  101. data/lib/rbui/input/input.rb +26 -0
  102. data/lib/rbui/link/link.rb +97 -0
  103. data/lib/rbui/pagination/pagination.rb +19 -0
  104. data/lib/rbui/pagination/pagination_content.rb +17 -0
  105. data/lib/rbui/pagination/pagination_ellipsis.rb +42 -0
  106. data/lib/rbui/pagination/pagination_item.rb +28 -0
  107. data/lib/rbui/popover/popover.rb +25 -0
  108. data/lib/rbui/popover/popover_content.rb +22 -0
  109. data/lib/rbui/popover/popover_trigger.rb +20 -0
  110. data/lib/rbui/radio_button/radio_button.rb +22 -0
  111. data/lib/rbui/select/select.rb +23 -0
  112. data/lib/rbui/select/select_content.rb +32 -0
  113. data/lib/rbui/select/select_group.rb +15 -0
  114. data/lib/rbui/select/select_input.rb +22 -0
  115. data/lib/rbui/select/select_item.rb +52 -0
  116. data/lib/rbui/select/select_label.rb +17 -0
  117. data/lib/rbui/select/select_trigger.rb +54 -0
  118. data/lib/rbui/select/select_value.rb +27 -0
  119. data/lib/rbui/sheet/sheet.rb +17 -0
  120. data/lib/rbui/sheet/sheet_content.rb +77 -0
  121. data/lib/rbui/sheet/sheet_description.rb +17 -0
  122. data/lib/rbui/sheet/sheet_footer.rb +17 -0
  123. data/lib/rbui/sheet/sheet_header.rb +17 -0
  124. data/lib/rbui/sheet/sheet_middle.rb +17 -0
  125. data/lib/rbui/sheet/sheet_title.rb +17 -0
  126. data/lib/rbui/sheet/sheet_trigger.rb +17 -0
  127. data/lib/rbui/shortcut_key/shortcut_key.rb +17 -0
  128. data/lib/rbui/table/table.rb +19 -0
  129. data/lib/rbui/table/table_body.rb +17 -0
  130. data/lib/rbui/table/table_caption.rb +17 -0
  131. data/lib/rbui/table/table_cell.rb +17 -0
  132. data/lib/rbui/table/table_footer.rb +17 -0
  133. data/lib/rbui/table/table_head.rb +17 -0
  134. data/lib/rbui/table/table_header.rb +17 -0
  135. data/lib/rbui/table/table_row.rb +17 -0
  136. data/lib/rbui/tabs/tabs.rb +25 -0
  137. data/lib/rbui/tabs/tabs_content.rb +26 -0
  138. data/lib/rbui/tabs/tabs_list.rb +17 -0
  139. data/lib/rbui/tabs/tabs_trigger.rb +28 -0
  140. data/lib/rbui/theme_toggle/theme_toggle.rb +41 -0
  141. data/lib/rbui/tooltip/tooltip.rb +26 -0
  142. data/lib/rbui/tooltip/tooltip_content.rb +26 -0
  143. data/lib/rbui/tooltip/tooltip_trigger.rb +19 -0
  144. data/lib/rbui/typography/typography_blockquote.rb +17 -0
  145. data/lib/rbui/typography/typography_h1.rb +17 -0
  146. data/lib/rbui/typography/typography_h2.rb +17 -0
  147. data/lib/rbui/typography/typography_h3.rb +17 -0
  148. data/lib/rbui/typography/typography_h4.rb +17 -0
  149. data/lib/rbui/typography/typography_inline_code.rb +17 -0
  150. data/lib/rbui/typography/typography_inline_link.rb +22 -0
  151. data/lib/rbui/typography/typography_large.rb +17 -0
  152. data/lib/rbui/typography/typography_lead.rb +17 -0
  153. data/lib/rbui/typography/typography_list.rb +47 -0
  154. data/lib/rbui/typography/typography_list_item.rb +17 -0
  155. data/lib/rbui/typography/typography_muted.rb +17 -0
  156. data/lib/rbui/typography/typography_p.rb +17 -0
  157. data/lib/rbui/typography/typography_small.rb +17 -0
  158. data/lib/rbui/version.rb +5 -0
  159. data/lib/rbui.rb +42 -3
  160. metadata +254 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f3131ea4a15099ea321929a2e78e72de8191a82f38c74f094d9a6eba86796a5
4
- data.tar.gz: 731f89b894ca93deb424316db772a120c00a97c1a67d88128e1cbf8da3606c29
3
+ metadata.gz: 794cdf4660f12d1e59c2c2d9f6652bc08142b19679b716b7455ef528ffe8de9a
4
+ data.tar.gz: cb8a388fc16a758575396ec1716a758614a341c70683ff5a83c4ff01d13e8360
5
5
  SHA512:
6
- metadata.gz: 37033795e0d1de250660fc90736524f34f2ca1e91e4ba8b5bcaa074b1364a72ce0e050f095cd1befed028acdc86e4ddc6195ac371326cd4a589332388cff9b95
7
- data.tar.gz: 261b4d3bd9c12f3320757b1e8a717199d0a39282d0d490646606442d31e94834a2579b40674febb0398b06a2eacd4188481ec1f40b5aaea8522e75427433e71c
6
+ metadata.gz: fac186cab781c5331efa8a88f510711f1b73455535e42b841e0d798b8548f66cd95498a6bfdf8ebf95570ef063ae611a6eae04c9915e14cfb17d4478b4b947fd
7
+ data.tar.gz: 43083c45bf22547efab83489001106102f82fce9ab07d61f4cd2f6047c3bcc0cc412360517367eb5ccfd7c5a19fa07b11dd36fde080df2149f6e8934c1ca6852
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBUI
4
+ class Accordion < Base
5
+ def view_template(&)
6
+ div(**attrs, &)
7
+ end
8
+
9
+ private
10
+
11
+ def default_attrs
12
+ {
13
+ class: "w-full"
14
+ }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBUI
4
+ class AccordionContent < Base
5
+ def view_template(&)
6
+ div(**attrs, &)
7
+ end
8
+
9
+ private
10
+
11
+ def default_attrs
12
+ {
13
+ data: {
14
+ rbui__accordion_target: "content"
15
+ },
16
+ class: "overflow-y-hidden",
17
+ style: "height: 0px;"
18
+ }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBUI
4
+ class AccordionDefaultContent < Base
5
+ def view_template(&)
6
+ div(**attrs, &)
7
+ end
8
+
9
+ private
10
+
11
+ def default_attrs
12
+ {
13
+ class: "pb-4 pt-0 text-sm"
14
+ }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBUI
4
+ class AccordionDefaultTrigger < Base
5
+ def view_template(&block)
6
+ div(class: "flex items-center justify-between w-full") do
7
+ p(&block)
8
+ RBUI.AccordionIcon
9
+ end
10
+ end
11
+
12
+ def default_attrs
13
+ {
14
+ data: {action: "click->rbui--accordion#toggle"},
15
+ class: "w-full flex flex-1 items-center justify-between py-4 text-sm font-medium transition-all hover:underline"
16
+ }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBUI
4
+ class AccordionIcon < Base
5
+ def view_template(&block)
6
+ span(**attrs) do
7
+ if block
8
+ block.call
9
+ else
10
+ icon
11
+ end
12
+ end
13
+ end
14
+
15
+ def icon
16
+ svg(
17
+ xmlns: "http://www.w3.org/2000/svg",
18
+ viewbox: "0 0 20 20",
19
+ fill: "currentColor",
20
+ class: "w-4 h-4"
21
+ ) do |s|
22
+ s.path(
23
+ fill_rule: "evenodd",
24
+ d:
25
+ "M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",
26
+ clip_rule: "evenodd"
27
+ )
28
+ end
29
+ end
30
+
31
+ def default_attrs
32
+ {
33
+ class: "opacity-50",
34
+ data: {rbui__accordion_target: "icon"}
35
+ }
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBUI
4
+ class AccordionItem < Base
5
+ def initialize(open: false, rotate_icon: 180, **attrs)
6
+ @open = open
7
+ @rotate_icon = rotate_icon
8
+ super(**attrs)
9
+ end
10
+
11
+ def view_template(&)
12
+ div(**attrs, &)
13
+ end
14
+
15
+ private
16
+
17
+ def default_attrs
18
+ {
19
+ data: {
20
+ controller: "rbui--accordion",
21
+ rbui__accordion_open_value: @open,
22
+ rbui__accordion_rotate_icon_value: @rotate_icon
23
+ },
24
+ class: "border-b"
25
+ }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBUI
4
+ class AccordionTrigger < Base
5
+ def view_template(&)
6
+ button(**attrs, &)
7
+ end
8
+
9
+ def default_attrs
10
+ {
11
+ data: {action: "click->rbui--accordion#toggle"},
12
+ class: "w-full flex flex-1 items-center justify-between py-4 text-sm font-medium transition-all hover:underline"
13
+ }
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBUI
4
+ class Alert < Base
5
+ def initialize(variant: nil, **attrs)
6
+ @variant = variant
7
+ super(**attrs) # must be called after variant is set
8
+ end
9
+
10
+ def view_template(&)
11
+ div(**attrs, &)
12
+ end
13
+
14
+ private
15
+
16
+ def colors
17
+ case @variant
18
+ when nil
19
+ "ring-border bg-muted/20 text-foreground [&>svg]:opacity-80"
20
+ when :warning
21
+ "ring-warning/20 bg-warning/5 text-warning [&>svg]:text-warning/80"
22
+ when :success
23
+ "ring-success/20 bg-success/5 text-success [&>svg]:text-success/80"
24
+ when :destructive
25
+ "ring-destructive/20 bg-destructive/5 text-destructive [&>svg]:text-destructive/80"
26
+ end
27
+ end
28
+
29
+ def default_attrs
30
+ base_classes = "backdrop-blur relative w-full ring-1 ring-inset rounded-lg px-4 py-4 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg~*]:pl-8"
31
+ {
32
+ class: tokens(base_classes, colors)
33
+ }
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBUI
4
+ class AlertDescription < Base
5
+ def view_template(&)
6
+ div(**attrs, &)
7
+ end
8
+
9
+ private
10
+
11
+ def default_attrs
12
+ {
13
+ class: "text-sm [&_p]:leading-relaxed"
14
+ }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBUI
4
+ class AlertTitle < Base
5
+ def view_template(&)
6
+ h5(**attrs, &)
7
+ end
8
+
9
+ private
10
+
11
+ def default_attrs
12
+ {
13
+ class: "mb-1 font-medium leading-none tracking-tight"
14
+ }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBUI
4
+ class AlertDialog < Base
5
+ def initialize(open: false, **attrs)
6
+ @open = open
7
+ super(**attrs)
8
+ end
9
+
10
+ def view_template(&)
11
+ div(**attrs, &)
12
+ end
13
+
14
+ private
15
+
16
+ def default_attrs
17
+ {
18
+ data: {
19
+ controller: "rbui--alert-dialog",
20
+ rbui__alert_dialog_open_value: @open.to_s
21
+ },
22
+ class: "inline-block"
23
+ }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBUI
4
+ class AlertDialogAction < Base
5
+ def view_template(&)
6
+ render RBUI::Button.new(**attrs, &)
7
+ end
8
+
9
+ private
10
+
11
+ def default_attrs
12
+ {
13
+ variant: :primary
14
+ }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBUI
4
+ class AlertDialogCancel < Base
5
+ def view_template(&)
6
+ render RBUI::Button.new(**attrs, &)
7
+ end
8
+
9
+ private
10
+
11
+ def default_attrs
12
+ {
13
+ variant: :outline,
14
+ data: {
15
+ action: "click->rbui--alert-dialog#dismiss"
16
+ },
17
+ class: "mt-2 sm:mt-0"
18
+ }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBUI
4
+ class AlertDialogContent < Base
5
+ def view_template(&block)
6
+ template_tag(**attrs) do
7
+ div(data: {controller: "rbui--alert-dialog"}) do
8
+ background
9
+ container(&block)
10
+ end
11
+ end
12
+ end
13
+
14
+ def background
15
+ div(
16
+ data_state: "open",
17
+ class:
18
+ "fixed inset-0 z-50 bg-black/80 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
19
+ style: "pointer-events:auto",
20
+ data_aria_hidden: "true",
21
+ aria_hidden: "true"
22
+ )
23
+ end
24
+
25
+ def container(&)
26
+ div(
27
+ role: "alertdialog",
28
+ data_state: "open",
29
+ class: "fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg md:w-full",
30
+ style: "pointer-events:auto",
31
+ &
32
+ )
33
+ end
34
+
35
+ private
36
+
37
+ def default_attrs
38
+ {
39
+ data: {
40
+ rbui__alert_dialog_target: "content"
41
+ }
42
+ }
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBUI
4
+ class AlertDialogDescription < Base
5
+ def view_template(&)
6
+ p(**attrs, &)
7
+ end
8
+
9
+ private
10
+
11
+ def default_attrs
12
+ {
13
+ class: "text-sm text-muted-foreground"
14
+ }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBUI
4
+ class AlertDialogFooter < Base
5
+ def view_template(&)
6
+ div(**attrs, &)
7
+ end
8
+
9
+ private
10
+
11
+ def default_attrs
12
+ {
13
+ class: "flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2"
14
+ }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBUI
4
+ class AlertDialogHeader < Base
5
+ def view_template(&)
6
+ div(**attrs, &)
7
+ end
8
+
9
+ private
10
+
11
+ def default_attrs
12
+ {
13
+ class: "flex flex-col space-y-2 text-center sm:text-left"
14
+ }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBUI
4
+ class AlertDialogTitle < Base
5
+ def view_template(&)
6
+ h2(**attrs, &)
7
+ end
8
+
9
+ private
10
+
11
+ def default_attrs
12
+ {
13
+ class: "text-lg font-semibold"
14
+ }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBUI
4
+ class AlertDialogTrigger < Base
5
+ def view_template(&)
6
+ div(**attrs, &)
7
+ end
8
+
9
+ private
10
+
11
+ def default_attrs
12
+ {
13
+ data: {action: "click->rbui--alert-dialog#open"},
14
+ class: "inline-block"
15
+ }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBUI
4
+ class AspectRatio < Base
5
+ def initialize(aspect_ratio: "16/9", **attrs)
6
+ raise "aspect_ratio must be in the format of a string with a slash in the middle (eg. '16/9', '1/1')" unless aspect_ratio.is_a?(String) && aspect_ratio.include?("/")
7
+
8
+ @aspect_ratio = aspect_ratio
9
+ super(**attrs)
10
+ end
11
+
12
+ def view_template(&block)
13
+ div(
14
+ class: "relative w-full",
15
+ style: "padding-bottom: #{padding_bottom}%;"
16
+ ) do
17
+ div(**attrs, &block)
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def padding_bottom
24
+ @aspect_ratio.split("/").map(&:to_i).reverse.reduce(&:fdiv) * 100
25
+ end
26
+
27
+ def default_attrs
28
+ {
29
+ class: "bg-muted absolute inset-0 [&>img]:object-cover [&>img]:absolute [&>img]:h-full [&>img]:w-full [&>img]:inset-0 [&>img]:text-transparent"
30
+ }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBUI
4
+ class Avatar < Base
5
+ SIZES = {
6
+ xs: "h-4 w-4 text-[0.5rem]",
7
+ sm: "h-6 w-6 text-xs",
8
+ md: "h-10 w-10 text-base",
9
+ lg: "h-14 w-14 text-xl",
10
+ xl: "h-20 w-20 text-3xl"
11
+ }
12
+
13
+ def initialize(size: :md, **attrs)
14
+ @size = size
15
+ @size_classes = SIZES[@size]
16
+ super(**attrs)
17
+ end
18
+
19
+ def view_template(&)
20
+ span(**attrs, &)
21
+ end
22
+
23
+ private
24
+
25
+ def default_attrs
26
+ {
27
+ class: tokens("relative flex shrink-0 overflow-hidden rounded-full", @size_classes)
28
+ }
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBUI
4
+ class AvatarFallback < Base
5
+ def view_template(&)
6
+ span(**attrs, &)
7
+ end
8
+
9
+ private
10
+
11
+ def default_attrs
12
+ {
13
+ class: "flex h-full w-full items-center justify-center rounded-full bg-muted"
14
+ }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBUI
4
+ class AvatarImage < Base
5
+ def initialize(src:, alt: "", **attrs)
6
+ @src = src
7
+ @alt = alt
8
+ super(**attrs)
9
+ end
10
+
11
+ def view_template
12
+ img(**attrs)
13
+ end
14
+
15
+ private
16
+
17
+ def default_attrs
18
+ {
19
+ loading: "lazy",
20
+ class: "aspect-square h-full w-full",
21
+ alt: @alt,
22
+ src: @src
23
+ }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBUI
4
+ class Badge < Base
5
+ SIZES = {
6
+ sm: "px-1.5 py-0.5 text-xs",
7
+ md: "px-2 py-1 text-xs",
8
+ lg: "px-3 py-1 text-sm"
9
+ }
10
+
11
+ COLORS = {
12
+ primary: "text-primary bg-primary/5 ring-primary/20",
13
+ secondary: "text-secondary bg-secondary/10 ring-secondary/20",
14
+ outline: "text-foreground bg-background ring-border",
15
+ destructive: "text-destructive bg-destructive/10 ring-destructive/20",
16
+ success: "text-success bg-success/10 ring-success/20",
17
+ warning: "text-warning bg-warning/10 ring-warning/20",
18
+ slate: "text-slate-500 bg-slate-500/10 ring-slate-500/20",
19
+ gray: "text-gray-500 bg-gray-500/10 ring-gray-500/20",
20
+ zinc: "text-zinc-500 bg-zinc-500/10 ring-zinc-500/20",
21
+ neutral: "text-neutral-500 bg-neutral-500/10 ring-neutral-500/20",
22
+ stone: "text-stone-500 bg-stone-500/10 ring-stone-500/20",
23
+ red: "text-red-500 bg-red-500/10 ring-red-500/20",
24
+ orange: "text-orange-500 bg-orange-500/10 ring-orange-500/20",
25
+ amber: "text-amber-500 bg-amber-500/10 ring-amber-500/20",
26
+ yellow: "text-yellow-500 bg-yellow-500/10 ring-yellow-500/20",
27
+ lime: "text-lime-500 bg-lime-500/10 ring-lime-500/20",
28
+ green: "text-green-500 bg-green-500/10 ring-green-500/20",
29
+ emerald: "text-emerald-500 bg-emerald-500/10 ring-emerald-500/20",
30
+ teal: "text-teal-500 bg-teal-500/10 ring-teal-500/20",
31
+ cyan: "text-cyan-500 bg-cyan-500/10 ring-cyan-500/20",
32
+ sky: "text-sky-500 bg-sky-500/10 ring-sky-500/20",
33
+ blue: "text-blue-500 bg-blue-500/10 ring-blue-500/20",
34
+ indigo: "text-indigo-500 bg-indigo-500/10 ring-indigo-500/20",
35
+ violet: "text-violet-500 bg-violet-500/10 ring-violet-500/20",
36
+ purple: "text-purple-500 bg-purple-500/10 ring-purple-500/20",
37
+ fuchsia: "text-fuchsia-500 bg-fuchsia-500/10 ring-fuchsia-500/20",
38
+ pink: "text-pink-500 bg-pink-500/10 ring-pink-500/20",
39
+ rose: "text-rose-500 bg-rose-500/10 ring-rose-500/20"
40
+ }
41
+
42
+ def initialize(variant: :primary, size: :md, **args)
43
+ @variant = variant
44
+ @size = size
45
+ super(**args)
46
+ end
47
+
48
+ def view_template(&)
49
+ span(**attrs, &)
50
+ end
51
+
52
+ private
53
+
54
+ def default_attrs
55
+ {
56
+ class: tokens("inline-flex items-center rounded-md font-medium ring-1 ring-inset", SIZES[@size], COLORS[@variant])
57
+ }
58
+ end
59
+ end
60
+ end
data/lib/rbui/base.rb ADDED
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tailwind_merge"
4
+
5
+ module RBUI
6
+ class Base < Phlex::HTML
7
+ attr_reader :attrs
8
+
9
+ def initialize(**user_attrs)
10
+ @attrs = mix(default_attrs, user_attrs)
11
+ @attrs[:class] = ::TailwindMerge::Merger.new.merge(@attrs[:class]) if @attrs[:class]
12
+ end
13
+
14
+ if defined?(Rails) && Rails.env.development?
15
+ def before_template
16
+ comment { "Before #{self.class.name}" }
17
+ super
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def default_attrs
24
+ {}
25
+ end
26
+ end
27
+ end