Class: Primer::Alpha::TreeView::SubTreeNode

Inherits:
Component
  • Object
show all
Defined in:
app/components/primer/alpha/tree_view/sub_tree_node.rb

Overview

A ‘TreeView` sub-tree node.

This component is part of the <%= link_to_component(Primer::Alpha::TreeView) %> component and should not be used directly.

Direct Known Subclasses

FileTreeView::DirectoryNode

Constant Summary collapse

DEFAULT_SELECT_STRATEGY =
:mixed_descendants
SELECT_STRATEGIES =
[
  :self,
  DEFAULT_SELECT_STRATEGY,
  :descendants
]

Constants inherited from Component

Component::INVALID_ARIA_LABEL_TAGS

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from TestSelectorHelper

TestSelectorHelper::TEST_SELECTOR_TAG

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Constants included from Primer::AttributesHelper

Primer::AttributesHelper::PLURAL_ARIA_ATTRIBUTES, Primer::AttributesHelper::PLURAL_DATA_ATTRIBUTES

Instance Method Summary collapse

Methods inherited from Component

deprecated?, generate_id

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from TestSelectorHelper

#add_test_selector

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?

Methods included from ClassNameHelper

#class_names

Methods included from Primer::AttributesHelper

#aria, #data, #extract_data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes

Methods included from ExperimentalSlotHelpers

included

Methods included from ExperimentalRenderHelpers

included

Constructor Details

#initialize(label:, path:, node_variant:, sub_tree_component_klass: SubTree, expanded: false, select_strategy: DEFAULT_SELECT_STRATEGY, **system_arguments) ⇒ SubTreeNode

Returns a new instance of SubTreeNode.

Parameters:

  • label (String)

    The node’s label, i.e. it’s textual content.

  • path (Array<String>)

    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.

  • node_variant (Symbol)

    The variant to use for this node. <%= one_of(Primer::Alpha::TreeView::NODE_VARIANT_OPTIONS) %>

  • sub_tree_component_klass (Class) (defaults to: SubTree)

    The class to use for the sub-tree instead of the default <%= link_to_component(Primer::Alpha::TreeView::SubTree) %>

  • expanded (Boolean) (defaults to: false)

    Whether or not this sub-tree should be rendered expanded.

  • select_strategy (Symbol) (defaults to: DEFAULT_SELECT_STRATEGY)

    What should happen when this sub-tree node is checked. <%= one_of(Primer::Alpha::TreeView::SubTreeNode::SELECT_STRATEGIES) %>

  • system_arguments (Hash)

    The arguments accepted by <%= link_to_component(Primer::Alpha::TreeView::Node) %>.



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'app/components/primer/alpha/tree_view/sub_tree_node.rb', line 134

def initialize(
  label:,
  path:,
  node_variant:,
  sub_tree_component_klass: SubTree,
  expanded: false,
  select_strategy: DEFAULT_SELECT_STRATEGY,
  **system_arguments
)
  @label = label
  @system_arguments = system_arguments
  @select_strategy = fetch_or_fallback(SELECT_STRATEGIES, select_strategy, DEFAULT_SELECT_STRATEGY)

  @system_arguments[:aria] = merge_aria(
    @system_arguments,
    { aria: { expanded: expanded } }
  )

  @system_arguments[:data] = merge_data(
    @system_arguments, {
    data: {
      target: "tree-view-sub-tree-node.node",
      "node-type": "sub-tree"
    }
  }
  )

  sub_tree_arguments = @system_arguments.delete(:sub_tree_arguments) || {}

  @sub_tree = sub_tree_component_klass.new(
    expanded: expanded,
    path: path,
    node_variant: node_variant,
    **sub_tree_arguments
  )

  @node = Primer::Alpha::TreeView::Node.new(
    **@system_arguments,
    path: @sub_tree.path,
    node_variant: node_variant
  )

  return unless @node.select_variant == :multiple

  @node.merge_system_arguments!(
    data: {
      "select-strategy": @select_strategy
    }
  )
end

Instance Method Details

#render_in(*args, &block) ⇒ Object



185
186
187
188
189
190
191
192
# File 'app/components/primer/alpha/tree_view/sub_tree_node.rb', line 185

def render_in(*args, &block)
  super.tap do
    # check this _after_ rendering so @sub_tree's slots are defined
    if @node.select_variant != :none && @sub_tree.defer?
      raise ArgumentError, "TreeView does not currently support select variants for sub-trees loaded asynchronously."
    end
  end
end

#with_leading_action_button(**system_arguments, &block) ⇒ Object

Adds a leading action rendered to the left of the node’s label and any leading visuals or checkboxes.

Parameters:

  • system_arguments (Hash)

    The arguments accepted by <%= link_to_component(Primer::Beta::IconButton) %>.



4
5
# File 'app/components/primer/alpha/tree_view/sub_tree_node.rb', line 4

def with_leading_action_button(**system_arguments, &block)
end

#with_leading_visual_icon(label: nil, **system_arguments, &block) ⇒ Object

Adds a leading visual icon rendered to the left of the node’s label.

Parameters:

  • label (String) (defaults to: nil)

    A label describing the visual, displayed only to screen readers.

  • system_arguments (Hash)

    The arguments accepted by <%= link_to_component(Primer::Alpha::TreeView::Icon) %>.



5
6
# File 'app/components/primer/alpha/tree_view/sub_tree_node.rb', line 5

def with_leading_visual_icon(label: nil, **system_arguments, &block)
end

#with_leading_visual_icons(label: nil, **system_arguments, &block) ⇒ Object

Adds a pair of leading visual icon rendered to the left of the node’s label.

Parameters:

  • label (String) (defaults to: nil)

    A label describing the visual, displayed only to screen readers.

  • system_arguments (Hash)

    The arguments accepted by <%= link_to_component(Primer::Alpha::TreeView::IconPair) %>.



5
6
# File 'app/components/primer/alpha/tree_view/sub_tree_node.rb', line 5

def with_leading_visual_icons(label: nil, **system_arguments, &block)
end

#with_trailing_action_button(**system_arguments, &block) ⇒ Object

Adds a trailing action rendered to the right of the node’s content.

Parameters:

  • system_arguments (Hash)

    The arguments accepted by <%= link_to_component(Primer::Beta::IconButton) %>.



4
5
# File 'app/components/primer/alpha/tree_view/sub_tree_node.rb', line 4

def with_trailing_action_button(**system_arguments, &block)
end

#with_trailing_visual_icon(label: nil, **system_arguments, &block) ⇒ Object

Adds a trailing visual icon rendered to the right of the node’s label.

Parameters:

  • label (String) (defaults to: nil)

    A label describing the visual, displayed only to screen readers.

  • system_arguments (Hash)

    The arguments accepted by <%= link_to_component(Primer::Alpha::TreeView::Icon) %>.



5
6
# File 'app/components/primer/alpha/tree_view/sub_tree_node.rb', line 5

def with_trailing_visual_icon(label: nil, **system_arguments, &block)
end