dsfr-view-components 0.2.1 → 0.3.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 +4 -4
- data/README.md +2 -2
- data/app/components/dsfr_component/tabs_component/tab_component.rb +58 -0
- data/app/components/dsfr_component/tabs_component.html.erb +12 -0
- data/app/components/dsfr_component/tabs_component.rb +19 -0
- data/app/helpers/dsfr_components_helper.rb +1 -0
- data/lib/dsfr/components/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e93e6bf0c8951900e6b030e6e0f25b59cf5adda2d357522f150cf2c2700d22b7
|
4
|
+
data.tar.gz: e445fe61031ec9e52a2d1abb82240293825e988995fdf72eba461d88b23aeed8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ce58d44d3ada31a6f9381017fc6da31a1dad95e8d14128f2e30a91dba279a63c19dfdbcb992807f422f5e3536d13d4b5198537cd313414eb8427fdea7af04db
|
7
|
+
data.tar.gz: 2baad7dedd1acb5e512f8056f819d586937e9d49c360b4c4aa3e162f122dd2c0d17eba1217db9f05cb6403987f3bf702b089efbc57b37bc7378d5de20fe312f7
|
data/README.md
CHANGED
@@ -42,7 +42,7 @@ require "dsfr/components"
|
|
42
42
|
|
43
43
|
Cette gem a pour but de supporter tous les composants proposés par le Design Système de l'État hormis ceux concernant les formulaires. Ceux-ci seront fournis dans une gem indépendante dans le futur.
|
44
44
|
|
45
|
-
|
45
|
+
11/36 composants sont disponibles :
|
46
46
|
|
47
47
|
- [x] Accordéon - Accordion
|
48
48
|
- [x] Alertes - Alert
|
@@ -69,7 +69,7 @@ Cette gem a pour but de supporter tous les composants proposés par le Design Sy
|
|
69
69
|
- [ ] Mise en exergue - Highlight
|
70
70
|
- [x] Modale - Modal
|
71
71
|
- [ ] Navigation principale - Main navigation
|
72
|
-
- [
|
72
|
+
- [x] Onglets - Tabs
|
73
73
|
- [ ] Pagination
|
74
74
|
- [ ] Paramètres d'affichage - Display
|
75
75
|
- [ ] Partage - Share
|
@@ -0,0 +1,58 @@
|
|
1
|
+
class DsfrComponent::TabsComponent::TabComponent < DsfrComponent::Base
|
2
|
+
# @param title [String] Le titre de l’onglet affiché dans la barre d’onglets
|
3
|
+
# @param active [Boolean] Définit si l’onglet est actif ou non
|
4
|
+
# @param path [String] (optionnel) chemin vers lequel l’onglet pointe, utilisable avec Turbo Drive, transforme le bouton en lien, avec une turbo action `advance`
|
5
|
+
# @param icon [String] (optionnel) icône affichée à gauche du titre de l’onglet (sans le préfixe `fr-icon-`)
|
6
|
+
def initialize(title:, active: false, path: nil, icon: nil, classes: [], html_attributes: {})
|
7
|
+
@title = title
|
8
|
+
@active = active
|
9
|
+
@path = path
|
10
|
+
@icon = icon
|
11
|
+
|
12
|
+
super(classes: classes, html_attributes: html_attributes)
|
13
|
+
end
|
14
|
+
|
15
|
+
def nav_id
|
16
|
+
@nav_id ||= "tab-#{title_slug}-nav"
|
17
|
+
end
|
18
|
+
|
19
|
+
def panel_id
|
20
|
+
@panel_id ||= "tab-#{title_slug}-panel"
|
21
|
+
end
|
22
|
+
|
23
|
+
def nav_item
|
24
|
+
path ? nav_link : nav_button
|
25
|
+
end
|
26
|
+
|
27
|
+
def call
|
28
|
+
tag.div(**html_attributes) { content }
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
attr_reader :title, :active, :path, :icon
|
34
|
+
|
35
|
+
def default_attributes
|
36
|
+
classes = ['fr-tabs__panel']
|
37
|
+
classes << "fr-tabs__panel--selected" if active
|
38
|
+
{ id: panel_id, class: classes, role: 'tabpanel', "aria-labelledby": nav_id }
|
39
|
+
end
|
40
|
+
|
41
|
+
def title_slug
|
42
|
+
@title_slug ||= title.parameterize
|
43
|
+
end
|
44
|
+
|
45
|
+
def nav_button
|
46
|
+
tag.button(title, **nav_html_attributes)
|
47
|
+
end
|
48
|
+
|
49
|
+
def nav_link
|
50
|
+
tag.a(title, href: path, data: { turbo_action: "advance" }, **nav_html_attributes)
|
51
|
+
end
|
52
|
+
|
53
|
+
def nav_html_attributes
|
54
|
+
classes = ["fr-tabs__tab"]
|
55
|
+
classes += ["fr-icon-#{icon}", "fr-tabs__tab--icon-left"] if icon.present?
|
56
|
+
{ id: nav_id, class: classes, role: 'tab', "aria-selected": active ? "true" : "false", "aria-controls": panel_id }
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<%= tag.div(**html_attributes) do %>
|
2
|
+
<ul class="fr-tabs__list" role="tablist" aria-label="<%= label %>">
|
3
|
+
<% tabs.each do |tab| %>
|
4
|
+
<li role="presentation">
|
5
|
+
<%= tab.nav_item %>
|
6
|
+
</li>
|
7
|
+
<% end %>
|
8
|
+
</ul>
|
9
|
+
<% tabs.each do |tab| %>
|
10
|
+
<%= tab %>
|
11
|
+
<% end %>
|
12
|
+
<% end %>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class DsfrComponent::TabsComponent < DsfrComponent::Base
|
2
|
+
renders_many :tabs, "DsfrComponent::TabsComponent::TabComponent"
|
3
|
+
|
4
|
+
# @param label [String] Le nom du système d’onglets, sera uniquement affiché comme aria-label (optionnel)
|
5
|
+
def initialize(label: nil, classes: [], html_attributes: {})
|
6
|
+
@label = label
|
7
|
+
@tabs = []
|
8
|
+
|
9
|
+
super(classes: classes, html_attributes: html_attributes)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
attr_reader :label
|
15
|
+
|
16
|
+
def default_attributes
|
17
|
+
{ class: 'fr-tabs' }
|
18
|
+
end
|
19
|
+
end
|
@@ -14,6 +14,7 @@ module DsfrComponentsHelper
|
|
14
14
|
dsfr_header_tool_link: 'DsfrComponent::HeaderComponent::ToolLinkComponent',
|
15
15
|
dsfr_header_direct_link: 'DsfrComponent::HeaderComponent::DirectLinkComponent',
|
16
16
|
dsfr_header_direct_dropdown_link: 'DsfrComponent::HeaderComponent::DirectLinkDropdownComponent',
|
17
|
+
dsfr_tabs: 'DsfrComponent::TabsComponent',
|
17
18
|
# DO NOT REMOVE: new component mapping here
|
18
19
|
}.freeze
|
19
20
|
HELPER_NAME_TO_CLASS_NAME.each do |name, klass|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dsfr-view-components
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- BetaGouv developers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -461,6 +461,9 @@ files:
|
|
461
461
|
- app/components/dsfr_component/modal_component.rb
|
462
462
|
- app/components/dsfr_component/stepper_component.html.erb
|
463
463
|
- app/components/dsfr_component/stepper_component.rb
|
464
|
+
- app/components/dsfr_component/tabs_component.html.erb
|
465
|
+
- app/components/dsfr_component/tabs_component.rb
|
466
|
+
- app/components/dsfr_component/tabs_component/tab_component.rb
|
464
467
|
- app/components/dsfr_component/tag_component.rb
|
465
468
|
- app/components/dsfr_component/tile_component.html.erb
|
466
469
|
- app/components/dsfr_component/tile_component.rb
|