daisyui-view-components 0.0.2 → 0.0.3

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 (133) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/daisyui-view-components/app/components/daisyui_view_components/accordion/component.rb +28 -0
  4. data/daisyui-view-components/app/components/daisyui_view_components/alert/component.html.erb +34 -0
  5. data/daisyui-view-components/app/components/daisyui_view_components/alert/component.rb +27 -0
  6. data/daisyui-view-components/app/components/daisyui_view_components/avatar/component.rb +21 -0
  7. data/daisyui-view-components/app/components/daisyui_view_components/avatar_group/component.rb +19 -0
  8. data/daisyui-view-components/app/components/daisyui_view_components/badge/component.rb +41 -0
  9. data/daisyui-view-components/app/components/daisyui_view_components/base_component.rb +118 -0
  10. data/daisyui-view-components/app/components/daisyui_view_components/bottom_nav/component.rb +50 -0
  11. data/daisyui-view-components/app/components/daisyui_view_components/breadcrumbs/component.html.erb +7 -0
  12. data/daisyui-view-components/app/components/daisyui_view_components/breadcrumbs/component.rb +21 -0
  13. data/daisyui-view-components/app/components/daisyui_view_components/button/component.rb +68 -0
  14. data/daisyui-view-components/app/components/daisyui_view_components/card/component.rb +64 -0
  15. data/daisyui-view-components/app/components/daisyui_view_components/carousel/component.rb +35 -0
  16. data/daisyui-view-components/app/components/daisyui_view_components/checkbox/component.html.erb +19 -0
  17. data/daisyui-view-components/app/components/daisyui_view_components/checkbox/component.rb +40 -0
  18. data/daisyui-view-components/app/components/daisyui_view_components/collapse/component.html.erb +9 -0
  19. data/daisyui-view-components/app/components/daisyui_view_components/collapse/component.rb +62 -0
  20. data/daisyui-view-components/app/components/daisyui_view_components/dropdown/component.html.erb +4 -0
  21. data/daisyui-view-components/app/components/daisyui_view_components/dropdown/component.rb +37 -0
  22. data/daisyui-view-components/app/components/daisyui_view_components/file_input/component.html.erb +5 -0
  23. data/daisyui-view-components/app/components/daisyui_view_components/file_input/component.rb +44 -0
  24. data/daisyui-view-components/app/components/daisyui_view_components/form_control/component.rb +21 -0
  25. data/daisyui-view-components/app/components/daisyui_view_components/label/component.rb +22 -0
  26. data/daisyui-view-components/app/components/daisyui_view_components/link/component.rb +34 -0
  27. data/daisyui-view-components/app/components/daisyui_view_components/menu/component.html.erb +7 -0
  28. data/daisyui-view-components/app/components/daisyui_view_components/menu/component.rb +28 -0
  29. data/daisyui-view-components/app/components/daisyui_view_components/modal/action/component.rb +30 -0
  30. data/daisyui-view-components/app/components/daisyui_view_components/modal/box/component.html.erb +9 -0
  31. data/daisyui-view-components/app/components/daisyui_view_components/modal/box/component.rb +15 -0
  32. data/daisyui-view-components/app/components/daisyui_view_components/modal/component.html.erb +8 -0
  33. data/daisyui-view-components/app/components/daisyui_view_components/modal/component.rb +18 -0
  34. data/daisyui-view-components/app/components/daisyui_view_components/navbar/component.html.erb +9 -0
  35. data/daisyui-view-components/app/components/daisyui_view_components/navbar/component.rb +42 -0
  36. data/daisyui-view-components/app/components/daisyui_view_components/radio/component.html.erb +19 -0
  37. data/daisyui-view-components/app/components/daisyui_view_components/radio/component.rb +57 -0
  38. data/daisyui-view-components/app/components/daisyui_view_components/range/component.rb +45 -0
  39. data/daisyui-view-components/app/components/daisyui_view_components/rating/component.rb +73 -0
  40. data/daisyui-view-components/app/components/daisyui_view_components/select/component.html.erb +5 -0
  41. data/daisyui-view-components/app/components/daisyui_view_components/select/component.rb +73 -0
  42. data/daisyui-view-components/app/components/daisyui_view_components/steps/component.rb +56 -0
  43. data/daisyui-view-components/app/components/daisyui_view_components/swap/component.rb +49 -0
  44. data/daisyui-view-components/app/components/daisyui_view_components/table/component.html.erb +5 -0
  45. data/daisyui-view-components/app/components/daisyui_view_components/table/component.rb +92 -0
  46. data/daisyui-view-components/app/components/daisyui_view_components/tabs/component.html.erb +5 -0
  47. data/daisyui-view-components/app/components/daisyui_view_components/tabs/component.rb +50 -0
  48. data/daisyui-view-components/app/components/daisyui_view_components/text_input/component.html.erb +9 -0
  49. data/daisyui-view-components/app/components/daisyui_view_components/text_input/component.rb +71 -0
  50. data/daisyui-view-components/app/components/daisyui_view_components/textarea/component.html.erb +5 -0
  51. data/daisyui-view-components/app/components/daisyui_view_components/textarea/component.rb +50 -0
  52. data/daisyui-view-components/app/components/daisyui_view_components/toggle/component.rb +43 -0
  53. data/daisyui-view-components/lib/daisyui_view_components/cache.rb +50 -0
  54. data/daisyui-view-components/lib/daisyui_view_components/engine.rb +30 -0
  55. data/daisyui-view-components/lib/daisyui_view_components/helpers/component.rb +36 -0
  56. data/daisyui-view-components/lib/daisyui_view_components/tailwind_merger.rb +23 -0
  57. data/daisyui-view-components/lib/daisyui_view_components/version.rb +7 -0
  58. data/daisyui-view-components/lib/daisyui_view_components.rb +12 -0
  59. data/daisyui-view-components/previews/accordion/default.html.erb +29 -0
  60. data/daisyui-view-components/previews/accordion/preview.rb +14 -0
  61. data/daisyui-view-components/previews/alert/default.html.erb +4 -0
  62. data/daisyui-view-components/previews/alert/info_color.html.erb +4 -0
  63. data/daisyui-view-components/previews/alert/preview.rb +23 -0
  64. data/daisyui-view-components/previews/alert/with_buttons.html.erb +10 -0
  65. data/daisyui-view-components/previews/alert/with_icon_title_and_description.html.erb +14 -0
  66. data/daisyui-view-components/previews/avatar/default.html.erb +5 -0
  67. data/daisyui-view-components/previews/avatar/preview.rb +19 -0
  68. data/daisyui-view-components/previews/avatar_group/default.html.erb +17 -0
  69. data/daisyui-view-components/previews/avatar_group/preview.rb +12 -0
  70. data/daisyui-view-components/previews/badge/default.html.erb +1 -0
  71. data/daisyui-view-components/previews/badge/preview.rb +14 -0
  72. data/daisyui-view-components/previews/bottom_nav/default.html.erb +44 -0
  73. data/daisyui-view-components/previews/bottom_nav/preview.rb +16 -0
  74. data/daisyui-view-components/previews/bottom_nav/with_labels.html.erb +47 -0
  75. data/daisyui-view-components/previews/breadcrumbs/default.html.erb +11 -0
  76. data/daisyui-view-components/previews/breadcrumbs/preview.rb +16 -0
  77. data/daisyui-view-components/previews/breadcrumbs/with_icons.html.erb +50 -0
  78. data/daisyui-view-components/previews/button/default.html.erb +3 -0
  79. data/daisyui-view-components/previews/button/preview.rb +28 -0
  80. data/daisyui-view-components/previews/card/default.html.erb +24 -0
  81. data/daisyui-view-components/previews/card/preview.rb +12 -0
  82. data/daisyui-view-components/previews/carousel/default.html.erb +37 -0
  83. data/daisyui-view-components/previews/carousel/preview.rb +19 -0
  84. data/daisyui-view-components/previews/checkbox/default.html.erb +1 -0
  85. data/daisyui-view-components/previews/checkbox/preview.rb +34 -0
  86. data/daisyui-view-components/previews/checkbox/with_form.html.erb +3 -0
  87. data/daisyui-view-components/previews/collapse/default.html.erb +9 -0
  88. data/daisyui-view-components/previews/collapse/preview.rb +14 -0
  89. data/daisyui-view-components/previews/dropdown/default.html.erb +11 -0
  90. data/daisyui-view-components/previews/dropdown/preview.rb +13 -0
  91. data/daisyui-view-components/previews/file_input/default.html.erb +1 -0
  92. data/daisyui-view-components/previews/file_input/preview.rb +26 -0
  93. data/daisyui-view-components/previews/file_input/with_form.html.erb +13 -0
  94. data/daisyui-view-components/previews/link/default.html.erb +1 -0
  95. data/daisyui-view-components/previews/link/preview.rb +17 -0
  96. data/daisyui-view-components/previews/modal/default.html.erb +14 -0
  97. data/daisyui-view-components/previews/modal/preview.rb +19 -0
  98. data/daisyui-view-components/previews/navbar/default.html.erb +75 -0
  99. data/daisyui-view-components/previews/navbar/preview.rb +12 -0
  100. data/daisyui-view-components/previews/radio/default.html.erb +1 -0
  101. data/daisyui-view-components/previews/radio/preview.rb +26 -0
  102. data/daisyui-view-components/previews/radio/with_form.html.erb +4 -0
  103. data/daisyui-view-components/previews/range_slider/default.html.erb +1 -0
  104. data/daisyui-view-components/previews/range_slider/preview.rb +14 -0
  105. data/daisyui-view-components/previews/rating/default.html.erb +6 -0
  106. data/daisyui-view-components/previews/rating/preview.rb +14 -0
  107. data/daisyui-view-components/previews/select/default.html.erb +1 -0
  108. data/daisyui-view-components/previews/select/preview.rb +26 -0
  109. data/daisyui-view-components/previews/select/with_form.html.erb +13 -0
  110. data/daisyui-view-components/previews/steps/default.html.erb +14 -0
  111. data/daisyui-view-components/previews/steps/preview.rb +13 -0
  112. data/daisyui-view-components/previews/swap/default.html.erb +9 -0
  113. data/daisyui-view-components/previews/swap/flip_effect.html.erb +9 -0
  114. data/daisyui-view-components/previews/swap/hamburger_button.html.erb +26 -0
  115. data/daisyui-view-components/previews/swap/preview.rb +28 -0
  116. data/daisyui-view-components/previews/swap/rotate_effect.html.erb +23 -0
  117. data/daisyui-view-components/previews/swap/volume_icons.html.erb +27 -0
  118. data/daisyui-view-components/previews/table/default.html.erb +60 -0
  119. data/daisyui-view-components/previews/table/preview.rb +17 -0
  120. data/daisyui-view-components/previews/tabs/default.html.erb +11 -0
  121. data/daisyui-view-components/previews/tabs/preview.rb +21 -0
  122. data/daisyui-view-components/previews/text_input/default.html.erb +1 -0
  123. data/daisyui-view-components/previews/text_input/preview.rb +42 -0
  124. data/daisyui-view-components/previews/text_input/with_form.html.erb +13 -0
  125. data/daisyui-view-components/previews/text_input/with_icon_inside.html.erb +59 -0
  126. data/daisyui-view-components/previews/text_input/with_text_label_inside.html.erb +26 -0
  127. data/daisyui-view-components/previews/textarea/default.html.erb +1 -0
  128. data/daisyui-view-components/previews/textarea/preview.rb +26 -0
  129. data/daisyui-view-components/previews/textarea/with_form.html.erb +13 -0
  130. data/daisyui-view-components/previews/toggle/default.html.erb +1 -0
  131. data/daisyui-view-components/previews/toggle/preview.rb +26 -0
  132. data/daisyui-view-components/previews/toggle/with_form.html.erb +3 -0
  133. metadata +137 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f2d582cdc44cbf6277222d97638f1ac9a583427e138d10ad117e2847ca24350
4
- data.tar.gz: 19e5279512c365142a30d9bf6eca7a68237f1c02f158a145e46a0e23d1941970
3
+ metadata.gz: 6ab2d16e1c0bd5199899bcf151c760d5af18cfaf5c0fc8a343ed9503f7473187
4
+ data.tar.gz: 1de2e11b5dd7a70b5b65b4a404a1f3efc2b08d19629dcc5d63ed30d0c98c42b4
5
5
  SHA512:
6
- metadata.gz: 2dffadf1f7a2ffb4b80464586a0c6a9e7f1d30f362451c20372b077e890417c8cd6fe9aff6cb479cc4ed4964cd4129f7a7817ca80c392f73496d07f499d7d308
7
- data.tar.gz: e60b1f4897340f65837726793a02a59beef5780c6bef2c7f53aa8b4addaf82f96e6e1128dc1579133ea58d1fb1fece895edeab5461c96d47d8a2f9db9a4cd230
6
+ metadata.gz: 22a42fa9b7a4a2fd1eac4ce8ca8417d005873e70b8c1dd20c547dc22968abbf51b94cd110ade3018501abfd0764f6c2f03a6750159483f3d6b9f03a60e6d4fcd
7
+ data.tar.gz: 43137115a6987c1aebf4802af8f9b907ee620f56a03dc1be4bed60fadcc34b079dfd59f5a07814f57bcb91fe1442c0df077641957772877be6e923d12d6ab0c6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.3](https://github.com/ganchdev/daisyui-view-components/compare/v0.0.2...v0.0.3) (2024-10-23)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * paths in gemspec ([58c3181](https://github.com/ganchdev/daisyui-view-components/commit/58c3181e75140b40d839a1346cf671087dc17498))
9
+
3
10
  ## [0.0.2](https://github.com/ganchdev/daisyui-view-components/compare/v0.0.1...v0.0.2) (2024-10-13)
4
11
 
5
12
 
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DaisyUIViewComponents
4
+ module Accordion
5
+ class Component < DaisyUIViewComponents::BaseComponent
6
+
7
+ option :gap, default: proc { 2 }
8
+ option :arrow, default: proc { false }
9
+
10
+ renders_many :collapses, lambda { |arrow: @arrow|
11
+ DaisyUIViewComponents::Collapse::Component.new(arrow: arrow)
12
+ }
13
+
14
+ def call
15
+ html :div, class: css_classes do
16
+ collapses.each do |collapse|
17
+ concat collapse
18
+ end
19
+ end
20
+ end
21
+
22
+ def css_classes
23
+ css("flex flex-wrap gap-#{@gap}")
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,34 @@
1
+ <%= html :div, role: 'alert' do %>
2
+ <% if title.present? && description.present? %>
3
+
4
+ <% if icon.present? %>
5
+ <%= icon %>
6
+ <% end %>
7
+
8
+ <div>
9
+ <h3 class="font-bold">
10
+ <%= title %>
11
+ </h3>
12
+ <div class="text-xs">
13
+ <%= description %>
14
+ </div>
15
+ </div>
16
+
17
+ <% unless icon.present? %>
18
+ <div></div>
19
+ <% end %>
20
+
21
+ <div>
22
+ <% buttons.each do |button| %>
23
+ <%= button %>
24
+ <% end %>
25
+ </div>
26
+ <% else %>
27
+ <%= content %>
28
+ <div>
29
+ <% buttons.each do |button| %>
30
+ <%= button %>
31
+ <% end %>
32
+ </div>
33
+ <% end %>
34
+ <% end %>
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DaisyUIViewComponents
4
+ module Alert
5
+ class Component < DaisyUIViewComponents::BaseComponent
6
+
7
+ COLOR_CLASSES = {
8
+ info: 'alert-info',
9
+ success: 'alert-success',
10
+ warning: 'alert-warning',
11
+ error: 'alert-error'
12
+ }.freeze
13
+
14
+ COLOR_OPTIONS = COLOR_CLASSES.keys.freeze
15
+
16
+ renders_one :icon
17
+ renders_one :title
18
+ renders_one :description
19
+ renders_many :buttons, DaisyUIViewComponents::Button::Component
20
+
21
+ option :color, optional: true, desc: COLOR_CLASSES, type: proc(&:to_sym)
22
+
23
+ css_classes 'alert', with: :color
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DaisyUIViewComponents
4
+ module Avatar
5
+ class Component < DaisyUIViewComponents::BaseComponent
6
+
7
+ option :online, default: proc { false }
8
+ option :offline, default: proc { false }
9
+ option :placeholder, default: proc { '' }
10
+
11
+ css_classes 'avatar', with: [:online, :offline, :placeholder]
12
+
13
+ def call
14
+ html :span do
15
+ content
16
+ end
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DaisyUIViewComponents
4
+ module AvatarGroup
5
+ class Component < DaisyUIViewComponents::BaseComponent
6
+
7
+ renders_many :avatars, DaisyUIViewComponents::Avatar::Component
8
+
9
+ def call
10
+ html :div, class: css('avatar-group -space-x-6 rtl:space-x-reverse') do
11
+ avatars.each do |avatar|
12
+ concat avatar
13
+ end
14
+ end
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DaisyUIViewComponents
4
+ module Badge
5
+ class Component < DaisyUIViewComponents::BaseComponent
6
+
7
+ COLOR_CLASSES = {
8
+ primary: 'badge-primary',
9
+ secondary: 'badge-secondary',
10
+ accent: 'badge-accent',
11
+ info: 'badge-info',
12
+ success: 'badge-success',
13
+ warning: 'badge-warning',
14
+ error: 'badge-error'
15
+ }.freeze
16
+
17
+ SIZE_CLASSES = {
18
+ xs: 'range-xs',
19
+ sm: 'range-sm',
20
+ md: 'range-md',
21
+ lg: 'range-lg'
22
+ }.freeze
23
+
24
+ SIZE_OPTIONS = SIZE_CLASSES.keys.freeze
25
+ COLOR_OPTIONS = COLOR_CLASSES.keys.freeze
26
+ DEFAULT_COLOR = :primary
27
+
28
+ option :color, optional: true, desc: COLOR_CLASSES, type: proc(&:to_sym)
29
+ option :size, optional: true, desc: SIZE_CLASSES, type: proc(&:to_sym)
30
+
31
+ css_classes 'badge', with: [:color, :size]
32
+
33
+ def call
34
+ html :span do
35
+ content
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'view_component'
4
+ require 'dry-initializer'
5
+
6
+ # rubocop:disable Metrics/AbcSize
7
+ # rubocop:disable Metrics/MethodLength
8
+ module DaisyUIViewComponents
9
+ class BaseComponent < ViewComponent::Base
10
+
11
+ extend Dry::Initializer[undefined: false]
12
+
13
+ def initialize(text = nil, **opts)
14
+ @_text = text
15
+ @html_options = opts
16
+
17
+ super(**opts)
18
+ end
19
+
20
+ def content
21
+ super || @_text
22
+ end
23
+
24
+ def html_options(**opts)
25
+ if opts[:class]
26
+ original = @html_options[:class]
27
+ @html_options[:class] = [opts.delete(:class)]
28
+ @html_options[:class] << original if original
29
+ end
30
+
31
+ # Remove all options that are used by the component
32
+ self.class.dry_initializer.attributes(self).each_key do |key|
33
+ @html_options.delete(key)
34
+ end
35
+
36
+ @html_options.merge(opts)
37
+ end
38
+
39
+ # Html wrapper for components that render
40
+ # tags with given html attributes and content.
41
+ # It makes it easy to pass html options around
42
+ # without always having to merge them.
43
+ #
44
+ # @param tag [Symbol] the tag to render
45
+ # @param opts [Hash] the html attributes to render
46
+ # @param block [Proc] the content to render
47
+ # @return [String] the rendered html
48
+ def html(tag, **opts, &block)
49
+ opts = opts.merge(class: css_classes) if defined?(classes)
50
+ attributes = html_options.merge(opts)
51
+
52
+ content = capture(&block) if block
53
+
54
+ content_tag(tag, content, **attributes)
55
+ end
56
+
57
+ def css(css_classes = '')
58
+ if external_classes = html_options[:class]
59
+ cn("#{external_classes} #{css_classes}")
60
+ else
61
+ cn(css_classes)
62
+ end
63
+ end
64
+
65
+ def self.css_classes(base, **modifiers, &block)
66
+ cattr_accessor :classes
67
+
68
+ self.classes ||= {}
69
+
70
+ if block_given?
71
+ self.classes[self] = {
72
+ base: base,
73
+ modifiers: block
74
+ }
75
+ else
76
+ self.classes[self] = {
77
+ base: base,
78
+ modifiers: modifiers[:with]
79
+ }
80
+ end
81
+ end
82
+
83
+ # Sets css classes for a component
84
+ # based on what the base class is
85
+ # and what modifiers were passed to the
86
+ # class method above. It is used within
87
+ # the html wrapper but could also be used
88
+ # on its own when necessary.
89
+ #
90
+ # @return [String]
91
+ def css_classes
92
+ component_classes = classes[self.class]
93
+ css_classes = Array(component_classes[:base])
94
+ modifiers = component_classes[:modifiers]
95
+
96
+ case modifiers
97
+ when Proc
98
+ # Execute the proc in the context of the instance
99
+ instance_exec(css_classes, &modifiers)
100
+ when Array, Symbol
101
+ Array(modifiers).each do |modifier|
102
+ modifier_value = public_send(modifier)
103
+ next if modifier_value.nil?
104
+
105
+ css_classes << self.class.const_get("#{modifier}_classes".upcase)[modifier_value]
106
+ rescue NameError
107
+ # Fallback for boolean modifiers
108
+ css_classes << modifier.to_s.gsub('_', '-') if public_send(modifier)
109
+ end
110
+ end
111
+
112
+ css(css_classes.join(' '))
113
+ end
114
+
115
+ end
116
+ end
117
+ # rubocop:enable Metrics/AbcSize
118
+ # rubocop:enable Metrics/MethodLength
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DaisyUIViewComponents
4
+ module BottomNav
5
+ class Component < DaisyUIViewComponents::BaseComponent
6
+
7
+ renders_many :buttons, 'Button'
8
+
9
+ def call
10
+ html :div, class: css('btm-nav') do
11
+ buttons.each do |button|
12
+ concat button
13
+ end
14
+ end
15
+ end
16
+
17
+ class Button < DaisyUIViewComponents::BaseComponent
18
+
19
+ option :active, default: proc { false }
20
+
21
+ renders_one :label, 'Label'
22
+
23
+ def call
24
+ html :button, class: css_classes do
25
+ concat content
26
+ concat label
27
+ end
28
+ end
29
+
30
+ class Label < DaisyUIViewComponents::BaseComponent
31
+
32
+ def call
33
+ html :span, class: css('btm-nav-label') do
34
+ content
35
+ end
36
+ end
37
+
38
+ end
39
+
40
+ private
41
+
42
+ def css_classes
43
+ css(active ? 'active' : nil)
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,7 @@
1
+ <%= html :div, class: css('breadcrumbs') do %>
2
+ <ul>
3
+ <% items.each do |item| %>
4
+ <%= item %>
5
+ <% end %>
6
+ </ul>
7
+ <% end %>
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DaisyUIViewComponents
4
+ module Breadcrumbs
5
+ class Component < DaisyUIViewComponents::BaseComponent
6
+
7
+ renders_many :items, 'Item'
8
+
9
+ class Item < DaisyUIViewComponents::BaseComponent
10
+
11
+ def call
12
+ html :li do
13
+ content
14
+ end
15
+ end
16
+
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DaisyUIViewComponents
4
+ module Button
5
+ class Component < DaisyUIViewComponents::BaseComponent
6
+
7
+ COLOR_CLASSES = {
8
+ neutral: 'btn-neural',
9
+ primary: 'btn-primary',
10
+ accent: 'btn-accent',
11
+ info: 'btn-info',
12
+ success: 'btn-success',
13
+ warning: 'btn-warning',
14
+ error: 'btn-error',
15
+ ghost: 'btn-ghost'
16
+ }.freeze
17
+
18
+ STYLE_CLASSES = {
19
+ link: 'btn-link',
20
+ outline: 'btn-outline'
21
+ }.freeze
22
+
23
+ COLOR_OPTIONS = COLOR_CLASSES.keys.freeze
24
+ STYLE_OPTIONS = STYLE_CLASSES.keys.freeze
25
+
26
+ option :url, optional: true, type: proc(&:to_s)
27
+ option :label, optional: true, type: proc(&:to_sym)
28
+ option :method, optional: true, type: proc(&:to_sym)
29
+ option :color, optional: true, desc: COLOR_CLASSES, type: proc(&:to_sym)
30
+ option :style, optional: true, desc: STYLE_OPTIONS, type: proc(&:to_sym)
31
+
32
+ css_classes 'btn', with: [:color, :style]
33
+
34
+ def call
35
+ button do
36
+ content
37
+ end
38
+ end
39
+
40
+ # rubocop:disable Metrics/AbcSize
41
+ # rubocop:disable Metrics/MethodLength
42
+ def button(&block)
43
+ @html_options[:class] = css_classes
44
+ options = { data: @data }
45
+
46
+ if @url.blank?
47
+ if @label.present?
48
+ options = options.except(:type)
49
+
50
+ label_tag(@label, **options, **html_options, &block)
51
+ else
52
+ button_tag(**options, **html_options, &block)
53
+ end
54
+ elsif @method.present?
55
+ options[:method] = @method
56
+ options[:type] = :button
57
+
58
+ button_to(@url, **options, **html_options, &block)
59
+ else
60
+ link_to(@url, **options, **html_options, &block)
61
+ end
62
+ end
63
+ # rubocop:enable Metrics/AbcSize
64
+ # rubocop:enable Metrics/MethodLength
65
+
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DaisyUIViewComponents
4
+ module Card
5
+ class Component < DaisyUIViewComponents::BaseComponent
6
+
7
+ renders_one :image, 'Image'
8
+ renders_one :card_body, 'CardBody'
9
+
10
+ def call
11
+ html :div, class: css('card w-96 bg-base-100 shadow-xl') do
12
+ content
13
+ end
14
+ end
15
+
16
+ class Image < DaisyUIViewComponents::BaseComponent
17
+
18
+ def call
19
+ html :figure do
20
+ content
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ class CardBody < DaisyUIViewComponents::BaseComponent
27
+
28
+ renders_one :title, 'Title'
29
+ renders_one :card_actions, 'CardActions'
30
+
31
+ def call
32
+ html :div, class: css('card-body') do
33
+ content
34
+ end
35
+ end
36
+
37
+ class Title < DaisyUIViewComponents::BaseComponent
38
+
39
+ def call
40
+ html :h2, class: css('card-title') do
41
+ content
42
+ end
43
+ end
44
+
45
+ end
46
+
47
+ class CardActions < DaisyUIViewComponents::BaseComponent
48
+
49
+ renders_many :buttons, DaisyUIViewComponents::Button::Component
50
+ renders_many :badges, DaisyUIViewComponents::Badge::Component
51
+
52
+ def call
53
+ html :div, class: css('card-actions') do
54
+ content
55
+ end
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DaisyUIViewComponents
4
+ module Carousel
5
+ class Component < DaisyUIViewComponents::BaseComponent
6
+
7
+ option :carousel_center, default: proc { false }, desc: 'Snap elements to center'
8
+ option :carousel_end, default: proc { false }, desc: 'Snap elements to end'
9
+ option :carousel_vertical, default: proc { false }, desc: 'Vertical carousel'
10
+
11
+ css_classes 'carousel', with: [:carousel_center, :carousel_end, :carousel_vertical]
12
+
13
+ renders_many :items, 'CarouselItem'
14
+
15
+ def call
16
+ html :div, class: css_classes do
17
+ items.each do |item|
18
+ concat item
19
+ end
20
+ end
21
+ end
22
+
23
+ class CarouselItem < DaisyUIViewComponents::BaseComponent
24
+
25
+ def call
26
+ html :div, class: css('carousel-item') do
27
+ content
28
+ end
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,19 @@
1
+ <% if label %>
2
+ <% if form.present? %>
3
+ <div class="form-control">
4
+ <%= label_tag field, class: "cursor-pointer label" do %>
5
+ <%= content_tag :span, label, class: "label-text" %>
6
+ <%= form.check_box field, class: css_classes, **html_options.except(:class) %>
7
+ <% end %>
8
+ </div>
9
+ <% else %>
10
+ <div class="form-control">
11
+ <%= label_tag field, class: "cursor-pointer label" do %>
12
+ <%= content_tag :span, label, class: "label-text" %>
13
+ <%= check_box_tag field, class: css_classes, **html_options.except(:class) %>
14
+ <% end %>
15
+ </div>
16
+ <% end %>
17
+ <% else %>
18
+ <%= check_box_tag field, class: css_classes, **html_options.except(:class) %>
19
+ <% end %>
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DaisyUIViewComponents
4
+ module Checkbox
5
+ class Component < DaisyUIViewComponents::BaseComponent
6
+
7
+ SIZE_CLASSES = {
8
+ xs: 'checkbox-xs',
9
+ sm: 'checkbox-sm',
10
+ md: 'checkbox-md',
11
+ lg: 'checkbox-lg'
12
+ }.freeze
13
+
14
+ SIZE_OPTIONS = SIZE_CLASSES.keys.freeze
15
+
16
+ COLOR_CLASSES = {
17
+ primary: 'checkbox-primary',
18
+ secondary: 'checkbox-secondary',
19
+ accent: 'checkbox-accent',
20
+ info: 'checkbox-info',
21
+ success: 'checkbox-success',
22
+ warning: 'checkbox-warning',
23
+ error: 'checkbox-error'
24
+ }.freeze
25
+
26
+ DEFAULT_COLOR = :primary
27
+
28
+ COLOR_OPTIONS = COLOR_CLASSES.keys.freeze
29
+
30
+ option :size, optional: true, desc: SIZE_OPTIONS, type: proc(&:to_sym)
31
+ option :color, optional: true, desc: COLOR_CLASSES, type: proc(&:to_sym)
32
+ option :form, optional: true
33
+ option :label, optional: true
34
+ option :field, optional: true, type: proc(&:to_s), default: proc { content&.to_sym }
35
+
36
+ css_classes 'checkbox', with: [:color, :size]
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,9 @@
1
+ <%= html :div do %>
2
+ <% if checkbox %>
3
+ <%= checkbox %>
4
+ <% elsif radio %>
5
+ <%= radio %>
6
+ <% end %>
7
+ <%= collapse_title %>
8
+ <%= collapse_content %>
9
+ <% end %>