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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a020015ecb6d9ee0a705d25830f1951b00c60be6ee4046939b878d3a720bfbda
4
- data.tar.gz: c9bc31844a168d4427423912be65f354387aba43f2c6d6711998cee947e2311d
3
+ metadata.gz: 767e282b6b6bdd3838a976a9ee4b75e2b89d0e42282955076b00ffa9de3c092b
4
+ data.tar.gz: d87d11791dee9d2b92d1273d39f7eebbeffd9ff20b947ba208ae48692497d45d
5
5
  SHA512:
6
- metadata.gz: f88796625ae5f6f7c7690563d0a687ed2d8932924d305cb12da0985fdcfdb00f629e6a25618afe5498ec6932af0e8c45b1cc3008a9f68d28940563f9f41f1fb0
7
- data.tar.gz: 5f09dacd5dab790708428cb3e853e40fa59a5d20da58b4d11f9e99cca76bf940b1d3d311e55e8396b140acb2271eddb3df202175164ba59306acc041427d65cd
6
+ metadata.gz: 949e31fa02cbf137771872b6c35c3abfc1ccbaebe065ae74076693a2b19861bd274bb00c55688c7d688dd4e92f01ae72886e9945a7b95d1f634bde95d4b67f87
7
+ data.tar.gz: 2072ec0b0557723d23df2d1b41af5aaa48e786f81a95715e29833aa9b33cb3b78e90a4625568756f33ec5cfcbb3624e681518aa66a329f6c38003f91791741fb
data/README.md CHANGED
@@ -6,19 +6,45 @@ ViewComponent, TailwindCSS, DaisyUI and more!
6
6
 
7
7
  <img src="//loco-motion-docs.profoundry.us/images/loco-chats.png" width="500px" style="border: 1px solid #bbb; padding: 2px; border-radius: 10px;">
8
8
 
9
- _**DISCLAIMER**_
9
+ <!-- omit from toc -->
10
+ ## DISCLAIMER / CURRENT STATUS
10
11
 
11
12
  This project is in active development and many changes occur with every release!
12
- In particular, new Daisy components are being added frequently and older
13
- components are being updated with new features meaning the APIs are very likely
14
- to change!
13
+
14
+ We've added a very basic / untested version of all DaisyUI 4 components. While
15
+ we originally intended to take some time to flesh out and attempt to use these
16
+ components, with the recent release of Tailwind 4 and DaisyUI 5, we feel our
17
+ time is best spent updating all of the components and dependencies for these
18
+ new releases.
19
+
20
+ This means that we will **NOT** be making any bug fixes to the current branch
21
+ (0.4.0), and will instead include any bug fixes / improvements into the 0.5.0
22
+ branch which will also upgrade to Tailwind 4 and DaisyUI 5.
23
+
24
+ - Current Release **(0.4.0)** - Works with DaisyUI 4 and Tailwind 3
25
+ - Next Release **(0.5.0)** - Will work with DaisyUI 5 and Tailwind 4
26
+
27
+ <!-- omit from toc -->
28
+ ## Additional Notes
29
+
30
+ ### DataInput Components
31
+
32
+ Many of the DataInput elements (file input, text input, select dropdown, etc)
33
+ were built rather hastily so that we would have a base version to start from.
34
+
35
+ However, the new DaisyUI 5 components are implemented in a much cleaner way and
36
+ we didn't want to invest too much time building these out and making them more
37
+ ideal since we're about to change them.
38
+
39
+ ### Hosting / Sites
15
40
 
16
41
  We expect to settle on and purchase a real domain name in the near future, but
17
42
  for the time being, the latest documentation is available at the links below.
18
43
 
19
- - [Docs / Demo (Latest Release)][1]
20
- - [API Docs (Latest Release)][2]
21
- - [Docs / Demo (Main Branch / Staging)][3]
44
+ - [Latest Release][1]
45
+ - [Main / Staging][3]
46
+
47
+ ### Getting Help
22
48
 
23
49
  Please reach out by opening an
24
50
  [Issue](https://github.com/profoundry-us/loco_motion/issues) if you've found a
@@ -33,11 +59,13 @@ your solution is aligned with our goals.
33
59
  - [About](#about)
34
60
  - [Getting Started](#getting-started)
35
61
  - [Installing / Setting up Rails](#installing--setting-up-rails)
62
+ - [Using UUIDs by Default](#using-uuids-by-default)
36
63
  - [Install HAML (Optional)](#install-haml-optional)
37
64
  - [Install DaisyUI (Optional)](#install-daisyui-optional)
38
65
  - [Try Out Your Application](#try-out-your-application)
39
66
  - [Debugging](#debugging)
40
67
  - [Testing](#testing)
68
+ - [Services / Service Objects](#services--service-objects)
41
69
  - [Authentication](#authentication)
42
70
  - [Web Console](#web-console)
43
71
  - [BetterErrors (Optional)](#bettererrors-optional)
@@ -45,6 +73,8 @@ your solution is aligned with our goals.
45
73
  - [Install](#install)
46
74
  - [Using Components](#using-components)
47
75
  - [Developing](#developing)
76
+ - [Contributing](#contributing)
77
+ - [Releasing](#releasing)
48
78
  - [Tooling](#tooling)
49
79
  - [TODO / Next Steps](#todo--next-steps)
50
80
 
@@ -203,6 +233,20 @@ Congratulations!
203
233
  You can now visit [http://localhost:3000](http://localhost:3000) in your web
204
234
  browser and see your running Rails application!
205
235
 
236
+ ### Using UUIDs by Default
237
+
238
+ We believe strongly in migrating all of your primary keys to UUIDs to increase
239
+ security as well as avoiding potential scaling issues in the future.
240
+
241
+ To enable this by default, create the following file:
242
+
243
+ ```ruby
244
+ # config/initializers/generators.rb
245
+ Rails.application.config.generators do |generator|
246
+ generator.orm :active_record, primary_key_type: :uuid
247
+ end
248
+ ```
249
+
206
250
  ### Install HAML (Optional)
207
251
 
208
252
  While you can use the default ERB templating system that comes with Rails, we
@@ -479,6 +523,28 @@ We'll have some guides and examples for this coming soon!
479
523
  > We plan to have a writeup soon (an ADR specifically) on exactly why we made
480
524
  > the switch.
481
525
 
526
+ ## Services / Service Objects
527
+
528
+ It is best practice to separate your logic into Service Objects rather than
529
+ shoving all of it into your Controllers and Models.
530
+
531
+ One solution we really like is
532
+ [ActiveInteraction](https://github.com/AaronLasseigne/active_interaction).
533
+
534
+ It is very stable, has wonderful documentation, and gives you a clean way to
535
+ build your service objects with support for things like composed interactions
536
+ and even ActiveModel validations.
537
+
538
+ Add `gem 'active_interaction', '~> 5.3'` to your `Gemfile` and create a new
539
+ class called `ApplicationInteraction` if you want to give it a try!
540
+
541
+ ```
542
+ # app/interactions/application_interaction.rb
543
+ class ApplicationInteraction < ActiveInteraction::Base
544
+ # Your interactions will inherit from this class!
545
+ end
546
+ ```
547
+
482
548
  ## Authentication
483
549
 
484
550
  There are a **lot** of different ways to handle user authentication in Ruby on
@@ -818,6 +884,20 @@ See the `Makefile` for all available commands.
818
884
  > make demo-restart
819
885
  > ```
820
886
 
887
+ ### Contributing
888
+
889
+ If you're interested in contributing to LocoMotion, please check out our
890
+ [CONTRIBUTING guide](docs/dev_guides/CONTRIBUTING.md) which provides detailed
891
+ information about the contribution process, code standards, documentation
892
+ requirements, and testing procedures.
893
+
894
+ ### Releasing
895
+
896
+ For core team members who need to release new versions of LocoMotion, please
897
+ refer to our [RELEASING guide](docs/dev_guides/RELEASING.md) for step-by-step
898
+ instructions on version updates, building, testing, and publishing both the Ruby
899
+ gem and NPM package.
900
+
821
901
  ### Tooling
822
902
 
823
903
  For VSCode, you may want to add the following to your settings to get
@@ -881,10 +961,10 @@ the GitHub Discussions feature and let us know!
881
961
  - [x] Basic versions of DaisyUI Data Display
882
962
  - [x] Basic versions of DaisyUI Navigation
883
963
  - [x] Basic versions of DaisyUI Feedback
884
- - [ ] Basic versions of DaisyUI Data Input
885
- - [ ] Basic versions of DaisyUI Layout
886
- - [ ] Basic versions of DaisyUI Mockup
887
- - [ ] ~~Get YARD docs rendering with (better) Markdown~~ _**Working for now**_
964
+ - [x] Basic versions of DaisyUI Data Input
965
+ - [x] Basic versions of DaisyUI Layout
966
+ - [x] Basic versions of DaisyUI Mockup
967
+ - [x] ~~Get YARD docs rendering with (better) Markdown~~ _**Working for now**_
888
968
  - [x] Extract relevant pieces into a yard-loco_motion plugin
889
969
  - [x] Publish Gem
890
970
  - [x] Publish NPM package
@@ -894,14 +974,21 @@ the GitHub Discussions feature and let us know!
894
974
  - [ ] Choose, recommend, and document a pagination gem
895
975
  - [ ] Discuss caching techniques / setup
896
976
  - [x] Create / publish a staging version of the demo site ([Demo Staging][2])
897
- - [ ] Create / publish a staging version of the docs site
898
- - [ ] Create / publish a production version of the demo site
899
- - [ ] Create / publish a production version of the docs site
977
+ - [x] Create / publish a staging version of the docs site
978
+ - [x] Create / publish a production version of the demo site
979
+ - [x] Create / publish a production version of the docs site
900
980
  - [x] Update demo site to allow for a different docs site using ENV var
901
981
  - [x] Update README to suggest Playwright
902
982
  - [ ] Build some have docs / guides / examples for using playwright-ruby-client
903
983
  - [x] See if we can build a `Tippable` concern that relevant components can
904
984
  include to automatically add the tooltip param and classes where possible
985
+ - [x] Rename `tail` methods to `end` since we use that in other places
986
+ - [x] Update CardComponent Figure to be a proper class like other components
987
+ - [x] Create a GitHub pull request template to standardize PR submissions
988
+ - [ ] See if we can update the Join component to auto-add the `join-item` CSS
989
+ under certain conditions
990
+ - [ ] Add title and description content_for blocks to all examples for SEO purposes
991
+ - [ ] Update to Tailwind 4 and DaisyUI 5
905
992
 
906
993
  [1]: https://loco-motion.profoundry.us/
907
994
  [2]: https://loco-motion-demo-staging.profoundry.us/
@@ -1,12 +1,97 @@
1
- # Here are the Button docs!
1
+ #
2
+ # The Button component can be used to render HTML `<button>` or `<a>` elements
3
+ # that are styled to look like a clickable element.
4
+ #
5
+ # Note that we do **not** use component parts for the icons since we're calling
6
+ # `heroicon_tag` within the component. But we **do** provide custom CSS & HTML
7
+ # options to allow overriding / customization.
8
+ #
9
+ # Includes the {LocoMotion::Concerns::TippableComponent} module to enable easy
10
+ # tooltip addition.
11
+ #
12
+ # @loco_example Basic Usage
13
+ # = daisy_button("Click Me")
14
+ #
15
+ # = daisy_button do
16
+ # Click Me Too
17
+ #
18
+ # = daisy_button(icon: "heart", tip: "Love")
19
+ #
20
+ # = daisy_button(title: "Button with Two Icons", left_icon: "heart", right_icon: "plus")
21
+ #
2
22
  class Daisy::Actions::ButtonComponent < LocoMotion::BaseComponent
3
23
  prepend LocoMotion::Concerns::TippableComponent
4
24
 
5
- set_component_name :btn
6
-
7
- def initialize(*args, **kws, &block)
25
+ #
26
+ # Instantiate a new Button component.
27
+ #
28
+ # @param title [String] The title of the button. Defaults to "Submit" if none
29
+ # of title, left icon, or right icon is provided. Will be considered the
30
+ # `action` parameter if **both** the title and a block are provided.
31
+ #
32
+ # @param action [String] The Stimulus action that should fire when the button
33
+ # is clicked.
34
+ #
35
+ # @param kws [Hash] The keyword arguments for the component.
36
+ #
37
+ # @option kws title [String] The title of the button. You can also
38
+ # pass the title, icons, or any other HTML content as a block.
39
+ #
40
+ # @option kws action [String] The Stimulus action that should fire
41
+ # when the button is clicked.
42
+ #
43
+ # > **Note:** _You should use either the `action` or the `href` option, but
44
+ # not both._
45
+ #
46
+ # @option kws href [String] A path or URL to which the user will be
47
+ # directed when the button is clicked. Forces the Button to use an `<a>`
48
+ # tag.
49
+ #
50
+ # > **Note:** _You should use either the `action` or the `href` option, but
51
+ # not both._
52
+ #
53
+ # @option kws target [String] The HTML `target` of for the `<a>` tag
54
+ # (`_blank`, `_parent`, or a specific tab / window / iframe, etc).
55
+ #
56
+ # @option kws icon [String] The name of Hero icon to render inside
57
+ # the button. This is an alias of `left_icon`.
58
+ #
59
+ # @option kws icon_css [String] The CSS classes to apply to the icon.
60
+ # This is an alias of `left_icon_css`.
61
+ #
62
+ # @option kws icon_html [Hash] Additional HTML attributes to apply to
63
+ # the icon. This is an alias of `left_icon_html`.
64
+ #
65
+ # @option kws left_icon [String] The name of Hero icon to render inside
66
+ # the button to the left of the text.
67
+ #
68
+ # @option kws left_icon_css [String] The CSS classes to apply to the left
69
+ # icon.
70
+ #
71
+ # @option kws left_icon_html [Hash] Additional HTML attributes to apply to
72
+ # the left icon.
73
+ #
74
+ # @option kws right_icon [String] The name of Hero icon to render inside
75
+ # the button to the right of the text.
76
+ #
77
+ # @option kws right_icon_css [String] The CSS classes to apply to the right
78
+ # icon.
79
+ #
80
+ # @option kws right_icon_html [Hash] Additional HTML attributes to apply to
81
+ # the right icon.
82
+ #
83
+ def initialize(title = nil, action = nil, **kws, &block)
8
84
  super
9
85
 
86
+ # If both a title and a block are provided, assume the title is the action
87
+ action = title if title && block_given?
88
+
89
+ # Force the title to be nil if a block is given so we don't accidentally
90
+ # render two titles
91
+ title = nil if block_given?
92
+
93
+ @action = config_option(:action, action)
94
+
10
95
  @href = config_option(:href)
11
96
  @target = config_option(:target)
12
97
 
@@ -23,15 +108,21 @@ class Daisy::Actions::ButtonComponent < LocoMotion::BaseComponent
23
108
  @right_icon_html = config_option(:right_icon_html, @icon_html)
24
109
 
25
110
  default_title = @left_icon || @right_icon ? nil : "Submit"
26
- @simple_title = config_option(:title, args[0] || default_title)
111
+ @simple_title = config_option(:title, title || default_title)
27
112
  end
28
113
 
114
+ #
115
+ # Calls the {setup_component} method before rendering the component.
116
+ #
29
117
  def before_render
30
118
  setup_component
31
119
  end
32
120
 
33
- private
34
-
121
+ #
122
+ # Sets the tagname to `<a>` if an `href` is provided, otherwise sets it to
123
+ # `<button>`. Adds the `btn` CSS class to the component. Also adds
124
+ # `items-center` and `gap-2` CSS classes if an icon is present.
125
+ #
35
126
  def setup_component
36
127
  if @href
37
128
  set_tag_name(:component, :a)
@@ -42,13 +133,23 @@ class Daisy::Actions::ButtonComponent < LocoMotion::BaseComponent
42
133
 
43
134
  add_css(:component, "btn")
44
135
 
45
- add_css(:component, "items-center gap-2") if @icon
136
+ if @icon || @left_icon || @right_icon
137
+ add_css(:component, "[:where(&)]:items-center [:where(&)]:gap-2")
138
+ end
139
+
140
+ add_html(:component, { "data-action": @action }) if @action
46
141
  end
47
142
 
143
+ #
144
+ # Returns the HTML attributes for the left icon.
145
+ #
48
146
  def left_icon_html
49
147
  { class: @left_icon_css }.merge(@left_icon_html)
50
148
  end
51
149
 
150
+ #
151
+ # Returns the HTML attributes for the right icon.
152
+ #
52
153
  def right_icon_html
53
154
  { class: @right_icon_css }.merge(@right_icon_html)
54
155
  end
@@ -1,13 +1,13 @@
1
1
  = part(:component) do
2
- - if title?
3
- = title
2
+ - if activator?
3
+ = activator
4
4
  - else
5
- = part(:title) do
6
- = @simple_title
5
+ = button
7
6
 
8
7
  - if items.any?
9
8
  = part(:menu) do
10
9
  - items.each do |item|
11
- = item
10
+ = part(:menu_item) do
11
+ = item
12
12
  - else
13
13
  = content
@@ -1,48 +1,117 @@
1
- # Here are the Button docs!
1
+ #
2
+ # The Dropdown component shows a Button, or any other component you wish, with a
3
+ # hovering menu that opens on click (or hover). It provides a flexible way to
4
+ # create dropdown menus with customizable triggers and content.
5
+ #
6
+ # Note that the dropdown uses slots for both the activator and menu items,
7
+ # allowing for maximum flexibility in how the dropdown is triggered and what
8
+ # content it displays.
9
+ #
10
+ # @part menu The default / styled menu rendered by the dropdown. Contains all
11
+ # menu items and provides the dropdown's positioning and animation.
12
+ # @part menu_item The styles for every item in the dropdown. Provides consistent
13
+ # spacing and hover states.
14
+ #
15
+ # @slot button The button that triggers the dropdown. This is the default trigger
16
+ # and is styled automatically.
17
+ # @slot activator A custom (i.e. non-button) activator for the dropdown.
18
+ # Automatically adds the `role="button"` and `tabindex="0"` attributes.
19
+ # @slot item+ The items in the dropdown. Each item will be styled consistently
20
+ # with proper spacing and hover states.
21
+ #
22
+ # @loco_example Basic Usage
23
+ # = daisy_dropdown do |dropdown|
24
+ # - dropdown.with_button do
25
+ # Click me!
26
+ # - dropdown.with_item do
27
+ # Item 1
28
+ # - dropdown.with_item do
29
+ # Item 2
30
+ #
31
+ # @loco_example Custom Activator
32
+ # = daisy_dropdown do |dropdown|
33
+ # - dropdown.with_activator do
34
+ # = heroicon_tag "bars-3", css: "size-6"
35
+ # - dropdown.with_item do
36
+ # Menu Item 1
37
+ # - dropdown.with_item do
38
+ # Menu Item 2
39
+ #
40
+ # @loco_example Complex Items
41
+ # = daisy_dropdown do |dropdown|
42
+ # - dropdown.with_button do
43
+ # User Settings
44
+ # - dropdown.with_item do
45
+ # .flex.gap-2.items-center
46
+ # = heroicon_tag "user-circle"
47
+ # Profile
48
+ # - dropdown.with_item do
49
+ # .flex.gap-2.items-center
50
+ # = heroicon_tag "cog-6-tooth"
51
+ # Settings
52
+ # - dropdown.with_item do
53
+ # .flex.gap-2.items-center.text-error
54
+ # = heroicon_tag "arrow-right-on-rectangle"
55
+ # Logout
56
+ #
2
57
  class Daisy::Actions::DropdownComponent < LocoMotion::BaseComponent
3
58
 
4
- TitleComponent = LocoMotion::BasicComponent.build do
5
- def before_render
6
- add_html(:component, { role: "button", tabindex: 0 })
7
- end
8
- end
9
-
10
- ItemComponent = LocoMotion::BasicComponent.build do
11
- def before_render
12
- set_tag_name(:component, :li)
13
- end
14
- end
59
+ include ViewComponent::SlotableDefault
15
60
 
16
- define_parts :title, :menu
61
+ define_parts :menu, :menu_item
17
62
 
18
- renders_one :title, TitleComponent
19
- renders_many :items, ItemComponent
63
+ renders_one :activator, LocoMotion::BasicComponent.build(html: { role: "button", tabindex: 0 })
64
+ renders_one :button, Daisy::Actions::ButtonComponent
65
+ renders_many :items
20
66
 
21
- def initialize(*args, **kws, &block)
67
+ #
68
+ # Creates a new instance of the DropdownComponent.
69
+ #
70
+ # @param title [String] The title of the dropdown. Will be used as the button
71
+ # text if no custom button or activator is provided.
72
+ #
73
+ # @param kws [Hash] The keyword arguments for the component.
74
+ #
75
+ # @option kws title [String] The title of the dropdown. You can also pass this
76
+ # as the first argument.
77
+ #
78
+ def initialize(title = nil, **kws, &block)
22
79
  super
23
80
 
24
- @simple_title = config_option(:title, "Submit")
81
+ @simple_title = config_option(:title, title)
25
82
  end
26
83
 
84
+ #
85
+ # Adds the relevant Daisy classes to the component.
86
+ #
27
87
  def before_render
28
88
  setup_component
29
- setup_title
30
89
  setup_menu
31
90
  end
32
91
 
92
+ #
93
+ # Add the `dropdown` CSS class to the component.
94
+ #
33
95
  def setup_component
34
96
  add_css(:component, "dropdown")
35
97
  end
36
98
 
37
- def setup_title
38
- set_tag_name(:title, :div)
39
- add_css(:title, "btn")
40
- add_html(:title, { role: "button", tabindex: 0 })
41
- end
42
-
99
+ #
100
+ # Make the menu a `<ul> / <li>` element and add the relevant Daisy classes.
101
+ #
43
102
  def setup_menu
103
+ # Setup menu itself
44
104
  set_tag_name(:menu, :ul)
45
105
  add_css(:menu, "dropdown-content menu bg-base-100 rounded-box shadow w-52 p-2 z-[1]")
46
- add_html(:menu, { role: "menu", tabindex: 0 })
106
+
107
+ # Setup menu items
108
+ set_tag_name(:menu_item, :li)
109
+ end
110
+
111
+ #
112
+ # Provides a default button if no button or custom activator is provided.
113
+ #
114
+ def default_button
115
+ Daisy::Actions::ButtonComponent.new(title: @simple_title)
47
116
  end
48
117
  end
@@ -1,6 +1,7 @@
1
1
  - if activator?
2
- = part(:activator) do
3
- = activator
2
+ = activator
3
+ - else
4
+ = button
4
5
 
5
6
  = part(:component) do
6
7
  = part(:box) do