|
1 | | -/* eslint-disable react/jsx-no-leaked-render */ |
| 1 | +import type { Meta } from '@storybook/react' |
| 2 | +import type { StoryObj } from '@storybook/react' |
2 | 3 |
|
3 | | -import type { PopoverProps } from '@atls-ui-parts/popover' |
4 | | -import type { Meta } from '@storybook/react' |
5 | | -import type { StoryObj } from '@storybook/react' |
6 | | -import type { PropsWithChildren } from 'react' |
7 | | -import type { ReactNode } from 'react' |
8 | | -import type { ReactElement } from 'react' |
| 4 | +import type { StoryPopoverProps } from './interfaces.js' |
9 | 5 |
|
10 | | -import { useState } from 'react' |
11 | | - |
12 | | -import { Popover } from '@atls-ui-parts/popover' |
13 | | - |
14 | | -import { storyTriggerStyles } from './popover.stories.css.js' |
15 | | -import { storyContainerStyles } from './popover.stories.css.js' |
16 | | -import { storyContainerCloseStyles } from './popover.stories.css.js' |
17 | | - |
18 | | -interface StoryPopoverProps |
19 | | - extends Pick<PopoverProps, 'animated' | 'arrow' | 'offset' | 'placement' | 'trigger'> { |
20 | | - customContainer: boolean |
21 | | -} |
22 | | - |
23 | | -interface StoryPopoverContainerProps extends PropsWithChildren { |
24 | | - title?: string |
25 | | - content?: ReactNode |
26 | | - onClose?: () => void |
27 | | -} |
| 6 | +import { StoryPopover } from './story-popover.js' |
28 | 7 |
|
29 | 8 | const meta: Meta<StoryPopoverProps> = { |
30 | 9 | title: 'Components/Popover', |
@@ -85,54 +64,6 @@ const meta: Meta<StoryPopoverProps> = { |
85 | 64 |
|
86 | 65 | export default meta |
87 | 66 |
|
88 | | -const StoryPopoverContainer = ({ |
89 | | - children, |
90 | | - content, |
91 | | - title, |
92 | | - onClose, |
93 | | -}: StoryPopoverContainerProps): ReactElement => ( |
94 | | - <div className={storyContainerStyles}> |
95 | | - <div>{title}</div> |
96 | | - <div>{content}</div> |
97 | | - <button type='button' className={storyContainerCloseStyles} onClick={onClose}> |
98 | | - Close |
99 | | - </button> |
100 | | - {children} |
101 | | - </div> |
102 | | -) |
103 | | - |
104 | | -const StoryPopover = ({ |
105 | | - animated, |
106 | | - arrow, |
107 | | - customContainer, |
108 | | - offset, |
109 | | - placement, |
110 | | - trigger, |
111 | | -}: StoryPopoverProps): ReactElement => { |
112 | | - const [open, setOpen] = useState<boolean>(false) |
113 | | - |
114 | | - const handleClose = (): void => { |
115 | | - setOpen(false) |
116 | | - } |
117 | | - |
118 | | - return ( |
119 | | - <Popover |
120 | | - open={open} |
121 | | - animated={animated} |
122 | | - arrow={arrow} |
123 | | - offset={offset} |
124 | | - placement={placement} |
125 | | - trigger={trigger} |
126 | | - title='Popover title' |
127 | | - content='Popover content' |
128 | | - container={customContainer ? <StoryPopoverContainer onClose={handleClose} /> : undefined} |
129 | | - onOpenChange={setOpen} |
130 | | - > |
131 | | - <div className={storyTriggerStyles}>Trigger</div> |
132 | | - </Popover> |
133 | | - ) |
134 | | -} |
135 | | - |
136 | 67 | export const Base: StoryObj<StoryPopoverProps> = { |
137 | 68 | render: StoryPopover, |
138 | 69 | } |
0 commit comments