From 99c9ee95113c559ada9d01f39915fec446def534 Mon Sep 17 00:00:00 2001 From: Sergey Moiseev Date: Sun, 1 Sep 2024 12:58:41 +0300 Subject: [PATCH 1/3] Support navigating away from dialog closing --- .../turbo_material/material_dialog_controller.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/turbo_material/material_dialog_controller.js b/app/assets/javascripts/turbo_material/material_dialog_controller.js index c3a2fd8..889ce81 100644 --- a/app/assets/javascripts/turbo_material/material_dialog_controller.js +++ b/app/assets/javascripts/turbo_material/material_dialog_controller.js @@ -1,10 +1,12 @@ import { Controller } from "@hotwired/stimulus"; +import { get } from "@rails/request.js"; export default class extends Controller { dialog = undefined; static values = { - opened: Boolean + opened: Boolean, + closeActionUrl: String } connect() { @@ -21,6 +23,9 @@ export default class extends Controller { close() { this.dialog.close(); + if (this.closeActionUrlValue) { + window.location.href = this.closeActionUrlValue; + } } open() { From 9909a440a0c8f5bd39562eb2018133d1c2f0fc66 Mon Sep 17 00:00:00 2001 From: Sergey Moiseev Date: Mon, 2 Sep 2024 17:35:26 +0300 Subject: [PATCH 2/3] Remove unneeded dep --- .../javascripts/turbo_material/material_dialog_controller.js | 1 - 1 file changed, 1 deletion(-) diff --git a/app/assets/javascripts/turbo_material/material_dialog_controller.js b/app/assets/javascripts/turbo_material/material_dialog_controller.js index 889ce81..44df9b2 100644 --- a/app/assets/javascripts/turbo_material/material_dialog_controller.js +++ b/app/assets/javascripts/turbo_material/material_dialog_controller.js @@ -1,5 +1,4 @@ import { Controller } from "@hotwired/stimulus"; -import { get } from "@rails/request.js"; export default class extends Controller { dialog = undefined; From 6728a5d96bc1bd8db55ca0ac77942637896d37f2 Mon Sep 17 00:00:00 2001 From: Sergey Moiseev Date: Mon, 2 Sep 2024 18:38:16 +0300 Subject: [PATCH 3/3] Rework dialog --- README.md | 19 +++++- app/helpers/turbo_material/modal_helper.rb | 6 +- app/views/components/_input.html.erb | 4 +- app/views/components/_modal.html.erb | 79 ++++++++++++---------- 4 files changed, 67 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 6377722..5b3ca7e 100644 --- a/README.md +++ b/README.md @@ -547,14 +547,27 @@ Implements [Material Design Menu Button](https://github.com/material-components/ Implements [Material Design Modal](https://github.com/material-components/material-components-web/tree/master/packages/mdc-dialog) component. ```erb -<%= material_modal title: 'Modal Title' %> +<%= material_modal title: 'Modal Title', contents_partial: 'common/modal_contents' %> +``` +or with block +```erb +<%= material_modal title: 'Modal Title' do %> + Contents +<% end %> ``` #### Options -| Option | Type | Description | -| --- | --- | --- | +| Option | Type | Description | +| --- | --- |-------------------------------------------------------------------------| | `title` | String | Title of the modal | +| `contents_partial` | String | Partial for modal contents | +| `cancel_button_text` | String | Text of the cancel button | +| `ok_button_text` | String | Text of the ok button | +| `opened` | Boolean | Whether the modal is opened | +| `dialog_surface_custom_css` | String | Custom CSS class for the dialog surface | +| `close_action_url` | String | URL for navigating to on modal close | +| `form` | Object | Form object for form-centric modals, replaces ok button with form submit | ### Tooltip diff --git a/app/helpers/turbo_material/modal_helper.rb b/app/helpers/turbo_material/modal_helper.rb index a738f1d..f0ff027 100644 --- a/app/helpers/turbo_material/modal_helper.rb +++ b/app/helpers/turbo_material/modal_helper.rb @@ -1,7 +1,9 @@ module TurboMaterial module ModalHelper - def material_modal(kwargs = {}) - render "components/modal", **kwargs + def material_modal(kwargs = {}, &block) + render "components/modal", **kwargs do + capture(&block) if block_given? + end end end end diff --git a/app/views/components/_input.html.erb b/app/views/components/_input.html.erb index 44f4bb0..99fd3e2 100644 --- a/app/views/components/_input.html.erb +++ b/app/views/components/_input.html.erb @@ -1,9 +1,9 @@ <%# locals: (form:, custom_controller: nil, custom_css: nil, disabled: false, required: false, name:, label: nil, id:, frame: nil, provide_hidden: false, value: nil, type: 'text', data: {}, min: nil, max: nil, helper: nil, parent: nil, style: 'filled', leading_icon: nil, trailing_icon: nil, leading_icon_data: {}, trailing_icon_data: {}) %> -