openproject-primer_view_components 0.66.2 → 0.67.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 (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/app/assets/javascripts/components/primer/open_project/tree_view/tree_view.d.ts +2 -0
  4. data/app/assets/javascripts/primer_view_components.js +1 -1
  5. data/app/assets/javascripts/primer_view_components.js.map +1 -1
  6. data/app/assets/styles/primer_view_components.css +1 -1
  7. data/app/assets/styles/primer_view_components.css.map +1 -1
  8. data/app/components/primer/open_project/border_box/collapsible_header.rb +3 -0
  9. data/app/components/primer/open_project/collapsible_section.rb +7 -1
  10. data/app/components/primer/open_project/tree_view/node.html.erb +2 -2
  11. data/app/components/primer/open_project/tree_view/node.rb +49 -26
  12. data/app/components/primer/open_project/tree_view/skeleton_loader.html.erb +1 -1
  13. data/app/components/primer/open_project/tree_view/spinner_loader.html.erb +2 -2
  14. data/app/components/primer/open_project/tree_view/sub_tree.html.erb +1 -1
  15. data/app/components/primer/open_project/tree_view/sub_tree.rb +8 -1
  16. data/app/components/primer/open_project/tree_view/sub_tree_node.rb +9 -3
  17. data/app/components/primer/open_project/tree_view/tree_view.d.ts +2 -0
  18. data/app/components/primer/open_project/tree_view/tree_view.js +29 -9
  19. data/app/components/primer/open_project/tree_view/tree_view.ts +31 -10
  20. data/app/components/primer/open_project/tree_view/tree_view_roving_tab_index.js +11 -7
  21. data/app/components/primer/open_project/tree_view/tree_view_roving_tab_index.ts +13 -8
  22. data/app/components/primer/open_project/tree_view/tree_view_sub_tree_node_element.js +38 -21
  23. data/app/components/primer/open_project/tree_view/tree_view_sub_tree_node_element.ts +42 -20
  24. data/app/components/primer/open_project/tree_view.css +1 -1
  25. data/app/components/primer/open_project/tree_view.css.json +9 -6
  26. data/app/components/primer/open_project/tree_view.css.map +1 -1
  27. data/app/components/primer/open_project/tree_view.pcss +53 -38
  28. data/app/components/primer/open_project/tree_view.rb +88 -24
  29. data/lib/primer/view_components/version.rb +2 -2
  30. data/previews/primer/open_project/border_box/collapsible_header_preview/playground.html.erb +1 -1
  31. data/previews/primer/open_project/tree_view_preview/buttons.html.erb +10 -0
  32. data/previews/primer/open_project/tree_view_preview/links.html.erb +17 -0
  33. data/previews/primer/open_project/tree_view_preview.rb +29 -3
  34. data/static/arguments.json +38 -2
  35. data/static/constants.json +17 -0
  36. data/static/info_arch.json +95 -3
  37. data/static/previews.json +26 -0
  38. metadata +4 -2
@@ -17,23 +17,27 @@
17
17
  # <ul role="tree">
18
18
  # <LeafNode>
19
19
  # <Node>
20
- # <li role="treeitem">
21
- # ...
20
+ # <li role="none">
21
+ # <div role="treeitem">
22
+ # ...
23
+ # </div>
22
24
  # </li>
23
25
  # </Node>
24
26
  # </LeafNode>
25
27
  #
26
28
  # <SubTreeNode>
27
29
  # <tree-view-sub-tree-node>
28
- # <li role="treeitem">
30
+ # <li role="none">
29
31
  #
30
32
  # <SubTreeContainer>
31
33
  # <ul role="group">
32
34
  # <SubTree>
33
35
  # <LeafNode>
34
36
  # <Node>
35
- # <li role="treeitem">
36
- # ...
37
+ # <li role="none">
38
+ # <div role="treeitem">
39
+ # ...
40
+ # </div>
37
41
  # </li>
38
42
  # </Node>
39
43
  # </LeafNode>
@@ -41,8 +45,10 @@
41
45
  # <SubTreeNode>
42
46
  # <tree-view-sub-tree-node>
43
47
  # <Node>
44
- # <li role="treeitem">
45
- # ...
48
+ # <li role="none">
49
+ # <div role="treeitem">
50
+ # ...
51
+ # </div>
46
52
  # </li>
47
53
  # </Node>
48
54
  # <SubTreeContainer>
@@ -72,19 +78,21 @@
72
78
  #
73
79
  # <LeafNode>
74
80
  # <Node>
75
- # <li role="treeitem">
76
- # <Visual>
77
- # <IconPair>
78
- # <tree-view-icon-pair>
79
- # <Icon slot="expanded_icon">
80
- # <Primer::Beta::Octicon />
81
- # </Icon>
82
- # <Icon slot="collapsed_icon">
83
- # <Primer::Beta::Octicon />
84
- # </Icon>
85
- # </tree-view-icon-pair>
86
- # </IconPair>
87
- # </Visual>
81
+ # <li role="none">
82
+ # <div role="treeitem">
83
+ # <Visual>
84
+ # <IconPair>
85
+ # <tree-view-icon-pair>
86
+ # <Icon slot="expanded_icon">
87
+ # <Primer::Beta::Octicon />
88
+ # </Icon>
89
+ # <Icon slot="collapsed_icon">
90
+ # <Primer::Beta::Octicon />
91
+ # </Icon>
92
+ # </tree-view-icon-pair>
93
+ # </IconPair>
94
+ # </Visual>
95
+ # </div>
88
96
  # </li>
89
97
  # </Node>
90
98
  # </LeafNode>
@@ -207,7 +215,7 @@ module Primer
207
215
  # Render a `Primer::OpenProject::TreeView::SubTree` in the action's template, tree_view_items/show.html_fragment.erb:
208
216
  #
209
217
  # ```erb
210
- # <%= render(Primer::OpenProject::TreeView::SubTree.new(path: @path)) do |tree| %>
218
+ # <%= render(Primer::OpenProject::TreeView::SubTree.new(path: @path, node_variant: :div)) do |tree| %>
211
219
  # <% tree.with_leaf(...) %>
212
220
  # <% tree.with_sub_tree(...) do |sub_tree| %>
213
221
  # ...
@@ -215,7 +223,53 @@ module Primer
215
223
  # <% end %>
216
224
  # ```
217
225
  #
218
- # ### JavaScript API
226
+ # ## Multi-select mode
227
+ #
228
+ # Passing `select_variant: :multiple` to both sub-tree and leaf nodes will add a check box to the left of the node's
229
+ # label. These check boxes behave according to the value of a second argument, `select_strategy:`.
230
+ #
231
+ # The default select strategy, `:descendants`, will cause all child nodes to be checked when the node is checked.
232
+ # This includes both sub-tree and leaf nodes. When the node is unchecked, all child nodes will also be unchecked.
233
+ # Unchecking a child node of a checked parent will cause the parent to enter a mixed or indeterminate state, which
234
+ # is represented by a horizontal line icon instead of a check mark. This icon indicates that some children are
235
+ # checked, but not all.
236
+ #
237
+ # A secondary select strategy, `:self`, is provided to allow disabling the automatic checking of child nodes. When
238
+ # `select_strategy: :self` is specified, checking sub-tree nodes does not check child nodes, and sub-tree nodes
239
+ # cannot enter a mixed or indeterminate state.
240
+ #
241
+ # Nodes can be checked via the keyboard by pressing the space key.
242
+ #
243
+ # ## Node tags
244
+ #
245
+ # `TreeView`s support three different node variants, `:anchor`, `:button`, and `:div` (the default), which controls
246
+ # which HTML tag is used to construct the nodes. The `:anchor` and `:button` variants correspond to `<a>` and
247
+ # `<button>` tags respectively, which are browser-native elements. Anchors and buttons can be activated (i.e.
248
+ # "clicked") using the mouse or keyboard via the enter or space keys. The node variant must be the same for all
249
+ # nodes in the tree, and is therefore specified at the root level, eg. `TreeView.new(node_variant: :anchor)`.
250
+ #
251
+ # Trees with node variants other than `:div` cannot have check boxes, i.e. cannot be put into multi-select mode.
252
+ #
253
+ # Trees with node variants other than `:div` do not emit the `treeViewNodeActivated` or `treeViewBeforeNodeActivated`
254
+ # events, since it is assumed any behavior associated with these variants is user- or browser-defined.
255
+ #
256
+ # ## Interaction behavior matrix
257
+ #
258
+ # |Interaction |Select variant|Tag |Result |
259
+ # |:---------------|:-------------|:------------|:--------------------------|
260
+ # |Enter/space |none |div |Expands/collapses |
261
+ # |Enter/space |none |anchor/button|Activates anchor/button |
262
+ # |Enter/space |multiple |div |Checks or unchecks |
263
+ # |Enter/space |multiple |anchor/button|N/A (not allowed) |
264
+ # |Left/right arrow|none |div |Expands/collapses |
265
+ # |Left/right arrow|none |anchor/button|Expands/collapses |
266
+ # |Left/right arrow|multiple |div |Expands/collapses |
267
+ # |Left/right arrow|multiple |anchor/button|N/A (not allowed) |
268
+ # |Click |none |div |Expands/collapses |
269
+ # |Click |multiple |div |Checks or unchecks |
270
+ # |Click |multiple |anchor/button|N/A (not allowed) |
271
+ #
272
+ # ## JavaScript API
219
273
  #
220
274
  # `TreeView`s render a `<tree-view>` custom element that exposes behavior to the client.
221
275
  #
@@ -237,7 +291,7 @@ module Primer
237
291
  # |`leafAtPath(path: string[]): HTMLLIElement | null` |Returns the leaf node at the given `path`, if it exists. |
238
292
  # |`getNodeCheckedValue(node: Element): TreeViewCheckedValue` |The same as `checkedValueAtPath`, but accepts a node instead of a path. |
239
293
  #
240
- # #### Events
294
+ # ### Events
241
295
  #
242
296
  # The events enumerated below include node information by way of the `TreeViewNodeInfo` object, which has the
243
297
  # following signature:
@@ -301,6 +355,9 @@ module Primer
301
355
  # both the `treeViewNodeChecked` and `treeViewBeforeNodeChecked` events provide an array of `TreeViewNodeInfo`
302
356
  # objects, which contain entries for every modified node in the tree.
303
357
  class TreeView < Primer::Component
358
+ DEFAULT_NODE_VARIANT = :div
359
+ NODE_VARIANT_OPTIONS = [DEFAULT_NODE_VARIANT, :anchor, :button].freeze
360
+
304
361
  # @!parse
305
362
  # # Adds an leaf node to the tree. Leaf nodes are nodes that do not have children.
306
363
  # #
@@ -322,6 +379,7 @@ module Primer
322
379
  renders: lambda { |component_klass: LeafNode, label:, **system_arguments|
323
380
  component_klass.new(
324
381
  **system_arguments,
382
+ node_variant: node_variant,
325
383
  path: [label],
326
384
  label: label
327
385
  )
@@ -334,6 +392,7 @@ module Primer
334
392
  renders: lambda { |component_klass: SubTreeNode, label:, **system_arguments|
335
393
  component_klass.new(
336
394
  **system_arguments,
395
+ node_variant: node_variant,
337
396
  path: [label],
338
397
  label: label
339
398
  )
@@ -343,10 +402,15 @@ module Primer
343
402
  }
344
403
  }
345
404
 
405
+ attr_reader :node_variant
406
+
407
+ # @param node_variant [Symbol] The variant to use for this node. <%= one_of(Primer::OpenProject::TreeView::NODE_VARIANT_OPTIONS) %>
346
408
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>.
347
- def initialize(**system_arguments)
409
+ def initialize(node_variant: DEFAULT_NODE_VARIANT, **system_arguments)
348
410
  @system_arguments = deny_tag_argument(**system_arguments)
349
411
 
412
+ @node_variant = fetch_or_fallback(NODE_VARIANT_OPTIONS, node_variant, DEFAULT_NODE_VARIANT)
413
+
350
414
  @system_arguments[:tag] = :ul
351
415
  @system_arguments[:role] = :tree
352
416
  @system_arguments[:classes] = class_names(
@@ -5,8 +5,8 @@ module Primer
5
5
  module ViewComponents
6
6
  module VERSION
7
7
  MAJOR = 0
8
- MINOR = 66
9
- PATCH = 2
8
+ MINOR = 67
9
+ PATCH = 0
10
10
 
11
11
  STRING = [MAJOR, MINOR, PATCH].join(".")
12
12
  end
@@ -4,7 +4,7 @@
4
4
  collapsed: collapsed)) do |header| %>
5
5
  <% header.with_title { title } %>
6
6
  <% header.with_count(count: count) %>
7
- <% header.with_description { description } %>
7
+ <% header.with_description { description } unless description.nil? %>
8
8
  <% end %>
9
9
  <% end %>
10
10
  <% component.with_body { "Body" } %>
@@ -0,0 +1,10 @@
1
+ <div style="max-width: 400px">
2
+ <%= render(Primer::OpenProject::TreeView.new(node_variant: :button)) do |tree_view| %>
3
+ <% tree_view.with_sub_tree(label: "Secrets", expanded: expanded, onclick: "alert('Shhhh')") do |sub_tree| %>
4
+ <% sub_tree.with_leaf(label: "Life and the universe", onclick: "alert(42)") %>
5
+ <% sub_tree.with_leaf(label: "Secret ingredient", onclick: "alert('Love')") %>
6
+ <% end %>
7
+
8
+ <% tree_view.with_leaf(label: "What do you give a sick bird?", onclick: "alert('Tweetment')") %>
9
+ <% end %>
10
+ </div>
@@ -0,0 +1,17 @@
1
+ <div style="max-width: 400px">
2
+ <%= render(Primer::OpenProject::TreeView.new(node_variant: :anchor)) do |tree_view| %>
3
+ <% tree_view.with_sub_tree(label: "Cloud Services", href: "https://en.wikipedia.org/wiki/Cloud_computing", target: "blank", expanded: expanded) do |sub_tree| %>
4
+ <% sub_tree.with_leaf(label: "OpenProject", href: "https://www.openproject.org", target: "blank") do |node| %>
5
+ <% node.with_trailing_visual_icon(icon: :"link-external") %>
6
+ <% end %>
7
+
8
+ <% sub_tree.with_leaf(label: "Hetzner", href: "https://www.hetzner.com", target: "blank") do |node| %>
9
+ <% node.with_trailing_visual_icon(icon: :"link-external") %>
10
+ <% end %>
11
+ <% end %>
12
+
13
+ <% tree_view.with_leaf(label: "GitHub", href: "https://github.com", target: "blank") do |node| %>
14
+ <% node.with_trailing_visual_icon(icon: :"link-external") %>
15
+ <% end %>
16
+ <% end %>
17
+ </div>
@@ -10,7 +10,11 @@ module Primer
10
10
  # @param expanded [Boolean] toggle
11
11
  # @param select_variant [Symbol] select [multiple, none]
12
12
  # @param select_strategy [Symbol] select [self, descendants]
13
- def default(expanded: false, select_variant: :none, select_strategy: :descendants)
13
+ def default(
14
+ expanded: false,
15
+ select_variant: Primer::OpenProject::TreeView::Node::DEFAULT_SELECT_VARIANT,
16
+ select_strategy: Primer::OpenProject::TreeView::SubTreeNode::DEFAULT_SELECT_STRATEGY
17
+ )
14
18
  render_with_template(locals: {
15
19
  expanded: coerce_bool(expanded),
16
20
  select_variant: select_variant.to_sym,
@@ -23,7 +27,11 @@ module Primer
23
27
  # @param expanded [Boolean] toggle
24
28
  # @param select_variant [Symbol] select [multiple, none]
25
29
  # @param select_strategy [Symbol] select [self, descendants]
26
- def playground(expanded: false, select_variant: :none, select_strategy: :descendants)
30
+ def playground(
31
+ expanded: false,
32
+ select_variant: Primer::OpenProject::TreeView::Node::DEFAULT_SELECT_VARIANT,
33
+ select_strategy: Primer::OpenProject::TreeView::SubTreeNode::DEFAULT_SELECT_STRATEGY
34
+ )
27
35
  render_with_template(locals: {
28
36
  expanded: coerce_bool(expanded),
29
37
  select_variant: select_variant.to_sym,
@@ -80,7 +88,7 @@ module Primer
80
88
  leading_visual_icon: nil,
81
89
  leading_action_icon: nil,
82
90
  trailing_visual_icon: nil,
83
- select_variant: :none
91
+ select_variant: Primer::OpenProject::TreeView::Node::DEFAULT_SELECT_VARIANT
84
92
  )
85
93
  render_with_template(locals: {
86
94
  label: label,
@@ -91,6 +99,24 @@ module Primer
91
99
  })
92
100
  end
93
101
 
102
+ # @label Links
103
+ #
104
+ # @param expanded [Boolean] toggle
105
+ def links(expanded: false)
106
+ render_with_template(locals: {
107
+ expanded: coerce_bool(expanded)
108
+ })
109
+ end
110
+
111
+ # @label Buttons
112
+ #
113
+ # @param expanded [Boolean] toggle
114
+ def buttons(expanded: false)
115
+ render_with_template(locals: {
116
+ expanded: coerce_bool(expanded)
117
+ })
118
+ end
119
+
94
120
  private
95
121
 
96
122
  def coerce_bool(value)
@@ -5419,6 +5419,12 @@
5419
5419
  "source": "https://github.com/primer/view_components/tree/main/app/components/primer/open_project/file_tree_view.rb",
5420
5420
  "lookbook": "https://primer.style/view-components/lookbook/inspect/primer/open_project/file_tree_view/default/",
5421
5421
  "parameters": [
5422
+ {
5423
+ "name": "node_variant",
5424
+ "type": "Symbol",
5425
+ "default": "`:div`",
5426
+ "description": "The variant to use for this node. One of `:anchor`, `:button`, or `:div`."
5427
+ },
5422
5428
  {
5423
5429
  "name": "system_arguments",
5424
5430
  "type": "Hash",
@@ -5844,6 +5850,12 @@
5844
5850
  "source": "https://github.com/primer/view_components/tree/main/app/components/primer/open_project/tree_view.rb",
5845
5851
  "lookbook": "https://primer.style/view-components/lookbook/inspect/primer/open_project/tree_view/default/",
5846
5852
  "parameters": [
5853
+ {
5854
+ "name": "node_variant",
5855
+ "type": "Symbol",
5856
+ "default": "`:div`",
5857
+ "description": "The variant to use for this node. One of `:anchor`, `:button`, or `:div`."
5858
+ },
5847
5859
  {
5848
5860
  "name": "system_arguments",
5849
5861
  "type": "Hash",
@@ -5970,6 +5982,18 @@
5970
5982
  "default": "N/A",
5971
5983
  "description": "The node's \"path,\" i.e. this node's label and the labels of all its ancestors. This node should be reachable by traversing the tree following this path."
5972
5984
  },
5985
+ {
5986
+ "name": "node_variant",
5987
+ "type": "Symbol",
5988
+ "default": "N/A",
5989
+ "description": "The node variant to use for the node's content, i.e. the `:button` or `:div`. One of `:anchor`, `:button`, or `:div`."
5990
+ },
5991
+ {
5992
+ "name": "href",
5993
+ "type": "String",
5994
+ "default": "`nil`",
5995
+ "description": "The URL to use as the `href` attribute for this node. If set to a truthy value, the `tag:` parameter is ignored and assumed to be `:a`."
5996
+ },
5973
5997
  {
5974
5998
  "name": "current",
5975
5999
  "type": "Boolean",
@@ -5989,10 +6013,10 @@
5989
6013
  "description": "The checked state of the node's checkbox. One of `false`, `mixed`, or `true`."
5990
6014
  },
5991
6015
  {
5992
- "name": "system_arguments",
6016
+ "name": "content_arguments",
5993
6017
  "type": "Hash",
5994
6018
  "default": "N/A",
5995
- "description": "The arguments accepted by [ActionList](/components/alpha/actionlist)."
6019
+ "description": "Arguments attached to the node's content, i.e the `<button>` or `<a>` element. [System arguments](/system-arguments)"
5996
6020
  }
5997
6021
  ]
5998
6022
  },
@@ -6054,6 +6078,12 @@
6054
6078
  "source": "https://github.com/primer/view_components/tree/main/app/components/primer/open_project/tree_view/sub_tree.rb",
6055
6079
  "lookbook": "https://primer.style/view-components/lookbook/inspect/primer/open_project/tree_view/sub_tree/default/",
6056
6080
  "parameters": [
6081
+ {
6082
+ "name": "node_variant",
6083
+ "type": "Symbol",
6084
+ "default": "N/A",
6085
+ "description": "The variant to use for this node. One of `:anchor`, `:button`, or `:div`."
6086
+ },
6057
6087
  {
6058
6088
  "name": "system_arguments",
6059
6089
  "type": "Hash",
@@ -6110,6 +6140,12 @@
6110
6140
  "default": "N/A",
6111
6141
  "description": "The node's \"path,\" i.e. this node's label and the labels of all its ancestors. This node should be reachable by traversing the tree following this path."
6112
6142
  },
6143
+ {
6144
+ "name": "node_variant",
6145
+ "type": "Symbol",
6146
+ "default": "N/A",
6147
+ "description": "The variant to use for this node. One of `:anchor`, `:button`, or `:div`."
6148
+ },
6113
6149
  {
6114
6150
  "name": "expanded",
6115
6151
  "type": "Boolean",
@@ -1786,12 +1786,18 @@
1786
1786
  "GeneratedSlotMethods": "Primer::OpenProject::SubHeader::SegmentedControl::GeneratedSlotMethods"
1787
1787
  },
1788
1788
  "Primer::OpenProject::TreeView": {
1789
+ "DEFAULT_NODE_VARIANT": "div",
1789
1790
  "GeneratedSlotMethods": "Primer::OpenProject::TreeView::GeneratedSlotMethods",
1790
1791
  "Icon": "Primer::OpenProject::TreeView::Icon",
1791
1792
  "IconPair": "Primer::OpenProject::TreeView::IconPair",
1792
1793
  "LeadingAction": "Primer::OpenProject::TreeView::LeadingAction",
1793
1794
  "LeafNode": "Primer::OpenProject::TreeView::LeafNode",
1794
1795
  "LoadingFailureMessage": "Primer::OpenProject::TreeView::LoadingFailureMessage",
1796
+ "NODE_VARIANT_OPTIONS": [
1797
+ "div",
1798
+ "anchor",
1799
+ "button"
1800
+ ],
1795
1801
  "Node": "Primer::OpenProject::TreeView::Node",
1796
1802
  "SkeletonLoader": "Primer::OpenProject::TreeView::SkeletonLoader",
1797
1803
  "SpinnerLoader": "Primer::OpenProject::TreeView::SpinnerLoader",
@@ -1824,8 +1830,19 @@
1824
1830
  "mixed"
1825
1831
  ],
1826
1832
  "DEFAULT_CHECKED_STATE": false,
1833
+ "DEFAULT_NODE_VARIANT": "div",
1827
1834
  "DEFAULT_SELECT_VARIANT": "none",
1828
1835
  "GeneratedSlotMethods": "Primer::OpenProject::TreeView::Node::GeneratedSlotMethods",
1836
+ "NODE_VARIANT_TAG_MAP": {
1837
+ "div": "div",
1838
+ "button": "button",
1839
+ "anchor": "a"
1840
+ },
1841
+ "NODE_VARIANT_TAG_OPTIONS": [
1842
+ "div",
1843
+ "button",
1844
+ "anchor"
1845
+ ],
1829
1846
  "SELECT_VARIANT_OPTIONS": [
1830
1847
  "multiple",
1831
1848
  "none"
@@ -18761,6 +18761,12 @@
18761
18761
  "source": "https://github.com/primer/view_components/tree/main/app/components/primer/open_project/file_tree_view.rb",
18762
18762
  "lookbook": "https://primer.style/view-components/lookbook/inspect/primer/open_project/file_tree_view/default/",
18763
18763
  "parameters": [
18764
+ {
18765
+ "name": "node_variant",
18766
+ "type": "Symbol",
18767
+ "default": "`:div`",
18768
+ "description": "The variant to use for this node. One of `:anchor`, `:button`, or `:div`."
18769
+ },
18764
18770
  {
18765
18771
  "name": "system_arguments",
18766
18772
  "type": "Hash",
@@ -20446,7 +20452,7 @@
20446
20452
  },
20447
20453
  {
20448
20454
  "fully_qualified_name": "Primer::OpenProject::TreeView",
20449
- "description": "TreeView is a hierarchical list of items that may have a parent-child relationship where children\ncan be toggled into view by expanding or collapsing their parent item.\n\n## Terminology\n\nConsider the following tree structure:\n\nsrc\n├ button.rb\n└ action_list\n ├ item.rb\n └ header.rb\n\n1. **Node**. A node is an item in the tree. Nodes can either be \"leaf\" nodes (i.e. have no children), or \"sub-tree\"\nnodes, which do have children. In the example above, button.rb, item.rb, and header.rb are all leaf nodes, while\naction_list is a sub-tree node.\n2. **Path**. A node's path is like its ID. It's an array of strings containing the current node's label and all the\nlabels of its ancestors, in order. In the example above, header.rb's path is [\"src\", \"action_list\", \"header.rb\"].\n\n## Static nodes\n\nThe `TreeView` component allows items to be provided statically or loaded dynamically from the server.\nProviding items statically is done using the `leaf` and `sub_tree` slots:\n\n```erb\n<%= render(Primer::OpenProject::TreeView.new) do |tree| %>\n <% tree.with_sub_tree(label: \"Directory\") do |sub_tree| %>\n <% sub_tree.with_leaf(label: \"File 1\")\n <% end %>\n <% tree.with_leaf(label: \"File 2\") %>\n<% end %>\n```\n\n## Dynamic nodes\n\nTree nodes can also be fetched dynamically from the server and will require creating a Rails controller action\nto respond with the list of nodes. Unlike other Primer components, `TreeView` allows the programmer to specify\nloading behavior on a per-sub-tree basis, i.e. each sub-tree must specify how its nodes are loaded. To load nodes\ndynamically for a given sub-tree, configure it with either a loading spinner or a loading skeleton, and provide\nthe URL to fetch nodes from:\n\n```erb\n<%= render(Primer::OpenProject::TreeView.new) do |tree| %>\n <% tree.with_sub_tree(label: \"Directory\") do |sub_tree| %>\n <% sub_tree.with_loading_spinner(src: tree_view_items_path) %>\n <% end %>\n<% end %>\n```\n\nDefine a controller action to serve the list of nodes. The `TreeView` component automatically includes the\nsub-tree's path as a GET parameter, encoded as a JSON array.\n\n```ruby\nclass TreeViewItemsController < ApplicationController\n def show\n @path = JSON.parse(params[:path])\n @results = get_tree_items(starting_at: path)\n end\nend\n```\n\nResponses must be HTML fragments, eg. have a content type of `text/html+fragment`. This content type isn't\navailable by default in Rails, so you may have to register it eg. in an initializer:\n\n```ruby\nMime::Type.register(\"text/fragment+html\", :html_fragment)\n```\n\nRender a `Primer::OpenProject::TreeView::SubTree` in the action's template, tree_view_items/show.html_fragment.erb:\n\n```erb\n<%= render(Primer::OpenProject::TreeView::SubTree.new(path: @path)) do |tree| %>\n <% tree.with_leaf(...) %>\n <% tree.with_sub_tree(...) do |sub_tree| %>\n ...\n <% end %>\n<% end %>\n```\n\n### JavaScript API\n\n`TreeView`s render a `<tree-view>` custom element that exposes behavior to the client.\n\n|Name |Notes |\n|:-----------------------------------------------------------------|:-------------------------------------------------------------------------------------------------------------------------------------------------|\n|`getNodePath(node: Element): string[]` |Returns the path to the given node. |\n|`getNodeType(node: Element): TreeViewNodeType | null` |Returns either `\"leaf\"` or `\"sub-tree\"`. |\n|`markCurrentAtPath(path: string[])` |Marks the node as the \"current\" node, which appears visually distinct from other nodes. |\n|`get currentNode(): HTMLLIElement | null` |Returns the current node. |\n|`expandAtPath(path: string[])` |Expands the sub-tree at `path`. |\n|`collapseAtPath(path: string[])` |Collapses the sub-tree at `path`. |\n|`toggleAtPath(path: string[])` |If the sub-tree at `path` is collapsed, this function expands it, and vice-versa. |\n|`checkAtPath(path: string[])` |If the node at `path` has a checkbox, this function checks it. |\n|`uncheckAtPath(path: string[])` |If the node at `path` has a checkbox, this function unchecks it. |\n|`toggleCheckedAtPath(path: string[])` |If the sub-tree at `path` is checked, this function unchecks it, and vice-versa. |\n|`checkedValueAtPath(path: string[]): TreeViewCheckedValue` |Returns `\"true\"` (all child nodes are checked), `\"false\"` (no child nodes are checked), or `\"mixed\"` (some child nodes are checked, some are not).|\n|`nodeAtPath(path: string[], selector?: string): Element | null` |Returns the node for the given `path`, either a leaf node or sub-tree node. |\n|`subTreeAtPath(path: string[]): TreeViewSubTreeNodeElement | null`|Returns the sub-tree at the given `path`, if it exists. |\n|`leafAtPath(path: string[]): HTMLLIElement | null` |Returns the leaf node at the given `path`, if it exists. |\n|`getNodeCheckedValue(node: Element): TreeViewCheckedValue` |The same as `checkedValueAtPath`, but accepts a node instead of a path. |\n\n#### Events\n\nThe events enumerated below include node information by way of the `TreeViewNodeInfo` object, which has the\nfollowing signature:\n\n```typescript\ntype TreeViewNodeType = 'leaf' | 'sub-tree'\ntype TreeViewCheckedValue = 'true' | 'false' | 'mixed'\n\ntype TreeViewNodeInfo = {\n node: Element\n type: TreeViewNodeType\n path: string[]\n checkedValue: TreeViewCheckedValue\n previousCheckedValue: TreeViewCheckedValue\n}\n```\n\n|Name |Type |Bubbles |Cancelable |\n|:----------------------------|:------------------------------------------|:-------|:----------|\n|`treeViewNodeActivated` |`CustomEvent<TreeViewNodeInfo>` |Yes |No |\n|`treeViewBeforeNodeActivated`|`CustomEvent<TreeViewNodeInfo>` |Yes |Yes |\n|`treeViewNodeExpanded` |`CustomEvent<TreeViewNodeInfo>>` |Yes |No |\n|`treeViewNodeCollapsed` |`CustomEvent<TreeViewNodeInfo>>` |Yes |No |\n|`treeViewNodeChecked` |`CustomEvent<TreeViewNodeInfo[]>` |Yes |Yes |\n|`treeViewBeforeNodeChecked` |`CustomEvent<TreeViewNodeInfo[]>` |Yes |No |\n\n_Item activation_\n\nThe `<tree-view>` element fires an `treeViewNodeActivated` event whenever a node is activated (eg. clicked)\nvia the mouse or keyboard.\n\nThe `treeViewBeforeNodeActivated` event fires before a node is activated. Canceling this event will prevent the\nnode from being activated.\n\n```typescript\ndocument.querySelector(\"select-panel\").addEventListener(\n \"treeViewBeforeNodeActivated\",\n (event: CustomEvent<TreeViewNodeInfo>) => {\n event.preventDefault() // Cancel the event to prevent activation (eg. expanding/collapsing)\n }\n)\n```\n\n_Item checking/unchecking_\n\nThe `tree-view` element fires a `treeViewNodeChecked` event whenever a node is checked or unchecked.\n\nThe `treeViewBeforeNodeChecked` event fires before a node is checked or unchecked. Canceling this event will\nprevent the check/uncheck operation.\n\n```typescript\ndocument.querySelector(\"select-panel\").addEventListener(\n \"treeViewBeforeNodeChecked\",\n (event: CustomEvent<TreeViewNodeInfo[]>) => {\n event.preventDefault() // Cancel the event to prevent activation (eg. expanding/collapsing)\n }\n)\n```\n\nBecause checking or unchecking a sub-tree results in the checking or unchecking of all its children recursively,\nboth the `treeViewNodeChecked` and `treeViewBeforeNodeChecked` events provide an array of `TreeViewNodeInfo`\nobjects, which contain entries for every modified node in the tree.",
20455
+ "description": "TreeView is a hierarchical list of items that may have a parent-child relationship where children\ncan be toggled into view by expanding or collapsing their parent item.\n\n## Terminology\n\nConsider the following tree structure:\n\nsrc\n├ button.rb\n└ action_list\n ├ item.rb\n └ header.rb\n\n1. **Node**. A node is an item in the tree. Nodes can either be \"leaf\" nodes (i.e. have no children), or \"sub-tree\"\nnodes, which do have children. In the example above, button.rb, item.rb, and header.rb are all leaf nodes, while\naction_list is a sub-tree node.\n2. **Path**. A node's path is like its ID. It's an array of strings containing the current node's label and all the\nlabels of its ancestors, in order. In the example above, header.rb's path is [\"src\", \"action_list\", \"header.rb\"].\n\n## Static nodes\n\nThe `TreeView` component allows items to be provided statically or loaded dynamically from the server.\nProviding items statically is done using the `leaf` and `sub_tree` slots:\n\n```erb\n<%= render(Primer::OpenProject::TreeView.new) do |tree| %>\n <% tree.with_sub_tree(label: \"Directory\") do |sub_tree| %>\n <% sub_tree.with_leaf(label: \"File 1\")\n <% end %>\n <% tree.with_leaf(label: \"File 2\") %>\n<% end %>\n```\n\n## Dynamic nodes\n\nTree nodes can also be fetched dynamically from the server and will require creating a Rails controller action\nto respond with the list of nodes. Unlike other Primer components, `TreeView` allows the programmer to specify\nloading behavior on a per-sub-tree basis, i.e. each sub-tree must specify how its nodes are loaded. To load nodes\ndynamically for a given sub-tree, configure it with either a loading spinner or a loading skeleton, and provide\nthe URL to fetch nodes from:\n\n```erb\n<%= render(Primer::OpenProject::TreeView.new) do |tree| %>\n <% tree.with_sub_tree(label: \"Directory\") do |sub_tree| %>\n <% sub_tree.with_loading_spinner(src: tree_view_items_path) %>\n <% end %>\n<% end %>\n```\n\nDefine a controller action to serve the list of nodes. The `TreeView` component automatically includes the\nsub-tree's path as a GET parameter, encoded as a JSON array.\n\n```ruby\nclass TreeViewItemsController < ApplicationController\n def show\n @path = JSON.parse(params[:path])\n @results = get_tree_items(starting_at: path)\n end\nend\n```\n\nResponses must be HTML fragments, eg. have a content type of `text/html+fragment`. This content type isn't\navailable by default in Rails, so you may have to register it eg. in an initializer:\n\n```ruby\nMime::Type.register(\"text/fragment+html\", :html_fragment)\n```\n\nRender a `Primer::OpenProject::TreeView::SubTree` in the action's template, tree_view_items/show.html_fragment.erb:\n\n```erb\n<%= render(Primer::OpenProject::TreeView::SubTree.new(path: @path, node_variant: :div)) do |tree| %>\n <% tree.with_leaf(...) %>\n <% tree.with_sub_tree(...) do |sub_tree| %>\n ...\n <% end %>\n<% end %>\n```\n\n## Multi-select mode\n\nPassing `select_variant: :multiple` to both sub-tree and leaf nodes will add a check box to the left of the node's\nlabel. These check boxes behave according to the value of a second argument, `select_strategy:`.\n\nThe default select strategy, `:descendants`, will cause all child nodes to be checked when the node is checked.\nThis includes both sub-tree and leaf nodes. When the node is unchecked, all child nodes will also be unchecked.\nUnchecking a child node of a checked parent will cause the parent to enter a mixed or indeterminate state, which\nis represented by a horizontal line icon instead of a check mark. This icon indicates that some children are\nchecked, but not all.\n\nA secondary select strategy, `:self`, is provided to allow disabling the automatic checking of child nodes. When\n`select_strategy: :self` is specified, checking sub-tree nodes does not check child nodes, and sub-tree nodes\ncannot enter a mixed or indeterminate state.\n\nNodes can be checked via the keyboard by pressing the space key.\n\n## Node tags\n\n`TreeView`s support three different node variants, `:anchor`, `:button`, and `:div` (the default), which controls\nwhich HTML tag is used to construct the nodes. The `:anchor` and `:button` variants correspond to `<a>` and\n`<button>` tags respectively, which are browser-native elements. Anchors and buttons can be activated (i.e.\n\"clicked\") using the mouse or keyboard via the enter or space keys. The node variant must be the same for all\nnodes in the tree, and is therefore specified at the root level, eg. `TreeView.new(node_variant: :anchor)`.\n\nTrees with node variants other than `:div` cannot have check boxes, i.e. cannot be put into multi-select mode.\n\nTrees with node variants other than `:div` do not emit the `treeViewNodeActivated` or `treeViewBeforeNodeActivated`\nevents, since it is assumed any behavior associated with these variants is user- or browser-defined.\n\n## Interaction behavior matrix\n\n|Interaction |Select variant|Tag |Result |\n|:---------------|:-------------|:------------|:--------------------------|\n|Enter/space |none |div |Expands/collapses |\n|Enter/space |none |anchor/button|Activates anchor/button |\n|Enter/space |multiple |div |Checks or unchecks |\n|Enter/space |multiple |anchor/button|N/A (not allowed) |\n|Left/right arrow|none |div |Expands/collapses |\n|Left/right arrow|none |anchor/button|Expands/collapses |\n|Left/right arrow|multiple |div |Expands/collapses |\n|Left/right arrow|multiple |anchor/button|N/A (not allowed) |\n|Click |none |div |Expands/collapses |\n|Click |multiple |div |Checks or unchecks |\n|Click |multiple |anchor/button|N/A (not allowed) |\n\n## JavaScript API\n\n`TreeView`s render a `<tree-view>` custom element that exposes behavior to the client.\n\n|Name |Notes |\n|:-----------------------------------------------------------------|:-------------------------------------------------------------------------------------------------------------------------------------------------|\n|`getNodePath(node: Element): string[]` |Returns the path to the given node. |\n|`getNodeType(node: Element): TreeViewNodeType | null` |Returns either `\"leaf\"` or `\"sub-tree\"`. |\n|`markCurrentAtPath(path: string[])` |Marks the node as the \"current\" node, which appears visually distinct from other nodes. |\n|`get currentNode(): HTMLLIElement | null` |Returns the current node. |\n|`expandAtPath(path: string[])` |Expands the sub-tree at `path`. |\n|`collapseAtPath(path: string[])` |Collapses the sub-tree at `path`. |\n|`toggleAtPath(path: string[])` |If the sub-tree at `path` is collapsed, this function expands it, and vice-versa. |\n|`checkAtPath(path: string[])` |If the node at `path` has a checkbox, this function checks it. |\n|`uncheckAtPath(path: string[])` |If the node at `path` has a checkbox, this function unchecks it. |\n|`toggleCheckedAtPath(path: string[])` |If the sub-tree at `path` is checked, this function unchecks it, and vice-versa. |\n|`checkedValueAtPath(path: string[]): TreeViewCheckedValue` |Returns `\"true\"` (all child nodes are checked), `\"false\"` (no child nodes are checked), or `\"mixed\"` (some child nodes are checked, some are not).|\n|`nodeAtPath(path: string[], selector?: string): Element | null` |Returns the node for the given `path`, either a leaf node or sub-tree node. |\n|`subTreeAtPath(path: string[]): TreeViewSubTreeNodeElement | null`|Returns the sub-tree at the given `path`, if it exists. |\n|`leafAtPath(path: string[]): HTMLLIElement | null` |Returns the leaf node at the given `path`, if it exists. |\n|`getNodeCheckedValue(node: Element): TreeViewCheckedValue` |The same as `checkedValueAtPath`, but accepts a node instead of a path. |\n\n### Events\n\nThe events enumerated below include node information by way of the `TreeViewNodeInfo` object, which has the\nfollowing signature:\n\n```typescript\ntype TreeViewNodeType = 'leaf' | 'sub-tree'\ntype TreeViewCheckedValue = 'true' | 'false' | 'mixed'\n\ntype TreeViewNodeInfo = {\n node: Element\n type: TreeViewNodeType\n path: string[]\n checkedValue: TreeViewCheckedValue\n previousCheckedValue: TreeViewCheckedValue\n}\n```\n\n|Name |Type |Bubbles |Cancelable |\n|:----------------------------|:------------------------------------------|:-------|:----------|\n|`treeViewNodeActivated` |`CustomEvent<TreeViewNodeInfo>` |Yes |No |\n|`treeViewBeforeNodeActivated`|`CustomEvent<TreeViewNodeInfo>` |Yes |Yes |\n|`treeViewNodeExpanded` |`CustomEvent<TreeViewNodeInfo>>` |Yes |No |\n|`treeViewNodeCollapsed` |`CustomEvent<TreeViewNodeInfo>>` |Yes |No |\n|`treeViewNodeChecked` |`CustomEvent<TreeViewNodeInfo[]>` |Yes |Yes |\n|`treeViewBeforeNodeChecked` |`CustomEvent<TreeViewNodeInfo[]>` |Yes |No |\n\n_Item activation_\n\nThe `<tree-view>` element fires an `treeViewNodeActivated` event whenever a node is activated (eg. clicked)\nvia the mouse or keyboard.\n\nThe `treeViewBeforeNodeActivated` event fires before a node is activated. Canceling this event will prevent the\nnode from being activated.\n\n```typescript\ndocument.querySelector(\"select-panel\").addEventListener(\n \"treeViewBeforeNodeActivated\",\n (event: CustomEvent<TreeViewNodeInfo>) => {\n event.preventDefault() // Cancel the event to prevent activation (eg. expanding/collapsing)\n }\n)\n```\n\n_Item checking/unchecking_\n\nThe `tree-view` element fires a `treeViewNodeChecked` event whenever a node is checked or unchecked.\n\nThe `treeViewBeforeNodeChecked` event fires before a node is checked or unchecked. Canceling this event will\nprevent the check/uncheck operation.\n\n```typescript\ndocument.querySelector(\"select-panel\").addEventListener(\n \"treeViewBeforeNodeChecked\",\n (event: CustomEvent<TreeViewNodeInfo[]>) => {\n event.preventDefault() // Cancel the event to prevent activation (eg. expanding/collapsing)\n }\n)\n```\n\nBecause checking or unchecking a sub-tree results in the checking or unchecking of all its children recursively,\nboth the `treeViewNodeChecked` and `treeViewBeforeNodeChecked` events provide an array of `TreeViewNodeInfo`\nobjects, which contain entries for every modified node in the tree.",
20450
20456
  "accessibility_docs": null,
20451
20457
  "is_form_component": false,
20452
20458
  "is_published": true,
@@ -20458,6 +20464,12 @@
20458
20464
  "source": "https://github.com/primer/view_components/tree/main/app/components/primer/open_project/tree_view.rb",
20459
20465
  "lookbook": "https://primer.style/view-components/lookbook/inspect/primer/open_project/tree_view/default/",
20460
20466
  "parameters": [
20467
+ {
20468
+ "name": "node_variant",
20469
+ "type": "Symbol",
20470
+ "default": "`:div`",
20471
+ "description": "The variant to use for this node. One of `:anchor`, `:button`, or `:div`."
20472
+ },
20461
20473
  {
20462
20474
  "name": "system_arguments",
20463
20475
  "type": "Hash",
@@ -20515,6 +20527,16 @@
20515
20527
  ],
20516
20528
  "return_types": [
20517
20529
 
20530
+ ]
20531
+ },
20532
+ {
20533
+ "name": "node_variant",
20534
+ "description": "Returns the value of attribute node_variant.",
20535
+ "parameters": [
20536
+
20537
+ ],
20538
+ "return_types": [
20539
+
20518
20540
  ]
20519
20541
  }
20520
20542
  ],
@@ -20609,6 +20631,32 @@
20609
20631
  "color-contrast"
20610
20632
  ]
20611
20633
  }
20634
+ },
20635
+ {
20636
+ "preview_path": "primer/open_project/tree_view/links",
20637
+ "name": "links",
20638
+ "snapshot": "false",
20639
+ "skip_rules": {
20640
+ "wont_fix": [
20641
+ "region"
20642
+ ],
20643
+ "will_fix": [
20644
+ "color-contrast"
20645
+ ]
20646
+ }
20647
+ },
20648
+ {
20649
+ "preview_path": "primer/open_project/tree_view/buttons",
20650
+ "name": "buttons",
20651
+ "snapshot": "false",
20652
+ "skip_rules": {
20653
+ "wont_fix": [
20654
+ "region"
20655
+ ],
20656
+ "will_fix": [
20657
+ "color-contrast"
20658
+ ]
20659
+ }
20612
20660
  }
20613
20661
  ],
20614
20662
  "subcomponents": [
@@ -20947,6 +20995,18 @@
20947
20995
  "default": "N/A",
20948
20996
  "description": "The node's \"path,\" i.e. this node's label and the labels of all its ancestors. This node should be reachable by traversing the tree following this path."
20949
20997
  },
20998
+ {
20999
+ "name": "node_variant",
21000
+ "type": "Symbol",
21001
+ "default": "N/A",
21002
+ "description": "The node variant to use for the node's content, i.e. the `:button` or `:div`. One of `:anchor`, `:button`, or `:div`."
21003
+ },
21004
+ {
21005
+ "name": "href",
21006
+ "type": "String",
21007
+ "default": "`nil`",
21008
+ "description": "The URL to use as the `href` attribute for this node. If set to a truthy value, the `tag:` parameter is ignored and assumed to be `:a`."
21009
+ },
20950
21010
  {
20951
21011
  "name": "current",
20952
21012
  "type": "Boolean",
@@ -20966,10 +21026,10 @@
20966
21026
  "description": "The checked state of the node's checkbox. One of `false`, `mixed`, or `true`."
20967
21027
  },
20968
21028
  {
20969
- "name": "system_arguments",
21029
+ "name": "content_arguments",
20970
21030
  "type": "Hash",
20971
21031
  "default": "N/A",
20972
- "description": "The arguments accepted by {{#link_to_component}}Primer::Alpha::ActionList{{/link_to_component}}."
21032
+ "description": "Arguments attached to the node's content, i.e the `<button>` or `<a>` element. {{link_to_system_arguments_docs}}"
20973
21033
  }
20974
21034
  ],
20975
21035
  "slots": [
@@ -21050,6 +21110,16 @@
21050
21110
  "Symbol"
21051
21111
  ]
21052
21112
  },
21113
+ {
21114
+ "name": "node_variant",
21115
+ "description": "This node's variant, eg. `:button`, `:div`, etc.",
21116
+ "parameters": [
21117
+
21118
+ ],
21119
+ "return_types": [
21120
+ "Symbol"
21121
+ ]
21122
+ },
21053
21123
  {
21054
21124
  "name": "level",
21055
21125
  "description": "The numeric depth of this node.",
@@ -21205,6 +21275,12 @@
21205
21275
  "source": "https://github.com/primer/view_components/tree/main/app/components/primer/open_project/tree_view/sub_tree.rb",
21206
21276
  "lookbook": "https://primer.style/view-components/lookbook/inspect/primer/open_project/tree_view/sub_tree/default/",
21207
21277
  "parameters": [
21278
+ {
21279
+ "name": "node_variant",
21280
+ "type": "Symbol",
21281
+ "default": "N/A",
21282
+ "description": "The variant to use for this node. One of `:anchor`, `:button`, or `:div`."
21283
+ },
21208
21284
  {
21209
21285
  "name": "system_arguments",
21210
21286
  "type": "Hash",
@@ -21291,6 +21367,16 @@
21291
21367
  ],
21292
21368
  "return_types": [
21293
21369
 
21370
+ ]
21371
+ },
21372
+ {
21373
+ "name": "node_variant",
21374
+ "description": "Returns the value of attribute node_variant.",
21375
+ "parameters": [
21376
+
21377
+ ],
21378
+ "return_types": [
21379
+
21294
21380
  ]
21295
21381
  }
21296
21382
  ],
@@ -21402,6 +21488,12 @@
21402
21488
  "default": "N/A",
21403
21489
  "description": "The node's \"path,\" i.e. this node's label and the labels of all its ancestors. This node should be reachable by traversing the tree following this path."
21404
21490
  },
21491
+ {
21492
+ "name": "node_variant",
21493
+ "type": "Symbol",
21494
+ "default": "N/A",
21495
+ "description": "The variant to use for this node. One of `:anchor`, `:button`, or `:div`."
21496
+ },
21405
21497
  {
21406
21498
  "name": "expanded",
21407
21499
  "type": "Boolean",