Class: Polaris::HeadlessButton
- Defined in:
- app/components/polaris/headless_button.rb
Direct Known Subclasses
Constant Summary collapse
- SIZE_DEFAULT =
:medium
- SIZE_MAPPINGS =
{ SIZE_DEFAULT => "", :slim => "Polaris-Button--sizeSlim", :large => "Polaris-Button--sizeLarge" }
- SIZE_OPTIONS =
SIZE_MAPPINGS.keys
- TEXT_ALIGN_DEFAULT =
:default
- TEXT_ALIGN_MAPPINGS =
{ TEXT_ALIGN_DEFAULT => "", :left => "Polaris-Button--textAlignLeft", :center => "Polaris-Button--textAlignCenter", :right => "Polaris-Button--textAlignRight" }
- TEXT_ALIGN_OPTIONS =
TEXT_ALIGN_MAPPINGS.keys
- DISCLOSURE_DEFAULT =
false
- DISCLOSURE_OPTIONS =
[true, false, :down, :up, :select, :horizontal_dots]
Constants included from ViewHelper
ViewHelper::POLARIS_HELPERS, ViewHelper::POLARIS_TEXT_STYLES
Constants included from FetchOrFallbackHelper
FetchOrFallbackHelper::InvalidValueError
Instance Method Summary collapse
- #html_options ⇒ Object
-
#initialize(url: nil, outline: false, plain: false, primary: false, pressed: false, monochrome: false, loading: false, destructive: false, disabled: false, disable_with_loader: false, disclosure: DISCLOSURE_DEFAULT, external: false, full_width: false, submit: false, remove_underline: false, size: SIZE_DEFAULT, text_align: TEXT_ALIGN_DEFAULT, icon_name: nil, **system_arguments) ⇒ HeadlessButton
constructor
A new instance of HeadlessButton.
- #system_arguments ⇒ Object
Methods included from ViewHelper
#polaris_body_styles, #polaris_html_classes, #polaris_html_styles, #polaris_icon_source
Methods included from StylesListHelper
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
Constructor Details
#initialize(url: nil, outline: false, plain: false, primary: false, pressed: false, monochrome: false, loading: false, destructive: false, disabled: false, disable_with_loader: false, disclosure: DISCLOSURE_DEFAULT, external: false, full_width: false, submit: false, remove_underline: false, size: SIZE_DEFAULT, text_align: TEXT_ALIGN_DEFAULT, icon_name: nil, **system_arguments) ⇒ HeadlessButton
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/components/polaris/headless_button.rb', line 27 def initialize( url: nil, outline: false, plain: false, primary: false, pressed: false, monochrome: false, loading: false, destructive: false, disabled: false, disable_with_loader: false, disclosure: DISCLOSURE_DEFAULT, external: false, full_width: false, submit: false, remove_underline: false, size: SIZE_DEFAULT, text_align: TEXT_ALIGN_DEFAULT, icon_name: nil, **system_arguments ) @tag = url.present? ? "a" : "button" @text_classes = class_names( "Polaris-Button__Text", "Polaris-Button--removeUnderline": plain && monochrome && remove_underline ) @loading = loading @disclosure = fetch_or_fallback(DISCLOSURE_OPTIONS, disclosure, DISCLOSURE_DEFAULT) @disclosure = :down if @disclosure === true @icon_name = icon_name @system_arguments = system_arguments @system_arguments[:type] = submit ? "submit" : "button" if loading @system_arguments[:disabled] = true end if url.present? @system_arguments.delete(:type) @system_arguments[:href] = url @system_arguments[:target] = "_blank" if external end if disabled @system_arguments[:disabled] = disabled end @system_arguments[:data] ||= {} prepend_option(@system_arguments[:data], :controller, "polaris-button") if disable_with_loader prepend_option(@system_arguments[:data], :action, "polaris-button#disable") end @system_arguments[:classes] = class_names( @system_arguments[:classes], "Polaris-Button", SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)], TEXT_ALIGN_MAPPINGS[fetch_or_fallback(TEXT_ALIGN_OPTIONS, text_align, TEXT_ALIGN_DEFAULT)], "Polaris-Button--destructive": destructive, "Polaris-Button--disabled": disabled || loading, "Polaris-Button--loading": loading, "Polaris-Button--fullWidth": full_width, "Polaris-Button--monochrome": monochrome, # "Polaris-Button--outline": outline, "Polaris-Button--plain": plain, "Polaris-Button--primary": primary, "Polaris-Button--pressed": pressed, "Polaris-Button--removeUnderline": plain && monochrome && remove_underline ) end |
Instance Method Details
#html_options ⇒ Object
102 103 104 105 106 107 |
# File 'app/components/polaris/headless_button.rb', line 102 def = system_arguments [:class] = [:classes] .delete(:classes) end |
#system_arguments ⇒ Object
94 95 96 97 98 99 100 |
# File 'app/components/polaris/headless_button.rb', line 94 def system_arguments @system_arguments[:classes] = class_names( @system_arguments[:classes], "Polaris-Button--iconOnly": (icon.present? || @icon_name.present?) && content.blank? ) @system_arguments end |