import { __ } from '@wordpress/i18n'; import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; import { PanelBody, ToggleControl, SelectControl, __experimentalInputControl as InputControl, } from '@wordpress/components'; export const edit = ( props ) => { const { attributes, setAttributes, context } = props; const blockProps = useBlockProps(); const { lpCourseData } = context; const courseImage = lpCourseData?.image || '
course thumbnail placeholder'; const sizeOption = [ { label: 'Thumbnail', value: 'thumbnail' }, { label: 'Medium', value: 'medium' }, { label: 'Large', value: 'large' }, { label: 'Full', value: 'full' }, { label: 'Custom', value: 'custom' }, ]; const getStyledCourseImage = () => { if ( lpCourseData?.image && attributes.size === 'custom' && attributes.customWidth === 500 && attributes.customHeight === 300 ) { return lpCourseData?.image; } let width = 2560; let height = 2560; if ( attributes.size === 'thumbnail' ) { width = 150; height = 150; } if ( attributes.size === 'medium' ) { width = 300; height = 300; } if ( attributes.size === 'large' ) { width = 1024; height = 724; } if ( attributes.size === 'full' ) { width = 2560; height = 2560; } if ( attributes.size === 'custom' ) { if ( attributes.customWidth && attributes.customWidth > 0 ) { width = attributes.customWidth; } if ( attributes.customHeight && attributes.customHeight > 0 ) { height = attributes.customHeight; } if ( attributes.customWidth == 0 ) { width = 2560; } if ( attributes.customHeight == 0 ) { width = 2560; } } const ratio = width / height; return `
course thumbnail placeholder`; }; return ( <> { if ( value !== 'custom' ) { setAttributes( { customWidth: 500, customHeight: 300 } ); } setAttributes( { size: value } ); } } /> { props.attributes.size === 'custom' ? (
{ __( 'px', 'learnpress' ) }
} value={ props.attributes.customWidth } onChange={ ( value ) => { const numValue = parseInt( value, 10 ); if ( ! isNaN( Number( numValue ) ) && numValue >= 0 ) { setAttributes( { customWidth: Number( numValue ) } ); } else { setAttributes( { customWidth: 500 } ); } } } /> { __( 'px', 'learnpress' ) }
} value={ props.attributes.customHeight } onChange={ ( value ) => { const numValue = parseInt( value, 10 ); if ( ! isNaN( Number( numValue ) ) && numValue >= 0 ) { setAttributes( { customHeight: Number( numValue ) } ); } else { setAttributes( { customHeight: 300 } ); } } } />
) : ( '' ) } { props.setAttributes( { isLink: value ? true : false, } ); } } /> { props.attributes.isLink ? ( { props.setAttributes( { target: value ? true : false, } ); } } /> ) : ( '' ) }
); };