atomic_view 0.1.10 → 0.1.11
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/lib/atomic_view/components/navigation_tree_component/item_component.erb +23 -0
- data/lib/atomic_view/components/navigation_tree_component/item_component.rb +54 -0
- data/lib/atomic_view/components/navigation_tree_component.erb +8 -0
- data/lib/atomic_view/components/navigation_tree_component.rb +40 -0
- data/lib/atomic_view/version.rb +1 -1
- metadata +5 -3
- data/lib/atomic_view/components/nav_item_component.erb +0 -6
- data/lib/atomic_view/components/nav_item_component.rb +0 -36
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 205025ff313e6a3303b0b163adb40754247e189320e839fa949cf6c419fd41a8
|
|
4
|
+
data.tar.gz: 8b62841b297e0bb48e4a536e0dd6d74ac3cff1d1aa956975a547012354900bed
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3c79d5697e7eaa4153b7b5b1087f31bc3b3a85032316784329b45ca6c6330f6f706901ffa2d5abf078d4b53d2e3ee2baca1317874fd79d54eac77b74984024e1
|
|
7
|
+
data.tar.gz: f67f35c7dcfc88d43cfd3d716f10bec7ce3c351f556d2c1eb1a3446a8582d85ef0cd4e9af3a2f129507e07d758659267f8253cc6bc6d6622d8e45a8baa844286
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<% if group? %>
|
|
2
|
+
<%= tag.details(**@options.except(:class), open: open?, class: "[&[open]>summary_svg:last-child]:rotate-90") do %>
|
|
3
|
+
<%= tag.summary(class: html_class) do %>
|
|
4
|
+
<% if icon_name.present? %>
|
|
5
|
+
<%= icon(icon_name, options: {class: "size-4 shrink-0"}).to_s.html_safe %>
|
|
6
|
+
<% end %>
|
|
7
|
+
<%= label %>
|
|
8
|
+
<%= icon("chevron-right", options: {class: "ml-auto size-4 shrink-0 transition-transform"}).to_s.html_safe %>
|
|
9
|
+
<% end %>
|
|
10
|
+
<div class="ml-6 mt-1 flex flex-col gap-1">
|
|
11
|
+
<% items.each do |item| %>
|
|
12
|
+
<%= item %>
|
|
13
|
+
<% end %>
|
|
14
|
+
</div>
|
|
15
|
+
<% end %>
|
|
16
|
+
<% else %>
|
|
17
|
+
<%= tag.a(**@options.except(:class), href: href, class: html_class) do %>
|
|
18
|
+
<% if icon_name.present? %>
|
|
19
|
+
<%= icon(icon_name, options: {class: "size-4 shrink-0"}).to_s.html_safe %>
|
|
20
|
+
<% end %>
|
|
21
|
+
<%= label %>
|
|
22
|
+
<% end %>
|
|
23
|
+
<% end %>
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module AtomicView
|
|
4
|
+
module Components
|
|
5
|
+
class NavigationTreeComponent
|
|
6
|
+
# A single NavigationTree row: a link when `href:` is given, or a
|
|
7
|
+
# collapsible disclosure (native `<details>`/`<summary>`, no JS) when
|
|
8
|
+
# it's not -- its own `with_item` children then render nested inside
|
|
9
|
+
# it. Rendered via `NavigationTreeComponent#with_item` -- see
|
|
10
|
+
# `NavigationTreeComponent`'s class docs.
|
|
11
|
+
class ItemComponent < AtomicView::Component
|
|
12
|
+
renders_many :items, "AtomicView::Components::NavigationTreeComponent::ItemComponent"
|
|
13
|
+
|
|
14
|
+
attr_reader :label, :href, :icon_name, :active
|
|
15
|
+
|
|
16
|
+
def initialize(label:, href: nil, icon: nil, active: false, **options)
|
|
17
|
+
super()
|
|
18
|
+
@label = label
|
|
19
|
+
@href = href
|
|
20
|
+
@icon_name = icon
|
|
21
|
+
@active = active
|
|
22
|
+
@options = options
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def group?
|
|
26
|
+
href.nil?
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# A group opens by default when it (or any descendant) is active.
|
|
30
|
+
def open?
|
|
31
|
+
active || items.any? { |item| item.active || item.open? }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def html_class
|
|
35
|
+
class_names(base_classes, group? ? "cursor-pointer list-none" : nil, active ? active_classes : inactive_classes, @options[:class])
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
def base_classes
|
|
41
|
+
"flex items-center gap-2 rounded-btn px-2.5 py-1.5 text-sm font-medium"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def active_classes
|
|
45
|
+
"bg-secondary text-secondary-foreground"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def inactive_classes
|
|
49
|
+
"text-muted-foreground hover:bg-offset hover:text-foreground"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<%= tag.nav(**@options.except(:class), class: container_class) do %>
|
|
2
|
+
<% if label.present? %>
|
|
3
|
+
<div class="px-2.5 pb-1 text-xs font-semibold uppercase tracking-wide text-muted-foreground"><%= label %></div>
|
|
4
|
+
<% end %>
|
|
5
|
+
<% items.each do |item| %>
|
|
6
|
+
<%= item %>
|
|
7
|
+
<% end %>
|
|
8
|
+
<% end %>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module AtomicView
|
|
4
|
+
module Components
|
|
5
|
+
# NavigationTree
|
|
6
|
+
#
|
|
7
|
+
# A sidebar navigation list -- flat links plus collapsible sections with
|
|
8
|
+
# nested sub-items (native `<details>`/`<summary>`, no JS). Each row is a
|
|
9
|
+
# `with_item` slot so items can nest arbitrarily:
|
|
10
|
+
#
|
|
11
|
+
# render(NavigationTreeComponent.new(label: "Products")) do |tree|
|
|
12
|
+
# tree.with_item(label: "Overview", href: "#", icon: "home", active: true)
|
|
13
|
+
#
|
|
14
|
+
# tree.with_item(label: "Connect", icon: "square-3-stack-3d") do |connect|
|
|
15
|
+
# connect.with_item(label: "Overview", href: "#")
|
|
16
|
+
# connect.with_item(label: "Connected accounts", href: "#")
|
|
17
|
+
# end
|
|
18
|
+
# end
|
|
19
|
+
#
|
|
20
|
+
# An item given `href:` renders as a link; an item without `href:` renders
|
|
21
|
+
# as a disclosure (a `<summary>` row with a trailing chevron) whose own
|
|
22
|
+
# `with_item` children render nested inside it once open -- see
|
|
23
|
+
# `ItemComponent` for the per-item API.
|
|
24
|
+
class NavigationTreeComponent < AtomicView::Component
|
|
25
|
+
renders_many :items, "ItemComponent"
|
|
26
|
+
|
|
27
|
+
attr_reader :label
|
|
28
|
+
|
|
29
|
+
def initialize(label: nil, **options)
|
|
30
|
+
super()
|
|
31
|
+
@label = label
|
|
32
|
+
@options = options
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def container_class
|
|
36
|
+
class_names("flex flex-col gap-1", @options[:class])
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
data/lib/atomic_view/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: atomic_view
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.11
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Joel Warrington
|
|
@@ -195,8 +195,10 @@ files:
|
|
|
195
195
|
- lib/atomic_view/components/modal_component.erb
|
|
196
196
|
- lib/atomic_view/components/modal_component.rb
|
|
197
197
|
- lib/atomic_view/components/month_field_component.rb
|
|
198
|
-
- lib/atomic_view/components/
|
|
199
|
-
- lib/atomic_view/components/
|
|
198
|
+
- lib/atomic_view/components/navigation_tree_component.erb
|
|
199
|
+
- lib/atomic_view/components/navigation_tree_component.rb
|
|
200
|
+
- lib/atomic_view/components/navigation_tree_component/item_component.erb
|
|
201
|
+
- lib/atomic_view/components/navigation_tree_component/item_component.rb
|
|
200
202
|
- lib/atomic_view/components/number_field_component.rb
|
|
201
203
|
- lib/atomic_view/components/pagination_component.erb
|
|
202
204
|
- lib/atomic_view/components/pagination_component.rb
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module AtomicView
|
|
4
|
-
module Components
|
|
5
|
-
class NavItemComponent < AtomicView::Component
|
|
6
|
-
attr_reader :label, :href, :icon_name, :active
|
|
7
|
-
|
|
8
|
-
def initialize(label:, href:, icon: nil, active: false, **options)
|
|
9
|
-
super()
|
|
10
|
-
@label = label
|
|
11
|
-
@href = href
|
|
12
|
-
@icon_name = icon
|
|
13
|
-
@active = active
|
|
14
|
-
@options = options
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
private
|
|
18
|
-
|
|
19
|
-
def html_class
|
|
20
|
-
class_names(base_classes, active ? active_classes : inactive_classes, @options[:class])
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def base_classes
|
|
24
|
-
"flex items-center gap-2 rounded-btn px-2.5 py-1.5 text-sm font-medium"
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def active_classes
|
|
28
|
-
"bg-secondary text-secondary-foreground"
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def inactive_classes
|
|
32
|
-
"text-muted-foreground hover:bg-offset hover:text-foreground"
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|