loco_motion-rails 0.0.7 → 0.4.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.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +101 -14
  3. data/app/components/daisy/actions/button_component.rb +109 -8
  4. data/app/components/daisy/actions/dropdown_component.html.haml +5 -5
  5. data/app/components/daisy/actions/dropdown_component.rb +94 -25
  6. data/app/components/daisy/actions/modal_component.html.haml +3 -2
  7. data/app/components/daisy/actions/modal_component.rb +94 -45
  8. data/app/components/daisy/actions/swap_component.rb +114 -5
  9. data/app/components/daisy/actions/theme_controller_component.html.haml +1 -1
  10. data/app/components/daisy/actions/theme_controller_component.rb +36 -1
  11. data/app/components/daisy/data_display/accordion_component.rb +79 -3
  12. data/app/components/daisy/data_display/avatar_component.rb +36 -16
  13. data/app/components/daisy/data_display/badge_component.rb +35 -5
  14. data/app/components/daisy/data_display/card_component.html.haml +5 -13
  15. data/app/components/daisy/data_display/card_component.rb +74 -39
  16. data/app/components/daisy/data_display/carousel_component.rb +38 -0
  17. data/app/components/daisy/data_display/chat_component.rb +40 -10
  18. data/app/components/daisy/data_display/collapse_component.rb +58 -1
  19. data/app/components/daisy/data_display/countdown_component.rb +49 -0
  20. data/app/components/daisy/data_display/diff_component.rb +37 -0
  21. data/app/components/daisy/data_display/figure_component.rb +49 -0
  22. data/app/components/daisy/data_display/kbd_component.rb +50 -2
  23. data/app/components/daisy/data_display/stat_component.rb +64 -6
  24. data/app/components/daisy/data_display/table_component.rb +99 -34
  25. data/app/components/daisy/data_display/timeline_component.rb +45 -0
  26. data/app/components/daisy/data_display/timeline_event_component.rb +39 -1
  27. data/app/components/daisy/data_input/checkbox_component.rb +92 -0
  28. data/app/components/daisy/data_input/file_input_component.rb +92 -0
  29. data/app/components/daisy/data_input/label_component.rb +84 -0
  30. data/app/components/daisy/data_input/radio_button_component.rb +87 -0
  31. data/app/components/daisy/data_input/range_component.rb +95 -0
  32. data/app/components/daisy/data_input/rating_component.html.haml +13 -0
  33. data/app/components/daisy/data_input/rating_component.rb +138 -0
  34. data/app/components/daisy/data_input/select_component.html.haml +15 -0
  35. data/app/components/daisy/data_input/select_component.rb +178 -0
  36. data/app/components/daisy/data_input/text_area_component.rb +124 -0
  37. data/app/components/daisy/data_input/text_input_component.html.haml +6 -0
  38. data/app/components/daisy/data_input/text_input_component.rb +140 -0
  39. data/app/components/daisy/data_input/toggle_component.rb +36 -0
  40. data/app/components/daisy/feedback/alert_component.rb +46 -1
  41. data/app/components/daisy/feedback/loading_component.rb +39 -0
  42. data/app/components/daisy/feedback/progress_component.rb +39 -1
  43. data/app/components/daisy/feedback/radial_progress_component.rb +44 -1
  44. data/app/components/daisy/feedback/skeleton_component.rb +44 -0
  45. data/app/components/daisy/feedback/toast_component.rb +36 -0
  46. data/app/components/daisy/feedback/tooltip_component.rb +46 -10
  47. data/app/components/daisy/layout/artboard_component.rb +48 -0
  48. data/app/components/daisy/layout/divider_component.rb +50 -10
  49. data/app/components/daisy/layout/drawer_component.rb +62 -17
  50. data/app/components/daisy/layout/footer_component.rb +51 -11
  51. data/app/components/daisy/layout/hero_component.rb +67 -5
  52. data/app/components/daisy/layout/indicator_component.rb +55 -8
  53. data/app/components/daisy/layout/join_component.rb +71 -0
  54. data/app/components/daisy/layout/stack_component.rb +59 -0
  55. data/app/components/daisy/mockup/browser_component.rb +78 -0
  56. data/app/components/daisy/mockup/code_component.rb +144 -0
  57. data/app/components/daisy/mockup/device_component.rb +81 -0
  58. data/app/components/daisy/mockup/frame_component.rb +62 -0
  59. data/app/components/daisy/navigation/bottom_nav_component.rb +81 -2
  60. data/app/components/daisy/navigation/breadcrumbs_component.rb +40 -3
  61. data/app/components/daisy/navigation/link_component.rb +31 -6
  62. data/app/components/daisy/navigation/menu_component.rb +52 -20
  63. data/app/components/daisy/navigation/navbar_component.html.haml +1 -1
  64. data/app/components/daisy/navigation/navbar_component.rb +63 -2
  65. data/app/components/daisy/navigation/steps_component.rb +76 -0
  66. data/app/components/daisy/navigation/tabs_component.rb +110 -7
  67. data/app/components/hero/icon_component.rb +40 -0
  68. data/app/helpers/daisy/form_builder_helper.rb +159 -0
  69. data/lib/daisy.rb +10 -0
  70. data/lib/loco_motion/base_component.rb +9 -2
  71. data/lib/loco_motion/engine.rb +6 -0
  72. data/lib/loco_motion/helpers.rb +19 -0
  73. data/lib/loco_motion/version.rb +5 -0
  74. metadata +51 -5
@@ -1,51 +1,81 @@
1
1
  #
2
2
  # The Modal component renders a modal dialog that can be opened and closed. It
3
- # includes a backdrop, a close icon, a title, and actions.
3
+ # provides a structured way to display content that requires user attention or
4
+ # interaction, such as forms, confirmations, or detailed information.
4
5
  #
5
- # @part dialog The main `<dialog>` container.
6
- # @part box The container for the modal content.
7
- # @part activator The container for the activator which opens the modal.
8
- # @part close_icon_wrapper The container for the close icon.
9
- # @part close_icon The default close icon.
10
- # @part backdrop The backdrop that covers the rest of the screen.
11
- # @part title Container for the default title for the modal.
12
- # @part actions Container for all modal actions.
13
- # @part start_actions Container for the left (start) aligned actions for the modal.
14
- # @part end_actions The end actions for the modal.
6
+ # Note that the modal uses the HTML `<dialog>` element and its native methods
7
+ # (`showModal()` and `close()`). This provides better accessibility and keyboard
8
+ # navigation compared to div-based modals.
15
9
  #
16
- # @slot activator The activator for the modal.
17
- # @slot close_icon A custom close icon for the modal.
18
- # @slot title A custom title for the modal.
19
- # @slot start_actions Left (or start) aligned actions for the modal.
20
- # @slot end_actions Right (or end) aligned actions for the modal.
10
+ # @part dialog The main `<dialog>` container that wraps the modal content.
11
+ # @part box The container for the modal content, providing padding and layout.
12
+ # @part close_icon_wrapper The container for the close icon, positioned in the
13
+ # top-right corner.
14
+ # @part close_icon The default close icon button.
15
+ # @part backdrop The semi-transparent backdrop that covers and dims the main
16
+ # content.
17
+ # @part title Container for the modal title, styled for prominence.
18
+ # @part actions Container for all modal action buttons.
19
+ # @part start_actions Container for left (start) aligned action buttons.
20
+ # @part end_actions Container for right (end) aligned action buttons.
21
21
  #
22
- # @loco_example Basic Usage
22
+ # @slot activator A custom element that opens the modal. Automatically adds
23
+ # `role="button"` and `tabindex="0"` attributes for accessibility.
24
+ # @slot button The button that opens the modal. Defaults to a standard Daisy
25
+ # button with the modal's title.
26
+ # @slot close_icon A custom close button to replace the default 'X' icon.
27
+ # @slot title Custom title content, replacing the default text title.
28
+ # @slot start_actions Left (start) aligned buttons, typically for secondary actions
29
+ # like "Cancel".
30
+ # @slot end_actions Right (end) aligned buttons, typically for primary actions
31
+ # like "Submit" or "Save".
32
+ #
33
+ # @loco_example Basic Modal
23
34
  # = daisy_modal(title: "Simple Modal") do |modal|
35
+ # - modal.with_button(css: "btn-primary") { "Open Modal" }
36
+ # %p This is a basic modal with some content.
37
+ # - modal.with_end_actions do
38
+ # %form{ method: :dialog }
39
+ # = daisy_button { "Close" }
40
+ #
41
+ # @loco_example Form Modal
42
+ # = daisy_modal(title: "Edit Profile") do |modal|
43
+ # - modal.with_button { "Edit Profile" }
44
+ # = form_with(model: @user) do |f|
45
+ # .space-y-4
46
+ # = f.text_field :name, class: "input input-bordered w-full"
47
+ # = f.email_field :email, class: "input input-bordered w-full"
48
+ # - modal.with_start_actions do
49
+ # %form{ method: :dialog }
50
+ # = daisy_button { "Cancel" }
51
+ # - modal.with_end_actions do
52
+ # = daisy_button(css: "btn-primary", type: "submit") { "Save Changes" }
53
+ #
54
+ # @loco_example Custom Activator
55
+ # = daisy_modal(title: "User Details") do |modal|
24
56
  # - modal.with_activator do
25
- # - onclick = "document.getElementById('#{modal.dialog_id}').showModal()"
26
- # = daisy_button(css: 'btn-primary', html: { onclick: onclick }) do
27
- # Open Modal
57
+ # .flex.items-center.gap-2.cursor-pointer
58
+ # = heroicon_tag "user-circle"
59
+ # %span View Details
28
60
  #
29
- # Here is some really long modal content that should go well past the
30
- # spot where the close icon appears...
61
+ # %dl.space-y-2
62
+ # %dt Name
63
+ # %dd John Doe
64
+ # %dt Email
65
+ # %dd john@example.com
31
66
  #
32
- # - modal.with_end_actions(css: "flex flex-row items-center gap-2") do
67
+ # - modal.with_end_actions do
33
68
  # %form{ method: :dialog }
34
- # = daisy_button do
35
- # Cancel
36
- # %form{ action: "", method: :get }
37
- # %input{ type: "hidden", name: "submitted", value: "true" }
38
- # = daisy_button(css: "btn-primary") do
39
- # Submit
69
+ # = daisy_button { "Close" }
40
70
  #
41
71
  class Daisy::Actions::ModalComponent < LocoMotion::BaseComponent
42
72
  set_component_name :modal
43
73
 
44
- define_parts :dialog, :box, :actions,
45
- :activator, :close_icon_wrapper, :close_icon,
74
+ define_parts :dialog, :box, :actions, :close_icon_wrapper, :close_icon,
46
75
  :backdrop, :title, :start_actions, :end_actions
47
76
 
48
- renders_one :activator
77
+ renders_one :activator, LocoMotion::BasicComponent.build(html: { role: "button", tabindex: 0 })
78
+ renders_one :button, Daisy::Actions::ButtonComponent
49
79
  renders_one :close_icon
50
80
  renders_one :title
51
81
  renders_one :start_actions
@@ -63,33 +93,35 @@ class Daisy::Actions::ModalComponent < LocoMotion::BaseComponent
63
93
  attr_reader :simple_title
64
94
 
65
95
  #
66
- # Instantiate a new Modal component. All options are expected to be passed as
67
- # keyword arguments.
96
+ # Creates a new instance of the ModalComponent.
97
+ #
98
+ # @param title [String] The title of the modal. Used in both the modal header
99
+ # and the default trigger button.
68
100
  #
69
- # @param args [Array] Currently unused and passed through to the
70
- # BaseComponent.
71
101
  # @param kws [Hash] The keyword arguments for the component.
72
102
  #
73
- # @option kws dialog_id [String] A specific ID you would like the dialog to
74
- # use. Auto-generates a random ID using `SecureRandom.uuid` if not provided.
75
- # @option kws closable [Boolean] Whether or not the modal should allow
76
- # closing.
77
- # @option kws title [String] A simple title that you would like the
78
- # component to render above the main content of the modal (see
79
- # {simple_title}).
103
+ # @option kws title [String] The title of the modal. You can also pass this as
104
+ # the first argument.
105
+ #
106
+ # @option kws closable [Boolean] If true (default), shows a close icon in the
107
+ # top-right corner.
80
108
  #
81
- def initialize(*args, **kws, &block)
109
+ # @option kws dialog_id [String] A custom ID for the dialog element. If not
110
+ # provided, a unique ID will be generated.
111
+ #
112
+ def initialize(title = nil, **kws, &block)
82
113
  super
83
114
 
84
115
  @dialog_id = config_option(:dialog_id, SecureRandom.uuid)
85
116
  @closable = config_option(:closable, true)
86
- @simple_title = config_option(:title)
117
+ @simple_title = config_option(:title, title)
87
118
  end
88
119
 
89
120
  #
90
121
  # Sets up the component with various CSS classes and HTML attributes.
91
122
  #
92
123
  def before_render
124
+ setup_activator_or_button
93
125
  setup_component
94
126
  setup_backdrop
95
127
  setup_box
@@ -100,6 +132,18 @@ class Daisy::Actions::ModalComponent < LocoMotion::BaseComponent
100
132
 
101
133
  private
102
134
 
135
+ def setup_activator_or_button
136
+ onclick = "document.getElementById('#{dialog_id}').showModal()"
137
+
138
+ element = if activator?
139
+ activator
140
+ else
141
+ button || default_button
142
+ end
143
+
144
+ element.add_html(:component, { onclick: onclick })
145
+ end
146
+
103
147
  def setup_component
104
148
  set_tag_name(:component, :dialog)
105
149
  add_html(:component, id: dialog_id)
@@ -131,4 +175,9 @@ class Daisy::Actions::ModalComponent < LocoMotion::BaseComponent
131
175
  def setup_actions
132
176
  add_css(:actions, "mt-2 flex flex-row items-center justify-between")
133
177
  end
178
+
179
+ # Provide a default button if no button is supplied.
180
+ def default_button
181
+ with_button(simple_title)
182
+ end
134
183
  end
@@ -1,3 +1,67 @@
1
+ #
2
+ # The Swap component allows toggling between two states, "on" and "off", with an
3
+ # optional indeterminate state. It provides a flexible way to create animated
4
+ # toggles, switches, or any other element that needs to alternate between
5
+ # different visual states. The component supports both simple text/emoji swaps
6
+ # and complex HTML content swaps.
7
+ #
8
+ # It also includes built-in animations that can be enabled through CSS classes
9
+ # like `swap-rotate` or `swap-flip`.
10
+ #
11
+ # Includes the {LocoMotion::Concerns::TippableComponent} module to enable easy
12
+ # tooltip addition.
13
+ #
14
+ # @part checkbox The checkbox input element that handles the toggle state.
15
+ # @part on Wraps the HTML content displayed when the swap is in the "on" state.
16
+ # @part off Wraps the HTML content displayed when the swap is in the "off" state.
17
+ # @part indeterminate Wraps the HTML content displayed when the swap is in an
18
+ # indeterminate state. Only shown when the checkbox is in an indeterminate
19
+ # state.
20
+ #
21
+ # @slot on The HTML content to be displayed when the swap is in the "on" state.
22
+ # @slot off The HTML content to be displayed when the swap is in the "off" state.
23
+ # @slot indeterminate The HTML content to be displayed when the swap is in an
24
+ # indeterminate state.
25
+ #
26
+ # @loco_example Basic Text Swap
27
+ # = daisy_swap(checked: true, on: "✅ On", off: "❌ Off", css: "swap-rotate")
28
+ #
29
+ # @loco_example Basic Usage with Args
30
+ # = daisy_swap("✅ On", "❌ Off", true, css: "swap-rotate")
31
+ #
32
+ # @loco_example Icon Swap with Tooltip
33
+ # = daisy_swap(tip: "Toggle Theme") do |swap|
34
+ # - swap.with_on do
35
+ # = heroicon_tag "sun", css: "size-6"
36
+ # - swap.with_off do
37
+ # = heroicon_tag "moon", css: "size-6"
38
+ #
39
+ # @loco_example Complex Content with Animation
40
+ # = daisy_swap(css: "swap-flip") do |swap|
41
+ # - swap.with_on do
42
+ # .bg-primary.text-primary-content.p-4.rounded-lg
43
+ # .font-bold Subscribed
44
+ # %p You're all set!
45
+ # - swap.with_off do
46
+ # .bg-base-200.p-4.rounded-lg
47
+ # .font-bold Subscribe
48
+ # %p Click to join
49
+ #
50
+ # @loco_example With Indeterminate State
51
+ # = daisy_swap(css: "swap-flip", tip: "Task Status") do |swap|
52
+ # - swap.with_on do
53
+ # .text-success
54
+ # = heroicon_tag "check-circle"
55
+ # %span Complete
56
+ # - swap.with_off do
57
+ # .text-error
58
+ # = heroicon_tag "x-circle"
59
+ # %span Failed
60
+ # - swap.with_indeterminate do
61
+ # .text-warning
62
+ # = heroicon_tag "clock"
63
+ # %span Processing
64
+ #
1
65
  class Daisy::Actions::SwapComponent < LocoMotion::BaseComponent
2
66
  prepend LocoMotion::Concerns::TippableComponent
3
67
 
@@ -25,32 +89,77 @@ class Daisy::Actions::SwapComponent < LocoMotion::BaseComponent
25
89
  renders_one :off, SwapOff
26
90
  renders_one :indeterminate, SwapIndeterminate
27
91
 
28
- attr_reader :simple_on, :simple_off
92
+ # @return [String] The value of the `on` option. Usually text or emoji.
93
+ attr_reader :simple_on
29
94
 
30
- def initialize(*args, **kwargs, &block)
95
+ # @return [String] The value of the `off` option. Usually text or emoji.
96
+ attr_reader :simple_off
97
+
98
+ #
99
+ # Creates a new instance of the SwapComponent.
100
+ #
101
+ # @param on [String] Simple text/emoji to display in the "on" state. If provided
102
+ # along with `off`, enables simple text swap mode.
103
+ #
104
+ # @param off [String] Simple text/emoji to display in the "off" state. If provided
105
+ # along with `on`, enables simple text swap mode.
106
+ #
107
+ # @param checked [Boolean] Whether the swap should start in the checked ("on")
108
+ # state. Defaults to false.
109
+ #
110
+ # @param kws [Hash] The keyword arguments for the component.
111
+ #
112
+ # @option kws on [String] Simple text/emoji for the "on" state. Alternative to
113
+ # providing it as the first argument.
114
+ #
115
+ # @option kws off [String] Simple text/emoji for the "off" state. Alternative to
116
+ # providing it as the second argument.
117
+ #
118
+ # @option kws checked [Boolean] Whether the swap should start checked. Alternative
119
+ # to providing it as the third argument.
120
+ #
121
+ # @option kws indeterminate [Boolean] If true, starts the swap in an indeterminate
122
+ # state. Requires the indeterminate slot to be meaningful.
123
+ #
124
+ def initialize(on = nil, off = nil, checked = nil, **kws, &block)
31
125
  super
32
126
 
33
- @checked = config_option(:checked, false)
34
- @simple_on = config_option(:on)
35
- @simple_off = config_option(:off)
127
+ @checked = config_option(:checked, checked || false)
128
+ @simple_on = config_option(:on, on)
129
+ @simple_off = config_option(:off, off)
36
130
  end
37
131
 
132
+ #
133
+ # Sets up the component with various CSS classes and HTML attributes.
134
+ #
38
135
  def before_render
39
136
  setup_component
40
137
  setup_checkbox
41
138
  setup_on_off
42
139
  end
43
140
 
141
+ private
142
+
143
+ #
144
+ # Sets up the main component structure. The component is rendered as a label
145
+ # element to allow clicking anywhere on it to toggle the checkbox.
146
+ #
44
147
  def setup_component
45
148
  set_tag_name(:component, :label)
46
149
  add_css(:component, "swap")
47
150
  end
48
151
 
152
+ #
153
+ # Sets up the checkbox input element that handles the toggle state.
154
+ #
49
155
  def setup_checkbox
50
156
  set_tag_name(:checkbox, :input)
51
157
  add_html(:checkbox, { type: "checkbox", checked: @checked })
52
158
  end
53
159
 
160
+ #
161
+ # Sets up the CSS classes for the "on" and "off" states.
162
+ #
54
163
  def setup_on_off
55
164
  add_css(:on, "swap-on")
56
165
  add_css(:off, "swap-off")
@@ -1,5 +1,5 @@
1
1
  = part(:component) do
2
- - SOME_THEMES.map do |theme|
2
+ - @themes.map do |theme|
3
3
  %label.label.cursor-pointer.gap-4
4
4
  %span.label-text= theme.titleize
5
5
  %input.radio.theme-controller{ name: "theme", type: "radio", value: theme, checked: theme == "light"}
@@ -1,7 +1,42 @@
1
- # Renders a very basic radio-button theme controller.
1
+ #
2
+ # The Theme Controller component provides a simple interface for switching
3
+ # between different DaisyUI themes. It renders a set of radio buttons that
4
+ # allow users to select from a predefined list of themes.
5
+ #
6
+ # The component is designed to work with DaisyUI's theme system and
7
+ # automatically updates the `data-theme` attribute on the HTML element when
8
+ # a theme is selected.
9
+ #
10
+ # @loco_example Basic Usage
11
+ # = daisy_theme_controller
12
+ #
13
+ # @loco_example Custom Theme List
14
+ # = daisy_theme_controller(themes: ["light", "dark", "cyberpunk"])
15
+ #
16
+ # @loco_example With Custom Styling
17
+ # = daisy_theme_controller(css: "gap-6 p-4 bg-base-200 rounded-lg")
18
+ #
2
19
  class Daisy::Actions::ThemeControllerComponent < LocoMotion::BaseComponent
20
+ # Default list of themes to display in the controller
3
21
  SOME_THEMES = ["light", "dark", "synthwave", "retro", "cyberpunk", "wireframe"].freeze
4
22
 
23
+ #
24
+ # Creates a new instance of the ThemeControllerComponent.
25
+ #
26
+ # @param kws [Hash] The keyword arguments for the component.
27
+ #
28
+ # @option kws themes [Array<String>] List of DaisyUI theme names to include
29
+ # in the controller. Defaults to {SOME_THEMES}.
30
+ #
31
+ def initialize(**kws, &block)
32
+ super
33
+
34
+ @themes = config_option(:themes, SOME_THEMES)
35
+ end
36
+
37
+ #
38
+ # Sets up the component's CSS classes for proper layout and spacing.
39
+ #
5
40
  def before_render
6
41
  add_css(:component, "flex flex-col lg:flex-row gap-4 items-center")
7
42
  end
@@ -1,8 +1,55 @@
1
- # The Accordion component shows sections that can be expanded or collapsed.
1
+ #
2
+ # The Accordion component shows collapsible sections of content, with only one
3
+ # section open at a time. Each section has a title that can be clicked to show
4
+ # or hide its content.
5
+ #
6
+ # Includes the {LocoMotion::Concerns::TippableComponent} module to enable easy
7
+ # tooltip addition.
8
+ #
9
+ # @slot section+ Multiple sections that can be expanded or collapsed. Each
10
+ # section can have a title and content.
11
+ #
12
+ # @loco_example Basic Usage
13
+ # = daisy_accordion do |accordion|
14
+ # - accordion.with_section(title: "Section 1") do
15
+ # This is the content of section 1
16
+ # - accordion.with_section(title: "Section 2") do
17
+ # This is the content of section 2
18
+ #
19
+ # @loco_example With Arrow Icons
20
+ # = daisy_accordion(:arrow) do |accordion|
21
+ # - accordion.with_section(title: "Section 1") do
22
+ # This is the content of section 1
23
+ # - accordion.with_section(title: "Section 2") do
24
+ # This is the content of section 2
25
+ #
26
+ # @loco_example With Plus Icons
27
+ # = daisy_accordion(:plus) do |accordion|
28
+ # - accordion.with_section(title: "Section 1") do
29
+ # This is the content of section 1
30
+ # - accordion.with_section(title: "Section 2") do
31
+ # This is the content of section 2
32
+ #
33
+ # @loco_example With Custom Title Content
34
+ # = daisy_accordion do |accordion|
35
+ # - accordion.with_section do |section|
36
+ # - section.with_title do
37
+ # .flex.items-center.gap-2
38
+ # = heroicon_tag "star"
39
+ # Featured Section
40
+ # This is the content of the featured section
41
+ #
2
42
  class Daisy::DataDisplay::AccordionComponent < LocoMotion::BaseComponent
3
43
  prepend LocoMotion::Concerns::TippableComponent
4
44
 
5
45
  # Renders a single section of the accordion.
46
+ #
47
+ # @part radio_button The radio input that controls the section's state.
48
+ # @part title The title bar that can be clicked to expand/collapse the section.
49
+ # @part content The container for the section's content.
50
+ #
51
+ # @slot title Custom content for the section's title bar.
52
+ #
6
53
  class AccordionSectionComponent < LocoMotion::BasicComponent
7
54
  define_parts :radio_button, :title, :content
8
55
 
@@ -12,7 +59,23 @@ class Daisy::DataDisplay::AccordionComponent < LocoMotion::BaseComponent
12
59
  # config.
13
60
  attr_reader :simple_title
14
61
 
15
- def initialize(*args, **kws, &block)
62
+ # Creates a new accordion section.
63
+ #
64
+ # @param kws [Hash] The keyword arguments for the component.
65
+ #
66
+ # @option kws title [String] The text to display in the section's title bar.
67
+ # You can also provide a custom title content using the title slot.
68
+ #
69
+ # @option kws value [String] The value for the radio button that controls
70
+ # this section. Defaults to a random string.
71
+ #
72
+ # @option kws checked [Boolean] Whether this section should start expanded.
73
+ # Defaults to false.
74
+ #
75
+ # @option kws name [String] The name attribute for the radio button group.
76
+ # Usually provided by the parent accordion.
77
+ #
78
+ def initialize(**kws, &block)
16
79
  super
17
80
 
18
81
  @value = config_option(:value)
@@ -73,9 +136,22 @@ class Daisy::DataDisplay::AccordionComponent < LocoMotion::BaseComponent
73
136
 
74
137
  renders_many :sections, AccordionSectionComponent
75
138
 
139
+ # @return [String] The name attribute for all radio buttons in this accordion.
76
140
  attr_reader :name
77
141
 
78
- def initialize(*args, **kws, &block)
142
+ #
143
+ # Creates a new accordion component.
144
+ #
145
+ # @param kws [Hash] The keyword arguments for the component.
146
+ #
147
+ # @option kws name [String] The name attribute for all radio buttons in this
148
+ # accordion. Defaults to a random string.
149
+ #
150
+ # @option kws modifier [Symbol] Optional modifier for the accordion's appearance.
151
+ # Use `:arrow` to show arrow indicators, or `:plus` to show plus/minus
152
+ # indicators.
153
+ #
154
+ def initialize(**kws, &block)
79
155
  super
80
156
 
81
157
  @name = config_option(:name, "accordion-#{SecureRandom.uuid}")
@@ -1,27 +1,37 @@
1
- # The Avatar Component displays in image, icon, or placeholder text to represent
2
- # a user.
1
+ # The Avatar component displays an image, icon, or placeholder text to represent
2
+ # a user or entity. It provides a consistent, circular display with fallback
3
+ # options when an image is not available.
4
+ #
5
+ # Includes the {LocoMotion::Concerns::TippableComponent} module to enable easy
6
+ # tooltip addition.
3
7
  #
4
8
  # It utilizes the CSS `where()` pseudo-class to reduce the specificity to 0 to
5
9
  # allow for easy overriding while giving you some sane defaults.
6
10
  #
7
- # - Width: <code>w-24</code> (can override with w-10, h-10, etc.)
8
- # - Corners: `rounded-full`
11
+ # @part wrapper The outer container that maintains the avatar's shape and size.
12
+ # @part img The image element when an image source is provided.
13
+ # @part icon The icon element when an icon is specified.
14
+ # @part placeholder The container for placeholder content when no image or icon
15
+ # is provided.
16
+ #
17
+ # @loco_example Basic Usage with Image
18
+ # = daisy_avatar(src: "https://example.com/avatar.jpg")
9
19
  #
10
- # If no image is provided, these additional classes will be added so that any
11
- # text or icons are visible.
20
+ # @loco_example With Icon
21
+ # = daisy_avatar(icon: "user")
12
22
  #
13
- # - Background: +bg-neutral+
14
- # - Text Color: `text-neutral-content`
23
+ # @loco_example With Custom Icon Styling
24
+ # = daisy_avatar(icon: "user", icon_css: "text-yellow-400")
15
25
  #
16
- # ## Examples
26
+ # @loco_example With Placeholder Text
27
+ # = daisy_avatar do
28
+ # JD
17
29
  #
18
- # ```language-haml
19
- # - # Display an avatar with an image
20
- # = daisy_avatar src: "https://example.com/avatar.jpg"
30
+ # @loco_example With Custom Size
31
+ # = daisy_avatar(src: "avatar.jpg", css: "w-16 h-16")
21
32
  #
22
- # - # Display an avatar with an icon
23
- # = daisy_avatar icon: "user", icon_css: "text-yellow-400"
24
- # ```
33
+ # @loco_example With Tooltip
34
+ # = daisy_avatar(src: "avatar.jpg", tip: "John Doe")
25
35
  #
26
36
  class Daisy::DataDisplay::AvatarComponent < LocoMotion::BaseComponent
27
37
  prepend LocoMotion::Concerns::TippableComponent
@@ -31,7 +41,17 @@ class Daisy::DataDisplay::AvatarComponent < LocoMotion::BaseComponent
31
41
  define_parts :wrapper, :img, :icon, :placeholder
32
42
 
33
43
  # Create a new avatar component.
34
- def initialize(*args, **kws, &block)
44
+ #
45
+ # @param kws [Hash] The keyword arguments for the component.
46
+ #
47
+ # @option kws src [String] URL to the avatar image. If not provided, the
48
+ # component will display an icon or placeholder content.
49
+ #
50
+ # @option kws icon [String] Name of the Heroicon to display when no image is
51
+ # provided. If neither src nor icon is provided, placeholder content from
52
+ # the block will be shown.
53
+ #
54
+ def initialize(**kws, &block)
35
55
  super
36
56
 
37
57
  @src = config_option(:src)
@@ -1,6 +1,28 @@
1
1
  #
2
- # The Badge component renders as a small, rounded element with various
3
- # background colors.
2
+ # The Badge component renders as a small, rounded element used to display status,
3
+ # labels, or notifications. It supports various background colors and can be used
4
+ # inline with text.
5
+ #
6
+ # Includes the {LocoMotion::Concerns::TippableComponent} module to enable easy
7
+ # tooltip addition.
8
+ #
9
+ # @loco_example Basic Usage
10
+ # = daisy_badge("New!")
11
+ #
12
+ # @loco_example With Different Colors
13
+ # = daisy_badge("Primary", css: "badge-primary")
14
+ # = daisy_badge("Secondary", css: "badge-secondary")
15
+ # = daisy_badge("Accent", css: "badge-accent")
16
+ # = daisy_badge("Ghost", css: "badge-ghost")
17
+ #
18
+ # @loco_example With Tooltip
19
+ # = daisy_badge("Beta", tip: "This feature is in beta testing")
20
+ #
21
+ # @loco_example Using a Block
22
+ # = daisy_badge do
23
+ # %span.flex.items-center.gap-1
24
+ # = heroicon_tag "star", css: "size-4"
25
+ # Featured
4
26
  #
5
27
  # @!parse class Daisy::DataDisplay::BadgeComponent < LocoMotion::BaseComponent; end
6
28
  class Daisy::DataDisplay::BadgeComponent < LocoMotion::BaseComponent
@@ -11,10 +33,18 @@ class Daisy::DataDisplay::BadgeComponent < LocoMotion::BaseComponent
11
33
  #
12
34
  # Create a new Badge component.
13
35
  #
14
- def initialize(*args, **kws, &block)
36
+ # @param title [String] The text to display in the badge. You can also pass
37
+ # the title as a keyword argument or provide content via a block.
38
+ #
39
+ # @param kwargs [Hash] The keyword arguments for the component.
40
+ #
41
+ # @option kwargs title [String] The text to display in the badge. You can also
42
+ # pass the title as the first argument or provide content via a block.
43
+ #
44
+ def initialize(title = nil, **kws, &block)
15
45
  super
16
46
 
17
- @title = config_option(:title, args[0])
47
+ @title = config_option(:title, title)
18
48
  end
19
49
 
20
50
  def before_render
@@ -29,7 +59,7 @@ class Daisy::DataDisplay::BadgeComponent < LocoMotion::BaseComponent
29
59
  # additional whitespace gets added to the output.
30
60
  #
31
61
  def call
32
- part(:component) { @title || content }
62
+ part(:component) { content || @title }
33
63
  end
34
64
 
35
65
  private
@@ -1,17 +1,9 @@
1
1
  = part(:component) do
2
- - if top_figure?
3
- = top_figure
4
-
5
- = part(:body) do
6
- - if title?
7
- = title
8
- - elsif @simple_title
9
- %h2.card-title= @simple_title
2
+ = top_figure if top_figure?
10
3
 
4
+ .card-body
5
+ = title if title?
11
6
  = content
7
+ = actions if actions?
12
8
 
13
- - if actions?
14
- = actions
15
-
16
- - if bottom_figure?
17
- = bottom_figure
9
+ = bottom_figure if bottom_figure?