Skip to content

Commit 5e60168

Browse files
committed
feat(popover): add a title attribute
1 parent b34bfc9 commit 5e60168

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

packages/fractal/src/components/Popover/Popover.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const meta: Meta<PopoverProps> = {
4848
fullWidth: false,
4949
modal: false,
5050
side: undefined,
51+
title: undefined,
5152
toggleOnTriggerClick: true,
5253
toggleOnTriggerHover: false,
5354
trigger: 'Text',

packages/fractal/src/components/Popover/Popover.tsx

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
useState,
1515
} from 'react'
1616

17+
import isEmpty from 'lodash/fp/isEmpty'
1718
import isFunction from 'lodash/fp/isFunction'
1819
import isNumber from 'lodash/fp/isNumber'
1920
import omit from 'lodash/fp/omit'
@@ -52,6 +53,7 @@ export const Popover = forwardRef<CombinedRefs, PopoverProps>(
5253
open,
5354
popover = {},
5455
side,
56+
title,
5557
toggleOnTriggerClick = true,
5658
toggleOnTriggerHover = false,
5759
trigger,
@@ -292,21 +294,34 @@ export const Popover = forwardRef<CombinedRefs, PopoverProps>(
292294
)}
293295
>
294296
<Paper className="relative" elevation={elevation}>
295-
{withCloseButton && (
296-
<RxPopover.Close
297-
asChild
298-
className={cj(`${PREFIX}-${GROUP_NAME}__close`)}
297+
{(withCloseButton || !isEmpty(title)) && (
298+
<div
299+
className={cj(
300+
'flex flex-row items-center justify-between',
301+
!isEmpty(title) ? 'mb-1' : '',
302+
)}
299303
>
300-
<div className="flex justify-end text-right">
301-
<Button
302-
icon={<CloseIcon />}
303-
iconOnly
304-
label={closeButtonLabel}
305-
variant="text"
306-
onClick={onCloseButtonClick}
307-
/>
308-
</div>
309-
</RxPopover.Close>
304+
{!isEmpty(title) && (
305+
<Typography variant="body-1-bold">{title}</Typography>
306+
)}
307+
308+
{withCloseButton && (
309+
<RxPopover.Close
310+
asChild
311+
className={cj(`${PREFIX}-${GROUP_NAME}__close`)}
312+
>
313+
<div className="mt-half flex size-full items-center justify-end text-right">
314+
<Button
315+
icon={<CloseIcon />}
316+
iconOnly
317+
label={closeButtonLabel}
318+
variant="text"
319+
onClick={onCloseButtonClick}
320+
/>
321+
</div>
322+
</RxPopover.Close>
323+
)}
324+
</div>
310325
)}
311326

312327
{withScroll ? (

packages/fractal/src/components/Popover/Popover.types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export type CombinedRefs = {
1818
trigger: HTMLElement | null
1919
}
2020

21-
export interface PopoverProps extends AllHTMLAttributes<HTMLDivElement> {
21+
export interface PopoverProps
22+
extends Omit<AllHTMLAttributes<HTMLDivElement>, 'title'> {
2223
/**
2324
* The content of the popover.
2425
*/
@@ -74,6 +75,8 @@ export interface PopoverProps extends AllHTMLAttributes<HTMLDivElement> {
7475
>
7576
/** The preferred side of the trigger to render the popover. */
7677
side?: RxPopoverContentProps['side']
78+
/** The title of the popover. */
79+
title?: string
7780
/**
7881
* Indicates if you want to toggle the popover when clicking on the trigger
7982
* (if provided of course).

0 commit comments

Comments
 (0)