Class: Primer::Alpha::TreeView::Node
- Defined in:
- app/components/primer/alpha/tree_view/node.rb
Overview
A generic ‘TreeView` node.
This component is part of the <%= link_to_component(Primer::Alpha::TreeView) %> component and should not be used directly.
Constant Summary collapse
- DEFAULT_NODE_VARIANT =
Primer::Alpha::TreeView::DEFAULT_NODE_VARIANT
- NODE_VARIANT_TAG_MAP =
{ DEFAULT_NODE_VARIANT => :div, :button => :button, :anchor => :a }.freeze
- NODE_VARIANT_TAG_OPTIONS =
NODE_VARIANT_TAG_MAP.keys.freeze
- DEFAULT_SELECT_VARIANT =
:none
- SELECT_VARIANT_OPTIONS =
[ :multiple, DEFAULT_SELECT_VARIANT ].freeze
- DEFAULT_CHECKED_STATE =
false
- CHECKED_STATES =
[ DEFAULT_CHECKED_STATE, true, "mixed" ]
Constants inherited from Component
Component::INVALID_ARIA_LABEL_TAGS
Constants included from Status::Dsl
Constants included from ViewHelper
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 Attribute Summary collapse
-
#checked ⇒ String
readonly
This node’s checked state.
-
#current ⇒ Boolean
(also: #current?)
readonly
Wether or not this node is the current node.
-
#disabled ⇒ Boolean
(also: #disabled?)
readonly
Whether or not this node is disabled, i.e.
-
#node_variant ⇒ Symbol
readonly
This node’s variant, eg.
-
#select_variant ⇒ Symbol
readonly
This node’s select variant (i.e. check box variant).
Instance Method Summary collapse
-
#initialize(path:, node_variant:, href: nil, current: false, select_variant: DEFAULT_SELECT_VARIANT, checked: DEFAULT_CHECKED_STATE, disabled: false, value: nil, **content_arguments) ⇒ Node
constructor
A new instance of Node.
-
#level ⇒ Integer
The numeric depth of this node.
-
#merge_system_arguments!(**other_arguments) ⇒ Object
Merges the given arguments into the current hash of system arguments provided when the component was initially constructed.
Methods inherited from Component
Methods included from JoinStyleArgumentsHelper
Methods included from TestSelectorHelper
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?
Methods included from ClassNameHelper
Methods included from Primer::AttributesHelper
#aria, #data, #extract_data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes
Methods included from ExperimentalSlotHelpers
Methods included from ExperimentalRenderHelpers
Constructor Details
#initialize(path:, node_variant:, href: nil, current: false, select_variant: DEFAULT_SELECT_VARIANT, checked: DEFAULT_CHECKED_STATE, disabled: false, value: nil, **content_arguments) ⇒ Node
Returns a new instance of Node.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'app/components/primer/alpha/tree_view/node.rb', line 79 def initialize( path:, node_variant:, href: nil, current: false, select_variant: DEFAULT_SELECT_VARIANT, checked: DEFAULT_CHECKED_STATE, disabled: false, value: nil, **content_arguments ) @system_arguments = { tag: :li, role: :none, classes: "TreeViewItem" } @content_arguments = content_arguments @path = path @current = current @select_variant = fetch_or_fallback(SELECT_VARIANT_OPTIONS, select_variant, DEFAULT_SELECT_VARIANT) @checked = fetch_or_fallback(CHECKED_STATES, checked, DEFAULT_CHECKED_STATE) @disabled = disabled @node_variant = fetch_or_fallback(NODE_VARIANT_TAG_OPTIONS, node_variant, DEFAULT_NODE_VARIANT) @content_arguments[:tag] = NODE_VARIANT_TAG_MAP[@node_variant] @content_arguments[:href] = href if href @content_arguments[:id] = content_id @content_arguments[:role] = :treeitem @content_arguments[:tabindex] = current? ? 0 : -1 @content_arguments[:classes] = class_names( @content_arguments.delete(:classes), "TreeViewItemContent" ) @content_arguments[:aria] = merge_aria( @content_arguments, { aria: { level: level, selected: false, checked: checked, labelledby: content_id, disabled: disabled? } } ) @content_arguments[:data] = merge_data( @content_arguments, { data: { value: value, path: @path.to_json } } ) return unless current? @content_arguments[:aria] = merge_aria( @content_arguments, { aria: { current: true } } ) end |
Instance Attribute Details
#checked ⇒ String (readonly)
This node’s checked state.
39 40 41 |
# File 'app/components/primer/alpha/tree_view/node.rb', line 39 def checked @checked end |
#current ⇒ Boolean (readonly) Also known as: current?
Wether or not this node is the current node.
33 34 35 |
# File 'app/components/primer/alpha/tree_view/node.rb', line 33 def current @current end |
#disabled ⇒ Boolean (readonly) Also known as: disabled?
Whether or not this node is disabled, i.e. cannot be activated.
54 55 56 |
# File 'app/components/primer/alpha/tree_view/node.rb', line 54 def disabled @disabled end |
#node_variant ⇒ Symbol (readonly)
This node’s variant, eg. ‘:button`, `:div`, etc.
49 50 51 |
# File 'app/components/primer/alpha/tree_view/node.rb', line 49 def node_variant @node_variant end |
#select_variant ⇒ Symbol (readonly)
This node’s select variant (i.e. check box variant).
44 45 46 |
# File 'app/components/primer/alpha/tree_view/node.rb', line 44 def select_variant @select_variant end |
Instance Method Details
#level ⇒ Integer
The numeric depth of this node.
147 148 149 |
# File 'app/components/primer/alpha/tree_view/node.rb', line 147 def level @level ||= @path.size end |
#merge_system_arguments!(**other_arguments) ⇒ Object
Merges the given arguments into the current hash of system arguments provided when the component was initially constructed. This method can be used to add additional arguments just before rendering.
155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'app/components/primer/alpha/tree_view/node.rb', line 155 def merge_system_arguments!(**other_arguments) @content_arguments[:aria] = merge_aria( @content_arguments, other_arguments ) @content_arguments[:data] = merge_data( @content_arguments, other_arguments ) @content_arguments.merge!(**other_arguments) end |