primer_view_components 0.0.83 → 0.0.86

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +50 -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/components/primer/alpha/auto_complete/auto_complete.html.erb +24 -0
  6. data/app/components/primer/alpha/auto_complete/item.rb +46 -0
  7. data/app/components/primer/alpha/auto_complete.rb +158 -0
  8. data/app/components/primer/alpha/button_marketing.rb +1 -1
  9. data/app/components/primer/alpha/text_field.rb +105 -0
  10. data/app/components/primer/alpha/tool-tip-element.d.ts +3 -1
  11. data/app/components/primer/alpha/tool-tip-element.js +20 -13
  12. data/app/components/primer/alpha/tool-tip-element.ts +23 -14
  13. data/app/components/primer/alpha/tooltip.rb +1 -1
  14. data/app/components/primer/beta/auto_complete/auto_complete.html.erb +21 -17
  15. data/app/components/primer/beta/auto_complete/item.html.erb +21 -0
  16. data/app/components/primer/beta/auto_complete/item.rb +42 -6
  17. data/app/components/primer/beta/auto_complete.rb +93 -55
  18. data/app/components/primer/beta/base_button.rb +47 -0
  19. data/app/components/primer/{alpha → beta}/border_box/header.html.erb +0 -0
  20. data/app/components/primer/{alpha → beta}/border_box/header.rb +6 -6
  21. data/app/components/primer/{border_box_component.html.erb → beta/border_box.html.erb} +0 -0
  22. data/app/components/primer/beta/border_box.rb +147 -0
  23. data/app/components/primer/blankslate_component.rb +2 -150
  24. data/app/components/primer/border_box_component.rb +2 -140
  25. data/app/components/primer/button_component.html.erb +12 -4
  26. data/app/components/primer/button_component.rb +2 -2
  27. data/app/components/primer/clipboard_copy.rb +6 -2
  28. data/app/components/primer/close_button.rb +1 -1
  29. data/app/components/primer/conditional_wrapper.rb +36 -0
  30. data/app/components/primer/hellip_button.rb +1 -1
  31. data/app/components/primer/icon_button.html.erb +6 -0
  32. data/app/components/primer/icon_button.rb +46 -10
  33. data/app/components/primer/link_component.html.erb +12 -0
  34. data/app/components/primer/link_component.rb +2 -9
  35. data/app/lib/primer/join_style_arguments_helper.rb +1 -1
  36. data/lib/primer/classify/utilities.rb +3 -6
  37. data/lib/primer/form_components.rb +36 -0
  38. data/lib/primer/forms/acts_as_component.rb +118 -0
  39. data/lib/primer/forms/base.html.erb +8 -0
  40. data/lib/primer/forms/base.rb +137 -0
  41. data/lib/primer/forms/base_component.rb +58 -0
  42. data/lib/primer/forms/buffer_rewriter.rb +50 -0
  43. data/lib/primer/forms/caption.html.erb +10 -0
  44. data/lib/primer/forms/caption.rb +29 -0
  45. data/lib/primer/forms/check_box.html.erb +9 -0
  46. data/lib/primer/forms/check_box.rb +16 -0
  47. data/lib/primer/forms/check_box_group.html.erb +12 -0
  48. data/lib/primer/forms/check_box_group.rb +14 -0
  49. data/lib/primer/forms/dsl/check_box_group_input.rb +41 -0
  50. data/lib/primer/forms/dsl/check_box_input.rb +27 -0
  51. data/lib/primer/forms/dsl/form_object.rb +25 -0
  52. data/lib/primer/forms/dsl/form_reference_input.rb +36 -0
  53. data/lib/primer/forms/dsl/hidden_input.rb +29 -0
  54. data/lib/primer/forms/dsl/input.rb +259 -0
  55. data/lib/primer/forms/dsl/input_group.rb +41 -0
  56. data/lib/primer/forms/dsl/input_methods.rb +86 -0
  57. data/lib/primer/forms/dsl/multi_input.rb +58 -0
  58. data/lib/primer/forms/dsl/radio_button_group_input.rb +38 -0
  59. data/lib/primer/forms/dsl/radio_button_input.rb +37 -0
  60. data/lib/primer/forms/dsl/select_list_input.rb +53 -0
  61. data/lib/primer/forms/dsl/submit_button_input.rb +28 -0
  62. data/lib/primer/forms/dsl/text_area_input.rb +33 -0
  63. data/lib/primer/forms/dsl/text_field_input.rb +65 -0
  64. data/lib/primer/forms/form_control.html.erb +18 -0
  65. data/lib/primer/forms/form_control.rb +23 -0
  66. data/lib/primer/forms/form_list.html.erb +5 -0
  67. data/lib/primer/forms/form_list.rb +21 -0
  68. data/lib/primer/forms/form_reference.html.erb +3 -0
  69. data/lib/primer/forms/form_reference.rb +14 -0
  70. data/lib/primer/forms/group.html.erb +5 -0
  71. data/lib/primer/forms/group.rb +27 -0
  72. data/lib/primer/forms/hidden_field.html.erb +1 -0
  73. data/lib/primer/forms/hidden_field.rb +15 -0
  74. data/lib/primer/forms/multi.html.erb +3 -0
  75. data/lib/primer/forms/multi.rb +14 -0
  76. data/lib/primer/forms/radio_button.html.erb +14 -0
  77. data/lib/primer/forms/radio_button.rb +29 -0
  78. data/lib/primer/forms/radio_button_group.html.erb +12 -0
  79. data/lib/primer/forms/radio_button_group.rb +14 -0
  80. data/lib/primer/forms/select_list.html.erb +5 -0
  81. data/lib/primer/forms/select_list.rb +26 -0
  82. data/lib/primer/forms/separator.html.erb +1 -0
  83. data/lib/primer/forms/separator.rb +8 -0
  84. data/lib/primer/forms/spacing_wrapper.html.erb +3 -0
  85. data/lib/primer/forms/spacing_wrapper.rb +8 -0
  86. data/lib/primer/forms/submit_button.html.erb +4 -0
  87. data/lib/primer/forms/submit_button.rb +50 -0
  88. data/lib/primer/forms/text_area.html.erb +5 -0
  89. data/lib/primer/forms/text_area.rb +16 -0
  90. data/lib/primer/forms/text_field.html.erb +19 -0
  91. data/lib/primer/forms/text_field.rb +14 -0
  92. data/lib/primer/view_components/engine.rb +23 -0
  93. data/lib/primer/view_components/linters/argument_mappers/button.rb +2 -2
  94. data/lib/primer/view_components/linters/button_component_migration_counter.rb +1 -1
  95. data/lib/primer/view_components/linters/helpers/deprecated_components_helpers.rb +4 -8
  96. data/lib/primer/view_components/version.rb +1 -1
  97. data/lib/rubocop/cop/primer/component_name_migration.rb +3 -0
  98. data/lib/tasks/deprecated.rake +22 -0
  99. data/lib/tasks/docs.rake +8 -6
  100. data/static/arguments.yml +188 -52
  101. data/static/audited_at.json +7 -2
  102. data/static/classes.yml +25 -8
  103. data/static/constants.json +66 -39
  104. data/static/statuses.json +8 -3
  105. metadata +71 -7
  106. data/app/components/primer/base_button.rb +0 -43
  107. data/app/components/primer/blankslate_component.html.erb +0 -30
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # TODO: use generic ActionList item for Autocomplete
3
4
  module Primer
4
5
  module Beta
5
6
  class AutoComplete
@@ -7,6 +8,32 @@ module Primer
7
8
  class Item < Primer::Component
8
9
  status :beta
9
10
 
11
+ ALLOWED_DESCRIPTION_VARIANTS = [:inline, :block].freeze
12
+
13
+ # The leading visual rendered before the link.
14
+ #
15
+ # @param kwargs [Hash] The arguments accepted by <%= link_to_component(Primer::Beta::Avatar) %> or <%= link_to_component(Primer::OcticonComponent) %>
16
+ renders_one :leading_visual, types: {
17
+ icon: Primer::OcticonComponent,
18
+ avatar: lambda { |**kwargs|
19
+ Primer::Beta::Avatar.new(**{ **kwargs, size: 16 })
20
+ }
21
+ }
22
+
23
+ # The trailing visual rendered after the link.
24
+ #
25
+ # @param kwargs [Hash] The arguments accepted by <%= link_to_component(Primer::OcticonComponent) %>, <%= link_to_component(Primer::LabelComponent) %>, or <%= link_to_component(Primer::CounterComponent) %>
26
+ renders_one :trailing_visual, types: {
27
+ icon: Primer::OcticonComponent,
28
+ label: Primer::LabelComponent,
29
+ counter: Primer::CounterComponent
30
+ }
31
+
32
+ # Optional description
33
+ #
34
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
35
+ renders_one :description
36
+
10
37
  # @example Default
11
38
  # <%= render(Primer::Beta::AutoComplete::Item.new(selected: true, value: "value")) do |c| %>
12
39
  # Selected
@@ -18,8 +45,12 @@ module Primer
18
45
  # @param value [String] Value of the item.
19
46
  # @param selected [Boolean] Whether the item is selected.
20
47
  # @param disabled [Boolean] Whether the item is disabled.
48
+ # @param description_variant [Hash] Changes the description style. Allowed values are :inline, :block
49
+ # @param description [String] Display description text below label
21
50
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
22
- def initialize(value:, selected: false, disabled: false, **system_arguments)
51
+ def initialize(value:, selected: false, disabled: false, description_variant: :block, **system_arguments)
52
+ @description_variant = ALLOWED_DESCRIPTION_VARIANTS.include?(description_variant) ? description_variant : :block
53
+
23
54
  @system_arguments = deny_tag_argument(**system_arguments)
24
55
  @system_arguments[:tag] = :li
25
56
  @system_arguments[:role] = :option
@@ -29,14 +60,19 @@ module Primer
29
60
  @system_arguments[:"aria-disabled"] = true if disabled
30
61
 
31
62
  @system_arguments[:classes] = class_names(
32
- "autocomplete-item",
33
- system_arguments[:classes],
34
- "disabled" => disabled
63
+ "ActionList-item",
64
+ system_arguments[:classes]
35
65
  )
36
66
  end
37
67
 
38
- def call
39
- render(Primer::BaseComponent.new(**@system_arguments)) { content }
68
+ # Description variant class.
69
+ def description_variant_class
70
+ case @description_variant
71
+ when :block
72
+ "ActionList-item-blockDescription"
73
+ when :inline
74
+ "ActionList-item-descriptionWrap--inline"
75
+ end
40
76
  end
41
77
  end
42
78
  end
@@ -8,12 +8,20 @@ module Primer
8
8
  # Always set an accessible label to help the user interact with the component.
9
9
  #
10
10
  # * `label_text` is required and visible by default.
11
- # * If you must use a non-visible label, set `is_label_visible` to `false`.
11
+ # * If you must hide the label, set `visually_hide_label` to `true`.
12
12
  # However, please note that a visible label should almost always
13
13
  # be used unless there is compelling reason not to. A placeholder is not a label.
14
14
  class AutoComplete < Primer::Component
15
15
  status :beta
16
- #
16
+
17
+ DEFAULT_SIZE = :medium
18
+ SIZE_MAPPINGS = {
19
+ :small => "FormControl-small",
20
+ DEFAULT_SIZE => "FormControl-medium",
21
+ :large => "FormControl-large"
22
+ }.freeze
23
+ SIZE_OPTIONS = SIZE_MAPPINGS.keys
24
+
17
25
  # Customizable results list.
18
26
  #
19
27
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
@@ -22,13 +30,25 @@ module Primer
22
30
  system_arguments[:tag] = :ul
23
31
  system_arguments[:id] = @list_id
24
32
  system_arguments[:classes] = class_names(
25
- "autocomplete-results",
33
+ "ActionList",
26
34
  system_arguments[:classes]
27
35
  )
28
36
 
29
37
  Primer::BaseComponent.new(**system_arguments)
30
38
  }
31
39
 
40
+ # Leading visual.
41
+ #
42
+ # - `leading_visual_icon` for a <%= link_to_component(Primer::OcticonComponent) %>.
43
+ #
44
+ # @param system_arguments [Hash] Same arguments as <%= link_to_component(Primer::OcticonComponent) %>.
45
+ renders_one :leading_visual, types: {
46
+ icon: lambda { |**system_arguments|
47
+ system_arguments[:classes] = class_names("FormControl-input-leadingVisual")
48
+ Primer::OcticonComponent.new(**system_arguments)
49
+ }
50
+ }
51
+
32
52
  # Customizable input used to search for results.
33
53
  # It is preferred to use this slot sparingly - it will be created by default if not explicity added.
34
54
  #
@@ -38,7 +58,7 @@ module Primer
38
58
  sanitized_args = deny_single_argument(:autofocus, "autofocus is not allowed for accessibility reasons. See https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus#accessibility_considerations for more information.", **sanitized_args)
39
59
  deny_aria_key(
40
60
  :label,
41
- "instead of `aria-label`, include `label_text` and set `is_label_visible` to `false` on the component initializer.",
61
+ "instead of `aria-label`, include `label_text` and set `visually_hide_label` to `true` on the component initializer.",
42
62
  **sanitized_args
43
63
  )
44
64
  deny_single_argument(
@@ -55,45 +75,66 @@ module Primer
55
75
  sanitized_args[:name] = @input_name
56
76
  sanitized_args[:tag] = :input
57
77
  sanitized_args[:autocomplete] = "off"
58
-
78
+ sanitized_args[:disabled] = true if @disabled
79
+ sanitized_args[:invalid] = true if @invalid
59
80
  sanitized_args[:type] = :text
60
81
  sanitized_args[:classes] = class_names(
61
- "form-control",
62
- sanitized_args[:classes]
82
+ "FormControl-input",
83
+ SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, @size, DEFAULT_SIZE)],
84
+ sanitized_args[:classes],
85
+ "FormControl-inset": @inset,
86
+ "FormControl-monospace": @monospace
63
87
  )
88
+ sanitized_args[:placeholder] = @placeholder
64
89
 
65
90
  Primer::BaseComponent.new(**sanitized_args)
66
91
  }
67
92
 
68
- # @example Default
93
+ # @example Leading visual
69
94
  # @description
70
- # Labels are stacked by default.
95
+ # Display any Octicon as a leading visual within the field
71
96
  # @code
72
- # <%= render(Primer::Beta::AutoComplete.new(label_text: "Fruits", src: "/auto_complete", input_id: "fruits-input--default", list_id: "fruits-popup--default")) %>
97
+ # <%= render(Primer::Beta::AutoComplete.new(label_text: "Select a fruit", src: "/auto_complete", input_id:"input-id-1", list_id: "list-id-1")) do |c| %>
98
+ # <% c.leading_visual_icon(icon: :search) %>
99
+ # <% end %>
73
100
  #
74
- # @example With inline label
101
+ # @example Trailing action
75
102
  # @description
76
- # Labels can be inline by setting `is_label_inline: true`. However, labels will always become stacked on smaller screen sizes.
103
+ # Show a clear button
77
104
  # @code
78
- # <%= render(Primer::Beta::AutoComplete.new(label_text: "Fruits", src: "/auto_complete", is_label_inline: true, input_id: "fruits-input--inline-label", list_id: "fruits-popup--inline-label")) %>
105
+ # <%= render(Primer::Beta::AutoComplete.new(label_text: "Select a fruit", input_id: "input-id-2", list_id: "list-id-2", src: "/auto_complete", show_clear_button: true )) %>
79
106
  #
80
- # @example With non-visible label
107
+ # @example Visually hidden label
81
108
  # @description
82
- # A non-visible label may be rendered with `is_label_visible: false`, but it is highly discouraged. See <%= link_to_accessibility %>.
109
+ # A non-visible label may be rendered with `visually_hide_label: true`, but it is highly discouraged. See <%= link_to_accessibility %>.
83
110
  # @code
84
- # <%= render(Primer::Beta::AutoComplete.new(label_text: "Fruits", src: "/auto_complete", input_id: "fruits-input--non-visible-label", list_id: "fruits-popup--non-visible-label", is_label_visible: false)) %>
111
+ # <%= render(Primer::Beta::AutoComplete.new(label_text: "Select a fruit", input_id: "fruits-input--custom-results-1", list_id: "fruits-popup--custom-result-1", src: "/auto_complete", visually_hide_label: true)) do |c| %>
112
+ # <% c.leading_visual_icon(icon: :search) %>
113
+ # <% end %>
85
114
  #
86
- # @example With icon
115
+ # @example Full width field
87
116
  # @description
88
- # To display a search icon, set `with_icon` to `true`.
117
+ # To allow field to span width of its container, set `full_width` to `true`.
89
118
  # @code
90
- # <%= render(Primer::Beta::AutoComplete.new(label_text: "Fruits", src: "/auto_complete", list_id: "fruits-popup--icon", input_id: "fruits-input--icon", with_icon: true)) %>
119
+ # <%= render(Primer::Beta::AutoComplete.new(label_text: "Select a fruit", input_id: "fruits-input--custom-results-2", list_id: "fruits-popup--custom-results-2", src: "/auto_complete", full_width: true)) do |c| %>
120
+ # <% c.leading_visual_icon(icon: :search) %>
121
+ # <% end %>
91
122
  #
92
- # @example With icon and non-visible label
93
- # <%= render(Primer::Beta::AutoComplete.new(label_text: "Fruits", src: "/auto_complete", list_id: "fruits-popup--icon-no-label", input_id: "fruits-input--icon-no-label", with_icon: true, is_label_visible: false)) %>
123
+ # @example Inset variant
124
+ # @description
125
+ # Use the `inset` variant to change the input background color to be subtle.
126
+ # @code
127
+ # <%= render(Primer::Beta::AutoComplete.new(label_text: "Select a fruit", input_id: "fruits-input--custom-results-2", list_id: "fruits-popup--custom-results-2", src: "/auto_complete", inset: true)) do |c| %>
128
+ # <% c.leading_visual_icon(icon: :search) %>
129
+ # <% end %>
94
130
  #
95
- # @example With clear button
96
- # <%= render(Primer::Beta::AutoComplete.new(label_text: "Fruits", src: "/auto_complete", input_id: "fruits-input--clear", list_id: "fruits-popup--clear", is_clearable: true)) %>
131
+ # @example Monospace variant
132
+ # @description
133
+ # Use the `monospace` variant to change the input font family.
134
+ # @code
135
+ # <%= render(Primer::Beta::AutoComplete.new(label_text: "Select a fruit", input_id: "fruits-input--custom-results-2", list_id: "fruits-popup--custom-results-2", src: "/auto_complete", monospace: true)) do |c| %>
136
+ # <% c.leading_visual_icon(icon: :search) %>
137
+ # <% end %>
97
138
  #
98
139
  # @example With custom classes for the input
99
140
  # <%= render(Primer::Beta::AutoComplete.new(label_text: "Fruits", src: "/auto_complete", input_id: "fruits-input--custom-input", list_id: "fruits-popup--custom-input")) do |c| %>
@@ -102,14 +143,7 @@ module Primer
102
143
  #
103
144
  # @example With custom classes for the results
104
145
  # <%= render(Primer::Beta::AutoComplete.new(label_text: "Fruits", src: "/auto_complete", input_id: "fruits-input--custom-results", list_id: "fruits-popup--custom-results")) do |c| %>
105
- # <% c.results(classes: "custom-class") do %>
106
- # <%= render(Primer::Beta::AutoComplete::Item.new(selected: true, value: "apple")) do |c| %>
107
- # Apple
108
- # <% end %>
109
- # <%= render(Primer::Beta::AutoComplete::Item.new(value: "orange")) do |c| %>
110
- # Orange
111
- # <% end %>
112
- # <% end %>
146
+ # <% c.results(classes: "custom-class") %>
113
147
  # <% end %>
114
148
  #
115
149
  # @param label_text [String] The label of the input.
@@ -117,25 +151,43 @@ module Primer
117
151
  # @param input_id [String] Id of the input element.
118
152
  # @param input_name [String] Optional name of the input element, defaults to `input_id` when not set.
119
153
  # @param list_id [String] Id of the list element.
120
- # @param with_icon [Boolean] Controls if a search icon is visible, defaults to `false`.
121
- # @param is_label_visible [Boolean] Controls if the label is visible. If `false`, screen reader only text will be added.
122
- # @param is_clearable [Boolean] Adds optional clear button.
123
- # @param is_label_inline [Boolean] Controls if the label is inline. On smaller screens, label will always become stacked.
154
+ # @param visually_hide_label [Boolean] Controls if the label is visible. If `true`, screen reader only text will be added.
155
+ # @param show_clear_button [Boolean] Adds optional clear button.
124
156
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
125
- def initialize(label_text:, src:, list_id:, input_id:, input_name: nil, is_label_visible: true, is_label_inline: false, with_icon: false, is_clearable: false, **system_arguments)
157
+ # @param size [Hash] Input size can be small, medium (default), or large
158
+ # @param full_width [Boolean] Input can be full-width or fit to content
159
+ # @param disabled [Boolean] Disabled input
160
+ # @param invalid [Boolean] Invalid input
161
+ # @param placeholder [String] The placeholder text displayed within the input
162
+ # @param inset [Boolean] subtle input background color
163
+ # @param monospace [Boolean] monospace input font family
164
+ def initialize(label_text:, src:, list_id:, input_id:, input_name: nil, placeholder: nil, show_clear_button: false, visually_hide_label: false, size: DEFAULT_SIZE, full_width: false, disabled: false, invalid: false, inset: false, monospace: false, **system_arguments)
126
165
  @label_text = label_text
127
166
  @list_id = list_id
128
167
  @input_id = input_id
129
168
  @input_name = input_name || input_id
130
- @is_label_visible = is_label_visible
131
- @with_icon = with_icon
132
- @is_clearable = is_clearable
133
-
134
- @label_classes = label_classes(is_label_visible: is_label_visible, is_label_inline: is_label_inline)
169
+ @placeholder = placeholder
170
+ @visually_hide_label = visually_hide_label
171
+ @show_clear_button = show_clear_button
135
172
  @system_arguments = deny_tag_argument(**system_arguments)
136
173
  @system_arguments[:tag] = "auto-complete"
137
174
  @system_arguments[:src] = src
138
175
  @system_arguments[:for] = list_id
176
+ @disabled = disabled
177
+ @invalid = invalid
178
+ @size = size
179
+ @inset = inset
180
+ @monospace = monospace
181
+ @full_width = full_width
182
+ @field_wrap_classes = class_names(
183
+ "FormControl-input-wrap",
184
+ SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, @size, DEFAULT_SIZE)],
185
+ "FormControl-input-wrap--trailingAction": show_clear_button
186
+ )
187
+ @form_group_classes = class_names(
188
+ "FormControl",
189
+ "FormControl--fullWidth": full_width
190
+ )
139
191
  end
140
192
 
141
193
  # add `input` and `results` without needing to explicitly call them in the view
@@ -143,20 +195,6 @@ module Primer
143
195
  results(classes: "") unless results
144
196
  input(classes: "") unless input
145
197
  end
146
-
147
- private
148
-
149
- # Private: determines the label classes based on component configration.
150
- #
151
- # If the label is not visible, return an empty string.
152
- #
153
- # @param args [Hash] The component configuration.
154
- # @return [String] The label classes.
155
- def label_classes(**args)
156
- return "" if args[:is_label_visible] == false
157
-
158
- args[:is_label_inline] ? "autocomplete-label-inline" : "autocomplete-label-stacked"
159
- end
160
198
  end
161
199
  end
162
200
  end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ module Beta
5
+ # Use `BaseButton` to render an unstyled `<button>` tag that can be customized.
6
+ class BaseButton < Primer::Component
7
+ status :beta
8
+
9
+ DEFAULT_TAG = :button
10
+ TAG_OPTIONS = [DEFAULT_TAG, :a, :summary].freeze
11
+
12
+ DEFAULT_TYPE = :button
13
+ TYPE_OPTIONS = [DEFAULT_TYPE, :reset, :submit].freeze
14
+
15
+ # @example Block
16
+ # <%= render(Primer::Beta::BaseButton.new(block: :true)) { "Block" } %>
17
+ # <%= render(Primer::Beta::BaseButton.new(block: :true, scheme: :primary)) { "Primary block" } %>
18
+ #
19
+ # @param tag [Symbol] <%= one_of(Primer::Beta::BaseButton::TAG_OPTIONS) %>
20
+ # @param type [Symbol] <%= one_of(Primer::Beta::BaseButton::TYPE_OPTIONS) %>
21
+ # @param block [Boolean] Whether button is full-width with `display: block`.
22
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
23
+ def initialize(
24
+ tag: DEFAULT_TAG,
25
+ type: DEFAULT_TYPE,
26
+ block: false,
27
+ **system_arguments
28
+ )
29
+ @system_arguments = system_arguments
30
+ @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, DEFAULT_TAG)
31
+
32
+ @system_arguments[:type] = fetch_or_fallback(TYPE_OPTIONS, type, DEFAULT_TYPE) if @system_arguments[:tag] == :button
33
+
34
+ @system_arguments[:classes] = class_names(
35
+ system_arguments[:classes],
36
+ "btn-block" => block
37
+ )
38
+ end
39
+
40
+ def call
41
+ render(Primer::BaseComponent.new(**@system_arguments)) { content }
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ Primer::BaseButton = Primer::Beta::BaseButton
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Primer
4
- module Alpha
5
- module BorderBox
4
+ module Beta
5
+ class BorderBox
6
6
  # `BorderBox::Header` is used inside `BorderBox` to render its header slot.
7
7
  #
8
8
  # @accessibility When using `header.title`, set `tag` to one of `h1`, `h2`, `h3`, etc. based on what is appropriate for the page context. <%= link_to_heading_practices %>
@@ -12,7 +12,7 @@ module Primer
12
12
 
13
13
  # Optional Title.
14
14
  #
15
- # @param tag [Symbol] <%= one_of(Primer::Alpha::BorderBox::Header::TITLE_TAG_OPTIONS) %>
15
+ # @param tag [Symbol] <%= one_of(Primer::Beta::BorderBox::Header::TITLE_TAG_OPTIONS) %>
16
16
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
17
17
  renders_one :title, lambda { |tag:, **system_arguments|
18
18
  system_arguments[:tag] = fetch_or_fallback(TITLE_TAG_OPTIONS, tag, TITLE_TAG_FALLBACK)
@@ -24,14 +24,14 @@ module Primer
24
24
  Primer::BaseComponent.new(**system_arguments)
25
25
  }
26
26
 
27
- # @example default use case
27
+ # @example Default
28
28
  #
29
- # <%= render(Primer::Alpha::BorderBox::Header.new) do %>
29
+ # <%= render(Primer::Beta::BorderBox::Header.new) do %>
30
30
  # Header
31
31
  # <% end %>
32
32
  #
33
33
  # @example with title
34
- # <%= render(Primer::Alpha::BorderBox::Header.new) do |h| %>
34
+ # <%= render(Primer::Beta::BorderBox::Header.new) do |h| %>
35
35
  # <% h.title(tag: :h3) do %>I am a title<% end %>
36
36
  # <% end %>
37
37
  #
@@ -0,0 +1,147 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ module Beta
5
+ # `BorderBox` is a Box component with a border.
6
+ class BorderBox < Primer::Component
7
+ status :beta
8
+
9
+ DEFAULT_PADDING = :default
10
+ PADDING_MAPPINGS = {
11
+ DEFAULT_PADDING => "",
12
+ :condensed => "Box--condensed",
13
+ :spacious => "Box--spacious"
14
+ }.freeze
15
+ PADDING_SUGGESTION = "Perhaps you could consider using :padding options of #{PADDING_MAPPINGS.keys.to_sentence}?"
16
+
17
+ DEFAULT_ROW_SCHEME = :default
18
+ ROW_SCHEME_MAPPINGS = {
19
+ DEFAULT_ROW_SCHEME => "",
20
+ :neutral => "Box-row--gray",
21
+ :info => "Box-row--blue",
22
+ :warning => "Box-row--yellow"
23
+ }.freeze
24
+
25
+ # Optional Header.
26
+ #
27
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
28
+ # @accessibility
29
+ # When using header.title, the recommended tag is a heading tag, such as h1, h2, h3, etc.
30
+ renders_one :header, "Primer::Beta::BorderBox::Header"
31
+
32
+ # Optional Body.
33
+ #
34
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
35
+ renders_one :body, lambda { |**system_arguments|
36
+ system_arguments[:tag] = :div
37
+ system_arguments[:classes] = class_names(
38
+ "Box-body",
39
+ system_arguments[:classes]
40
+ )
41
+
42
+ Primer::BaseComponent.new(**system_arguments)
43
+ }
44
+
45
+ # Optional Footer.
46
+ #
47
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
48
+ renders_one :footer, lambda { |**system_arguments|
49
+ system_arguments[:tag] = :div
50
+ system_arguments[:classes] = class_names(
51
+ "Box-footer",
52
+ system_arguments[:classes]
53
+ )
54
+
55
+ Primer::BaseComponent.new(**system_arguments)
56
+ }
57
+
58
+ # Use Rows to add rows with borders and maintain the same padding.
59
+ #
60
+ # @param scheme [Symbol] Color scheme. <%= one_of(Primer::Beta::BorderBox::ROW_SCHEME_MAPPINGS.keys) %>
61
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
62
+ renders_many :rows, lambda { |scheme: DEFAULT_ROW_SCHEME, **system_arguments|
63
+ system_arguments[:tag] = :li
64
+ system_arguments[:classes] = class_names(
65
+ "Box-row",
66
+ ROW_SCHEME_MAPPINGS[fetch_or_fallback(ROW_SCHEME_MAPPINGS.keys, scheme, DEFAULT_ROW_SCHEME)],
67
+ system_arguments[:classes]
68
+ )
69
+
70
+ Primer::BaseComponent.new(**system_arguments)
71
+ }
72
+
73
+ # @example Header with title, body, rows, and footer
74
+ # <%= render(Primer::Beta::BorderBox.new) do |component| %>
75
+ # <% component.header do |h| %>
76
+ # <% h.title(tag: :h2) do %>
77
+ # Header
78
+ # <% end %>
79
+ # <% end %>
80
+ # <% component.body do %>
81
+ # Body
82
+ # <% end %>
83
+ # <% component.row do %>
84
+ # <% if true %>
85
+ # Row one
86
+ # <% end %>
87
+ # <% end %>
88
+ # <% component.row do %>
89
+ # Row two
90
+ # <% end %>
91
+ # <% component.footer do %>
92
+ # Footer
93
+ # <% end %>
94
+ # <% end %>
95
+ #
96
+ # @example Padding density
97
+ # <%= render(Primer::Beta::BorderBox.new(padding: :condensed)) do |component| %>
98
+ # <% component.header do %>
99
+ # Header
100
+ # <% end %>
101
+ # <% component.body do %>
102
+ # Body
103
+ # <% end %>
104
+ # <% component.row do %>
105
+ # Row two
106
+ # <% end %>
107
+ # <% component.footer do %>
108
+ # Footer
109
+ # <% end %>
110
+ # <% end %>
111
+ #
112
+ # @example Row colors
113
+ # <%= render(Primer::Beta::BorderBox.new) do |component| %>
114
+ # <% component.row do %>
115
+ # Default
116
+ # <% end %>
117
+ # <% component.row(scheme: :neutral) do %>
118
+ # Neutral
119
+ # <% end %>
120
+ # <% component.row(scheme: :info) do %>
121
+ # Info
122
+ # <% end %>
123
+ # <% component.row(scheme: :warning) do %>
124
+ # Warning
125
+ # <% end %>
126
+ # <% end %>
127
+ #
128
+ # @param padding [Symbol] <%= one_of(Primer::Beta::BorderBox::PADDING_MAPPINGS.keys) %>
129
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
130
+ def initialize(padding: DEFAULT_PADDING, **system_arguments)
131
+ @system_arguments = deny_tag_argument(**system_arguments)
132
+ @system_arguments[:tag] = :div
133
+ @system_arguments[:classes] = class_names(
134
+ "Box",
135
+ PADDING_MAPPINGS[fetch_or_fallback(PADDING_MAPPINGS.keys, padding, DEFAULT_PADDING)],
136
+ system_arguments[:classes]
137
+ )
138
+
139
+ @system_arguments[:system_arguments_denylist] = { [:p, :pt, :pb, :pr, :pl] => PADDING_SUGGESTION }
140
+ end
141
+
142
+ def render?
143
+ rows.any? || header.present? || body.present? || footer.present?
144
+ end
145
+ end
146
+ end
147
+ end