Sha256: 42a4e6a642d41ee5a704fd06f6dc109489cbbcf7cfa8fe286c879de5b08c37a2

Contents?: true

Size: 1.18 KB

Versions: 4

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module Optics
  module Icon
    class Component < ApplicationViewComponent
      SIZES = %w[normal large x-large].freeze
      WEIGHTS = %w[light normal semi-bold bold].freeze
      EMPHASES = %w[low normal high].freeze

      requires :name
      accepts :data
      accepts :emphasis, default: 'normal'
      accepts :filled, default: false
      accepts :size, default: 'normal'
      accepts :title
      accepts :weight, default: 'normal'

      def call
        content_tag(
          :span,
          class: classes,
          'aria-label': title,
          title:,
          data:
        ) do
          name
        end
      end

      def classes
        class_names(
          'material-symbols-outlined',
          size_class,
          weight_class,
          emphasis_class,
          'icon--filled': filled
        ).join(' ')
      end

      def size_class
        return if size == 'normal'

        "icon--#{size}"
      end

      def weight_class
        return if weight == 'normal'

        "icon--weight-#{weight}"
      end

      def emphasis_class
        return if emphasis == 'normal'

        "icon--#{emphasis}-emphasis"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
optics_view_components-0.1.4 app/components/optics/icon/component.rb
optics_view_components-0.1.3 app/components/optics/icon/component.rb
optics_view_components-0.1.2 app/components/optics/icon/component.rb
optics_view_components-0.1.1 app/components/optics/icon/component.rb