primer_view_components 0.41.0 → 0.42.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: 3cecb9c07526e9ed4c595b81ab2407709d46e00be974ce5ea60023f1091ff1c1
4
+ data.tar.gz: a4d50670d1294e10aaa8d249c87c8bea4d879bd1b9ca3cbe43ca4a082f265784
5
5
  SHA512:
6
- metadata.gz: d9cc017ed5a8295dcf4576cf9aaa555b618d5e0c1629d09d50fd716aa9313e524ef717e3ad9f906002c060bba2ae7bdece9b026d4aeccce1e7f601cc017a912b
7
- data.tar.gz: 3d7eb52d24074091b151573fd63f9324538866559b0b9cf395e9889847d5faa8b0a06cd0283c7cdb71140b109feda1bf13cc39cf8c4f1d6a2d2192024adb5f02
6
+ metadata.gz: 4d8c7cdb2e70078106522c2fe88a4ea8205dfbc0416a008f5bd8c9005305ea670b767a4ab26b9772392be13107136c26de8e840e999b23368f27d4d5a429072a
7
+ data.tar.gz: 73cf2a36f12cafabe4cdbfb6af9e720fabccdfcb8fb26eb9a6aeb5e18854e7cf0c6b49274bc03698b335273507d339046314e70a349cdd3a63f5d2126b1fab1c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.42.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#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
8
+
9
+ ### Patch Changes
10
+
11
+ - [#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
12
+
3
13
  ## 0.41.0
4
14
 
5
15
  ### 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 %>
@@ -0,0 +1,26 @@
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
+ # @param src [String] The URL from which to retrieve an HTML element fragment.
12
+ # @param loading [Symbol] <%= one_of([:lazy, :eager]) %>
13
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
14
+ def initialize(src: nil, loading: :eager, **system_arguments)
15
+ @system_arguments = system_arguments
16
+ @system_arguments[:tag] = "include-fragment"
17
+ @system_arguments[:loading] = loading
18
+ @system_arguments[:src] = src
19
+ end
20
+
21
+ def call
22
+ render(Primer::BaseComponent.new(**@system_arguments)) { content }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -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,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 = 42
9
9
  PATCH = 0
10
10
 
11
11
  STRING = [MAJOR, MINOR, PATCH].join(".")
@@ -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.42.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-15 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
@@ -681,6 +682,7 @@ files:
681
682
  - lib/primer/view_components/linters/argument_mappers/conversion_error.rb
682
683
  - lib/primer/view_components/linters/argument_mappers/flash.rb
683
684
  - lib/primer/view_components/linters/argument_mappers/helpers/erb_block.rb
685
+ - lib/primer/view_components/linters/argument_mappers/include_fragment.rb
684
686
  - lib/primer/view_components/linters/argument_mappers/label.rb
685
687
  - lib/primer/view_components/linters/argument_mappers/system_arguments.rb
686
688
  - lib/primer/view_components/linters/autocorrectable.rb
@@ -699,6 +701,7 @@ files:
699
701
  - lib/primer/view_components/linters/helpers/deprecated_components_helpers.rb
700
702
  - lib/primer/view_components/linters/helpers/rubocop_helpers.rb
701
703
  - lib/primer/view_components/linters/helpers/rule_helpers.rb
704
+ - lib/primer/view_components/linters/include_fragment_component_migration_counter.rb
702
705
  - lib/primer/view_components/linters/label_component_migration_counter.rb
703
706
  - lib/primer/view_components/linters/migrate_deprecated_flash_arguments.rb
704
707
  - lib/primer/view_components/linters/migrations/iconbutton_component.rb
@@ -786,6 +789,7 @@ files:
786
789
  - previews/primer/alpha/form_control_preview/playground.html.erb
787
790
  - previews/primer/alpha/hellip_button_preview.rb
788
791
  - previews/primer/alpha/hidden_text_expander_preview.rb
792
+ - previews/primer/alpha/include_fragment_preview.rb
789
793
  - previews/primer/alpha/layout_preview.rb
790
794
  - previews/primer/alpha/menu_preview.rb
791
795
  - previews/primer/alpha/menu_preview/default.html.erb