Skip to content

Commit 771c645

Browse files
authored
Merge pull request #504 from clairenollet/feat/add-disabled-props-for-tiles
Feat/add disabled props for tiles
2 parents 9dad012 + 3e746c3 commit 771c645

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

src/components/DsfrTile/DsfrTile.stories.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export default {
2727
control: 'boolean',
2828
description: 'Permet le basculement de la tuile en mode horizontal',
2929
},
30+
disabled: {
31+
control: 'boolean',
32+
description: 'Permet de rendre la tuile désactivée et non-cliquable',
33+
},
3034
to: {
3135
control: 'text',
3236
description: 'Lien vers lequel la tuile pointe. Peut être une string ou objet à donner à `RouterLink` ou un lien externe (`string` commençant par `"http"`)',
@@ -55,6 +59,7 @@ export const TuileSimple = (args) => ({
5559
:imgSrc="imgSrc"
5660
:description="description"
5761
:horizontal="horizontal"
62+
:disabled="false"
5863
:to="to"
5964
:title-tag="titleTag"
6065
/>
@@ -70,6 +75,7 @@ TuileSimple.args = {
7075
imgSrc: 'http://placekitten.com/g/200/200',
7176
description: 'Une tuile absolument formidable',
7277
horizontal: false,
78+
disabled: false,
7379
to: '#',
7480
titleTag: 'h2',
7581
}

src/components/DsfrTile/DsfrTile.vue

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default defineComponent({
1818
type: String,
1919
default: undefined,
2020
},
21+
disabled: Boolean,
2122
horizontal: Boolean,
2223
to: {
2324
type: [String, Object],
@@ -40,7 +41,10 @@ export default defineComponent({
4041
<template>
4142
<div
4243
class="fr-tile fr-enlarge-link"
43-
:class="{ 'fr-tile--horizontal': horizontal }"
44+
:class="{
45+
'fr-tile--horizontal': horizontal,
46+
'fr-tile--disabled': disabled,
47+
}"
4448
>
4549
<div class="fr-tile__body">
4650
<component
@@ -51,12 +55,12 @@ export default defineComponent({
5155
v-if="isExternalLink"
5256
class="fr-tile__link"
5357
target="_blank"
54-
:href="to"
58+
:href="disabled ? '' : to"
5559
>{{ title }}</a>
5660
<RouterLink
5761
v-if="!isExternalLink"
5862
class="fr-tile__link so-test"
59-
:to="to"
63+
:to="disabled ? '' : to"
6064
>
6165
{{ title }}
6266
</RouterLink>
@@ -83,3 +87,12 @@ export default defineComponent({
8387
</template>
8488

8589
<style src="@gouvfr/dsfr/dist/component/tile/tile.main.min.css" />
90+
<style scoped>
91+
.fr-tile.fr-tile--disabled {
92+
background-color: var(--background-disabled-grey);
93+
box-shadow: inset 0 0 0 1px var(--border-default-grey), inset 0 -0.25rem 0 0 var(--border-disabled-grey);
94+
}
95+
.fr-tile.fr-tile--disabled a {
96+
cursor: not-allowed;
97+
}
98+
</style>

src/components/DsfrTile/DsfrTiles.spec.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,44 @@ describe('DsfrTiles', () => {
110110
expect(titleEl.parentNode.parentNode.parentNode).toHaveClass('fr-tile--horizontal')
111111
expect(descriptionEl).toHaveClass('fr-tile__desc')
112112
})
113+
it('should display 1 disabled and 1 enabled tile', async () => {
114+
const title1 = 'Titre de la tuile 1'
115+
const title2 = 'Titre de la tuile 2'
116+
const imgSrc1 = 'https://placekitten.com/80/81'
117+
const imgSrc2 = 'https://placekitten.com/80/82'
118+
const description1 = 'Description 1'
119+
const description2 = 'Description 2'
120+
121+
const tiles = [
122+
{
123+
title: title1,
124+
imgSrc: imgSrc1,
125+
description: description1,
126+
disabled: true,
127+
to: '/one',
128+
},
129+
{
130+
title: title2,
131+
imgSrc: imgSrc2,
132+
description: description2,
133+
to: '/two',
134+
},
135+
]
136+
137+
const { getByText } = render(DsfrTiles, {
138+
global: {
139+
plugins: [router],
140+
},
141+
props: {
142+
tiles,
143+
},
144+
})
145+
146+
await router.isReady()
147+
148+
const titleEl1 = getByText(title1)
149+
const titleEl2 = getByText(title2)
150+
expect(titleEl1.parentNode.parentNode.parentNode).toHaveClass('fr-tile--disabled')
151+
expect(titleEl2.parentNode.parentNode.parentNode).not.toHaveClass('fr-tile--disabled')
152+
})
113153
})

0 commit comments

Comments
 (0)