Sha256: 5e699a0df29bf0253d8f3f5ceed5f0b15229a29aff334f47656053a8b4768f1e

Contents?: true

Size: 1.53 KB

Versions: 36

Compression:

Stored size: 1.53 KB

Contents

module Lookbook
  class Theme
    BASE_THEMES = {
      indigo: {
        favicon_light_mode: "#4F46E5",
        favicon_dark_mode: "#818CF8"
      },
      zinc: {
        favicon_light_mode: "#52525b",
        favicon_dark_mode: "#E4E4E7"
      },
      blue: {
        favicon_light_mode: "#2563EB",
        favicon_dark_mode: "#60A5FA"
      },
      green: {
        favicon_light_mode: "#16a34a",
        favicon_dark_mode: "#66E093"
      },
      rose: {
        favicon_light_mode: "#E11D48",
        favicon_dark_mode: "#FFA0B5"
      }
    }

    def initialize(base_theme, overrides = {})
      @base_theme = base_theme
      @overrides = overrides
      @css = nil
    end

    def favicon_light_mode
      (
        @overrides[:favicon_light_mode].presence ||
        @overrides[:favicon].presence ||
        BASE_THEMES[@base_theme.to_sym][:favicon_light_mode]
      )
    end

    def favicon_dark_mode
      (
        @overrides[:favicon_dark_mode].presence ||
        @overrides[:favicon].presence ||
        BASE_THEMES[@base_theme.to_sym][:favicon_dark_mode]
      )
    end

    def to_css
      return @css unless @css.nil?
      @css ||= if @overrides.present?
        styles = [":root {"]
        styles << @overrides.reject { |key| key.to_s.start_with?("favicon") }.map do |key, value|
          "  --lookbook-#{key.to_s.underscore.tr("_", "-")}: #{value};"
        end
        styles.push "}"
        styles.join("\n")
      else
        ""
      end
    end

    def self.valid_theme?(name)
      BASE_THEMES.key? name.to_sym
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
lookbook-2.2.1 lib/lookbook/theme.rb
lookbook-2.2.0 lib/lookbook/theme.rb
lookbook-2.1.1 lib/lookbook/theme.rb
lookbook-2.1.0 lib/lookbook/theme.rb
lookbook-2.0.5 lib/lookbook/theme.rb
lookbook-2.0.4 lib/lookbook/theme.rb
lookbook-2.0.3 lib/lookbook/theme.rb
lookbook-2.0.2 lib/lookbook/theme.rb
lookbook-2.0.1 lib/lookbook/theme.rb
lookbook-2.0.0 lib/lookbook/theme.rb
lookbook-2.0.0.rc.3 lib/lookbook/theme.rb
lookbook-1.5.5 lib/lookbook/theme.rb
lookbook-1.5.4 lib/lookbook/theme.rb
lookbook-2.0.0.rc.2 lib/lookbook/theme.rb
lookbook-2.0.0.rc.1 lib/lookbook/theme.rb
lookbook-2.0.0.beta.9 lib/lookbook/theme.rb
lookbook-2.0.0.beta.8 lib/lookbook/theme.rb
lookbook-2.0.0.beta.7 lib/lookbook/theme.rb
lookbook-2.0.0.beta.6 lib/lookbook/theme.rb
lookbook-2.0.0.beta.5 lib/lookbook/theme.rb