Skip to content

Commit afaff05

Browse files
authored
Merge pull request #1128 from dnum-mi/feat/#1126-dsfr-collout-accent
Ajoute l'accentuation au DsfrCallout
2 parents d2fcba3 + 113ef1c commit afaff05

File tree

5 files changed

+103
-8
lines changed

5 files changed

+103
-8
lines changed
Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import { render } from '@testing-library/vue'
2+
import { describe, expect, it } from 'vitest'
23

34
import VIcon from '../VIcon/VIcon.vue'
45

5-
// import '@gouvfr/dsfr/dist/core/core.module.js'
6-
76
import DsfrCallout from './DsfrCallout.vue'
87

98
describe('DsfrCallout', () => {
10-
it('should display a callout without a button', () => {
9+
it('should display a callout', () => {
1110
const title = 'Titre de la mise en avant'
1211
const content = 'Lorem ipsum dolor sit amet, consectetur adipiscing, incididunt, ut labore et dol'
12+
const accent = 'orange-terre-battue'
13+
const icon = 'fr-icon-alarm-warning-line'
14+
const button = { label: 'label bouton' }
1315

14-
const { getByText } = render(DsfrCallout, {
16+
const { getByText, container } = render(DsfrCallout, {
1517
global: {
1618
components: {
1719
VIcon,
@@ -20,13 +22,21 @@ describe('DsfrCallout', () => {
2022
props: {
2123
title,
2224
content,
25+
accent,
26+
icon,
27+
button,
2328
},
2429
})
2530

31+
const calloutEl = container.querySelector('.fr-callout')
2632
const titleEl = getByText(title)
2733
const contentEl = getByText(content)
34+
const buttonEl = container.querySelector('.fr-btn')
2835

29-
expect(titleEl).toHaveClass('fr-callout__title')
30-
expect(contentEl).toHaveClass('fr-callout__text')
36+
expect(calloutEl?.className).toContain(`fr-callout--${accent}`)
37+
expect(calloutEl?.className).toContain(icon)
38+
expect(titleEl.className).toContain('fr-callout__title')
39+
expect(contentEl.className).toContain('fr-callout__text')
40+
expect(buttonEl?.innerHTML).toContain(button.label)
3141
})
3242
})

src/components/DsfrCallout/DsfrCallout.stories.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ const meta: Meta<typeof DsfrCallout> = {
3030
description:
3131
'Permet de passer l’icône désirée en chaîne de caractères (cf. remix-icon)',
3232
},
33+
accent: {
34+
control: 'text',
35+
description:
36+
'Permet de passer la couleur d‘accentuation',
37+
},
3338
button: {
3439
control: 'object',
3540
description:
@@ -163,3 +168,40 @@ MiseEnAvantSansTitre.args = {
163168
'Lorem ipsum dolor sit amet, consectetur adipiscing, incididunt, ut labore et dol',
164169
titleTag: undefined,
165170
}
171+
172+
export const MiseEnAvantAvecAccentuation = (args) => ({
173+
components: {
174+
DsfrCallout,
175+
VIcon,
176+
},
177+
178+
data () {
179+
return {
180+
...args,
181+
button: args.button && {
182+
...args.button,
183+
onClick: args.onClick,
184+
},
185+
}
186+
},
187+
188+
template: `
189+
<DsfrCallout
190+
:title
191+
:content
192+
:button
193+
:icon
194+
:title-tag
195+
:accent
196+
/>
197+
`,
198+
})
199+
MiseEnAvantAvecAccentuation.args = {
200+
title: 'Titre de la mise en avant',
201+
button: undefined,
202+
icon: '',
203+
content:
204+
'Lorem ipsum dolor sit amet, consectetur adipiscing, incididunt, ut labore et dol',
205+
titleTag: undefined,
206+
accent: 'orange-terre-battue',
207+
}
Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,39 @@
1+
import type { TitleTag } from '../../common-types'
12
import type { DsfrButtonProps } from '../DsfrButton/DsfrButton.types'
23
import type { VIconProps } from '../VIcon/VIcon.vue'
34

5+
/**
6+
* Type union des accents de couleur DSFR utilisable dans DsfrCallout.
7+
* Représente les noms des thèmes de couleur (avant "-main")
8+
*/
9+
export type DsfrColorAccent =
10+
| 'blue-france'
11+
| 'red-marianne'
12+
| 'info'
13+
| 'success'
14+
| 'warning'
15+
| 'error'
16+
| 'green-tilleul-verveine'
17+
| 'green-bourgeon'
18+
| 'green-emeraude'
19+
| 'green-menthe'
20+
| 'green-archipel'
21+
| 'blue-ecume'
22+
| 'blue-cumulus'
23+
| 'purple-glycine'
24+
| 'pink-macaron'
25+
| 'pink-tuile'
26+
| 'yellow-tournesol'
27+
| 'yellow-moutarde'
28+
| 'orange-terre-battue'
29+
| 'brown-cafe-creme'
30+
| 'brown-caramel'
31+
432
export type DsfrCalloutProps = {
533
title?: string
634
content?: string
7-
titleTag?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'
35+
titleTag?: TitleTag
836
button?: DsfrButtonProps
937
icon?: string | VIconProps
38+
accent?: DsfrColorAccent
1039
}

src/components/DsfrCallout/DsfrCallout.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const props = withDefaults(defineProps<DsfrCalloutProps>(), {
1313
button: () => undefined,
1414
titleTag: 'h3',
1515
icon: undefined,
16+
accent: undefined,
1617
})
1718
1819
const dsfrIcon = computed(() => typeof props.icon === 'string' && props.icon.startsWith('fr-icon-'))
@@ -22,7 +23,7 @@ const iconProps = computed(() => dsfrIcon.value ? undefined : typeof props.icon
2223
<template>
2324
<div
2425
class="fr-callout"
25-
:class="{ [String(icon)]: dsfrIcon }"
26+
:class="{ [String(icon)]: dsfrIcon, [`fr-callout--${accent}`]: !!accent }"
2627
>
2728
<VIcon
2829
v-if="icon && iconProps"

src/components/DsfrCallout/docs-demo/DsfrCalloutDemo.vue

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ const icon = 'ri:notification-3-line'
1212
const content = 'Lorem ipsum dolor sit amet, consectetur adipiscing, incididunt, ut labore et dol'
1313
const titleTag = undefined
1414
15+
const accent = 'orange-terre-battue'
16+
const accentTitle = 'Titre de la mise en avant accentué'
17+
const accentIcon = 'fr-icon-alarm-warning-line'
18+
const accentContent = 'Accentuation à partir des couleurs du Dsfr (ex orange-terre-battue)'
19+
1520
const animateTitle = 'Titre de la mise en avant stylée'
1621
const animatedIcon: VIconProps = { name: 'bi:bell', animation: 'ring' }
1722
const animatedtitleTag = 'h4'
@@ -35,6 +40,14 @@ const getRandomAnimation = () => getRandomEl<(typeof possibleAnimations)[number]
3540
:icon="icon"
3641
:title-tag="titleTag"
3742
/>
43+
<DsfrCallout
44+
:title="`${accentTitle} (${accentTitleTag ?? 'h3'})`"
45+
:content="accentContent"
46+
:button="button"
47+
:icon="accentIcon"
48+
:title-tag="titleTag"
49+
:accent="accent"
50+
/>
3851
<DsfrCallout
3952
:title="`${animateTitle} (${animatedtitleTag ?? 'h3'})`"
4053
:button="button"

0 commit comments

Comments
 (0)