@@ -15,6 +15,8 @@ import {
15
15
import { cloneElement , useState } from 'react' ;
16
16
import { flushSync } from 'react-dom' ;
17
17
18
+ import { Icon } from '@/ui' ;
19
+ import classNames from 'classnames' ;
18
20
import { OpenState } from '../../utils/types' ;
19
21
import { Button } from './Button' ;
20
22
import { ButtonProps } from './types' ;
@@ -24,10 +26,14 @@ export type ButtonMenuProps = {
24
26
children : React . ReactNode ;
25
27
/** Placement du menu pour l'élément floating-ui */
26
28
menuPlacement ?: Placement ;
29
+ /** Classe CSS à appliquer au container du menu */
30
+ menuContainerClassName ?: string ;
27
31
/** Rend le composant controllable */
28
32
openState ?: OpenState ;
29
33
/** Permet de donner un text au bouton d'ouverture car children est déjà utilisé pour le contenu du menu */
30
34
text ?: string ;
35
+ /** Affiche une flèche signalant l'ouverture du menu */
36
+ withArrow ?: boolean ;
31
37
} & ButtonProps ;
32
38
33
39
/**
@@ -40,6 +46,8 @@ export const ButtonMenu = ({
40
46
openState,
41
47
children,
42
48
text,
49
+ withArrow,
50
+ menuContainerClassName,
43
51
...props
44
52
} : ButtonMenuProps ) => {
45
53
const isControlled = ! ! openState ;
@@ -90,7 +98,25 @@ export const ButtonMenu = ({
90
98
return (
91
99
< >
92
100
{ cloneElement (
93
- < Button { ...props } children = { text } /> ,
101
+ < Button
102
+ { ...props }
103
+ children = {
104
+ text || withArrow ? (
105
+ < >
106
+ { text && < span className = "line-clamp-1" > { text } </ span > }
107
+ { withArrow && (
108
+ < Icon
109
+ icon = "arrow-down-s-line"
110
+ size = "sm"
111
+ className = { classNames ( 'ml-2 transition-all' , {
112
+ 'rotate-180' : isOpen ,
113
+ } ) }
114
+ />
115
+ ) }
116
+ </ >
117
+ ) : undefined
118
+ }
119
+ /> ,
94
120
getReferenceProps ( {
95
121
ref : refs . setReference ,
96
122
} )
@@ -107,8 +133,10 @@ export const ButtonMenu = ({
107
133
left : x ,
108
134
maxHeight : maxHeight - 16 ,
109
135
} ,
110
- className :
136
+ className : classNames (
111
137
'relative z-[1] overflow-y-auto bg-white rounded-b-lg border border-grey-4 rounded-lg shadow-card' ,
138
+ menuContainerClassName
139
+ ) ,
112
140
} ) }
113
141
>
114
142
{ children }
0 commit comments