kiso 0.5.0.pre → 0.5.1.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/views/kiso/components/_avatar.html.erb +2 -1
- data/lib/kiso/color_utils.rb +21 -0
- data/lib/kiso/version.rb +1 -1
- data/lib/kiso.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ec9db03b8817d60855f31922f8b666e572b4912a4874a3743162b65848c4fb49
|
|
4
|
+
data.tar.gz: 2c9af63f8072aa5a2a1a3b3c1e309f0ef8128ff791877d47e3c68b4724fc1ccf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1556e351f329cb486292d199a857b9bde20648c76168e0f0dc3b21485cbaaa347f658b45dfc670384f53bfa651d24c47c85f04cbf79a02923c0c49bde400fd16
|
|
7
|
+
data.tar.gz: 602821bc77a6273cd8e7fe5995f18eb9eaadf2d76f7e603874236b7fea7611bf014b7dfc4894045f574ed97021a4ebfd455daa7c481e2fe82284d4ee0a0bafbd
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
<%# locals: (src: nil, alt: "", text: nil, size: :md, color: nil, ui: {}, css_classes: "", **component_options) %>
|
|
2
|
+
<% text_color = Kiso::ColorUtils.contrast_text_color(color) if color %>
|
|
2
3
|
<%= content_tag :span,
|
|
3
4
|
class: Kiso::Themes::Avatar.render(size: size, class: css_classes),
|
|
4
|
-
style: (color ? "background-color: #{color};" : nil),
|
|
5
|
+
style: (color ? "background-color: #{color}; color: #{text_color};" : nil),
|
|
5
6
|
data: kiso_prepare_options(component_options, slot: "avatar", size: size),
|
|
6
7
|
**component_options do %>
|
|
7
8
|
<% content = capture { yield }.presence %>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Kiso
|
|
4
|
+
module ColorUtils
|
|
5
|
+
module_function
|
|
6
|
+
|
|
7
|
+
# Returns "white" or "black" based on WCAG relative luminance.
|
|
8
|
+
# Accepts 3-digit (#abc) or 6-digit (#aabbcc) hex strings.
|
|
9
|
+
def contrast_text_color(hex)
|
|
10
|
+
hex = hex.delete("#")
|
|
11
|
+
hex = hex.chars.map { |c| c * 2 }.join if hex.length == 3
|
|
12
|
+
|
|
13
|
+
r, g, b = hex.scan(/../).map { |c| c.to_i(16) / 255.0 }
|
|
14
|
+
luminance = [r, g, b].map { |c|
|
|
15
|
+
(c <= 0.04045) ? c / 12.92 : ((c + 0.055) / 1.055)**2.4
|
|
16
|
+
}.then { |lr, lg, lb| 0.2126 * lr + 0.7152 * lg + 0.0722 * lb }
|
|
17
|
+
|
|
18
|
+
(luminance > 0.179) ? "black" : "white"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/kiso/version.rb
CHANGED
data/lib/kiso.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: kiso
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.1.pre
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Steve Clarke
|
|
@@ -343,6 +343,7 @@ files:
|
|
|
343
343
|
- lib/kiso/cli/icons.rb
|
|
344
344
|
- lib/kiso/cli/main.rb
|
|
345
345
|
- lib/kiso/cli/make.rb
|
|
346
|
+
- lib/kiso/color_utils.rb
|
|
346
347
|
- lib/kiso/configuration.rb
|
|
347
348
|
- lib/kiso/engine.rb
|
|
348
349
|
- lib/kiso/presets.rb
|