Class: Avo::Configuration::Appearance
- Inherits:
-
Object
- Object
- Avo::Configuration::Appearance
- Defined in:
- lib/avo/configuration/appearance.rb
Constant Summary collapse
- PICKER_LAYOUTS =
[:inline, :dropdown].freeze
- DEFAULT_NEUTRALS =
%w[brand slate stone gray zinc neutral taupe mauve mist olive].freeze
- DEFAULT_ACCENTS =
%w[brand red orange amber yellow lime green emerald teal cyan sky blue indigo violet purple fuchsia pink rose].freeze
- LOCKABLE =
%i[scheme neutral accent].freeze
- NEUTRAL_SHADES =
[25, 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950].freeze
- ACCENT_TOKENS =
[:color, :content, :foreground].freeze
- ACCENT_TOKEN_VAR_NAMES =
{ color: "--color-accent", content: "--color-accent-content", foreground: "--color-accent-foreground" }.freeze
- DEFAULTS =
{ scheme: :auto, persistence: :cookie, logo: "avo/logo.png", logomark: "avo/logomark.png", favicon: "avo/favicon.ico", favicon_dark: "avo/favicon-dark.ico", chart_colors: %w[#0B8AE2 #34C683 #FFBE4F #FF7676 #2AB1EE #34C6A8 #EC8CFF #80FF91 #FFFC38 #1BDBE8], placeholder: "avo/placeholder.svg", neutrals: DEFAULT_NEUTRALS, accents: DEFAULT_ACCENTS, lock: [], picker_layout: :inline }.freeze
Instance Attribute Summary collapse
-
#accent ⇒ Object
readonly
:auto | :light | :dark.
-
#accent_colors ⇒ Object
readonly
:auto | :light | :dark.
-
#accents ⇒ Object
readonly
:auto | :light | :dark.
-
#chart_colors ⇒ Object
readonly
:auto | :light | :dark.
-
#favicon ⇒ Object
readonly
:auto | :light | :dark.
-
#favicon_dark ⇒ Object
readonly
:auto | :light | :dark.
-
#load_settings_block ⇒ Object
readonly
:auto | :light | :dark.
-
#lock ⇒ Object
readonly
:auto | :light | :dark.
-
#logo ⇒ Object
readonly
:auto | :light | :dark.
-
#logo_dark ⇒ Object
readonly
:auto | :light | :dark.
-
#logomark ⇒ Object
readonly
:auto | :light | :dark.
-
#logomark_dark ⇒ Object
readonly
:auto | :light | :dark.
-
#neutral ⇒ Object
readonly
:auto | :light | :dark.
-
#neutral_colors ⇒ Object
readonly
:auto | :light | :dark.
-
#neutrals ⇒ Object
readonly
:auto | :light | :dark.
-
#persistence ⇒ Object
readonly
:auto | :light | :dark.
-
#picker_layout ⇒ Object
readonly
:auto | :light | :dark.
-
#placeholder ⇒ Object
readonly
:auto | :light | :dark.
-
#save_settings_block ⇒ Object
readonly
:auto | :light | :dark.
-
#scheme ⇒ Object
readonly
:auto | :light | :dark.
Instance Method Summary collapse
-
#accent_css_class ⇒ Object
Returns the accent name for the data attribute (nil when accent is unset).
- #accent_locked? ⇒ Boolean
-
#brand_css_overrides ⇒ Object
Returns the inline CSS string that overrides brand vars at :root when neutral_colors / accent_colors are configured.
- #database_persistence? ⇒ Boolean
-
#initialize(options = {}) ⇒ Appearance
constructor
A new instance of Appearance.
-
#neutral_css_class ⇒ Object
Returns the neutral name for the data attribute (nil when neutral is unset).
- #neutral_locked? ⇒ Boolean
- #scheme_locked? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Appearance
Returns a new instance of Appearance.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/avo/configuration/appearance.rb', line 57 def initialize( = {}) config = DEFAULTS.merge() @scheme = config[:scheme] @neutral = config[:neutral] @accent = config[:accent] @neutral_colors = config[:neutral_colors] @accent_colors = config[:accent_colors] @neutrals = Array(config[:neutrals]).map(&:to_s).freeze @accents = Array(config[:accents]).map(&:to_s).freeze @lock = Array(config[:lock]).map(&:to_sym).freeze @persistence = config[:persistence] @logo = config[:logo] @logo_dark = config[:logo_dark] @logomark = config[:logomark] @logomark_dark = config[:logomark_dark] @favicon = config[:favicon] @favicon_dark = config[:favicon_dark] @chart_colors = config[:chart_colors] @placeholder = config[:placeholder] @picker_layout = config[:picker_layout] @load_settings_block = config[:load_settings] @save_settings_block = config[:save_settings] validate_picker_layout!(@picker_layout) validate_selection!("neutral", @neutral) validate_selection!("accent", @accent) validate_color_palette!("neutral_colors", @neutral_colors, NEUTRAL_SHADES, "shades") if @neutral_colors validate_color_palette!("accent_colors", @accent_colors, ACCENT_TOKENS, "tokens") if @accent_colors end |
Instance Attribute Details
#accent ⇒ Object (readonly)
:auto | :light | :dark
2 3 4 |
# File 'lib/avo/configuration/appearance.rb', line 2 def accent @accent end |
#accent_colors ⇒ Object (readonly)
:auto | :light | :dark
2 3 4 |
# File 'lib/avo/configuration/appearance.rb', line 2 def accent_colors @accent_colors end |
#accents ⇒ Object (readonly)
:auto | :light | :dark
2 3 4 |
# File 'lib/avo/configuration/appearance.rb', line 2 def accents @accents end |
#chart_colors ⇒ Object (readonly)
:auto | :light | :dark
2 3 4 |
# File 'lib/avo/configuration/appearance.rb', line 2 def chart_colors @chart_colors end |
#favicon ⇒ Object (readonly)
:auto | :light | :dark
2 3 4 |
# File 'lib/avo/configuration/appearance.rb', line 2 def favicon @favicon end |
#favicon_dark ⇒ Object (readonly)
:auto | :light | :dark
2 3 4 |
# File 'lib/avo/configuration/appearance.rb', line 2 def favicon_dark @favicon_dark end |
#load_settings_block ⇒ Object (readonly)
:auto | :light | :dark
2 3 4 |
# File 'lib/avo/configuration/appearance.rb', line 2 def load_settings_block @load_settings_block end |
#lock ⇒ Object (readonly)
:auto | :light | :dark
2 3 4 |
# File 'lib/avo/configuration/appearance.rb', line 2 def lock @lock end |
#logo ⇒ Object (readonly)
:auto | :light | :dark
2 3 4 |
# File 'lib/avo/configuration/appearance.rb', line 2 def logo @logo end |
#logo_dark ⇒ Object (readonly)
:auto | :light | :dark
2 3 4 |
# File 'lib/avo/configuration/appearance.rb', line 2 def logo_dark @logo_dark end |
#logomark ⇒ Object (readonly)
:auto | :light | :dark
2 3 4 |
# File 'lib/avo/configuration/appearance.rb', line 2 def logomark @logomark end |
#logomark_dark ⇒ Object (readonly)
:auto | :light | :dark
2 3 4 |
# File 'lib/avo/configuration/appearance.rb', line 2 def logomark_dark @logomark_dark end |
#neutral ⇒ Object (readonly)
:auto | :light | :dark
2 3 4 |
# File 'lib/avo/configuration/appearance.rb', line 2 def neutral @neutral end |
#neutral_colors ⇒ Object (readonly)
:auto | :light | :dark
2 3 4 |
# File 'lib/avo/configuration/appearance.rb', line 2 def neutral_colors @neutral_colors end |
#neutrals ⇒ Object (readonly)
:auto | :light | :dark
2 3 4 |
# File 'lib/avo/configuration/appearance.rb', line 2 def neutrals @neutrals end |
#persistence ⇒ Object (readonly)
:auto | :light | :dark
2 3 4 |
# File 'lib/avo/configuration/appearance.rb', line 2 def persistence @persistence end |
#picker_layout ⇒ Object (readonly)
:auto | :light | :dark
2 3 4 |
# File 'lib/avo/configuration/appearance.rb', line 2 def picker_layout @picker_layout end |
#placeholder ⇒ Object (readonly)
:auto | :light | :dark
2 3 4 |
# File 'lib/avo/configuration/appearance.rb', line 2 def placeholder @placeholder end |
#save_settings_block ⇒ Object (readonly)
:auto | :light | :dark
2 3 4 |
# File 'lib/avo/configuration/appearance.rb', line 2 def save_settings_block @save_settings_block end |
#scheme ⇒ Object (readonly)
:auto | :light | :dark
2 3 4 |
# File 'lib/avo/configuration/appearance.rb', line 2 def scheme @scheme end |
Instance Method Details
#accent_css_class ⇒ Object
Returns the accent name for the data attribute (nil when accent is unset)
100 |
# File 'lib/avo/configuration/appearance.rb', line 100 def accent_css_class = accent&.to_s |
#accent_locked? ⇒ Boolean
94 |
# File 'lib/avo/configuration/appearance.rb', line 94 def accent_locked? = @lock.include?(:accent) |
#brand_css_overrides ⇒ Object
Returns the inline CSS string that overrides brand vars at :root when neutral_colors / accent_colors are configured. Returns nil when neither is set so the layout can skip emitting the