openproject-primer_view_components 0.40.0 → 0.41.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff9f0c72e9e37305fe52894e785773c8608e6c6716483145ebbb12874d1c7e57
4
- data.tar.gz: b8b5b507657c7824aa5eb714d51194f8c2273275c100f8000f06fa18e8f019da
3
+ metadata.gz: 14593fb2905980052a721c86d1b8b52a0f111166b477860d3edf7bf28310aa48
4
+ data.tar.gz: '0838140880dbe21f751bb20d65694d038e13f8af131196cb5bda047e49661b94'
5
5
  SHA512:
6
- metadata.gz: 943eb81e21e077dab36f19896866d95b91f612b022339aa54844341238616c4845002851cce92c0aad68f88209b4d7ab53563378ea7eeb82fe82003b5b28a9aa
7
- data.tar.gz: 800f37b7ad626d74ad1cc4aea0376170afb9f8d6e8629e6f9193ed3a1de05a8c19efcf46618b516114f6b95b56435eb0a45c79acca6a7e8f85b6d66e280d036a
6
+ metadata.gz: e8d58bdd1701157d8a20e140b681a7e23f381a23c98bf03024ba53cb40689fbe76af9d6b08cef6c721710c5c819aa9c397c667d570598d4c0fd546d87b13f582
7
+ data.tar.gz: e87fac40947b33003faf5a91d9945ffa1527afe6f93b0c48fa0441b3af6b3a4aac09d2c6ec362599d70e4d3133b264e391d44746dfbfda32cebe3b2b1a977e26
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.41.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#149](https://github.com/opf/primer_view_components/pull/149) [`63cd602`](https://github.com/opf/primer_view_components/commit/63cd6022bc2dda79b602ebefcffe6f1e0ed1436f) Thanks [@HDinger](https://github.com/HDinger)! - Add support for an editable state of Primer::OpenProject::PageHeader
8
+
3
9
  ## 0.40.0
4
10
 
5
11
  ### Minor Changes
@@ -0,0 +1,7 @@
1
+ <%= render Primer::BaseComponent.new(**@system_arguments) do %>
2
+ <% if show_state? %>
3
+ <%= content %>
4
+ <% elsif editable_form.present? %>
5
+ <%= editable_form %>
6
+ <% end %>
7
+ <% end %>
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ module OpenProject
5
+ class PageHeader
6
+ # A Helper class to create a Title inside the PageHeader title slot
7
+ # It should not be used standalone
8
+ class Title < Primer::Component
9
+ status :open_project
10
+
11
+ HEADING_TAG_OPTIONS = [:h1, :h2, :h3, :h4, :h5, :h6].freeze
12
+ HEADING_TAG_FALLBACK = :h1
13
+
14
+ renders_one :editable_form, lambda { |model: nil, update_path:, cancel_path:, input_name: :title, method: :put, label: I18n.t(:label_title), placeholder: I18n.t(:label_title), **system_arguments|
15
+ primer_form_with(
16
+ model: model,
17
+ method: method,
18
+ url: update_path,
19
+ **system_arguments
20
+ ) do |f|
21
+ render_inline_form(f) do |query_form|
22
+ query_form.group(layout: :horizontal) do |group|
23
+ group.text_field(
24
+ name: input_name,
25
+ placeholder: placeholder,
26
+ label: label,
27
+ visually_hide_label: true,
28
+ required: true,
29
+ autofocus: true
30
+ )
31
+
32
+ group.submit(name: :submit, label: I18n.t("button_save"), scheme: :primary)
33
+
34
+ group.button(
35
+ name: :cancel,
36
+ scheme: :secondary,
37
+ label: I18n.t(:button_cancel),
38
+ tag: :a,
39
+ data: { "turbo-stream": true },
40
+ href: cancel_path
41
+ )
42
+ end
43
+ end
44
+ end
45
+ }
46
+
47
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
48
+ def initialize(tag: HEADING_TAG_FALLBACK, state: Primer::OpenProject::PageHeader::STATE_DEFAULT, **system_arguments)
49
+ @system_arguments = system_arguments
50
+ @system_arguments[:tag] = fetch_or_fallback(HEADING_TAG_OPTIONS, tag, HEADING_TAG_FALLBACK)
51
+
52
+ @state = state
53
+ end
54
+
55
+ def render?
56
+ raise ArgumentError, "Please define form paramaters for the editable title" if !show_state? && !editable_form?
57
+
58
+ content? && (show_state? || editable_form?)
59
+ end
60
+
61
+ private
62
+
63
+ def show_state?
64
+ @state == Primer::OpenProject::PageHeader::STATE_DEFAULT
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -20,7 +20,7 @@
20
20
  <div class="PageHeader-titleBar">
21
21
  <%= leading_action %>
22
22
  <%= title %>
23
- <% if actions.any? %>
23
+ <% if actions.any? && show_state? %>
24
24
  <div class="PageHeader-actions">
25
25
  <% actions.each do |action| %>
26
26
  <%= action %>
@@ -4,9 +4,6 @@ module Primer
4
4
  module OpenProject
5
5
  # A ViewComponent PageHeader inspired by the primer react variant
6
6
  class PageHeader < Primer::Component
7
- HEADING_TAG_OPTIONS = [:h1, :h2, :h3, :h4, :h5, :h6].freeze
8
- HEADING_TAG_FALLBACK = :h1
9
-
10
7
  DEFAULT_HEADER_VARIANT = :medium
11
8
  HEADER_VARIANT_OPTIONS = [
12
9
  DEFAULT_HEADER_VARIANT,
@@ -27,21 +24,24 @@ module Primer
27
24
  DEFAULT_BREADCRUMBS_DISPLAY = [:none, :flex].freeze
28
25
  DEFAULT_PARENT_LINK_DISPLAY = [:block, :none].freeze
29
26
 
27
+ STATE_DEFAULT = :show
28
+ STATE_EDIT = :edit
29
+ STATE_OPTIONS = [STATE_DEFAULT, STATE_EDIT].freeze
30
+
30
31
  status :open_project
31
32
 
32
33
  # The title of the page header
33
34
  #
34
35
  # @param tag [Symbol] <%= one_of(Primer::Beta::Heading::TAG_OPTIONS) %>
35
36
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
36
- renders_one :title, lambda { |tag: HEADING_TAG_FALLBACK, variant: DEFAULT_HEADER_VARIANT, **system_arguments|
37
- system_arguments[:tag] = fetch_or_fallback(HEADING_TAG_OPTIONS, tag, HEADING_TAG_FALLBACK)
37
+ renders_one :title, lambda { |variant: DEFAULT_HEADER_VARIANT, **system_arguments|
38
38
  system_arguments[:classes] = class_names(
39
39
  system_arguments[:classes],
40
40
  "PageHeader-title",
41
41
  "PageHeader-title--#{variant}"
42
42
  )
43
43
 
44
- Primer::BaseComponent.new(**system_arguments)
44
+ Primer::OpenProject::PageHeader::Title.new(state: @state, **system_arguments)
45
45
  }
46
46
 
47
47
  # Optional description below the title row
@@ -235,7 +235,7 @@ module Primer
235
235
 
236
236
  # @param mobile_menu_label [String] The tooltip label of the mobile menu
237
237
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
238
- def initialize(mobile_menu_label: I18n.t("label_more"), **system_arguments)
238
+ def initialize(mobile_menu_label: I18n.t("label_more"), state: STATE_DEFAULT, **system_arguments)
239
239
  @system_arguments = deny_tag_argument(**system_arguments)
240
240
  @mobile_menu_label = mobile_menu_label
241
241
 
@@ -246,6 +246,8 @@ module Primer
246
246
  "PageHeader"
247
247
  )
248
248
 
249
+ @state = fetch_or_fallback(STATE_OPTIONS, state, STATE_DEFAULT)
250
+
249
251
  @mobile_action_menu = Primer::Alpha::ActionMenu.new(
250
252
  display: MOBILE_ACTIONS_DISPLAY,
251
253
  anchor_align: :end
@@ -263,6 +265,10 @@ module Primer
263
265
  actions.count > 1
264
266
  end
265
267
 
268
+ def show_state?
269
+ @state == STATE_DEFAULT
270
+ end
271
+
266
272
  private
267
273
 
268
274
  def set_action_arguments(system_arguments, scheme: nil)
@@ -5,7 +5,7 @@ module Primer
5
5
  module ViewComponents
6
6
  module VERSION
7
7
  MAJOR = 0
8
- MINOR = 40
8
+ MINOR = 41
9
9
  PATCH = 0
10
10
 
11
11
  STRING = [MAJOR, MINOR, PATCH].join(".")
@@ -1,5 +1,10 @@
1
- <%= render Primer::OpenProject::PageHeader.new do |header| %>
2
- <%= header.with_title(variant: variant) { title } %>
1
+ <%= render Primer::OpenProject::PageHeader.new(state: in_edit_state ? :edit : :show) do |header| %>
2
+ <%= header.with_title(variant: variant) do |t| %>
3
+ <% if in_edit_state %>
4
+ <%= t.with_editable_form(model: nil, update_path: "/foo", cancel_path: "/bar") %>
5
+ <% end %>
6
+ <%= title %>
7
+ <% end %>
3
8
  <%= header.with_description { description } %>
4
9
  <%= header.with_leading_action(icon: with_leading_action, href: '#', 'aria-label': "A leading action") if with_leading_action && with_leading_action != :none %>
5
10
  <%= header.with_breadcrumbs(breadcrumb_items) %>
@@ -24,13 +24,15 @@ module Primer
24
24
  # @param with_leading_action [Symbol] octicon
25
25
  # @param with_actions [Boolean]
26
26
  # @param with_tab_nav [Boolean]
27
+ # @param in_edit_state [Boolean]
27
28
  def playground(
28
29
  variant: :medium,
29
30
  title: "Hello",
30
31
  description: "Last updated 5 minutes ago by XYZ.",
31
32
  with_leading_action: :"none",
32
33
  with_actions: true,
33
- with_tab_nav: false
34
+ with_tab_nav: false,
35
+ in_edit_state: false
34
36
  )
35
37
  breadcrumb_items = [{ href: "/foo", text: "Foo" }, { href: "/bar", text: "Bar" }, "Baz"]
36
38
 
@@ -40,7 +42,8 @@ module Primer
40
42
  with_leading_action: with_leading_action,
41
43
  with_actions: with_actions,
42
44
  breadcrumb_items: breadcrumb_items,
43
- with_tab_nav: with_tab_nav })
45
+ with_tab_nav: with_tab_nav,
46
+ in_edit_state: in_edit_state })
44
47
  end
45
48
 
46
49
  # @label Large title
@@ -54,6 +57,18 @@ module Primer
54
57
  end
55
58
  end
56
59
 
60
+ # @label Editable title
61
+ def editable_title
62
+ breadcrumb_items = [{ href: "/foo", text: "Foo" }, { href: "/bar", text: "Bar" }, "Baz"]
63
+ render(Primer::OpenProject::PageHeader.new(state: :edit)) do |header|
64
+ header.with_title do |title|
65
+ title.with_editable_form(model: nil, update_path: "/foo", cancel_path: "/bar")
66
+ "Hello"
67
+ end
68
+ header.with_breadcrumbs(breadcrumb_items)
69
+ end
70
+ end
71
+
57
72
  # @label With actions
58
73
  def actions
59
74
  render_with_template(locals: {})
@@ -5199,6 +5199,22 @@
5199
5199
  }
5200
5200
  ]
5201
5201
  },
5202
+ {
5203
+ "component": "OpenProject::PageHeader::Title",
5204
+ "status": "open_project",
5205
+ "a11y_reviewed": false,
5206
+ "short_name": "OpenProjectPageHeaderTitle",
5207
+ "source": "https://github.com/primer/view_components/tree/main/app/components/primer/open_project/page_header/title.rb",
5208
+ "lookbook": "https://primer.style/view-components/lookbook/inspect/primer/open_project/page_header/title/default/",
5209
+ "parameters": [
5210
+ {
5211
+ "name": "system_arguments",
5212
+ "type": "Hash",
5213
+ "default": "N/A",
5214
+ "description": "[System arguments](/system-arguments)"
5215
+ }
5216
+ ]
5217
+ },
5202
5218
  {
5203
5219
  "component": "OpenProject::SidePanel",
5204
5220
  "status": "open_project",
@@ -125,6 +125,7 @@
125
125
  "Primer::OpenProject::PageHeader": "",
126
126
  "Primer::OpenProject::PageHeader::Dialog": "",
127
127
  "Primer::OpenProject::PageHeader::Menu": "",
128
+ "Primer::OpenProject::PageHeader::Title": "",
128
129
  "Primer::OpenProject::SidePanel": "",
129
130
  "Primer::OpenProject::SidePanel::Section": "",
130
131
  "Primer::OpenProject::SubHeader": "",
@@ -1479,25 +1479,34 @@
1479
1479
  "medium",
1480
1480
  "large"
1481
1481
  ],
1482
- "HEADING_TAG_FALLBACK": "h1",
1483
- "HEADING_TAG_OPTIONS": [
1484
- "h1",
1485
- "h2",
1486
- "h3",
1487
- "h4",
1488
- "h5",
1489
- "h6"
1490
- ],
1491
1482
  "MOBILE_ACTIONS_DISPLAY": [
1492
1483
  "flex",
1493
1484
  "none"
1494
1485
  ],
1495
- "Menu": "Primer::OpenProject::PageHeader::Menu"
1486
+ "Menu": "Primer::OpenProject::PageHeader::Menu",
1487
+ "STATE_DEFAULT": "show",
1488
+ "STATE_EDIT": "edit",
1489
+ "STATE_OPTIONS": [
1490
+ "show",
1491
+ "edit"
1492
+ ],
1493
+ "Title": "Primer::OpenProject::PageHeader::Title"
1496
1494
  },
1497
1495
  "Primer::OpenProject::PageHeader::Dialog": {
1498
1496
  },
1499
1497
  "Primer::OpenProject::PageHeader::Menu": {
1500
1498
  },
1499
+ "Primer::OpenProject::PageHeader::Title": {
1500
+ "HEADING_TAG_FALLBACK": "h1",
1501
+ "HEADING_TAG_OPTIONS": [
1502
+ "h1",
1503
+ "h2",
1504
+ "h3",
1505
+ "h4",
1506
+ "h5",
1507
+ "h6"
1508
+ ]
1509
+ },
1501
1510
  "Primer::OpenProject::SidePanel": {
1502
1511
  "Section": "Primer::OpenProject::SidePanel::Section"
1503
1512
  },
@@ -17796,6 +17796,19 @@
17796
17796
  ]
17797
17797
  }
17798
17798
  },
17799
+ {
17800
+ "preview_path": "primer/open_project/page_header/editable_title",
17801
+ "name": "editable_title",
17802
+ "snapshot": "false",
17803
+ "skip_rules": {
17804
+ "wont_fix": [
17805
+ "region"
17806
+ ],
17807
+ "will_fix": [
17808
+ "color-contrast"
17809
+ ]
17810
+ }
17811
+ },
17799
17812
  {
17800
17813
  "preview_path": "primer/open_project/page_header/actions",
17801
17814
  "name": "actions",
@@ -18024,6 +18037,46 @@
18024
18037
 
18025
18038
  ]
18026
18039
  },
18040
+ {
18041
+ "fully_qualified_name": "Primer::OpenProject::PageHeader::Title",
18042
+ "description": "A Helper class to create a Title inside the PageHeader title slot\nIt should not be used standalone",
18043
+ "accessibility_docs": null,
18044
+ "is_form_component": false,
18045
+ "is_published": true,
18046
+ "requires_js": false,
18047
+ "component": "OpenProject::PageHeader::Title",
18048
+ "status": "open_project",
18049
+ "a11y_reviewed": false,
18050
+ "short_name": "OpenProjectPageHeaderTitle",
18051
+ "source": "https://github.com/primer/view_components/tree/main/app/components/primer/open_project/page_header/title.rb",
18052
+ "lookbook": "https://primer.style/view-components/lookbook/inspect/primer/open_project/page_header/title/default/",
18053
+ "parameters": [
18054
+ {
18055
+ "name": "system_arguments",
18056
+ "type": "Hash",
18057
+ "default": "N/A",
18058
+ "description": "{{link_to_system_arguments_docs}}"
18059
+ }
18060
+ ],
18061
+ "slots": [
18062
+ {
18063
+ "name": "editable_form",
18064
+ "description": null,
18065
+ "parameters": [
18066
+
18067
+ ]
18068
+ }
18069
+ ],
18070
+ "methods": [
18071
+
18072
+ ],
18073
+ "previews": [
18074
+
18075
+ ],
18076
+ "subcomponents": [
18077
+
18078
+ ]
18079
+ },
18027
18080
  {
18028
18081
  "fully_qualified_name": "Primer::OpenProject::SidePanel",
18029
18082
  "description": "Add a general description of component here\nAdd additional usage considerations or best practices that may aid the user to use the component correctly.",
data/static/previews.json CHANGED
@@ -5391,6 +5391,19 @@
5391
5391
  ]
5392
5392
  }
5393
5393
  },
5394
+ {
5395
+ "preview_path": "primer/open_project/page_header/editable_title",
5396
+ "name": "editable_title",
5397
+ "snapshot": "false",
5398
+ "skip_rules": {
5399
+ "wont_fix": [
5400
+ "region"
5401
+ ],
5402
+ "will_fix": [
5403
+ "color-contrast"
5404
+ ]
5405
+ }
5406
+ },
5394
5407
  {
5395
5408
  "preview_path": "primer/open_project/page_header/actions",
5396
5409
  "name": "actions",
data/static/statuses.json CHANGED
@@ -125,6 +125,7 @@
125
125
  "Primer::OpenProject::PageHeader": "open_project",
126
126
  "Primer::OpenProject::PageHeader::Dialog": "open_project",
127
127
  "Primer::OpenProject::PageHeader::Menu": "open_project",
128
+ "Primer::OpenProject::PageHeader::Title": "open_project",
128
129
  "Primer::OpenProject::SidePanel": "open_project",
129
130
  "Primer::OpenProject::SidePanel::Section": "open_project",
130
131
  "Primer::OpenProject::SubHeader": "open_project",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openproject-primer_view_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.40.0
4
+ version: 0.41.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Open Source
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-07-29 00:00:00.000000000 Z
12
+ date: 2024-08-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionview
@@ -508,6 +508,8 @@ files:
508
508
  - app/components/primer/open_project/page_header.rb
509
509
  - app/components/primer/open_project/page_header/dialog.rb
510
510
  - app/components/primer/open_project/page_header/menu.rb
511
+ - app/components/primer/open_project/page_header/title.html.erb
512
+ - app/components/primer/open_project/page_header/title.rb
511
513
  - app/components/primer/open_project/page_header_element.d.ts
512
514
  - app/components/primer/open_project/page_header_element.js
513
515
  - app/components/primer/open_project/page_header_element.ts