Skip to content

Commit b5347b7

Browse files
committed
feat(DsfrButton): ✨ permet d’ajouter des propriétés à l’icône
- permet notamment de changer la couleur ou d’animer l’icône (cf la documentation de oh-vue-icon)
1 parent 4f308b3 commit b5347b7

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

src/components/DsfrButton/DsfrButton.stories.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { OhVueIcon as VIcon, addIcons } from 'oh-vue-icons'
22

3-
import { RiCheckboxCircleLine, RiSearchLine } from 'oh-vue-icons/icons/ri/index.js'
3+
import { RiCheckboxCircleLine, RiLoader4Line, RiSearchLine } from 'oh-vue-icons/icons/ri/index.js'
44

55
import DsfrButton from './DsfrButton.vue'
66

7-
addIcons(RiCheckboxCircleLine, RiSearchLine)
7+
addIcons(RiCheckboxCircleLine, RiSearchLine, RiLoader4Line)
88

99
/**
1010
* [Voir quand l’utiliser sur la documentation du DSFR](https://www.systeme-de-design.gouv.fr/elements-d-interface/composants/bouton)
@@ -114,6 +114,35 @@ BoutonPrimaireAvecIcone.args = {
114114
size: undefined,
115115
}
116116

117+
export const BoutonPrimaireAvecIconeAnimee = (args) => ({
118+
components: { DsfrButton },
119+
data () {
120+
return {
121+
...args,
122+
}
123+
},
124+
template: `
125+
<DsfrButton
126+
:label="label"
127+
:disabled="disabled"
128+
:icon="icon"
129+
:size="size"
130+
:no-outline="noOutline"
131+
:icon-right="iconRight"
132+
@click="onClick"
133+
/>
134+
`,
135+
136+
})
137+
BoutonPrimaireAvecIconeAnimee.args = {
138+
label: 'Label bouton',
139+
disabled: false,
140+
icon: { name: 'ri-loader-4-line', animation: 'spin' },
141+
iconRight: true,
142+
noOutline: false,
143+
size: undefined,
144+
}
145+
117146
export const BoutonSecondaire = (args) => ({
118147
components: { DsfrButton },
119148
data () {

src/components/DsfrButton/DsfrButton.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts" setup>
22
import { type Ref, computed, ref } from 'vue'
33
import { OhVueIcon as VIcon } from 'oh-vue-icons'
4+
import { type CustomizeIconType } from 'oh-vue-icons'
45
56
// import '@gouvfr/dsfr/dist/component/button/button.module.js'
67
@@ -13,7 +14,7 @@ export type DsfrButtonProps = {
1314
iconOnly?: boolean
1415
noOutline?: boolean
1516
size?: 'sm' | 'small' | 'lg' | 'large' | 'md' | 'medium' | '' | undefined
16-
icon?: string
17+
icon?: string | CustomizeIconType
1718
onClick?: ($event: MouseEvent) => void
1819
}
1920
@@ -33,6 +34,8 @@ const focus = () => {
3334
btn.value?.focus()
3435
}
3536
defineExpose({ focus })
37+
38+
const iconProps = computed(() => typeof props.icon === 'string' ? { name: props.icon } : props.icon)
3639
</script>
3740

3841
<template>
@@ -57,7 +60,7 @@ defineExpose({ focus })
5760
>
5861
<VIcon
5962
v-if="icon"
60-
:name="icon"
63+
v-bind="iconProps"
6164
/>
6265
<span v-if="!iconOnly">
6366
{{ label }}

0 commit comments

Comments
 (0)