loco_motion-rails 0.4.0 → 0.5.0
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/README.md +6 -1
- data/app/components/daisy/actions/button_component.html.haml +2 -2
- data/app/components/daisy/actions/button_component.rb +98 -59
- data/app/components/daisy/actions/dropdown_component.html.haml +1 -2
- data/app/components/daisy/actions/dropdown_component.rb +7 -10
- data/app/components/daisy/actions/modal_component.html.haml +10 -8
- data/app/components/daisy/actions/modal_component.rb +6 -6
- data/app/components/daisy/actions/swap_component.rb +13 -9
- data/app/components/daisy/actions/theme_controller.js +113 -0
- data/app/components/daisy/actions/theme_controller_component.rb +58 -17
- data/app/components/daisy/actions/theme_preview_component.html.haml +5 -0
- data/app/components/daisy/actions/theme_preview_component.rb +68 -0
- data/app/components/daisy/data_display/accordion_component.html.haml +0 -1
- data/app/components/daisy/data_display/accordion_component.rb +10 -3
- data/app/components/daisy/data_display/avatar_component.html.haml +1 -1
- data/app/components/daisy/data_display/avatar_component.rb +17 -7
- data/app/components/daisy/data_display/badge_component.rb +122 -4
- data/app/components/daisy/data_display/card_component.html.haml +1 -1
- data/app/components/daisy/data_display/card_component.rb +20 -6
- data/app/components/daisy/data_display/chat_component.rb +2 -2
- data/app/components/daisy/data_display/collapse_component.rb +9 -5
- data/app/components/daisy/data_display/countdown_component.rb +15 -5
- data/app/components/daisy/data_display/figure_component.rb +8 -3
- data/app/components/daisy/data_display/kbd_component.rb +13 -4
- data/app/components/daisy/data_display/list_component.html.haml +5 -0
- data/app/components/daisy/data_display/list_component.rb +82 -0
- data/app/components/daisy/data_display/list_item_component.rb +39 -0
- data/app/components/daisy/data_display/stat_component.html.haml +5 -6
- data/app/components/daisy/data_display/stat_component.rb +21 -8
- data/app/components/daisy/data_display/status_component.rb +47 -0
- data/app/components/daisy/data_display/timeline_component.rb +1 -1
- data/app/components/daisy/data_input/cally_component.html.haml +14 -0
- data/app/components/daisy/data_input/cally_component.rb +182 -0
- data/app/components/daisy/data_input/cally_input_component.html.haml +5 -0
- data/app/components/daisy/data_input/cally_input_component.rb +165 -0
- data/app/components/daisy/data_input/cally_input_controller.js +235 -0
- data/app/components/daisy/data_input/checkbox_component.html.haml +20 -0
- data/app/components/daisy/data_input/checkbox_component.rb +21 -7
- data/app/components/daisy/data_input/fieldset_component.html.haml +8 -0
- data/app/components/daisy/data_input/fieldset_component.rb +57 -0
- data/app/components/daisy/data_input/file_input_component.rb +6 -0
- data/app/components/daisy/data_input/filter_component.html.haml +3 -0
- data/app/components/daisy/data_input/filter_component.rb +221 -0
- data/app/components/daisy/data_input/label_component.rb +2 -2
- data/app/components/daisy/data_input/radio_button_component.rb +1 -1
- data/app/components/daisy/data_input/rating_component.html.haml +0 -2
- data/app/components/daisy/data_input/rating_component.rb +3 -2
- data/app/components/daisy/data_input/select_component.html.haml +27 -15
- data/app/components/daisy/data_input/select_component.rb +152 -10
- data/app/components/daisy/data_input/text_area_component.rb +11 -8
- data/app/components/daisy/data_input/text_input_component.html.haml +25 -4
- data/app/components/daisy/data_input/text_input_component.rb +38 -36
- data/app/components/daisy/data_input/toggle_component.rb +12 -0
- data/app/components/daisy/feedback/alert_component.html.haml +1 -1
- data/app/components/daisy/feedback/alert_component.rb +86 -2
- data/app/components/daisy/feedback/loading_component.rb +10 -3
- data/app/components/daisy/feedback/skeleton_component.rb +1 -1
- data/app/components/daisy/layout/divider_component.rb +4 -2
- data/app/components/daisy/layout/drawer_component.html.haml +0 -1
- data/app/components/daisy/layout/footer_component.rb +6 -6
- data/app/components/daisy/mockup/device_component.rb +15 -18
- data/app/components/daisy/navigation/breadcrumbs_component.html.haml +0 -1
- data/app/components/daisy/navigation/breadcrumbs_component.rb +84 -9
- data/app/components/daisy/navigation/dock_component.rb +146 -0
- data/app/components/daisy/navigation/link_component.rb +18 -9
- data/app/components/daisy/navigation/menu_component.rb +15 -9
- data/app/components/daisy/navigation/navbar_component.html.haml +1 -1
- data/app/components/daisy/navigation/navbar_component.rb +2 -13
- data/app/components/daisy/navigation/steps_component.rb +6 -6
- data/app/components/daisy/navigation/tabs_component.html.haml +0 -1
- data/app/components/daisy/navigation/tabs_component.rb +26 -16
- data/app/components/hero/icon_component.rb +15 -5
- data/app/helpers/daisy/form_builder_helper.rb +30 -3
- data/app/views/examples/daisy/data_input/filters.html.haml +62 -0
- data/lib/hero.rb +1 -1
- data/lib/loco_motion/base_component.rb +44 -1
- data/lib/loco_motion/component_config.rb +1 -0
- data/lib/loco_motion/concerns/iconable_component.rb +134 -0
- data/lib/loco_motion/concerns/labelable_component.rb +142 -0
- data/lib/loco_motion/concerns/linkable_component.rb +40 -0
- data/lib/loco_motion/concerns/tippable_component.rb +25 -10
- data/lib/loco_motion/helpers.rb +27 -18
- data/lib/loco_motion/patches/view_component/slot_loco_parent_patch.rb +37 -0
- data/lib/loco_motion/patches/view_component/slotable_default_patch.rb +21 -0
- data/lib/loco_motion/version.rb +1 -1
- data/lib/loco_motion.rb +12 -2
- metadata +65 -19
- data/app/components/daisy/actions/theme_controller_component.html.haml +0 -5
- data/app/components/daisy/layout/artboard_component.rb +0 -59
- data/app/components/daisy/navigation/bottom_nav_component.rb +0 -138
@@ -1,15 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
1
|
+
- if has_any_label?
|
2
|
+
= part(:label_wrapper) do
|
3
|
+
- if has_start_label?
|
4
|
+
- if start?
|
5
|
+
= start
|
6
|
+
- else
|
7
|
+
= part(:start) do
|
8
|
+
= @start
|
9
|
+
|
10
|
+
- if has_floating_label?
|
11
|
+
- if floating?
|
12
|
+
= floating
|
13
|
+
- else
|
14
|
+
= part(:floating) do
|
15
|
+
= @floating
|
16
|
+
|
17
|
+
= render_component
|
18
|
+
|
19
|
+
- if has_end_label?
|
20
|
+
- if end?
|
21
|
+
= self.send(:end)
|
22
|
+
- else
|
23
|
+
= part(:end) do
|
24
|
+
= @end
|
25
|
+
|
26
|
+
- else
|
27
|
+
= render_component
|
@@ -2,21 +2,46 @@
|
|
2
2
|
|
3
3
|
#
|
4
4
|
# The Select component provides a styled dropdown select input for forms.
|
5
|
-
# It supports various styling options, including sizes, colors,
|
5
|
+
# It supports various styling options, including sizes, colors, and variants.
|
6
|
+
# Additionally, it supports labelable functionality with start, end, and
|
7
|
+
# floating labels.
|
6
8
|
#
|
7
|
-
# @
|
9
|
+
# @note Select inputs have a border by default and a width of 20rem. Use
|
10
|
+
# `select-ghost` to remove the border.
|
11
|
+
#
|
12
|
+
# @part placeholder The placeholder option element that is shown when no option
|
13
|
+
# is selected.
|
14
|
+
# @part label_wrapper The wrapper element for labels (when using
|
15
|
+
# start/end/floating labels).
|
16
|
+
# @part start The element that contains the start label (appears before the
|
17
|
+
# select).
|
18
|
+
# @part end The element that contains the end label (appears after the select).
|
19
|
+
# @part floating The element that contains the floating label (appears floating
|
20
|
+
# above the select).
|
8
21
|
#
|
9
22
|
# @slot options+ Custom options to be rendered in the select.
|
23
|
+
# @slot start Custom content for the start label.
|
24
|
+
# @slot end Custom content for the end label.
|
25
|
+
# @slot floating Custom content for the floating label.
|
10
26
|
#
|
11
27
|
# @loco_example Using simple strings for options
|
12
|
-
# = daisy_select(name: "size", css: "select-sm
|
28
|
+
# = daisy_select(name: "size", css: "select-sm", options: ["Small", "Medium", "Large"])
|
13
29
|
#
|
14
30
|
# @loco_example Using a block to define options
|
15
31
|
# = daisy_select(name: "color", css: "select-primary") do |select|
|
16
32
|
# - select.with_option(value: "red", label: "Red")
|
17
33
|
# - select.with_option(value: "green", label: "Green")
|
18
34
|
# - select.with_option(value: "blue", label: "Blue")
|
35
|
+
#
|
36
|
+
# @loco_example With a start label
|
37
|
+
# = daisy_select(name: "color", start: "Select a color", options: ["Red", "Green", "Blue"])
|
38
|
+
#
|
39
|
+
# @loco_example With a floating label
|
40
|
+
# = daisy_select(name: "color", floating: "Color", options: ["Red", "Green", "Blue"])
|
41
|
+
#
|
19
42
|
class Daisy::DataInput::SelectComponent < LocoMotion::BaseComponent
|
43
|
+
include LocoMotion::Concerns::LabelableComponent
|
44
|
+
|
20
45
|
class SelectOptionComponent < LocoMotion::BasicComponent
|
21
46
|
attr_reader :value, :label, :selected, :disabled
|
22
47
|
|
@@ -64,7 +89,7 @@ class Daisy::DataInput::SelectComponent < LocoMotion::BaseComponent
|
|
64
89
|
|
65
90
|
define_part :placeholder
|
66
91
|
|
67
|
-
attr_reader :name, :id, :value, :
|
92
|
+
attr_reader :name, :id, :value, :include_blank, :disabled, :required, :options_css, :options_html
|
68
93
|
|
69
94
|
#
|
70
95
|
# Initialize a new select component.
|
@@ -78,8 +103,8 @@ class Daisy::DataInput::SelectComponent < LocoMotion::BaseComponent
|
|
78
103
|
# @option kws value [String, Symbol, Integer] The current value of the select input.
|
79
104
|
# Determines which option is selected on initial render.
|
80
105
|
#
|
81
|
-
# @option kws
|
82
|
-
#
|
106
|
+
# @option kws include_blank [Boolean] Whether to include a blank option at the
|
107
|
+
# top of the list.
|
83
108
|
#
|
84
109
|
# @option kws disabled [Boolean] Whether the select input is disabled. Defaults to
|
85
110
|
# false.
|
@@ -94,24 +119,32 @@ class Daisy::DataInput::SelectComponent < LocoMotion::BaseComponent
|
|
94
119
|
#
|
95
120
|
# @option kws options_html [Hash] HTML attributes to apply to each option.
|
96
121
|
#
|
122
|
+
# @option kws option_label [Symbol] The key to use for the option label.
|
123
|
+
#
|
124
|
+
# @option kws option_value [Symbol] The key to use for the option value.
|
125
|
+
#
|
97
126
|
def initialize(**kws)
|
98
127
|
super(**kws)
|
99
128
|
|
100
129
|
@name = config_option(:name)
|
101
130
|
@id = config_option(:id)
|
102
131
|
@value = config_option(:value)
|
103
|
-
@
|
132
|
+
@include_blank = config_option(:include_blank, false)
|
104
133
|
@disabled = config_option(:disabled, false)
|
105
134
|
@required = config_option(:required, false)
|
106
135
|
@options_list = config_option(:options)
|
107
136
|
@options_css = config_option(:options_css, "")
|
108
137
|
@options_html = config_option(:options_html, {})
|
138
|
+
@option_label = config_option(:option_label, :label)
|
139
|
+
@option_value = config_option(:option_value, :value)
|
109
140
|
end
|
110
141
|
|
111
142
|
#
|
112
143
|
# Sets up the component before rendering.
|
113
144
|
#
|
114
145
|
def before_render
|
146
|
+
super
|
147
|
+
|
115
148
|
setup_component
|
116
149
|
setup_placeholder
|
117
150
|
end
|
@@ -119,10 +152,23 @@ class Daisy::DataInput::SelectComponent < LocoMotion::BaseComponent
|
|
119
152
|
#
|
120
153
|
# Sets up the component by configuring the tag name, CSS classes, and HTML attributes.
|
121
154
|
# Sets the tag to 'select' and adds the 'select' CSS class.
|
155
|
+
# Also adds Stimulus controller data attributes.
|
122
156
|
#
|
123
157
|
def setup_component
|
124
158
|
set_tag_name(:component, :select)
|
125
|
-
|
159
|
+
|
160
|
+
if has_floating_label?
|
161
|
+
add_css(:label_wrapper, "floating-label")
|
162
|
+
add_css(:component, "select")
|
163
|
+
elsif has_start_label? || has_end_label?
|
164
|
+
add_stimulus_controller(:label_wrapper, "select")
|
165
|
+
|
166
|
+
add_css(:label_wrapper, "select")
|
167
|
+
add_css(:start, "label")
|
168
|
+
add_css(:end, "label")
|
169
|
+
else
|
170
|
+
add_css(:component, "select")
|
171
|
+
end
|
126
172
|
|
127
173
|
# Add HTML attributes for the select element
|
128
174
|
add_html(:component,
|
@@ -152,8 +198,8 @@ class Daisy::DataInput::SelectComponent < LocoMotion::BaseComponent
|
|
152
198
|
return [] unless @options_list
|
153
199
|
|
154
200
|
options_list.map do |option|
|
155
|
-
value = option
|
156
|
-
label =
|
201
|
+
value = extract_option_value(option)
|
202
|
+
label = extract_option_label(option, value)
|
157
203
|
|
158
204
|
Daisy::DataInput::SelectComponent::SelectOptionComponent.new(
|
159
205
|
value: value,
|
@@ -167,6 +213,102 @@ class Daisy::DataInput::SelectComponent < LocoMotion::BaseComponent
|
|
167
213
|
|
168
214
|
private
|
169
215
|
|
216
|
+
# Extracts the value from an option using the configured @option_value key or method.
|
217
|
+
#
|
218
|
+
# @param option [Object] The option to extract the value from
|
219
|
+
# @return [Object] The extracted value
|
220
|
+
#
|
221
|
+
def extract_option_value(option)
|
222
|
+
if option.is_a?(Hash)
|
223
|
+
option[@option_value]
|
224
|
+
elsif option.respond_to?(@option_value)
|
225
|
+
option.public_send(@option_value)
|
226
|
+
else
|
227
|
+
option
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
# Extracts the label from an option using the configured @option_label key or method.
|
232
|
+
# Falls back to the value if no label can be extracted.
|
233
|
+
#
|
234
|
+
# @param option [Object] The option to extract the label from
|
235
|
+
# @param value [Object] The extracted value to use as fallback
|
236
|
+
# @return [String] The extracted label or string representation of the value
|
237
|
+
#
|
238
|
+
def extract_option_label(option, value)
|
239
|
+
if option.is_a?(Hash)
|
240
|
+
option[@option_label] || value.to_s
|
241
|
+
elsif option.respond_to?(@option_label)
|
242
|
+
option.public_send(@option_label)
|
243
|
+
else
|
244
|
+
value.to_s
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
# Alias for include_blank to match Ruby convention for boolean methods
|
249
|
+
def include_blank?
|
250
|
+
@include_blank
|
251
|
+
end
|
252
|
+
|
253
|
+
#
|
254
|
+
# Renders the select options based on the configuration.
|
255
|
+
# This method is used by the template to render options consistently.
|
256
|
+
#
|
257
|
+
# @return [String] The HTML for all options in the select.
|
258
|
+
#
|
259
|
+
def render_select_options
|
260
|
+
result = ""
|
261
|
+
|
262
|
+
# Add blank option if configured
|
263
|
+
if include_blank?
|
264
|
+
result += content_tag(:option, "", value: "")
|
265
|
+
end
|
266
|
+
|
267
|
+
# Add options from the block or default options
|
268
|
+
if options?
|
269
|
+
options.each do |option|
|
270
|
+
result += option.call
|
271
|
+
end
|
272
|
+
elsif default_options.present?
|
273
|
+
default_options.each do |option|
|
274
|
+
result += render(option)
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
result.html_safe
|
279
|
+
end
|
280
|
+
|
281
|
+
#
|
282
|
+
# Renders the component part with placeholder, options and content.
|
283
|
+
# This method is used by the template to render the select component consistently.
|
284
|
+
#
|
285
|
+
# @return [String] The HTML for the select component.
|
286
|
+
#
|
287
|
+
def render_component
|
288
|
+
part(:component) do
|
289
|
+
result = ""
|
290
|
+
|
291
|
+
# Add placeholder if provided
|
292
|
+
if @placeholder
|
293
|
+
result += part(:placeholder) do
|
294
|
+
@placeholder
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
# Add options
|
299
|
+
result += render_select_options
|
300
|
+
|
301
|
+
# Add content if present
|
302
|
+
if content?
|
303
|
+
result += (content || "")
|
304
|
+
end
|
305
|
+
|
306
|
+
result.html_safe
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
private
|
311
|
+
|
170
312
|
#
|
171
313
|
# Ensures the options list is always an array, even if a single option is provided.
|
172
314
|
#
|
@@ -5,6 +5,9 @@
|
|
5
5
|
# It can be used standalone or with a form builder, and supports
|
6
6
|
# various styling options and states.
|
7
7
|
#
|
8
|
+
# @note Text areas have a border by default. Use `textarea-ghost` to remove the
|
9
|
+
# border.
|
10
|
+
#
|
8
11
|
# @part component The main textarea element that users can type into.
|
9
12
|
#
|
10
13
|
# @loco_example Basic Usage
|
@@ -19,23 +22,23 @@
|
|
19
22
|
# @loco_example With Specified Rows
|
20
23
|
# = daisy_text_area(name: "message", rows: 6)
|
21
24
|
#
|
22
|
-
# @loco_example
|
23
|
-
# = daisy_text_area(name: "message", css: "textarea-
|
25
|
+
# @loco_example Borderless Style
|
26
|
+
# = daisy_text_area(name: "message", css: "textarea-ghost")
|
24
27
|
#
|
25
28
|
# @loco_example Different Colors
|
26
29
|
# .flex.flex-col.gap-4
|
27
|
-
# = daisy_text_area(name: "primary", placeholder: "Primary", css: "textarea-primary
|
28
|
-
# = daisy_text_area(name: "secondary", placeholder: "Secondary", css: "textarea-secondary
|
29
|
-
# = daisy_text_area(name: "accent", placeholder: "Accent", css: "textarea-accent
|
30
|
+
# = daisy_text_area(name: "primary", placeholder: "Primary", css: "textarea-primary")
|
31
|
+
# = daisy_text_area(name: "secondary", placeholder: "Secondary", css: "textarea-secondary")
|
32
|
+
# = daisy_text_area(name: "accent", placeholder: "Accent", css: "textarea-accent")
|
30
33
|
#
|
31
34
|
# @loco_example Disabled TextArea
|
32
|
-
# = daisy_text_area(name: "message", disabled: true
|
35
|
+
# = daisy_text_area(name: "message", disabled: true)
|
33
36
|
#
|
34
37
|
# @loco_example Required TextArea
|
35
|
-
# = daisy_text_area(name: "message", required: true
|
38
|
+
# = daisy_text_area(name: "message", required: true)
|
36
39
|
#
|
37
40
|
# @loco_example Readonly TextArea
|
38
|
-
# = daisy_text_area(name: "message", readonly: true, value: "This content cannot be edited."
|
41
|
+
# = daisy_text_area(name: "message", readonly: true, value: "This content cannot be edited.")
|
39
42
|
#
|
40
43
|
class Daisy::DataInput::TextAreaComponent < LocoMotion::BaseComponent
|
41
44
|
attr_reader :name, :id, :value, :placeholder, :rows, :cols, :disabled, :required, :readonly
|
@@ -1,6 +1,27 @@
|
|
1
|
-
|
2
|
-
=
|
1
|
+
- if has_any_label?
|
2
|
+
= part(:label_wrapper) do
|
3
|
+
- if has_start_label?
|
4
|
+
- if start?
|
5
|
+
= start
|
6
|
+
- else
|
7
|
+
= part(:start) do
|
8
|
+
= @start
|
3
9
|
|
4
|
-
|
10
|
+
- if has_floating_label?
|
11
|
+
- if floating?
|
12
|
+
= floating
|
13
|
+
- else
|
14
|
+
= part(:floating) do
|
15
|
+
= @floating
|
5
16
|
|
6
|
-
|
17
|
+
= part(:component)
|
18
|
+
|
19
|
+
- if has_end_label?
|
20
|
+
- if end?
|
21
|
+
= self.send(:end)
|
22
|
+
- else
|
23
|
+
= part(:end) do
|
24
|
+
= @end
|
25
|
+
|
26
|
+
- else
|
27
|
+
= part(:component)
|
@@ -5,13 +5,20 @@
|
|
5
5
|
# It can be used standalone or with a form builder, and supports
|
6
6
|
# various styling options including different types, sizes and variants.
|
7
7
|
#
|
8
|
-
#
|
9
|
-
#
|
8
|
+
# @note Input fields have a border by default and a width of 20rem. Use
|
9
|
+
# `input-ghost` to remove the border.
|
10
10
|
#
|
11
|
-
# @part
|
11
|
+
# @part label_wrapper The wrapper element for labels (when using
|
12
|
+
# start/end/floating labels).
|
13
|
+
# @part start The element that contains the start label (appears before the
|
14
|
+
# input).
|
15
|
+
# @part end The element that contains the end label (appears after the input).
|
16
|
+
# @part floating The element that contains the floating label (appears floating
|
17
|
+
# above the input).
|
12
18
|
#
|
13
19
|
# @slot start Content to display before the input field.
|
14
|
-
# @slot end
|
20
|
+
# @slot end Content to display after the input field.
|
21
|
+
# @slot floating Custom content for the floating label.
|
15
22
|
#
|
16
23
|
# @loco_example Basic Usage
|
17
24
|
# = daisy_text_input(name: "username", id: "username")
|
@@ -19,10 +26,22 @@
|
|
19
26
|
# @loco_example With Placeholder
|
20
27
|
# = daisy_text_input(name: "email", id: "email", placeholder: "Enter your email")
|
21
28
|
#
|
29
|
+
# @loco_example Ghost Style (No Border)
|
30
|
+
# = daisy_text_input(name: "search", id: "search", css: "input-ghost")
|
31
|
+
#
|
22
32
|
# @loco_example Different Types
|
23
33
|
# = daisy_text_input(name: "password", id: "password", type: "password")
|
24
34
|
# = daisy_text_input(name: "email", id: "email", type: "email")
|
25
35
|
#
|
36
|
+
# @loco_example With Start Label
|
37
|
+
# = daisy_text_input(name: "username", id: "username", start: "Username:")
|
38
|
+
#
|
39
|
+
# @loco_example With End Label
|
40
|
+
# = daisy_text_input(name: "email", id: "email", end: "@example.com")
|
41
|
+
#
|
42
|
+
# @loco_example With Floating Label
|
43
|
+
# = daisy_text_input(name: "username", id: "username", floating: "Username")
|
44
|
+
#
|
26
45
|
# @loco_example With Icons
|
27
46
|
# = daisy_text_input(name: "search", placeholder: "Search...") do |text_input|
|
28
47
|
# - text_input.with_start do
|
@@ -39,12 +58,9 @@
|
|
39
58
|
# = daisy_text_input(name: "username", id: "username", disabled: true)
|
40
59
|
#
|
41
60
|
class Daisy::DataInput::TextInputComponent < LocoMotion::BaseComponent
|
42
|
-
|
61
|
+
include LocoMotion::Concerns::LabelableComponent
|
43
62
|
|
44
|
-
|
45
|
-
renders_one :end
|
46
|
-
|
47
|
-
attr_reader :name, :id, :value, :placeholder, :type, :disabled, :required, :readonly
|
63
|
+
attr_reader :name, :id, :value, :type, :disabled, :required, :readonly
|
48
64
|
|
49
65
|
#
|
50
66
|
# Instantiate a new TextInput component.
|
@@ -57,8 +73,6 @@ class Daisy::DataInput::TextInputComponent < LocoMotion::BaseComponent
|
|
57
73
|
#
|
58
74
|
# @option kws value [String] The initial value of the text input.
|
59
75
|
#
|
60
|
-
# @option kws placeholder [String] Placeholder text for the text input.
|
61
|
-
#
|
62
76
|
# @option kws type [String] The type of input (text, password, email, etc.).
|
63
77
|
# Defaults to "text".
|
64
78
|
#
|
@@ -77,19 +91,20 @@ class Daisy::DataInput::TextInputComponent < LocoMotion::BaseComponent
|
|
77
91
|
@name = config_option(:name)
|
78
92
|
@id = config_option(:id)
|
79
93
|
@value = config_option(:value, nil)
|
80
|
-
@placeholder = config_option(:placeholder, nil)
|
81
94
|
@type = config_option(:type, "text")
|
82
95
|
@disabled = config_option(:disabled, false)
|
83
96
|
@required = config_option(:required, false)
|
84
97
|
@readonly = config_option(:readonly, false)
|
98
|
+
@change = config_option(:change)
|
85
99
|
end
|
86
100
|
|
87
101
|
#
|
88
102
|
# Calls the {setup_component} method before rendering the component.
|
89
103
|
#
|
90
104
|
def before_render
|
105
|
+
super
|
106
|
+
|
91
107
|
setup_component
|
92
|
-
setup_input
|
93
108
|
end
|
94
109
|
|
95
110
|
#
|
@@ -101,23 +116,17 @@ class Daisy::DataInput::TextInputComponent < LocoMotion::BaseComponent
|
|
101
116
|
# placeholder, type, and states like disabled, required, and readonly.
|
102
117
|
#
|
103
118
|
def setup_component
|
104
|
-
set_tag_name(:component, :
|
119
|
+
set_tag_name(:component, :input)
|
105
120
|
|
106
|
-
|
107
|
-
|
121
|
+
if has_floating_label?
|
122
|
+
add_css(:label_wrapper, "floating-label input")
|
123
|
+
elsif has_start_label? || has_end_label?
|
124
|
+
add_css(:label_wrapper, "input")
|
125
|
+
else
|
126
|
+
add_css(:component, "input")
|
127
|
+
end
|
108
128
|
|
109
|
-
|
110
|
-
# Sets up the input part by configuring the tag name, CSS classes, and HTML
|
111
|
-
# attributes. Sets the tag to input with appropriate type and adds the grow
|
112
|
-
# styling to ensure the input expands to fill available space.
|
113
|
-
#
|
114
|
-
# This configures basic input attributes like name, id, value, placeholder,
|
115
|
-
# and states like disabled, required, and readonly.
|
116
|
-
#
|
117
|
-
def setup_input
|
118
|
-
set_tag_name(:input, :input)
|
119
|
-
add_css(:input, "[:where(&)]:grow")
|
120
|
-
add_html(:input, {
|
129
|
+
add_html(:component, {
|
121
130
|
type: @type,
|
122
131
|
name: @name,
|
123
132
|
id: @id,
|
@@ -127,14 +136,7 @@ class Daisy::DataInput::TextInputComponent < LocoMotion::BaseComponent
|
|
127
136
|
required: @required,
|
128
137
|
readonly: @readonly
|
129
138
|
})
|
130
|
-
end
|
131
139
|
|
132
|
-
|
133
|
-
#
|
134
|
-
# Since `end` is a reserved word in Ruby, we need to use a different method
|
135
|
-
# name in the template.
|
136
|
-
#
|
137
|
-
def end_content
|
138
|
-
self.end
|
140
|
+
add_html(:component, { onchange: "document.getElementById('#{@change}').value = this.value" }) if @change
|
139
141
|
end
|
140
142
|
end
|
@@ -5,6 +5,15 @@
|
|
5
5
|
# It can be used standalone or with a form builder, and provides a visual way
|
6
6
|
# to toggle between two states (on/off).
|
7
7
|
#
|
8
|
+
# @part label_wrapper The wrapper element for labels (when using
|
9
|
+
# start/end/floating labels).
|
10
|
+
# @part start The element that contains the start label (appears before the
|
11
|
+
# toggle).
|
12
|
+
# @part end The element that contains the end label (appears after the toggle).
|
13
|
+
#
|
14
|
+
# @slot start Custom content for the start label.
|
15
|
+
# @slot end Custom content for the end label.
|
16
|
+
#
|
8
17
|
# @loco_example Basic Usage
|
9
18
|
# = daisy_toggle(name: "notifications", id: "notifications")
|
10
19
|
#
|
@@ -17,6 +26,9 @@
|
|
17
26
|
# @loco_example Disabled Toggle
|
18
27
|
# = daisy_toggle(name: "disabled", id: "disabled", disabled: true)
|
19
28
|
#
|
29
|
+
# @loco_example With End Label (common for toggles)
|
30
|
+
# = daisy_toggle(name: "notifications", id: "notifications", end: "Enable notifications")
|
31
|
+
#
|
20
32
|
class Daisy::DataInput::ToggleComponent < Daisy::DataInput::CheckboxComponent
|
21
33
|
#
|
22
34
|
# Instantiate a new Toggle component.
|
@@ -9,6 +9,12 @@
|
|
9
9
|
# @part content_wrapper [HTML] A wrapper for the main content of the alert.
|
10
10
|
# This allows for proper spacing and alignment with the icon.
|
11
11
|
#
|
12
|
+
# @option kws [String] :style (:default) The style of the alert.
|
13
|
+
# [:info, :success, :warning, :error, :default]
|
14
|
+
# @option kws [Boolean] :soft (false) Use the soft style variant.
|
15
|
+
# @option kws [Boolean] :outline (false) Use the outline style variant.
|
16
|
+
# @option kws [Boolean] :dash (false) Use the dash style variant.
|
17
|
+
#
|
12
18
|
# @loco_example Basic Alert
|
13
19
|
# = daisy_alert do
|
14
20
|
# This is a standard alert message.
|
@@ -30,7 +36,77 @@
|
|
30
36
|
# = daisy_alert(icon: "exclamation-circle", css: "alert-error", icon_html: { variant: :outline }) do
|
31
37
|
# Error alert.
|
32
38
|
#
|
39
|
+
# @loco_example Default
|
40
|
+
# = daisy_alert do
|
41
|
+
# This is an default alert.
|
42
|
+
#
|
43
|
+
# @loco_example Info
|
44
|
+
# = daisy_alert(css: "alert-info") do
|
45
|
+
# This is an info alert.
|
46
|
+
#
|
47
|
+
# @loco_example Success
|
48
|
+
# = daisy_alert(css: "alert-success") do
|
49
|
+
# This is a success alert.
|
50
|
+
#
|
51
|
+
# @loco_example Warning
|
52
|
+
# = daisy_alert(css: "alert-warning") do
|
53
|
+
# This is a warning alert.
|
54
|
+
#
|
55
|
+
# @loco_example Error
|
56
|
+
# = daisy_alert(css: "alert-error") do
|
57
|
+
# This is an error alert.
|
58
|
+
#
|
59
|
+
# @loco_example Soft Info
|
60
|
+
# = daisy_alert(css: "alert-info alert-soft") do
|
61
|
+
# This is a soft info alert.
|
62
|
+
#
|
63
|
+
# @loco_example Soft Success
|
64
|
+
# = daisy_alert(css: "alert-success alert-soft") do
|
65
|
+
# This is a soft success alert.
|
66
|
+
#
|
67
|
+
# @loco_example Soft Warning
|
68
|
+
# = daisy_alert(css: "alert-warning alert-soft") do
|
69
|
+
# This is a soft warning alert.
|
70
|
+
#
|
71
|
+
# @loco_example Soft Error
|
72
|
+
# = daisy_alert(css: "alert-error alert-soft") do
|
73
|
+
# This is a soft error alert.
|
74
|
+
#
|
75
|
+
# @loco_example Outline Info
|
76
|
+
# = daisy_alert(css: "alert-info alert-outline") do
|
77
|
+
# This is an outline info alert.
|
78
|
+
#
|
79
|
+
# @loco_example Outline Success
|
80
|
+
# = daisy_alert(css: "alert-success alert-outline") do
|
81
|
+
# This is an outline success alert.
|
82
|
+
#
|
83
|
+
# @loco_example Outline Warning
|
84
|
+
# = daisy_alert(css: "alert-warning alert-outline") do
|
85
|
+
# This is an outline warning alert.
|
86
|
+
#
|
87
|
+
# @loco_example Outline Error
|
88
|
+
# = daisy_alert(css: "alert-error alert-outline") do
|
89
|
+
# This is an outline error alert.
|
90
|
+
#
|
91
|
+
# @loco_example Dash Info
|
92
|
+
# = daisy_alert(css: "alert-info alert-dash") do
|
93
|
+
# This is a dash info alert.
|
94
|
+
#
|
95
|
+
# @loco_example Dash Success
|
96
|
+
# = daisy_alert(css: "alert-success alert-dash") do
|
97
|
+
# This is a dash success alert.
|
98
|
+
#
|
99
|
+
# @loco_example Dash Warning
|
100
|
+
# = daisy_alert(css: "alert-warning alert-dash") do
|
101
|
+
# This is a dash warning alert.
|
102
|
+
#
|
103
|
+
# @loco_example Dash Error
|
104
|
+
# = daisy_alert(css: "alert-error alert-dash") do
|
105
|
+
# This is a dash error alert.
|
106
|
+
#
|
33
107
|
class Daisy::Feedback::AlertComponent < LocoMotion::BaseComponent
|
108
|
+
include LocoMotion::Concerns::IconableComponent
|
109
|
+
|
34
110
|
define_parts :icon, :content_wrapper
|
35
111
|
|
36
112
|
#
|
@@ -49,16 +125,24 @@ class Daisy::Feedback::AlertComponent < LocoMotion::BaseComponent
|
|
49
125
|
# `alert-info`, `alert-success`, `alert-warning`, or `alert-error` for
|
50
126
|
# different alert types.
|
51
127
|
#
|
128
|
+
# @option kws style [String] The style of the alert.
|
129
|
+
# [:info, :success, :warning, :error, :default]
|
130
|
+
# @option kws soft [Boolean] Use the soft style variant.
|
131
|
+
# @option kws outline [Boolean] Use the outline style variant.
|
132
|
+
# @option kws dash [Boolean] Use the dash style variant.
|
133
|
+
#
|
52
134
|
def initialize(*args, **kws, &block)
|
53
135
|
super
|
54
136
|
|
55
137
|
@icon = config_option(:icon)
|
56
138
|
end
|
57
139
|
|
140
|
+
def default_icon_size
|
141
|
+
"where:size-6"
|
142
|
+
end
|
143
|
+
|
58
144
|
def before_render
|
59
145
|
add_css(:component, "alert")
|
60
146
|
add_html(:component, { role: "alert" })
|
61
|
-
|
62
|
-
add_css(:icon, "[:where(&)]:size-8")
|
63
147
|
end
|
64
148
|
end
|
@@ -20,7 +20,7 @@
|
|
20
20
|
# readability, but CSS classes must still use the `loading-*` prefix.
|
21
21
|
#
|
22
22
|
class Daisy::Feedback::LoadingComponent < LocoMotion::BaseComponent
|
23
|
-
|
23
|
+
include LocoMotion::Concerns::TippableComponent
|
24
24
|
|
25
25
|
#
|
26
26
|
# Creates a new Loading component.
|
@@ -41,10 +41,17 @@ class Daisy::Feedback::LoadingComponent < LocoMotion::BaseComponent
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def before_render
|
44
|
-
|
44
|
+
setup_component
|
45
|
+
super
|
45
46
|
end
|
46
|
-
|
47
|
+
|
47
48
|
def call
|
48
49
|
part(:component)
|
49
50
|
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def setup_component
|
55
|
+
add_css(:component, "loading")
|
56
|
+
end
|
50
57
|
end
|