Sha256: 034b724108a6f6799d312c943f042d3b248eae8a6b50886e77a8d06d119ad432
Contents?: true
Size: 1.74 KB
Versions: 3
Compression:
Stored size: 1.74 KB
Contents
# frozen_string_literal: true module Primer # Renders an [Octicon](https://primer.style/octicons/) with <%= link_to_system_arguments_docs %>. class OcticonComponent < Primer::Component include Primer::ClassNameHelper include OcticonsHelper SIZE_DEFAULT = :small SIZE_MAPPINGS = { SIZE_DEFAULT => 16, :medium => 32, :large => 64 }.freeze SIZE_OPTIONS = SIZE_MAPPINGS.keys # @example auto|Default # <%= render(Primer::OcticonComponent.new(icon: "check")) %> # # @example auto|Medium # <%= render(Primer::OcticonComponent.new(icon: "people", size: :medium)) %> # # @example auto|Large # <%= render(Primer::OcticonComponent.new(icon: "x", size: :large)) %> # # @param icon [String] Name of [Octicon](https://primer.style/octicons/) to use. # @param size [Symbol] <%= one_of(Primer::OcticonComponent::SIZE_MAPPINGS) %> # @param system_arguments [Hash] <%= link_to_system_arguments_docs %> def initialize(icon:, size: SIZE_DEFAULT, **system_arguments) @icon = icon @system_arguments = system_arguments @system_arguments[:class] = Primer::Classify.call(**@system_arguments)[:class] @system_arguments[:height] ||= SIZE_MAPPINGS[size] # 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_helper_options = @system_arguments.slice(:height, :width) @system_arguments = @system_arguments.except(*Primer::Classify::VALID_KEYS, :classes).merge(octicon_helper_options) end def call octicon(@icon, { **@system_arguments }) end def self.status Primer::Component::STATUSES[:beta] end end end
Version data entries
3 entries across 3 versions & 1 rubygems