klods-ruby 1.8.0 → 1.9.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: 87a5f902747bd81956d30a633be0110f491143f9e654c5f31f19947055ae2688
4
- data.tar.gz: 715ebbf52e2ca26a5de3c2bb4ec595fd0317edde2cd98dde9aa4b70378d1037c
3
+ metadata.gz: 11f7d4a6457d9dfa17e344a1a3573db08040760ad3f4513b7d1a9db9715e73c8
4
+ data.tar.gz: 567d112587e59c9c022e43cf4b89c82c5826db2fea27f0407c906842e7f60ca0
5
5
  SHA512:
6
- metadata.gz: cab19f6703c6d3b0bfeed4efbd5a7c12e329ab84b8d56d6dfe86c4863289f4da7405fd37128f05bdc2ee5329deb0e6d8922c6ed42808bd15275d7b52faa488f8
7
- data.tar.gz: a14b0b42e520982a0ac50976b26d5011b5b77521baedef77654fdb0ed7da9c0cd021869287c98c8c31f1e5321fe55e17868c50735e093a28964b5dbb95deed9c
6
+ metadata.gz: 655d9db0706f57969ed44d85509d942430580cc9c7f516c52f3635c316ea540fdf4dae2268a18b1f0cea9717171a7373e09eee52387d729f3baf57e2dd482e47
7
+ data.tar.gz: 8fcc410fa3e6849faa8e44b77b777b8589c79d233f5e79c5d469b4a6855eebf30753125a9ab4986872b8b3abbcaee0b41bbf87821d0d236bb2a50b2a2a4d555e
@@ -19,6 +19,7 @@ module Klods
19
19
  include Klods::Components::Modal
20
20
  include Klods::Components::Nav
21
21
  include Klods::Components::Prose
22
+ include Klods::Components::Segmented
22
23
  include Klods::Components::Status
23
24
  include Klods::Components::Toc
24
25
  include Klods::Components::Table
@@ -0,0 +1,42 @@
1
+ module Klods
2
+ module Components
3
+ # A row of radio buttons drawn as one pill, for picking one of a few short
4
+ # options. Arrow keys move between them, and the choice is sent with a form.
5
+ #
6
+ # segmented({name: "theme", label: "Theme", value: "auto",
7
+ # options: [{label: "Auto", value: "auto"}, {label: "Dark", value: "dark"}]})
8
+ # segmented({name: "view", "aria-labelledby": "view-label", options: ["Day", "Week"]})
9
+ #
10
+ # An option is a string (its text and value) or a hash with label, and
11
+ # optionally value and disabled. Use label: to name the group for screen
12
+ # readers, or aria-labelledby when a visible label names it.
13
+ module Segmented
14
+ def segmented(props)
15
+ props = props.transform_keys(&:to_s)
16
+ name = props.delete("name")
17
+ options = props.delete("options") || []
18
+ value = props.delete("value")
19
+ label = props.delete("label")
20
+ disabled = props.delete("disabled")
21
+ extra_class = props.delete("class")
22
+
23
+ items = options.map do |option|
24
+ option = option.is_a?(Hash) ? option.transform_keys(&:to_s) : {"label" => option}
25
+ text = option["label"]
26
+ option_value = option.fetch("value", text)
27
+
28
+ input_attrs = {"type" => "radio", "class" => "klods-segmented__input", "name" => name, "value" => option_value}
29
+ input_attrs["checked"] = true if option_value == value
30
+ input_attrs["disabled"] = true if disabled || option["disabled"]
31
+ Core.el("label", {"class" => "klods-segmented__option"}, [Node.new("input", input_attrs), text])
32
+ end
33
+
34
+ cls = Core.class_names("klods-segmented", Core.resolve_class(extra_class))
35
+ attrs = props.merge("role" => "radiogroup")
36
+ attrs["aria-label"] = label unless label.nil?
37
+ attrs["class"] = cls.empty? ? nil : cls
38
+ Core.el("div", attrs.compact, items)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -14,6 +14,7 @@ require_relative "components/list"
14
14
  require_relative "components/modal"
15
15
  require_relative "components/nav"
16
16
  require_relative "components/prose"
17
+ require_relative "components/segmented"
17
18
  require_relative "components/status"
18
19
  require_relative "components/table"
19
20
  require_relative "components/tabs"
data/lib/klods/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Klods
2
- VERSION = "1.8.0"
2
+ VERSION = "1.9.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: klods-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Drue Wilding
@@ -93,6 +93,7 @@ files:
93
93
  - lib/klods/components/modal.rb
94
94
  - lib/klods/components/nav.rb
95
95
  - lib/klods/components/prose.rb
96
+ - lib/klods/components/segmented.rb
96
97
  - lib/klods/components/status.rb
97
98
  - lib/klods/components/table.rb
98
99
  - lib/klods/components/tabs.rb