Skip to content

Commit

Permalink
chore: revert popover API
Browse files Browse the repository at this point in the history
  • Loading branch information
jmfrancois committed Oct 12, 2023
1 parent 0c40aa0 commit 557b309
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
21 changes: 15 additions & 6 deletions packages/design-system/src/components/Popover/Popover.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ context('<Popover />', () => {
describe('default', () => {
it('should show a popover', () => {
cy.mount(
<Popover data-testid="my.popover" popup="Popover content">
<ButtonPrimary data-testid="my.button">Open popover</ButtonPrimary>
<Popover
data-testid="my.popover"
disclosure={<ButtonPrimary data-testid="my.button">Open popover</ButtonPrimary>}
>
Popover content
</Popover>,
);

Expand All @@ -23,10 +26,16 @@ context('<Popover />', () => {
<CollapsiblePanel
title="panel"
metadata={[
<Popover key="my.popover" data-testid="my.popover" popup={<p>Popover content</p>}>
<ButtonPrimary onClick={() => {}} data-testid="my.button">
Open popover
</ButtonPrimary>
<Popover
key="my.popover"
data-testid="my.popover"
disclosure={
<ButtonPrimary onClick={() => {}} data-testid="my.button">
Open popover
</ButtonPrimary>
}
>
<p>Popover content</p>
</Popover>,
]}
>
Expand Down
14 changes: 7 additions & 7 deletions packages/design-system/src/components/Popover/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { usePopover } from './usePopover';
import theme from './Popover.module.scss';

type PopoverOptions = {
popup: ReactNode | ((props: any) => ReactNode);
initialOpen?: boolean;
placement?: Placement;
modal?: boolean;
Expand All @@ -23,7 +22,8 @@ type PopoverOptions = {
};

export type PopoverProps = {
children: ChildOrGenerator<ReactNode, object>;
disclosure: ChildOrGenerator<ReactNode, object>;
children: ReactNode | ((props: any) => ReactNode);
} & PopoverOptions;

export type PopoverStateReturn = {
Expand All @@ -34,7 +34,7 @@ export function Popover({
children,
modal = true,
isFixed = false,
popup,
disclosure,
hasPadding = true,
...restOptions
}: PopoverProps) {
Expand All @@ -52,7 +52,7 @@ export function Popover({

return (
<>
{renderOrClone(children, { ...childrenProps, ref: popover.refs.setReference })}
{renderOrClone(disclosure, { ...childrenProps, ref: popover.refs.setReference })}
<Wrapper>
<div
ref={popover.refs.setFloating}
Expand All @@ -69,9 +69,9 @@ export function Popover({
stroke={tokens.coralColorIllustrationShadow}
fill={tokens.coralColorNeutralBackground}
/>
{typeof popup === 'function'
? popup({ ...popover.getFloatingProps(), setOpen: popover.setOpen })
: popup}
{typeof children === 'function'
? children({ ...popover.getFloatingProps(), setOpen: popover.setOpen })
: children}
</div>
</Wrapper>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { BasicSearch } from './BasicSearch.component';
import { FacetedManager } from '../FacetedManager';
import { USAGE_TRACKING_TAGS } from '../../constants';

jest.unmock('@talend/design-system');

describe('BasicSearch', () => {
const badgeText = {
properties: {
Expand Down

0 comments on commit 557b309

Please sign in to comment.