dsfr-view-components 5.0.0.pre → 5.0.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: be08ee815bcd05cde35b9b28469c01af61b7c6242c93597e3e40f675e090c690
4
- data.tar.gz: b3ef44ef8460bd258aedd1698fefd2918739264b52022b6043f76f45828ff15e
3
+ metadata.gz: 02b516513b253dd53b123c414a4b08ae91c4a5c51ea8633843bec5f9605cfdc4
4
+ data.tar.gz: 9f45ba667ec0f130097de1d2c2fc14f4bbdda018e3ebef3eb3fb8f786cff2cfa
5
5
  SHA512:
6
- metadata.gz: ba9029e0f6f299c38e6a287fa55f36eff1abb1b6492b6e0922377c534a9abea09f960c1277d7e39a1bfb5b432b2b66932723f1c25f4917dc78017f67bb69457f
7
- data.tar.gz: 47d7732b63da68357c01ce0be606dc845b3086100ce718920462ea0418c392999789edf7af27c5a737f71d9971b4a40a4c667d41db07fb736b95d23187df7f67
6
+ metadata.gz: 60c971316b5d90cd567a7e7ae7c296d644227d9b85601847a59b13c25dee4a3c0e12af5239a6c8384d7fbf58df993134c9af6648bb9533adaa648a45010b5c0b
7
+ data.tar.gz: c617ade15d0eb93211488799cd38963e7cecd349d2779bade57565644c59d94fc6ee9cd9d58acdc32d34be6d39ee3fa678c0ea6bfcab9cc6d512916e6918b8b9
@@ -0,0 +1,43 @@
1
+ <%= tag.div(**html_attributes) do %>
2
+ <div class="fr-card__body">
3
+ <div class="fr-card__content">
4
+ <%= title_tag(class: "fr-card__title") do %>
5
+ <a class="fr-card__link" href="<%= url %>"><%= title %></a>
6
+ <% end %>
7
+ <% if description.present? %>
8
+ <p class="fr-card__desc"><%= description %></p>
9
+ <% end %>
10
+ <% if start_detail.present? %>
11
+ <div class="fr-card__start">
12
+ <p class="<%= start_detail_classes %>"><%= start_detail %></p>
13
+ </div>
14
+ <% end %>
15
+ <% if end_detail.present? %>
16
+ <div class="fr-card__end">
17
+ <p class="<%= end_detail_classes %>"><%= end_detail %></p>
18
+ </div>
19
+ <% end %>
20
+ </div>
21
+ <% if footer? %>
22
+ <div class="fr-card__footer">
23
+ <%= footer %>
24
+ </div>
25
+ <% end %>
26
+ </div>
27
+ <% if image_src.present? || badges.any? %>
28
+ <div class="fr-card__header">
29
+ <% if image_src.present? %>
30
+ <div class="fr-card__img">
31
+ <img class="fr-responsive-img" src="<%= image_src %>" alt="<%= image_alt %>">
32
+ </div>
33
+ <% end %>
34
+ <% if badges.any? %>
35
+ <ul class="fr-badges-group">
36
+ <% badges.each do |badge| %>
37
+ <li><%= badge %></li>
38
+ <% end %>
39
+ </ul>
40
+ <% end %>
41
+ </div>
42
+ <% end %>
43
+ <% end %>
@@ -0,0 +1,79 @@
1
+ module DsfrComponent
2
+ class CardComponent < DsfrComponent::Base
3
+ SIZES = %i[sm lg].freeze
4
+ HORIZONTAL_RATIOS = [true, :half, :tier].freeze
5
+
6
+ renders_many :badges, "DsfrComponent::BadgeComponent"
7
+ renders_one :footer
8
+
9
+ def initialize(
10
+ title:,
11
+ url:,
12
+ description: nil,
13
+ image_src: nil,
14
+ image_alt: "",
15
+ heading_level: 3,
16
+ size: nil,
17
+ horizontal: false,
18
+ start_detail: nil,
19
+ start_detail_icon: nil,
20
+ end_detail: nil,
21
+ end_detail_icon: nil,
22
+ enlarge_link: true,
23
+ html_attributes: {}
24
+ )
25
+ raise ArgumentError, "`size` should be one of #{SIZES}" if size && SIZES.exclude?(size)
26
+ raise ArgumentError, "`heading_level` should be one of #{HEADING_LEVELS}" if HEADING_LEVELS.exclude?(heading_level)
27
+ raise ArgumentError, "`horizontal` should be one of #{[false] + HORIZONTAL_RATIOS}" if horizontal != false && HORIZONTAL_RATIOS.exclude?(horizontal)
28
+
29
+ @title = title
30
+ @url = url
31
+ @description = description
32
+ @image_src = image_src
33
+ @image_alt = image_alt
34
+ @heading_level = heading_level
35
+ @size = size
36
+ @horizontal = horizontal
37
+ @start_detail = start_detail
38
+ @start_detail_icon = start_detail_icon
39
+ @end_detail = end_detail
40
+ @end_detail_icon = end_detail_icon
41
+ @enlarge_link = enlarge_link
42
+
43
+ super(html_attributes: html_attributes)
44
+ end
45
+
46
+ # this guard is set at render-time because we cannot make the
47
+ # footer-slot distinction in the constructor
48
+ def before_render
49
+ raise ArgumentError, "You cannot setup a footer on a card with `enlarge_link: true`" if footer? && enlarge_link
50
+ end
51
+
52
+ private
53
+
54
+ attr_reader :title, :url, :description, :image_src, :image_alt,
55
+ :heading_level, :size, :horizontal, :start_detail, :start_detail_icon,
56
+ :end_detail, :end_detail_icon, :enlarge_link
57
+
58
+ def default_attributes
59
+ classes = ["fr-card"]
60
+ classes << "fr-enlarge-link" if enlarge_link
61
+ classes << "fr-card--horizontal" if horizontal
62
+ classes << "fr-card--horizontal-#{horizontal}" if horizontal.is_a?(Symbol)
63
+ classes << "fr-card--#{size}" if size
64
+ { class: classes }
65
+ end
66
+
67
+ def title_tag(*args, **kwargs, &block)
68
+ content_tag("h#{heading_level}", *args, **kwargs, &block)
69
+ end
70
+
71
+ def start_detail_classes
72
+ ["fr-card__detail", start_detail_icon && "fr-icon-#{start_detail_icon}"].compact.join(" ")
73
+ end
74
+
75
+ def end_detail_classes
76
+ ["fr-card__detail", end_detail_icon && "fr-icon-#{end_detail_icon}"].compact.join(" ")
77
+ end
78
+ end
79
+ end
@@ -1,6 +1,13 @@
1
1
  <%= tag.div(**html_attributes) do %>
2
2
  <div class="fr-tile__body">
3
3
  <div class="fr-tile__content">
4
+ <% if badges.any? %>
5
+ <div class="fr-tile__start">
6
+ <% badges.each do |badge| %>
7
+ <%= badge %>
8
+ <% end %>
9
+ </div>
10
+ <% end %>
4
11
  <%= title_tag(class: "fr-tile__title") do %>
5
12
  <a class="fr-tile__link" href="<%= url %>">
6
13
  <%= title %>
@@ -1,5 +1,7 @@
1
1
  module DsfrComponent
2
2
  class TileComponent < DsfrComponent::Base
3
+ renders_many :badges, "DsfrComponent::BadgeComponent"
4
+
3
5
  # @param title [String] title (required)
4
6
  # @param url [String] url (required)
5
7
  # @param image_src [String] chemin vers l'image (optional)
@@ -21,6 +23,10 @@ module DsfrComponent
21
23
  super(html_attributes: html_attributes)
22
24
  end
23
25
 
26
+ def before_render
27
+ raise ArgumentError, "TileComponent accepte au maximum 4 badges (#{badges.size} fournis)" if badges.size > 4
28
+ end
29
+
24
30
  private
25
31
 
26
32
  attr_reader :title, :url, :image_src, :image_alt, :description, :orientation, :heading_level
@@ -24,6 +24,7 @@ module DsfrComponentsHelper
24
24
  dsfr_proconnect_button: 'DsfrComponent::ProconnectButtonComponent',
25
25
  dsfr_side_menu: 'DsfrComponent::SideMenuComponent',
26
26
  dsfr_side_menu_item: 'DsfrComponent::SideMenuComponent::ItemComponent',
27
+ dsfr_card: 'DsfrComponent::CardComponent',
27
28
  # DO NOT REMOVE: new component mapping here
28
29
  }.freeze
29
30
  HELPER_NAME_TO_CLASS_NAME.each do |name, klass|
@@ -1,5 +1,5 @@
1
1
  module Dsfr
2
2
  module Components
3
- VERSION = '5.0.0.pre'.freeze
3
+ VERSION = '5.0.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dsfr-view-components
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0.pre
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - BetaGouv developers
@@ -347,6 +347,8 @@ files:
347
347
  - app/components/dsfr_component/breadcrumbs_component.rb
348
348
  - app/components/dsfr_component/button_component.rb
349
349
  - app/components/dsfr_component/callout_component.rb
350
+ - app/components/dsfr_component/card_component.html.erb
351
+ - app/components/dsfr_component/card_component.rb
350
352
  - app/components/dsfr_component/header_component.html.erb
351
353
  - app/components/dsfr_component/header_component.rb
352
354
  - app/components/dsfr_component/header_component/direct_link_component.rb
@@ -418,7 +420,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
418
420
  - !ruby/object:Gem::Version
419
421
  version: '0'
420
422
  requirements: []
421
- rubygems_version: 4.0.6
423
+ rubygems_version: 3.6.9
422
424
  specification_version: 4
423
425
  summary: Composants ViewComponent pour le Système de Design de l'État (DSFR)
424
426
  test_files: []