Skip to content

Commit 4cfd937

Browse files
cparthurfarnoux
authored andcommitted
DS ButtonMenu - possibilité d'affichage d'une flèche sur le bouton de trigger
1 parent ad35736 commit 4cfd937

File tree

2 files changed

+46
-9
lines changed

2 files changed

+46
-9
lines changed

packages/ui/src/design-system/Button/ButtonMenu.stories.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import {Meta, StoryObj} from '@storybook/nextjs';
1+
import { Meta, StoryObj } from '@storybook/nextjs';
22

3-
import {ButtonMenu} from './ButtonMenu';
4-
import {useState} from 'react';
3+
import { useState } from 'react';
4+
import { ButtonMenu } from './ButtonMenu';
55

66
const meta: Meta<typeof ButtonMenu> = {
77
component: ButtonMenu,
8-
argTypes: {},
98
args: {
109
icon: 'equalizer-fill',
1110
children: (
@@ -23,18 +22,18 @@ export default meta;
2322
type Story = StoryObj<typeof ButtonMenu>;
2423

2524
export const Default: Story = {
26-
render: args => {
25+
render: (args) => {
2726
return (
2827
<div className="flex gap-24 justify-between mb-52">
2928
<ButtonMenu {...args} menuPlacement="bottom-start" />
30-
<ButtonMenu {...args} notification={{number: 2}} />
29+
<ButtonMenu {...args} notification={{ number: 2 }} />
3130
</div>
3231
);
3332
},
3433
};
3534

3635
export const Controlled: Story = {
37-
render: args => {
36+
render: (args) => {
3837
const [isOpen, setIsOpen] = useState(false);
3938
return (
4039
<div className="mb-52">
@@ -50,3 +49,13 @@ export const Controlled: Story = {
5049
);
5150
},
5251
};
52+
53+
export const WithArrow: Story = {
54+
render: (args) => {
55+
return (
56+
// <div className="flex gap-24 justify-between mb-52">
57+
// </div>
58+
<ButtonMenu {...args} text="Button Menu" withArrow />
59+
);
60+
},
61+
};

packages/ui/src/design-system/Button/ButtonMenu.tsx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
import { cloneElement, useState } from 'react';
1616
import { flushSync } from 'react-dom';
1717

18+
import { Icon } from '@/ui';
19+
import classNames from 'classnames';
1820
import { OpenState } from '../../utils/types';
1921
import { Button } from './Button';
2022
import { ButtonProps } from './types';
@@ -24,10 +26,14 @@ export type ButtonMenuProps = {
2426
children: React.ReactNode;
2527
/** Placement du menu pour l'élément floating-ui */
2628
menuPlacement?: Placement;
29+
/** Classe CSS à appliquer au container du menu */
30+
menuContainerClassName?: string;
2731
/** Rend le composant controllable */
2832
openState?: OpenState;
2933
/** Permet de donner un text au bouton d'ouverture car children est déjà utilisé pour le contenu du menu */
3034
text?: string;
35+
/** Affiche une flèche signalant l'ouverture du menu */
36+
withArrow?: boolean;
3137
} & ButtonProps;
3238

3339
/**
@@ -40,6 +46,8 @@ export const ButtonMenu = ({
4046
openState,
4147
children,
4248
text,
49+
withArrow,
50+
menuContainerClassName,
4351
...props
4452
}: ButtonMenuProps) => {
4553
const isControlled = !!openState;
@@ -90,7 +98,25 @@ export const ButtonMenu = ({
9098
return (
9199
<>
92100
{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+
/>,
94120
getReferenceProps({
95121
ref: refs.setReference,
96122
})
@@ -107,8 +133,10 @@ export const ButtonMenu = ({
107133
left: x,
108134
maxHeight: maxHeight - 16,
109135
},
110-
className:
136+
className: classNames(
111137
'relative z-[1] overflow-y-auto bg-white rounded-b-lg border border-grey-4 rounded-lg shadow-card',
138+
menuContainerClassName
139+
),
112140
})}
113141
>
114142
{children}

0 commit comments

Comments
 (0)