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_html_classes, #polaris_html_styles, #polaris_icon_source

Methods included from StylesListHelper

#styles_list

Methods included from OptionHelper

#append_option, #prepend_option

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #fetch_or_fallback_nested

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(connected_top: false, full_width: false, segmented: false, spacing: SPACING_DEFAULT, nowrap: false, **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
53
54
# File 'app/components/polaris/button_group_component.rb', line 26

def initialize(
  connected_top: false,
  full_width: false,
  segmented: false,
  spacing: SPACING_DEFAULT,
  nowrap: false,
  **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,
    "Polaris-ButtonGroup--noWrap": nowrap
  )
end

Instance Method Details

#all_itemsObject



60
61
62
# File 'app/components/polaris/button_group_component.rb', line 60

def all_items
  @all_items ||= buttons + items
end

#ordered_itemsObject



64
65
66
# File 'app/components/polaris/button_group_component.rb', line 64

def ordered_items
  all_items.sort_by(&:position)
end

#render?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'app/components/polaris/button_group_component.rb', line 56

def render?
  all_items.any?
end