import React from "react"; import { createStoryMetaSettingsDecorator } from "../../../storybook"; import { Button, Dialog, DialogContentContainer, Flex, IconButton } from "../../../components"; import { ExampleContent } from "./helpers"; import { Info } from "../../Icon/Icons"; import { closeTriggersInteractionSuite } from "../__tests__/Dialog.interactions"; import { CLICK_OUTSIDE_DIALOG, CLICK_OUTSIDE_DIALOG_BUTTON, CONTEXT_MENU_DIALOG, HIDE_TRIGGERS_CONTAINER } from "../__tests__/DialogDataTestIds"; import useSwitch from "../../../hooks/useSwitch"; import "./Dialog.stories.scss"; import { HideShowEvent } from "../../../constants/dialog"; import { DialogProps } from "../Dialog"; const metaSettings = createStoryMetaSettingsDecorator({ component: Dialog, enumPropNamesArray: [], // List enum props here iconPropNamesArray: [], // List props that are typed as icons here actionPropsArray: [] // List the component's actions here }); const showHideArgTypes = { options: Object.values(HideShowEvent), control: { type: "multi-select" }, table: { type: { summary: Object.values(HideShowEvent).join(" | ") } } }; export default { title: "Popover/Dialog", component: Dialog, argTypes: { ...metaSettings.argTypes, hideTrigger: showHideArgTypes, showTrigger: showHideArgTypes }, decorators: metaSettings.decorators, parameters: { docs: { liveEdit: { scope: { useSwitch, ExampleContent } } } } }; const dialogTemplate = ({ showTrigger, hideTrigger, shouldShowOnMount = true, position, ...dialogProps }: DialogProps) => { // for prevent dialog to move while scrolling const modifiers = [ { name: "preventOverflow", options: { mainAxis: false } } ]; return (
} >
); }; export const Overview = { render: dialogTemplate.bind({}), name: "Overview", parameters: { docs: { liveEdit: { isEnabled: false } } } }; export const Positions = { render: // for prevent dialog to move while scrolling () => { // For maintain active state of each button according to the dialog open state (this hooks is available for your usage) const { isChecked: checkedTop, onChange: onChangeTop } = useSwitch({ defaultChecked: false }); const { isChecked: checkedBottom, onChange: onChangeBottom } = useSwitch({ defaultChecked: false }); const { isChecked: checkedRight, onChange: onChangeRight } = useSwitch({ defaultChecked: false }); const { isChecked: checkedLeft, onChange: onChangeLeft } = useSwitch({ defaultChecked: false }); const modifiers = [ { name: "preventOverflow", options: { mainAxis: false } } ]; return ( } > } > } > } > ); }, name: "Positions" }; export const ShowTriggers = { render: () => { const { isChecked: clickButtonActive, onChange: onClickClickButton } = useSwitch({ defaultChecked: false }); const { isChecked: hoverButtonActive, onChange: onHoverButton } = useSwitch({ defaultChecked: false }); const { isChecked: focusButtonActive, onChange: onFocusButton } = useSwitch({ defaultChecked: false }); const modifiers = [ { name: "preventOverflow", options: { mainAxis: false } } ]; return ( } > } >
} > } >
); }, name: "Show triggers", parameters: { chromatic: { pauseAnimationAtEnd: true } } }; export const HideTriggers = { render: () => { // For maintain active state of each button according to the dialog open state (this hooks is available for your usage) const { isChecked: clickButtonActive, onChange: switchClickButtonActive } = useSwitch({ defaultChecked: true }); const { isChecked: clickOutsideButtonActive, onChange: switchClickOutsideActive } = useSwitch({ defaultChecked: true }); const { isChecked: mouseLeaveButtonActive, onChange: switchMouseLeaveActive } = useSwitch({ defaultChecked: true }); const { isChecked: blurButtonActive, onChange: switchBlurButtonActive } = useSwitch({ defaultChecked: true }); const { isChecked: contentClickButtonActive, onChange: switchContentClickActive } = useSwitch({ defaultChecked: true }); const { isChecked: contextMenuButtonActive, onChange: switchContextMenuActive } = useSwitch({ defaultChecked: true }); // for prevent dialog to move while scrolling const modifiers = [ { name: "preventOverflow", options: { mainAxis: false } } ]; return ( } > } > } > } > } > } > ); }, name: "Hide triggers", play: closeTriggersInteractionSuite, parameters: { chromatic: { pauseAnimationAtEnd: true }, docs: { liveEdit: { scope: { HIDE_TRIGGERS_CONTAINER, CLICK_OUTSIDE_DIALOG, CLICK_OUTSIDE_DIALOG_BUTTON, CONTEXT_MENU_DIALOG } } } } }; export const ControlledDialog = { render: () => { const { isChecked: isOpen, onChange: setIsOpen } = useSwitch({ defaultChecked: false }); return ( } > ); }, name: "Controlled Dialog" }; export const DialogWithTooltip = { // for prevent dialog to move while scrolling render: () => { const modifiers = [ { name: "preventOverflow", options: { mainAxis: false } } ]; return (
} >
); }, name: "Dialog with tooltip", parameters: { docs: { liveEdit: { scope: { Info } } } } }; export const DisableScrollWhenDialogOpen = { render: () => { // For maintain active state of each button according to the dialog open state (this hooks is available for your usage) const { isChecked: checkedTop, onChange: onChangeTop } = useSwitch({ defaultChecked: false }); return (
} >
); }, name: "Disable scroll when dialog open" };