import * as React from "react"; import styled from "styled-components"; import { has } from "lodash"; import theme from "@sc/components/ui/theme"; import { SectionsLegendProps } from "./types"; import SectionItem from "./SectionItem"; import { DragDropContext, Droppable, Draggable } from "react-beautiful-dnd"; import { Icon, IconTypes } from "@sc/plugins/webcomponents/v2/Icon"; import { EditorObjectState } from "@sc/modules/v2/Editor/components/EditorObject/types"; const styles = { container: { border: `1px solid #DDD`, borderRadius: 4, }, }; const StyledButton = styled.button` width: 100%; padding: 10px; margin-top: 20px; background-color: white; border: 1px solid #ddd; border-bottom-width: 2px; border-radius: 4px; cursor: pointer; color: ${theme.primaryColor}; &:hover { background-color: #f4f4f4; } `; /** * A quick at-a-glance way to see a manage all the sections on that page * * - • As a user I would like to see all the sections on my page... * - • As a user I would like a way to easily open the [Add New Section] drawer * - • As a user I would like to reorder them up and down using drag-and-drop and have the order immediately reflected in the editor canvas * - • As a user I would like to toggle between seeing and not seeing this view in case I want to focus only on the editor canvas * - • As a user I would like the section in the editor canvas to highlight when i mouse over * - • As a user I would like the section in the editor canvas to activate when I click on the section */ const SectionsLegend: React.FC = ({ title = "Page Sections", sections = [], onChange = () => null, onCreate = () => null, onChangeState = () => null, style = {}, }) => { const [isVisible, setIsVisible] = React.useState(true); const pageSections = sections; /** * Shows or Hides the component * @params */ const showHideToggle = (): void => { setIsVisible(!isVisible); }; // this will re-order the sections // const onDragEnd = (result) => { // if (!result.destination) return; // console.log({ result }); // const sIndex = result.source.index; // const dIndex = result.destination.index; // // remove source item // const withoutSource = pageSections.filter((itm, k) => k !== sIndex); // // add source item next to destination item // const content = [ // ...withoutSource.slice(0, dIndex), // pageSections[sIndex], // ...withoutSource.slice(dIndex), // ]; // onChange(content); // }; const onDragEnd = (result) => { if (!result.destination) return; const sourceItem = pageSections[result.source.index]; const destinationItem = pageSections[result.destination.index]; onChange(sourceItem.id, destinationItem.id); }; return (
{isVisible &&

{title.toUpperCase()}

}
{isVisible && ( <> {(provided, snapshot) => (
{pageSections.map((section, key) => ( {(provided, snapshot) => (
onChangeState( section.id, EditorObjectState.HOVER ) } onMouseLeave={() => onChangeState( section.id, EditorObjectState.NORMAL ) } onClick={() => onChangeState( section.id, EditorObjectState.ACTIVE ) } />
)}
))} {provided.placeholder}
)}
)}
Add New Section
); }; export default SectionsLegend;