| 1 |
import { __ } from '@wordpress/i18n'; |
| 2 |
import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; |
| 3 |
import { PanelBody, ToggleControl } from '@wordpress/components'; |
| 4 |
|
| 5 |
export const edit = ( props ) => { |
| 6 |
const blockProps = useBlockProps(); |
| 7 |
const { attributes, setAttributes, context } = props; |
| 8 |
const { lpCourseData } = context; |
| 9 |
const courseInstructor = lpCourseData?.instructor || '<strong>Instructor</strong>'; |
| 10 |
return ( |
| 11 |
<> |
| 12 |
<InspectorControls> |
| 13 |
<PanelBody title={ __( 'Settings', 'learnpress' ) }> |
| 14 |
<ToggleControl |
| 15 |
label={ __( "Show text 'by'", 'learnpress' ) } |
| 16 |
checked={ props.attributes.showText ? true : false } |
| 17 |
onChange={ ( value ) => { |
| 18 |
props.setAttributes( { |
| 19 |
showText: value ? true : false, |
| 20 |
} ); |
| 21 |
} } |
| 22 |
/> |
| 23 |
<ToggleControl |
| 24 |
label={ __( 'Make the instructor a link', 'learnpress' ) } |
| 25 |
checked={ props.attributes.isLink ? true : false } |
| 26 |
onChange={ ( value ) => { |
| 27 |
props.setAttributes( { |
| 28 |
isLink: value ? true : false, |
| 29 |
} ); |
| 30 |
} } |
| 31 |
/> |
| 32 |
{ props.attributes.isLink ? ( |
| 33 |
<ToggleControl |
| 34 |
label={ __( 'Open is new tab', 'learnpress' ) } |
| 35 |
checked={ props.attributes.target ? true : false } |
| 36 |
onChange={ ( value ) => { |
| 37 |
props.setAttributes( { |
| 38 |
target: value ? true : false, |
| 39 |
} ); |
| 40 |
} } |
| 41 |
/> |
| 42 |
) : ( |
| 43 |
'' |
| 44 |
) } |
| 45 |
</PanelBody> |
| 46 |
</InspectorControls> |
| 47 |
<div { ...blockProps }> |
| 48 |
<div className="is-layout-flex c-gap-4"> |
| 49 |
<label>{ props.attributes.showText ? 'by ' : '' }</label> |
| 50 |
<div className="course-instructor"> |
| 51 |
{ props.attributes.isLink ? ( |
| 52 |
<a |
| 53 |
dangerouslySetInnerHTML={ { |
| 54 |
__html: courseInstructor, |
| 55 |
} } |
| 56 |
></a> |
| 57 |
) : ( |
| 58 |
<div |
| 59 |
dangerouslySetInnerHTML={ { |
| 60 |
__html: courseInstructor, |
| 61 |
} } |
| 62 |
></div> |
| 63 |
) } |
| 64 |
</div> |
| 65 |
</div> |
| 66 |
</div> |
| 67 |
</> |
| 68 |
); |
| 69 |
}; |
| 70 |
|