From e40416136a33b3c26d39fabf429b103abb46f3ff Mon Sep 17 00:00:00 2001 From: Valerii Sidorenko Date: Wed, 14 Feb 2024 12:26:14 +0100 Subject: [PATCH] chore: update Popup stories (#1337) --- .../Popup/__stories__/Popup.stories.tsx | 233 ++++++++++-------- 1 file changed, 129 insertions(+), 104 deletions(-) diff --git a/src/components/Popup/__stories__/Popup.stories.tsx b/src/components/Popup/__stories__/Popup.stories.tsx index 05cc21d0ba..2824695128 100644 --- a/src/components/Popup/__stories__/Popup.stories.tsx +++ b/src/components/Popup/__stories__/Popup.stories.tsx @@ -1,132 +1,157 @@ import React from 'react'; -import type {Meta, StoryFn} from '@storybook/react'; +import type {Meta, StoryObj} from '@storybook/react'; -import {useUniqId, useVirtualElementRef} from '../../../hooks'; +import {useVirtualElementRef} from '../../../hooks'; import {Button} from '../../Button'; -import {TextInput} from '../../controls'; +import {Text} from '../../Text'; import {Popup} from '../Popup'; -import type {PopupPlacement, PopupProps} from '../Popup'; +import type {PopupPlacement} from '../Popup'; -export default { +const meta: Meta = { title: 'Components/Overlays/Popup', component: Popup, -} as Meta; +}; + +export default meta; + +type Story = StoryObj; + +export const Default: Story = { + render: function PopupStory(props) { + const anchorRef = React.useRef(null); + const [open, setOpen] = React.useState(false); + + return ( + + setOpen(false)}> +
Popup content
+
+
+ +
+
+ ); + }, +}; -export const Default: StoryFn = (props: PopupProps) => { - const anchorRef = React.useRef(null); - const [open, setOpen] = React.useState(false); +export const Placement: Story = { + render: function PopupStory(props) { + const anchorRef = React.useRef(null); + const [open, setOpen] = React.useState(true); + const contentStyle = {padding: 10}; + const placements: PopupPlacement = [ + 'top-start', + 'top', + 'top-end', + 'right-start', + 'right', + 'right-end', + 'bottom-end', + 'bottom', + 'bottom-start', + 'left-end', + 'left', + 'left-start', + ]; - return ( - - setOpen(false)}> -
Popup content
-
+ return (
- + + {placements.map((placement) => ( + +
{placement}
+
+ ))}
-
- ); + ); + }, + parameters: { + layout: 'centered', + }, }; -export const Placement: StoryFn = (args) => { - const anchorRef = React.useRef(null); - const [open, setOpen] = React.useState(true); - const contentStyle = {padding: 10}; - const placements: PopupPlacement = [ - 'top-start', - 'top', - 'top-end', - 'right-start', - 'right', - 'right-end', - 'bottom-end', - 'bottom', - 'bottom-start', - 'left-end', - 'left', - 'left-start', - ]; +export const Position: Story = { + render: function PopupStory(props) { + const [left, setLeft] = React.useState(0); + const [top, setTop] = React.useState(0); - return ( -
- - {placements.map((placement) => ( - -
{placement}
-
- ))} -
- ); -}; -Placement.parameters = { - layout: 'centered', -}; + const [contextElement, setContextElement] = React.useState(null); + const anchorRef = useVirtualElementRef({ + rect: {top, left}, + contextElement: contextElement ?? undefined, + }); + const [open, setOpen] = React.useState(false); -export const Position: StoryFn = (args) => { - const [left, setLeft] = React.useState(100); - const [top, setTop] = React.useState(100); - const anchorRef = useVirtualElementRef({rect: {top, left}}); + const handleMouseMove = (event: React.MouseEvent) => { + setLeft(event.clientX); + setTop(event.clientY); + }; - const id = useUniqId(); + React.useEffect(() => { + window.dispatchEvent(new CustomEvent('scroll')); + }, [left, top]); - return ( -
-