import React, { useContext, useState } from 'react'; import Blocks from './Blocks'; import { ChevronDownIcon } from '@heroicons/react/solid'; import Context from './Context'; import Field from '../Form/Field'; import { FieldContext } from '../../Contexts'; import { TypeBlocks } from './Types'; import _ from 'lodash'; interface Props { name: string; } interface WrapperProps { children: JSX.Element | JSX.Element[]; group: string; activeGroup: string; groupKey: number; setActiveGroup: (state: string) => undefined; } const Wrapper: any = ({ children, group, activeGroup, groupKey, setActiveGroup, }: WrapperProps): JSX.Element | JSX.Element[] => { return group === 'undefined' ? ( children ) : (
{children}
); }; const BlockProperties = ({ name }: Props): JSX.Element => { const { selected } = useContext(Context); const context = useContext(FieldContext); const blocks = context.value ? (context.value as TypeBlocks) : []; const block = blocks.find(({ id }) => id === selected); const index = blocks.findIndex(({ id }) => id === selected); const EditorBlock = Blocks.find(({ name }) => name === block?.type); const fieldGroups = _.groupBy(EditorBlock?.fields, (e) => e.group); const [activeGroup, setActiveGroup] = useState(); return (
{EditorBlock?.name} {EditorBlock?.description ? (
{EditorBlock?.description}
) : null}
{Object.keys(fieldGroups).map((group, groupKey) => { return (
{fieldGroups[group].map((field, key) => { return (
); })}
); })}
); }; export default BlockProperties;