import { useState } from 'react'
import type { Meta, StoryObj } from '@storybook/react-vite'
import { Button } from './Button'
import { Lightbox } from './Lightbox'
/** A drawn picture rather than a photograph, so the story needs no network. */
const svg = (w: number, h: number, body: string) =>
`data:image/svg+xml;utf8,${encodeURIComponent(
``,
)}`
const WIDE = svg(
960,
540,
``,
)
const TALL = svg(
540,
960,
``,
)
const meta = {
title: 'Overlays/Lightbox',
component: Lightbox,
parameters: {
layout: 'fullscreen',
// Portals a full-screen overlay to document.body — render in an iframe on
// the Docs page so it does not cover the docs.
docs: { story: { inline: false, height: '520px' } },
},
args: {
src: WIDE,
alt: 'checkout-flow.png',
onClose: () => {},
},
} satisfies Meta
export default meta
type Story = StoryObj
/**
* A wide picture, as large as the screen allows and never larger: it is
* contained, so nothing is cropped and nothing is stretched.
*/
export const APicture: Story = {}
/** A tall one in the same viewer — the height is what runs out first. */
export const ATallPicture: Story = { args: { src: TALL, alt: 'signup-screen.png' } }
/**
* **Open it and close it**, which is the whole point of the part.
*
* Escape closes it, so does the ✕ and so does a press on the scrim — a press on
* the picture does not. Focus is trapped while it is open and returns to the
* button that opened it, which is what neither hand-built viewer did.
*/
export const OpenAndClose: Story = {
parameters: { controls: { disable: true } },
render: (args) => {
const [open, setOpen] = useState(false)
return (