import React, { useEffect, useRef, useState } from 'react' import { type Meta } from '@storybook/react' import classnames from 'classnames' import { Heading } from '~components/Heading' import { type StickerSheetStory } from '~storybook/components/StickerSheet' import { Popover, useFloating, type PopoverProps } from '../index' export default { title: 'Components/MultiSelect/Popover', parameters: { chromatic: { disable: false }, controls: { disable: true }, }, } satisfies Meta const PopoverTemplate = (args: Partial>): JSX.Element => { const [isOpen, setIsOpen] = useState(true) const { refs } = useFloating() return (
{isOpen && (
{args.children ?? 'Content here!'}
)}
) } const StickerSheetTemplate: StickerSheetStory = { render: (_, { parameters }) => { const portalRef = useRef(null) const [portalContainer, setPortalContainer] = useState() useEffect(() => { if (portalRef.current !== null) { setPortalContainer(portalRef.current) } }, []) return (
{parameters.textDirection === 'rtl' ? 'Default alignment to bottom-right; align to left when no space on left' : 'Default alignment to bottom-left; align to right when no space on right'}
Flips to top when no space below
Content below popover
) }, } export const StickerSheetDefault: StickerSheetStory = { ...StickerSheetTemplate, name: 'Sticker Sheet (Default)', } export const StickerSheetRTL: StickerSheetStory = { ...StickerSheetTemplate, name: 'Sticker Sheet (RTL)', parameters: { textDirection: 'rtl' }, } const PopoverWithPortal = ({ portalClassName, ...props }: Partial> & { portalClassName?: string }): JSX.Element => { const portalRef = useRef(null) const [portalContainer, setPortalContainer] = useState() useEffect(() => { if (portalRef.current !== null) { setPortalContainer(portalRef.current) } }, []) return (
) } const List = ({ items }: { items: string[] }): JSX.Element => (
    {items.map((item) => (
  • {item}
  • ))}
) export const StickerSheetWidth: StickerSheetStory = { name: 'Sticker Sheet (Width)', render: () => (
Content short (min-width) Content long (max-width) Window max-width 250px
), } const itemsLong = [ 'Super long string where the container is fixed width and the selected string goes multiline', 'Another super long string where the container is fixed width and the selected string goes multiline', 'Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5', 'Item 6', 'Item 7', 'Item 8', 'Item 9', 'Item 10', 'Item 11', 'Item 12', 'Item 13', 'Item 14', 'Item 15', ] export const StickerSheetHeight: StickerSheetStory = { name: 'Sticker Sheet (Height)', render: () => (
Content overflow (max-height) Window max-height 250px
), }