class Primer::OcticonComponent
‘Octicon` can also be rendered with the `primer_octicon` helper, which accepts the same arguments.
`Octicon` renders an <%= link_to_octicons %> with <%= link_to_system_arguments_docs %>.
def self._after_compile
def self._after_compile Primer::Octicon::Cache.preload! end
def initialize(icon_name = nil, icon: nil, size: SIZE_DEFAULT, use_symbol: false, **system_arguments)
-
system_arguments(Hash) -- <%= link_to_system_arguments_docs %> -
use_symbol(Boolean) -- EXPERIMENTAL (May change or be removed) - Set to true when using with <%= link_to_component(Primer::OcticonSymbolsComponent) %>. -
size(Symbol) -- <%= one_of(Primer::OcticonComponent::SIZE_MAPPINGS, sort: false) %> -
icon(Symbol, String) -- Name of <%= link_to_octicons %> to use. -
icon_name(Symbol, String) -- Name of <%= link_to_octicons %> to use.
Other tags:
- Example: Helper -
Example: Medium -
Example: Default -
def initialize(icon_name = nil, icon: nil, size: SIZE_DEFAULT, use_symbol: false, **system_arguments) icon_key = icon_name || icon # Don't allow sizes under 16px if system_arguments[:height].present? && system_arguments[:height].to_i < 16 || system_arguments[:width].present? && system_arguments[:width].to_i < 16 system_arguments.delete(:height) system_arguments.delete(:width) end cache_key = Primer::Octicon::Cache.get_key( symbol: icon_key, size: size, height: system_arguments[:height], width: system_arguments[:width] ) @system_arguments = system_arguments @system_arguments[:tag] = :svg @system_arguments[:aria] ||= {} @use_symbol = use_symbol if @system_arguments[:aria][:label] || @system_arguments[:"aria-label"] @system_arguments[:role] = "img" else @system_arguments[:aria][:hidden] = true end if (cache_icon = Primer::Octicon::Cache.read(cache_key)) @icon = cache_icon else # Filter out classify options to prevent them from becoming invalid html attributes. # Note height and width are both classify options and valid html attributes. octicon_options = { height: SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)] }.merge(@system_arguments.slice(:height, :width)) @icon = Octicons::Octicon.new(icon_key, octicon_options) Primer::Octicon::Cache.set(cache_key, @icon) end @system_arguments[:classes] = class_names( @icon.options[:class], @system_arguments[:classes] ) @system_arguments.merge!(@icon.options.except(:class, :'aria-hidden')) end