import { useFormBuilderContext } from '@admin/context/FormBuilderContext'; import { Button } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import styled from 'styled-components'; import { applyFilters } from '@wordpress/hooks'; import EditInput from './EditInput'; import EditDropdown from './EditDropdown'; import EditCheckbox from './EditCheckbox'; import EditContent from './EditContent'; import EditSubmit from './EditSubmit'; import FieldList from './FieldList'; const screenKeys = [ 'email', 'tel', 'text', 'date', 'select', 'checkbox', 'wysiwyg', 'submit', 'textarea', ] as const; type ScreenType = (typeof screenKeys)[number]; const BuilderSettingsWrapper = styled.div` padding: var(--ptr-admin-spacing-md); border-radius: 8px; border: 1px solid rgba(00, 00, 00, 0.1); background-color: var(--ptr-admin-color-light); position: relative; h3, p { margin-top: 0; margin-bottom: var(--ptr-admin-spacing-md); } button { margin-bottom: var(--ptr-admin-spacing-md); } `; export default function BuilderSettings() { const { formBuilderFields, builderEditScreen, setBuilderEditScreen } = useFormBuilderContext(); const currentField = formBuilderFields[builderEditScreen]; const currentType = currentField?.type; const screens: Record React.ReactNode> = { email: () => , tel: () => , text: () => , date: () => , textarea: () => , select: () => , checkbox: () => , wysiwyg: () => , submit: () => , default: () => , }; const ScreenComponent = () => { const DefaultComponent = screenKeys.includes(currentType as ScreenType) ? screens[currentType as ScreenType] : screens.default; /** * Apply any additional edit screen components for the current field * This allows custom components to be used for specific field types or field keys * * @param component The default component to be overridden * @param currentField The current field being edited * @param builderEditScreen The screen key of the current field * @returns The final component to be rendered */ const FinalScreenComponent = applyFilters( 'petitioner.formBuilder.editScreenComponent', DefaultComponent, currentField, builderEditScreen ) as () => React.ReactNode; if (typeof FinalScreenComponent !== 'function') { return ; } return ; }; return ( {builderEditScreen != 'default' && ( <>

{__('Editing: ', 'petitioner')} {currentField?.fieldName}

{__( 'Edit the properties of this field below.', 'petitioner' )}

)}
); }