primer_view_components 0.41.0 → 0.43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c96d27c7589b44364a5dbcd2371bb0360b7fd629371fd224cde69914570055b
4
- data.tar.gz: b33fc96b99c510c1efa1c421b20e21d5ce42e575b5b7f58472aef80d86f77c77
3
+ metadata.gz: 8b8def83f2582f5a2ac49a275b6f0262473510b6bc9f3931cb72115bb91e1b8d
4
+ data.tar.gz: ea003aff30f6d1b2570c432c2921a93e8ec9bdb9a682d39fb5d5bf4e29729418
5
5
  SHA512:
6
- metadata.gz: d9cc017ed5a8295dcf4576cf9aaa555b618d5e0c1629d09d50fd716aa9313e524ef717e3ad9f906002c060bba2ae7bdece9b026d4aeccce1e7f601cc017a912b
7
- data.tar.gz: 3d7eb52d24074091b151573fd63f9324538866559b0b9cf395e9889847d5faa8b0a06cd0283c7cdb71140b109feda1bf13cc39cf8c4f1d6a2d2192024adb5f02
6
+ metadata.gz: 314b33264d58ea808b7db78d0137cc03d151a4e6f3aab8a363a8ea4c0fecd622edfcdb6df81499f02807d0616298978e80b94865ac4b435109911056073f9503
7
+ data.tar.gz: 83449ea51244eec9fa28f361221b66a9bb0e6450e2a025f30e9adc5e8f848af08eb4f9057c5f0b583128799d07f8d1877659708350c59363feeea1a9ead0b31e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.43.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#3466](https://github.com/primer/view_components/pull/3466) [`57f6c41`](https://github.com/primer/view_components/commit/57f6c41025de70dfcd6880dab7e881d182e3cbd9) Thanks [@manuelpuyol](https://github.com/manuelpuyol)! - Create Primer::CurrentAttributes allowing apps to set request specific context to components. Update IncludeFragment to add data-nonce when a current nonce is present.
8
+
9
+ ### Patch Changes
10
+
11
+ - [#3447](https://github.com/primer/view_components/pull/3447) [`c2b88cb`](https://github.com/primer/view_components/commit/c2b88cb1d75e86fc0b410e3fc597e48326f471a5) Thanks [@bsatarnejad](https://github.com/bsatarnejad)! - Add a new custom label for close button in dialog header
12
+
13
+ - [#3450](https://github.com/primer/view_components/pull/3450) [`5e86bf4`](https://github.com/primer/view_components/commit/5e86bf422b13a3818def5ceab464f8e362f9021b) Thanks [@francinelucca](https://github.com/francinelucca)! - Fix(SelectPanel): incorrect padding when no filter
14
+
15
+ ## 0.42.0
16
+
17
+ ### Minor Changes
18
+
19
+ - [#3428](https://github.com/primer/view_components/pull/3428) [`1ab1b06`](https://github.com/primer/view_components/commit/1ab1b06509763ea60fc89770754edf06229b4f63) Thanks [@manuelpuyol](https://github.com/manuelpuyol)! - Create IncludeFragment component. Allow ConditionalWrapper to render components other than BaseComponent
20
+
21
+ ### Patch Changes
22
+
23
+ - [#3429](https://github.com/primer/view_components/pull/3429) [`6ea9fd5`](https://github.com/primer/view_components/commit/6ea9fd5dc90c1964ab3882faf1733c6b49c80e21) Thanks [@manuelpuyol](https://github.com/manuelpuyol)! - Create IncludeFragment linter to migrate <include-fragment> uses
24
+
3
25
  ## 0.41.0
4
26
 
5
27
  ### Minor Changes
@@ -3,7 +3,7 @@
3
3
  <%= render(@overlay) do |overlay| %>
4
4
  <% overlay.with_body(padding: :none) do %>
5
5
  <% if @src.present? %>
6
- <include-fragment src="<%= @src %>" loading="<%= preload? ? "eager" : "lazy" %>" data-target="action-menu.includeFragment">
6
+ <%= render(Primer::Alpha::IncludeFragment.new(src: @src, loading: preload? ? :eager : :lazy, "data-target": "action-menu.includeFragment")) do %>
7
7
  <%= render(Primer::Alpha::ActionMenu::List.new(id: "#{@menu_id}-list", menu_id: @menu_id)) do |list| %>
8
8
  <% list.with_item(
9
9
  aria: { disabled: true },
@@ -18,7 +18,7 @@
18
18
  <%= render Primer::Beta::Spinner.new(aria: { label: "Loading content..." }) %>
19
19
  <% end %>
20
20
  <% end %>
21
- </include-fragment>
21
+ <% end %>
22
22
  <% else %>
23
23
  <%= render(@list) %>
24
24
  <% end %>
@@ -13,7 +13,7 @@
13
13
  <% end %>
14
14
  </div>
15
15
  <div class="Overlay-actionWrap">
16
- <%= render Primer::Beta::CloseButton.new(classes: "Overlay-closeButton", "data-close-dialog-id": @id) %>
16
+ <%= render Primer::Beta::CloseButton.new(classes: "Overlay-closeButton", "data-close-dialog-id": @id, aria: { label: @close_label }) %>
17
17
  </div>
18
18
  </div>
19
19
  <%= filter %>
@@ -16,6 +16,8 @@ module Primer
16
16
  }.freeze
17
17
  VARIANT_OPTIONS = VARIANT_MAPPINGS.keys
18
18
 
19
+ DEFAULT_CLOSE_LABEL = "Close"
20
+
19
21
  # Optional filter slot for adding a filter input to the header.
20
22
  #
21
23
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
@@ -48,6 +50,7 @@ module Primer
48
50
  # @param show_divider [Boolean] Show a divider between the header and body.
49
51
  # @param visually_hide_title [Boolean] Visually hide the `title` while maintaining a label for assistive technologies.
50
52
  # @param variant [Symbol] <%= one_of(Primer::Alpha::Dialog::Header::VARIANT_OPTIONS) %>
53
+ # @param close_label [String] The aria-label text of the close "x" button.
51
54
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
52
55
  def initialize(
53
56
  id:,
@@ -56,12 +59,14 @@ module Primer
56
59
  show_divider: false,
57
60
  visually_hide_title: false,
58
61
  variant: DEFAULT_VARIANT,
62
+ close_label: DEFAULT_CLOSE_LABEL,
59
63
  **system_arguments
60
64
  )
61
65
  @id = id
62
66
  @title = title
63
67
  @subtitle = subtitle
64
68
  @visually_hide_title = visually_hide_title
69
+ @close_label = close_label
65
70
  @system_arguments = deny_tag_argument(**system_arguments)
66
71
  @system_arguments[:tag] = :div
67
72
 
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ module Alpha
5
+ # Use `IncludeFragment` to load HTML elements from the server.
6
+ # Add additional usage considerations or best practices that may aid the user to use the component correctly.
7
+ # @accessibility Add any accessibility considerations
8
+ class IncludeFragment < Primer::Component
9
+ status :alpha
10
+
11
+ ALLOWED_LOADING_VALUES = [:lazy, :eager].freeze
12
+ DEFAULT_LOADING = :eager
13
+
14
+ # @param src [String] The URL from which to retrieve an HTML element fragment.
15
+ # @param loading [Symbol] <%= one_of([:lazy, :eager]) %>
16
+ # @param accept [String] What to send as the Accept header.
17
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
18
+ def initialize(src: nil, loading: nil, accept: nil, **system_arguments)
19
+ @system_arguments = system_arguments
20
+ @system_arguments[:tag] = "include-fragment"
21
+ @system_arguments[:loading] = loading
22
+ @system_arguments[:src] = src
23
+ @system_arguments[:accept] = accept if accept
24
+
25
+ if loading
26
+ @system_arguments[:loading] = fetch_or_fallback(ALLOWED_LOADING_VALUES, loading.to_sym, DEFAULT_LOADING)
27
+ end
28
+
29
+ if Primer::CurrentAttributes.nonce
30
+ @system_arguments[:"data-nonce"] = Primer::CurrentAttributes.nonce
31
+ end
32
+ end
33
+
34
+ def call
35
+ render(Primer::BaseComponent.new(**@system_arguments)) { content }
36
+ end
37
+ end
38
+ end
39
+ end
@@ -50,7 +50,7 @@
50
50
  <% end %>
51
51
  <% end %>
52
52
  <% end %>
53
- <%= render Primer::Alpha::Dialog::Body.new(mt: show_filter? ? 0 : 2, p: 0) do %>
53
+ <%= render Primer::Alpha::Dialog::Body.new(p: 0) do %>
54
54
  <focus-group direction="vertical" mnemonics retain>
55
55
  <live-region data-target="select-panel.liveRegion"></live-region>
56
56
  <%= render(Primer::BaseComponent.new(
@@ -62,7 +62,7 @@
62
62
  )) do %>
63
63
  <div id="<%= @body_id %>">
64
64
  <% if @src.present? %>
65
- <%= render(Primer::ConditionalWrapper.new(condition: @fetch_strategy == :eventually_local, tag: "include-fragment", data: { target: "select-panel.includeFragment" }, src: @src, loading: preload? ? "eager" : "lazy", accept: "text/fragment+html")) do %>
65
+ <%= render(Primer::ConditionalWrapper.new(condition: @fetch_strategy == :eventually_local, component: Primer::Alpha::IncludeFragment, data: { target: "select-panel.includeFragment" }, src: @src, loading: preload? ? "eager" : "lazy", accept: "text/fragment+html")) do %>
66
66
  <%= render(Primer::BaseComponent.new(
67
67
  tag: :div,
68
68
  id: "#{@panel_id}-list",
@@ -1,14 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Primer
4
- # Conditionally renders a `Primer::BaseComponent` around the given content. If the given condition
5
- # is true, a `Primer::BaseComponent` will render around the content. If the condition is false, only
4
+ # Conditionally renders a component around the given content. If the given condition
5
+ # is true, the component will render around the content. If the condition is false, only
6
6
  # the content is rendered.
7
7
  class ConditionalWrapper < Primer::Component
8
- # @param condition [Boolean] Whether or not to wrap the content in a `Primer::BaseComponent`.
9
- # @param base_component_arguments [Hash] The arguments to pass to `Primer::BaseComponent`.
10
- def initialize(condition:, **base_component_arguments)
8
+ # @param condition [Boolean] Whether or not to wrap the content in a component.
9
+ # @param component [Class] The component class to use as a wrapper, defaults to `Primer::BaseComponent`
10
+ # @param base_component_arguments [Hash] The arguments to pass to the component.
11
+ def initialize(condition:, component: Primer::BaseComponent, **base_component_arguments)
11
12
  @condition = condition
13
+ @component = component
12
14
  @base_component_arguments = base_component_arguments
13
15
  @trim = !!@base_component_arguments.delete(:trim)
14
16
  end
@@ -18,7 +20,7 @@ module Primer
18
20
  return @trim ? trimmed_content : content
19
21
  end
20
22
 
21
- BaseComponent.new(trim: @trim, **@base_component_arguments).render_in(self) { content }
23
+ @component.new(trim: @trim, **@base_component_arguments).render_in(self) { content }
22
24
  end
23
25
  end
24
26
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ # `Primer::CurrentAttributes` can be used by controllers to set request-bound data
5
+ # that can be propagated to components.
6
+ class CurrentAttributes < ActiveSupport::CurrentAttributes
7
+ attribute :nonce
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "base"
4
+
5
+ module ERBLint
6
+ module Linters
7
+ module ArgumentMappers
8
+ # Maps attributes in the include-fragment element to arguments for the IncludeFragment component.
9
+ class IncludeFragment < Base
10
+ DEFAULT_TAG = "include-fragment"
11
+ ATTRIBUTES = %w[loading src accept role preload tabindex autofocus hidden].freeze
12
+
13
+ def attribute_to_args(attribute)
14
+ attr_name = attribute.name
15
+
16
+ { attr_name.to_sym => erb_helper.convert(attribute) }
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "base_linter"
4
+ require_relative "autocorrectable"
5
+ require_relative "argument_mappers/include_fragment"
6
+
7
+ module ERBLint
8
+ module Linters
9
+ # Counts the number of times a HTML include-fragment is used instead of the component.
10
+ class IncludeFragmentComponentMigrationCounter < BaseLinter
11
+ include Autocorrectable
12
+
13
+ TAGS = %w[include-fragment].freeze
14
+ REQUIRED_ARGUMENTS = [].freeze
15
+ MESSAGE = "We are migrating include-fragment to use [Primer::Alpha::IncludeFragment](https://primer.style/view-components/lookbook/inspect/primer/alpha/include_fragment/default), please try to use that instead of raw HTML."
16
+ ARGUMENT_MAPPER = ArgumentMappers::IncludeFragment
17
+ COMPONENT = "Primer::Alpha::IncludeFragment"
18
+ end
19
+ end
20
+ end
@@ -5,7 +5,7 @@ module Primer
5
5
  module ViewComponents
6
6
  module VERSION
7
7
  MAJOR = 0
8
- MINOR = 41
8
+ MINOR = 43
9
9
  PATCH = 0
10
10
 
11
11
  STRING = [MAJOR, MINOR, PATCH].join(".")
@@ -0,0 +1,5 @@
1
+ <%= render(Primer::Alpha::Dialog.new(id: "my-dialog", title: title, subtitle: subtitle, visually_hide_title: false)) do |dialog| %>
2
+ <% dialog.with_header(show_divider: show_divider, close_label: close_label) %>
3
+ <% dialog.with_show_button_content(button_text) %>
4
+ <% dialog.with_body_content("Hello World") %>
5
+ <% end %>
@@ -0,0 +1,8 @@
1
+ <%= render(Primer::Alpha::Dialog.new(id: "my-dialog", title: title, subtitle: subtitle, visually_hide_title: false)) do |dialog| %>
2
+ <% dialog.with_header(show_divider: show_divider, close_scheme: :none) %>
3
+ <% dialog.with_show_button_content(button_text) %>
4
+ <% dialog.with_body_content("Hello World") %>
5
+ <% dialog.with_footer do %>
6
+ <%= render(Primer::Beta::Button.new(data: { "close-dialog-id": "my-dialog" })) { "Close" } %>
7
+ <% end %>
8
+ <% end %>
@@ -302,6 +302,38 @@ module Primer
302
302
  def with_header_filter
303
303
  render_with_template(locals: {})
304
304
  end
305
+
306
+ # @label With custom label for close button of header
307
+ #
308
+ # @param title [String] text
309
+ # @param subtitle [String] text
310
+ # @param button_text [String] text
311
+ # @param show_divider [Boolean] toggle
312
+ # @param close_label [String] text
313
+ def with_header_close_button_label(title: "Test Dialog", subtitle: nil, button_text: "Show Dialog", show_divider: true, close_label: "Close me!")
314
+ render_with_template(locals: {
315
+ title: title,
316
+ subtitle: subtitle,
317
+ button_text: button_text,
318
+ show_divider: show_divider,
319
+ close_label: close_label
320
+ })
321
+ end
322
+
323
+ # @label Without custom label for close button of header
324
+ #
325
+ # @param title [String] text
326
+ # @param subtitle [String] text
327
+ # @param button_text [String] text
328
+ # @param show_divider [Boolean] toggle
329
+ def without_header_close_button_label(title: "Test Dialog", subtitle: nil, button_text: "Show Dialog", show_divider: true)
330
+ render_with_template(locals: {
331
+ title: title,
332
+ subtitle: subtitle,
333
+ button_text: button_text,
334
+ show_divider: show_divider
335
+ })
336
+ end
305
337
  end
306
338
  end
307
339
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Setup Playground to use all available component props
4
+ # Setup Features to use individual component props and combinations
5
+
6
+ module Primer
7
+ module Alpha
8
+ # @label IncludeFragment
9
+ class IncludeFragmentPreview < ViewComponent::Preview
10
+ # @label Playground
11
+ # @param loading select [eager, lazy]
12
+ def playground(loading: :eager)
13
+ render(Primer::Alpha::IncludeFragment.new(loading: loading, src: UrlHelpers.include_fragment_deferred_path)) { "Loading..." }
14
+ end
15
+
16
+ # @label Default options
17
+ def default
18
+ render(Primer::Alpha::IncludeFragment.new(loading: :eager, src: UrlHelpers.include_fragment_deferred_path)) { "Loading..." }
19
+ end
20
+ end
21
+ end
22
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: primer_view_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.41.0
4
+ version: 0.43.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Open Source
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-11 00:00:00.000000000 Z
11
+ date: 2025-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -201,6 +201,7 @@ files:
201
201
  - app/components/primer/alpha/hellip_button.rb
202
202
  - app/components/primer/alpha/hidden_text_expander.rb
203
203
  - app/components/primer/alpha/image.rb
204
+ - app/components/primer/alpha/include_fragment.rb
204
205
  - app/components/primer/alpha/layout.css
205
206
  - app/components/primer/alpha/layout.css.json
206
207
  - app/components/primer/alpha/layout.css.map
@@ -550,6 +551,7 @@ files:
550
551
  - app/lib/primer/css/layout.css.json
551
552
  - app/lib/primer/css/utilities.css
552
553
  - app/lib/primer/css/utilities.css.json
554
+ - app/lib/primer/current_attributes.rb
553
555
  - app/lib/primer/experimental_render_helpers.rb
554
556
  - app/lib/primer/experimental_slot_helpers.rb
555
557
  - app/lib/primer/fetch_or_fallback_helper.rb
@@ -681,6 +683,7 @@ files:
681
683
  - lib/primer/view_components/linters/argument_mappers/conversion_error.rb
682
684
  - lib/primer/view_components/linters/argument_mappers/flash.rb
683
685
  - lib/primer/view_components/linters/argument_mappers/helpers/erb_block.rb
686
+ - lib/primer/view_components/linters/argument_mappers/include_fragment.rb
684
687
  - lib/primer/view_components/linters/argument_mappers/label.rb
685
688
  - lib/primer/view_components/linters/argument_mappers/system_arguments.rb
686
689
  - lib/primer/view_components/linters/autocorrectable.rb
@@ -699,6 +702,7 @@ files:
699
702
  - lib/primer/view_components/linters/helpers/deprecated_components_helpers.rb
700
703
  - lib/primer/view_components/linters/helpers/rubocop_helpers.rb
701
704
  - lib/primer/view_components/linters/helpers/rule_helpers.rb
705
+ - lib/primer/view_components/linters/include_fragment_component_migration_counter.rb
702
706
  - lib/primer/view_components/linters/label_component_migration_counter.rb
703
707
  - lib/primer/view_components/linters/migrate_deprecated_flash_arguments.rb
704
708
  - lib/primer/view_components/linters/migrations/iconbutton_component.rb
@@ -779,13 +783,16 @@ files:
779
783
  - previews/primer/alpha/dialog_preview/with_footer.html.erb
780
784
  - previews/primer/alpha/dialog_preview/with_form.html.erb
781
785
  - previews/primer/alpha/dialog_preview/with_header.html.erb
786
+ - previews/primer/alpha/dialog_preview/with_header_close_button_label.html.erb
782
787
  - previews/primer/alpha/dialog_preview/with_header_filter.html.erb
783
788
  - previews/primer/alpha/dialog_preview/with_text_input.html.erb
789
+ - previews/primer/alpha/dialog_preview/without_header_close_button_label.html.erb
784
790
  - previews/primer/alpha/dropdown_preview.rb
785
791
  - previews/primer/alpha/form_control_preview.rb
786
792
  - previews/primer/alpha/form_control_preview/playground.html.erb
787
793
  - previews/primer/alpha/hellip_button_preview.rb
788
794
  - previews/primer/alpha/hidden_text_expander_preview.rb
795
+ - previews/primer/alpha/include_fragment_preview.rb
789
796
  - previews/primer/alpha/layout_preview.rb
790
797
  - previews/primer/alpha/menu_preview.rb
791
798
  - previews/primer/alpha/menu_preview/default.html.erb