-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PLAY-1510] Loading state for Rails form, resolution of Dialog loading (
#3753) **What does this PR do?** A clear and concise description with your runway ticket url. https://runway.powerhrg.com/backlog_items/PLAY-1510 **Screenshots:** Screenshots to visualize your addition/change **How to test?** Steps to confirm the desired behavior: 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' 4. See addition/change #### Checklist: - [ ] **LABELS** Add a label: `enhancement`, `bug`, `improvement`, `new kit`, `deprecated`, or `breaking`. See [Changelog & Labels](https://github.com/powerhome/playbook/wiki/Changelog-&-Labels) for details. - [ ] **DEPLOY** I have added the `milano` label to show I'm ready for a review. - [ ] **TESTS** I have added test coverage to my code.
- Loading branch information
Showing
10 changed files
with
107 additions
and
10 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
37 changes: 30 additions & 7 deletions
37
playbook/app/pb_kits/playbook/pb_dialog/docs/_dialog_loading.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 |
---|---|---|
@@ -1,13 +1,36 @@ | ||
<%= pb_rails("button", props: { text: "Open Dialog", data: {"open-dialog": "dialog-loading"} }) %> | ||
|
||
<%= pb_rails("dialog", props: { | ||
id:"dialog-loading", | ||
size: "sm", | ||
title: "Loading Exmaple", | ||
text: "Make a loading request?", | ||
cancel_button: "Cancel Button", | ||
<%= pb_rails("dialog", props: { | ||
id:"dialog-loading", | ||
size: "sm", | ||
title: "Loading Example", | ||
text: "Make a loading request?", | ||
cancel_button: "Cancel Button", | ||
cancel_button_id: "cancel-button-loading", | ||
confirm_button: "Okay", | ||
confirm_button: "Okay", | ||
confirm_button_id: "confirm-button-loading", | ||
loading: true, | ||
}) %> | ||
|
||
<script> | ||
const loadingButton = document.querySelector('[data-disable-with="Loading"]'); | ||
if (loadingButton) { | ||
loadingButton.addEventListener("click", function() { | ||
const okayLoadingButton = document.querySelector('[data-disable-with="Loading"]'); | ||
const cancelButton = document.querySelector('[data-disable-cancel-with="Loading"]'); | ||
let currentClass = okayLoadingButton.className; | ||
let cancelClass = cancelButton ? cancelButton.className : ""; | ||
|
||
setTimeout(function() { | ||
okayLoadingButton.disabled = false; | ||
okayLoadingButton.className = currentClass.replace("_disabled_loading", "_enabled"); | ||
|
||
if (cancelButton) { | ||
cancelButton.disabled = false; | ||
cancelButton.className = cancelClass.replace("_disabled", "_enabled"); | ||
} | ||
}, 5000); | ||
|
||
}); | ||
} | ||
</script> |
2 changes: 0 additions & 2 deletions
2
playbook/app/pb_kits/playbook/pb_dialog/docs/_dialog_loading.md
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,3 +1 @@ | ||
Pressing the "Okay" button will trigger a loading state where the button content is replaced by a spinner icon and both buttons are disabled. | ||
|
||
Currently, the loading state cannot be undone and will require a page refresh to reset the dialog. |
39 changes: 39 additions & 0 deletions
39
playbook/app/pb_kits/playbook/pb_form/docs/_form_form_with_loading.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,39 @@ | ||
<%= pb_form_with(scope: :example, url: "", method: :get, loading: true) do |form| %> | ||
<%= form.text_field :example_text_field, props: { label: true } %> | ||
|
||
<%= form.actions do |action| %> | ||
<%= action.submit %> | ||
<%= action.button props: { type: "reset", text: "Cancel", variant: "secondary" } %> | ||
<% end %> | ||
<% end %> | ||
|
||
<script> | ||
const loadingForm = document.querySelector(".pb_form_loading") | ||
if (loadingForm) { | ||
loadingForm.addEventListener("submit", function(event) { | ||
event.preventDefault(); | ||
|
||
const submitButton = event['submitter']; | ||
const cancelButton = event['target'].querySelector('button[type="reset"]'); | ||
|
||
if (submitButton) { | ||
let currentClass = submitButton.className; | ||
let newClass = currentClass.replace("_disabled_loading", "_enabled"); | ||
|
||
let cancelClass = cancelButton ? cancelButton.className : ""; | ||
let newCancelClass = cancelClass.replace("_disabled", "_enabled"); | ||
|
||
setTimeout(function() { | ||
submitButton.disabled = false; | ||
submitButton.className = currentClass; | ||
|
||
if (cancelButton) { | ||
cancelButton.disabled = false; | ||
cancelButton.className = cancelClass; | ||
} | ||
}, 5000); | ||
} | ||
}); | ||
} | ||
</script> | ||
|
1 change: 1 addition & 0 deletions
1
playbook/app/pb_kits/playbook/pb_form/docs/_form_form_with_loading.md
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 @@ | ||
Pressing Submit will trigger a loading state where the button content is replaced by a spinner icon and the submit button will be disabled. |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const formHelper = () => { | ||
const loadingForm = document.querySelector(".pb_form_loading") | ||
if (loadingForm) { | ||
loadingForm.addEventListener("submit", function(event) { | ||
const submitButton = event['submitter']; | ||
const cancelButton = event['target'].querySelector('button[type="reset"]'); | ||
|
||
if (submitButton) { | ||
let currentClass = submitButton.className; | ||
let newClass = currentClass.replace("_enabled", "_disabled_loading"); | ||
|
||
let cancelClass = cancelButton ? cancelButton.className : ""; | ||
let newCancelClass = cancelClass.replace("_enabled", "_disabled"); | ||
|
||
submitButton.disabled = true; | ||
submitButton.className = newClass; | ||
|
||
if (cancelButton) { | ||
cancelButton.disabled = true; | ||
cancelButton.className = newCancelClass; | ||
} | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
export default formHelper; |
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