-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Admin] Add modal component #5364
Conversation
b58519a
to
5b7ec4e
Compare
5b7ec4e
to
e42aacf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Left a couple of suggestions / questions 👍
static values = { modal: String } | ||
|
||
toggleModal(e) { | ||
document.getElementById(e.currentTarget.dataset.modalId).classList.toggle('hidden'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you consider using action params already? I know they're way more verbose but would cleanup the JS a little bit. https://stimulus.hotwired.dev/reference/actions#action-parameters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also if I understand this correctly in the presence of multiple modals in the same page the code would be executed by each of them and potentially multiple toggles could happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: we could use the hidden
attribute which is more semantic than the class, all browsers have a default stile for elements with it to be [hidden] {display:none}
and we added a couple of TW variants to deal with it in classes:
plugin(({ addVariant }) => addVariant('hidden', '&([hidden])')),
plugin(({ addVariant }) => addVariant('visible', '&:not([hidden])')),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoa, great insights! 🚀
I decided to stop using the hidden
attribute and go with the open
one, provided by the <dialog>
element :)
Those variants are great tho!
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also if I understand this correctly in the presence of multiple modals in the same page the code would be executed by each of them and potentially multiple toggles could happen.
Hmmm 🤔 I don't think I understood. The target is the modal's id, so it wound only trigger the one that is on the data-ui--modal-modal-id-param
attribute.
Also on the Lookbok's Overview I render 3 different modals on the same page. They all are correctly targeted.
e42aacf
to
184b63c
Compare
184b63c
to
cffd048
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, great work! 👏 I've left a few comments 👍
<button type="button" class="close" data-action=<%= "#{stimulus_id}#toggleModal" %> aria-label="Close" <%= "data-#{stimulus_id}-modal-id-param=#{@id}" %>> | ||
<span aria-hidden="true">×</span> | ||
</button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use a component('ui/button')
for this button?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately our button component only allows primary, secondary and ghost "layouts"; the x
button on the modal does not match any of those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! I left some more notes, but looks good generally, up to you on how to act on each of them.
In any case some stuff will be adjusted once we start using it!
'data-action': 'click->ui--modal#toggleModal', | ||
'data-controller': 'ui--modal', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should find a way to avoid reusing the same controller for both the modal and the button opening it, but I think we can fix it later when we start using them.
cffd048
to
2324e2f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏
0a42f67
to
1288f9c
Compare
2324e2f
to
edfa2d4
Compare
edfa2d4
to
ce5fdec
Compare
ce5fdec
to
be002cc
Compare
be002cc
to
66a61cf
Compare
Those slots allow the developer to pass a block to the component, this enables an in-depth customization of the component, especially for the modal, in which the body should be dynamic. Co-Authored-By: Elia Schito <[email protected]>
66a61cf
to
8166fb7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
Summary
Those slots allow the developer to pass a block to the component, this enables an in-depth customization of the component, especially for the modal, in which the body should be dynamic. Since modals also carry action confirmations,
I've added the possibility to change the action button as well.
The modal is actually just a UI trick to show regular content and the close button (along with clicking on the backdrop) are simple links and just point to a URL which will need to be provided explicitly.
Currently we don't have a use case for
alert()
/confirm()
style modals that are transactional, but we'll bake in that functionality if we'll bump into such cases.Checklist
Check out our PR guidelines for more details.
The following are mandatory for all PRs:
The following are not always needed: