keystone_ui 0.42.0 → 0.44.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: 399e1a496d6abbf8fc37149cbf05ea62223222c1cf6b5678dc400b286a17f06a
4
+ data.tar.gz: 5d7566e89343b57e8a35a6693e4fe6107184203299a880d58eab541b6ff16d81
5
5
  SHA512:
6
- metadata.gz: 3e63c3495c2b1709109cb25584e9a9e5c5b7fcaef4cfb1cc1e948641b5ae06a22acc3703f52d038d69a7371b57d39a554d75a8ac671e90662f525734979ab8fd
7
- data.tar.gz: 8941b3263e4944bbfc4e6d6dbc8eb82f74908ee51b922f9c6f61b6cb9c4af869171c22b8e5cbdc4bef6e7c238e740d2f531b143cd5abaddba2a5d73b36d34b1a
6
+ metadata.gz: e0e0ab5ac2704a8612ec78bd80987d61ddfaee104cf0eedf976075e8ea28b4d64ac26990e061055165d334f06c8951b0eb8083b6005cb666dd8d47fec7ec5a7f
7
+ data.tar.gz: 8de679cd46c03c8c8856196fc1d73d87def5ab3910c7b142d744ab7fca02c8b011f0cea93a2a2b42979d677b84c7448c32880d2ab6783851506188622bba7c30
@@ -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)
@@ -0,0 +1,11 @@
1
+ <dl class="<%= classes %>">
2
+ <% rows.each do |row| %>
3
+ <div class="<%= row_classes(row) %>">
4
+ <dt class="ks-value-list-label">
5
+ <%= row[:label] %>
6
+ <% if row[:note] %><span class="ks-value-list-note"><%= row[:note] %></span><% end %>
7
+ </dt>
8
+ <dd class="ks-value-list-value"><%= shown_value(row) %></dd>
9
+ </div>
10
+ <% end %>
11
+ </dl>
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Keystone
4
+ module Ui
5
+ class ValueListComponent < ViewComponent::Base
6
+ ALIGN_CLASSES = { start: nil, end: "ks-value-list-end" }.freeze
7
+
8
+ attr_reader :rows
9
+
10
+ def initialize(rows:, align: :start)
11
+ @rows = rows
12
+ @align = align
13
+ end
14
+
15
+ def classes
16
+ [ "ks-value-list", ALIGN_CLASSES.fetch(@align) ].compact.join(" ")
17
+ end
18
+
19
+ def shown_value(row)
20
+ row[:value].to_s.empty? ? row[:fallback] : row[:value]
21
+ end
22
+
23
+ def row_classes(row)
24
+ [ "ks-value-list-row", ("ks-value-list-total" if row[:total]) ].compact.join(" ")
25
+ end
26
+ end
27
+ end
28
+ end
@@ -249,6 +249,10 @@ module KeystoneUiHelper
249
249
  render Keystone::Ui::ParagraphComponent.new(**args)
250
250
  end
251
251
 
252
+ def ui_value_list(**args)
253
+ render Keystone::Ui::ValueListComponent.new(**args)
254
+ end
255
+
252
256
  def ui_info(**args, &block)
253
257
  render(Keystone::Ui::InfoComponent.new(**args), &block)
254
258
  end
@@ -32,6 +32,7 @@ module Keystone
32
32
  Keystone::Ui::CardLinkComponent,
33
33
  Keystone::Ui::InputComponent,
34
34
  Keystone::Ui::TextareaComponent,
35
+ Keystone::Ui::ValueListComponent,
35
36
  Keystone::Ui::FormFieldComponent,
36
37
  Keystone::Ui::PageHeaderComponent,
37
38
  Keystone::Ui::ParagraphComponent,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KeystoneUi
4
- VERSION = "0.42.0"
4
+ VERSION = "0.44.0"
5
5
  end
@@ -66,6 +66,7 @@ not available in the app yet, that is `keystone_ui-install`'s job.
66
66
  - `ui_heading` — a heading at one of three sizes, with an optional short note on its right.
67
67
  - `ui_caption` — small uppercase muted text placed above a title or a figure.
68
68
  - `ui_paragraph` — a paragraph of running text.
69
+ - `ui_value_list` — rows of a label and its value, such as a ledger or a byline.
69
70
  - `ui_alert` — a banner message, optionally dismissible.
70
71
  - `ui_progress` — a labelled progress bar.
71
72
  - `ui_stat_card` — a single metric tile with optional change, link and info button.
@@ -404,6 +405,9 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
404
405
  and `note:` puts a short muted note at the right end of the heading's row.
405
406
  - `ui_caption(text:)` shows small uppercase muted text above a title or a figure.
406
407
  - `ui_paragraph(text:)` shows running text.
408
+ - `ui_value_list(rows:, align: :start)` — each row is `{ label:, value: }`
409
+ with optional `note:`, `total: true` and `fallback:`, shown when the value
410
+ is `nil` or empty. `align: :end` pushes values to the right, as in a ledger.
407
411
 
408
412
  10. Explain figures.
409
413
 
@@ -67,6 +67,7 @@ develop:
67
67
  - ui_heading
68
68
  - ui_caption
69
69
  - ui_paragraph
70
+ - ui_value_list
70
71
  - ui_breakdown
71
72
  - ui_theme_toggle
72
73
  - Keystone::Ui::Column
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.44.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Schneider
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 0.19.0
18
+ version: 0.20.0
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: 0.19.0
25
+ version: 0.20.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: view_component
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -202,6 +202,8 @@ files:
202
202
  - app/components/keystone/ui/textarea_component.rb
203
203
  - app/components/keystone/ui/theme_toggle_component.html.erb
204
204
  - app/components/keystone/ui/theme_toggle_component.rb
205
+ - app/components/keystone/ui/value_list_component.html.erb
206
+ - app/components/keystone/ui/value_list_component.rb
205
207
  - app/helpers/keystone_ui_helper.rb
206
208
  - config/importmap.rb
207
209
  - lib/generators/keystone/install_generator.rb