bulma-phlex 0.1.1 → 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.
- checksums.yaml +4 -4
- data/README.md +37 -6
- data/lib/bulma-phlex.rb +1 -0
- data/lib/bulma_phlex/version.rb +1 -1
- data/lib/components/bulma/dropdown.rb +109 -0
- data/lib/components/bulma/tabs.rb +14 -6
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5838ff317a395e9e57b33d45dad7f62c3a7820112a2453c35e9305e7a6ac19c1
|
4
|
+
data.tar.gz: 48988fd8c7210d47b0090d9d385fa6fce278d2ad6d47d10673aabf9e46034df8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49c89b3e7e9aa630d01ce8ae14b0c35694d811533c37512e42d2d21dbcae83546a96e5ef0262b4078d9235d6cea73f3dcad529ed91c4dd0ccfda1eee1af040d4
|
7
|
+
data.tar.gz: 9840cfdb56b3af42f2a32c3717b985a29ef93d939444ceaef47545915e450e8717c543eff3f867946aacdaac45ca51dcd2845f0d53b3b61a3eaa594586964847
|
data/README.md
CHANGED
@@ -62,6 +62,35 @@ render Components::Bulma::Card.new do |card|
|
|
62
62
|
end
|
63
63
|
```
|
64
64
|
|
65
|
+
### Dropdown
|
66
|
+
|
67
|
+
The [Dropdown](https://bulma.io/documentation/components/dropdown/) component provides a flexible dropdown menu for navigation or actions. It supports both click-to-toggle (default, requires a Stimulus controller) and hoverable modes, as well as alignment and icon customization.
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
render Components::Bulma::Dropdown.new("Next Actions...") do |dropdown|
|
71
|
+
dropdown.link "View Profile", "/profile"
|
72
|
+
dropdown.link "Go to Settings", "/settings"
|
73
|
+
dropdown.divider
|
74
|
+
dropdown.item("This is just a text item")
|
75
|
+
dropdown.item do
|
76
|
+
div(class: "has-text-weight-bold") { "This is a bold item" }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
```
|
80
|
+
|
81
|
+
**Options:**
|
82
|
+
|
83
|
+
- `label` (required): The dropdown button label.
|
84
|
+
- `click`: Stimulus controller name for click-to-toggle (default: `"bulma--dropdown"`). Set to `false` for hoverable.
|
85
|
+
- `alignment`: `:left` (default), `:right`, or `:up`.
|
86
|
+
- `icon`: Icon class for the dropdown arrow (default: `"fas fa-angle-down"`).
|
87
|
+
|
88
|
+
**Dropdown methods:**
|
89
|
+
|
90
|
+
- `link(label, path)`: Adds a link item.
|
91
|
+
- `item(content = nil, &block)`: Adds a custom item (string or block).
|
92
|
+
- `divider`: Adds a divider line.
|
93
|
+
|
65
94
|
### Level
|
66
95
|
|
67
96
|
The [Level](https://bulma.io/documentation/layout/level/) component provides a flexible horizontal layout system with left and right alignment.
|
@@ -88,12 +117,12 @@ The [NavigationBar](https://bulma.io/documentation/components/navbar/) component
|
|
88
117
|
```ruby
|
89
118
|
render Components::Bulma::NavigationBar.new do |navbar|
|
90
119
|
navbar.brand_item "My App", "/"
|
91
|
-
|
120
|
+
|
92
121
|
navbar.left do |menu|
|
93
122
|
menu.item "Home", "/"
|
94
123
|
menu.item "Products", "/products"
|
95
124
|
end
|
96
|
-
|
125
|
+
|
97
126
|
navbar.right do |menu|
|
98
127
|
menu.item "About", "/about"
|
99
128
|
menu.dropdown "Account" do |dropdown|
|
@@ -123,6 +152,8 @@ render Components::Bulma::Pagination.new(@products, ->(page) { products_path(pag
|
|
123
152
|
|
124
153
|
The [Table](https://bulma.io/documentation/elements/table/) component provides a way to display data in rows and columns with customizable headers and formatting options.
|
125
154
|
|
155
|
+
It requires a Hotwired Stimulus controller to manage the tabs and the content. By default, the controller name is assumed to be `bulma--tabs`, but can be overridden with the constructor keyword argument `stimulus_controller`. Stimulus targets and actions are added to the component.
|
156
|
+
|
126
157
|
```ruby
|
127
158
|
users = User.all
|
128
159
|
|
@@ -130,11 +161,11 @@ render Components::Bulma::Table.new(users) do |table|
|
|
130
161
|
table.column "Name" do |user|
|
131
162
|
user.full_name
|
132
163
|
end
|
133
|
-
|
164
|
+
|
134
165
|
table.column "Email" do |user|
|
135
166
|
user.email
|
136
167
|
end
|
137
|
-
|
168
|
+
|
138
169
|
table.column "Actions" do |user|
|
139
170
|
link_to "Edit", edit_user_path(user), class: "button is-small"
|
140
171
|
end
|
@@ -150,11 +181,11 @@ render Components::Bulma::Tabs.new do |tabs|
|
|
150
181
|
tabs.tab(id: "profile", title: "Profile", active: true) do
|
151
182
|
"Profile content goes here"
|
152
183
|
end
|
153
|
-
|
184
|
+
|
154
185
|
tabs.tab(id: "settings", title: "Settings", icon: "fas fa-cog") do
|
155
186
|
"Settings content goes here"
|
156
187
|
end
|
157
|
-
|
188
|
+
|
158
189
|
tabs.tab(id: "notifications", title: "Notifications", icon: "fas fa-bell") do
|
159
190
|
"Notifications content goes here"
|
160
191
|
end
|
data/lib/bulma-phlex.rb
CHANGED
@@ -6,6 +6,7 @@ require "bulma_phlex/version"
|
|
6
6
|
require "components/bulma"
|
7
7
|
require "components/bulma/base"
|
8
8
|
require "components/bulma/card"
|
9
|
+
require "components/bulma/dropdown"
|
9
10
|
require "components/bulma/level"
|
10
11
|
require "components/bulma/navigation_bar_dropdown"
|
11
12
|
require "components/bulma/navigation_bar"
|
data/lib/bulma_phlex/version.rb
CHANGED
@@ -0,0 +1,109 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Components
|
4
|
+
module Bulma
|
5
|
+
# Dropdown component
|
6
|
+
#
|
7
|
+
# This component implements the [Bulma Dropdown](https://bulma.io/documentation/components/dropdown/).
|
8
|
+
#
|
9
|
+
# ## [Hoverable or Toggable](https://bulma.io/documentation/components/dropdown/#hoverable-or-toggable)
|
10
|
+
#
|
11
|
+
# By default the dropdown is in Click Mode and assumes a Stimulus controller named `bulma--dropdown` is present to
|
12
|
+
# handle the click events. The controller name can be customized using the `click` option.
|
13
|
+
#
|
14
|
+
# Set click to `false` to make the dropdown hoverable instead of togglable.
|
15
|
+
#
|
16
|
+
# ## Alignment
|
17
|
+
#
|
18
|
+
# Use the `alignment` option to control the dropdown's alignment. By default, it aligns to the left. Pass in
|
19
|
+
# `:right` or `:up` to change the alignment.
|
20
|
+
#
|
21
|
+
# ## Icon
|
22
|
+
#
|
23
|
+
# Use the `icon` option to customize the dropdown's icon. By default, it uses the Font Awesome angle down icon.
|
24
|
+
#
|
25
|
+
# ## Example
|
26
|
+
#
|
27
|
+
# ```ruby
|
28
|
+
# render Components::Bulma::Dropdown.new("Next Actions...") do |dropdown|
|
29
|
+
# dropdown.link "View Profile", "/profile"
|
30
|
+
# dropdown.link "Go to Settings", "/settings"
|
31
|
+
# dropdown.divider
|
32
|
+
# dropdown.item("This is just a text item")
|
33
|
+
# dropdown.item do
|
34
|
+
# div(class: "has-text-weight-bold") { "This is a bold item" }
|
35
|
+
# end
|
36
|
+
# end
|
37
|
+
# ```
|
38
|
+
#
|
39
|
+
class Dropdown < Components::Bulma::Base
|
40
|
+
def initialize(label, click: "bulma--dropdown", alignment: "left", icon: "fas fa-angle-down")
|
41
|
+
@label = label
|
42
|
+
@click = click
|
43
|
+
@alignment = alignment
|
44
|
+
@icon = icon
|
45
|
+
end
|
46
|
+
|
47
|
+
def view_template(&)
|
48
|
+
div(class: "dropdown #{"is-hoverable" unless @click} #{alignment_class}".strip, **stimulus_controller) do
|
49
|
+
div(class: "dropdown-trigger") do
|
50
|
+
button(
|
51
|
+
class: "button",
|
52
|
+
aria_haspopup: "true",
|
53
|
+
aria_controls: "dropdown-menu",
|
54
|
+
**stimulus_action
|
55
|
+
) do
|
56
|
+
span { @label }
|
57
|
+
span(class: "icon is-small") do
|
58
|
+
i(class: @icon, aria_hidden: "true")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
div(class: "dropdown-menu", id: "dropdown-menu", role: "menu") do
|
64
|
+
div(class: "dropdown-content", &)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def item(content = nil, &)
|
70
|
+
if block_given?
|
71
|
+
div(class: "dropdown-item", &)
|
72
|
+
else
|
73
|
+
div(class: "dropdown-item") { content }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def link(label, path)
|
78
|
+
a(class: "dropdown-item", href: path) { label }
|
79
|
+
end
|
80
|
+
|
81
|
+
def divider
|
82
|
+
hr(class: "dropdown-divider")
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def alignment_class
|
88
|
+
case @alignment.to_sym
|
89
|
+
when :right
|
90
|
+
"is-right"
|
91
|
+
when :up
|
92
|
+
"is-up"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def stimulus_controller
|
97
|
+
return {} unless @click
|
98
|
+
|
99
|
+
{ data: { controller: @click } }
|
100
|
+
end
|
101
|
+
|
102
|
+
def stimulus_action
|
103
|
+
return {} unless @click
|
104
|
+
|
105
|
+
{ data: { action: "#{@click}#toggle" } }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -30,7 +30,8 @@ module Components
|
|
30
30
|
Tab = Data.define(:id, :title, :icon, :active)
|
31
31
|
Content = Data.define(:id, :block, :active)
|
32
32
|
|
33
|
-
def initialize
|
33
|
+
def initialize(stimulus_controller: "bulma--tabs")
|
34
|
+
@stimulus_controller = stimulus_controller
|
34
35
|
@tabs = []
|
35
36
|
@contents = []
|
36
37
|
end
|
@@ -43,15 +44,16 @@ module Components
|
|
43
44
|
def view_template(&)
|
44
45
|
vanish(&)
|
45
46
|
|
46
|
-
div(data: { controller:
|
47
|
+
div(data: { controller: @stimulus_controller }) do
|
47
48
|
div(class: "tabs is-boxed") do
|
48
49
|
ul do
|
49
50
|
@tabs.each do |tab|
|
50
51
|
li(
|
52
|
+
id: "#{tab.id}-tab",
|
51
53
|
data: {
|
52
|
-
|
54
|
+
target_key => "tab",
|
53
55
|
tab_content: tab.id,
|
54
|
-
action: "click
|
56
|
+
action: "click->#{@stimulus_controller}#showTabContent"
|
55
57
|
},
|
56
58
|
class: tab.active ? "is-active" : ""
|
57
59
|
) do
|
@@ -66,13 +68,19 @@ module Components
|
|
66
68
|
|
67
69
|
@contents.each do |content|
|
68
70
|
div(id: content.id,
|
69
|
-
class: content.active ? "" : "hidden",
|
70
|
-
data: {
|
71
|
+
class: content.active ? "" : "is-hidden",
|
72
|
+
data: { target_key => "content" }) do
|
71
73
|
content.block.call
|
72
74
|
end
|
73
75
|
end
|
74
76
|
end
|
75
77
|
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def target_key
|
82
|
+
"#{@stimulus_controller}-target"
|
83
|
+
end
|
76
84
|
end
|
77
85
|
end
|
78
86
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bulma-phlex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todd Kummer
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- lib/components/bulma.rb
|
95
95
|
- lib/components/bulma/base.rb
|
96
96
|
- lib/components/bulma/card.rb
|
97
|
+
- lib/components/bulma/dropdown.rb
|
97
98
|
- lib/components/bulma/level.rb
|
98
99
|
- lib/components/bulma/navigation_bar.rb
|
99
100
|
- lib/components/bulma/navigation_bar_dropdown.rb
|