primer_view_components 0.0.118 → 0.0.119

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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/app/assets/javascripts/primer_view_components.js +1 -1
  4. data/app/assets/javascripts/primer_view_components.js.map +1 -1
  5. data/app/assets/styles/primer_view_components.css +1 -1
  6. data/app/assets/styles/primer_view_components.css.map +1 -1
  7. data/app/components/primer/alpha/action_list/item.rb +1 -1
  8. data/app/components/primer/alpha/action_list.rb +1 -1
  9. data/app/components/primer/alpha/dialog.rb +2 -2
  10. data/app/components/primer/alpha/text_field.css +1 -1
  11. data/app/components/primer/alpha/text_field.css.json +1 -1
  12. data/app/components/primer/alpha/text_field.css.map +1 -1
  13. data/app/components/primer/alpha/text_field.pcss +6 -0
  14. data/app/components/primer/alpha/toggle_switch.css +1 -1
  15. data/app/components/primer/alpha/toggle_switch.css.json +1 -1
  16. data/app/components/primer/alpha/toggle_switch.css.map +1 -1
  17. data/app/components/primer/alpha/toggle_switch.html.erb +4 -2
  18. data/app/components/primer/alpha/toggle_switch.js +23 -11
  19. data/app/components/primer/alpha/toggle_switch.pcss +6 -0
  20. data/app/components/primer/alpha/toggle_switch.ts +27 -11
  21. data/app/components/primer/alpha/tool_tip.js +0 -3
  22. data/app/components/primer/alpha/tool_tip.ts +0 -4
  23. data/app/components/primer/alpha/tooltip.rb +4 -3
  24. data/app/components/primer/beta/icon_button.rb +1 -1
  25. data/app/components/primer/component.rb +4 -0
  26. data/app/components/primer/icon_button.rb +1 -1
  27. data/app/components/primer/primer.d.ts +1 -0
  28. data/app/components/primer/primer.js +1 -0
  29. data/app/components/primer/primer.ts +1 -0
  30. data/app/forms/example_toggle_switch_form.rb +1 -1
  31. data/lib/primer/forms/dsl/input.rb +1 -1
  32. data/lib/primer/forms/toggle_switch.html.erb +7 -2
  33. data/lib/primer/forms/toggle_switch.rb +2 -4
  34. data/lib/primer/forms/toggle_switch_input.d.ts +5 -0
  35. data/lib/primer/forms/toggle_switch_input.js +29 -0
  36. data/lib/primer/forms/toggle_switch_input.ts +19 -0
  37. data/lib/primer/view_components/version.rb +1 -1
  38. data/previews/primer/alpha/tooltip_preview.rb +8 -8
  39. data/previews/primer/beta/clipboard_copy_preview.rb +1 -1
  40. data/previews/primer/forms/forms_preview/example_toggle_switch_form.html.erb +3 -1
  41. data/static/arguments.json +2 -2
  42. metadata +5 -16
@@ -65,7 +65,7 @@ module Primer
65
65
 
66
66
  @system_arguments = system_arguments
67
67
 
68
- @system_arguments[:id] ||= "icon-button-#{SecureRandom.hex(4)}"
68
+ @system_arguments[:id] ||= self.class.generate_id
69
69
 
70
70
  @system_arguments[:classes] = class_names(
71
71
  "btn-octicon",
@@ -13,3 +13,4 @@ import './alpha/tab_container';
13
13
  import './time_ago_component';
14
14
  import '../../../lib/primer/forms/primer_multi_input';
15
15
  import '../../../lib/primer/forms/primer_text_field';
16
+ import '../../../lib/primer/forms/toggle_switch_input';
@@ -13,3 +13,4 @@ import './alpha/tab_container';
13
13
  import './time_ago_component';
14
14
  import '../../../lib/primer/forms/primer_multi_input';
15
15
  import '../../../lib/primer/forms/primer_text_field';
16
+ import '../../../lib/primer/forms/toggle_switch_input';
@@ -13,3 +13,4 @@ import './alpha/tab_container'
13
13
  import './time_ago_component'
14
14
  import '../../../lib/primer/forms/primer_multi_input'
15
15
  import '../../../lib/primer/forms/primer_text_field'
16
+ import '../../../lib/primer/forms/toggle_switch_input'
@@ -3,6 +3,6 @@
3
3
  # :nodoc:
4
4
  class ExampleToggleSwitchForm < Primer::Forms::ToggleSwitchForm
5
5
  def initialize(**system_arguments)
6
- super(name: :example_field, label: "Example", **system_arguments)
6
+ super(name: :example_field, label: "Example", caption: "This is an example toggle switch.", **system_arguments)
7
7
  end
8
8
  end
@@ -76,7 +76,7 @@ module Primer
76
76
 
77
77
  @input_arguments[:invalid] = "true" if invalid?
78
78
 
79
- base_id = SecureRandom.hex[0..5]
79
+ base_id = SecureRandom.uuid
80
80
 
81
81
  @ids = {}.tap do |id_map|
82
82
  id_map[:validation] = "validation-#{base_id}" if invalid?
@@ -1,9 +1,14 @@
1
- <%= content_tag(:div, **@form_group_arguments) do %>
1
+ <%= content_tag("toggle-switch-input", **@input.input_arguments) do %>
2
2
  <span style="flex-grow: 1">
3
3
  <%= builder.label(@input.name, **@input.label_arguments) do %>
4
4
  <%= @input.label %>
5
5
  <% end %>
6
- <%= render(Caption.new(input: @input)) %>
6
+
7
+ <%= content_tag(:div, data: { target: "toggle-switch-input.validationElement" }, **@input.validation_arguments) do %>
8
+ <%= content_tag(:span, @input.validation_messages.first, data: { target: "toggle-switch-input.validationMessageElement" }, **@input.validation_message_arguments) %>
9
+ <% end %>
10
+
11
+ <div><%= render(Caption.new(input: @input)) %></div>
7
12
  </span>
8
13
  <%
9
14
  csrf = @input.csrf || @view_context.form_authenticity_token(
@@ -9,10 +9,8 @@ module Primer
9
9
  def initialize(input:)
10
10
  @input = input
11
11
  @input.add_label_classes("FormControl-label")
12
-
13
- @form_group_arguments = { class: "d-flex" }
14
-
15
- @form_group_arguments[:hidden] = "hidden" if @input.hidden?
12
+ @input.add_input_classes("FormControl-toggleSwitchInput")
13
+ @input.input_arguments[:hidden] = "hidden" if @input.hidden?
16
14
  end
17
15
  end
18
16
  end
@@ -0,0 +1,5 @@
1
+ export declare class ToggleSwitchInputElement extends HTMLElement {
2
+ validationElement: HTMLElement;
3
+ validationMessageElement: HTMLElement;
4
+ connectedCallback(): void;
5
+ }
@@ -0,0 +1,29 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { controller, target } from '@github/catalyst';
8
+ let ToggleSwitchInputElement = class ToggleSwitchInputElement extends HTMLElement {
9
+ connectedCallback() {
10
+ this.addEventListener('toggleSwitchError', (event) => {
11
+ this.validationMessageElement.innerText = event.detail;
12
+ this.validationElement.removeAttribute('hidden');
13
+ });
14
+ this.addEventListener('toggleSwitchSuccess', () => {
15
+ this.validationMessageElement.innerText = '';
16
+ this.validationElement.setAttribute('hidden', 'hidden');
17
+ });
18
+ }
19
+ };
20
+ __decorate([
21
+ target
22
+ ], ToggleSwitchInputElement.prototype, "validationElement", void 0);
23
+ __decorate([
24
+ target
25
+ ], ToggleSwitchInputElement.prototype, "validationMessageElement", void 0);
26
+ ToggleSwitchInputElement = __decorate([
27
+ controller
28
+ ], ToggleSwitchInputElement);
29
+ export { ToggleSwitchInputElement };
@@ -0,0 +1,19 @@
1
+ import {controller, target} from '@github/catalyst'
2
+
3
+ @controller
4
+ export class ToggleSwitchInputElement extends HTMLElement {
5
+ @target validationElement: HTMLElement
6
+ @target validationMessageElement: HTMLElement
7
+
8
+ connectedCallback() {
9
+ this.addEventListener('toggleSwitchError', (event: Event) => {
10
+ this.validationMessageElement.innerText = (event as CustomEvent).detail
11
+ this.validationElement.removeAttribute('hidden')
12
+ })
13
+
14
+ this.addEventListener('toggleSwitchSuccess', () => {
15
+ this.validationMessageElement.innerText = ''
16
+ this.validationElement.setAttribute('hidden', 'hidden')
17
+ })
18
+ }
19
+ }
@@ -6,7 +6,7 @@ module Primer
6
6
  module VERSION
7
7
  MAJOR = 0
8
8
  MINOR = 0
9
- PATCH = 118
9
+ PATCH = 119
10
10
 
11
11
  STRING = [MAJOR, MINOR, PATCH].join(".")
12
12
  end
@@ -7,7 +7,7 @@ module Primer
7
7
  # @param type [Symbol] select [["Description", description], ["Label", label]]
8
8
  # @param direction select [s, n, e, w, ne, nw, se, sw]
9
9
  # @param tooltip_text text
10
- def playground(type: :description, direction: :s, tooltip_text: "Tooltip text")
10
+ def playground(type: :description, direction: :s, tooltip_text: "You can press a button")
11
11
  render(Primer::Beta::Button.new(id: "button-with-tooltip")) do |component|
12
12
  component.with_tooltip(text: tooltip_text, type: type, direction: direction)
13
13
  "Button"
@@ -17,7 +17,7 @@ module Primer
17
17
  # @param type [Symbol] select [["Description", description], ["Label", label]]
18
18
  # @param direction select [s, n, e, w, ne, nw, se, sw]
19
19
  # @param tooltip_text text
20
- def default(type: :description, direction: :s, tooltip_text: "Tooltip text")
20
+ def default(type: :description, direction: :s, tooltip_text: "You can press a button")
21
21
  render(Primer::Beta::Button.new(id: "button-with-tooltip")) do |component|
22
22
  component.with_tooltip(text: tooltip_text, type: type, direction: direction)
23
23
  "Button"
@@ -26,7 +26,7 @@ module Primer
26
26
 
27
27
  # @param direction select [s, n, e, w, ne, nw, se, sw]
28
28
  # @param tooltip_text text
29
- def label_tooltip_on_button_with_existing_labelledby(type: :label, direction: :s, tooltip_text: "Tooltip text")
29
+ def label_tooltip_on_button_with_existing_labelledby(type: :label, direction: :s, tooltip_text: "You can press a button")
30
30
  render(Primer::Beta::Button.new(id: "button-with-existing-label", "aria-labelledby": "existing-label-id")) do |component|
31
31
  component.with_tooltip(text: tooltip_text, type: type, direction: direction)
32
32
  "Button"
@@ -35,7 +35,7 @@ module Primer
35
35
 
36
36
  # @param direction select [s, n, e, w, ne, nw, se, sw]
37
37
  # @param tooltip_text text
38
- def description_tooltip_on_button_with_existing_describedby(type: :description, direction: :s, tooltip_text: "Tooltip text")
38
+ def description_tooltip_on_button_with_existing_describedby(type: :description, direction: :s, tooltip_text: "You can press a button")
39
39
  render(Primer::Beta::Button.new(id: "button-with-existing-description", "aria-describedby": "existing-description-id")) do |component|
40
40
  component.with_tooltip(text: tooltip_text, type: type, direction: direction)
41
41
  "Button"
@@ -56,7 +56,7 @@ module Primer
56
56
 
57
57
  # @param direction select [s, n, e, w, ne, nw, se, sw]
58
58
  # @param tooltip_text text
59
- def with_multiple_on_a_page(type: :description, direction: :s, tooltip_text: "Tooltip text")
59
+ def with_multiple_on_a_page(type: :description, direction: :s, tooltip_text: "You can press a button")
60
60
  render_with_template(
61
61
  locals: {
62
62
  type: type,
@@ -68,7 +68,7 @@ module Primer
68
68
 
69
69
  # @!group Tooltip enabled elements
70
70
  # @label Tooltip with Primer::Beta::Button
71
- def tooltip_with_button(type: :description, direction: :s, tooltip_text: "Tooltip text")
71
+ def tooltip_with_button(type: :description, direction: :s, tooltip_text: "You can press a button")
72
72
  render(Primer::Beta::Button.new(id: "button-with-tooltip")) do |component|
73
73
  component.with_tooltip(text: tooltip_text, type: type, direction: direction)
74
74
  "Button"
@@ -76,7 +76,7 @@ module Primer
76
76
  end
77
77
 
78
78
  # @label Tooltip with Primer::Beta::Link
79
- def tooltip_with_link(type: :description, direction: :s, tooltip_text: "Tooltip text")
79
+ def tooltip_with_link(type: :description, direction: :s, tooltip_text: "You can press a button")
80
80
  render(Primer::Beta::Link.new(href: "#link-with-tooltip", id: "link-with-tooltip")) do |component|
81
81
  component.with_tooltip(text: tooltip_text, type: type, direction: direction)
82
82
  "Button"
@@ -84,7 +84,7 @@ module Primer
84
84
  end
85
85
 
86
86
  # @label Tooltip with Primer::IconButton
87
- def tooltip_with_icon_button(direction: :s, tooltip_text: "Tooltip text")
87
+ def tooltip_with_icon_button(direction: :s, tooltip_text: "You can press a button")
88
88
  render(Primer::Beta::IconButton.new(icon: :search, "aria-label": tooltip_text, tooltip_direction: direction))
89
89
  end
90
90
  # @!endgroup
@@ -24,7 +24,7 @@ module Primer
24
24
  #
25
25
  # @param aria_label [String]
26
26
  # @param value [String]
27
- def text(value: "Text to copy", aria_label: "Copy text to the system clipboard")
27
+ def text(value: "Text to copy", aria_label: "Click to copy!")
28
28
  render(Primer::Beta::ClipboardCopy.new(value: value, "aria-label": aria_label)) { "Click to copy!" }
29
29
  end
30
30
 
@@ -1 +1,3 @@
1
- <%= render(ExampleToggleSwitchForm.new(csrf: "let_me_in", src: toggle_switch_index_path)) %>
1
+ <%= render(ExampleToggleSwitchForm.new(csrf: "let_me_in", src: toggle_switch_index_path, id: "success-toggle")) %>
2
+ <hr>
3
+ <%= render(ExampleToggleSwitchForm.new(csrf: "a_bad_value", src: toggle_switch_index_path, id: "error-toggle")) %>
@@ -194,7 +194,7 @@
194
194
  {
195
195
  "name": "id",
196
196
  "type": "String",
197
- "default": "`SecureRandom.hex`",
197
+ "default": "`self.class.generate_id`",
198
198
  "description": "Used internally."
199
199
  },
200
200
  {
@@ -308,7 +308,7 @@
308
308
  {
309
309
  "name": "id",
310
310
  "type": "String",
311
- "default": "`\"dialog-#{(36**3 + rand(36**4)).to_s(36)}\"`",
311
+ "default": "`self.class.generate_id`",
312
312
  "description": "The id of the dialog."
313
313
  },
314
314
  {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: primer_view_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.118
4
+ version: 0.0.119
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Open Source
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-11 00:00:00.000000000 Z
11
+ date: 2023-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -100,20 +100,6 @@ dependencies:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
102
  version: 0.6.3
103
- - !ruby/object:Gem::Dependency
104
- name: axe-core-api
105
- requirement: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - "~>"
108
- - !ruby/object:Gem::Version
109
- version: 4.2.0
110
- type: :development
111
- prerelease: false
112
- version_requirements: !ruby/object:Gem::Requirement
113
- requirements:
114
- - - "~>"
115
- - !ruby/object:Gem::Version
116
- version: 4.2.0
117
103
  - !ruby/object:Gem::Dependency
118
104
  name: benchmark-ips
119
105
  requirement: !ruby/object:Gem::Requirement
@@ -851,6 +837,9 @@ files:
851
837
  - lib/primer/forms/toggle_switch.html.erb
852
838
  - lib/primer/forms/toggle_switch.rb
853
839
  - lib/primer/forms/toggle_switch_form.rb
840
+ - lib/primer/forms/toggle_switch_input.d.ts
841
+ - lib/primer/forms/toggle_switch_input.js
842
+ - lib/primer/forms/toggle_switch_input.ts
854
843
  - lib/primer/forms/utils.rb
855
844
  - lib/primer/view_components.rb
856
845
  - lib/primer/view_components/audited.rb