Class: Yattho::Alpha::SegmentedControl
- Defined in:
- app/components/yattho/alpha/segmented_control.rb,
app/components/yattho/alpha/segmented_control/item.rb
Overview
Use a segmented control to let users select an option from a short list and immediately apply the selection
Defined Under Namespace
Classes: Item
Constant Summary collapse
- FULL_WIDTH_DEFAULT =
false
- HIDE_LABELS_DEFAULT =
false
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
Instance Method Summary collapse
-
#initialize(hide_labels: HIDE_LABELS_DEFAULT, full_width: FULL_WIDTH_DEFAULT, size: Yattho::Beta::Button::DEFAULT_SIZE, **system_arguments) ⇒ SegmentedControl
constructor
A new instance of SegmentedControl.
- #render? ⇒ Boolean
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
Constructor Details
#initialize(hide_labels: HIDE_LABELS_DEFAULT, full_width: FULL_WIDTH_DEFAULT, size: Yattho::Beta::Button::DEFAULT_SIZE, **system_arguments) ⇒ SegmentedControl
Returns a new instance of SegmentedControl.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/components/yattho/alpha/segmented_control.rb', line 68 def initialize(hide_labels: HIDE_LABELS_DEFAULT, full_width: FULL_WIDTH_DEFAULT, size: Yattho::Beta::Button::DEFAULT_SIZE, **system_arguments) @full_width = full_width @size = size @hide_labels = hide_labels @system_arguments = system_arguments @system_arguments[:tag] = :ul @system_arguments[:role] = "list" @system_arguments[:classes] = class_names( system_arguments[:classes], "SegmentedControl", 'SegmentedControl--iconOnly': hide_labels, 'SegmentedControl--fullWidth': full_width ) end |
Instance Method Details
#render? ⇒ Boolean
85 86 87 88 89 90 91 92 93 |
# File 'app/components/yattho/alpha/segmented_control.rb', line 85 def render? valid_items_count = items.count <= (@hide_labels ? 6 : 5) && items.count >= 2 if !valid_items_count && !Rails.env.production? raise ArgumentError, "A segmented control should have 2-5 choices with text labels, or up to 6 icon-only buttons." end valid_items_count end |