dsfr-view-components 5.0.0.pre → 5.0.1

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: 5095d1305a3f94fe5a01ee178af11833e291ad6ec0119b59e94b9170ee0acb0b
4
+ data.tar.gz: acf69b43c9330f356754a8592772287b5b2bdeb0db174cba46f5e2a35f780144
5
5
  SHA512:
6
- metadata.gz: ba9029e0f6f299c38e6a287fa55f36eff1abb1b6492b6e0922377c534a9abea09f960c1277d7e39a1bfb5b432b2b66932723f1c25f4917dc78017f67bb69457f
7
- data.tar.gz: 47d7732b63da68357c01ce0be606dc845b3086100ce718920462ea0418c392999789edf7af27c5a737f71d9971b4a40a4c667d41db07fb736b95d23187df7f67
6
+ metadata.gz: 773981869125a91a17f51f3bcef476a59777e328157d0142ebff7ec0d54e4029a5922b5e987032ec34be0dce70bc54b5418bbb3ddb31ffeb72bc4c41e2e5b970
7
+ data.tar.gz: 1df1573b2231bb50d66c58e3e04adf1d4ba3f51ed21792810f0018e159d72ffd6a2fb5f1cea6c9beaebb20eb40ef07e8ecbd943aed2e568840457c21c76f982d
@@ -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,106 +1,7 @@
1
1
  require "rails/engine"
2
- require "active_support/configurable"
3
2
 
4
3
  module Dsfr
5
4
  module Components
6
- include ActiveSupport::Configurable
7
-
8
- class << self
9
- # Configure the form builder in the usual manner. All of the
10
- # keys in {DEFAULTS} can be configured as per the example below
11
- #
12
- # @example
13
- # Dsfr::Components.configure do |conf|
14
- # conf.do_some_things = 'yes'
15
- # end
16
- def configure
17
- yield(config)
18
- end
19
-
20
- # Resets each of the configurable values to its default
21
- #
22
- # @note This method is only really intended for use to clean up
23
- # during testing
24
- def reset!
25
- configure do |c|
26
- DEFAULTS.each { |k, v| c.send("#{k}=", v) }
27
- end
28
- end
29
- end
30
-
31
- # @!group Defaults
32
- #
33
- # Default components configuration
34
- #
35
- # +:default_back_link_text+ Default text for the back link, defaults to +Back+
36
- # +:default_breadcrumbs_collapse_on_mobile+ false
37
- # +:default_breadcrumbs_hide_in_print+ false
38
- # +:default_cookie_banner_aria_label+ "Cookie banner"
39
- # +:default_cookie_banner_hide_in_print+ true
40
- # +:default_header_navigation_label+ 'Navigation menu'
41
- # +:default_header_menu_button_label+ 'Show or hide navigation menu'
42
- # +:default_header_logotype+ 'GOV.UK'
43
- # +:default_header_homepage_url+ '/'
44
- # +:default_header_service_name+ nil
45
- # +:default_header_service_url+ '/'
46
- # +:default_footer_meta_text+ nil
47
- # +:default_footer_copyright_text+ '© Crown copyright'
48
- # +:default_footer_copyright_url+ "https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/"
49
- # +:default_pagination_landmark_label+ "results"
50
- # +:default_pagination_next_text+ Default 'next' text for pagination. An +Array+ where the first item is visible and the second visually hidden. Defaults to ["Next", "page"]
51
- # +:default_pagination_previous_text+ Default 'previous' text for pagination. An +Array+ where the first item is visible and the second visually hidden. Defaults to ["Previous", "page"]
52
- # +:default_phase_banner_tag+ nil
53
- # +:default_phase_banner_text+ nil
54
- # +:default_section_break_visible+ false
55
- # +:default_section_break_size+ Size of the section break, possible values: +m+, +l+ and +xl+. Defaults to nil.
56
- # +:default_tag_colour+ the default colour for tags, possible values: +grey+, +green+, +turquoise+, +blue+, +red+, +purple+, +pink+, +orange+, +yellow+. Defaults to +nil+
57
- # +:default_start_button_as_button+ false
58
- # +:default_summary_list_borders+ true
59
- # +:default_notification_banner_title_id+ "govuk-notification-banner-title"
60
- # +:default_notification_disable_auto_focus+ nil
61
- # +:default_notification_title_heading_level+ 2
62
- # +:default_notification_title_success+ false
63
- # +:default_warning_text_icon_fallback_text+ "Warning"
64
- # +:default_warning_text_icon+ "!"
65
- #
66
- # +:require_summary_list_action_visually_hidden_text+ when true forces visually hidden text to be set for every action. It can still be explicitly skipped by passing in +nil+. Defaults to +false+
67
- DEFAULTS = {
68
- default_back_link_text: 'Back',
69
- default_breadcrumbs_collapse_on_mobile: false,
70
- default_breadcrumbs_hide_in_print: false,
71
- default_cookie_banner_aria_label: "Cookie banner",
72
- default_cookie_banner_hide_in_print: true,
73
- default_header_navigation_label: 'Navigation menu',
74
- default_header_menu_button_label: 'Show or hide navigation menu',
75
- default_header_logotype: 'GOV.UK',
76
- default_header_homepage_url: '/',
77
- default_header_service_name: nil,
78
- default_header_service_url: '/',
79
- default_footer_meta_text: nil,
80
- default_footer_copyright_text: '© Crown copyright',
81
- default_footer_copyright_url: "https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/",
82
- default_pagination_landmark_label: "results",
83
- default_pagination_next_text: %w(Next page),
84
- default_pagination_previous_text: %w(Previous page),
85
- default_phase_banner_tag: nil,
86
- default_phase_banner_text: nil,
87
- default_section_break_visible: false,
88
- default_section_break_size: nil,
89
- default_tag_colour: nil,
90
- default_start_button_as_button: false,
91
- default_summary_list_borders: true,
92
- default_notification_banner_title_id: "govuk-notification-banner-title",
93
- default_notification_disable_auto_focus: nil,
94
- default_notification_title_heading_level: 2,
95
- default_notification_title_success: false,
96
- default_warning_text_icon_fallback_text: "Warning",
97
- default_warning_text_icon: "!",
98
-
99
- require_summary_list_action_visually_hidden_text: false,
100
- }.freeze
101
-
102
- DEFAULTS.each_key { |k| config_accessor(k) { DEFAULTS[k] } }
103
-
104
5
  class Engine < ::Rails::Engine
105
6
  isolate_namespace Dsfr::Components
106
7
  end
@@ -1,5 +1,5 @@
1
1
  module Dsfr
2
2
  module Components
3
- VERSION = '5.0.0.pre'.freeze
3
+ VERSION = '5.0.1'.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.1
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