import React, { useState, useContext } from 'react'; import { SchemaForUI, Size } from '@pdfme/common'; import { ZOOM, RULER_HEIGHT, SIDEBAR_WIDTH } from '../../../constants'; import { I18nContext } from '../../../contexts'; import backIcon from '../../../assets/icons/back.svg'; import forwardIcon from '../../../assets/icons/forward.svg'; import ListView from './ListView'; import DetailView from './DetailView'; export type SidebarProps = { height: number; fields: string[]; hoveringSchemaId: string | null; onChangeHoveringSchemaId: (id: string | null) => void; size: Size; pageSize: Size; activeElements: HTMLElement[]; schemas: SchemaForUI[]; onSortEnd: (sortedSchemas: SchemaForUI[]) => void; onEdit: (id: string) => void; onEditEnd: () => void; changeSchemas: (objs: { key: string; value: string | number; schemaId: string }[]) => void; addSchema: () => void; }; const Sidebar = (props: SidebarProps) => { const { height, size, activeElements, schemas, addSchema } = props; const i18n = useContext(I18nContext); const [open, setOpen] = useState(true); const getActiveSchemas = () => { const ids = activeElements.map((ae) => ae.id); return schemas.filter((s) => ids.includes(s.id)); }; const getLastActiveSchema = () => { const activeSchemas = getActiveSchemas(); return activeSchemas[activeSchemas.length - 1]; }; return (
{getActiveSchemas().length === 0 ? ( ) : ( )}
); }; export default Sidebar;