Custom Property Editor allows you to create custom editing fields for elements in YayMail. This guide will help you understand how to implement and use custom property editors effectively.
Copy function admin_enqueue_scripts( $hook_suffix ) {
if ( in_array( $hook_suffix, [ 'yaycommerce_page_yaymail-settings' ], true ) && class_exists( 'WC_Emails' ) ) {
\YayMail\Utils\YayMailViteApp::get_instance()->enqueue_entry( 'yaymail-addon.tsx', [ 'react', 'react-dom' ] );
}
}
add_action( 'admin_enqueue_scripts', 'admin_enqueue_scripts' );
Copy // yaymail-addon.tsx
import YourCustomEditor from './elements/YourCustomEditor';
document.addEventListener('yaymail-loaded', (event) => {
window.yaymailData.shared?.stores?.useAddonStore
?.getState()
.registerAddonCustomPropertyEditor({
name: 'addon_your_custom_editor', // Must start with 'addon_'
component: YourCustomEditor
});
});
Copy // elements/YourCustomEditor.tsx
import { PropertyBuilderComponentType } from '@src/features/email-customizer/components/sidebar/element-editor/types';
interface YourCustomEditorProps {
data: {
value_path?: string;
title?: string;
default_value?: any;
extras_data?: any;
};
}
const YourCustomEditor: PropertyBuilderComponentType<YourCustomEditorProps> = ({ data }) => {
const { title, default_value, extras_data } = data;
const updateChosenElementData = useTemplateContentStore(
(state) => state.updateChosenElementData
);
const handleChange = (value: any) => {
updateChosenElementData(
(draftData: any) => {
draftData[data.value_path] = value;
},
{ attribute: data.title }
);
};
return (
<div className="yaymail-editor-property">
<div className="yaymail-title">{title}</div>
{/* Your custom editor UI */}
<input
type="text"
value={default_value}
onChange={(e) => handleChange(e.target.value)}
/>
</div>
);
};
export default YourCustomEditor;