class Primer::Beta::Button
Use ‘Button` for actions (e.g. in forms). Use links for destinations, or moving from one page to another.
def before_render
def before_render return unless @scheme == :invisible && !trailing_visual && !leading_visual && !trailing_action @system_arguments[:classes] = class_names( @system_arguments[:classes], "Button--invisible-noVisuals" ) end
def initialize(
-
system_arguments
(Hash
) -- <%= link_to_system_arguments_docs %> -
disabled
(Boolean
) -- Whether or not the button is disabled. If true, this option forces `tag:` to `:button`. -
type
(Symbol
) -- (Primer::Beta::BaseButton::DEFAULT_TYPE) <%= one_of(Primer::Beta::BaseButton::TYPE_OPTIONS) %> -
tag
(Symbol
) -- (Primer::Beta::BaseButton::DEFAULT_TAG) <%= one_of(Primer::Beta::BaseButton::TAG_OPTIONS) %> -
align_content
(Symbol
) -- <%= one_of(Primer::Beta::Button::ALIGN_CONTENT_OPTIONS) %> -
block
(Boolean
) -- Whether button is full-width with `display: block`. -
size
(Symbol
) -- <%= one_of(Primer::Beta::Button::SIZE_OPTIONS) %> -
scheme
(Symbol
) -- <%= one_of(Primer::Beta::Button::SCHEME_OPTIONS) %> -
base_button_class
(Class
) -- The button class to render.
def initialize( base_button_class: Primer::Beta::BaseButton, scheme: DEFAULT_SCHEME, size: DEFAULT_SIZE, block: false, align_content: DEFAULT_ALIGN_CONTENT, disabled: false, **system_arguments ) @base_button_class = base_button_class @scheme = scheme @block = block @system_arguments = system_arguments @system_arguments[:disabled] = disabled @id = @system_arguments[:id] raise ArgumentError, "The `variant:` argument is no longer supported on Primer::Beta::Button. Consider `scheme:` or `size:`." if !Rails.env.production? && @system_arguments[:variant].present? raise ArgumentError, "The `dropdown:` argument is no longer supported on Primer::Beta::Button. Use the `trailing_action` slot instead." if !Rails.env.production? && @system_arguments[:dropdown].present? @align_content_classes = class_names( "Button-content", ALIGN_CONTENT_MAPPINGS[fetch_or_fallback(ALIGN_CONTENT_OPTIONS, align_content, DEFAULT_ALIGN_CONTENT)] ) @system_arguments[:classes] = class_names( system_arguments[:classes], SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_OPTIONS, scheme, DEFAULT_SCHEME)], SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE)], "Button", "Button--fullWidth" => @block ) end
def trimmed_content
def trimmed_content return if content.blank? trimmed_content = content.strip return trimmed_content unless content.html_safe? # strip unsets `html_safe`, so we have to set it back again to guarantee that HTML blocks won't break trimmed_content.html_safe # rubocop:disable Rails/OutputSafety end