-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #205 from betagouv/feat/highlight-component
Feat/highlight component
- Loading branch information
Showing
8 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module DsfrComponent | ||
class HighlightComponent < DsfrComponent::Base | ||
# @param text [String] Le contenu textuel du composant | ||
# @param size [Symbol] La taille de la mise en exergue | ||
def initialize(text:, size: :md, classes: [], html_attributes: {}) | ||
@text = text | ||
@size = size | ||
|
||
raise ArgumentError if not SIZES.include?(size) | ||
|
||
super(classes: classes, html_attributes: html_attributes) | ||
end | ||
|
||
def call | ||
tag.div(**html_attributes) do | ||
tag.p(class: "fr-text--#{@size}") do | ||
@text | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :text, :size | ||
|
||
def default_attributes | ||
{ class: 'fr-highlight' } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
title: Mise en exergue - Highlight | ||
--- | ||
|
||
.fr-text-wrap | ||
:markdown | ||
|
||
La mise en exergue permet à l'utilisateur de distinguer et repérer une information facilement. Elle met en évidence **une information déjà présente** dans le reste du contenu : soit une reformulation, soit une reprise du texte. | ||
|
||
Pour mettre en évidence une information complémentaire, utilisez le composant "Mise en avant". | ||
|
||
La taille du texte peut être adaptée avec le paramètre `size: :sm[/md/lg]`. | ||
|
||
= render('/partials/example.haml', caption: "Vue d'ensemble", code: highlight_default) do | ||
:markdown | ||
Le rendu de base de la mise en exergue | ||
|
||
= render('/partials/example.haml', caption: "Avec du texte élargi", code: highlight_larger) do | ||
:markdown | ||
Rendu avec une taille de texte élargie | ||
|
||
= render('/partials/related-info.haml', links: dsfr_component_doc_link("Le composant Mise en exergue/Highlight", "mise-en-exergue")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Examples | ||
module HighlightHelpers | ||
def highlight_default | ||
<<~RAW | ||
= dsfr_highlight(text: "Ceci est une information mise en avant") | ||
RAW | ||
end | ||
|
||
def highlight_larger | ||
<<~RAW | ||
= dsfr_highlight(text: "Ceci est une information mise en avant, avec un texte plus large", size: :lg) | ||
RAW | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
spec/components/dsfr_component/highlight_component_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe(DsfrComponent::HighlightComponent, type: :component) do | ||
context "when an unknown size is passed" do | ||
it "raises an error" do | ||
expect { render_inline(described_class.new(text: "foo", size: :xz)) }.to raise_error ArgumentError | ||
end | ||
end | ||
|
||
it "generates the right markup" do | ||
render_inline(described_class.new(text: "foo")) | ||
|
||
expect(rendered_content).to have_tag(:div, with: { class: "fr-highlight" }) do | ||
with_tag(:p, with: { class: "fr-text--md" }) do | ||
"foo" | ||
end | ||
end | ||
end | ||
|
||
context "when a different size is specified" do | ||
it "produces the corresponding markup" do | ||
render_inline(described_class.new(text: "foo", size: :lg)) | ||
|
||
expect(rendered_content).to have_tag(:p, with: { class: "fr-text--lg" }) | ||
end | ||
end | ||
end |