primer_view_components 0.8.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +85 -0
- data/app/assets/javascripts/app/components/primer/primer.d.ts +1 -1
- data/app/assets/javascripts/primer_view_components.js +1 -1
- data/app/assets/javascripts/primer_view_components.js.map +1 -1
- data/app/assets/styles/primer_view_components.css +1 -1
- data/app/assets/styles/primer_view_components.css.map +1 -1
- data/app/components/primer/alpha/action_bar/item.rb +3 -2
- data/app/components/primer/alpha/action_bar.rb +1 -5
- data/app/components/primer/alpha/action_menu/action_menu_element.js +2 -1
- data/app/components/primer/alpha/action_menu/action_menu_element.ts +2 -1
- data/app/components/primer/alpha/check_box_group.rb +2 -0
- data/app/components/primer/alpha/dialog/header.rb +12 -0
- data/app/components/primer/alpha/dialog.rb +1 -1
- data/app/components/primer/alpha/nav_list/divider.rb +2 -5
- data/app/components/primer/alpha/nav_list/group.rb +2 -98
- data/app/components/primer/alpha/nav_list/heading.rb +2 -27
- data/app/components/primer/alpha/nav_list/item.rb +2 -147
- data/app/components/primer/alpha/nav_list.rb +2 -205
- data/app/components/primer/alpha/overlay.css +1 -1
- data/app/components/primer/alpha/overlay.css.json +3 -1
- data/app/components/primer/alpha/overlay.css.map +1 -1
- data/app/components/primer/alpha/overlay.pcss +5 -7
- data/app/components/primer/alpha/overlay.rb +6 -4
- data/app/components/primer/alpha/radio_button_group.rb +2 -0
- data/app/components/primer/alpha/text_field.css +1 -1
- data/app/components/primer/alpha/text_field.css.json +4 -1
- data/app/components/primer/alpha/text_field.css.map +1 -1
- data/app/components/primer/alpha/text_field.pcss +18 -3
- data/app/components/primer/alpha/tool_tip.js +28 -8
- data/app/components/primer/alpha/tool_tip.ts +27 -8
- data/app/components/primer/alpha/tooltip.rb +3 -1
- data/app/components/primer/anchored_position.js +14 -5
- data/app/components/primer/anchored_position.ts +13 -4
- data/app/components/primer/beta/button.css +1 -1
- data/app/components/primer/beta/button.css.json +2 -0
- data/app/components/primer/beta/button.css.map +1 -1
- data/app/components/primer/beta/button.pcss +11 -3
- data/app/components/primer/beta/icon_button.html.erb +1 -1
- data/app/components/primer/beta/icon_button.rb +8 -1
- data/app/components/primer/beta/link.css +1 -1
- data/app/components/primer/beta/link.css.json +1 -0
- data/app/components/primer/beta/link.css.map +1 -1
- data/app/components/primer/beta/link.pcss +5 -0
- data/app/components/primer/beta/link.rb +2 -2
- data/app/components/primer/beta/nav_list/divider.rb +14 -0
- data/app/components/primer/beta/nav_list/group.rb +107 -0
- data/app/components/primer/beta/nav_list/heading.rb +36 -0
- data/app/components/primer/beta/nav_list/item.rb +156 -0
- data/app/components/primer/beta/nav_list.rb +212 -0
- data/app/components/primer/beta/spinner.html.erb +1 -1
- data/app/components/primer/focus_group.js +2 -1
- data/app/components/primer/focus_group.ts +2 -1
- data/app/components/primer/primer.d.ts +1 -1
- data/app/components/primer/primer.js +1 -1
- data/app/components/primer/primer.ts +1 -1
- data/app/helpers/primer/form_helper.rb +10 -0
- data/lib/primer/deprecations.yml +20 -0
- data/lib/primer/forms/check_box_group.html.erb +3 -0
- data/lib/primer/forms/dsl/check_box_group_input.rb +1 -5
- data/lib/primer/forms/dsl/check_box_input.rb +5 -0
- data/lib/primer/forms/dsl/radio_button_input.rb +5 -0
- data/lib/primer/forms/form_control.html.erb +1 -4
- data/lib/primer/forms/radio_button_group.html.erb +3 -0
- data/lib/primer/forms/utils.rb +2 -0
- data/lib/primer/forms/validation_message.html.erb +4 -0
- data/lib/primer/forms/validation_message.rb +14 -0
- data/lib/primer/forms.rb +16 -0
- data/lib/primer/view_components/linters/migrations/iconbutton_component.rb +36 -0
- data/lib/primer/view_components/version.rb +1 -1
- data/lib/primer/yard/component_manifest.rb +4 -0
- data/previews/primer/alpha/check_box_group_preview.rb +13 -0
- data/previews/primer/alpha/dialog_preview/with_header.html.erb +5 -0
- data/previews/primer/alpha/dialog_preview.rb +17 -0
- data/previews/primer/alpha/overlay_preview/in_an_action_menu.html.erb +13 -0
- data/previews/primer/alpha/overlay_preview.rb +5 -0
- data/previews/primer/alpha/radio_button_group_preview.rb +13 -0
- data/previews/primer/alpha/radio_button_preview.rb +1 -1
- data/previews/primer/alpha/text_field_preview/input_group_leading_action_menu.html.erb +21 -0
- data/previews/primer/alpha/text_field_preview/input_group_leading_button.html.erb +18 -0
- data/previews/primer/alpha/text_field_preview/input_group_trailing_button.html.erb +18 -0
- data/previews/primer/alpha/text_field_preview.rb +21 -0
- data/previews/primer/beta/button_preview.rb +1 -1
- data/previews/primer/{alpha → beta}/nav_list_preview/trailing_action.html.erb +1 -1
- data/previews/primer/{alpha → beta}/nav_list_preview.rb +5 -5
- data/static/arguments.json +182 -6
- data/static/audited_at.json +5 -0
- data/static/classes.json +3 -0
- data/static/constants.json +23 -0
- data/static/info_arch.json +1013 -523
- data/static/previews.json +98 -7
- data/static/statuses.json +10 -5
- metadata +25 -11
- /data/app/assets/javascripts/app/components/primer/{alpha → beta}/nav_list.d.ts +0 -0
- /data/app/components/primer/{alpha → beta}/nav_list/group.html.erb +0 -0
- /data/app/components/primer/{alpha → beta}/nav_list/item.html.erb +0 -0
- /data/app/components/primer/{alpha → beta}/nav_list.d.ts +0 -0
- /data/app/components/primer/{alpha → beta}/nav_list.html.erb +0 -0
- /data/app/components/primer/{alpha → beta}/nav_list.js +0 -0
- /data/app/components/primer/{alpha → beta}/nav_list.ts +0 -0
@@ -0,0 +1,212 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Primer
|
4
|
+
module Beta
|
5
|
+
# `NavList` provides a simple way to render side navigation, i.e. navigation
|
6
|
+
# that appears to the left or right side of some main content. Each group in a
|
7
|
+
# nav list is a list of links.
|
8
|
+
#
|
9
|
+
# Nav list groups can contain sub items. Rather than navigating to a URL, groups
|
10
|
+
# with sub items expand and collapse on click. To indicate this functionality, the
|
11
|
+
# group will automatically render with a trailing chevron icon that changes direction
|
12
|
+
# when the group expands and collapses.
|
13
|
+
#
|
14
|
+
# Nav list items appear visually active when selected. Each nav item must have one
|
15
|
+
# or more ID values that determine which item will appear selected. Use the
|
16
|
+
# `selected_item_id` argument to select the appropriate item.
|
17
|
+
class NavList < Primer::Component
|
18
|
+
status :beta
|
19
|
+
audited_at "2023-07-10"
|
20
|
+
|
21
|
+
# @private
|
22
|
+
def self.custom_element_name
|
23
|
+
"nav-list"
|
24
|
+
end
|
25
|
+
|
26
|
+
# The heading for the list at large. Accepts the arguments accepted by <%= link_to_component(Primer::Beta::NavList::Heading) %>.
|
27
|
+
#
|
28
|
+
renders_one :heading, Primer::Beta::NavList::Heading
|
29
|
+
|
30
|
+
# @!parse
|
31
|
+
# # Adds an item to the list.
|
32
|
+
# #
|
33
|
+
# # @param component_klass [Class] The class to use instead of the default <%= link_to_component(Primer::Beta::NavList::Item) %>
|
34
|
+
# # @param system_arguments [Hash] These arguments are forwarded to <%= link_to_component(Primer::Beta::NavList::Item) %>, or whatever class is passed as the `component_klass` argument.
|
35
|
+
# def with_item(component_klass: Primer::Beta::NavList::Item, **system_arguments, &block)
|
36
|
+
# end
|
37
|
+
|
38
|
+
# @!parse
|
39
|
+
# # Adds an avatar item to the list. Avatar items are a convenient way to accessibly add an item with a leading avatar image.
|
40
|
+
# #
|
41
|
+
# # @param src [String] The source url of the avatar image.
|
42
|
+
# # @param username [String] The username associated with the avatar.
|
43
|
+
# # @param full_name [String] Optional. The user's full name.
|
44
|
+
# # @param full_name_scheme [Symbol] Optional. How to display the user's full name. <%= one_of(Primer::Alpha::ActionList::Item::DESCRIPTION_SCHEME_OPTIONS) %>
|
45
|
+
# # @param component_klass [Class] The class to use instead of the default <%= link_to_component(Primer::Beta::NavList::Item) %>
|
46
|
+
# # @param avatar_arguments [Hash] Optional. The arguments accepted by <%= link_to_component(Primer::Beta::Avatar) %>
|
47
|
+
# # @param system_arguments [Hash] These arguments are forwarded to <%= link_to_component(Primer::Beta::NavList::Item) %>, or whatever class is passed as the `component_klass` argument.
|
48
|
+
# def with_avatar_item(src:, username:, full_name: nil, full_name_scheme: Primer::Alpha::ActionList::Item::DEFAULT_DESCRIPTION_SCHEME, component_klass: Primer::Beta::NavList::Item, avatar_arguments: {}, **system_arguments, &block)
|
49
|
+
# end
|
50
|
+
|
51
|
+
# @!parse
|
52
|
+
# # Adds a group to the list. A group is a list of links and a (required) heading.
|
53
|
+
# #
|
54
|
+
# # @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Beta::NavList::Group) %>.
|
55
|
+
# def with_group(**system_arguments, &block)
|
56
|
+
# end
|
57
|
+
|
58
|
+
# @!parse
|
59
|
+
# # Adds a divider to the list. Dividers visually separate items and groups.
|
60
|
+
# #
|
61
|
+
# # @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Beta::NavList::Divider) %>.
|
62
|
+
# def with_divider(**system_arguments, &block)
|
63
|
+
# end
|
64
|
+
|
65
|
+
# Items. Items can be individual items, dividers, or groups. See the documentation for `#with_item`, `#with_divider`, and `#with_group` respectively for more information.
|
66
|
+
#
|
67
|
+
renders_many :items, types: {
|
68
|
+
item: {
|
69
|
+
renders: lambda { |**system_arguments, &block|
|
70
|
+
build_item(**system_arguments, &block)
|
71
|
+
},
|
72
|
+
|
73
|
+
as: :item
|
74
|
+
},
|
75
|
+
|
76
|
+
avatar_item: {
|
77
|
+
renders: lambda { |**system_arguments|
|
78
|
+
build_avatar_item(**system_arguments)
|
79
|
+
},
|
80
|
+
|
81
|
+
as: :avatar_item
|
82
|
+
},
|
83
|
+
|
84
|
+
divider: {
|
85
|
+
renders: Primer::Beta::NavList::Divider,
|
86
|
+
as: :divider
|
87
|
+
},
|
88
|
+
|
89
|
+
group: {
|
90
|
+
renders: lambda { |**system_arguments, &block|
|
91
|
+
Primer::Beta::NavList::Group.new(
|
92
|
+
selected_item_id: @selected_item_id,
|
93
|
+
**system_arguments,
|
94
|
+
&block
|
95
|
+
)
|
96
|
+
},
|
97
|
+
|
98
|
+
as: :group
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
# @param selected_item_id [Symbol] The ID of the currently selected item. The default is `nil`, meaning no item is selected.
|
103
|
+
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
104
|
+
def initialize(selected_item_id: nil, **system_arguments)
|
105
|
+
@system_arguments = system_arguments
|
106
|
+
@selected_item_id = selected_item_id
|
107
|
+
end
|
108
|
+
|
109
|
+
# Builds a new item but does not add it to the list. Use this method
|
110
|
+
# instead of the `#with_item` slot if you need to render an item outside
|
111
|
+
# the context of a list, eg. if rendering additional items to append to
|
112
|
+
# an existing list, perhaps via a separate HTTP request.
|
113
|
+
#
|
114
|
+
# @param component_klass [Class] The class to use instead of the default <%= link_to_component(Primer::Beta::NavList::Item) %>
|
115
|
+
# @param system_arguments [Hash] These arguments are forwarded to <%= link_to_component(Primer::Beta::NavList::Item) %>, or whatever class is passed as the `component_klass` argument.
|
116
|
+
def build_item(component_klass: Primer::Beta::NavList::Item, **system_arguments, &block)
|
117
|
+
component_klass.new(
|
118
|
+
list: top_level_group,
|
119
|
+
selected_item_id: @selected_item_id,
|
120
|
+
**system_arguments,
|
121
|
+
&block
|
122
|
+
)
|
123
|
+
end
|
124
|
+
|
125
|
+
# Builds a new avatar item but does not add it to the list. Avatar items
|
126
|
+
# are a convenient way to accessibly add an item with a leading avatar
|
127
|
+
# image. Use this method instead of the `#with_avatar_item` slot if you
|
128
|
+
# need to render an avatar item outside the context of a list, eg. if
|
129
|
+
# rendering additional items to append to an existing list, perhaps via
|
130
|
+
# a separate HTTP request.
|
131
|
+
#
|
132
|
+
# @param src [String] The source url of the avatar image.
|
133
|
+
# @param username [String] The username associated with the avatar.
|
134
|
+
# @param full_name [String] Optional. The user's full name.
|
135
|
+
# @param full_name_scheme [Symbol] Optional. How to display the user's full name. <%= one_of(Primer::Alpha::ActionList::Item::DESCRIPTION_SCHEME_OPTIONS) %>
|
136
|
+
# @param component_klass [Class] The class to use instead of the default <%= link_to_component(Primer::Beta::NavList::Item) %>
|
137
|
+
# @param avatar_arguments [Hash] Optional. The arguments accepted by <%= link_to_component(Primer::Beta::Avatar) %>
|
138
|
+
# @param system_arguments [Hash] These arguments are forwarded to <%= link_to_component(Primer::Beta::NavList::Item) %>, or whatever class is passed as the `component_klass` argument.
|
139
|
+
def build_avatar_item(src:, username:, full_name: nil, full_name_scheme: Primer::Alpha::ActionList::Item::DEFAULT_DESCRIPTION_SCHEME, component_klass: Primer::Beta::NavList::Item, avatar_arguments: {}, **system_arguments)
|
140
|
+
component_klass.new(
|
141
|
+
list: top_level_group,
|
142
|
+
selected_item_id: @selected_item_id,
|
143
|
+
label: username,
|
144
|
+
description_scheme: full_name_scheme,
|
145
|
+
**system_arguments
|
146
|
+
).tap do |item|
|
147
|
+
item.with_leading_visual_raw_content do
|
148
|
+
# no alt text necessary
|
149
|
+
item.render(Primer::Beta::Avatar.new(src: src, **avatar_arguments, role: :presentation, size: 16))
|
150
|
+
end
|
151
|
+
|
152
|
+
item.with_description_content(full_name) if full_name
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
private
|
157
|
+
|
158
|
+
def before_render
|
159
|
+
if heading?
|
160
|
+
raise ArgumentError, "Please don't set an aria-label if a heading is provided" if aria(:label, @system_arguments)
|
161
|
+
|
162
|
+
@system_arguments[:aria] = merge_aria(
|
163
|
+
@system_arguments,
|
164
|
+
{ aria: { labelledby: heading.id } }
|
165
|
+
)
|
166
|
+
else
|
167
|
+
raise ArgumentError, "When no heading is provided, an aria-label must be given" unless aria(:label, @system_arguments)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
# Lists that contain top-level items (i.e. items outside of a group) should be wrapped in a <ul>
|
172
|
+
def render_outer_list?
|
173
|
+
items.any? { |item| !group?(item) }
|
174
|
+
end
|
175
|
+
|
176
|
+
def render_divider_between?(item1, item2)
|
177
|
+
return false if either_is_divider?(item1, item2)
|
178
|
+
|
179
|
+
both_are_groups?(item1, item2) || heterogeneous?(item1, item2)
|
180
|
+
end
|
181
|
+
|
182
|
+
def both_are_groups?(item1, item2)
|
183
|
+
group?(item1) && group?(item2)
|
184
|
+
end
|
185
|
+
|
186
|
+
def heterogeneous?(item1, item2)
|
187
|
+
kind(item1) != kind(item2)
|
188
|
+
end
|
189
|
+
|
190
|
+
def either_is_divider?(item1, item2)
|
191
|
+
divider?(item1) || divider?(item2)
|
192
|
+
end
|
193
|
+
|
194
|
+
def group?(item)
|
195
|
+
kind(item) == :group
|
196
|
+
end
|
197
|
+
|
198
|
+
def divider?(item)
|
199
|
+
kind(item) == :divider
|
200
|
+
end
|
201
|
+
|
202
|
+
def kind(item)
|
203
|
+
item.respond_to?(:kind) ? item.kind : :item
|
204
|
+
end
|
205
|
+
|
206
|
+
def top_level_group
|
207
|
+
# dummy group for the list: argument in the item slot above
|
208
|
+
@top_level_group ||= Primer::Beta::NavList::Group.new(selected_item_id: @selected_item_id)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
1
|
<%= render Primer::BaseComponent.new(**@system_arguments) do %>
|
2
|
-
<circle cx="8" cy="8" r="7" stroke="currentColor" stroke-opacity="0.25" stroke-width="2" vector-effect="non-scaling-stroke" />
|
2
|
+
<circle cx="8" cy="8" r="7" stroke="currentColor" stroke-opacity="0.25" stroke-width="2" vector-effect="non-scaling-stroke" fill="none" />
|
3
3
|
<path d="M15 8a7.002 7.002 0 00-7-7" stroke="currentColor" stroke-width="2" stroke-linecap="round" vector-effect="non-scaling-stroke" />
|
4
4
|
<% end %>
|
@@ -11,7 +11,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
11
11
|
};
|
12
12
|
var _FocusGroupElement_instances, _FocusGroupElement_abortController, _FocusGroupElement_items_get;
|
13
13
|
import '@oddbird/popover-polyfill';
|
14
|
-
const
|
14
|
+
const validSelectors = ['[role="menuitem"]', '[role="menuitemcheckbox"]', '[role="menuitemradio"]'];
|
15
|
+
const menuItemSelector = validSelectors.map(selector => `:not([hidden]) > ${selector}`).join(', ');
|
15
16
|
const getMnemonicFor = (item) => { var _a; return (_a = item.textContent) === null || _a === void 0 ? void 0 : _a.trim()[0].toLowerCase(); };
|
16
17
|
const printable = /^\S$/;
|
17
18
|
export default class FocusGroupElement extends HTMLElement {
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import '@oddbird/popover-polyfill'
|
2
2
|
|
3
|
-
const
|
3
|
+
const validSelectors = ['[role="menuitem"]', '[role="menuitemcheckbox"]', '[role="menuitemradio"]']
|
4
|
+
const menuItemSelector = validSelectors.map(selector => `:not([hidden]) > ${selector}`).join(', ')
|
4
5
|
|
5
6
|
const getMnemonicFor = (item: Element) => item.textContent?.trim()[0].toLowerCase()
|
6
7
|
|
@@ -6,7 +6,7 @@ import './anchored_position';
|
|
6
6
|
import './focus_group';
|
7
7
|
import './alpha/image_crop';
|
8
8
|
import './alpha/modal_dialog';
|
9
|
-
import './
|
9
|
+
import './beta/nav_list';
|
10
10
|
import './alpha/segmented_control';
|
11
11
|
import './alpha/toggle_switch';
|
12
12
|
import './alpha/tool_tip';
|
@@ -6,7 +6,7 @@ import './anchored_position';
|
|
6
6
|
import './focus_group';
|
7
7
|
import './alpha/image_crop';
|
8
8
|
import './alpha/modal_dialog';
|
9
|
-
import './
|
9
|
+
import './beta/nav_list';
|
10
10
|
import './alpha/segmented_control';
|
11
11
|
import './alpha/toggle_switch';
|
12
12
|
import './alpha/tool_tip';
|
@@ -6,7 +6,7 @@ import './anchored_position'
|
|
6
6
|
import './focus_group'
|
7
7
|
import './alpha/image_crop'
|
8
8
|
import './alpha/modal_dialog'
|
9
|
-
import './
|
9
|
+
import './beta/nav_list'
|
10
10
|
import './alpha/segmented_control'
|
11
11
|
import './alpha/toggle_switch'
|
12
12
|
import './alpha/tool_tip'
|
@@ -19,5 +19,15 @@ module Primer
|
|
19
19
|
&block
|
20
20
|
)
|
21
21
|
end
|
22
|
+
|
23
|
+
def inline_form(*args, &block)
|
24
|
+
Primer::Forms.inline_form(*args, &block)
|
25
|
+
end
|
26
|
+
|
27
|
+
def render_inline_form(*args, &block)
|
28
|
+
# rubocop:disable GitHub/RailsViewRenderLiteral
|
29
|
+
render(inline_form(*args, &block))
|
30
|
+
# rubocop:enable GitHub/RailsViewRenderLiteral
|
31
|
+
end
|
22
32
|
end
|
23
33
|
end
|
data/lib/primer/deprecations.yml
CHANGED
@@ -5,6 +5,26 @@
|
|
5
5
|
# See 'docs/contributors/deprecations.md' for information on configuration options.
|
6
6
|
|
7
7
|
deprecations:
|
8
|
+
- component: "Primer::Alpha::NavList::Divider"
|
9
|
+
autocorrect: true
|
10
|
+
replacement: "Primer::Beta::NavList::Divider"
|
11
|
+
|
12
|
+
- component: "Primer::Alpha::NavList::Item"
|
13
|
+
autocorrect: true
|
14
|
+
replacement: "Primer::Beta::NavList::Item"
|
15
|
+
|
16
|
+
- component: "Primer::Alpha::NavList::Heading"
|
17
|
+
autocorrect: true
|
18
|
+
replacement: "Primer::Beta::NavList::Heading"
|
19
|
+
|
20
|
+
- component: "Primer::Alpha::NavList::Group"
|
21
|
+
autocorrect: true
|
22
|
+
replacement: "Primer::Beta::NavList::Group"
|
23
|
+
|
24
|
+
- component: "Primer::Alpha::NavList"
|
25
|
+
autocorrect: true
|
26
|
+
replacement: "Primer::Beta::NavList"
|
27
|
+
|
8
28
|
- component: "Primer::Alpha::AutoComplete"
|
9
29
|
autocorrect: true
|
10
30
|
replacement: "Primer::Beta::AutoComplete"
|
@@ -5,7 +5,7 @@ module Primer
|
|
5
5
|
module Dsl
|
6
6
|
# :nodoc:
|
7
7
|
class CheckBoxGroupInput < Input
|
8
|
-
attr_reader :label, :check_boxes
|
8
|
+
attr_reader :name, :label, :check_boxes
|
9
9
|
|
10
10
|
def initialize(name: nil, label: nil, **system_arguments)
|
11
11
|
@name = name
|
@@ -21,10 +21,6 @@ module Primer
|
|
21
21
|
CheckBoxGroup.new(input: self)
|
22
22
|
end
|
23
23
|
|
24
|
-
def name
|
25
|
-
nil
|
26
|
-
end
|
27
|
-
|
28
24
|
def type
|
29
25
|
:check_box_group
|
30
26
|
end
|
@@ -9,10 +9,7 @@
|
|
9
9
|
<% end %>
|
10
10
|
<% end %>
|
11
11
|
<%= content %>
|
12
|
-
<%=
|
13
|
-
<span class="FormControl-inlineValidation--visual"><%= render(Primer::Beta::Octicon.new(icon: :"alert-fill", size: :xsmall, aria: { hidden: true })) %></span>
|
14
|
-
<%= content_tag(:span, @input.invalid? ? @input.validation_messages.first : "", **@input.validation_message_arguments) %>
|
15
|
-
<% end %>
|
12
|
+
<%= render(ValidationMessage.new(input: @input)) %>
|
16
13
|
<%= render(Caption.new(input: @input)) %>
|
17
14
|
<% end %>
|
18
15
|
<% else %>
|
data/lib/primer/forms/utils.rb
CHANGED
@@ -15,6 +15,8 @@ module Primer
|
|
15
15
|
# conventions, so it should work ok. Zeitwerk also has this information but lacks a
|
16
16
|
# public API to map constants to source files.
|
17
17
|
def const_source_location(class_name)
|
18
|
+
return nil unless class_name
|
19
|
+
|
18
20
|
# NOTE: underscore respects namespacing, i.e. will convert Foo::Bar to foo/bar.
|
19
21
|
class_path = "#{class_name.underscore}.rb"
|
20
22
|
|
@@ -0,0 +1,4 @@
|
|
1
|
+
<%= content_tag(:div, **@input.validation_arguments) do %>
|
2
|
+
<span class="FormControl-inlineValidation--visual"><%= render(Primer::Beta::Octicon.new(icon: :"alert-fill", size: :xsmall, aria: { hidden: true })) %></span>
|
3
|
+
<%= content_tag(:span, @input.invalid? ? @input.validation_messages.first : "", **@input.validation_message_arguments) %>
|
4
|
+
<% end %>
|
data/lib/primer/forms.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Primer
|
4
|
+
# :nodoc:
|
5
|
+
module Forms
|
6
|
+
def self.inline_form(builder, base = nil, &block)
|
7
|
+
base ||= defined?(ApplicationForm) ? ApplicationForm : Primer::Forms::Base
|
8
|
+
|
9
|
+
klass = Class.new(base) do
|
10
|
+
form(&block)
|
11
|
+
end
|
12
|
+
|
13
|
+
klass.new(builder)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Migrations
|
6
|
+
# Lint and autocorrect deprecated IconButton
|
7
|
+
class IconButtonComponent < RuboCop::Cop::Cop
|
8
|
+
INVALID_MESSAGE = <<~STR
|
9
|
+
`Primer::IconButton` is deprecated. Please use `Primer::Beta::IconButton` instead.
|
10
|
+
STR
|
11
|
+
|
12
|
+
def_node_matcher :icon_button, <<~PATTERN
|
13
|
+
(send $(const (const nil? :Primer) :IconButton) :new ...)
|
14
|
+
PATTERN
|
15
|
+
|
16
|
+
def_node_matcher :hash_with_box_value?, <<~PATTERN
|
17
|
+
(hash ... (pair (sym :box) (...)) ... )
|
18
|
+
PATTERN
|
19
|
+
|
20
|
+
def on_send(node)
|
21
|
+
return unless icon_button(node)
|
22
|
+
|
23
|
+
add_offense(node, message: INVALID_MESSAGE)
|
24
|
+
end
|
25
|
+
|
26
|
+
def autocorrect(node)
|
27
|
+
return if hash_with_box_value?(node.arguments.first)
|
28
|
+
|
29
|
+
lambda do |corrector|
|
30
|
+
corrector.replace(icon_button(node), "Primer::Beta::IconButton")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -73,6 +73,10 @@ module Primer
|
|
73
73
|
Primer::Alpha::NavList::Item => { js: true, examples: false },
|
74
74
|
Primer::Alpha::NavList::Group => { js: true, examples: false },
|
75
75
|
|
76
|
+
Primer::Beta::NavList => { js: true },
|
77
|
+
Primer::Beta::NavList::Item => { js: true, examples: false },
|
78
|
+
Primer::Beta::NavList::Group => { js: true, examples: false },
|
79
|
+
|
76
80
|
# ActionList is a base component that should not be used by itself, and thus
|
77
81
|
# does not have examples of its own
|
78
82
|
Primer::Alpha::ActionList => { js: true, examples: false },
|
@@ -9,17 +9,20 @@ module Primer
|
|
9
9
|
# @param name text
|
10
10
|
# @param label text
|
11
11
|
# @param caption text
|
12
|
+
# @param validation_message text
|
12
13
|
# @param disabled toggle
|
13
14
|
def playground(
|
14
15
|
name: "my-check-group",
|
15
16
|
label: "I would go into battle with:",
|
16
17
|
caption: "Qa'pla!",
|
18
|
+
validation_message: nil,
|
17
19
|
disabled: false
|
18
20
|
)
|
19
21
|
system_arguments = {
|
20
22
|
name: name,
|
21
23
|
label: label,
|
22
24
|
caption: caption,
|
25
|
+
validation_message: validation_message,
|
23
26
|
disabled: disabled
|
24
27
|
}
|
25
28
|
|
@@ -41,6 +44,16 @@ module Primer
|
|
41
44
|
end
|
42
45
|
end
|
43
46
|
|
47
|
+
# @label Invalid
|
48
|
+
def invalid
|
49
|
+
render(Primer::Alpha::CheckBoxGroup.new(validation_message: "Please choose at least one", name: "my-check-group", label: "I would go into battle with:")) do |component|
|
50
|
+
component.check_box(label: "Jean-Luc Picard", value: "picard4")
|
51
|
+
component.check_box(label: "Hikaru Sulu", value: "sulu4")
|
52
|
+
component.check_box(label: "Kathryn Janeway", value: "janeway4")
|
53
|
+
component.check_box(label: "Benjamin Sisko", value: "sisko4")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
44
57
|
# @!group Options
|
45
58
|
# @snapshot
|
46
59
|
#
|
@@ -60,6 +60,23 @@ module Primer
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
+
# @label With Header
|
64
|
+
#
|
65
|
+
# @param title [String] text
|
66
|
+
# @param subtitle [String] text
|
67
|
+
# @param header_variant [Symbol] select [medium, large]
|
68
|
+
# @param button_text [String] text
|
69
|
+
# @param show_divider [Boolean] toggle
|
70
|
+
def with_header(title: "Test Dialog", subtitle: nil, header_variant: :medium, button_text: "Show Dialog", show_divider: true)
|
71
|
+
render_with_template(locals: {
|
72
|
+
title: title,
|
73
|
+
subtitle: subtitle,
|
74
|
+
header_variant: header_variant,
|
75
|
+
button_text: button_text,
|
76
|
+
show_divider: show_divider
|
77
|
+
})
|
78
|
+
end
|
79
|
+
|
63
80
|
# @label With Footer
|
64
81
|
#
|
65
82
|
# @param title [String] text
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<%= render(Primer::Alpha::ActionMenu.new()) do |menu| %>
|
2
|
+
<% menu.with_show_button { "Menu" } %>
|
3
|
+
<% menu.with_item(label: "Open Overlay", content_arguments: { id: "overlay-show-my-overlay", popovertarget: "my-overlay" }) %>
|
4
|
+
<% end %>
|
5
|
+
<%= render(Primer::Alpha::Overlay.new(
|
6
|
+
id: "my-overlay",
|
7
|
+
title: "An overlay",
|
8
|
+
role: :dialog,
|
9
|
+
popover: "manual",
|
10
|
+
)) do |d| %>
|
11
|
+
<% d.with_header(title: "An overlay") %>
|
12
|
+
<% d.with_body { "This is an overlay" } %>
|
13
|
+
<% end %>
|
@@ -9,17 +9,20 @@ module Primer
|
|
9
9
|
# @param name text
|
10
10
|
# @param label text
|
11
11
|
# @param caption text
|
12
|
+
# @param validation_message text
|
12
13
|
# @param disabled toggle
|
13
14
|
def playground(
|
14
15
|
name: "my-radio-group",
|
15
16
|
label: "Question: what kind of bear is best?",
|
16
17
|
caption: "There are basically two schools of thought",
|
18
|
+
validation_message: nil,
|
17
19
|
disabled: false
|
18
20
|
)
|
19
21
|
system_arguments = {
|
20
22
|
name: name,
|
21
23
|
label: label,
|
22
24
|
caption: caption,
|
25
|
+
validation_message: validation_message,
|
23
26
|
disabled: disabled
|
24
27
|
}
|
25
28
|
|
@@ -40,6 +43,16 @@ module Primer
|
|
40
43
|
end
|
41
44
|
end
|
42
45
|
|
46
|
+
# @label Invalid
|
47
|
+
# @snapshot
|
48
|
+
def invalid
|
49
|
+
render(Primer::Alpha::RadioButtonGroup.new(validation_message: "Please select an option", name: "my-radio-group", label: "Question: what kind of bear is best?")) do |component|
|
50
|
+
component.radio_button(label: "Bears", value: "bears")
|
51
|
+
component.radio_button(label: "Beets", value: "beets")
|
52
|
+
component.radio_button(label: "Battlestar Galactica", value: "bsg")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
43
56
|
# @!group Options
|
44
57
|
#
|
45
58
|
# @label With caption
|
@@ -51,7 +51,7 @@ module Primer
|
|
51
51
|
# @label Checked
|
52
52
|
# @snapshot
|
53
53
|
def checked
|
54
|
-
render(Primer::Alpha::RadioButton.new(name: "my-radio-button", label: "Battlestar Galactica", value: "bsg2", checked: true
|
54
|
+
render(Primer::Alpha::RadioButton.new(name: "my-radio-button", label: "Battlestar Galactica", value: "bsg2", checked: true))
|
55
55
|
end
|
56
56
|
|
57
57
|
# @label Visually hidden label
|