Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

document rendering form inside primer dialog

ulferts27af087eee18
diff --git a/lookbook/previews/open_project/datepicker_preview.rb b/lookbook/previews/open_project/datepicker_preview.rb
index 56f859753eb..a9a9bf8a39f 100644
--- a/lookbook/previews/open_project/datepicker_preview.rb
+++ b/lookbook/previews/open_project/datepicker_preview.rb
@@ -1,5 +1,5 @@
module OpenProject
- # @logical_path OpenProject/common
+ # @logical_path OpenProject/Common
class DatepickerPreview < Lookbook::Preview
##
# **Single date picker**
diff --git a/lookbook/previews/open_project/dialog_preview.rb b/lookbook/previews/open_project/dialog_preview.rb
new file mode 100644
index 00000000000..c529ec73edb
--- /dev/null
+++ b/lookbook/previews/open_project/dialog_preview.rb
@@ -0,0 +1,60 @@
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2024 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+# ++
+
+module OpenProject
+ # @logical_path OpenProject/Common
+ class DialogPreview < Lookbook::Preview
+ ##
+ # **Form dialogs**
+ # ---------------------
+ # Within the OpenProject application, forms are oftentimes rendered within a dialog. It is used e.g. for
+ # the creation of new models or for the modification of existing ones.
+ #
+ # Form dialogs consist of a header, a body where the form is rendered in and a footer with the buttons to submit
+ # or cancel the action.
+ #
+ # The primer specification [suggests a pattern](/lookbook/inspect/primer/alpha/dialog/with_form) for rendering such dialogs.
+ # It consists of a form spanning both the body as well as the footer of the dialog. This has the drawback of the footer
+ # potentially being rendered outside of the dialog. That behaviour is undesirable. Primer defines to cope with longer
+ # content by scrolling the body.
+ #
+ # In order for this to happen the form should only be rendered inside the body. The submit button can be logically put inside
+ # the form via the `form` attribute.
+ #
+ # @param button_text
+ # @param dialog_title
+ # @param dialog_id
+ # @param form_id
+ def form(button_text: 'Show form dialog',
+ dialog_title: 'Dialog title',
+ dialog_id: 'dialog-id',
+ form_id: 'form-id')
+ render_with_template(locals: { button_text:, dialog_title:, dialog_id:, form_id: })
+ end
+ end
+end
diff --git a/lookbook/previews/open_project/dialog_preview/form.html.erb b/lookbook/previews/open_project/dialog_preview/form.html.erb
new file mode 100644
index 00000000000..e5320324af4
--- /dev/null
+++ b/lookbook/previews/open_project/dialog_preview/form.html.erb
@@ -0,0 +1,19 @@
+<%= render(Primer::Alpha::Dialog.new(title: dialog_title,
+ size: :large,
+ id: dialog_id)) do |d| %>
+ <% d.with_show_button { button_text } %>
+ <% d.with_header(variant: :large, mb: 3) %>
+
+ <%= render(Primer::Alpha::Dialog::Body.new) do %>
+ <%= primer_form_with(
+ url: '/abc',
+ id: form_id) do %>
+ Some form elements could be rendered here
+ <% end %>
+ <% end %>
+
+ <%= render(Primer::Alpha::Dialog::Footer.new) do %>
+ <%= render(Primer::ButtonComponent.new(data: { "close-dialog-id": dialog_id })) { I18n.t(:button_cancel) } %>
+ <%= render(Primer::ButtonComponent.new(scheme: :primary, type: :submit, form: form_id)) { I18n.t(:button_apply) } %>
+ <% end %>
+<% end %>
diff --git a/lookbook/previews/open_project/loading_indicator_preview.rb b/lookbook/previews/open_project/loading_indicator_preview.rb
index 1a0b76eaae2..8612f81018d 100644
--- a/lookbook/previews/open_project/loading_indicator_preview.rb
+++ b/lookbook/previews/open_project/loading_indicator_preview.rb
@@ -1,5 +1,5 @@
module OpenProject
- # @logical_path OpenProject/common
+ # @logical_path OpenProject/Common
class LoadingIndicatorPreview < Lookbook::Preview
def default; end
end