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 primer form dialog in patterns section

ulferts74d60396e445
diff --git a/lookbook/docs/patterns/dialogs.md.erb b/lookbook/docs/patterns/dialogs.md.erb
new file mode 100644
index 00000000000..efb8d79734d
--- /dev/null
+++ b/lookbook/docs/patterns/dialogs.md.erb
@@ -0,0 +1,21 @@
+As of now, this page is still a stub. In particular, the considerations on when and where to apply Dialogs are still missing.
+
+For now, it can be stated that OpenProject employs Dialogs for more purposes than GitHub Primer specifies.
+
+## 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.
+
+<%= embed OpenProject::Common::DialogPreview, :form %>
diff --git a/lookbook/previews/open_project/common/dialog_preview.rb b/lookbook/previews/open_project/common/dialog_preview.rb
new file mode 100644
index 00000000000..09e30242f18
--- /dev/null
+++ b/lookbook/previews/open_project/common/dialog_preview.rb
@@ -0,0 +1,45 @@
+# -- 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
+ module Common
+ # @logical_path OpenProject/Common
+ class DialogPreview < Lookbook::Preview
+ # @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
+end
diff --git a/lookbook/previews/open_project/common/dialog_preview/form.html.erb b/lookbook/previews/open_project/common/dialog_preview/form.html.erb
new file mode 100644
index 00000000000..8a455298b2a
--- /dev/null
+++ b/lookbook/previews/open_project/common/dialog_preview/form.html.erb
@@ -0,0 +1,58 @@
+<%
+ the_form = Class.new(ApplicationForm) do
+ form do |query_form|
+ query_form.group do |group|
+ group.text_field(
+ name: 'a',
+ label: 'The first field'
+ )
+
+ group.text_field(
+ name: 'b',
+ label: 'The second field'
+ )
+
+ group.text_field(
+ name: 'c',
+ label: 'The third field'
+ )
+
+ group.text_field(
+ name: 'd',
+ label: 'The fourth field'
+ )
+
+ group.text_field(
+ name: 'e',
+ label: 'The fifth field'
+ )
+
+ group.text_field(
+ name: 'f',
+ label: 'The sixth field'
+ )
+ end
+ end
+ end
+%>
+
+
+<%= 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 |f|
+ render(the_form.new(f))
+ 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/dialog_preview.rb b/lookbook/previews/open_project/dialog_preview.rb
deleted file mode 100644
index c529ec73edb..00000000000
--- a/lookbook/previews/open_project/dialog_preview.rb
+++ /dev/null
@@ -1,60 +0,0 @@
-# -- 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
deleted file mode 100644
index e5320324af4..00000000000
--- a/lookbook/previews/open_project/dialog_preview/form.html.erb
+++ /dev/null
@@ -1,19 +0,0 @@
-<%= 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 %>