Class: Polaris::ButtonGroupComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/polaris/button_group_component.rb

Defined Under Namespace

Classes: ButtonGroupItemButtonComponent, ButtonGroupItemComponent

Constant Summary collapse

SPACING_DEFAULT =
:default
SPACING_MAPPINGS =
{
  SPACING_DEFAULT => "",
  :extra_tight => "Polaris-ButtonGroup--extraTight",
  :tight => "Polaris-ButtonGroup--tight",
  :loose => "Polaris-ButtonGroup--loose"
}
SPACING_OPTIONS =
SPACING_MAPPINGS.keys

Constants included from ViewHelper

ViewHelper::POLARIS_HELPERS, ViewHelper::POLARIS_TEXT_STYLES

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods included from ViewHelper

#polaris_body_styles, #polaris_icon_source, #polaris_inversed_colors

Methods included from OptionHelper

#append_option, #prepend_option

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(connected_top: false, full_width: false, segmented: false, spacing: SPACING_DEFAULT, **system_arguments) ⇒ ButtonGroupComponent

Returns a new instance of ButtonGroupComponent.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/components/polaris/button_group_component.rb', line 26

def initialize(
  connected_top: false,
  full_width: false,
  segmented: false,
  spacing: SPACING_DEFAULT,
  **system_arguments
)
  @counter = 0

  @system_arguments = system_arguments
  if connected_top
    @system_arguments["data-buttongroup-connected-top"] = true
  end
  if full_width
    @system_arguments["data-buttongroup-full-width"] = true
  end
  if segmented
    @system_arguments["data-buttongroup-segmented"] = true
  end
  @system_arguments[:classes] = class_names(
    @system_arguments[:classes],
    "Polaris-ButtonGroup",
    SPACING_MAPPINGS[fetch_or_fallback(SPACING_OPTIONS, spacing, SPACING_DEFAULT)],
    "Polaris-ButtonGroup--fullWidth": full_width,
    "Polaris-ButtonGroup--segmented": segmented
  )
end

Instance Method Details

#all_itemsObject



58
59
60
# File 'app/components/polaris/button_group_component.rb', line 58

def all_items
  @all_items ||= buttons + items
end

#ordered_itemsObject



62
63
64
# File 'app/components/polaris/button_group_component.rb', line 62

def ordered_items
  all_items.sort_by(&:position)
end

#render?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'app/components/polaris/button_group_component.rb', line 54

def render?
  all_items.any?
end