anchor_view_components 0.11.3 → 0.12.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/CHANGELOG.md +14 -0
- data/app/components/anchor/action_menu_component.html.erb +15 -23
- data/app/components/anchor/action_menu_component.rb +4 -2
- data/app/components/anchor/anchor_view_components.ts +6 -6
- data/app/components/anchor/popover_component.html.erb +18 -0
- data/app/components/anchor/popover_component.rb +5 -0
- data/app/components/anchor/{action_menu_controller.ts → popover_controller.ts} +1 -4
- data/app/components/anchor/table_component.en.yml +1 -0
- data/app/components/anchor/table_component.html.erb +8 -4
- data/app/components/anchor/table_component.rb +13 -6
- data/app/helpers/anchor/view_helper.rb +8 -0
- data/lib/anchor/view_components/version.rb +1 -1
- data/previews/anchor/table_component_preview.rb +6 -3
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8f0780ee72bc13ea791c529b15bbb6b4ec3318abc7054c9bea275d9e7818682
|
4
|
+
data.tar.gz: 505d4f6138f09dee2ceffdda7d68626ab85726bff41346e24e6c14597eb8198c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a81c2270c9c76ded2106b6184bb84d6dccc786a0ce3b6ea8dd5530f62cb120fc7eef4a1b2b4fdd87c2e8ec0bbcd42fe2822429d66ef7ab15432de2300af35be
|
7
|
+
data.tar.gz: 3125a9b7090de76a6d7d8c97f0cba7507fbc00b796472f04db59f59fd65b74775cd9eef57f4717428c8f5e26cb29aee0f746a3bb8f7eae5c8a23af8084942500
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.12.0 - 2023-09-11
|
4
|
+
|
5
|
+
### Changed
|
6
|
+
- Added a record argument to the TableComponent row link lambda
|
7
|
+
|
8
|
+
|
9
|
+
## 0.11.4 - 2023-09-07
|
10
|
+
|
11
|
+
### Added
|
12
|
+
- PopoverComponent was extracted from ActionMenuComponent
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
- Added optional totals to TableComponent
|
16
|
+
|
3
17
|
## 0.11.3 - 2023-09-06
|
4
18
|
|
5
19
|
### Added
|
@@ -1,25 +1,17 @@
|
|
1
|
-
<%=
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
<%= tag.div(
|
7
|
-
class: class_names(
|
8
|
-
"absolute -left-full -top-full m-0 px-0 py-1 bg-white rounded border border-subdued popover-open:block",
|
9
|
-
menu_classes
|
10
|
-
),
|
11
|
-
data: { action: "toggle->action-menu#positionPopover" },
|
12
|
-
id: menu_id,
|
13
|
-
popover: "auto",
|
14
|
-
) do %>
|
15
|
-
<ul>
|
16
|
-
<% items.each do |item| %>
|
17
|
-
<%= tag.li(
|
18
|
-
item,
|
19
|
-
class: "action-menu-item whitespace-nowrap hover:bg-grey-10",
|
20
|
-
data: { testid: "action-menu-item" }
|
21
|
-
) %>
|
22
|
-
<% end %>
|
23
|
-
</ul>
|
1
|
+
<%= anchor_popover(id: menu_id, classes: class_names("px-0", "py-1", menu_classes)) do |popover| %>
|
2
|
+
<% if show_button? %>
|
3
|
+
<% popover.with_trigger do %>
|
4
|
+
<%= show_button %>
|
5
|
+
<% end %>
|
24
6
|
<% end %>
|
7
|
+
|
8
|
+
<ul>
|
9
|
+
<% items.each do |item| %>
|
10
|
+
<%= tag.li(
|
11
|
+
item,
|
12
|
+
class: "action-menu-item whitespace-nowrap hover:bg-grey-10",
|
13
|
+
data: { testid: "action-menu-item" }
|
14
|
+
) %>
|
15
|
+
<% end %>
|
16
|
+
</ul>
|
25
17
|
<% end %>
|
@@ -2,8 +2,10 @@ module Anchor
|
|
2
2
|
class ActionMenuComponent < Component
|
3
3
|
renders_one :show_button, lambda { |**kwargs|
|
4
4
|
ButtonComponent.new(
|
5
|
-
|
6
|
-
|
5
|
+
**popover_trigger_attributes(
|
6
|
+
popovertarget: menu_id,
|
7
|
+
data: { testid: "action-menu-btn" }
|
8
|
+
),
|
7
9
|
**kwargs
|
8
10
|
)
|
9
11
|
}
|
@@ -1,29 +1,29 @@
|
|
1
1
|
import "@oddbird/popover-polyfill";
|
2
2
|
|
3
|
-
import ActionMenuController from "./action_menu_controller";
|
4
3
|
import AutocompleteController from "./autocomplete_controller";
|
5
4
|
import DialogController from "./dialog_controller";
|
6
5
|
import InvokerController from "./invoker_controller";
|
6
|
+
import PopoverController from "./popover_controller";
|
7
|
+
import Sortable from "stimulus-sortable";
|
7
8
|
import ToastController from "./toast_controller";
|
8
9
|
import ToggleController from "./toggle_controller";
|
9
|
-
import Sortable from "stimulus-sortable";
|
10
10
|
import { Application } from "@hotwired/stimulus";
|
11
11
|
|
12
12
|
export function registerAnchorControllers(application: Application) {
|
13
|
-
application.register("action-menu", ActionMenuController);
|
14
13
|
application.register("autocomplete", AutocompleteController);
|
15
14
|
application.register("dialog", DialogController);
|
16
15
|
application.register("invoker", InvokerController);
|
17
|
-
application.register("
|
16
|
+
application.register("popover", PopoverController);
|
17
|
+
application.register("sortable", Sortable);
|
18
18
|
application.register("toast", ToastController);
|
19
19
|
application.register("toggle", ToggleController);
|
20
20
|
}
|
21
21
|
|
22
22
|
export {
|
23
|
-
ActionMenuController,
|
24
23
|
AutocompleteController,
|
25
24
|
DialogController,
|
26
25
|
InvokerController,
|
26
|
+
PopoverController,
|
27
27
|
ToastController,
|
28
|
-
ToggleController
|
28
|
+
ToggleController,
|
29
29
|
};
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<%= tag.div(
|
2
|
+
class: "contents",
|
3
|
+
data: { controller: "popover" },
|
4
|
+
) do %>
|
5
|
+
<%= trigger if trigger? %>
|
6
|
+
|
7
|
+
<%= tag.div(
|
8
|
+
class: class_names(
|
9
|
+
"absolute -left-full -top-full m-0 bg-white rounded border border-subdued popover-open:block",
|
10
|
+
classes
|
11
|
+
),
|
12
|
+
data: { action: "toggle->popover#positionPopover" },
|
13
|
+
id:,
|
14
|
+
popover: "auto",
|
15
|
+
) do %>
|
16
|
+
<%= content %>
|
17
|
+
<% end %>
|
18
|
+
<% end %>
|
@@ -10,10 +10,7 @@ export default class extends Controller<HTMLDivElement> {
|
|
10
10
|
const popover = event.target;
|
11
11
|
computePosition(this.buttonTarget, popover, {
|
12
12
|
placement: "bottom-start",
|
13
|
-
middleware: [
|
14
|
-
flip(),
|
15
|
-
offset(4),
|
16
|
-
]
|
13
|
+
middleware: [flip(), offset(4)],
|
17
14
|
}).then(({ x, y }) => {
|
18
15
|
Object.assign(popover.style, {
|
19
16
|
left: `${x}px`,
|
@@ -33,7 +33,7 @@
|
|
33
33
|
"pl-8 py-3 pr-2 bg-[url('assets/icons/menu.svg')] bg-[length:16px_16px] bg-[8px_center] bg-no-repeat": sortable? && index.zero?,
|
34
34
|
"px-2 py-3": !sortable? || index.positive?,
|
35
35
|
),
|
36
|
-
data: { testid: "tr-#{model.id}-td-#{
|
36
|
+
data: { testid: "tr-#{model.id}-td-#{column.header.to_s.parameterize}" },
|
37
37
|
) %>
|
38
38
|
<% end
|
39
39
|
end
|
@@ -41,7 +41,11 @@
|
|
41
41
|
end %>
|
42
42
|
</table>
|
43
43
|
|
44
|
-
<% if data.
|
45
|
-
<%= tag.
|
46
|
-
<% end
|
44
|
+
<% if show_total && data.any? %>
|
45
|
+
<%= tag.div total, class: "mt-3 text-base font-semibold" %>
|
46
|
+
<% end %>
|
47
|
+
|
48
|
+
<% if data.empty? %>
|
49
|
+
<%= tag.p empty_message, class: "text-base text-center mt-6", data: { testid: "empty-table-state" } %>
|
50
|
+
<% end %>
|
47
51
|
</div>
|
@@ -1,22 +1,25 @@
|
|
1
1
|
module Anchor
|
2
2
|
class TableComponent < Component
|
3
3
|
renders_many :columns, "ColumnComponent"
|
4
|
-
renders_one :link
|
5
4
|
|
6
|
-
attr_reader :data, :sortable, :caption
|
5
|
+
attr_reader :data, :sortable, :caption, :rows_link_to, :show_total
|
7
6
|
|
8
7
|
def initialize(
|
9
8
|
data:,
|
10
9
|
caption: nil,
|
11
10
|
empty_message: nil,
|
11
|
+
rows_link_to: nil,
|
12
12
|
sort_url: nil,
|
13
|
-
sortable: false
|
13
|
+
sortable: false,
|
14
|
+
show_total: false
|
14
15
|
)
|
15
16
|
@data = data
|
16
17
|
@empty_message = empty_message
|
18
|
+
@rows_link_to = rows_link_to
|
17
19
|
@sortable = sortable
|
18
20
|
@sort_url = sort_url
|
19
21
|
@caption = caption
|
22
|
+
@show_total = show_total
|
20
23
|
|
21
24
|
super
|
22
25
|
end
|
@@ -29,7 +32,7 @@ module Anchor
|
|
29
32
|
|
30
33
|
def row_classes
|
31
34
|
row_classes = %w(border-b focus-within:bg-grey-10)
|
32
|
-
if
|
35
|
+
if rows_link_to.present?
|
33
36
|
row_classes += %w(hover:bg-grey-10 hover:cursor-pointer)
|
34
37
|
end
|
35
38
|
if sortable?
|
@@ -40,8 +43,8 @@ module Anchor
|
|
40
43
|
|
41
44
|
def maybe_link(model, column, index, view_context)
|
42
45
|
value = value_for(model, column)
|
43
|
-
if
|
44
|
-
path =
|
46
|
+
if rows_link_to.present?
|
47
|
+
path = rows_link_to.call(model)
|
45
48
|
if index.zero?
|
46
49
|
text = view_context.link_to(value, path)
|
47
50
|
else
|
@@ -91,6 +94,10 @@ module Anchor
|
|
91
94
|
columns.present?
|
92
95
|
end
|
93
96
|
|
97
|
+
def total
|
98
|
+
t(".total", count: data.size)
|
99
|
+
end
|
100
|
+
|
94
101
|
class ColumnComponent < Anchor::Component
|
95
102
|
attr_reader :header, :value
|
96
103
|
|
@@ -11,6 +11,7 @@ module Anchor
|
|
11
11
|
icon
|
12
12
|
loading_indicator
|
13
13
|
panel
|
14
|
+
popover
|
14
15
|
prose
|
15
16
|
side_nav
|
16
17
|
tab_bar
|
@@ -68,5 +69,12 @@ module Anchor
|
|
68
69
|
|
69
70
|
doc.to_html.html_safe
|
70
71
|
end
|
72
|
+
|
73
|
+
def popover_trigger_attributes(popovertarget:, data: {})
|
74
|
+
{
|
75
|
+
data: { popover_target: "button", **data },
|
76
|
+
popovertarget:,
|
77
|
+
}
|
78
|
+
end
|
71
79
|
end
|
72
80
|
end
|
@@ -14,8 +14,11 @@ module Anchor
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def playground
|
17
|
-
|
18
|
-
|
17
|
+
render Anchor::TableComponent.new(
|
18
|
+
data:,
|
19
|
+
caption: "A demo table",
|
20
|
+
show_total: true
|
21
|
+
) do |table|
|
19
22
|
table.with_column(header: "Id", value: :id)
|
20
23
|
table.with_column(header: "Name", value: -> { _1.name.capitalize })
|
21
24
|
end
|
@@ -41,7 +44,7 @@ module Anchor
|
|
41
44
|
end
|
42
45
|
|
43
46
|
def empty
|
44
|
-
render Anchor::TableComponent.new(data: []) do |table|
|
47
|
+
render Anchor::TableComponent.new(data: [], show_total: true) do |table|
|
45
48
|
table.with_column(header: "Id", value: :id)
|
46
49
|
table.with_column(header: "Name", value: -> { _1.name.capitalize })
|
47
50
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anchor_view_components
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Buoy Software
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -62,7 +62,6 @@ files:
|
|
62
62
|
- app/assets/stylesheets/components/toast.css
|
63
63
|
- app/components/anchor/action_menu_component.html.erb
|
64
64
|
- app/components/anchor/action_menu_component.rb
|
65
|
-
- app/components/anchor/action_menu_controller.ts
|
66
65
|
- app/components/anchor/anchor_view_components.ts
|
67
66
|
- app/components/anchor/autocomplete_component.en.yml
|
68
67
|
- app/components/anchor/autocomplete_component.html.erb
|
@@ -95,6 +94,9 @@ files:
|
|
95
94
|
- app/components/anchor/panel/header_component.rb
|
96
95
|
- app/components/anchor/panel_component.html.erb
|
97
96
|
- app/components/anchor/panel_component.rb
|
97
|
+
- app/components/anchor/popover_component.html.erb
|
98
|
+
- app/components/anchor/popover_component.rb
|
99
|
+
- app/components/anchor/popover_controller.ts
|
98
100
|
- app/components/anchor/prose_component.html.erb
|
99
101
|
- app/components/anchor/prose_component.rb
|
100
102
|
- app/components/anchor/side_nav_component.en.yml
|
@@ -160,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
162
|
- !ruby/object:Gem::Version
|
161
163
|
version: '0'
|
162
164
|
requirements: []
|
163
|
-
rubygems_version: 3.4.
|
165
|
+
rubygems_version: 3.4.10
|
164
166
|
signing_key:
|
165
167
|
specification_version: 4
|
166
168
|
summary: ViewComponents for Buoy’s design system, Anchor
|