loco_motion-rails 0.0.7 → 0.0.8

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 (58) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +45 -1
  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/feedback/alert_component.rb +46 -1
  28. data/app/components/daisy/feedback/loading_component.rb +39 -0
  29. data/app/components/daisy/feedback/progress_component.rb +39 -1
  30. data/app/components/daisy/feedback/radial_progress_component.rb +44 -1
  31. data/app/components/daisy/feedback/skeleton_component.rb +44 -0
  32. data/app/components/daisy/feedback/toast_component.rb +36 -0
  33. data/app/components/daisy/feedback/tooltip_component.rb +46 -10
  34. data/app/components/daisy/layout/artboard_component.rb +48 -0
  35. data/app/components/daisy/layout/divider_component.rb +50 -10
  36. data/app/components/daisy/layout/drawer_component.rb +62 -17
  37. data/app/components/daisy/layout/footer_component.rb +51 -11
  38. data/app/components/daisy/layout/hero_component.rb +67 -5
  39. data/app/components/daisy/layout/indicator_component.rb +55 -8
  40. data/app/components/daisy/layout/join_component.rb +71 -0
  41. data/app/components/daisy/layout/stack_component.rb +59 -0
  42. data/app/components/daisy/mockup/browser_component.rb +78 -0
  43. data/app/components/daisy/mockup/code_component.rb +144 -0
  44. data/app/components/daisy/mockup/device_component.rb +81 -0
  45. data/app/components/daisy/mockup/frame_component.rb +62 -0
  46. data/app/components/daisy/navigation/bottom_nav_component.rb +81 -2
  47. data/app/components/daisy/navigation/breadcrumbs_component.rb +40 -3
  48. data/app/components/daisy/navigation/link_component.rb +31 -6
  49. data/app/components/daisy/navigation/menu_component.rb +52 -20
  50. data/app/components/daisy/navigation/navbar_component.html.haml +1 -1
  51. data/app/components/daisy/navigation/navbar_component.rb +63 -2
  52. data/app/components/daisy/navigation/steps_component.rb +76 -0
  53. data/app/components/daisy/navigation/tabs_component.rb +110 -7
  54. data/app/components/hero/icon_component.rb +40 -0
  55. data/lib/daisy.rb +5 -0
  56. data/lib/loco_motion/helpers.rb +7 -0
  57. data/lib/loco_motion/version.rb +5 -0
  58. metadata +25 -5
@@ -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?
@@ -1,54 +1,89 @@
1
+ #
2
+ # The Card component is a flexible container for displaying content with a
3
+ # consistent style. It can include images, titles, text, and actions.
4
+ #
5
+ # Includes the {LocoMotion::Concerns::TippableComponent} module to enable easy
6
+ # tooltip addition.
7
+ #
8
+ # @part body The main content area of the card.
9
+ # @part title The title text container when using the simple title option.
10
+ #
11
+ # @slot title A custom title section, typically rendered as an `h2` element.
12
+ # @slot top_figure {Daisy::DataDisplay::FigureComponent} An optional figure
13
+ # (usually an image) to display at the top of the card.
14
+ # @slot bottom_figure {Daisy::DataDisplay::FigureComponent} An optional figure
15
+ # (usually an image) to display at the bottom of the card.
16
+ # @slot actions A container for action buttons or links, typically displayed at
17
+ # the bottom of the card.
18
+ #
19
+ # @loco_example Basic Usage
20
+ # = daisy_card(title: "Simple Card") do
21
+ # This is a basic card with just a title and some content.
22
+ #
23
+ # @loco_example With Top Image
24
+ # = daisy_card do |card|
25
+ # - card.with_top_figure(src: "example.jpg")
26
+ # - card.with_title { "Card with Image" }
27
+ # A card with an image at the top and a custom title.
28
+ #
29
+ # @loco_example With Actions
30
+ # = daisy_card do |card|
31
+ # - card.with_title { "Interactive Card" }
32
+ # This card has buttons for user interaction.
33
+ # - card.with_actions do
34
+ # = daisy_button("Learn More")
35
+ # = daisy_button("Share")
36
+ #
37
+ # @loco_example Complex Layout
38
+ # = daisy_card do |card|
39
+ # - card.with_top_figure(src: "header.jpg")
40
+ # - card.with_title do
41
+ # .flex.items-center.gap-2
42
+ # = heroicon_tag "star"
43
+ # Featured Article
44
+ # %p{ class: "text-base-content/70" } A beautifully designed card with rich content.
45
+ # - card.with_bottom_figure(src: "footer.jpg")
46
+ # - card.with_actions do
47
+ # .flex.justify-between.w-full
48
+ # = daisy_button("Read More")
49
+ # .flex.gap-2
50
+ # = daisy_button(icon: "heart", tip: "Like")
51
+ # = daisy_button(icon: "share", tip: "Share")
52
+ #
1
53
  class Daisy::DataDisplay::CardComponent < LocoMotion::BaseComponent
2
54
  prepend LocoMotion::Concerns::TippableComponent
3
55
 
4
- Figure = LocoMotion::BasicComponent.build do
5
- define_part :image, tag_name: :img, css: "card-image"
6
-
7
- def initialize(*args, **kws, &block)
8
- super
9
-
10
- @src = kws[:src]
11
- end
12
-
13
- def before_render
14
- set_tag_name(:component, :figure)
15
- add_html(:image, src: @src) if @src
16
- end
17
-
18
- def call
19
- part(:component) do
20
- if @src
21
- part(:image)
22
- else
23
- content
24
- end
25
- end
26
- end
27
- end
28
-
29
- define_parts :body, :title
30
-
31
56
  renders_one :title, LocoMotion::BasicComponent.build(tag_name: :h2, css: "card-title")
32
- renders_one :top_figure, Figure
33
- renders_one :bottom_figure, Figure
57
+ renders_one :top_figure, Daisy::DataDisplay::FigureComponent.build(css: "card-image")
58
+ renders_one :bottom_figure, Daisy::DataDisplay::FigureComponent.build(css: "card-image")
34
59
  renders_one :actions, LocoMotion::BasicComponent.build(css: "card-actions")
35
60
 
36
- def initialize(*args, **kws, &block)
61
+ # @return [String] The title text when using the simple title option.
62
+ attr_reader :simple_title
63
+
64
+ # Creates a new card component.
65
+ #
66
+ # @param kws [Hash] The keyword arguments for the component.
67
+ #
68
+ # @option kws title [String] Optional simple title text. For more complex
69
+ # titles, use the `with_title` method instead.
70
+ #
71
+ # @option kws css [String] Additional CSS classes for styling. Common
72
+ # options include:
73
+ # - Image Side: `image-full` (image becomes background)
74
+ # - Borders: `bordered`
75
+ # - Compact: `compact` (less padding)
76
+ # - Colors: `bg-base-100`, `bg-primary`, `bg-secondary`
77
+ #
78
+ def initialize(**kws, &block)
37
79
  super
38
80
 
39
81
  @simple_title = kws[:title]
40
- end
41
-
42
- def before_render
43
- setup_component
44
- setup_body
45
- end
46
82
 
47
- def setup_component
48
83
  add_css(:component, "card")
49
84
  end
50
85
 
51
- def setup_body
52
- add_css(:body, "card-body")
86
+ def before_render
87
+ with_title { simple_title } if simple_title && !title?
53
88
  end
54
89
  end
@@ -1,4 +1,42 @@
1
+ #
2
+ # The Carousel component displays a horizontal scrolling list of items, such as
3
+ # images, cards, or any other content. It's useful for showcasing multiple
4
+ # items in a space-efficient manner.
5
+ #
6
+ # @slot item+ Multiple items to display in the carousel. Each item will be
7
+ # displayed side by side and can be scrolled horizontally.
8
+ #
9
+ # @loco_example Basic Usage with Images
10
+ # = daisy_carousel do |carousel|
11
+ # - carousel.with_item do
12
+ # %img{ src: "image1.jpg", class: "w-full" }
13
+ # - carousel.with_item do
14
+ # %img{ src: "image2.jpg", class: "w-full" }
15
+ # - carousel.with_item do
16
+ # %img{ src: "image3.jpg", class: "w-full" }
17
+ #
18
+ # @loco_example With Cards
19
+ # = daisy_carousel do |carousel|
20
+ # - carousel.with_item do
21
+ # = daisy_card(title: "Card 1") do
22
+ # First card content
23
+ # - carousel.with_item do
24
+ # = daisy_card(title: "Card 2") do
25
+ # Second card content
26
+ #
27
+ # @loco_example With Custom Styling
28
+ # = daisy_carousel(css: "h-96 rounded-box") do |carousel|
29
+ # - carousel.with_item(css: "w-1/2") do
30
+ # .bg-primary.text-primary-content.p-4.h-full
31
+ # %h2.text-2xl First Slide
32
+ # %p Some content for the first slide
33
+ # - carousel.with_item(css: "w-1/2") do
34
+ # .bg-secondary.text-secondary-content.p-4.h-full
35
+ # %h2.text-2xl Second Slide
36
+ # %p Some content for the second slide
37
+ #
1
38
  class Daisy::DataDisplay::CarouselComponent < LocoMotion::BaseComponent
39
+ # A component for rendering individual items within the carousel.
2
40
  class ItemComponent < LocoMotion::BasicComponent
3
41
  def before_render
4
42
  add_css(:component, "carousel-item")