flowbite-components 0.1.4 → 0.3.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 (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +28 -4
  3. data/README.md +23 -4
  4. data/app/components/flowbite/badge/badge.html.erb +4 -0
  5. data/app/components/flowbite/badge/dot.rb +45 -0
  6. data/app/components/flowbite/badge/pill.rb +40 -0
  7. data/app/components/flowbite/badge.rb +116 -0
  8. data/app/components/flowbite/breadcrumb/home_icon.rb +28 -0
  9. data/app/components/flowbite/breadcrumb/item/current.rb +35 -0
  10. data/app/components/flowbite/breadcrumb/item/first.rb +37 -0
  11. data/app/components/flowbite/breadcrumb/item.rb +50 -0
  12. data/app/components/flowbite/breadcrumb/separator_icon.rb +34 -0
  13. data/app/components/flowbite/breadcrumb.rb +54 -0
  14. data/app/components/flowbite/button.rb +6 -5
  15. data/app/components/flowbite/card.rb +15 -1
  16. data/app/components/flowbite/input/checkbox.rb +2 -2
  17. data/app/components/flowbite/input/date.rb +2 -2
  18. data/app/components/flowbite/input/date_time.rb +11 -0
  19. data/app/components/flowbite/input/email.rb +2 -2
  20. data/app/components/flowbite/input/file.rb +2 -2
  21. data/app/components/flowbite/input/hint.rb +6 -1
  22. data/app/components/flowbite/input/label.rb +1 -1
  23. data/app/components/flowbite/input/number.rb +2 -2
  24. data/app/components/flowbite/input/password.rb +2 -2
  25. data/app/components/flowbite/input/phone.rb +2 -2
  26. data/app/components/flowbite/input/radio_button.rb +2 -2
  27. data/app/components/flowbite/input/select.rb +2 -2
  28. data/app/components/flowbite/input/textarea.rb +2 -2
  29. data/app/components/flowbite/input/url.rb +2 -2
  30. data/app/components/flowbite/input/validation_error.rb +1 -1
  31. data/app/components/flowbite/input.rb +155 -0
  32. data/app/components/flowbite/input_field/checkbox.rb +7 -7
  33. data/app/components/flowbite/input_field/date_time.rb +13 -0
  34. data/app/components/flowbite/input_field/input_field.html.erb +2 -2
  35. data/app/components/flowbite/input_field/radio_button.rb +9 -15
  36. data/app/components/flowbite/input_field/select.rb +1 -1
  37. data/app/components/flowbite/input_field.rb +120 -69
  38. data/app/components/flowbite/link.rb +2 -0
  39. data/app/components/flowbite/sidebar/item.rb +68 -0
  40. data/app/components/flowbite/sidebar/navigation.rb +62 -0
  41. data/app/components/flowbite/sidebar.rb +62 -0
  42. data/app/components/flowbite/toast/icon.html.erb +5 -0
  43. data/app/components/flowbite/toast/icon.rb +57 -0
  44. data/app/components/flowbite/toast/toast.html.erb +40 -0
  45. data/app/components/flowbite/toast.rb +37 -0
  46. data/lib/flowbite/components/version.rb +1 -1
  47. data/lib/yard/flowbite_viewcomponent.rb +24 -0
  48. metadata +40 -5
  49. data/app/components/flowbite/input/field.rb +0 -126
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0013a87a4e4924d4ca2fe6f3ba8eff3f9f266be23a15b07cbddd25164d436805
4
- data.tar.gz: d50dd418f1403dc2375754f4b0d295c9c2d4f1a09c0904bffce88fc76268135b
3
+ metadata.gz: 2df1ff6599a8e3fa6a41cd9b6329654d3ebb532eae460f37dceb1c8e9b3e0be5
4
+ data.tar.gz: 33362285ce24f76a7490f646dffb524a66f3c44c584e8da5d66abad27a74f809
5
5
  SHA512:
6
- metadata.gz: e410ab1f18d6264c18cae8e5c0322c612422e33aa4136ab99ff21e6b0564ceaeb95decd262a265d72b9029022ff76965c19eeb0438d3d295c85cd2962986a3ab
7
- data.tar.gz: 168b101505fbddfc952c334cc169c1e12e5f129beb8c3f884ffd32047c0548bd22655fd03a6da3589f9ff5071c94850d727761c7aacb96b2712c09420657147c
6
+ metadata.gz: 9968e1c9ad9230e73475ddc85d1069395444700af804f5712b8f3bef027fd4744b3eec136cd3edc737f947aaf478b5fa22279ed3f9494735684c8d66e93690c4
7
+ data.tar.gz: 3d3f420dbf18ceb93de989ea5818aff5551279cc29e11e4c326ccb2148ca76dfaf8c451571c911c0149ff129f772d674752ec7b126ece767bd7f34d3b1a43503
data/CHANGELOG.md CHANGED
@@ -3,13 +3,37 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
- ## [Unreleased]
6
+ ## [0.3.0]
7
7
 
8
8
  ### Added
9
9
 
10
+ * Badge component.
11
+ * Sidebar component.
12
+
10
13
  ### Changed
11
14
 
12
- ### Removed
15
+ ### Fixed
16
+
17
+ * `:class` arguments to subcomponents (ie `hint` and `input`) of Flowbite::InputField are now forwarded correctly. If passed as `:class` the given value is added to the existing class names, if passed in `options[:class]` the existing class attribute is replaced.
18
+
19
+
20
+ ## [0.2.0]
21
+
22
+ ### Added
23
+
24
+ * Breadcrumb component, including Flowbite::Breadcrumb::Item with Flowbite::Breadcrumb::Item::First and Flowbite::Breadcrumb::Item::Current variants.
25
+ * DateTime input field components.
26
+ * Toast component.
27
+ * Ruby 4.0 support (no changes).
28
+
29
+ ### Changed
30
+
31
+ * [BREAKING] The API of Flowbite::InputField::RadioButton now follows the same structure as the other components for hints. Instead of passing a String (`hint: "This is the hint"`) you now have to pass a Hash that's passed along to the Hint component (i.e. `hint: {content: "This is the hint"}`), allowing you to customize other options (eg HTML attributes like class) as well.
32
+ * [BREAKING] Flowbite::Input::Field has been renamed to Flowbite::Input. All individual input components now use that as their superclass. This matches the class hierarchy of Flowbite::InputField::* classes better and allows Flowbite::Input to automagically appear in the documentation.
33
+
34
+ ### Fixed
35
+
36
+ * Flowbite::InputField classes now correctly add their options to the container element, so you can add id attributes or connect Stimulus controllers again.
13
37
 
14
38
 
15
39
  ## [0.1.4]
@@ -19,7 +43,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
19
43
  * Flowbite::Link component to render links.
20
44
  * Flowbite::Card now displays a title via the title argument/slot.
21
45
  * Improved error message when an unknown style is requested.
22
- * Input-elements now support forms without an object; ie forms built with `form_tag` - not `form_for` or `form_with`.
46
+ * Input-elements now support forms without an object; i.e. forms built with `form_tag` - not `form_for` or `form_with`.
23
47
 
24
48
  ### Changed
25
49
 
@@ -28,7 +52,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
28
52
 
29
53
  ### Removed
30
54
 
31
- * [BREAKING] Color-specific styles from Flowbite::Button, ie `alternative`, `green`, `light`, `purple`, `red`, `yellow`.
55
+ * [BREAKING] Color-specific styles from Flowbite::Button, i.e. `alternative`, `green`, `light`, `purple`, `red`, `yellow`.
32
56
 
33
57
 
34
58
  ## [0.1.3]
data/README.md CHANGED
@@ -7,6 +7,8 @@ Unofficial, open source implementation of [Flowbite](https://flowbite.com/) comp
7
7
 
8
8
  Flowbite Components provides a comprehensive library of UI components following the Flowbite design system, implemented as Rails ViewComponents with full Tailwind CSS integration and dark mode support.
9
9
 
10
+ Preview the components at https://flowbite-components.substancelab.com/lookbook/
11
+
10
12
  ## Features
11
13
 
12
14
  - **Full Flowbite Design System**: Faithful implementation of Flowbite components
@@ -82,6 +84,8 @@ If you want to use one of the other [Flowbite themes](https://flowbite.com/docs/
82
84
  <% end %>
83
85
  ```
84
86
 
87
+ See more examples at https://flowbite-components.substancelab.com/lookbook/inspect/input_field/inputfield.
88
+
85
89
  ### Button Examples
86
90
 
87
91
  ```erb
@@ -91,16 +95,18 @@ If you want to use one of the other [Flowbite themes](https://flowbite.com/docs/
91
95
  <% end %>
92
96
 
93
97
  <!-- Outline button with color -->
94
- <%= render Flowbite::Button::Outline.new(style: :blue) do %>
98
+ <%= render Flowbite::Button::Outline.new(style: :success) do %>
95
99
  Outline Button
96
100
  <% end %>
97
101
 
98
102
  <!-- Pill button -->
99
- <%= render Flowbite::Button::Pill.new(style: :green) do %>
103
+ <%= render Flowbite::Button::Pill.new(style: :danger) do %>
100
104
  Pill Button
101
105
  <% end %>
102
106
  ```
103
107
 
108
+ See more examples at https://flowbite-components.substancelab.com/lookbook/inspect/button/default.
109
+
104
110
  ### Custom Input Options
105
111
 
106
112
  ```erb
@@ -118,6 +124,8 @@ If you want to use one of the other [Flowbite themes](https://flowbite.com/docs/
118
124
  ) %>
119
125
  ```
120
126
 
127
+ See more examples at https://flowbite-components.substancelab.com/lookbook/inspect/input_field/inputfield.
128
+
121
129
  ### Custom Labels
122
130
 
123
131
  ```erb
@@ -131,6 +139,8 @@ If you want to use one of the other [Flowbite themes](https://flowbite.com/docs/
131
139
  ) %>
132
140
  ```
133
141
 
142
+ See more examples at https://flowbite-components.substancelab.com/lookbook/inspect/input_label/inputlabel.
143
+
134
144
  ### Disabled and Error States
135
145
 
136
146
  ```erb
@@ -149,6 +159,8 @@ If you want to use one of the other [Flowbite themes](https://flowbite.com/docs/
149
159
  ) %>
150
160
  ```
151
161
 
162
+ See more examples at https://flowbite-components.substancelab.com/lookbook/inspect/input_field/disabled_state.
163
+
152
164
  ## How to customize components
153
165
 
154
166
  ### Add specific CSS classes
@@ -238,7 +250,7 @@ render(Component.new(class: "these are added"))
238
250
  ```
239
251
 
240
252
  This makes for easier customization of components, where you don't have to
241
- recreate the entire classlist, ie in order to increase sizes or add margins or
253
+ recreate the entire classlist, i.e. in order to increase sizes or add margins or
242
254
  whatever.
243
255
 
244
256
  If you want to replace the entire class attribute for a component, pass it as part of the `options` hash, ie
@@ -276,7 +288,7 @@ This library includes a demo application with previews for all components. To vi
276
288
  1. cd demo
277
289
  2. Run `bundle && npm install`
278
290
  3. Run `rails server`
279
- 4. Visit `http://localhost:3000/rails/lookbook`
291
+ 4. Visit `http://localhost:3000/lookbook`
280
292
 
281
293
  ## Contributing
282
294
 
@@ -296,6 +308,13 @@ Bug reports and pull requests are welcome on GitHub at [https://github.com/subst
296
308
  - [ViewComponent Documentation](https://viewcomponent.org/)
297
309
  - [Tailwind CSS Documentation](https://tailwindcss.com/docs)
298
310
 
311
+ ## Other ViewComponent-based libraries
312
+
313
+ If Flowbite isn't your preference, perhaps one of these other component libraries suits you better?
314
+
315
+ * [GOV.UK Components](https://govuk-components.netlify.app/introduction/get-started/)
316
+ * [Primer Product UI for Rails](https://primer.style/product/getting-started/rails/)
317
+
299
318
  ## Other Flowbite component libraries
300
319
 
301
320
  * https://flowbite-react.com/
@@ -0,0 +1,4 @@
1
+ <%= content_tag(tag_name, **tag_options) do %>
2
+ <% if dot? %><%= render(Flowbite::Badge::Dot.new(style: @style)) %><% end %>
3
+ <%= content %>
4
+ <% end %>
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flowbite
4
+ class Badge
5
+ # Renders a colored dot indicator for use inside a badge.
6
+ #
7
+ # @param style [Symbol] The color style of the dot (:alternative, :brand,
8
+ # :danger, :gray, :success, :warning).
9
+ class Dot < ViewComponent::Base
10
+ CLASSES = {
11
+ alternative: ["bg-heading", "me-1", "rounded-full"],
12
+ brand: ["bg-fg-brand-strong", "me-1", "rounded-full"],
13
+ danger: ["bg-fg-danger-strong", "me-1", "rounded-full"],
14
+ gray: ["bg-heading", "me-1", "rounded-full"],
15
+ success: ["bg-fg-success-strong", "me-1", "rounded-full"],
16
+ warning: ["bg-fg-warning", "me-1", "rounded-full"]
17
+ }.freeze
18
+
19
+ SIZES = {
20
+ default: ["h-1.5", "w-1.5"]
21
+ }.freeze
22
+
23
+ class << self
24
+ def classes(size: :default, style: :brand)
25
+ CLASSES.fetch(style) + sizes.fetch(size)
26
+ end
27
+
28
+ def sizes
29
+ SIZES
30
+ end
31
+ end
32
+
33
+ attr_reader :size, :style
34
+
35
+ def initialize(size: :default, style: :brand)
36
+ @size = size
37
+ @style = style
38
+ end
39
+
40
+ def call
41
+ content_tag(:span, nil, class: self.class.classes(size: size, style: style))
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flowbite
4
+ class Badge
5
+ # Renders a pill-shaped badge with fully rounded corners.
6
+ #
7
+ # @example Basic usage
8
+ # <%= render(Flowbite::Badge::Pill.new) { "Default" } %>
9
+ #
10
+ # @see https://flowbite.com/docs/components/badge/
11
+ class Pill < Flowbite::Badge
12
+ class << self
13
+ # rubocop:disable Layout/LineLength
14
+ def styles
15
+ Flowbite::Styles.from_hash({
16
+ alternative: {
17
+ default: ["bg-neutral-primary-soft", "hover:bg-neutral-secondary-medium", "rounded-full", "text-heading"]
18
+ },
19
+ brand: {
20
+ default: ["bg-brand-softer", "hover:bg-brand-soft", "rounded-full", "text-fg-brand-strong"]
21
+ },
22
+ danger: {
23
+ default: ["bg-danger-soft", "hover:bg-danger-medium", "rounded-full", "text-fg-danger-strong"]
24
+ },
25
+ gray: {
26
+ default: ["bg-neutral-secondary-medium", "hover:bg-neutral-tertiary-medium", "rounded-full", "text-heading"]
27
+ },
28
+ success: {
29
+ default: ["bg-success-soft", "hover:bg-success-medium", "rounded-full", "text-fg-success-strong"]
30
+ },
31
+ warning: {
32
+ default: ["bg-warning-soft", "hover:bg-warning-medium", "rounded-full", "text-fg-warning"]
33
+ }
34
+ }.freeze)
35
+ end
36
+ # rubocop:enable Layout/LineLength
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flowbite
4
+ # Renders a badge component for displaying labels, counts, or status
5
+ # indicators.
6
+ #
7
+ # @example Basic usage
8
+ # <%= render(Flowbite::Badge.new) { "Default" } %>
9
+ #
10
+ # @example With border
11
+ # <%= render(Flowbite::Badge.new(bordered: true, style: :success)) { "Success" } %>
12
+ #
13
+ # @see https://flowbite.com/docs/components/badge/
14
+ # @lookbook_embed BadgePreview
15
+ class Badge < ViewComponent::Base
16
+ SIZES = {
17
+ default: ["text-xs", "font-medium", "px-1.5", "py-0.5"],
18
+ lg: ["text-sm", "font-medium", "px-2", "py-1"]
19
+ }.freeze
20
+
21
+ BORDER_CLASSES = {
22
+ alternative: ["border", "border-default"],
23
+ brand: ["border", "border-brand-subtle"],
24
+ danger: ["border", "border-danger-subtle"],
25
+ gray: ["border", "border-default-medium"],
26
+ success: ["border", "border-success-subtle"],
27
+ warning: ["border", "border-warning-subtle"]
28
+ }.freeze
29
+
30
+ class << self
31
+ def classes(size: :default, state: :default, style: :brand)
32
+ styles.fetch(style).fetch(state) + sizes.fetch(size)
33
+ end
34
+
35
+ def sizes
36
+ SIZES
37
+ end
38
+
39
+ # rubocop:disable Layout/LineLength
40
+ def styles
41
+ Flowbite::Styles.from_hash({
42
+ alternative: {
43
+ default: ["bg-neutral-primary-soft", "hover:bg-neutral-secondary-medium", "rounded", "text-heading"]
44
+ },
45
+ brand: {
46
+ default: ["bg-brand-softer", "hover:bg-brand-soft", "rounded", "text-fg-brand-strong"]
47
+ },
48
+ danger: {
49
+ default: ["bg-danger-soft", "hover:bg-danger-medium", "rounded", "text-fg-danger-strong"]
50
+ },
51
+ gray: {
52
+ default: ["bg-neutral-secondary-medium", "hover:bg-neutral-tertiary-medium", "rounded", "text-heading"]
53
+ },
54
+ success: {
55
+ default: ["bg-success-soft", "hover:bg-success-medium", "rounded", "text-fg-success-strong"]
56
+ },
57
+ warning: {
58
+ default: ["bg-warning-soft", "hover:bg-warning-medium", "rounded", "text-fg-warning"]
59
+ }
60
+ }.freeze)
61
+ end
62
+ # rubocop:enable Layout/LineLength
63
+ end
64
+
65
+ attr_reader :options
66
+
67
+ # @param bordered [Boolean] Whether to add a border to the badge.
68
+ # @param class [String, Array<String>] Additional CSS classes.
69
+ # @param dot [Boolean] Whether to show a dot indicator.
70
+ # @param href [String] If provided, renders the badge as a link.
71
+ # @param size [Symbol] The size of the badge (:default or :lg).
72
+ # @param style [Symbol] The color style (:alternative, :brand, :danger,
73
+ # :gray, :success, :warning).
74
+ def initialize(bordered: false, class: nil, dot: false, href: nil,
75
+ size: :default, style: :brand, **options)
76
+ @bordered = bordered
77
+ @class = Array.wrap(binding.local_variable_get(:class))
78
+ @dot = dot
79
+ @href = href
80
+ @size = size
81
+ @style = style
82
+ @options = options
83
+ end
84
+
85
+ def bordered?
86
+ !!@bordered
87
+ end
88
+
89
+ def dot?
90
+ !!@dot
91
+ end
92
+
93
+ def link?
94
+ @href.present?
95
+ end
96
+
97
+ private
98
+
99
+ def classes
100
+ result = self.class.classes(size: @size, state: :default, style: @style)
101
+ result += BORDER_CLASSES.fetch(@style) if bordered?
102
+ result += ["inline-flex", "items-center"] if dot?
103
+ result + @class
104
+ end
105
+
106
+ def tag_name
107
+ link? ? :a : :span
108
+ end
109
+
110
+ def tag_options
111
+ opts = {class: classes}
112
+ opts[:href] = @href if link?
113
+ opts.merge(options)
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flowbite
4
+ class Breadcrumb
5
+ # Renders a breadcrumb home icon.
6
+ #
7
+ # This is typically used as a prefix icon in the first breadcrumb item,
8
+ # but can be used standalone if needed.
9
+ #
10
+ # @example Standalone usage
11
+ # <%= render Flowbite::Breadcrumb::HomeIcon.new %>
12
+ class HomeIcon < ViewComponent::Base
13
+ def call
14
+ tag.svg(
15
+ class: "w-3 h-3 me-2.5",
16
+ "aria-hidden": "true",
17
+ xmlns: "http://www.w3.org/2000/svg",
18
+ fill: "currentColor",
19
+ viewBox: "0 0 20 20"
20
+ ) do
21
+ tag.path(
22
+ d: "m19.707 9.293-2-2-7-7a1 1 0 0 0-1.414 0l-7 7-2 2a1 1 0 0 0 1.414 1.414L2 10.414V18a2 2 0 0 0 2 2h3a1 1 0 0 0 1-1v-4a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v4a1 1 0 0 0 1 1h3a2 2 0 0 0 2-2v-7.586l.293.293a1 1 0 0 0 1.414-1.414Z"
23
+ )
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flowbite
4
+ class Breadcrumb
5
+ class Item
6
+ # Renders the current page breadcrumb item.
7
+ # Current items are rendered as non-interactive spans with different styling.
8
+ #
9
+ # @param options [Hash] Additional HTML attributes to pass to the span element.
10
+ #
11
+ # @example Current page item
12
+ # <%= render Flowbite::Breadcrumb::Item::Current.new { "Current Page" } %>
13
+ class Current < Item
14
+ def initialize(**options)
15
+ super(href: nil, **options)
16
+ end
17
+
18
+ protected
19
+
20
+ def item_options
21
+ {"aria-current": "page"}
22
+ end
23
+
24
+ def render_link
25
+ link_options = {class: link_classes}.merge(options)
26
+ content_tag(:span, content, **link_options)
27
+ end
28
+
29
+ def link_classes
30
+ ["ms-1", "text-sm", "font-medium", "text-body-subtle"]
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flowbite
4
+ class Breadcrumb
5
+ class Item
6
+ # Renders the first breadcrumb item (typically home).
7
+ # First items don't show a separator icon.
8
+ #
9
+ # @param href [String] The URL for the breadcrumb link.
10
+ # @param options [Hash] Additional HTML attributes to pass to the link element.
11
+ #
12
+ # @example First item
13
+ # <%= render Flowbite::Breadcrumb::Item::First.new(href: "/") { "Home" } %>
14
+ class First < Item
15
+ protected
16
+
17
+ def item_options
18
+ {class: "inline-flex items-center"}
19
+ end
20
+
21
+ def link_classes
22
+ ["text-sm", "font-medium", "inline-flex", "items-center", "text-body", "hover:text-fg-brand"]
23
+ end
24
+
25
+ def prefix_icon
26
+ nil
27
+ end
28
+
29
+ def render_link
30
+ icon = render(Flowbite::Breadcrumb::HomeIcon.new)
31
+ link_options = {class: link_classes}.merge(options)
32
+ content_tag(:a, safe_join([icon, content]), href: href, **link_options)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flowbite
4
+ class Breadcrumb
5
+ # Base class for rendering a breadcrumb item (middle items in the breadcrumb trail).
6
+ #
7
+ # @param href [String] The URL for the breadcrumb link.
8
+ # @param options [Hash] Additional HTML attributes to pass to the link element.
9
+ #
10
+ # @example Middle item
11
+ # <%= render Flowbite::Breadcrumb::Item.new(href: "/projects") { "Projects" } %>
12
+ class Item < ViewComponent::Base
13
+ attr_reader :href, :options
14
+
15
+ def initialize(href:, **options)
16
+ super()
17
+ @href = href
18
+ @options = options
19
+ end
20
+
21
+ def call
22
+ content_tag(:li, item_options) do
23
+ content_tag(:div, class: "flex items-center") do
24
+ concat(render(prefix_icon)) if prefix_icon
25
+ concat(render_link)
26
+ end
27
+ end
28
+ end
29
+
30
+ protected
31
+
32
+ def item_options
33
+ {}
34
+ end
35
+
36
+ def prefix_icon
37
+ Flowbite::Breadcrumb::SeparatorIcon.new
38
+ end
39
+
40
+ def render_link
41
+ link_options = {class: link_classes}.merge(options)
42
+ content_tag(:a, content, href: href, **link_options)
43
+ end
44
+
45
+ def link_classes
46
+ ["ms-1", "text-sm", "font-medium", "text-body", "hover:text-fg-brand"]
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flowbite
4
+ class Breadcrumb
5
+ # Renders a breadcrumb separator icon.
6
+ #
7
+ # This is automatically used by Breadcrumb::Item components, but can be
8
+ # used standalone if needed.
9
+ #
10
+ # @example Standalone usage
11
+ # <%= render Flowbite::Breadcrumb::SeparatorIcon.new %>
12
+ class SeparatorIcon < ViewComponent::Base
13
+ def call
14
+ tag.svg(
15
+ class: "w-3.5 h-3.5 rtl:rotate-180 text-body",
16
+ "aria-hidden": "true",
17
+ xmlns: "http://www.w3.org/2000/svg",
18
+ fill: "none",
19
+ height: 24,
20
+ viewBox: "0 0 24 24",
21
+ width: 24
22
+ ) do
23
+ tag.path(
24
+ stroke: "currentColor",
25
+ "stroke-linecap": "round",
26
+ "stroke-linejoin": "round",
27
+ "stroke-width": "2",
28
+ d: "m9 5 7 7-7 7"
29
+ )
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flowbite
4
+ # Renders a breadcrumb navigation component.
5
+ #
6
+ # Use {Flowbite::Breadcrumb} and the child {Flowbite::Breadcrumb::Item}
7
+ # components to create and indicate a series of page structure and URLs to
8
+ # help the user navigate through the website.
9
+ #
10
+ # Breadcrumbs consist of the following components:
11
+ #
12
+ # - {Flowbite::Breadcrumb}: Container for breadcrumb items.
13
+ # - {Flowbite::Breadcrumb::HomeIcon}: Home icon for the first breadcrumb item.
14
+ # - {Flowbite::Breadcrumb::SeparatorIcon}: Separator between breadcrumb items.
15
+ # - {Flowbite::Breadcrumb::Item}: An individual breadcrumb item.
16
+ # - {Flowbite::Breadcrumb::Item::Current}: An individual breadcrumb item
17
+ # without a link, usually used for the current page in the breadcrumb trail.
18
+ # - {Flowbite::Breadcrumb::Item::First}: An individual breadcrumb item with a
19
+ # home icon on it.
20
+ #
21
+ # @example Usage
22
+ # <%= render(Flowbite::Breadcrumb.new) do |breadcrumb| %>
23
+ # <% breadcrumb.with_item do %>
24
+ # <%= render(Flowbite::Breadcrumb::Item::First.new(href: "/")) { "Root page" } %>
25
+ # <% end %>
26
+ # <% breadcrumb.with_item do %>
27
+ # <%= render(Flowbite::Breadcrumb::Item.new(href: "/projects")) { "Parent page" } %>
28
+ # <% end %>
29
+ # <% breadcrumb.with_item do %>
30
+ # <%= render(Flowbite::Breadcrumb::Item::Current.new) { "Current Page" } %>
31
+ # <% end %>
32
+ # <% end %>
33
+ #
34
+ # @viewcomponent_slot [Flowbite::Breadcrumb::Item] items The items of the
35
+ # breadcrumb trail. Use {Flowbite::Breadcrumb::Item::First} for the first
36
+ # item to get a home icon, and {Flowbite::Breadcrumb::Item::Current} for the
37
+ # last item to render it without a link.
38
+ #
39
+ # @lookbook_embed BreadcrumbPreview
40
+ # @see https://flowbite.com/docs/components/breadcrumb/
41
+ class Breadcrumb < ViewComponent::Base
42
+ renders_many :items
43
+
44
+ def call
45
+ content_tag(:nav, class: "flex", "aria-label": "Breadcrumb") do
46
+ content_tag(:ol, class: "inline-flex items-center space-x-1 md:space-x-2 rtl:space-x-reverse") do
47
+ items.each do |item|
48
+ concat(item)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,14 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flowbite
4
- # Renders a HTML button element.
5
- #
6
- # See https://flowbite.com/docs/components/buttons/
7
- #
8
- # @param label [String] The text to display on the button.
4
+ # Renders a HTML button element. See https://flowbite.com/docs/components/buttons/
9
5
  #
10
6
  # All other parameters are optional and are passed directly to the button tag
11
7
  # as HTML attributes.
8
+ #
9
+ # @example Basic usage
10
+ # <%= render Flowbite::Button.new { "Click me" } %>
11
+ #
12
+ # @lookbook_embed ButtonPreview
12
13
  class Button < ViewComponent::Base
13
14
  SIZES = {
14
15
  xs: ["text-xs", "px-3", "py-1.5"],
@@ -3,7 +3,21 @@
3
3
  module Flowbite
4
4
  # Renders a card element.
5
5
  #
6
- # See https://flowbite.com/docs/components/cards/
6
+ # To render a title in the card, use the title argument or the title slot.
7
+ #
8
+ # @example Using the title slot
9
+ # <%= render(Flowbite::Card.new) do |card| %>
10
+ # <% card.with_title do %>
11
+ # <div><%= parent_category.name %></div>
12
+ # <%= render(Flowbite::Card::Title.new) { category.name } %>
13
+ # <% end %>
14
+ # <% end %>
15
+ #
16
+ # @viewcomponent_slot [Flowbite::Card::Title] title The title of the card,
17
+ # rendered at the top. Use +with_title+ to set custom content.
18
+ #
19
+ # @see https://flowbite.com/docs/components/cards/
20
+ # @lookbook_embed CardPreview
7
21
  class Card < ViewComponent::Base
8
22
  renders_one :title
9
23
 
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flowbite
4
- module Input
4
+ class Input
5
5
  # The checkbox component can be used to receive one or more selected options
6
6
  # from the user in the form of a square box available in multiple styles,
7
7
  # sizes, colors, and variants coded with the utility classes from Tailwind
8
8
  # CSS and with support for dark mode.
9
9
  #
10
10
  # https://flowbite.com/docs/forms/checkbox/
11
- class Checkbox < Field
11
+ class Checkbox < Input
12
12
  DEFAULT_CHECKED_VALUE = "1"
13
13
  DEFAULT_UNCHECKED_VALUE = "0"
14
14