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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/daisyui-view-components/app/components/daisyui_view_components/accordion/component.rb +28 -0
- data/daisyui-view-components/app/components/daisyui_view_components/alert/component.html.erb +34 -0
- data/daisyui-view-components/app/components/daisyui_view_components/alert/component.rb +27 -0
- data/daisyui-view-components/app/components/daisyui_view_components/avatar/component.rb +21 -0
- data/daisyui-view-components/app/components/daisyui_view_components/avatar_group/component.rb +19 -0
- data/daisyui-view-components/app/components/daisyui_view_components/badge/component.rb +41 -0
- data/daisyui-view-components/app/components/daisyui_view_components/base_component.rb +118 -0
- data/daisyui-view-components/app/components/daisyui_view_components/bottom_nav/component.rb +50 -0
- data/daisyui-view-components/app/components/daisyui_view_components/breadcrumbs/component.html.erb +7 -0
- data/daisyui-view-components/app/components/daisyui_view_components/breadcrumbs/component.rb +21 -0
- data/daisyui-view-components/app/components/daisyui_view_components/button/component.rb +68 -0
- data/daisyui-view-components/app/components/daisyui_view_components/card/component.rb +64 -0
- data/daisyui-view-components/app/components/daisyui_view_components/carousel/component.rb +35 -0
- data/daisyui-view-components/app/components/daisyui_view_components/checkbox/component.html.erb +19 -0
- data/daisyui-view-components/app/components/daisyui_view_components/checkbox/component.rb +40 -0
- data/daisyui-view-components/app/components/daisyui_view_components/collapse/component.html.erb +9 -0
- data/daisyui-view-components/app/components/daisyui_view_components/collapse/component.rb +62 -0
- data/daisyui-view-components/app/components/daisyui_view_components/dropdown/component.html.erb +4 -0
- data/daisyui-view-components/app/components/daisyui_view_components/dropdown/component.rb +37 -0
- data/daisyui-view-components/app/components/daisyui_view_components/file_input/component.html.erb +5 -0
- data/daisyui-view-components/app/components/daisyui_view_components/file_input/component.rb +44 -0
- data/daisyui-view-components/app/components/daisyui_view_components/form_control/component.rb +21 -0
- data/daisyui-view-components/app/components/daisyui_view_components/label/component.rb +22 -0
- data/daisyui-view-components/app/components/daisyui_view_components/link/component.rb +34 -0
- data/daisyui-view-components/app/components/daisyui_view_components/menu/component.html.erb +7 -0
- data/daisyui-view-components/app/components/daisyui_view_components/menu/component.rb +28 -0
- data/daisyui-view-components/app/components/daisyui_view_components/modal/action/component.rb +30 -0
- data/daisyui-view-components/app/components/daisyui_view_components/modal/box/component.html.erb +9 -0
- data/daisyui-view-components/app/components/daisyui_view_components/modal/box/component.rb +15 -0
- data/daisyui-view-components/app/components/daisyui_view_components/modal/component.html.erb +8 -0
- data/daisyui-view-components/app/components/daisyui_view_components/modal/component.rb +18 -0
- data/daisyui-view-components/app/components/daisyui_view_components/navbar/component.html.erb +9 -0
- data/daisyui-view-components/app/components/daisyui_view_components/navbar/component.rb +42 -0
- data/daisyui-view-components/app/components/daisyui_view_components/radio/component.html.erb +19 -0
- data/daisyui-view-components/app/components/daisyui_view_components/radio/component.rb +57 -0
- data/daisyui-view-components/app/components/daisyui_view_components/range/component.rb +45 -0
- data/daisyui-view-components/app/components/daisyui_view_components/rating/component.rb +73 -0
- data/daisyui-view-components/app/components/daisyui_view_components/select/component.html.erb +5 -0
- data/daisyui-view-components/app/components/daisyui_view_components/select/component.rb +73 -0
- data/daisyui-view-components/app/components/daisyui_view_components/steps/component.rb +56 -0
- data/daisyui-view-components/app/components/daisyui_view_components/swap/component.rb +49 -0
- data/daisyui-view-components/app/components/daisyui_view_components/table/component.html.erb +5 -0
- data/daisyui-view-components/app/components/daisyui_view_components/table/component.rb +92 -0
- data/daisyui-view-components/app/components/daisyui_view_components/tabs/component.html.erb +5 -0
- data/daisyui-view-components/app/components/daisyui_view_components/tabs/component.rb +50 -0
- data/daisyui-view-components/app/components/daisyui_view_components/text_input/component.html.erb +9 -0
- data/daisyui-view-components/app/components/daisyui_view_components/text_input/component.rb +71 -0
- data/daisyui-view-components/app/components/daisyui_view_components/textarea/component.html.erb +5 -0
- data/daisyui-view-components/app/components/daisyui_view_components/textarea/component.rb +50 -0
- data/daisyui-view-components/app/components/daisyui_view_components/toggle/component.rb +43 -0
- data/daisyui-view-components/lib/daisyui_view_components/cache.rb +50 -0
- data/daisyui-view-components/lib/daisyui_view_components/engine.rb +30 -0
- data/daisyui-view-components/lib/daisyui_view_components/helpers/component.rb +36 -0
- data/daisyui-view-components/lib/daisyui_view_components/tailwind_merger.rb +23 -0
- data/daisyui-view-components/lib/daisyui_view_components/version.rb +7 -0
- data/daisyui-view-components/lib/daisyui_view_components.rb +12 -0
- data/daisyui-view-components/previews/accordion/default.html.erb +29 -0
- data/daisyui-view-components/previews/accordion/preview.rb +14 -0
- data/daisyui-view-components/previews/alert/default.html.erb +4 -0
- data/daisyui-view-components/previews/alert/info_color.html.erb +4 -0
- data/daisyui-view-components/previews/alert/preview.rb +23 -0
- data/daisyui-view-components/previews/alert/with_buttons.html.erb +10 -0
- data/daisyui-view-components/previews/alert/with_icon_title_and_description.html.erb +14 -0
- data/daisyui-view-components/previews/avatar/default.html.erb +5 -0
- data/daisyui-view-components/previews/avatar/preview.rb +19 -0
- data/daisyui-view-components/previews/avatar_group/default.html.erb +17 -0
- data/daisyui-view-components/previews/avatar_group/preview.rb +12 -0
- data/daisyui-view-components/previews/badge/default.html.erb +1 -0
- data/daisyui-view-components/previews/badge/preview.rb +14 -0
- data/daisyui-view-components/previews/bottom_nav/default.html.erb +44 -0
- data/daisyui-view-components/previews/bottom_nav/preview.rb +16 -0
- data/daisyui-view-components/previews/bottom_nav/with_labels.html.erb +47 -0
- data/daisyui-view-components/previews/breadcrumbs/default.html.erb +11 -0
- data/daisyui-view-components/previews/breadcrumbs/preview.rb +16 -0
- data/daisyui-view-components/previews/breadcrumbs/with_icons.html.erb +50 -0
- data/daisyui-view-components/previews/button/default.html.erb +3 -0
- data/daisyui-view-components/previews/button/preview.rb +28 -0
- data/daisyui-view-components/previews/card/default.html.erb +24 -0
- data/daisyui-view-components/previews/card/preview.rb +12 -0
- data/daisyui-view-components/previews/carousel/default.html.erb +37 -0
- data/daisyui-view-components/previews/carousel/preview.rb +19 -0
- data/daisyui-view-components/previews/checkbox/default.html.erb +1 -0
- data/daisyui-view-components/previews/checkbox/preview.rb +34 -0
- data/daisyui-view-components/previews/checkbox/with_form.html.erb +3 -0
- data/daisyui-view-components/previews/collapse/default.html.erb +9 -0
- data/daisyui-view-components/previews/collapse/preview.rb +14 -0
- data/daisyui-view-components/previews/dropdown/default.html.erb +11 -0
- data/daisyui-view-components/previews/dropdown/preview.rb +13 -0
- data/daisyui-view-components/previews/file_input/default.html.erb +1 -0
- data/daisyui-view-components/previews/file_input/preview.rb +26 -0
- data/daisyui-view-components/previews/file_input/with_form.html.erb +13 -0
- data/daisyui-view-components/previews/link/default.html.erb +1 -0
- data/daisyui-view-components/previews/link/preview.rb +17 -0
- data/daisyui-view-components/previews/modal/default.html.erb +14 -0
- data/daisyui-view-components/previews/modal/preview.rb +19 -0
- data/daisyui-view-components/previews/navbar/default.html.erb +75 -0
- data/daisyui-view-components/previews/navbar/preview.rb +12 -0
- data/daisyui-view-components/previews/radio/default.html.erb +1 -0
- data/daisyui-view-components/previews/radio/preview.rb +26 -0
- data/daisyui-view-components/previews/radio/with_form.html.erb +4 -0
- data/daisyui-view-components/previews/range_slider/default.html.erb +1 -0
- data/daisyui-view-components/previews/range_slider/preview.rb +14 -0
- data/daisyui-view-components/previews/rating/default.html.erb +6 -0
- data/daisyui-view-components/previews/rating/preview.rb +14 -0
- data/daisyui-view-components/previews/select/default.html.erb +1 -0
- data/daisyui-view-components/previews/select/preview.rb +26 -0
- data/daisyui-view-components/previews/select/with_form.html.erb +13 -0
- data/daisyui-view-components/previews/steps/default.html.erb +14 -0
- data/daisyui-view-components/previews/steps/preview.rb +13 -0
- data/daisyui-view-components/previews/swap/default.html.erb +9 -0
- data/daisyui-view-components/previews/swap/flip_effect.html.erb +9 -0
- data/daisyui-view-components/previews/swap/hamburger_button.html.erb +26 -0
- data/daisyui-view-components/previews/swap/preview.rb +28 -0
- data/daisyui-view-components/previews/swap/rotate_effect.html.erb +23 -0
- data/daisyui-view-components/previews/swap/volume_icons.html.erb +27 -0
- data/daisyui-view-components/previews/table/default.html.erb +60 -0
- data/daisyui-view-components/previews/table/preview.rb +17 -0
- data/daisyui-view-components/previews/tabs/default.html.erb +11 -0
- data/daisyui-view-components/previews/tabs/preview.rb +21 -0
- data/daisyui-view-components/previews/text_input/default.html.erb +1 -0
- data/daisyui-view-components/previews/text_input/preview.rb +42 -0
- data/daisyui-view-components/previews/text_input/with_form.html.erb +13 -0
- data/daisyui-view-components/previews/text_input/with_icon_inside.html.erb +59 -0
- data/daisyui-view-components/previews/text_input/with_text_label_inside.html.erb +26 -0
- data/daisyui-view-components/previews/textarea/default.html.erb +1 -0
- data/daisyui-view-components/previews/textarea/preview.rb +26 -0
- data/daisyui-view-components/previews/textarea/with_form.html.erb +13 -0
- data/daisyui-view-components/previews/toggle/default.html.erb +1 -0
- data/daisyui-view-components/previews/toggle/preview.rb +26 -0
- data/daisyui-view-components/previews/toggle/with_form.html.erb +3 -0
- metadata +137 -7
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DaisyUIViewComponents
|
4
|
+
module Select
|
5
|
+
class Component < DaisyUIViewComponents::BaseComponent
|
6
|
+
|
7
|
+
SIZE_CLASSES = {
|
8
|
+
xs: 'select-xs',
|
9
|
+
sm: 'select-sm',
|
10
|
+
md: 'select-md',
|
11
|
+
lg: 'select-lg'
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
COLOR_CLASSES = {
|
15
|
+
primary: 'select-primary',
|
16
|
+
secondary: 'select-secondary',
|
17
|
+
accent: 'select-accent',
|
18
|
+
info: 'select-info',
|
19
|
+
success: 'select-success',
|
20
|
+
warning: 'select-warning',
|
21
|
+
error: 'select-error'
|
22
|
+
}.freeze
|
23
|
+
|
24
|
+
SIZE_OPTIONS = SIZE_CLASSES.keys.freeze
|
25
|
+
COLOR_OPTIONS = COLOR_CLASSES.keys.freeze
|
26
|
+
DEFAULT_COLOR = :primary
|
27
|
+
|
28
|
+
option :size, optional: true, desc: SIZE_OPTIONS, type: proc(&:to_sym)
|
29
|
+
option :ghost, optional: true, default: false
|
30
|
+
option :bordered, optional: true, default: false
|
31
|
+
option :color, optional: true, desc: COLOR_CLASSES, type: proc(&:to_sym)
|
32
|
+
option :form, optional: true
|
33
|
+
option :field, optional: true, type: proc(&:to_s), default: proc { content&.to_sym }
|
34
|
+
option :choices, default: proc { [] }
|
35
|
+
option :include_blank, optional: true
|
36
|
+
option :disable_blank, default: proc { false }
|
37
|
+
|
38
|
+
css_classes 'select' do |classes|
|
39
|
+
classes << SIZE_CLASSES[size] if size
|
40
|
+
classes << COLOR_CLASSES[color] if color
|
41
|
+
classes << 'select-ghost' if ghost
|
42
|
+
classes << 'select-bordered' if bordered
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def include_blank_options
|
48
|
+
return {} unless @include_blank
|
49
|
+
|
50
|
+
if @disable_blank && @form
|
51
|
+
# Form select helper options with blank disabled
|
52
|
+
{
|
53
|
+
selected: "",
|
54
|
+
disabled: "",
|
55
|
+
prompt: @include_blank
|
56
|
+
}
|
57
|
+
else
|
58
|
+
# Options for `select_tag` require an empty hash when blank disabled
|
59
|
+
# so that we can build prompt option manually otherwise two `include_blank` options are rendered
|
60
|
+
@disable_blank ? {} : { include_blank: @include_blank }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def prepare_choices
|
65
|
+
return @choices unless @include_blank && @disable_blank
|
66
|
+
|
67
|
+
blank_option = content_tag("option", @include_blank, value: "", selected: "", disabled: @disable_blank)
|
68
|
+
blank_option + @choices
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DaisyUIViewComponents
|
4
|
+
module Steps
|
5
|
+
class Component < DaisyUIViewComponents::BaseComponent
|
6
|
+
|
7
|
+
DIRECTION_CLASSES = {
|
8
|
+
vertical: 'steps-vertical',
|
9
|
+
horizontal: 'steps-horizontal'
|
10
|
+
}.freeze
|
11
|
+
|
12
|
+
DIRECTION_OPTIONS = DIRECTION_CLASSES.keys.freeze
|
13
|
+
|
14
|
+
option :direction, optional: true, desc: DIRECTION_OPTIONS, type: proc(&:to_sym)
|
15
|
+
|
16
|
+
css_classes 'steps', with: :direction
|
17
|
+
|
18
|
+
renders_many :steps, 'Step'
|
19
|
+
|
20
|
+
def call
|
21
|
+
html :ul do
|
22
|
+
content
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Step < DaisyUIViewComponents::BaseComponent
|
27
|
+
|
28
|
+
COLOR_CLASSES = {
|
29
|
+
primary: 'step-primary',
|
30
|
+
secondary: 'step-secondary',
|
31
|
+
accent: 'step-accent',
|
32
|
+
info: 'step-info',
|
33
|
+
success: 'step-success',
|
34
|
+
warning: 'step-warning',
|
35
|
+
error: 'step-error',
|
36
|
+
}.freeze
|
37
|
+
|
38
|
+
DEFAULT_COLOR = :primary
|
39
|
+
|
40
|
+
COLOR_OPTIONS = COLOR_CLASSES.keys.freeze
|
41
|
+
|
42
|
+
option :color, optional: true, desc: COLOR_CLASSES, type: proc(&:to_sym)
|
43
|
+
|
44
|
+
css_classes 'step', with: :color
|
45
|
+
|
46
|
+
def call
|
47
|
+
html :li do
|
48
|
+
content
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DaisyUIViewComponents
|
4
|
+
module Swap
|
5
|
+
class Component < DaisyUIViewComponents::BaseComponent
|
6
|
+
|
7
|
+
renders_one :swap_on, 'SwapOn'
|
8
|
+
renders_one :swap_off, 'SwapOff'
|
9
|
+
renders_one :input, 'SwapInput'
|
10
|
+
|
11
|
+
def call
|
12
|
+
html :label, class: css('swap') do
|
13
|
+
content
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class SwapInput < DaisyUIViewComponents::BaseComponent
|
18
|
+
|
19
|
+
def call
|
20
|
+
html :input, type: 'checkbox', class: css('hidden') do
|
21
|
+
content
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
class SwapOn < DaisyUIViewComponents::BaseComponent
|
28
|
+
|
29
|
+
def call
|
30
|
+
html :div, class: css('swap-on') do
|
31
|
+
content
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
class SwapOff < DaisyUIViewComponents::BaseComponent
|
38
|
+
|
39
|
+
def call
|
40
|
+
html :div, class: css('swap-off') do
|
41
|
+
content
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DaisyUIViewComponents
|
4
|
+
module Table
|
5
|
+
class Component < DaisyUIViewComponents::BaseComponent
|
6
|
+
|
7
|
+
SIZE_CLASSES = {
|
8
|
+
xs: 'table-xs',
|
9
|
+
sm: 'table-sm',
|
10
|
+
md: 'table-md',
|
11
|
+
lg: 'table-lg'
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
SIZE_OPTIONS = SIZE_CLASSES.keys.freeze
|
15
|
+
|
16
|
+
option :zebra, optional: true
|
17
|
+
option :size, optional: true, desc: SIZE_OPTIONS, type: proc(&:to_sym)
|
18
|
+
|
19
|
+
css_classes 'table' do |classes|
|
20
|
+
classes << 'table-zebra' if zebra
|
21
|
+
classes << SIZE_CLASSES[size] if size
|
22
|
+
end
|
23
|
+
|
24
|
+
renders_one :head, 'Head'
|
25
|
+
renders_one :body, 'Body'
|
26
|
+
renders_one :footer
|
27
|
+
|
28
|
+
class Cell < DaisyUIViewComponents::BaseComponent
|
29
|
+
|
30
|
+
option :tag
|
31
|
+
|
32
|
+
def call
|
33
|
+
html tag do
|
34
|
+
content
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
class Head < DaisyUIViewComponents::BaseComponent
|
41
|
+
|
42
|
+
renders_many :cells, lambda { |*args, **kwargs, &block|
|
43
|
+
DaisyUIViewComponents::Table::Component::Cell.new(*args, tag: :th, **kwargs, &block)
|
44
|
+
}
|
45
|
+
|
46
|
+
def call
|
47
|
+
html :thead do
|
48
|
+
content_tag :tr do
|
49
|
+
cells.each do |cell|
|
50
|
+
concat cell
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
class Body < DaisyUIViewComponents::BaseComponent
|
59
|
+
|
60
|
+
renders_many :rows, 'Row'
|
61
|
+
|
62
|
+
def call
|
63
|
+
html :tbody do
|
64
|
+
rows.each do |row|
|
65
|
+
concat row
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class Row < DaisyUIViewComponents::BaseComponent
|
71
|
+
|
72
|
+
option :hover, optional: true
|
73
|
+
|
74
|
+
renders_many :cells, lambda { |*args, **kwrags, &block|
|
75
|
+
DaisyUIViewComponents::Table::Component::Cell.new(*args, tag: :td, **kwrags, &block)
|
76
|
+
}
|
77
|
+
|
78
|
+
def call
|
79
|
+
html :tr, class: css(hover ? 'hover' : '') do
|
80
|
+
cells.each do |cell|
|
81
|
+
concat cell
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DaisyUIViewComponents
|
4
|
+
module Tabs
|
5
|
+
class Component < DaisyUIViewComponents::BaseComponent
|
6
|
+
|
7
|
+
SIZE_CLASSES = {
|
8
|
+
xs: 'tabs-xs',
|
9
|
+
sm: 'tabs-sm',
|
10
|
+
md: 'tabs-md',
|
11
|
+
lg: 'tabs-lg'
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
SIZE_OPTIONS = SIZE_CLASSES.keys.freeze
|
15
|
+
|
16
|
+
option :size, optional: true, desc: SIZE_OPTIONS, type: proc(&:to_sym)
|
17
|
+
option :boxed, optional: true, default: proc { false }
|
18
|
+
option :bordered, optional: true, default: proc { false }
|
19
|
+
option :lifted, optional: true, default: proc { false }
|
20
|
+
|
21
|
+
css_classes 'tabs' do |classes|
|
22
|
+
classes << SIZE_CLASSES[size] if size
|
23
|
+
classes << 'tabs-boxed' if boxed
|
24
|
+
classes << 'tabs-bordered' if bordered
|
25
|
+
classes << 'tabs-lifted' if lifted
|
26
|
+
end
|
27
|
+
|
28
|
+
renders_many :tabs, 'Tab'
|
29
|
+
|
30
|
+
class Tab < DaisyUIViewComponents::BaseComponent
|
31
|
+
|
32
|
+
option :active, optional: true
|
33
|
+
option :disabled, optional: true
|
34
|
+
|
35
|
+
css_classes 'tab' do |classes|
|
36
|
+
classes << 'tab-active' if active
|
37
|
+
classes << 'tab-disabled' if disabled
|
38
|
+
end
|
39
|
+
|
40
|
+
def call
|
41
|
+
html :a, role: 'tab' do
|
42
|
+
content
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DaisyUIViewComponents
|
4
|
+
module TextInput
|
5
|
+
class Component < DaisyUIViewComponents::BaseComponent
|
6
|
+
|
7
|
+
SIZE_CLASSES = {
|
8
|
+
xs: 'input-xs',
|
9
|
+
sm: 'input-sm',
|
10
|
+
md: 'input-md',
|
11
|
+
lg: 'input-lg'
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
COLOR_CLASSES = {
|
15
|
+
primary: 'input-primary',
|
16
|
+
secondary: 'input-secondary',
|
17
|
+
accent: 'input-accent',
|
18
|
+
info: 'input-info',
|
19
|
+
success: 'input-success',
|
20
|
+
warning: 'input-warning',
|
21
|
+
error: 'input-error'
|
22
|
+
}.freeze
|
23
|
+
|
24
|
+
SIZE_OPTIONS = SIZE_CLASSES.keys.freeze
|
25
|
+
COLOR_OPTIONS = COLOR_CLASSES.keys.freeze
|
26
|
+
DEFAULT_COLOR = :primary
|
27
|
+
|
28
|
+
option :size, optional: true, desc: SIZE_OPTIONS, type: proc(&:to_sym)
|
29
|
+
option :bordered, optional: true, default: false
|
30
|
+
option :ghost, optional: true, default: false
|
31
|
+
option :color, optional: true, desc: COLOR_CLASSES, type: proc(&:to_sym)
|
32
|
+
option :form, optional: true
|
33
|
+
option :field, optional: true, type: proc(&:to_s)
|
34
|
+
|
35
|
+
css_classes 'input' do |classes|
|
36
|
+
classes << SIZE_CLASSES[size] if size
|
37
|
+
classes << COLOR_CLASSES[color] if color
|
38
|
+
classes << 'input-ghost' if ghost
|
39
|
+
classes << 'input-bordered' if bordered
|
40
|
+
end
|
41
|
+
|
42
|
+
renders_one :before
|
43
|
+
renders_one :after
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def field
|
48
|
+
@field ||= content
|
49
|
+
end
|
50
|
+
|
51
|
+
def value
|
52
|
+
html_options[:value]
|
53
|
+
end
|
54
|
+
|
55
|
+
def input_opts
|
56
|
+
html_options.except(:class)
|
57
|
+
end
|
58
|
+
|
59
|
+
def input
|
60
|
+
cls = before || after ? 'grow border-none focuso:outline-none focus:ring-0' : css_classes
|
61
|
+
|
62
|
+
if form.present?
|
63
|
+
form.text_field field, class: css(cls), **input_opts
|
64
|
+
else
|
65
|
+
text_field_tag field, value, class: css(cls), **input_opts
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DaisyUIViewComponents
|
4
|
+
module Textarea
|
5
|
+
class Component < DaisyUIViewComponents::BaseComponent
|
6
|
+
|
7
|
+
SIZE_CLASSES = {
|
8
|
+
xs: 'textarea-xs',
|
9
|
+
sm: 'textarea-sm',
|
10
|
+
md: 'textarea-md',
|
11
|
+
lg: 'textarea-lg'
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
COLOR_CLASSES = {
|
15
|
+
primary: 'textarea-primary',
|
16
|
+
secondary: 'textarea-secondary',
|
17
|
+
accent: 'textarea-accent',
|
18
|
+
info: 'textarea-info',
|
19
|
+
success: 'textarea-success',
|
20
|
+
warning: 'textarea-warning',
|
21
|
+
error: 'textarea-error'
|
22
|
+
}.freeze
|
23
|
+
|
24
|
+
SIZE_OPTIONS = SIZE_CLASSES.keys.freeze
|
25
|
+
COLOR_OPTIONS = COLOR_CLASSES.keys.freeze
|
26
|
+
DEFAULT_COLOR = :primary
|
27
|
+
|
28
|
+
option :size, optional: true, desc: SIZE_OPTIONS, type: proc(&:to_sym)
|
29
|
+
option :color, optional: true, desc: COLOR_CLASSES, type: proc(&:to_sym)
|
30
|
+
option :ghost, optional: true, default: false
|
31
|
+
option :bordered, optional: true, default: false
|
32
|
+
option :form, optional: true
|
33
|
+
option :field, optional: true, type: proc(&:to_s), default: proc { content&.to_sym }
|
34
|
+
|
35
|
+
css_classes 'textarea' do |classes|
|
36
|
+
classes << 'textarea-ghost' if ghost
|
37
|
+
classes << 'textarea-bordered' if bordered
|
38
|
+
classes << SIZE_CLASSES[size] if size
|
39
|
+
classes << COLOR_CLASSES[color] if color
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def value
|
45
|
+
html_options[:value]
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DaisyUIViewComponents
|
4
|
+
module Toggle
|
5
|
+
class Component < DaisyUIViewComponents::Checkbox::Component
|
6
|
+
|
7
|
+
SIZE_CLASSES = {
|
8
|
+
xs: 'toggle-xs',
|
9
|
+
sm: 'toggle-sm',
|
10
|
+
md: 'toggle-md',
|
11
|
+
lg: 'toggle-lg'
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
SIZE_OPTIONS = SIZE_CLASSES.keys.freeze
|
15
|
+
|
16
|
+
COLOR_CLASSES = {
|
17
|
+
primary: 'toggle-primary',
|
18
|
+
secondary: 'toggle-secondary',
|
19
|
+
accent: 'toggle-accent',
|
20
|
+
info: 'toggle-info',
|
21
|
+
success: 'toggle-success',
|
22
|
+
warning: 'toggle-warning',
|
23
|
+
error: 'toggle-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 'toggle' do |classes|
|
37
|
+
classes << SIZE_CLASSES[size] if size
|
38
|
+
classes << COLOR_CLASSES[color] if color
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DaisyUIViewComponents
|
4
|
+
module Cache
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def component_cache
|
9
|
+
@component_cache ||= {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def namespaces
|
13
|
+
@namespaces ||= ['']
|
14
|
+
end
|
15
|
+
|
16
|
+
def append_namespace(namespace)
|
17
|
+
namespaces << namespace
|
18
|
+
end
|
19
|
+
|
20
|
+
def find(name)
|
21
|
+
if (component_class = component_cache[name])
|
22
|
+
return component_class
|
23
|
+
end
|
24
|
+
|
25
|
+
class_names = %W[
|
26
|
+
DaisyUIViewComponents::#{name.to_s.camelize}::Component
|
27
|
+
#{name.to_s.camelize}ViewComponent::Component
|
28
|
+
]
|
29
|
+
|
30
|
+
namespaces.each do |namespace|
|
31
|
+
class_names.each do |class_name|
|
32
|
+
component_class = "#{namespace}::#{class_name}".constantize
|
33
|
+
component_cache[name] = component_class unless Rails.env.development?
|
34
|
+
return component_class
|
35
|
+
rescue NameError
|
36
|
+
# skip
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
checked_constants = namespaces.map do |ns|
|
41
|
+
class_names.map { |cn| "#{ns}::#{cn}" }
|
42
|
+
end.flatten
|
43
|
+
|
44
|
+
raise "No component named '#{name}' could be found (looked in #{checked_constants.join(', ')})"
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/engine'
|
4
|
+
require 'daisyui_view_components'
|
5
|
+
|
6
|
+
module DaisyUIViewComponents
|
7
|
+
class Engine < ::Rails::Engine
|
8
|
+
|
9
|
+
isolate_namespace DaisyUIViewComponents
|
10
|
+
|
11
|
+
config.autoload_paths << "#{config.root}/lib"
|
12
|
+
config.eager_load_paths << "#{config.root}/app/components"
|
13
|
+
|
14
|
+
initializer 'daisyui_view_components.assets' do |app|
|
15
|
+
app.config.assets.precompile += %w[daisyui_view_components] if app.config.respond_to?(:assets)
|
16
|
+
end
|
17
|
+
|
18
|
+
initializer 'daisyui_view_components.inflections' do
|
19
|
+
inflector = Rails.autoloaders.main.inflector
|
20
|
+
inflector.inflect('daisyui_view_components' => 'DaisyUIViewComponents')
|
21
|
+
end
|
22
|
+
|
23
|
+
initializer 'daisyui_view_components.include_helpers' do
|
24
|
+
ActiveSupport::Reloader.to_prepare do
|
25
|
+
ActionView::Base.include DaisyUIViewComponents::Helpers::Component
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DaisyUIViewComponents
|
4
|
+
module Helpers
|
5
|
+
module Component
|
6
|
+
|
7
|
+
def component(name, content = nil, **kwargs, &block)
|
8
|
+
component = DaisyUIViewComponents::Cache.find(name)
|
9
|
+
|
10
|
+
if (collection = kwargs.delete(:collection))
|
11
|
+
component = component.with_collection(collection, **kwargs)
|
12
|
+
render(component, &block)
|
13
|
+
elsif content.present?
|
14
|
+
component = component.new(content, **kwargs)
|
15
|
+
else
|
16
|
+
component = component.new(**kwargs)
|
17
|
+
end
|
18
|
+
|
19
|
+
render(component, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def cn(*inputs)
|
23
|
+
normalized = inputs.flat_map do |input|
|
24
|
+
if input.is_a?(Array)
|
25
|
+
input.flatten
|
26
|
+
else
|
27
|
+
input
|
28
|
+
end
|
29
|
+
end.compact.join(' ')
|
30
|
+
|
31
|
+
DaisyUIViewComponents::TailwindMerger.merge(normalized)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tailwind_merge'
|
4
|
+
|
5
|
+
module DaisyUIViewComponents
|
6
|
+
class TailwindMerger
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
def merge(...)
|
11
|
+
merger.merge(...)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def merger
|
17
|
+
@merger ||= TailwindMerge::Merger.new
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'daisyui_view_components/version'
|
4
|
+
require_relative 'daisyui_view_components/cache'
|
5
|
+
require_relative 'daisyui_view_components/helpers/component'
|
6
|
+
require_relative 'daisyui_view_components/engine'
|
7
|
+
require_relative 'daisyui_view_components/tailwind_merger'
|
8
|
+
|
9
|
+
module DaisyUIViewComponents
|
10
|
+
class Error < StandardError
|
11
|
+
end
|
12
|
+
end
|