primer_view_components 0.0.112 → 0.0.113

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +38 -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 +3 -1
  6. data/app/assets/styles/primer_view_components.css.map +1 -1
  7. data/app/components/primer/alpha/action_list.css +1 -1
  8. data/app/components/primer/alpha/action_list.css.json +1 -1
  9. data/app/components/primer/alpha/action_list.css.map +1 -1
  10. data/app/components/primer/alpha/action_list.pcss +0 -15
  11. data/app/components/primer/alpha/auto_complete.css +1 -1
  12. data/app/components/primer/alpha/auto_complete.css.map +1 -1
  13. data/app/components/primer/alpha/auto_complete.pcss +1 -1
  14. data/app/components/primer/alpha/banner.css +1 -1
  15. data/app/components/primer/alpha/banner.css.map +1 -1
  16. data/app/components/primer/alpha/banner.pcss +2 -2
  17. data/app/components/primer/alpha/dialog/body.rb +3 -0
  18. data/app/components/primer/alpha/dialog/footer.rb +3 -0
  19. data/app/components/primer/alpha/dialog/header.rb +3 -0
  20. data/app/components/primer/alpha/dialog.css +1 -0
  21. data/app/components/primer/alpha/dialog.css.json +1 -0
  22. data/app/components/primer/alpha/dialog.css.map +1 -0
  23. data/app/components/primer/alpha/dialog.pcss +484 -0
  24. data/app/components/primer/alpha/dialog.rb +3 -0
  25. data/app/components/primer/alpha/segmented_control.css +1 -1
  26. data/app/components/primer/alpha/segmented_control.css.map +1 -1
  27. data/app/components/primer/alpha/text_field.css +3 -0
  28. data/app/components/primer/alpha/text_field.css.json +1 -0
  29. data/app/components/primer/alpha/text_field.css.map +1 -0
  30. data/app/components/primer/alpha/text_field.pcss +683 -0
  31. data/app/components/primer/alpha/toggle_switch.d.ts +1 -1
  32. data/app/components/primer/alpha/toggle_switch.js +7 -4
  33. data/app/components/primer/alpha/toggle_switch.ts +7 -3
  34. data/app/components/primer/beta/button_group.css +1 -0
  35. data/app/components/primer/beta/button_group.css.json +1 -0
  36. data/app/components/primer/beta/button_group.css.map +1 -0
  37. data/app/components/primer/beta/button_group.pcss +92 -0
  38. data/app/components/primer/{clipboard_copy.d.ts → beta/clipboard_copy.d.ts} +0 -0
  39. data/app/components/primer/{clipboard_copy.html.erb → beta/clipboard_copy.html.erb} +0 -0
  40. data/app/components/primer/{clipboard_copy.js → beta/clipboard_copy.js} +0 -0
  41. data/app/components/primer/beta/clipboard_copy.rb +50 -0
  42. data/app/components/primer/{clipboard_copy.ts → beta/clipboard_copy.ts} +0 -0
  43. data/app/components/primer/beta/popover.css.map +1 -1
  44. data/app/components/primer/beta/popover.pcss +5 -5
  45. data/app/components/primer/beta/relative_time.rb +160 -0
  46. data/app/components/primer/button_component.css +1 -0
  47. data/app/components/primer/button_component.css.json +1 -0
  48. data/app/components/primer/button_component.css.map +1 -0
  49. data/app/components/primer/button_component.pcss +557 -0
  50. data/app/components/primer/button_component.rb +1 -1
  51. data/app/components/primer/clipboard_copy.rb +2 -43
  52. data/app/components/primer/component.rb +4 -0
  53. data/app/components/primer/local_time.d.ts +1 -1
  54. data/app/components/primer/local_time.js +1 -1
  55. data/app/components/primer/local_time.rb +3 -1
  56. data/app/components/primer/local_time.ts +1 -1
  57. data/app/components/primer/primer.d.ts +1 -1
  58. data/app/components/primer/primer.js +1 -1
  59. data/app/components/primer/primer.pcss +10 -0
  60. data/app/components/primer/primer.ts +1 -1
  61. data/app/components/primer/time_ago_component.d.ts +1 -1
  62. data/app/components/primer/time_ago_component.js +1 -1
  63. data/app/components/primer/time_ago_component.rb +2 -1
  64. data/app/components/primer/time_ago_component.ts +1 -1
  65. data/app/forms/submit_button_form.rb +8 -2
  66. data/app/helpers/primer/form_helper.rb +12 -0
  67. data/lib/postcss_mixins/clearfix.pcss +12 -0
  68. data/lib/primer/deprecations.rb +96 -26
  69. data/lib/primer/deprecations.yml +68 -0
  70. data/lib/primer/forms/base.rb +7 -20
  71. data/lib/primer/forms/base_component.rb +15 -1
  72. data/lib/primer/forms/button.html.erb +4 -0
  73. data/lib/primer/forms/button.rb +68 -0
  74. data/lib/primer/forms/check_box.html.erb +2 -2
  75. data/lib/primer/forms/check_box.rb +1 -1
  76. data/lib/primer/forms/check_box_group.html.erb +2 -2
  77. data/lib/primer/forms/dsl/button_input.rb +29 -0
  78. data/lib/primer/forms/dsl/input_methods.rb +7 -2
  79. data/lib/primer/forms/dsl/submit_button_input.rb +1 -0
  80. data/lib/primer/forms/dsl/text_field_input.rb +0 -7
  81. data/lib/primer/forms/radio_button.html.erb +2 -2
  82. data/lib/primer/forms/radio_button.rb +1 -1
  83. data/lib/primer/forms/radio_button_group.html.erb +2 -2
  84. data/lib/primer/forms/select_list.html.erb +1 -1
  85. data/lib/primer/forms/select_list.rb +4 -1
  86. data/lib/primer/forms/submit_button.html.erb +1 -4
  87. data/lib/primer/forms/submit_button.rb +1 -37
  88. data/lib/primer/forms/text_area.html.erb +1 -1
  89. data/lib/primer/forms/text_area.rb +5 -1
  90. data/lib/primer/forms/text_field.html.erb +1 -1
  91. data/lib/primer/forms/text_field.rb +11 -0
  92. data/lib/primer/forms/utils.rb +28 -0
  93. data/lib/primer/view_components/audited.rb +14 -0
  94. data/lib/primer/view_components/engine.rb +1 -0
  95. data/lib/primer/view_components/linters/clipboard_copy_component_migration_counter.rb +2 -2
  96. data/lib/primer/view_components/linters/helpers/deprecated_components_helpers.rb +3 -18
  97. data/lib/primer/view_components/version.rb +1 -1
  98. data/lib/rubocop/cop/primer/component_name_migration.rb +2 -2
  99. data/lib/tasks/docs.rake +3 -2
  100. data/previews/primer/alpha/auto_complete_preview.rb +12 -0
  101. data/previews/primer/alpha/segmented_control_preview.rb +9 -6
  102. data/previews/primer/alpha/text_field_preview.rb +77 -52
  103. data/previews/primer/beta/clipboard_copy_preview/element.html.erb +2 -0
  104. data/previews/primer/beta/clipboard_copy_preview.rb +39 -0
  105. data/previews/primer/beta/relative_time_preview.rb +271 -0
  106. data/previews/primer/forms/forms_preview.rb +1 -0
  107. data/static/arguments.json +143 -33
  108. data/static/audited_at.json +6 -4
  109. data/static/constants.json +124 -0
  110. data/static/statuses.json +4 -2
  111. metadata +34 -8
  112. data/previews/primer/clipboard_copy_preview/element.html.erb +0 -2
  113. data/previews/primer/clipboard_copy_preview.rb +0 -37
@@ -4,46 +4,10 @@ module Primer
4
4
  module Forms
5
5
  # :nodoc:
6
6
  class SubmitButton < BaseComponent
7
- # :nodoc:
8
- module SubmitAttributeGenerator
9
- extend ActionView::Helpers::FormTagHelper
10
-
11
- class << self
12
- alias submit_tag_attributes submit_tag
13
-
14
- private
15
-
16
- # FormTagHelper#submit_tag ultimately calls the #tag method. We return the options hash here instead
17
- # of returning a string so it can be merged into the hash of options we pass to the Primer::ButtonComponent.
18
- def tag(_name, options)
19
- options
20
- end
21
- end
22
- end
23
-
24
7
  delegate :builder, :form, to: :@input
25
8
 
26
9
  def initialize(input:)
27
- @input = input
28
- @input.add_input_classes("FormField-input flex-self-start")
29
- @input.merge_input_arguments!(
30
- SubmitAttributeGenerator.submit_tag_attributes(input.label, name: input.name).deep_symbolize_keys
31
- )
32
-
33
- # rails uses a string for this, but PVC wants a symbol
34
- @input.merge_input_arguments!(type: :submit)
35
-
36
- # Never disable submit buttons. This overrides the global
37
- # ActionView::Base.automatically_disable_submit_tag setting.
38
- # Disabling the submit button is not accessible.
39
- @input.remove_input_data(:disable_with)
40
- end
41
-
42
- def input_arguments
43
- @input_arguments ||= @input.input_arguments.deep_dup.tap do |args|
44
- # rails uses :class but PVC wants :classes
45
- args[:classes] = args.delete(:class)
46
- end
10
+ @button = Button.new(input: input, type: :submit)
47
11
  end
48
12
  end
49
13
  end
@@ -1,5 +1,5 @@
1
1
  <%= render(FormControl.new(input: @input)) do %>
2
- <%= content_tag(:div, class: @field_wrap_classes) do %>
2
+ <%= content_tag(:div, **@field_wrap_arguments) do %>
3
3
  <%= builder.text_area(@input.name, **@input.input_arguments) %>
4
4
  <% end %>
5
5
  <% end %>
@@ -9,7 +9,11 @@ module Primer
9
9
  def initialize(input:)
10
10
  @input = input
11
11
  @input.add_input_classes("FormControl-input", "FormControl--medium")
12
- @field_wrap_classes = class_names("FormControl-input-wrap")
12
+
13
+ @field_wrap_arguments = {
14
+ class: class_names("FormControl-input-wrap"),
15
+ hidden: @input.hidden?
16
+ }
13
17
  end
14
18
  end
15
19
  end
@@ -1,6 +1,6 @@
1
1
  <%= render(FormControl.new(input: @input)) do %>
2
2
  <% if @input.leading_visual || @input.show_clear_button? %>
3
- <%= content_tag(:div, class: @input.field_wrap_classes) do %>
3
+ <%= content_tag(:div, **@field_wrap_arguments) do %>
4
4
  <% if @input.leading_visual %>
5
5
  <span class="FormControl-input-leadingVisualWrap">
6
6
  <%= render(Primer::OcticonComponent.new(**@input.leading_visual)) %>
@@ -8,6 +8,17 @@ module Primer
8
8
 
9
9
  def initialize(input:)
10
10
  @input = input
11
+
12
+ @field_wrap_arguments = {
13
+ class: class_names(
14
+ "FormControl-input-wrap",
15
+ Primer::Forms::Dsl::Input::SIZE_MAPPINGS[@input.size],
16
+ "FormControl-input-wrap--trailingAction": @input.show_clear_button?,
17
+ "FormControl-input-wrap--leadingVisual": @input.leading_visual?
18
+ ),
19
+
20
+ hidden: @input.hidden?
21
+ }
11
22
  end
12
23
  end
13
24
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ # :nodoc:
5
+ module Forms
6
+ # :nodoc:
7
+ module Utils
8
+ # Unfortunately this bug (https://github.com/ruby/ruby/pull/5646) prevents us from using
9
+ # Ruby's native Module.const_source_location. Instead we have to fudge it by searching
10
+ # for the file in the configured autoload paths. Doing so relies on Rails' autoloading
11
+ # conventions, so it should work ok. Zeitwerk also has this information but lacks a
12
+ # public API to map constants to source files.
13
+ def const_source_location(class_name)
14
+ # NOTE: underscore respects namespacing, i.e. will convert Foo::Bar to foo/bar.
15
+ class_path = "#{class_name.underscore}.rb"
16
+
17
+ ActiveSupport::Dependencies.autoload_paths.each do |autoload_path|
18
+ absolute_path = File.join(autoload_path, class_path)
19
+ return absolute_path if File.exist?(absolute_path)
20
+ end
21
+
22
+ nil
23
+ end
24
+ end
25
+
26
+ Utils.extend(Utils)
27
+ end
28
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module Primer
6
+ # :nodoc:
7
+ module ViewComponents
8
+ AUDITED = JSON.parse(
9
+ File.read(
10
+ File.join(File.dirname(__FILE__), "../../../static/audited_at.json")
11
+ )
12
+ ).freeze
13
+ end
14
+ end
@@ -57,6 +57,7 @@ module Primer
57
57
  autoloader.ignore(Engine.root.join("lib", "primer", "view_components", "linters.rb"))
58
58
  autoloader.ignore(Engine.root.join("lib", "primer", "view_components", "linters", "**", "*.rb"))
59
59
  autoloader.ignore(Engine.root.join("lib", "primer", "view_components", "statuses.rb"))
60
+ autoloader.ignore(Engine.root.join("lib", "primer", "view_components", "audited.rb"))
60
61
  end
61
62
  end
62
63
 
@@ -12,9 +12,9 @@ module ERBLint
12
12
 
13
13
  TAGS = %w[clipboard-copy].freeze
14
14
  REQUIRED_ARGUMENTS = [/for|value/, "aria-label"].freeze
15
- MESSAGE = "We are migrating clipboard-copy to use [Primer::ClipboardCopy](https://primer.style/view-components/components/clipboardcopy), please try to use that instead of raw HTML."
15
+ MESSAGE = "We are migrating clipboard-copy to use [Primer::Beta::ClipboardCopy](https://primer.style/view-components/components/clipboardcopy), please try to use that instead of raw HTML."
16
16
  ARGUMENT_MAPPER = ArgumentMappers::ClipboardCopy
17
- COMPONENT = "Primer::ClipboardCopy"
17
+ COMPONENT = "Primer::Beta::ClipboardCopy"
18
18
  end
19
19
  end
20
20
  end
@@ -7,27 +7,12 @@ module ERBLint
7
7
  module Helpers
8
8
  # Helpers to share between DeprecatedComponents ERB lint and Rubocop cop
9
9
  module DeprecatedComponentsHelpers
10
- def message(component)
11
- message = "#{component} has been deprecated and should not be used."
12
-
13
- if Primer::Deprecations.correctable?(component)
14
- suggested_component = Primer::Deprecations.suggested_component(component)
15
- message += " Try #{suggested_component} instead."
16
- end
17
-
18
- message
19
- end
20
-
21
- def statuses_json
22
- JSON.parse(
23
- File.read(
24
- File.join(File.dirname(__FILE__), "../../../../../static/statuses.json")
25
- )
26
- ).freeze
10
+ def message(component_name)
11
+ Primer::Deprecations.deprecation_message(component_name)
27
12
  end
28
13
 
29
14
  def deprecated_components
30
- @deprecated_components ||= statuses_json.select { |_, value| value == "deprecated" }.keys
15
+ Primer::Deprecations.deprecated_components
31
16
  end
32
17
  end
33
18
  end
@@ -6,7 +6,7 @@ module Primer
6
6
  module VERSION
7
7
  MAJOR = 0
8
8
  MINOR = 0
9
- PATCH = 112
9
+ PATCH = 113
10
10
 
11
11
  STRING = [MAJOR, MINOR, PATCH].join(".")
12
12
  end
@@ -26,8 +26,8 @@ module RuboCop
26
26
  component_name = node.const_name
27
27
  return unless ::Primer::Deprecations.correctable?(component_name)
28
28
 
29
- suggested_component = ::Primer::Deprecations.suggested_component(component_name)
30
- corrector.replace(node, suggested_component) if suggested_component.present?
29
+ replacement = ::Primer::Deprecations.replacement(component_name)
30
+ corrector.replace(node, replacement) if replacement.present?
31
31
  end
32
32
  end
33
33
  end
data/lib/tasks/docs.rake CHANGED
@@ -29,6 +29,7 @@ namespace :docs do
29
29
  # Rails controller for rendering arbitrary ERB
30
30
  view_context = ApplicationController.new.tap { |c| c.request = ActionDispatch::TestRequest.create }.view_context
31
31
  components = [
32
+ Primer::Beta::RelativeTime,
32
33
  Primer::Beta::IconButton,
33
34
  Primer::Beta::Button,
34
35
  Primer::Alpha::SegmentedControl,
@@ -53,7 +54,7 @@ namespace :docs do
53
54
  Primer::ButtonComponent,
54
55
  Primer::Beta::ButtonGroup,
55
56
  Primer::Alpha::ButtonMarketing,
56
- Primer::ClipboardCopy,
57
+ Primer::Beta::ClipboardCopy,
57
58
  Primer::Beta::CloseButton,
58
59
  Primer::Beta::Counter,
59
60
  Primer::Beta::Details,
@@ -104,7 +105,7 @@ namespace :docs do
104
105
  Primer::Alpha::ImageCrop,
105
106
  Primer::Beta::AutoComplete,
106
107
  Primer::Alpha::Banner,
107
- Primer::ClipboardCopy,
108
+ Primer::Beta::ClipboardCopy,
108
109
  Primer::TabContainerComponent,
109
110
  Primer::TimeAgoComponent,
110
111
  Primer::Alpha::UnderlinePanels,
@@ -11,7 +11,9 @@ module Primer
11
11
  # @param with_icon toggle
12
12
  # @param is_clearable toggle
13
13
  def playground(label_text: "Select a fruit", is_label_visible: true, is_label_inline: false, with_icon: false, is_clearable: false)
14
+ # rubocop:disable Primer/ComponentNameMigration
14
15
  render(Primer::Alpha::AutoComplete.new(label_text: label_text, input_id: "input-id", list_id: "test-id", src: "/auto_complete?version=alpha", is_label_visible: is_label_visible, is_label_inline: is_label_inline, with_icon: with_icon, is_clearable: is_clearable))
16
+ # rubocop:enable Primer/ComponentNameMigration
15
17
  end
16
18
 
17
19
  # @label Default Options
@@ -21,29 +23,39 @@ module Primer
21
23
  # @param with_icon toggle
22
24
  # @param is_clearable toggle
23
25
  def default(label_text: "Select a fruit", is_label_visible: true, is_label_inline: false, with_icon: false, is_clearable: false)
26
+ # rubocop:disable Primer/ComponentNameMigration
24
27
  render(Primer::Alpha::AutoComplete.new(label_text: label_text, input_id: "input-id", list_id: "test-id", src: "/auto_complete?version=alpha", is_label_visible: is_label_visible, is_label_inline: is_label_inline, with_icon: with_icon, is_clearable: is_clearable))
28
+ # rubocop:enable Primer/ComponentNameMigration
25
29
  end
26
30
 
27
31
  # @!group More examples
28
32
 
29
33
  # @label AutoComplete with non-visible label
30
34
  def with_non_visible_label
35
+ # rubocop:disable Primer/ComponentNameMigration
31
36
  render(Primer::Alpha::AutoComplete.new(label_text: "Select a fruit", input_id: "input-id-1", list_id: "test-id-1", src: "/auto_complete?version=alpha", is_label_visible: false))
37
+ # rubocop:enable Primer/ComponentNameMigration
32
38
  end
33
39
 
34
40
  # @label AutoComplete with inline label
35
41
  def with_inline_label
42
+ # rubocop:disable Primer/ComponentNameMigration
36
43
  render(Primer::Alpha::AutoComplete.new(label_text: "Select a fruit", input_id: "input-id-2", list_id: "test-id-2", src: "/auto_complete?version=alpha", is_label_inline: true))
44
+ # rubocop:enable Primer/ComponentNameMigration
37
45
  end
38
46
 
39
47
  # @label AutoComplete with search icon
40
48
  def with_icon
49
+ # rubocop:disable Primer/ComponentNameMigration
41
50
  render(Primer::Alpha::AutoComplete.new(label_text: "Select a fruit", input_id: "input-id-3", list_id: "test-id-3", src: "/auto_complete?version=alpha", with_icon: true))
51
+ # rubocop:enable Primer/ComponentNameMigration
42
52
  end
43
53
 
44
54
  # @label AutoComplete with clear button
45
55
  def with_clear_button
56
+ # rubocop:disable Primer/ComponentNameMigration
46
57
  render(Primer::Alpha::AutoComplete.new(label_text: "Select a fruit", input_id: "input-id-4", list_id: "test-id-4", src: "/auto_complete?version=alpha", is_clearable: true))
58
+ # rubocop:enable Primer/ComponentNameMigration
47
59
  end
48
60
 
49
61
  # @!endgroup
@@ -34,8 +34,9 @@ module Primer
34
34
 
35
35
  # @!group Full width
36
36
  # @label Size small
37
- def full_width_small(hide_labels: false, size: :small)
38
- render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", full_width: true, size: :small)) do |c|
37
+ # @param hide_labels [Boolean] toggle
38
+ def full_width_small(hide_labels: false)
39
+ render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", hide_labels: hide_labels, full_width: true, size: :small)) do |c|
39
40
  c.with_item(label: "Preview", selected: true)
40
41
  c.with_item(label: "Raw")
41
42
  c.with_item(label: "Blame")
@@ -43,8 +44,9 @@ module Primer
43
44
  end
44
45
 
45
46
  # @label Size medium
46
- def full_width_medium(hide_labels: false, size: :medium)
47
- render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", full_width: true, size: :medium)) do |c|
47
+ # @param hide_labels [Boolean] toggle
48
+ def full_width_medium(hide_labels: false)
49
+ render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", hide_labels: hide_labels, full_width: true, size: :medium)) do |c|
48
50
  c.with_item(label: "Preview", selected: true)
49
51
  c.with_item(label: "Raw")
50
52
  c.with_item(label: "Blame")
@@ -52,8 +54,9 @@ module Primer
52
54
  end
53
55
 
54
56
  # @label Size large
55
- def full_width_large(hide_labels: false, size: :large)
56
- render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", full_width: true, size: :large)) do |c|
57
+ # @param hide_labels [Boolean] toggle
58
+ def full_width_large(hide_labels: false)
59
+ render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", hide_labels: hide_labels, full_width: true, size: :large)) do |c|
57
60
  c.with_item(label: "Preview", selected: true)
58
61
  c.with_item(label: "Raw")
59
62
  c.with_item(label: "Blame")
@@ -63,62 +63,87 @@ module Primer
63
63
  end
64
64
 
65
65
  # @label Default
66
+ def default
67
+ render(Primer::Alpha::TextField.new(name: "my-text-field", label: "My text field"))
68
+ end
69
+
70
+ # @!group Sizes
66
71
  #
67
- # @param name text
68
- # @param id text
69
- # @param label text
70
- # @param visually_hide_label toggle
71
- # @param size [Symbol] select [small, medium, large]
72
- # @param show_clear_button toggle
73
- # @param clear_button_id text
74
- # @param full_width toggle
75
- # @param disabled toggle
76
- # @param invalid toggle
77
- # @param placeholder text
78
- # @param inset toggle
79
- # @param monospace toggle
80
- # @param leading_visual_icon text
81
- def default(
82
- name: "my-text-field",
83
- id: "my-text-field",
84
- label: "My text field",
85
- visually_hide_label: false,
86
- size: Primer::Forms::Dsl::Input::DEFAULT_SIZE.to_s,
87
- show_clear_button: false,
88
- clear_button_id: "my-text-field-clear-button",
89
- full_width: false,
90
- disabled: false,
91
- invalid: false,
92
- placeholder: nil,
93
- inset: false,
94
- monospace: false,
95
- leading_visual_icon: nil
96
- )
97
- system_arguments = {
98
- name: name,
99
- id: id,
100
- label: label,
101
- visually_hide_label: visually_hide_label,
102
- size: size,
103
- show_clear_button: show_clear_button,
104
- clear_button_id: clear_button_id,
105
- full_width: full_width,
106
- disabled: disabled,
107
- invalid: invalid,
108
- placeholder: placeholder,
109
- inset: inset,
110
- monospace: monospace
111
- }
72
+ # @label Small
73
+ def size_small
74
+ render(Primer::Alpha::TextField.new(size: :small, visually_hide_label: true, name: "my-text-field", label: "My text field"))
75
+ end
112
76
 
113
- if leading_visual_icon
114
- system_arguments[:leading_visual] = {
115
- icon: leading_visual_icon,
116
- size: :small
117
- }
118
- end
77
+ # @label Medium
78
+ def size_medium
79
+ render(Primer::Alpha::TextField.new(size: :medium, visually_hide_label: true, name: "my-text-field", label: "My text field"))
80
+ end
119
81
 
120
- render(Primer::Alpha::TextField.new(**system_arguments))
82
+ # @label Large
83
+ def size_large
84
+ render(Primer::Alpha::TextField.new(size: :large, visually_hide_label: true, name: "my-text-field", label: "My text field"))
85
+ end
86
+ #
87
+ # @!endgroup
88
+
89
+ # @!group Options
90
+ #
91
+ # @label With caption
92
+ def with_caption
93
+ render(Primer::Alpha::TextField.new(caption: "With a caption", name: "my-text-field", label: "My text field"))
94
+ end
95
+
96
+ # @label Visually hidden label
97
+ def visually_hide_label
98
+ render(Primer::Alpha::TextField.new(visually_hide_label: true, name: "my-text-field", label: "My text field"))
99
+ end
100
+
101
+ # @label Show clear button
102
+ def show_clear_button
103
+ render(Primer::Alpha::TextField.new(show_clear_button: true, name: "my-text-field", label: "My text field"))
104
+ end
105
+
106
+ # @label Full width
107
+ def full_width
108
+ render(Primer::Alpha::TextField.new(full_width: true, name: "my-text-field", label: "My text field"))
109
+ end
110
+
111
+ # @label Disabled
112
+ def disabled
113
+ render(Primer::Alpha::TextField.new(disabled: true, name: "my-text-field", label: "My text field"))
114
+ end
115
+
116
+ # @label Invalid
117
+ def invalid
118
+ render(Primer::Alpha::TextField.new(invalid: true, name: "my-text-field", label: "My text field"))
119
+ end
120
+
121
+ # @label With placeholder
122
+ def with_placeholder
123
+ render(Primer::Alpha::TextField.new(placeholder: "with a placeholder", name: "my-text-field", label: "My text field"))
124
+ end
125
+
126
+ # @label Inset
127
+ def inset
128
+ render(Primer::Alpha::TextField.new(inset: true, name: "my-text-field", label: "My text field"))
129
+ end
130
+
131
+ # @label Monospace
132
+ def monospace
133
+ render(Primer::Alpha::TextField.new(monospace: true, name: "my-text-field", label: "My text field"))
121
134
  end
135
+
136
+ # @label With leading visual
137
+ def with_leading_visual
138
+ render(Primer::Alpha::TextField.new(leading_visual: { icon: :search }, name: "my-text-field", label: "My text field"))
139
+ end
140
+
141
+ # @label With validation message
142
+ def with_validation_message
143
+ render(Primer::Alpha::TextField.new(validation_message: "An error occurred!", name: "my-text-field", label: "My text field"))
144
+ end
145
+ #
146
+ # @!endgroup
122
147
  end
123
148
  end
124
149
  end
@@ -0,0 +1,2 @@
1
+ <%= render(Primer::Beta::ClipboardCopy.new(for: "blob-path", "aria-label": aria_label)) %>
2
+ <div id="blob-path">src/index.js</div>
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ module Beta
5
+ # @label ClipboardCopy
6
+ class ClipboardCopyPreview < ViewComponent::Preview
7
+ # @label Playground
8
+ #
9
+ # @param aria_label [String]
10
+ # @param value [String]
11
+ def playground(value: "Text to copy", aria_label: "Copy text to the system clipboard")
12
+ render(Primer::Beta::ClipboardCopy.new(value: value, "aria-label": aria_label))
13
+ end
14
+
15
+ # @label Default Options
16
+ #
17
+ # @param aria_label [String]
18
+ # @param value [String]
19
+ def default(value: "Text to copy", aria_label: "Copy text to the system clipboard")
20
+ render(Primer::Beta::ClipboardCopy.new(value: value, "aria-label": aria_label))
21
+ end
22
+
23
+ # @label With text instead of icons
24
+ #
25
+ # @param aria_label [String]
26
+ # @param value [String]
27
+ def text(value: "Text to copy", aria_label: "Copy text to the system clipboard")
28
+ render(Primer::Beta::ClipboardCopy.new(value: value, "aria-label": aria_label)) { "Click to copy!" }
29
+ end
30
+
31
+ # @label Copying from an element
32
+ #
33
+ # @param aria_label [String]
34
+ def element(aria_label: "Copy text to the system clipboard")
35
+ render_with_template(locals: { aria_label: aria_label })
36
+ end
37
+ end
38
+ end
39
+ end