import { RichText, InspectorControls } from '@wordpress/block-editor'; import { createBlock } from '@wordpress/blocks'; import { BaseControl, Button, CustomSelectControl, DatePicker, Dropdown, TextControl, PanelBody, } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import clsx from 'clsx'; import moment from 'moment'; import './editor.scss'; const name = 'a8c/task'; const edit = ( { attributes, setAttributes, mergeBlocks, onReplace, className } ) => { const { assignedTo, content, placeholder, status, dueDate, startDate } = attributes; const todoClass = clsx( 'wp-block-todo', className, { 'is-checked': status === 'done' } ); const options = [ { key: 'new', name: 'New', }, { key: 'in-progress', name: 'In Progress', }, { key: 'done', name: 'Done', }, ]; const dueDateDisplay = dueDate ? moment( dueDate ).format( 'll' ) : ''; const startDateDisplay = startDate ? moment( startDate ).format( 'll' ) : ''; return ( <> option.key === status ) || options[ 0 ] } onChange={ ( value ) => setAttributes( { status: value.selectedItem.key } ) } /> setAttributes( { assignedTo: value } ) } /> ( <> { startDate ? ( ) : ( ) } ) } renderContent={ () => ( setAttributes( { startDate: date } ) } /> ) } /> ( ) } renderContent={ () => ( setAttributes( { dueDate: date } ) } /> ) } />
{ ( status === 'done' || status === 'new' ) && ( ) } setAttributes( { content: value } ) } onMerge={ mergeBlocks } onSplit={ ( value ) => { if ( ! content.length ) { return createBlock( 'core/paragraph' ); } if ( ! value ) { return createBlock( name ); } return createBlock( name, { ...attributes, content: value, } ); } } onReplace={ onReplace } onRemove={ onReplace ? () => onReplace( [] ) : undefined } className={ className } placeholder={ placeholder || __( 'Add task…' ) } /> { assignedTo && (
@{ assignedTo } { assignedTo[ 0 ] }
) } { dueDate && ( ( ) } renderContent={ () => ( setAttributes( { dueDate: date } ) } /> ) } /> ) }
); }; export default edit;