Class: HakumiComponents::SelectionControl::TreeNode

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
app/components/hakumi_components/selection_control/tree_node.rb

Constant Summary collapse

RawValue =
T.type_alias do
  T.nilable(T.any(String, Symbol, Numeric, T::Boolean, T::Array[T.untyped], T::Hash[Types::HtmlKey, T.untyped]))
end
InputHash =
T.type_alias { T::Hash[Types::HtmlKey, RawValue] }
Input =
T.type_alias { T.any(TreeNode, InputHash) }
Payload =
T.type_alias { T::Hash[Symbol, T.nilable(T.any(String, Symbol, Numeric, T::Boolean, T::Array[T.untyped]))] }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label:, value:, children: [], disabled: false, selectable: true, checkable: true, disable_checkbox: false, icon: nil, switcher_icon: nil, async: false, loading: false) ⇒ TreeNode

Returns a new instance of TreeNode.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/components/hakumi_components/selection_control/tree_node.rb', line 31

def initialize(
  label:,
  value:,
  children: [],
  disabled: false,
  selectable: true,
  checkable: true,
  disable_checkbox: false,
  icon: nil,
  switcher_icon: nil,
  async: false,
  loading: false
)
  @label = label
  @value = value
  @children = children
  @disabled = disabled
  @selectable = selectable
  @checkable = checkable
  @disable_checkbox = disable_checkbox
  @icon = icon
  @switcher_icon = switcher_icon
  @async = async
  @loading = loading
end

Instance Attribute Details

#asyncObject (readonly)

Returns the value of attribute async.



85
86
87
# File 'app/components/hakumi_components/selection_control/tree_node.rb', line 85

def async
  @async
end

#checkableObject (readonly)

Returns the value of attribute checkable.



73
74
75
# File 'app/components/hakumi_components/selection_control/tree_node.rb', line 73

def checkable
  @checkable
end

#childrenObject (readonly)

Returns the value of attribute children.



64
65
66
# File 'app/components/hakumi_components/selection_control/tree_node.rb', line 64

def children
  @children
end

#disable_checkboxObject (readonly)

Returns the value of attribute disable_checkbox.



76
77
78
# File 'app/components/hakumi_components/selection_control/tree_node.rb', line 76

def disable_checkbox
  @disable_checkbox
end

#disabledObject (readonly)

Returns the value of attribute disabled.



67
68
69
# File 'app/components/hakumi_components/selection_control/tree_node.rb', line 67

def disabled
  @disabled
end

#iconObject (readonly)

Returns the value of attribute icon.



79
80
81
# File 'app/components/hakumi_components/selection_control/tree_node.rb', line 79

def icon
  @icon
end

#labelObject (readonly)

Returns the value of attribute label.



58
59
60
# File 'app/components/hakumi_components/selection_control/tree_node.rb', line 58

def label
  @label
end

#loadingObject (readonly)

Returns the value of attribute loading.



88
89
90
# File 'app/components/hakumi_components/selection_control/tree_node.rb', line 88

def loading
  @loading
end

#selectableObject (readonly)

Returns the value of attribute selectable.



70
71
72
# File 'app/components/hakumi_components/selection_control/tree_node.rb', line 70

def selectable
  @selectable
end

#switcher_iconObject (readonly)

Returns the value of attribute switcher_icon.



82
83
84
# File 'app/components/hakumi_components/selection_control/tree_node.rb', line 82

def switcher_icon
  @switcher_icon
end

#valueObject (readonly)

Returns the value of attribute value.



61
62
63
# File 'app/components/hakumi_components/selection_control/tree_node.rb', line 61

def value
  @value
end

Instance Method Details

#string_valueObject



91
92
93
# File 'app/components/hakumi_components/selection_control/tree_node.rb', line 91

def string_value
  @value.to_s
end

#to_cascader_optionObject



113
114
115
116
117
118
119
120
# File 'app/components/hakumi_components/selection_control/tree_node.rb', line 113

def to_cascader_option
  {
    value: @value,
    label: @label,
    disabled: @disabled,
    children: @children.map(&:to_cascader_option)
  }.compact
end

#to_tree_nodeObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'app/components/hakumi_components/selection_control/tree_node.rb', line 96

def to_tree_node
  {
    key: string_value,
    title: @label,
    children: @children.map(&:to_tree_node),
    disabled: @disabled,
    selectable: @selectable,
    checkable: @checkable,
    disable_checkbox: @disable_checkbox,
    icon: @icon,
    switcher_icon: @switcher_icon,
    async: @async,
    loading: @loading
  }.compact
end