Skip to content

Commit

Permalink
Rename Popover to Popover.Root
Browse files Browse the repository at this point in the history
  • Loading branch information
Barsnes committed Jun 18, 2024
1 parent 6f181b6 commit 1ad6452
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 46 deletions.
8 changes: 4 additions & 4 deletions packages/react/src/components/HelpText/HelpText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import cl from 'clsx/lite';
import type { Placement } from '@floating-ui/utils';

import { Popover, Paragraph } from '../';
import type { PopoverProps } from '../Popover/Popover';
import type { PopoverRootProps } from '../Popover/PopoverRoot';
import type { PortalProps } from '../../types/Portal';

import { HelpTextIcon } from './HelpTextIcon';
Expand All @@ -18,7 +18,7 @@ export type HelpTextProps = {
* Size of the helptext
* @default md
*/
size?: PopoverProps['size'];
size?: PopoverRootProps['size'];
/**
* Placement of the Popover.
* @default 'right'
Expand All @@ -40,7 +40,7 @@ const HelpText = ({

return (
<>
<Popover
<Popover.Root
variant='info'
placement={placement}
size={size}
Expand Down Expand Up @@ -87,7 +87,7 @@ const HelpText = ({
{children}
</Popover.Content>
</Paragraph>
</Popover>
</Popover.Root>
</>
);
};
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/Popover/Popover.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import * as PopoverStories from './Popover.stories.tsx';
```tsx
import { Popover } from '@digdir/designsystemet-react';

<Popover>
<Popover.Root>
<Popover.Trigger>Trigger</Popover.Trigger>
<Popover.Content>Content</Popover.Content>
</Popover.Trigger>
Expand Down
34 changes: 17 additions & 17 deletions packages/react/src/components/Popover/Popover.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ const marginDecorator = (Story: StoryFn) => (

export default {
title: 'Komponenter/Popover',
component: Popover,
component: Popover.Root,
} as Meta;

export const Preview: StoryFn<typeof Popover> = (args) => {
export const Preview: StoryFn<typeof Popover.Root> = (args) => {
return (
<Popover {...args}>
<Popover.Root {...args}>
<Popover.Trigger>My trigger!</Popover.Trigger>
<Popover.Content>popover content</Popover.Content>
</Popover>
</Popover.Root>
);
};

Expand All @@ -34,7 +34,7 @@ Preview.args = {

Preview.decorators = [marginDecorator];

export const Variants: StoryFn<typeof Popover> = () => {
export const Variants: StoryFn<typeof Popover.Root> = () => {
const [open, setOpen] = useState(false);

useEffect(() => {
Expand All @@ -43,37 +43,37 @@ export const Variants: StoryFn<typeof Popover> = () => {

return (
<div style={{ display: 'flex', gap: 'var(--ds-spacing-2)' }}>
<Popover
<Popover.Root
open={open}
placement='top'
>
<Popover.Trigger>popover</Popover.Trigger>
<Popover.Content>default</Popover.Content>
</Popover>
<Popover
</Popover.Root>
<Popover.Root
open={open}
placement='bottom'
variant='danger'
>
<Popover.Trigger>popover</Popover.Trigger>
<Popover.Content>danger</Popover.Content>
</Popover>
<Popover
</Popover.Root>
<Popover.Root
open={open}
placement='top'
variant='info'
>
<Popover.Trigger>popover</Popover.Trigger>
<Popover.Content>info</Popover.Content>
</Popover>
<Popover
</Popover.Root>
<Popover.Root
open={open}
placement='bottom'
variant='warning'
>
<Popover.Trigger>popover</Popover.Trigger>
<Popover.Content>warning</Popover.Content>
</Popover>
</Popover.Root>
</div>
);
};
Expand All @@ -85,7 +85,7 @@ export const Controlled: StoryFn<typeof Popover> = () => {

return (
<>
<Popover
<Popover.Root
open={open}
onClose={() => setOpen(false)}
>
Expand All @@ -105,7 +105,7 @@ export const Controlled: StoryFn<typeof Popover> = () => {
Slett
</Button>
</Popover.Content>
</Popover>
</Popover.Root>
</>
);
};
Expand All @@ -114,9 +114,9 @@ Controlled.decorators = [marginDecorator];

export const InPortal = () => {
return (
<Popover portal>
<Popover.Root portal>
<Popover.Trigger>My trigger</Popover.Trigger>
<Popover.Content>popover content</Popover.Content>
</Popover>
</Popover.Root>
);
};
10 changes: 5 additions & 5 deletions packages/react/src/components/Popover/Popover.test.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { act, render as renderRtl, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import type { PopoverProps } from './Popover';
import type { PopoverRootProps } from './PopoverRoot';

import { Popover } from './';

const contentText = 'popover content';

const Comp = (args: Partial<PopoverProps>) => {
const Comp = (args: Partial<PopoverRootProps>) => {
return (
<Popover {...args}>
<Popover.Root {...args}>
<Popover.Trigger>trigger</Popover.Trigger>
<Popover.Content>{contentText}</Popover.Content>
</Popover>
</Popover.Root>
);
};

const render = async (props: Partial<PopoverProps> = {}) => {
const render = async (props: Partial<PopoverRootProps> = {}) => {
/* Flush microtasks */
await act(async () => {});
const user = userEvent.setup();
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/Popover/PopoverContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import cl from 'clsx/lite';
import { Paragraph } from '../Typography';
import { useIsomorphicLayoutEffect } from '../../hooks';

import { PopoverContext } from './Popover';
import { PopoverContext } from './PopoverRoot';

const ARROW_HEIGHT = 7;
const ARROW_GAP = 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as React from 'react';

import type { PortalProps } from '../../types/Portal';

export type PopoverProps = {
export type PopoverRootProps = {
/**
* Placement of the tooltip on the trigger.
* @default top
Expand Down Expand Up @@ -34,7 +34,7 @@ export type PopoverProps = {
children: React.ReactNode;
} & PortalProps;

export const Popover = ({
export const PopoverRoot = ({
children,
placement = 'top',
open,
Expand All @@ -43,7 +43,7 @@ export const Popover = ({
size = 'md',
onOpenChange,
onClose,
}: PopoverProps) => {
}: PopoverRootProps) => {
const triggerRef = useRef<Element>(null);
const [internalOpen, setInternalOpen] = useState(open ?? false);

Expand Down Expand Up @@ -94,11 +94,11 @@ export const PopoverContext = React.createContext<{
triggerId?: string;
isControlled?: boolean;
internalOpen: boolean;
size: NonNullable<PopoverProps['size']>;
variant: NonNullable<PopoverProps['variant']>;
size: NonNullable<PopoverRootProps['size']>;
variant: NonNullable<PopoverRootProps['variant']>;
placement: Placement;
onOpenChange?: PopoverProps['onOpenChange'];
onClose?: PopoverProps['onClose'];
onOpenChange?: PopoverRootProps['onOpenChange'];
onClose?: PopoverRootProps['onClose'];
setPopoverId?: (id: string) => void;
setTriggerId?: (id: string) => void;
setInternalOpen: (open: boolean) => void;
Expand All @@ -112,4 +112,4 @@ export const PopoverContext = React.createContext<{
setInternalOpen: () => {},
});

Popover.displayName = 'Popover';
PopoverRoot.displayName = 'Popover.Root';
2 changes: 1 addition & 1 deletion packages/react/src/components/Popover/PopoverTrigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Slot } from '@radix-ui/react-slot';

import { Button } from '../Button';

import { PopoverContext } from './Popover';
import { PopoverContext } from './PopoverRoot';

export type PopoverTriggerProps = React.ComponentPropsWithRef<typeof Button>;

Expand Down
17 changes: 8 additions & 9 deletions packages/react/src/components/Popover/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import { Popover as PopoverRoot } from './Popover';
import { PopoverRoot } from './PopoverRoot';
import type { PopoverContentProps } from './PopoverContent';
import { PopoverContent } from './PopoverContent';
import type { PopoverTriggerProps } from './PopoverTrigger';
import { PopoverTrigger } from './PopoverTrigger';
import type { PopoverProps } from './Popover';
import type { PopoverRootProps } from './PopoverRoot';

type PopoverComponent = typeof PopoverRoot & {
type PopoverComponent = {
Root: typeof PopoverRoot;
Content: typeof PopoverContent;
Trigger: typeof PopoverTrigger;
};

const Popover = PopoverRoot as PopoverComponent;
const Popover = {} as PopoverComponent;

Popover.Root = PopoverRoot;
Popover.Content = PopoverContent;
Popover.Trigger = PopoverTrigger;

Popover.Content.displayName = 'Popover.Content';
Popover.Trigger.displayName = 'Popover.Trigger';

export type { PopoverProps, PopoverContentProps, PopoverTriggerProps };
export { Popover, PopoverContent, PopoverTrigger };
export type { PopoverRootProps, PopoverContentProps, PopoverTriggerProps };
export { Popover, PopoverRoot, PopoverContent, PopoverTrigger };

0 comments on commit 1ad6452

Please sign in to comment.