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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4bf4475ba64978e58e6321ac224b3912cf463dae75462ee3372f86faf4b69799
4
- data.tar.gz: ee8c23fdd9a81b0b4abd8a097371a4720b8327e2c719c6b1a5cb84ea21a22962
3
+ metadata.gz: ec9db03b8817d60855f31922f8b666e572b4912a4874a3743162b65848c4fb49
4
+ data.tar.gz: 2c9af63f8072aa5a2a1a3b3c1e309f0ef8128ff791877d47e3c68b4724fc1ccf
5
5
  SHA512:
6
- metadata.gz: abdb896617cba586d6906624bb2e30434ad40ccd2c1a12d589284ca43149056724c4ecb6dad7cb4a27915f3dad846e64b2a12bc3efa5a0d0fe82378aaf6494ad
7
- data.tar.gz: 00d0ce8bd9933e5f3500d3ac0dfa57a068ae8c3923371943e398122f179e508fe5c7bd39b308df15a92eda836e50a41693be5e295e5a7c1bd3f6aea1bf2a57af
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Kiso
4
4
  # @return [String] the current gem version
5
- VERSION = "0.5.0.pre"
5
+ VERSION = "0.5.1.pre"
6
6
  end
data/lib/kiso.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require "class_variants"
4
4
  require "tailwind_merge"
5
5
  require "kiso/version"
6
+ require "kiso/color_utils"
6
7
  require "kiso/configuration"
7
8
  require "kiso/presets"
8
9
  require "kiso/theme_overrides"
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.0.pre
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