import * as React from "react"; import { DragSource } from "react-dnd"; import styled from "styled-components"; import Button from "@material-ui/core/Button"; import IconButton from "@material-ui/core/IconButton"; import PreviewIcon from "@material-ui/icons/Visibility"; import AddIcon from "@material-ui/icons/Add"; import Tooltip from "@material-ui/core/Tooltip"; import theme from "@sc/components/ui/theme"; import { SectionPreviewProps } from "./types"; // import { Popup } from "@sc/plugins/webcomponents/v2"; const Container = styled.li` position: relative; border-radius: 4px; transition: 0.25s; cursor: move; list-style: none; text-align: left; border: 1px solid rgb(0, 0, 0, 0.1); `; const Label = styled.span` position: absolute; display: inline-block; bottom: 0; padding: 10px; margin: 10px; background-color: rgb(100, 100, 100, 0.5); color: #f3f3f3; border-radius: 4px; text-transform: uppercase; font-size: 10pt; font-weight: bold; `; const PreviewIconButton = styled.span` color: white; position: relative; top: 3px; &:hover { color: ${theme.secondaryColor}; } `; const ActionBar = styled.div` position: absolute; top: 0; padding: 10px; width: 100%; height: 80px; text-align: right; border-radius: 4px; background-image: linear-gradient( rgb(0, 0, 0, 0.3), rgb(0, 0, 0, 0.3), rgb(0, 0, 0, 0) ); `; const CURSOR_ID = 1111; const componentSource = { beginDrag(props) { return { ...props }; }, endDrag(props, monitor) { props.onAddSection(props.layout, CURSOR_ID); // props.onClose(); }, }; /** * A component for previewing blocks/sections -- Generates a picture of the provided component layout if a preview isn't provided */ const SectionPreview: React.FC = ({ label, layout, previewImage, onAddSection, connectDragSource, }) => { const [isHovering, setIsHovering] = React.useState(false); const [previewPopupIsShowing, setPreviewPopupIsShowing] = React.useState< boolean >(false); /** * Triggers when the [preview] button is clicked. Will show a popup window with a larger view of the section that will be added * @params */ const handlePreviewSection = (): void => { setPreviewPopupIsShowing(true); }; return connectDragSource(
setIsHovering(true)} onMouseLeave={() => setIsHovering(false)} onDoubleClick={() => onAddSection(layout)} > {previewPopupIsShowing && (
--- Popup Content --- {/* */}
)} {isHovering && ( <> {/* */} )}
); }; export default DragSource("box", componentSource, (connect, monitor) => ({ connectDragSource: connect.dragSource(), isDragging: monitor.isDragging(), }))(SectionPreview);