From b4ddf7a6740165a3362067875a24ae3633e0544a Mon Sep 17 00:00:00 2001 From: Sarka Chwastkova Date: Wed, 18 Sep 2024 21:11:28 +0200 Subject: [PATCH] chore(Popover): migrate from CSF2 to CSF3 --- .../src/Popover/Popover.stories.tsx | 743 +++++++----------- 1 file changed, 289 insertions(+), 454 deletions(-) diff --git a/packages/orbit-components/src/Popover/Popover.stories.tsx b/packages/orbit-components/src/Popover/Popover.stories.tsx index 4647c14758..e75fab726f 100644 --- a/packages/orbit-components/src/Popover/Popover.stories.tsx +++ b/packages/orbit-components/src/Popover/Popover.stories.tsx @@ -1,5 +1,6 @@ import * as React from "react"; import { action } from "@storybook/addon-actions"; +import type { Meta, StoryObj } from "@storybook/react"; import Tooltip from "../Tooltip"; import RenderInRtl from "../utils/rtl/RenderInRtl"; @@ -17,7 +18,18 @@ import Modal from "../Modal"; import Popover from "."; -const Content = () =>
; +const Content = () =>
; + +const listChoiceContent = Array.from({ length: 3 }, (_, idx) => ( + } + onClick={action("onClick")} + /> +)); const selects = ( @@ -49,338 +61,172 @@ const actions = ( ); -const longContent = ( - - {selects} - {selects} - {selects} - {selects} - {selects} - {selects} - {selects} - -); - -const PopoverState = ({ labelClose, placement }) => { - const [render, setRender] = React.useState(false); - - React.useEffect(() => { - setTimeout(() => { - if (!render) { - setRender(true); - } - }, 2000); - }, [render]); +const longContent = {Array(8).fill(selects)}; - return ( - - - } - onClick={action("onClick")} - /> - } - onClick={action("onClick")} - /> - } - onClick={action("onClick")} - /> -
- ) : ( - - ) - } - > - - - - ); -}; - -PopoverState.args = { - placement: PLACEMENTS.BOTTOM_START, - labelClose: "Close", -}; - -PopoverState.argTypes = { - placement: { - options: Object.values(PLACEMENTS), - control: { - type: "select", - }, - }, -}; - -export default { +const meta: Meta = { title: "Popover", -}; + component: Popover, -export const Default = ({ labelClose }) => { - return ( - - - - ); -}; + args: { + onOpen: action("open"), + onClose: action("close"), + }, -Default.story = { parameters: { - info: "You can try all possible configurations of this component. However, check Orbit.Kiwi for more detailed design guidelines.", + info: "Popover component. Check Orbit.Kiwi for more detailed guidelines.", }, }; -Default.args = { - labelClose: "Close", -}; - -export const InsideCard = () => { - const [isOpened, setIsOpened] = React.useState(false); - const [isOpenedPopover, setIsOpenedPopover] = React.useState(false); +export default meta; - return ( - <> - - { - setIsOpened(true); - }} - onClose={() => setIsOpened(false)} - > - { - setIsOpenedPopover(false); - }} - content={
Content
} - > - -
-
-
- {isOpened && setIsOpened(false)}>kek} - - ); -}; +type Story = StoryObj; -export const WithTooltip = ({ labelClose }) => { - return ( - Tooltip} labelClose={labelClose}> +export const Default: Story = { + render: args => ( + - ); -}; + ), + + args: { + onClose: undefined, + onOpen: undefined, + }, -WithTooltip.args = { - labelClose: "Close", + parameters: { + info: "Default setup of Popover component. Check Orbit.Kiwi for more detailed guidelines.", + controls: { + disable: true, + }, + }, }; -export const Placement = ({ placement, labelClose }) => { - return ( +export const Placement: Story = { + render: args => ( - + - ); -}; + ), -Placement.story = { parameters: { - info: "You can try all possible configurations of this component. However, check Orbit.Kiwi for more detailed design guidelines.", + controls: { + exclude: [ + "labelClose", + "renderInPortal", + "lockScrolling", + "renderTimeout", + "onOpen", + "onClose", + ], + }, }, -}; -Placement.args = { - placement: PLACEMENTS.TOP_START, - labelClose: "Close", -}; + args: { + placement: PLACEMENTS.BOTTOM_START, + }, -Placement.argTypes = { - placement: { - options: Object.values(PLACEMENTS), - control: { - type: "select", + argTypes: { + placement: { + options: Object.values(PLACEMENTS), + control: { + type: "select", + }, }, }, }; -export const WithListChoice = ({ width, labelClose }) => { - return ( - - } - onClick={action("onClick")} - /> - } - onClick={action("onClick")} - /> - } - onClick={action("onClick")} - /> -
- } - placement="bottom-start" - > +export const OpenedByProp: Story = { + render: args => ( + - ); -}; - -WithListChoice.story = { - name: "With ListChoice", + ), parameters: { - info: "You can try all possible configurations of this component. However, check Orbit.Kiwi for more detailed design guidelines.", + controls: { + exclude: [ + "labelClose", + "renderInPortal", + "placement", + "lockScrolling", + "renderTimeout", + "onOpen", + "onClose", + ], + }, }, -}; - -WithListChoice.args = { - width: "250px", - labelClose: "Close", -}; -export const OpenedByProp = ({ opened, labelClose }) => { - return ( - - - - ); -}; - -OpenedByProp.story = { - name: "Opened by prop", - - parameters: { - info: "You can try all possible configurations of this component. However, check Orbit.Kiwi for more detailed design guidelines.", + args: { + opened: false, }, }; -OpenedByProp.args = { - opened: false, - labelClose: "Close", -}; - -export const Overlapped = ({ overlapped, opened }) => { - return ( - +export const Overlapped: Story = { + render: ({ opened, ...args }) => ( + - ); -}; + ), -Overlapped.story = { parameters: { - info: "You can try all possible configurations of this component. However, check Orbit.Kiwi for more detailed design guidelines.", + controls: { + exclude: [ + "labelClose", + "renderInPortal", + "placement", + "lockScrolling", + "renderTimeout", + "onOpen", + "onClose", + ], + }, }, -}; -Overlapped.args = { - overlapped: true, - opened: false, + args: { + ...OpenedByProp.args, + overlapped: true, + }, }; -export const MultiplePopovers = () => { - return ( +export const MultiplePopovers: Story = { + render: args => ( - + - + - ); -}; + ), -MultiplePopovers.story = { parameters: { - info: "You can try all possible configurations of this component. However, check Orbit.Kiwi for more detailed design guidelines.", + info: "Example of multiple Popovers. Check Orbit.Kiwi for more detailed guidelines.", + controls: { + disable: true, + }, }, }; -export const LongContent = () => { - return ( +export const LongContent: Story = { + render: args => ( <> @@ -388,131 +234,206 @@ export const LongContent = () => { } - onOpen={action("open")} - onClose={action("close")} > - + - ); -}; - -LongContent.story = { - name: "Long content", + ), parameters: { - info: "You can try all possible configurations of this component. However, check Orbit.Kiwi for more detailed design guidelines.", + info: "Example of Popover with long content. Check Orbit.Kiwi for more detailed guidelines.", + controls: { + disable: true, + }, }, }; -export const ScrollingPage = ({ labelClose }) => { - return ( +export const ScrollingPage: Story = { + render: args => ( <>
- +
- - ); + ), + + parameters: { + info: "Example of Popover placed in scrolling element. Check Orbit.Kiwi for more detailed guidelines.", + controls: { + exclude: [ + "renderInPortal", + "placement", + "lockScrolling", + "renderTimeout", + "onOpen", + "onClose", + "labelClose", + ], + }, + }, + + args: { + fixed: true, + }, }; -ScrollingPage.story = { - name: "Scrolling page", +export const ScrollingContent: Story = { + render: args => ( +
+ +
+ + + +
+ +
+ ), parameters: { - info: "You can try all possible configurations of this component. However, check Orbit.Kiwi for more detailed design guidelines.", + info: "Example of Popover placed in scrolling element. Check Orbit.Kiwi for more detailed guidelines.", + controls: { + disable: true, + }, }, }; -ScrollingPage.args = { - labelClose: "Close", +export const LazyContentSimulated: Story = { + render: args => { + const [render, setRender] = React.useState(false); + + React.useEffect(() => { + setTimeout(() => { + if (!render) { + setRender(true); + } + }, 2000); + }, [render]); + + return ( + + }> + + + + ); + }, + + parameters: { + info: "Example of Popover with lazy loading component. Check Orbit.Kiwi for more detailed guidelines.", + controls: { + disable: true, + }, + }, }; -export const ScrollingContent = ({ labelClose }) => { - return ( -
-
+export const InsideCard: Story = { + render: args => { + const [isOpened, setIsOpened] = React.useState(false); + const [isOpenedPopover, setIsOpenedPopover] = React.useState(false); + + return ( + <> - { + setIsOpened(true); + }} + onClose={() => setIsOpened(false)} > - - + { + setIsOpenedPopover(false); + }} + content={
Content
} + > + +
+
- -
-
- ); + {isOpened && setIsOpened(false)}>kek} + + ); + }, + + parameters: { + info: "Example of Popover placed in card. Check Orbit.Kiwi for more detailed guidelines.", + controls: { + disable: true, + }, + }, }; -ScrollingContent.story = { - name: "Scrolling content", +export const WithTooltip: Story = { + render: args => ( + Tooltip}> + + + ), parameters: { - info: "You can try all possible configurations of this component. However, check Orbit.Kiwi for more detailed design guidelines.", + info: "Example of Popover component with tooltip in content. Check Orbit.Kiwi for more detailed guidelines.", + controls: { + disable: true, + }, }, }; -ScrollingContent.args = { - labelClose: "Close", +export const WithListChoice: Story = { + render: args => ( + + + + ), + + parameters: { + info: "Example of Popover component with ListChoice in content prop. Check Orbit.Kiwi for more detailed guidelines.", + controls: { + disable: true, + }, + }, }; -export const Playground = ({ - renderTimeout, - zIndex, - dataTest, - placement, - width, - maxHeight, - footerActions, - noPadding, - overlapped, - opened, - offset, - noFlip, - allowOverflow, -}) => { - return ( +type PlaygroundArgsAndCustomTypes = StoryObj< + React.ComponentProps & { footerActions: boolean } +>; +export const Playground: PlaygroundArgsAndCustomTypes = { + render: ({ footerActions, opened, ...args }) => ( @@ -523,149 +444,63 @@ export const Playground = ({ ) } - overlapped={overlapped} - onOpen={action("open")} - onClose={action("close")} >
- ); -}; + ), -Playground.story = { parameters: { - info: "You can try all possible configurations of this component. However, check Orbit.Kiwi for more detailed design guidelines.", - }, -}; - -Playground.args = { - renderTimeout: 0, - zIndex: 710, - dataTest: "test", - placement: PLACEMENTS.BOTTOM_START, - width: "350px", - maxHeight: "", - footerActions: true, - noPadding: false, - overlapped: false, - opened: true, - offset: { top: 0, left: 0 }, - noFlip: false, - allowOverflow: false, -}; - -Playground.argTypes = { - placement: { - options: Object.values(PLACEMENTS), - control: { - type: "select", + info: "You can try all possible configurations of this component. Check Orbit.Kiwi for more detailed guidelines.", + controls: { + exclude: ["onOpen", "onClose"], }, }, -}; -export const Rtl = ({ dataTest, labelClose, placement }) => { - return ( - - - - - - - - ); -}; - -Rtl.story = { - name: "RTL", - - parameters: { - info: "You can try all possible configurations of this component. However, check Orbit.Kiwi for more detailed design guidelines.", + args: { + ...Placement.args, + labelClose: "Close", + renderInPortal: true, + opened: true, + zIndex: 710, + id: "popover-id", + offset: { top: 0, left: 0 }, + fixed: true, + lockScrolling: true, + noFlip: false, + renderTimeout: 0, + allowOverflow: false, + noPadding: false, + width: "350px", + maxHeight: "", + overlapped: false, + footerActions: true, }, -}; - -Rtl.args = { - dataTest: "test", - labelClose: "Close", - placement: PLACEMENTS.BOTTOM_START, -}; -Rtl.argTypes = { - placement: { - options: Object.values(PLACEMENTS), - control: { - type: "select", - }, + argTypes: { + ...Placement.argTypes, }, }; -export const RtlReverse = ({ placement, labelClose }) => { - return ( +export const Rtl: Story = { + render: () => ( - - + + - ); -}; - -RtlReverse.story = { - name: "RTL Reverse", - - parameters: { - info: "You can try all possible configurations of this component. However, check Orbit.Kiwi for more detailed design guidelines.", - }, -}; - -RtlReverse.args = { - placement: PLACEMENTS.BOTTOM_START, - labelClose: "Close", -}; - -RtlReverse.argTypes = { - placement: { - options: Object.values(PLACEMENTS), - control: { - type: "select", - }, - }, -}; - -export const LazyContentSimlulated = args => { - return ; -}; - -LazyContentSimlulated.story = { - name: "LazyContent - simlulated", + ), parameters: { - info: "You can try all possible configurations of this component. However, check Orbit.Kiwi for more detailed design guidelines.", - }, -}; - -LazyContentSimlulated.args = { - placement: PLACEMENTS.BOTTOM_START, - labelClose: "Close", -}; - -LazyContentSimlulated.argTypes = { - placement: { - options: Object.values(PLACEMENTS), - control: { - type: "select", + info: "Example of RTL Popover component. Check Orbit.Kiwi for more detailed guidelines.", + controls: { + disable: true, }, }, };