Skip to content

Commit

Permalink
Separating anchored position and Overlay class (#2088)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonrohan committed Jun 23, 2023
1 parent f231e2e commit b79fec8
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 28 deletions.
5 changes: 5 additions & 0 deletions .changeset/popular-impalas-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/view-components": minor
---

Separating `<anchored-position>` web component and the .Overlay class into separate markup.
14 changes: 8 additions & 6 deletions app/components/primer/alpha/overlay.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<%= show_button %>
<%= render Primer::BaseComponent.new(**@system_arguments) do %>
<%= header %>
<% if content.present? %>
<%= content %>
<% else %>
<%= body %>
<%= footer %>
<%= render Primer::BaseComponent.new(tag: :div, classes: @wrapper_classes) do %>
<%= header %>
<% if content.present? %>
<%= content %>
<% else %>
<%= body %>
<%= footer %>
<% end %>
<% end %>
<% end %>
13 changes: 9 additions & 4 deletions app/components/primer/alpha/overlay.pcss
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
.Overlay[popover] {
anchored-position[popover] {
border-width: 0;
padding: 0;
position: absolute;
min-width: 192px;
inset: auto;
overflow: visible;
}

.Overlay[popover]:not(.\:popover-open) {
.Overlay {
display: flex;
}

anchored-position[popover]:not(.\:popover-open) {
display: none;
}

/* This reverts the declaration above for native popover, where `:popover-open` is supported */
@supports selector(:popover-open) {
.Overlay[popover]:not(.\:popover-open) {
anchored-position[popover]:not(.\:popover-open) {
display: revert;
}
}

/* This reverts the declaration above for native popover, where `:open` is supported (Chrome 113, Safari TP) */
@supports selector(:open) {
.Overlay[popover]:not(.\:popover-open) {
anchored-position[popover]:not(.\:popover-open) {
display: revert;
}
}
5 changes: 2 additions & 3 deletions app/components/primer/alpha/overlay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,9 @@ def initialize(
@system_arguments[:role] = fetch_or_fallback(ROLE_OPTIONS, role) if role.present?

@system_arguments[:id] = id.to_s
@system_arguments[:classes] = class_names(
@wrapper_classes = class_names(
"Overlay",
SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE)],
system_arguments[:classes]
SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE)]
)
@system_arguments[:tag] = "anchored-position"
@system_arguments[:anchor] = anchor || "overlay-show-#{@system_arguments[:id]}"
Expand Down
16 changes: 1 addition & 15 deletions app/components/primer/anchored_position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,9 @@ export default class AnchoredPositionElement extends HTMLElement implements Posi
this.#animationFrame = requestAnimationFrame(() => {
const anchor = this.anchorElement
if (!anchor) return
const {left, top, anchorSide, anchorAlign} = getAnchoredPosition(this, anchor, this)
const {left, top} = getAnchoredPosition(this, anchor, this)
this.style.top = `${top}px`
this.style.left = `${left}px`
this.classList.remove(
'Overlay--anchorAlign-start',
'Overlay--anchorAlign-center',
'Overlay--anchorAlign-end',
'Overlay--anchorSide-insideTop',
'Overlay--anchorSide-insideBottom',
'Overlay--anchorSide-insideLeft',
'Overlay--anchorSide-insideRight',
'Overlay--anchorSide-insideCenter',
'Overlay--anchorSide-outsideTop',
'Overlay--anchorSide-outsideLeft',
'Overlay--anchorSide-outsideRight'
)
this.classList.add(`Overlay--anchorAlign-${anchorAlign}`, `Overlay--anchorSide-${anchorSide}`)
})
}
}
Expand Down
11 changes: 11 additions & 0 deletions previews/primer/alpha/overlay_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,17 @@ def middle_of_page_with_relative_container(title: "Test Overlay", subtitle: nil,
body_text: body_text
})
end

# @label Dialog with header and footer
#
def dialog_with_header_footer
render(Primer::Alpha::Overlay.new(title: "Dialog", role: :dialog, size: :large, padding: :condensed)) do |d|
d.with_header(title: "Large Dialog Header", divider: true)
d.with_show_button { "Show Overlay" }
d.with_footer { "Large Dialog Footer" }
d.with_body { "This is a long body for the overlay dialog. <br>".html_safe * 20 }
end
end
end
end
end

0 comments on commit b79fec8

Please sign in to comment.