phlex_ui 0.0.5 → 0.1.6

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 (149) hide show
  1. checksums.yaml +4 -4
  2. data/lib/phlex_ui/accordion/builder.rb +22 -0
  3. data/lib/phlex_ui/accordion/content.rb +15 -15
  4. data/lib/phlex_ui/accordion/default_content.rb +11 -11
  5. data/lib/phlex_ui/accordion/default_trigger.rb +14 -14
  6. data/lib/phlex_ui/accordion/icon.rb +31 -31
  7. data/lib/phlex_ui/accordion/item.rb +20 -20
  8. data/lib/phlex_ui/accordion/trigger.rb +11 -11
  9. data/lib/phlex_ui/accordion.rb +10 -21
  10. data/lib/phlex_ui/alert/description.rb +10 -10
  11. data/lib/phlex_ui/alert/title.rb +10 -10
  12. data/lib/phlex_ui/alert.rb +27 -27
  13. data/lib/phlex_ui/alert_dialog/action.rb +11 -11
  14. data/lib/phlex_ui/alert_dialog/cancel.rb +15 -15
  15. data/lib/phlex_ui/alert_dialog/content.rb +36 -36
  16. data/lib/phlex_ui/alert_dialog/description.rb +11 -11
  17. data/lib/phlex_ui/alert_dialog/footer.rb +11 -11
  18. data/lib/phlex_ui/alert_dialog/header.rb +11 -11
  19. data/lib/phlex_ui/alert_dialog/title.rb +11 -11
  20. data/lib/phlex_ui/alert_dialog/trigger.rb +12 -12
  21. data/lib/phlex_ui/alert_dialog.rb +18 -18
  22. data/lib/phlex_ui/aspect_ratio.rb +24 -24
  23. data/lib/phlex_ui/attribute_merger.rb +59 -61
  24. data/lib/phlex_ui/avatar/builder.rb +36 -0
  25. data/lib/phlex_ui/avatar/fallback.rb +11 -11
  26. data/lib/phlex_ui/avatar/image.rb +19 -19
  27. data/lib/phlex_ui/avatar.rb +23 -41
  28. data/lib/phlex_ui/badge.rb +50 -50
  29. data/lib/phlex_ui/base.rb +16 -16
  30. data/lib/phlex_ui/button.rb +80 -80
  31. data/lib/phlex_ui/calendar/body.rb +19 -0
  32. data/lib/phlex_ui/calendar/days.rb +104 -0
  33. data/lib/phlex_ui/calendar/header.rb +17 -0
  34. data/lib/phlex_ui/calendar/next.rb +43 -0
  35. data/lib/phlex_ui/calendar/prev.rb +43 -0
  36. data/lib/phlex_ui/calendar/title.rb +27 -0
  37. data/lib/phlex_ui/calendar/weekdays.rb +33 -0
  38. data/lib/phlex_ui/calendar.rb +39 -0
  39. data/lib/phlex_ui/card/content.rb +11 -11
  40. data/lib/phlex_ui/card/description.rb +11 -11
  41. data/lib/phlex_ui/card/footer.rb +11 -11
  42. data/lib/phlex_ui/card/header.rb +11 -11
  43. data/lib/phlex_ui/card/title.rb +11 -11
  44. data/lib/phlex_ui/card.rb +11 -11
  45. data/lib/phlex_ui/chart.rb +23 -0
  46. data/lib/phlex_ui/checkbox.rb +12 -12
  47. data/lib/phlex_ui/clipboard/popover.rb +28 -28
  48. data/lib/phlex_ui/clipboard/source.rb +13 -13
  49. data/lib/phlex_ui/clipboard/trigger.rb +14 -14
  50. data/lib/phlex_ui/clipboard.rb +30 -30
  51. data/lib/phlex_ui/codeblock.rb +86 -86
  52. data/lib/phlex_ui/collapsible/content.rb +12 -12
  53. data/lib/phlex_ui/collapsible/trigger.rb +13 -13
  54. data/lib/phlex_ui/collapsible.rb +18 -18
  55. data/lib/phlex_ui/command/dialog.rb +17 -0
  56. data/lib/phlex_ui/command/dialog_content.rb +49 -0
  57. data/lib/phlex_ui/command/dialog_trigger.rb +29 -0
  58. data/lib/phlex_ui/command/empty.rb +19 -0
  59. data/lib/phlex_ui/command/group.rb +41 -0
  60. data/lib/phlex_ui/command/input.rb +56 -0
  61. data/lib/phlex_ui/command/item.rb +31 -0
  62. data/lib/phlex_ui/command/list.rb +17 -0
  63. data/lib/phlex_ui/command.rb +17 -0
  64. data/lib/phlex_ui/context_menu/content.rb +19 -19
  65. data/lib/phlex_ui/context_menu/item.rb +55 -55
  66. data/lib/phlex_ui/context_menu/label.rb +16 -16
  67. data/lib/phlex_ui/context_menu/separator.rb +13 -13
  68. data/lib/phlex_ui/context_menu/trigger.rb +14 -14
  69. data/lib/phlex_ui/context_menu.rb +19 -19
  70. data/lib/phlex_ui/dialog/content.rb +67 -67
  71. data/lib/phlex_ui/dialog/description.rb +11 -11
  72. data/lib/phlex_ui/dialog/footer.rb +11 -11
  73. data/lib/phlex_ui/dialog/header.rb +11 -11
  74. data/lib/phlex_ui/dialog/middle.rb +11 -11
  75. data/lib/phlex_ui/dialog/title.rb +11 -11
  76. data/lib/phlex_ui/dialog/trigger.rb +14 -13
  77. data/lib/phlex_ui/dialog.rb +18 -18
  78. data/lib/phlex_ui/dropdown_menu/content.rb +16 -16
  79. data/lib/phlex_ui/dropdown_menu/item.rb +21 -21
  80. data/lib/phlex_ui/dropdown_menu/label.rb +11 -11
  81. data/lib/phlex_ui/dropdown_menu/separator.rb +13 -13
  82. data/lib/phlex_ui/dropdown_menu/trigger.rb +12 -11
  83. data/lib/phlex_ui/dropdown_menu.rb +19 -19
  84. data/lib/phlex_ui/form/builder.rb +38 -0
  85. data/lib/phlex_ui/form/item.rb +11 -11
  86. data/lib/phlex_ui/form/spacer.rb +11 -11
  87. data/lib/phlex_ui/form.rb +9 -28
  88. data/lib/phlex_ui/hint.rb +11 -11
  89. data/lib/phlex_ui/hover_card/content.rb +16 -16
  90. data/lib/phlex_ui/hover_card/trigger.rb +14 -13
  91. data/lib/phlex_ui/hover_card.rb +20 -20
  92. data/lib/phlex_ui/input.rb +22 -22
  93. data/lib/phlex_ui/input_error.rb +11 -11
  94. data/lib/phlex_ui/label.rb +11 -11
  95. data/lib/phlex_ui/link.rb +81 -81
  96. data/lib/phlex_ui/popover/content.rb +16 -16
  97. data/lib/phlex_ui/popover/trigger.rb +14 -13
  98. data/lib/phlex_ui/popover.rb +18 -18
  99. data/lib/phlex_ui/select/builder.rb +67 -0
  100. data/lib/phlex_ui/select/content.rb +30 -0
  101. data/lib/phlex_ui/select/group.rb +15 -0
  102. data/lib/phlex_ui/select/input.rb +20 -0
  103. data/lib/phlex_ui/select/item.rb +48 -0
  104. data/lib/phlex_ui/select/label.rb +17 -0
  105. data/lib/phlex_ui/select/trigger.rb +45 -0
  106. data/lib/phlex_ui/select/value.rb +27 -0
  107. data/lib/phlex_ui/select.rb +30 -0
  108. data/lib/phlex_ui/sheet/content.rb +77 -0
  109. data/lib/phlex_ui/sheet/description.rb +17 -0
  110. data/lib/phlex_ui/sheet/footer.rb +17 -0
  111. data/lib/phlex_ui/sheet/header.rb +17 -0
  112. data/lib/phlex_ui/sheet/middle.rb +17 -0
  113. data/lib/phlex_ui/sheet/title.rb +17 -0
  114. data/lib/phlex_ui/sheet/trigger.rb +17 -0
  115. data/lib/phlex_ui/sheet.rb +17 -0
  116. data/lib/phlex_ui/shortcut_key.rb +11 -11
  117. data/lib/phlex_ui/table/body.rb +11 -11
  118. data/lib/phlex_ui/table/builder.rb +59 -59
  119. data/lib/phlex_ui/table/caption.rb +11 -11
  120. data/lib/phlex_ui/table/cell.rb +11 -11
  121. data/lib/phlex_ui/table/footer.rb +11 -11
  122. data/lib/phlex_ui/table/head.rb +11 -11
  123. data/lib/phlex_ui/table/header.rb +11 -11
  124. data/lib/phlex_ui/table/row.rb +11 -11
  125. data/lib/phlex_ui/table.rb +13 -13
  126. data/lib/phlex_ui/tabs/content.rb +18 -18
  127. data/lib/phlex_ui/tabs/list.rb +11 -11
  128. data/lib/phlex_ui/tabs/trigger.rb +20 -20
  129. data/lib/phlex_ui/tabs.rb +17 -17
  130. data/lib/phlex_ui/theme_toggle.rb +31 -31
  131. data/lib/phlex_ui/tooltip/content.rb +16 -16
  132. data/lib/phlex_ui/tooltip/trigger.rb +12 -11
  133. data/lib/phlex_ui/tooltip.rb +18 -18
  134. data/lib/phlex_ui/typography/blockquote.rb +11 -11
  135. data/lib/phlex_ui/typography/h1.rb +10 -10
  136. data/lib/phlex_ui/typography/h2.rb +10 -10
  137. data/lib/phlex_ui/typography/h3.rb +11 -11
  138. data/lib/phlex_ui/typography/h4.rb +11 -11
  139. data/lib/phlex_ui/typography/inline_code.rb +11 -11
  140. data/lib/phlex_ui/typography/inline_link.rb +22 -0
  141. data/lib/phlex_ui/typography/large.rb +11 -11
  142. data/lib/phlex_ui/typography/lead.rb +11 -11
  143. data/lib/phlex_ui/typography/list.rb +36 -36
  144. data/lib/phlex_ui/typography/list_item.rb +11 -11
  145. data/lib/phlex_ui/typography/muted.rb +11 -11
  146. data/lib/phlex_ui/typography/p.rb +11 -11
  147. data/lib/phlex_ui/typography/small.rb +11 -11
  148. data/lib/phlex_ui.rb +9 -4
  149. metadata +88 -7
@@ -1,17 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PhlexUI
4
- class AlertDialog::Header < Base
5
- def template(&)
6
- div(**attrs, &)
7
- end
4
+ class AlertDialog::Header < Base
5
+ def template(&block)
6
+ div(**attrs, &block)
7
+ end
8
8
 
9
- private
9
+ private
10
10
 
11
- def default_attrs
12
- {
13
- class: "flex flex-col space-y-2 text-center sm:text-left"
14
- }
15
- end
11
+ def default_attrs
12
+ {
13
+ class: "flex flex-col space-y-2 text-center sm:text-left"
14
+ }
16
15
  end
17
- end
16
+ end
17
+ end
@@ -1,17 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PhlexUI
4
- class AlertDialog::Title < Base
5
- def template(&)
6
- h2(**attrs, &)
7
- end
4
+ class AlertDialog::Title < Base
5
+ def template(&block)
6
+ h2(**attrs, &block)
7
+ end
8
8
 
9
- private
9
+ private
10
10
 
11
- def default_attrs
12
- {
13
- class: "text-lg font-semibold"
14
- }
15
- end
11
+ def default_attrs
12
+ {
13
+ class: "text-lg font-semibold"
14
+ }
16
15
  end
17
- end
16
+ end
17
+ end
@@ -1,18 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PhlexUI
4
- class AlertDialog::Trigger < Base
5
- def template(&)
6
- div(**attrs, &)
7
- end
4
+ class AlertDialog::Trigger < Base
5
+ def template(&block)
6
+ div(**attrs, &block)
7
+ end
8
8
 
9
- private
9
+ private
10
10
 
11
- def default_attrs
12
- {
13
- data: { action: "click->alert-dialog#open" },
14
- class: 'inline-block'
15
- }
16
- end
11
+ def default_attrs
12
+ {
13
+ data: {action: "click->alert-dialog#open"},
14
+ class: "inline-block"
15
+ }
17
16
  end
18
- end
17
+ end
18
+ end
@@ -1,26 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PhlexUI
4
- class AlertDialog < Base
5
- def initialize(open: false, **attrs)
6
- @open = open
7
- super(**attrs)
8
- end
4
+ class AlertDialog < Base
5
+ def initialize(open: false, **attrs)
6
+ @open = open
7
+ super(**attrs)
8
+ end
9
9
 
10
- def template(&)
11
- div(**attrs, &)
12
- end
10
+ def template(&block)
11
+ div(**attrs, &block)
12
+ end
13
13
 
14
- private
14
+ private
15
15
 
16
- def default_attrs
17
- {
18
- data: {
19
- controller: 'alert-dialog',
20
- alert_dialog_open_value: @open
21
- },
22
- class: 'inline-block'
23
- }
24
- end
16
+ def default_attrs
17
+ {
18
+ data: {
19
+ controller: "alert-dialog",
20
+ alert_dialog_open_value: @open
21
+ },
22
+ class: "inline-block"
23
+ }
25
24
  end
25
+ end
26
26
  end
@@ -1,33 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PhlexUI
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?("/")
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
7
 
8
- @aspect_ratio = aspect_ratio
9
- super(**attrs)
10
- end
8
+ @aspect_ratio = aspect_ratio
9
+ super(**attrs)
10
+ end
11
11
 
12
- def template(&)
13
- div(
14
- class: "relative w-full",
15
- style: "padding-bottom: #{padding_bottom}%;",
16
- ) do
17
- div(**attrs, &)
18
- end
19
- end
12
+ def 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
20
 
21
- private
21
+ private
22
22
 
23
- def padding_bottom
24
- @aspect_ratio.split("/").map(&:to_i).reverse.reduce(&:fdiv) * 100
25
- end
23
+ def padding_bottom
24
+ @aspect_ratio.split("/").map(&:to_i).reverse.reduce(&:fdiv) * 100
25
+ end
26
26
 
27
- def default_attrs
28
- {
29
- class: "bg-muted-background absolute inset-0 [&>img]:object-cover [&>img]:absolute [&>img]:h-full [&>img]:w-full [&>img]:inset-0 [&>img]:text-transparent"
30
- }
31
- end
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
+ }
32
31
  end
33
- end
32
+ end
33
+ end
@@ -1,75 +1,73 @@
1
1
  module PhlexUI
2
- class AttributeMerger
3
- attr_reader :default_attrs, :user_attrs
4
- OVERRIDE_KEY = '!'.freeze
2
+ class AttributeMerger
3
+ attr_reader :default_attrs, :user_attrs
4
+ OVERRIDE_KEY = "!".freeze
5
5
 
6
- def initialize(default_attrs, user_attrs)
7
- @default_attrs = flatten_hash(default_attrs)
8
- @user_attrs = flatten_hash(user_attrs)
9
- end
10
-
11
- def call
12
- merged_attrs = merge_hashes(default_attrs, non_override_attrs)
13
- mix(merged_attrs, override_attrs)
14
- end
6
+ def initialize(default_attrs, user_attrs)
7
+ @default_attrs = flatten_hash(default_attrs)
8
+ @user_attrs = flatten_hash(user_attrs)
9
+ end
15
10
 
16
- private
11
+ def call
12
+ merged_attrs = merge_hashes(default_attrs, non_override_attrs)
13
+ mix(merged_attrs, override_attrs)
14
+ end
17
15
 
18
- # @return [Hash]
19
- def mix(*args)
20
- args.each_with_object({}) do |object, result|
21
- result.merge!(object) do |_key, old, new|
22
- case new
23
- when Hash
24
- old.is_a?(Hash) ? mix(old, new) : new
25
- when Array
26
- old.is_a?(Array) ? (old + new) : new
27
- when String
28
- old.is_a?(String) ? "#{old} #{new}" : new
29
- else
30
- new
31
- end
32
- end
16
+ private
33
17
 
34
- result.transform_keys! do |key|
35
- key.end_with?("!") ? key.name.chop.to_sym : key
36
- end
37
- end
18
+ # @return [Hash]
19
+ def mix(*args)
20
+ args.each_with_object({}) do |object, result|
21
+ result.merge!(object) do |_key, old, new|
22
+ case new
23
+ when Hash
24
+ old.is_a?(Hash) ? mix(old, new) : new
25
+ when Array
26
+ old.is_a?(Array) ? (old + new) : new
27
+ when String
28
+ old.is_a?(String) ? "#{old} #{new}" : new
29
+ else
30
+ new
31
+ end
38
32
  end
39
33
 
40
- def override_attrs
41
- user_attrs.select do |key, value|
42
- key.to_s.include?(OVERRIDE_KEY)
43
- end
34
+ result.transform_keys! do |key|
35
+ key.end_with?("!") ? key.name.chop.to_sym : key
44
36
  end
37
+ end
38
+ end
45
39
 
46
- def non_override_attrs
47
- user_attrs.reject do |key, value|
48
- key.to_s.include?(OVERRIDE_KEY)
49
- end
50
- end
40
+ def override_attrs
41
+ user_attrs.select do |key, value|
42
+ key.to_s.include?(OVERRIDE_KEY)
43
+ end
44
+ end
51
45
 
52
- def flatten_hash(hash, parent_key = '', result_hash = {})
53
- hash.each do |key, value|
54
- new_key = parent_key.empty? ? key : "#{parent_key}_#{key}".to_sym
55
- if value.is_a? Hash
56
- flatten_hash(value, new_key, result_hash)
57
- else
58
- result_hash[new_key] = value
59
- end
60
- end
61
- result_hash
62
- end
46
+ def non_override_attrs
47
+ user_attrs.reject do |key, value|
48
+ key.to_s.include?(OVERRIDE_KEY)
49
+ end
50
+ end
63
51
 
64
- def merge_hashes(hash1, hash2)
65
- flat_hash1 = flatten_hash(hash1)
66
- flat_hash2 = flatten_hash(hash2)
52
+ def flatten_hash(hash, parent_key = "", result_hash = {})
53
+ hash.each do |key, value|
54
+ new_key = parent_key.empty? ? key : :"#{parent_key}_#{key}"
55
+ if value.is_a? Hash
56
+ flatten_hash(value, new_key, result_hash)
57
+ else
58
+ result_hash[new_key] = value
59
+ end
60
+ end
61
+ result_hash
62
+ end
67
63
 
68
- merged = flat_hash1.merge(flat_hash2) do |key, oldval, newval|
69
- "#{oldval} #{newval}"
70
- end
64
+ def merge_hashes(hash1, hash2)
65
+ flat_hash1 = flatten_hash(hash1)
66
+ flat_hash2 = flatten_hash(hash2)
71
67
 
72
- merged
73
- end
68
+ flat_hash1.merge(flat_hash2) do |key, oldval, newval|
69
+ "#{oldval} #{newval}"
70
+ end
74
71
  end
75
- end
72
+ end
73
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PhlexUI
4
+ class Avatar::Builder < Base
5
+ def initialize(size: :md, src: nil, alt: nil, initials: nil, **attrs)
6
+ @size = size
7
+ @src = src
8
+ @alt = alt
9
+ @initials = initials
10
+ super(**attrs)
11
+ end
12
+
13
+ def template
14
+ render PhlexUI::Avatar.new(size: @size, **attrs) do
15
+ render_image if @src
16
+ render_initials if @initials
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def render_image
23
+ render ::PhlexUI::Avatar::Image.new(src: @src, alt: @alt)
24
+ end
25
+
26
+ def render_initials
27
+ render ::PhlexUI::Avatar::Fallback.new { @initials }
28
+ end
29
+
30
+ def default_attrs
31
+ {
32
+ class: tokens("relative flex shrink-0 overflow-hidden rounded-full", @size_classes)
33
+ }
34
+ end
35
+ end
36
+ end
@@ -1,17 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PhlexUI
4
- class Avatar::Fallback < Base
5
- def template(&)
6
- span(**attrs, &)
7
- end
4
+ class Avatar::Fallback < Base
5
+ def template(&block)
6
+ span(**attrs, &block)
7
+ end
8
8
 
9
- private
9
+ private
10
10
 
11
- def default_attrs
12
- {
13
- class: "flex h-full w-full items-center justify-center rounded-full bg-muted-background"
14
- }
15
- end
11
+ def default_attrs
12
+ {
13
+ class: "flex h-full w-full items-center justify-center rounded-full bg-muted"
14
+ }
16
15
  end
17
- end
16
+ end
17
+ end
@@ -1,26 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PhlexUI
4
- class Avatar::Image < Base
5
- def initialize(src:, alt: '', **attrs)
6
- @src = src
7
- @alt = alt
8
- super(**attrs)
9
- end
4
+ class Avatar::Image < Base
5
+ def initialize(src:, alt: "", **attrs)
6
+ @src = src
7
+ @alt = alt
8
+ super(**attrs)
9
+ end
10
10
 
11
- def template
12
- img(**attrs)
13
- end
11
+ def template
12
+ img(**attrs)
13
+ end
14
14
 
15
- private
15
+ private
16
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
17
+ def default_attrs
18
+ {
19
+ loading: "lazy",
20
+ class: "aspect-square h-full w-full",
21
+ alt: @alt,
22
+ src: @src
23
+ }
25
24
  end
26
- end
25
+ end
26
+ end
@@ -1,49 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PhlexUI
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
- }
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
12
 
13
- def initialize(size: :md, src: nil, alt: nil, initials: nil, **attrs)
14
- @size = size
15
- @src = src
16
- @alt = alt
17
- @initials = initials
18
- @size_classes = SIZES[@size]
19
- super(**attrs)
20
- end
21
-
22
- def template(&block)
23
- if block_given?
24
- span(**attrs, &block)
25
- else
26
- span(**attrs) do
27
- render_image if @src
28
- render_initials
29
- end
30
- end
31
- end
32
-
33
- private
13
+ def initialize(size: :md, **attrs)
14
+ @size = size
15
+ @size_classes = SIZES[@size]
16
+ super(**attrs)
17
+ end
34
18
 
35
- def render_image
36
- render ::PhlexUI::Avatar::Image.new(src: @src, alt: @alt)
37
- end
19
+ def template(&block)
20
+ span(**attrs, &block)
21
+ end
38
22
 
39
- def render_initials
40
- render ::PhlexUI::Avatar::Fallback.new { @initials }
41
- end
23
+ private
42
24
 
43
- def default_attrs
44
- {
45
- class: tokens("relative flex shrink-0 overflow-hidden rounded-full", @size_classes)
46
- }
47
- end
25
+ def default_attrs
26
+ {
27
+ class: tokens("relative flex shrink-0 overflow-hidden rounded-full", @size_classes)
28
+ }
48
29
  end
49
- end
30
+ end
31
+ end
@@ -1,60 +1,60 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PhlexUI
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
- }
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
10
 
11
- COLORS = {
12
- primary: "text-primary bg-primary-50 dark:bg-primary-400/20 ring-primary-600/20",
13
- secondary: "text-text bg-muted-background ring-border",
14
- outline: "text-text bg-background ring-border",
15
- destructive: "text-destructive-600 bg-destructive-50 dark:bg-destructive-400/20 dark:text-destructive-400 ring-destructive-600/20",
16
- success: "text-success-600 bg-success-50 dark:bg-success-400/20 dark:text-success-400 ring-success-600/20",
17
- warning: "text-warning-600 bg-warning-50 dark:bg-warning-400/20 dark:text-warning-400 ring-warning-600/20",
18
- slate: "text-slate-600 bg-slate-50 dark:bg-slate-400/20 dark:text-slate-400 ring-slate-600/20",
19
- gray: "text-gray-600 bg-gray-50 dark:bg-gray-400/20 dark:text-gray-400 ring-gray-600/20",
20
- zinc: "text-zinc-600 bg-zinc-50 dark:bg-zinc-400/20 dark:text-zinc-400 ring-zinc-600/20",
21
- neutral: "text-neutral-600 bg-neutral-50 dark:bg-neutral-400/20 dark:text-neutral-400 ring-neutral-600/20",
22
- stone: "text-stone-600 bg-stone-50 dark:bg-stone-400/20 dark:text-stone-400 ring-stone-600/20",
23
- red: "text-red-600 bg-red-50 dark:bg-red-400/20 dark:text-red-400 ring-red-600/20",
24
- orange: "text-orange-600 bg-orange-50 dark:bg-orange-400/20 dark:text-orange-400 ring-orange-600/20",
25
- amber: "text-amber-600 bg-amber-50 dark:bg-amber-400/20 dark:text-amber-400 ring-amber-600/20",
26
- yellow: "text-yellow-600 bg-yellow-50 dark:bg-yellow-400/20 dark:text-yellow-400 ring-yellow-600/20",
27
- lime: "text-lime-600 bg-lime-50 dark:bg-lime-400/20 dark:text-lime-400 ring-lime-600/20",
28
- green: "text-green-600 bg-green-50 dark:bg-green-400/20 dark:text-green-400 ring-green-600/20",
29
- emerald: "text-emerald-600 bg-emerald-50 dark:bg-emerald-400/20 dark:text-emerald-400 ring-emerald-600/20",
30
- teal: "text-teal-600 bg-teal-50 dark:bg-teal-400/20 dark:text-teal-400 ring-teal-600/20",
31
- cyan: "text-cyan-600 bg-cyan-50 dark:bg-cyan-400/20 dark:text-cyan-400 ring-cyan-600/20",
32
- sky: "text-sky-600 bg-sky-50 dark:bg-sky-400/20 dark:text-sky-400 ring-sky-600/20",
33
- blue: "text-blue-600 bg-blue-50 dark:bg-blue-400/20 dark:text-blue-400 ring-blue-600/20",
34
- indigo: "text-indigo-600 bg-indigo-50 dark:bg-indigo-400/20 dark:text-indigo-400 ring-indigo-600/20",
35
- violet: "text-violet-600 bg-violet-50 dark:bg-violet-400/20 dark:text-violet-400 ring-violet-600/20",
36
- purple: "text-purple-600 bg-purple-50 dark:bg-purple-400/20 dark:text-purple-400 ring-purple-600/20",
37
- fuchsia: "text-fuchsia-600 bg-fuchsia-50 dark:bg-fuchsia-400/20 dark:text-fuchsia-400 ring-fuchsia-600/20",
38
- pink: "text-pink-600 bg-pink-50 dark:bg-pink-400/20 dark:text-pink-400 ring-pink-600/20",
39
- rose: "text-rose-600 bg-rose-50 dark:bg-rose-400/20 dark:text-rose-400 ring-rose-600/20"
40
- }
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
41
 
42
- def initialize(variant: :primary, size: :md, **args)
43
- @variant = variant
44
- @size = size
45
- super(**args)
46
- end
42
+ def initialize(variant: :primary, size: :md, **args)
43
+ @variant = variant
44
+ @size = size
45
+ super(**args)
46
+ end
47
47
 
48
- def template(&)
49
- span(**attrs, &)
50
- end
48
+ def template(&block)
49
+ span(**attrs, &block)
50
+ end
51
51
 
52
- private
52
+ private
53
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
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
+ }
59
58
  end
59
+ end
60
60
  end