Skip to content

Commit f1c0d82

Browse files
authored
feat(components/Popover): import components via Popover.Header, Popover.Body, Popover.Footer
1 parent 6a00b0e commit f1c0d82

File tree

4 files changed

+60
-51
lines changed

4 files changed

+60
-51
lines changed

packages/components/src/components/Popover/Popover.mdx

+9-20
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@ import * as Stories from './Popover.stories';
1616
Popover component as an overlay whose position is anchored to an element in the user interface.
1717

1818
```tsx
19-
import {
20-
Popover,
21-
PopoverHeader,
22-
PopoverContent,
23-
PopoverFooter,
24-
} from '@koobiq/react-components';
19+
import { Popover } from '@koobiq/react-components';
2520
```
2621

2722
<Story of={Stories.Base} />
@@ -34,9 +29,9 @@ import {
3429

3530
The component has the following helper components:
3631

37-
- `PopoverHeader` — header of the popover
38-
- `PopoverContent`content area of the component for placing the main information
39-
- `PopoverFooter` — footer of the component, can contain various actions.
32+
- `Popover.Header` — header of the popover
33+
- `Popover.Body`body of the component for placing the main information
34+
- `Popover.Footer` — footer of the component, can contain various actions.
4035

4136
## Usage
4237

@@ -60,22 +55,16 @@ The `children` prop can be `ReactNode` or a render function with the `PopoverPro
6055
The render function can help pass a function to close the popover.
6156

6257
```tsx
63-
import {
64-
Button,
65-
Popover,
66-
PopoverHeader,
67-
PopoverContent,
68-
PopoverFooter,
69-
} from '@koobiq/react-components';
58+
import { Button, Popover } from '@koobiq/react-components';
7059

7160
<Popover control={(props) => <Button {...props}>Open</Button>}>
7261
{({ close }) => (
7362
<>
74-
<PopoverHeader>Title</PopoverHeader>
75-
<PopoverContent>Content</PopoverContent>
76-
<PopoverFooter>
63+
<Popover.Header>Title</Popover.Header>
64+
<Popover.Body>Content</Popover.Body>
65+
<Popover.Footer>
7766
<Button onClick={close}>Close</Button>
78-
</PopoverFooter>
67+
</Popover.Footer>
7968
</>
8069
)}
8170
</Popover>;

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

+19-22
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,17 @@ import { spacing } from '../layout';
1313
import { Typography } from '../Typography';
1414

1515
import image from './__stories__/img.webp';
16-
import {
17-
Popover,
18-
PopoverContent,
19-
PopoverFooter,
20-
PopoverHeader,
21-
type PopoverPropPlacement,
22-
popoverPropSize,
23-
} from './index';
16+
import { Popover, type PopoverPropPlacement, popoverPropSize } from './index';
2417
import type { PopoverProps } from './index.js';
2518

2619
const meta = {
2720
title: 'Components/Popover',
2821
component: Popover,
29-
subcomponents: { PopoverHeader, PopoverContent, PopoverFooter },
22+
subcomponents: {
23+
'Popover.Header': Popover.Header,
24+
'Popover.Body': Popover.Body,
25+
'Popover.Footer': Popover.Footer,
26+
},
3027
parameters: {
3128
layout: 'centered',
3229
},
@@ -43,7 +40,7 @@ export const Base: Story = {
4340
hideCloseButton
4441
{...args}
4542
>
46-
<PopoverHeader>I&#39;m a popover!</PopoverHeader>
43+
<Popover.Header>I&#39;m a popover!</Popover.Header>
4744
</Popover>
4845
),
4946
};
@@ -57,7 +54,7 @@ export const Arrow: Story = {
5754
hideArrow
5855
{...args}
5956
>
60-
<PopoverHeader>I&#39;m a popover!</PopoverHeader>
57+
<Popover.Header>I&#39;m a popover!</Popover.Header>
6158
</Popover>
6259
),
6360
};
@@ -77,7 +74,7 @@ export const Offsets: Story = {
7774
hideCloseButton
7875
{...args}
7976
>
80-
<PopoverHeader>I&#39;m a popover!</PopoverHeader>
77+
<Popover.Header>I&#39;m a popover!</Popover.Header>
8178
</Popover>
8279
<FlexBox gap="m">
8380
<InputNumber
@@ -118,11 +115,11 @@ export const Size: Story = {
118115
>
119116
{({ close }) => (
120117
<>
121-
<PopoverHeader>{capitalizeFirstLetter(size)}</PopoverHeader>
122-
<PopoverContent>{text}</PopoverContent>
123-
<PopoverFooter>
118+
<Popover.Header>{capitalizeFirstLetter(size)}</Popover.Header>
119+
<Popover.Body>{text}</Popover.Body>
120+
<Popover.Footer>
124121
<Button onPress={close}>Ok</Button>
125-
</PopoverFooter>
122+
</Popover.Footer>
126123
</>
127124
)}
128125
</Popover>
@@ -134,11 +131,11 @@ export const Size: Story = {
134131
>
135132
{({ close }) => (
136133
<>
137-
<PopoverHeader>Custom size = 50%</PopoverHeader>
138-
<PopoverContent>{text}</PopoverContent>
139-
<PopoverFooter>
134+
<Popover.Header>Custom size = 50%</Popover.Header>
135+
<Popover.Body>{text}</Popover.Body>
136+
<Popover.Footer>
140137
<Button onPress={close}>Ok</Button>
141-
</PopoverFooter>
138+
</Popover.Footer>
142139
</>
143140
)}
144141
</Popover>
@@ -279,7 +276,7 @@ export const Placement: Story = {
279276
hideCloseButton
280277
{...args}
281278
>
282-
<PopoverContent>Check out my placement</PopoverContent>
279+
<Popover.Body>Check out my placement</Popover.Body>
283280
</Popover>
284281
</Grid>
285282
);
@@ -313,7 +310,7 @@ export const ControlledOpen: Story = {
313310
hideCloseButton
314311
{...args}
315312
>
316-
<PopoverHeader>I&#39;m a popover!</PopoverHeader>
313+
<Popover.Header>I&#39;m a popover!</Popover.Header>
317314
</Popover>
318315
</>
319316
);

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

+15-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import { Transition } from 'react-transition-group';
1414
import type { TransitionProps } from 'react-transition-group/Transition';
1515

16-
import { Dialog } from '../Dialog';
16+
import { Dialog, DialogContent, DialogFooter, DialogHeader } from '../Dialog';
1717

1818
import s from './Popover.module.css';
1919
import type { PopoverInnerProps, PopoverProps } from './types';
@@ -174,7 +174,7 @@ export const PopoverInner: FC<PopoverInnerProps> = (props) => {
174174
);
175175
};
176176

177-
export const Popover = forwardRef<ComponentRef<'div'>, PopoverProps>(
177+
const PopoverComponent = forwardRef<ComponentRef<'div'>, PopoverProps>(
178178
(props, ref) => {
179179
const { open, onOpenChange, defaultOpen, ...other } = props;
180180

@@ -189,4 +189,16 @@ export const Popover = forwardRef<ComponentRef<'div'>, PopoverProps>(
189189
}
190190
);
191191

192-
Popover.displayName = 'Popover';
192+
PopoverComponent.displayName = 'Popover';
193+
194+
type CompoundedComponent = typeof PopoverComponent & {
195+
Header: typeof DialogHeader;
196+
Body: typeof DialogContent;
197+
Footer: typeof DialogFooter;
198+
};
199+
200+
export const Popover = PopoverComponent as CompoundedComponent;
201+
202+
Popover.Header = DialogHeader;
203+
Popover.Body = DialogContent;
204+
Popover.Footer = DialogFooter;
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1+
import { DialogHeader, DialogFooter, DialogContent } from '../Dialog';
2+
13
export * from './Popover';
24
export * from './types';
3-
export { DialogHeader, DialogFooter, DialogContent } from '../Dialog';
45

5-
export {
6-
DialogHeader as PopoverHeader,
7-
DialogContent as PopoverContent,
8-
DialogFooter as PopoverFooter,
9-
} from '../Dialog';
6+
/**
7+
* @deprecated
8+
* This component has been deprecated, please use `Popover.Header` instead.
9+
*/
10+
export const PopoverHeader = DialogHeader;
11+
/**
12+
* @deprecated
13+
* This component has been deprecated, please use `Popover.Body` instead.
14+
*/
15+
export const PopoverContent = DialogContent;
16+
/**
17+
* @deprecated
18+
* This component has been deprecated, please use `Popover.Footer` instead.
19+
*/
20+
export const PopoverFooter = DialogFooter;

0 commit comments

Comments
 (0)