keystone_ui 0.42.0 → 0.43.0

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: 28436277e0b304a48d5093a2220bb1df0e04f94315f085781e93cb34207ea654
4
- data.tar.gz: 82bb8f8de9b4132f47da04e7ab3423ba3c73e216b2ae79659f8709b52888bfde
3
+ metadata.gz: ebff0095e42a243e35a441d1fd749813728e8abe011529ec23cb599602312c45
4
+ data.tar.gz: 0fc80932c6f8b9ea4c8511fa4ba83e9989eb97e4a74cbe9339999efdd8f62249
5
5
  SHA512:
6
- metadata.gz: 3e63c3495c2b1709109cb25584e9a9e5c5b7fcaef4cfb1cc1e948641b5ae06a22acc3703f52d038d69a7371b57d39a554d75a8ac671e90662f525734979ab8fd
7
- data.tar.gz: 8941b3263e4944bbfc4e6d6dbc8eb82f74908ee51b922f9c6f61b6cb9c4af869171c22b8e5cbdc4bef6e7c238e740d2f531b143cd5abaddba2a5d73b36d34b1a
6
+ metadata.gz: f9b81f7b07775c5ba362010016b5dacd0bb9a298620723cb20fee5fbd2ee96da12211256da33f4bb72029e8bfcc3392e6b5d42fad8efceb33a48d11642cbf99a
7
+ data.tar.gz: b0debeea715db19ec6aaac0731abd03bd7f4670a9f2a979f0a541a72588cccb2324b2569f3962c70812af5b0c514af17e57adcb46de28f509a27a173b84cd2fc
@@ -1,7 +1,7 @@
1
1
  import { Controller } from "@hotwired/stimulus"
2
2
 
3
3
  export default class extends Controller {
4
- static targets = ["swatch", "hexLabel", "input", "panel", "svArea", "svGradient", "svCursor", "hueSlider"]
4
+ static targets = ["swatch", "text", "input", "panel", "svArea", "svGradient", "svCursor", "hueSlider"]
5
5
  static values = { value: String }
6
6
 
7
7
  connect() {
@@ -10,7 +10,7 @@ export default class extends Controller {
10
10
  this.val = 1
11
11
  this.dragging = false
12
12
 
13
- if (this.valueValue) {
13
+ if (this.isSixDigitHex(this.valueValue)) {
14
14
  this.setFromHex(this.valueValue)
15
15
  }
16
16
 
@@ -55,6 +55,16 @@ export default class extends Controller {
55
55
  this.updateColor()
56
56
  }
57
57
 
58
+ textChanged() {
59
+ const colour = this.textTarget.value
60
+ if (!CSS.supports("color", colour)) return
61
+
62
+ if (this.isSixDigitHex(colour)) this.setFromHex(colour)
63
+ this.swatchTarget.style.backgroundColor = colour
64
+ this.inputTarget.value = colour
65
+ this.inputTarget.dispatchEvent(new Event("change", { bubbles: true }))
66
+ }
67
+
58
68
  svDown(event) {
59
69
  event.preventDefault()
60
70
  this.dragging = true
@@ -92,7 +102,7 @@ export default class extends Controller {
92
102
  updateColor() {
93
103
  const hex = this.hsvToHex(this.hue, this.sat, this.val)
94
104
  this.swatchTarget.style.backgroundColor = hex
95
- this.hexLabelTarget.textContent = hex
105
+ this.textTarget.value = hex
96
106
  this.inputTarget.value = hex
97
107
 
98
108
  this.inputTarget.dispatchEvent(new Event("change", { bubbles: true }))
@@ -118,6 +128,10 @@ export default class extends Controller {
118
128
  }
119
129
  }
120
130
 
131
+ isSixDigitHex(colour) {
132
+ return /^#[0-9a-f]{6}$/i.test(colour)
133
+ }
134
+
121
135
  hsvToHex(h, s, v) {
122
136
  const c = v * s
123
137
  const x = c * (1 - Math.abs(((h / 60) % 2) - 1))
@@ -10,7 +10,7 @@
10
10
  data-color-picker-target="swatch"
11
11
  data-action="color-picker#toggle">
12
12
  </button>
13
- <span class="text-sm text-gray-500 dark:text-gray-400" data-color-picker-target="hexLabel"><%= value %></span>
13
+ <input type="text" class="<%= TEXT_FIELD_CLASSES %>" value="<%= value %>" data-color-picker-target="text" data-action="input->color-picker#textChanged">
14
14
  </div>
15
15
 
16
16
  <input type="hidden" name="<%= name %>" value="<%= value %>" data-color-picker-target="input">
@@ -9,6 +9,8 @@ module Keystone
9
9
 
10
10
  PANEL_CLASSES = "ks-color-picker-panel absolute z-50 hidden"
11
11
 
12
+ TEXT_FIELD_CLASSES = "ks-input w-28 text-sm"
13
+
12
14
  attr_reader :name, :value, :label
13
15
 
14
16
  def initialize(name:, value: "#000000", label: nil)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KeystoneUi
4
- VERSION = "0.42.0"
4
+ VERSION = "0.43.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keystone_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.42.0
4
+ version: 0.43.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Schneider