Skip to content

Commit b42503a

Browse files
authored
Merge pull request #522 from cailliaud/develop
feat: ✨ Ajoute l'icône optionnelle au DsfrNavigationMenuLink
2 parents eb318ca + f91e8ad commit b42503a

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

src/components/DsfrNavigation/DsfrNavigationMenuLink.spec.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ const router = createRouter({
1515
})
1616

1717
describe('DsfrNavigationMenuLink', () => {
18-
it('should render a navigation menu link (internal)', async () => {
18+
it('should render a navigation menu link (internal) with icon', async () => {
1919
const to = '/'
2020
const text = 'Texte du lien'
21+
const icon = 'ri-home-2-line'
2122

2223
const { getByTestId } = render(DsfrNavigationMenuLink, {
2324
global: {
@@ -29,13 +30,37 @@ describe('DsfrNavigationMenuLink', () => {
2930
props: {
3031
to,
3132
text,
33+
icon,
3234
},
3335
})
3436

3537
await router.isReady()
3638

3739
const link = getByTestId('nav-router-link')
38-
expect(link.innerHTML).toBe(text)
40+
expect(link.innerHTML).toBe('<svg class="ov-icon" style="font-size: 1.2em;" aria-hidden="true" width="0" height="0" viewBox="0 0 0 0" fill="currentColor"></svg> ' + text)
41+
expect(link).toHaveAttribute('href', to)
42+
})
43+
it('should render a navigation menu link (internal) without icon', async () => {
44+
const to = '/'
45+
const text = 'Texte du lien'
46+
47+
const { getByTestId } = render(DsfrNavigationMenuLink, {
48+
global: {
49+
plugins: [router],
50+
components: {
51+
VIcon,
52+
},
53+
},
54+
props: {
55+
to,
56+
text,
57+
},
58+
})
59+
60+
await router.isReady()
61+
62+
const link = getByTestId('nav-router-link')
63+
expect(link.innerHTML).toBe('<!--v-if--> ' + text)
3964
expect(link).toHaveAttribute('href', to)
4065
})
4166
})

src/components/DsfrNavigation/DsfrNavigationMenuLink.stories.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import DsfrNavigation from './DsfrNavigation.vue'
33

44
import { setup } from '@storybook/vue3'
55

6+
import { addIcons } from 'oh-vue-icons'
7+
import { RiHome2Line } from 'oh-vue-icons/icons/ri/index.js'
8+
9+
addIcons(RiHome2Line)
10+
611
const RouterLink = {
712
name: 'RouterLink',
813
props: {
@@ -33,6 +38,10 @@ export default {
3338
control: 'text',
3439
description: '(Optionnel) Valeur de l’attribut `id` de la balise `<a>` du lien de navigation. Aura une valeur pseudo-aléatoire par défaut',
3540
},
41+
icon: {
42+
control: 'text',
43+
description: '(Optionnel) **Nom de l’icône** (tel que sur le site [RemixIcon](https://remixicon.com), exemple: `"ri-search-line"`) à afficher à côté du texte du bouton.\n\n Par défaut, l’icône est à gauche',
44+
},
3645
'toggle-id': {
3746
description: 'Événement émis lors du click sur le lien, avec en argument l’id de l’élément cliqué',
3847
},
@@ -54,14 +63,15 @@ export const NavigationLienMenu = (args) => ({
5463
<DsfrNavigationMenuLink
5564
:to="to"
5665
:text="text"
66+
:icon="icon"
5767
@click.prevent.stop=""
5868
/>
5969
</DsfrNavigation>
6070
`,
6171

62-
6372
})
6473
NavigationLienMenu.args = {
6574
to: '#test-navigation-menu-link',
6675
text: 'Lien de menu',
76+
icon: 'ri-home-2-line',
6777
}

src/components/DsfrNavigation/DsfrNavigationMenuLink.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
<script>
22
import { defineComponent } from 'vue'
3+
import { OhVueIcon as VIcon } from 'oh-vue-icons'
34
import { getRandomId } from '../../utils/random-utils.js'
45
56
export default defineComponent({
67
name: 'DsfrNavigationMenuLink',
78
9+
components: {
10+
VIcon,
11+
},
12+
813
props: {
914
id: {
1015
type: String,
@@ -18,6 +23,11 @@ export default defineComponent({
1823
type: String,
1924
required: true,
2025
},
26+
icon: {
27+
type: String,
28+
required: false,
29+
default: undefined,
30+
},
2131
},
2232
2333
emits: ['toggle-id'],
@@ -47,6 +57,10 @@ export default defineComponent({
4757
:to="to"
4858
@click="$emit('toggle-id', id)"
4959
>
60+
<VIcon
61+
v-if="icon"
62+
:name="icon"
63+
/>
5064
{{ text }}
5165
</RouterLink>
5266
</template>

0 commit comments

Comments
 (0)