Sha256: 8ff44845654d73dee9939acd612393e1e14482838a998e4d61a710011373a3c2

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 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"
      }
    }

    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.select { |key| !key.start_with?("favicon") }.map do |key, value|
          "  --lookbook-#{key.to_s.underscore.gsub("_","-")}: #{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

1 entries across 1 versions & 1 rubygems

Version Path
lookbook-1.0.0.beta.7 lib/lookbook/theme.rb