-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5378 from solidusio/elia/admin/component-fixes
[Admin] Misc. component fixes
- Loading branch information
Showing
18 changed files
with
139 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
admin/app/components/solidus_admin/ui/toggletip/component.erb
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
admin/app/components/solidus_admin/ui/toggletip/component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<details | ||
data-controller="<%= stimulus_id %>" | ||
<%= tag.attributes(**@attributes) %> | ||
> | ||
<summary | ||
type="button" | ||
class=" | ||
block | ||
w-[1rem] | ||
h-[1rem] | ||
cursor-pointer | ||
[&::marker]:hidden | ||
[&::-webkit-details-marker]:hidden | ||
" | ||
data-<%= stimulus_id %>-target="button" | ||
data-action=" | ||
click:prevent-><%= stimulus_id %>#toggle | ||
keydown.esc@window-><%= stimulus_id %>#close | ||
" | ||
aria-label="<%= t('.get_help') %>" | ||
> | ||
<%= icon_tag("question-fill", class: "w-[1rem] h-[1rem] #{icon_theme_classes}") %> | ||
</summary> | ||
|
||
<div | ||
class=" | ||
absolute | ||
inline-block | ||
w-[9rem] | ||
px-[0.75rem] | ||
body-tiny-bold | ||
rounded | ||
z-10 | ||
<%= bubble_position_classes %> | ||
<%= bubble_theme_classes %> | ||
" | ||
data-<%= stimulus_id %>-target="bubble" | ||
> | ||
<span | ||
role="status" | ||
class=" | ||
relative | ||
block | ||
bg-inherit | ||
py-[0.5rem] | ||
<%= bubble_arrow_pseudo_element %> | ||
" | ||
data-<%= stimulus_id %>-target="content" | ||
> | ||
<%= @text %> | ||
</span> | ||
</div> | ||
</details> |
38 changes: 9 additions & 29 deletions
38
admin/app/components/solidus_admin/ui/toggletip/component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,26 @@ | ||
import { Controller } from '@hotwired/stimulus' | ||
import { useClickOutside } from 'stimulus-use' | ||
|
||
export default class extends Controller { | ||
static targets = ['button', 'bubble', 'content'] | ||
|
||
connect () { | ||
// Progressive enhancement && a11y: the content is visible in plain HTML. | ||
// We first remove it and then make it an aria-live region so users are | ||
// updated when it's readded. | ||
this.contentTarget.textContent = '' | ||
this.contentTarget.setAttribute('role', 'status') | ||
useClickOutside(this) | ||
} | ||
|
||
// Close the bubble when clicking outside of it or pressing escape. | ||
document.addEventListener('click', (event) => { | ||
if (!this.buttonTarget.contains(event.target) && !this.bubbleTarget.contains(event.target)) { | ||
this.close() | ||
} | ||
}) | ||
document.addEventListener('keydown', (event) => { | ||
if (event.key === 'Escape') { | ||
this.close() | ||
} | ||
}) | ||
clickOutside () { | ||
this.close() | ||
} | ||
|
||
// Toggle the bubble when clicking the button. The content is added and | ||
// remove every time so that the aria-live region is updated and users are | ||
// notified.. | ||
toggle () { | ||
if (this.bubbleTarget.classList.contains('hidden')) { | ||
this.open() | ||
} else { | ||
this.close() | ||
} | ||
toggle (e) { | ||
this.element.open = !this.element.open | ||
} | ||
|
||
open () { | ||
this.bubbleTarget.classList.remove('hidden') | ||
this.contentTarget.textContent = this.bubbleTarget.dataset.content | ||
this.element.open = true | ||
} | ||
|
||
close () { | ||
this.bubbleTarget.classList.add('hidden') | ||
this.contentTarget.textContent = '' | ||
this.element.open = false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js" | ||
pin "@hotwired/turbo-rails", to: "turbo.js" | ||
|
||
pin "stimulus-use", to: "https://ga.jspm.io/npm:[email protected]/dist/index.js" | ||
|
||
pin "solidus_admin/application", preload: true | ||
pin "solidus_admin/utils" | ||
pin_all_from SolidusAdmin::Engine.root.join("app/javascript/solidus_admin/controllers"), under: "solidus_admin/controllers" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.