-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from evvnt/f/dynamic-theme-selection
Make theme selection dynamic
- Loading branch information
Showing
21 changed files
with
9,401 additions
and
14,804 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,5 @@ | |
.rspec_status | ||
/views/theme/node_modules/ | ||
/views/theme/npm-debug.log | ||
|
||
**/.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ GEM | |
rake (12.3.3) | ||
|
||
PLATFORMS | ||
arm64-darwin-21 | ||
x86_64-darwin-20 | ||
x86_64-linux | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
module Coprl | ||
module Presenters | ||
module Plugins | ||
module Theme | ||
class DefaultPalette | ||
|
||
COLORS = { | ||
primary10: '#49040E', | ||
primary9: '#790618', | ||
primary8: '#AA0921', | ||
primary7: '#CA0826', | ||
primary6: '#DC1F3C', | ||
primary: '#DC1F3C', | ||
primary5: '#F53855', | ||
primary4: '#F6556E', | ||
primary3: '#F98697', | ||
primary2: '#FBB6C1', | ||
primary1: '#FEE7EA', | ||
|
||
neutral10: '#090E11', | ||
neutral9: '#1B2932', | ||
neutral8: '#253944', | ||
neutral7: '#324D5C', | ||
neutral6: '#517C95', | ||
neutral5: '#6A96AE', | ||
neutral4: '#8BADC0', | ||
neutral3: '#ACC5D2', | ||
neutral2: '#CDDCE4', | ||
neutral1: '#EBF0F3', | ||
|
||
secondary14: '#00B587', | ||
secondary13: '#00E676', | ||
secondary12: '#69F0AE', | ||
secondary11: '#B9F6CA', | ||
secondary10: '#006064', | ||
secondary9: '#00838F', | ||
secondary8: '#0097A7', | ||
secondary7: '#00ACC1', | ||
secondary6: '#00BCD4', | ||
secondary: '#00ACC1', | ||
secondary5: '#26C6DA', | ||
secondary4: '#4DD0E1', | ||
secondary3: '#80DEEA', | ||
secondary2: '#9EF9E8', | ||
secondary1: '#E0F7FA', | ||
|
||
red10: '#B71C1C', | ||
red9: '#C62828', | ||
red8: '#D32F2F', | ||
red7: '#E53935', | ||
red6: '#F44336', | ||
red5: '#E55350', | ||
red4: '#E57373', | ||
red3: '#EF9A9A', | ||
red2: '#FFCDD2', | ||
red1: '#FFEBEE', | ||
|
||
yellow10: '#F57F17', | ||
yellow9: '#F9A825', | ||
yellow8: '#FBC02D', | ||
yellow7: '#FDD835', | ||
yellow6: '#FFEB3B', | ||
yellow5: '#FFEE58', | ||
yellow4: '#FFF176', | ||
yellow3: '#FFF59D', | ||
yellow2: '#FFF9C4', | ||
yellow1: '#FFFDE7', | ||
|
||
green10: '#1B5E20', | ||
green9: '#2E7D32', | ||
green8: '#388E3C', | ||
green7: '#43A047', | ||
green6: '#4CAF50', | ||
green5: '#66BB6A', | ||
green4: '#81C784', | ||
green3: '#A5D6A7', | ||
green2: '#C8E6C9', | ||
green1: '#E8F5E9' | ||
}.freeze | ||
|
||
FONTS = { | ||
default: 'Roboto' | ||
} | ||
|
||
def self.[](key) | ||
COLORS[key] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
require_relative 'default_palette' | ||
|
||
module Coprl | ||
module Presenters | ||
module Plugins | ||
module Theme | ||
class Palette | ||
attr_reader :primary_color, :secondary_color | ||
|
||
def initialize(primary_color:, secondary_color:) | ||
@primary_color = primary_color | ||
@secondary_color = secondary_color | ||
end | ||
|
||
def palette(color_code) | ||
locate_color(color_code) | ||
end | ||
|
||
def [](key) | ||
locate_color(key) | ||
end | ||
|
||
private | ||
|
||
def locate_color(color_code) | ||
if primary_color.present? && color_code.to_s.starts_with?('primary') | ||
return primary_color_hash[color_code] || DefaultPalette::COLORS[color_code] | ||
end | ||
|
||
if secondary_color.present? && color_code.to_s.starts_with?('secondary') | ||
return secondary_color_hash[color_code] || DefaultPalette::COLORS[color_code] | ||
end | ||
|
||
return DefaultPalette::COLORS[color_code] if DefaultPalette::COLORS[color_code].present? | ||
|
||
raise(Errors::ParameterValidation, "Failed to locate color for: #{color_code}") | ||
end | ||
|
||
def primary_color_hash | ||
@primary_color_hash ||= primary_color.present? ? generate_primary_color_hash : {} | ||
end | ||
|
||
def secondary_color_hash | ||
@secondary_color_hash ||= secondary_color.present? ? generate_secondary_color_hash : {} | ||
end | ||
|
||
def generate_primary_color_hash | ||
{ | ||
primary10: darken_color(primary_color, 0.4), | ||
primary9: darken_color(primary_color, 0.5), | ||
primary8: darken_color(primary_color, 0.6), | ||
primary7: darken_color(primary_color, 0.7), | ||
primary6: primary_color, | ||
primary: primary_color, | ||
primary5: lighten_color(primary_color, 0.2), | ||
primary4: lighten_color(primary_color, 0.4), | ||
primary3: lighten_color(primary_color, 0.5), | ||
primary2: lighten_color(primary_color, 0.6), | ||
primary1: lighten_color(primary_color, 0.8) | ||
} | ||
end | ||
|
||
def generate_secondary_color_hash | ||
{ | ||
secondary14: darken_color(secondary_color, 0.2), | ||
secondary13: darken_color(secondary_color, 0.3), | ||
secondary12: darken_color(secondary_color, 0.4), | ||
secondary11: darken_color(secondary_color, 0.5), | ||
secondary10: darken_color(secondary_color, 0.6), | ||
secondary9: darken_color(secondary_color, 0.7), | ||
secondary8: darken_color(secondary_color, 0.8), | ||
secondary7: darken_color(secondary_color, 0.9), | ||
secondary6: secondary_color, | ||
secondary: secondary_color, | ||
secondary5: lighten_color(secondary_color, 0.2), | ||
secondary4: lighten_color(secondary_color, 0.4), | ||
secondary3: lighten_color(secondary_color, 0.5), | ||
secondary2: lighten_color(secondary_color, 0.6), | ||
secondary1: lighten_color(secondary_color, 0.7) | ||
} | ||
end | ||
|
||
def darken_color(hex_color, amount) | ||
hex_color = hex_color.gsub('#','') | ||
rgb = hex_color.scan(/../).map {|color| color.hex} | ||
rgb[0] = (rgb[0].to_i * amount).round | ||
rgb[1] = (rgb[1].to_i * amount).round | ||
rgb[2] = (rgb[2].to_i * amount).round | ||
"#%02x%02x%02x" % rgb | ||
end | ||
|
||
# Amount should be a decimal between 0 and 1. Higher means lighter | ||
def lighten_color(hex_color, amount) | ||
hex_color = hex_color.gsub('#','') | ||
rgb = hex_color.scan(/../).map {|color| color.hex} | ||
rgb[0] = [(rgb[0].to_i + 255 * amount).round, 255].min | ||
rgb[1] = [(rgb[1].to_i + 255 * amount).round, 255].min | ||
rgb[2] = [(rgb[2].to_i + 255 * amount).round, 255].min | ||
"#%02x%02x%02x" % rgb | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.