import React, { useCallback, useRef, useState } from "react"; import Button from "../../Button/Button"; import Modal from "../Modal"; import { Dialog, DialogContentContainer, Heading } from "../../../components"; import Flex from "../../Flex/Flex"; import { DEFAULT_DIALOG_SHOW_TRIGGER } from "../../SplitButton/SplitButtonConstants"; import ModalFooterButtons from "../ModalFooter/ModalFooterButtons/ModalFooterButtons"; import styles from "./Modal.stories.module.scss"; import cx from "classnames"; import { StorybookLink, Tip } from "vibe-storybook-components"; // internal custom hook to help with writing tests and stories. export const useHelperOpenModalButton = ({ title = "Open modal", setShow, openModalButtonRef, color = undefined, testId = undefined }: any) => { return ( ); }; // Internal component for create all boilerplate needed for implementing modal example to the "Do and don't" section export const ModalExampleWrapper = ({ bestPractice, modalTitle, buttonTitle, children, hideFooter, show: defaultShow = false, openModalTestId, ...otherModalProps }: any) => { // Control if modal is display or hidden const [show, setShow] = useState(defaultShow); const openModalButtonRef = useRef(null); const closeModal = useCallback(() => { setShow(false); }, []); const openModalColor = bestPractice ? Button.colors.POSITIVE : Button.colors.NEGATIVE; const openModalButton = useHelperOpenModalButton({ testId: openModalTestId, title: buttonTitle || modalTitle, setShow, openModalButtonRef, color: openModalColor }); const footer = hideFooter ? null : ( ); return ( <> {openModalButton} ); }; export const DialogAsModalBadExample = () => { const [show, setShow] = useState(false); const closeDialog = useCallback(() => { setShow(false); }, []); const onShow = useCallback(() => { setShow(true); }, []); const dialogContent = ( Dialog content ); return ( ); }; export const TipAlertDialog = () => ( Set alertDialog to true in order to allow closing the modal only by the close buttons and not by ESC or by clicking outside. ); export const TipDialog = () => ( For creating a popover positioned next to other components, like customized menus, check out our{" "} Dialog {" "} component. ); export const TipDevDropdownInsideModal = () => ( {`If you wish to implement a dropdown inside a Modal container and need help displaying the dropdown's popovers correctly, read more about our dropdown in popovers technical pattern `} here. );