Skip to content

Commit e1e534e

Browse files
committed
feat: ✨ Nouvelle implémentation du composant DsfrTile
BREAKING CHANGE: Les props 'verticalAtMd' et 'verticalAtLg' n'existent plus
1 parent 93ba531 commit e1e534e

File tree

4 files changed

+126
-57
lines changed

4 files changed

+126
-57
lines changed

src/components/DsfrTile/DsfrTile.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,28 @@ describe('DsfrTile', () => {
6868
expect(titleEl.parentNode.parentNode.parentNode.parentNode).toHaveClass('fr-tile--horizontal')
6969
expect(descriptionEl).toHaveClass('fr-tile__desc')
7070
})
71+
72+
it('should display a tile with a download link', async () => {
73+
const title = 'Titre de la tuile'
74+
const imgSrc = 'https://placekitten.com/80/80'
75+
const description = 'Lorem ipsum dolor sit amet, consectetur adipiscing, incididunt, ut labore et dol'
76+
const download = true
77+
const { getByText } = render(DsfrTile, {
78+
global: {
79+
plugins: [router],
80+
},
81+
props: {
82+
title,
83+
imgSrc,
84+
description,
85+
download,
86+
to: 'https://placekitten.com/80/80',
87+
},
88+
})
89+
90+
await router.isReady()
91+
92+
const titleEl = getByText(title)
93+
expect(titleEl).toHaveAttribute('download', 'true')
94+
})
7195
})

src/components/DsfrTile/DsfrTile.stories.ts

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,49 +27,52 @@ export default {
2727
control: 'boolean',
2828
description: 'Permet le basculement de la tuile en mode horizontal',
2929
},
30-
verticalAtMd: {
31-
control: 'boolean',
32-
description: 'Permet le basculement de la tuile en mode vertical au point de rupture "md"',
30+
vertical: {
31+
options: ['md', 'lg'],
32+
control: {
33+
type: 'select',
34+
},
35+
description: 'Permet le basculement de la tuile en mode vertical, selon le point de rupture "md" ou "lg" spécifié',
3336
},
34-
verticalAtLg: {
37+
disabled: {
3538
control: 'boolean',
36-
description: 'Permet le basculement de la tuile en mode vertical au point de rupture "lg"',
39+
description: 'Permet de rendre la tuile désactivée et non-cliquable',
3740
},
38-
small: {
41+
to: {
42+
control: 'text',
43+
description: 'Lien vers lequel la tuile pointe. Peut être une string ou objet à donner à `RouterLink` ou un lien externe (`string` commençant par `"http"`)',
44+
},
45+
titleTag: {
46+
control: 'text',
47+
description: 'Permet de choisir la balise contenant le titre de la tuile (h3 par défaut)',
48+
},
49+
download: {
3950
control: 'boolean',
40-
description: 'Permet d’afficher la tuile dans un plus petit format',
51+
description: 'Permet de passer la tuile en mode téléchargement',
4152
},
42-
disabled: {
53+
small: {
4354
control: 'boolean',
44-
description: 'Permet de rendre la tuile désactivée et non-cliquable',
55+
description: 'Permet de basculer la tuile en petit format',
4556
},
46-
download: {
57+
icon: {
4758
control: 'boolean',
48-
description: 'Variante de tuile indiquant que le lien permet de télécharger un fichier (la tuile de téléchargement est obligatoirement horizontale)',
59+
description: 'Permet de désactiver l\'icone associée au lien',
4960
},
5061
noBorder: {
5162
control: 'boolean',
52-
description: 'Variante de tuile sans bordure',
63+
description: 'Permet de désactiver la bordure de la tuile',
5364
},
54-
noBackground: {
65+
shadow: {
5566
control: 'boolean',
56-
description: 'Variante de tuile sans arrière-plan',
67+
description: 'Permet d\'ajouter une ombre portée à la tuile',
5768
},
58-
shadow: {
69+
noBackground: {
5970
control: 'boolean',
60-
description: 'Variante de tuile avec ombre portée',
71+
description: 'Permet de désactiver la couleur de fond de la tuile',
6172
},
6273
grey: {
6374
control: 'boolean',
64-
description: 'Variante de tuile plus contrastée avec arrière-plan grisé',
65-
},
66-
to: {
67-
control: 'text',
68-
description: 'Lien vers lequel la tuile pointe. Peut être une string ou objet à donner à `RouterLink` ou un lien externe (`string` commençant par `"http"`)',
69-
},
70-
titleTag: {
71-
control: 'text',
72-
description: 'Permet de choisir la balise contenant le titre de la tuile (h3 par défaut)',
75+
description: 'Permet de passer le fond de la tuile en gris',
7376
},
7477
},
7578
}
@@ -92,36 +95,34 @@ export const TuileSimple = (args) => ({
9295
:description="description"
9396
:details="details"
9497
:horizontal="horizontal"
95-
:verticalAtMd="verticalAtMd"
96-
:verticalAtLg="verticalAtLg"
97-
:small="small"
98+
:vertical="vertical"
9899
:disabled="false"
100+
:to="to"
101+
:title-tag="titleTag"
99102
:download="download"
100-
:noBorder="noBorder"
101-
:noBackground="noBackground"
103+
:small="small"
104+
:icon="icon"
105+
:no-border="noBorder"
102106
:shadow="shadow"
107+
:no-background="noBackground"
103108
:grey="grey"
104-
:to="to"
105-
:title-tag="titleTag"
106109
/>
107110
`,
108111

109112
})
110113
TuileSimple.args = {
111114
title: 'Ma formidable tuile',
112-
imgSrc: 'http://placekitten.com/g/80/80',
115+
imgSrc: 'http://placekitten.com/g/200/200',
113116
description: 'Une tuile absolument formidable',
114-
details: 'Quelques détails',
115117
horizontal: false,
116-
verticalAtMd: false,
117-
verticalAtLg: false,
118-
small: false,
119118
disabled: false,
119+
to: '#',
120+
titleTag: 'h2',
120121
download: false,
122+
small: false,
123+
icon: false,
121124
noBorder: false,
122-
noBackground: false,
123125
shadow: false,
126+
noBackground: false,
124127
grey: false,
125-
to: '#',
126-
titleTag: 'h2',
127128
}

src/components/DsfrTile/DsfrTile.vue

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,28 @@ export type DsfrTileProps = {
99
details?: string
1010
disabled?: boolean
1111
horizontal?: boolean
12-
verticalAtMd?: boolean
13-
verticalAtLg?: boolean
14-
small?: boolean
12+
vertical?: 'md' | 'lg'
13+
to?: RouteLocationRaw,
14+
titleTag?: string
1515
download?: boolean
16+
small?: boolean
17+
icon?: boolean
1618
noBorder?: boolean
17-
noBackground?: boolean
1819
shadow?: boolean
20+
noBackground?: boolean
1921
grey?: boolean
20-
to?: RouteLocationRaw
21-
titleTag?: string
2222
}
2323
2424
const props = withDefaults(defineProps<DsfrTileProps>(), {
2525
title: 'Titre de la tuile',
2626
imgSrc: undefined,
2727
description: undefined,
2828
details: undefined,
29+
horizontal: false,
30+
vertical: undefined,
2931
to: '#',
3032
titleTag: 'h3',
33+
icon: true,
3134
})
3235
3336
const isExternalLink = computed(() => {
@@ -38,19 +41,20 @@ const isExternalLink = computed(() => {
3841
<template>
3942
<div
4043
class="fr-tile fr-enlarge-link"
41-
:class="{
42-
'fr-tile--vertical@md': verticalAtMd,
43-
'fr-tile--vertical@lg': verticalAtLg,
44-
'fr-tile--horizontal': horizontal,
44+
:class="[{
4545
'fr-tile--disabled': disabled,
46-
'fr-tile--sm': small,
47-
'fr-tile--no-icon': !imgSrc,
46+
'fr-tile--sm': small === true,
47+
'fr-tile--horizontal': horizontal === true,
48+
'fr-tile--vertical': horizontal === false || vertical === 'md' || vertical === 'lg',
49+
'fr-tile--vertical@md': vertical === 'md',
50+
'fr-tile--vertical@lg': vertical === 'lg',
4851
'fr-tile--download': download,
52+
'fr-tile--no-icon': icon === false,
4953
'fr-tile--no-border': noBorder,
5054
'fr-tile--no-background': noBackground,
5155
'fr-tile--shadow': shadow,
5256
'fr-tile--grey': grey,
53-
}"
57+
},]"
5458
>
5559
<div class="fr-tile__body">
5660
<div class="fr-tile__content">
@@ -60,13 +64,15 @@ const isExternalLink = computed(() => {
6064
>
6165
<a
6266
v-if="isExternalLink"
67+
class="fr-tile__link"
6368
target="_blank"
69+
:download="download"
6470
:href="disabled ? '' : (to as string)"
65-
>
66-
{{ title }}
67-
</a>
71+
>{{ title }}</a>
6872
<RouterLink
6973
v-if="!isExternalLink"
74+
:download="download"
75+
class="fr-tile__link so-test"
7076
:to="disabled ? '' : to"
7177
>
7278
{{ title }}
@@ -93,8 +99,8 @@ const isExternalLink = computed(() => {
9399
>
94100
<img
95101
:src="imgSrc"
96-
alt=""
97102
class="fr-artwork"
103+
alt=""
98104
>
99105
<!-- L'alternative de l'image (attribut alt) doit à priori rester vide car l'image est illustrative et ne doit pas être restituée aux technologies d’assistance. Vous pouvez toutefois remplir l'alternative si vous estimer qu'elle apporte une information essentielle à la compréhension du contenu non présente dans le texte -->
100106
</div>

src/components/DsfrTile/DsfrTiles.spec.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,42 @@ describe('DsfrTiles', () => {
150150
expect(titleEl1.parentNode.parentNode.parentNode.parentNode).toHaveClass('fr-tile--disabled')
151151
expect(titleEl2.parentNode.parentNode.parentNode.parentNode).not.toHaveClass('fr-tile--disabled')
152152
})
153+
154+
it('should display a tile with a download link and one without', async () => {
155+
const title1 = 'Titre de la tuile 1'
156+
const title2 = 'Titre de la tuile 2'
157+
const imgSrc = 'https://placekitten.com/80/80'
158+
159+
const tiles = [
160+
{
161+
title: title1,
162+
imgSrc,
163+
disabled: true,
164+
to: '/one',
165+
download: true,
166+
},
167+
{
168+
title: title2,
169+
imgSrc,
170+
to: '/two',
171+
download: false,
172+
},
173+
]
174+
175+
const { getByText } = render(DsfrTiles, {
176+
global: {
177+
plugins: [router],
178+
},
179+
props: {
180+
tiles,
181+
},
182+
})
183+
184+
await router.isReady()
185+
186+
const titleEl1 = getByText(title1)
187+
const titleEl2 = getByText(title2)
188+
expect(titleEl1).toHaveAttribute('download', 'true')
189+
expect(titleEl2).toHaveAttribute('download', 'false')
190+
})
153191
})

0 commit comments

Comments
 (0)