openproject-primer_view_components 0.11.0 → 0.13.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 +110 -0
- data/app/assets/javascripts/app/components/primer/alpha/tool_tip.d.ts +1 -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 +7 -4
- data/app/components/primer/alpha/action_bar.rb +2 -2
- data/app/components/primer/alpha/action_bar_element.js +9 -4
- data/app/components/primer/alpha/action_bar_element.ts +9 -2
- data/app/components/primer/alpha/action_list/form_wrapper.html.erb +4 -2
- data/app/components/primer/alpha/action_list/form_wrapper.rb +20 -9
- data/app/components/primer/alpha/action_menu/action_menu_element.js +162 -86
- data/app/components/primer/alpha/action_menu/action_menu_element.ts +197 -82
- data/app/components/primer/alpha/action_menu/list.rb +0 -2
- data/app/components/primer/alpha/action_menu.rb +120 -3
- 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/modal_dialog.js +10 -13
- data/app/components/primer/alpha/modal_dialog.ts +10 -13
- 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.map +1 -1
- data/app/components/primer/alpha/overlay.pcss +1 -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/segmented_control/item.html.erb +1 -8
- data/app/components/primer/alpha/segmented_control/item.rb +38 -4
- data/app/components/primer/alpha/segmented_control.css +1 -1
- data/app/components/primer/alpha/segmented_control.css.json +14 -13
- data/app/components/primer/alpha/segmented_control.css.map +1 -1
- data/app/components/primer/alpha/segmented_control.pcss +75 -66
- data/app/components/primer/alpha/segmented_control.rb +10 -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.d.ts +1 -0
- data/app/components/primer/alpha/tool_tip.js +26 -93
- data/app/components/primer/alpha/tool_tip.ts +25 -91
- data/app/components/primer/alpha/tooltip.rb +3 -1
- data/app/components/primer/beta/base_button.rb +4 -0
- 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 +17 -5
- 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/focus_group.js +30 -4
- data/app/components/primer/focus_group.ts +29 -2
- data/app/components/primer/open_project/flex_layout.html.erb +23 -0
- data/app/components/primer/open_project/flex_layout.rb +52 -0
- data/app/components/primer/open_project/grid_layout/area.rb +38 -0
- data/app/components/primer/open_project/grid_layout.html.erb +11 -0
- data/app/components/primer/open_project/grid_layout.rb +34 -0
- data/app/components/primer/open_project/page_header.css +1 -1
- data/app/components/primer/open_project/page_header.css.map +1 -1
- data/app/components/primer/open_project/page_header.pcss +4 -0
- 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/accessibility.rb +3 -1
- 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/static/generate_info_arch.rb +86 -5
- data/lib/primer/view_components/version.rb +1 -1
- data/lib/primer/yard/component_manifest.rb +4 -0
- data/previews/primer/alpha/action_menu_preview/single_select_form_items.html.erb +31 -0
- data/previews/primer/alpha/action_menu_preview/with_actions.html.erb +6 -5
- data/previews/primer/alpha/action_menu_preview.rb +10 -1
- data/previews/primer/alpha/check_box_group_preview.rb +13 -0
- data/previews/primer/alpha/check_box_preview.rb +1 -0
- data/previews/primer/alpha/dialog_preview/autofocus_element.html.erb +8 -0
- data/previews/primer/alpha/dialog_preview/with_header.html.erb +5 -0
- data/previews/primer/alpha/dialog_preview.rb +22 -0
- data/previews/primer/alpha/overlay_preview.rb +1 -1
- data/previews/primer/alpha/radio_button_group_preview.rb +13 -0
- data/previews/primer/alpha/radio_button_preview.rb +2 -1
- data/previews/primer/alpha/segmented_control_preview.rb +35 -0
- 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/alpha/tooltip_preview/tooltip_with_dialog_moving_focus_to_input.html.erb +23 -0
- data/previews/primer/alpha/tooltip_preview.rb +6 -1
- data/previews/primer/beta/button_group_preview.rb +6 -6
- data/previews/primer/beta/button_preview.rb +21 -3
- data/previews/primer/beta/icon_button_preview.rb +3 -0
- 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/previews/primer/open_project/flex_layout_preview.rb +73 -0
- data/previews/primer/open_project/grid_layout_preview.rb +37 -0
- data/static/arguments.json +278 -7
- data/static/audited_at.json +8 -0
- data/static/classes.json +15 -0
- data/static/constants.json +47 -1
- data/static/info_arch.json +1338 -632
- data/static/previews.json +271 -167
- data/static/statuses.json +13 -5
- metadata +33 -319
- /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
@@ -1,12 +1,15 @@
|
|
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
|
|
7
8
|
const printable = /^\S$/
|
8
9
|
|
9
10
|
export default class FocusGroupElement extends HTMLElement {
|
11
|
+
#retainSignal: AbortController | null = null
|
12
|
+
|
10
13
|
get nowrap(): boolean {
|
11
14
|
return this.hasAttribute('nowrap')
|
12
15
|
}
|
@@ -59,8 +62,32 @@ export default class FocusGroupElement extends HTMLElement {
|
|
59
62
|
const {direction, nowrap} = this
|
60
63
|
if (event.type === 'focusin') {
|
61
64
|
if (this.retain && event.target instanceof Element && event.target.matches(menuItemSelector)) {
|
65
|
+
this.#retainSignal?.abort()
|
66
|
+
const {signal} = (this.#retainSignal = new AbortController())
|
62
67
|
for (const item of this.#items) {
|
63
68
|
item.setAttribute('tabindex', item === event.target ? '0' : '-1')
|
69
|
+
const popover = event.target.closest<HTMLElement>('[popover]')
|
70
|
+
if (item === event.target && popover?.popover === 'auto' && popover.closest('focus-group') === this) {
|
71
|
+
popover.addEventListener(
|
72
|
+
'toggle',
|
73
|
+
(toggleEvent: Event) => {
|
74
|
+
if (!(toggleEvent.target instanceof Element)) return
|
75
|
+
if ((toggleEvent as ToggleEvent).newState === 'closed') {
|
76
|
+
this.#retainSignal?.abort()
|
77
|
+
item.setAttribute('tabindex', '-1')
|
78
|
+
if (popover.id) {
|
79
|
+
const invoker = this.querySelector(`[popovertarget="${popover.id}"]`)
|
80
|
+
if (invoker) {
|
81
|
+
invoker.setAttribute('tabindex', '0')
|
82
|
+
} else {
|
83
|
+
this.#items[0]?.setAttribute('tabindex', '0')
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
},
|
88
|
+
{signal}
|
89
|
+
)
|
90
|
+
}
|
64
91
|
}
|
65
92
|
}
|
66
93
|
} else if (event instanceof KeyboardEvent) {
|
@@ -110,7 +137,7 @@ export default class FocusGroupElement extends HTMLElement {
|
|
110
137
|
let el: HTMLElement | null = focusEl
|
111
138
|
do {
|
112
139
|
el = el.closest(`[popover]:not(:popover-open)`)
|
113
|
-
if (el?.popover === 'auto') {
|
140
|
+
if (el?.popover === 'auto' && !['ArrowRight', 'ArrowLeft'].includes(event.key)) {
|
114
141
|
el.showPopover()
|
115
142
|
}
|
116
143
|
el = el?.parentElement || null
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<% if rows.any? %>
|
2
|
+
<%= render(Primer::Box.new(**@system_arguments.merge(direction: :column))) do %>
|
3
|
+
<% rows.each do |row| %>
|
4
|
+
<%= row %>
|
5
|
+
<% end %>
|
6
|
+
<% end %>
|
7
|
+
<% end %>
|
8
|
+
|
9
|
+
<% if columns.any? %>
|
10
|
+
<%= render(Primer::Box.new(**@system_arguments.merge(direction: :row))) do %>
|
11
|
+
<% columns.each do |column| %>
|
12
|
+
<%= column %>
|
13
|
+
<% end %>
|
14
|
+
<% end %>
|
15
|
+
<% end %>
|
16
|
+
|
17
|
+
<% if boxes.any? %>
|
18
|
+
<%= render(Primer::Box.new(**@system_arguments)) do %>
|
19
|
+
<% boxes.each do |box| %>
|
20
|
+
<%= box %>
|
21
|
+
<% end %>
|
22
|
+
<% end %>
|
23
|
+
<% end %>
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Primer
|
4
|
+
module OpenProject
|
5
|
+
# A layouting component used to arrange multiple components next / below each other
|
6
|
+
class FlexLayout < Primer::Component
|
7
|
+
status :open_project
|
8
|
+
|
9
|
+
renders_many :rows, lambda { |**system_arguments, &block|
|
10
|
+
child_component(system_arguments, &block)
|
11
|
+
}
|
12
|
+
renders_many :columns, lambda { |**system_arguments, &block|
|
13
|
+
child_component(system_arguments, &block)
|
14
|
+
}
|
15
|
+
# boxes are used when direction is set to row or column based on responsive breakpoints
|
16
|
+
renders_many :boxes, lambda { |**system_arguments, &block|
|
17
|
+
child_component(system_arguments, &block)
|
18
|
+
}
|
19
|
+
|
20
|
+
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
21
|
+
def initialize(**system_arguments)
|
22
|
+
super
|
23
|
+
|
24
|
+
@system_arguments = deny_tag_argument(**system_arguments) || {}
|
25
|
+
@system_arguments[:display] = :flex
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def render?
|
31
|
+
# no slot provided
|
32
|
+
raise ArgumentError, "You have to provide either rows, columns or boxes as a slot" if rows.empty? && columns.empty? && boxes.empty?
|
33
|
+
|
34
|
+
if [rows, columns, boxes].count { |arr| !arr.empty? } == 1
|
35
|
+
# only rows or columns or boxes are used
|
36
|
+
true
|
37
|
+
elsif [rows, columns, boxes].count { |arr| !arr.empty? } > 1
|
38
|
+
# rows, columns and boxes are used together, which is not allowed
|
39
|
+
raise ArgumentError, "You can't mix row, column and box slots"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def child_component(system_arguments, &block)
|
44
|
+
if system_arguments[:flex_layout] == true
|
45
|
+
Primer::OpenProject::FlexLayout.new(**system_arguments.except(:flex_layout), &block)
|
46
|
+
else
|
47
|
+
Primer::Box.new(**system_arguments || {})
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Primer
|
4
|
+
module OpenProject
|
5
|
+
class GridLayout
|
6
|
+
# GridLayout::Area is an internal component that wraps the items in a div with the given new class and responding "grid-area"
|
7
|
+
class Area < Primer::Component
|
8
|
+
status :open_project
|
9
|
+
|
10
|
+
DEFAULT_TAG = :div
|
11
|
+
TAG_OPTIONS = [DEFAULT_TAG, :span].freeze
|
12
|
+
|
13
|
+
# @param css_class [String] The basic css class applied on the grid-container
|
14
|
+
# @param area_name [Symbol] The specific area name, used for creating the element class and the "grid-area" style
|
15
|
+
# @param component [ViewComponent::Base] The instance of the component to be rendered.
|
16
|
+
# @param tag [Symbol] <%= one_of(Primer::OpenProject::GridLayout::Area::TAG_OPTIONS) %>
|
17
|
+
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
18
|
+
def initialize(css_class, area_name, component = ::Primer::BaseComponent, tag: DEFAULT_TAG, **system_arguments)
|
19
|
+
@component = component
|
20
|
+
@system_arguments = system_arguments
|
21
|
+
@styles = [
|
22
|
+
"grid-area: #{area_name}"
|
23
|
+
]
|
24
|
+
@system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, DEFAULT_TAG)
|
25
|
+
@system_arguments[:style] = join_style_arguments(@system_arguments[:style], *@styles)
|
26
|
+
@system_arguments[:classes] = class_names(
|
27
|
+
@system_arguments[:classes],
|
28
|
+
"#{css_class}--#{area_name}"
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
def call
|
33
|
+
render(@component.new(**@system_arguments)) { content }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Primer
|
4
|
+
module OpenProject
|
5
|
+
# A layouting component used to arrange multiple components in a CSS Grid
|
6
|
+
# Note that this component only provides helpers (as the class names and grid-area styles).
|
7
|
+
# However, it does not define the actual Grid which should be done in a separate CSS-file.
|
8
|
+
class GridLayout < Primer::Component
|
9
|
+
status :open_project
|
10
|
+
attr_reader :css_class
|
11
|
+
|
12
|
+
renders_many :areas, lambda { |area_name, component = ::Primer::BaseComponent, **system_arguments, &block|
|
13
|
+
render(Primer::OpenProject::GridLayout::Area.new(@css_class, area_name, component, **system_arguments), &block)
|
14
|
+
}
|
15
|
+
|
16
|
+
# @param css_class [String] The basic css class applied on the grid-container
|
17
|
+
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
18
|
+
def initialize(css_class:, **system_arguments)
|
19
|
+
super
|
20
|
+
|
21
|
+
@system_arguments = system_arguments
|
22
|
+
@css_class = css_class
|
23
|
+
@system_arguments[:classes] = class_names(
|
24
|
+
@system_arguments[:classes],
|
25
|
+
css_class
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
def render?
|
30
|
+
areas.any?
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1 +1 @@
|
|
1
|
-
.PageHeader{border-bottom:var(--borderWidth-thin,max(1px,.0625rem)) solid var(--borderColor-muted,var(--color-border-muted));display:flex;flex-flow:row wrap;justify-content:flex-end;margin-bottom:var(--stack-gap-normal,1rem);padding-bottom:var(--stack-padding-condensed,.5rem)}.PageHeader-title{flex:1 1 auto;font-size:24px;font-weight:var(--base-text-weight-normal,400);order:0}.PageHeader-title--large{font-size:var(--text-title-size-large,2rem)}.PageHeader-description{color:var(--fgColor-muted,var(--color-fg-muted));flex:1 100%;font-size:var(--text-body-size-medium,.875rem);order:2}.PageHeader-actions{align-self:center;justify-content:flex-end;margin:var(--base-size-4,.25rem) 0 var(--base-size-4,.25rem) var(--base-size-4,.25rem);order:1}.PageHeader-actions+.PageHeader-description{margin-top:var(--base-size-4,.25rem)}
|
1
|
+
.PageHeader{border-bottom:var(--borderWidth-thin,max(1px,.0625rem)) solid var(--borderColor-muted,var(--color-border-muted));display:flex;flex-flow:row wrap;justify-content:flex-end;margin-bottom:var(--stack-gap-normal,1rem);padding-bottom:var(--stack-padding-condensed,.5rem)}@media (max-width:767.98px){.PageHeader{border-bottom:0}}.PageHeader-title{flex:1 1 auto;font-size:24px;font-weight:var(--base-text-weight-normal,400);order:0}.PageHeader-title--large{font-size:var(--text-title-size-large,2rem)}.PageHeader-description{color:var(--fgColor-muted,var(--color-fg-muted));flex:1 100%;font-size:var(--text-body-size-medium,.875rem);order:2}.PageHeader-actions{align-self:center;justify-content:flex-end;margin:var(--base-size-4,.25rem) 0 var(--base-size-4,.25rem) var(--base-size-4,.25rem);order:1}.PageHeader-actions+.PageHeader-description{margin-top:var(--base-size-4,.25rem)}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["page_header.pcss"],"names":[],"mappings":"AAEA,YAIE,gHAAqE,CAHrE,YAAa,CAIb,kBAAmB,CACnB,wBAAyB,CAHzB,0CAAsC,CADtC,
|
1
|
+
{"version":3,"sources":["page_header.pcss"],"names":[],"mappings":"AAEA,YAIE,gHAAqE,CAHrE,YAAa,CAIb,kBAAmB,CACnB,wBAAyB,CAHzB,0CAAsC,CADtC,mDASF,CAHE,4BARF,YASI,eAEJ,CADE,CAGF,kBAGE,aAAc,CAFd,cAAe,CACf,8CAA2C,CAE3C,OACF,CAEA,yBACE,2CACF,CAGA,wBAEE,gDAA2B,CAC3B,WAAY,CAFZ,8CAAuC,CAGvC,OACF,CAGA,oBAEE,iBAAkB,CAClB,wBAAyB,CAFzB,sFAAkE,CAGlE,OAKF,CAHE,4CACE,oCACF","file":"page_header.css","sourcesContent":["/* OP PageHeader */\n\n.PageHeader {\n display: flex;\n padding-bottom: var(--stack-padding-condensed);\n margin-bottom: var(--stack-gap-normal);\n border-bottom: var(--borderWidth-thin) solid var(--borderColor-muted);\n flex-flow: row wrap;\n justify-content: flex-end; /* Keep actions right aligned. */\n\n @media (max-width: 767.98px) {\n border-bottom: 0;\n }\n}\n\n.PageHeader-title {\n font-size: 24px;\n font-weight: var(--base-text-weight-normal);\n flex: 1 1 auto;\n order: 0;\n}\n\n.PageHeader-title--large {\n font-size: var(--text-title-size-large);\n}\n\n/* One-liner of supporting text */\n.PageHeader-description {\n font-size: var(--text-body-size-medium);\n color: var(--fgColor-muted);\n flex: 1 100%;\n order: 2;\n}\n\n/* Add 1 or 2 buttons to the right of the heading */\n.PageHeader-actions {\n margin: var(--base-size-4) 0 var(--base-size-4) var(--base-size-4);\n align-self: center;\n justify-content: flex-end;\n order: 1;\n\n & + .PageHeader-description {\n margin-top: var(--base-size-4);\n }\n}\n"]}
|
@@ -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/accessibility.rb
CHANGED
@@ -8,7 +8,9 @@ module Primer
|
|
8
8
|
# Do not add to this list for any other reason!
|
9
9
|
IGNORED_PREVIEWS = [
|
10
10
|
Primer::Beta::MarkdownPreview,
|
11
|
-
Primer::Beta::AutoCompleteItemPreview
|
11
|
+
Primer::Beta::AutoCompleteItemPreview,
|
12
|
+
Primer::Alpha::RadioButtonPreview,
|
13
|
+
Primer::Alpha::CheckBoxPreview
|
12
14
|
].freeze
|
13
15
|
|
14
16
|
# Skip `:region` which relates to preview page structure rather than individual component.
|
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
|
@@ -3,6 +3,7 @@
|
|
3
3
|
# :nocov:
|
4
4
|
|
5
5
|
require "json"
|
6
|
+
require "kramdown"
|
6
7
|
|
7
8
|
module Primer
|
8
9
|
module Static
|
@@ -35,7 +36,7 @@ module Primer
|
|
35
36
|
# rubocop:disable Style/IfUnlessModifier
|
36
37
|
"description" =>
|
37
38
|
if slot_method.base_docstring.to_s.present?
|
38
|
-
|
39
|
+
render_erb_ignoring_markdown_code_fences(slot_method.base_docstring)
|
39
40
|
end,
|
40
41
|
# rubocop:enable Style/IfUnlessModifier
|
41
42
|
"parameters" => serialize_params(param_tags, component)
|
@@ -57,7 +58,7 @@ module Primer
|
|
57
58
|
|
58
59
|
{
|
59
60
|
"name" => mtd.name,
|
60
|
-
"description" =>
|
61
|
+
"description" => render_erb_ignoring_markdown_code_fences(mtd.base_docstring),
|
61
62
|
"parameters" => serialize_params(param_tags, component)
|
62
63
|
}
|
63
64
|
end
|
@@ -66,7 +67,7 @@ module Primer
|
|
66
67
|
if component == Primer::BaseComponent
|
67
68
|
docs.base_docstring
|
68
69
|
else
|
69
|
-
|
70
|
+
render_erb_ignoring_markdown_code_fences(docs.base_docstring)
|
70
71
|
end
|
71
72
|
|
72
73
|
memo[component] = {
|
@@ -119,7 +120,7 @@ module Primer
|
|
119
120
|
component: "BaseComponent",
|
120
121
|
fully_qualified_name: "Primer::BaseComponent",
|
121
122
|
description_md: docs.base_docstring,
|
122
|
-
args_md:
|
123
|
+
args_md: render_erb_ignoring_markdown_code_fences(docs.constructor.base_docstring)
|
123
124
|
}
|
124
125
|
end
|
125
126
|
|
@@ -131,7 +132,7 @@ module Primer
|
|
131
132
|
"name" => tag.name,
|
132
133
|
"type" => tag.types&.join(", ") || "",
|
133
134
|
"default" => default_value,
|
134
|
-
"description" =>
|
135
|
+
"description" => render_erb_ignoring_markdown_code_fences(tag.text.squish)
|
135
136
|
}
|
136
137
|
end
|
137
138
|
end
|
@@ -151,6 +152,86 @@ module Primer
|
|
151
152
|
end
|
152
153
|
end
|
153
154
|
|
155
|
+
# Renders ERB code to a string, ignoring markdown code fences. For example, consider the
|
156
|
+
# following ERB code inside a markdown document:
|
157
|
+
#
|
158
|
+
# ### Heading
|
159
|
+
# ```erb
|
160
|
+
# <%= render(SomeComponent.new) %>
|
161
|
+
# ```
|
162
|
+
#
|
163
|
+
# <%= some_func(a, b) %>
|
164
|
+
#
|
165
|
+
# The ERB renderer does not understand that the fenced code, i.e. the part inside the triple
|
166
|
+
# backticks, should not be rendered. It sees the ERB tags both inside and outside the fence
|
167
|
+
# and renders them both.
|
168
|
+
#
|
169
|
+
# This method renders ERB tags in a markdown string, ignoring any fenced code blocks, so as
|
170
|
+
# to prevent rendering fenced ERB code.
|
171
|
+
#
|
172
|
+
def render_erb_ignoring_markdown_code_fences(markdown_str)
|
173
|
+
return view_context.render(inline: markdown_str) unless markdown_str.include?("```")
|
174
|
+
|
175
|
+
# identify all fenced code blocks in markdown string
|
176
|
+
code_ranges = find_fenced_code_ranges_in(markdown_str)
|
177
|
+
|
178
|
+
# replace code fences with placeholders
|
179
|
+
de_fenced_markdown_str = markdown_str.dup.tap do |memo|
|
180
|
+
code_ranges.reverse_each.with_index do |code_range, idx|
|
181
|
+
memo[code_range] = "<!--codefence#{idx}-->"
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
# Render ERB tags. The only ones left will explicitly exist _outside_ markdown code fences.
|
186
|
+
rendered_str = view_context.render(inline: de_fenced_markdown_str)
|
187
|
+
|
188
|
+
# replace placeholders with original code fences
|
189
|
+
code_ranges.reverse_each.with_index do |code_range, idx|
|
190
|
+
rendered_str.sub!("<!--codefence#{idx}-->", markdown_str[code_range])
|
191
|
+
end
|
192
|
+
|
193
|
+
rendered_str
|
194
|
+
end
|
195
|
+
|
196
|
+
def find_fenced_code_ranges_in(str)
|
197
|
+
doc = Kramdown::Document.new(str)
|
198
|
+
line_starts = find_line_starts_in(str)
|
199
|
+
|
200
|
+
[].tap do |code_ranges|
|
201
|
+
each_codespan_in(doc.root) do |node|
|
202
|
+
options = node.options
|
203
|
+
delimiter = options[:codespan_delimiter]
|
204
|
+
next unless delimiter.start_with?("```")
|
205
|
+
|
206
|
+
start_pos = line_starts[options[:location]]
|
207
|
+
end_pos = start_pos + node.value.size + delimiter.size
|
208
|
+
end_pos = str.index("```", end_pos) + 3
|
209
|
+
|
210
|
+
code_ranges << (start_pos...end_pos)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
def find_line_starts_in(str)
|
216
|
+
line_counter = 2
|
217
|
+
|
218
|
+
{ 1 => 0 }.tap do |memo|
|
219
|
+
str.scan(/\r?\n/) do
|
220
|
+
memo[line_counter] = Regexp.last_match.end(0)
|
221
|
+
line_counter += 1
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
def each_codespan_in(node, &block)
|
227
|
+
return unless node.respond_to?(:children)
|
228
|
+
|
229
|
+
node.children.each do |child|
|
230
|
+
yield child if child.type == :codespan
|
231
|
+
each_codespan_in(child, &block)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
154
235
|
def registry
|
155
236
|
@registry ||= Primer::Yard::Registry.make
|
156
237
|
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 },
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<%= render(Primer::Alpha::ActionMenu.new(select_variant: :single)) do |menu| %>
|
2
|
+
<% menu.with_show_button { "Group By" } %>
|
3
|
+
<% menu.with_item(
|
4
|
+
label: "Repository",
|
5
|
+
href: action_menu_form_action_path(format: route_format),
|
6
|
+
form_arguments: {
|
7
|
+
method: :post,
|
8
|
+
inputs: [{
|
9
|
+
name: "query",
|
10
|
+
value: "query"
|
11
|
+
}, {
|
12
|
+
name: "foo", # use "foo" here because that's what the controller expects
|
13
|
+
value: "group-by-repository",
|
14
|
+
}],
|
15
|
+
}
|
16
|
+
) %>
|
17
|
+
<% menu.with_item(
|
18
|
+
label: "Date",
|
19
|
+
href: action_menu_form_action_path(format: route_format),
|
20
|
+
form_arguments: {
|
21
|
+
method: :post,
|
22
|
+
inputs: [{
|
23
|
+
name: "query",
|
24
|
+
value: "query"
|
25
|
+
}, {
|
26
|
+
name: "foo", # use "foo" here because that's what the controller expects
|
27
|
+
value: "sort-by-date"
|
28
|
+
}]
|
29
|
+
}
|
30
|
+
) %>
|
31
|
+
<% end %>
|