PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / trunk
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses vtrunk
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / assets / src / apps / js / blocks / course-elements / course-title / edit.js

edit.js in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses trunk, at assets/src/apps/js/blocks/course-elements/course-title/edit.js

80 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { __ } from '@wordpress/i18n';
2 import { useBlockProps, InspectorControls } from '@wordpress/block-editor';
3 import { RawHTML } from '@wordpress/element';
4 import { PanelBody, SelectControl, ToggleControl } from '@wordpress/components';
5
6 const Edit = ( props ) => {
7 const { attributes, setAttributes, context } = props;
8 const { tag, isLink, target } = attributes;
9 const blockProps = useBlockProps();
10 const { lpCourseData } = context;
11 const tagOptions = [
12 { label: 'span', value: 'span' },
13 { label: 'div', value: 'div' },
14 { label: 'h1', value: 'h1' },
15 { label: 'h2', value: 'h2' },
16 { label: 'h3', value: 'h3' },
17 { label: 'h4', value: 'h4' },
18 { label: 'h5', value: 'h5' },
19 { label: 'h6', value: 'h6' },
20 ];
21 const courseTitle = lpCourseData?.title || __( 'Course Title', 'learnpress' );
22 const TagName = tag;
23 return (
24 <>
25 <InspectorControls>
26 <PanelBody title={ __( 'Settings', 'learnpress' ) }>
27 <SelectControl
28 label={ __( 'Tag', 'learnpress' ) }
29 value={ tag }
30 options={ tagOptions }
31 onChange={ ( value ) => setAttributes( { tag: value } ) }
32 />
33 <ToggleControl
34 // Default text of WP so not need text-domain
35 label={ __( 'Make the title a link' ) }
36 checked={ !! isLink }
37 onChange={ ( value ) => {
38 props.setAttributes( {
39 isLink: value,
40 } );
41 } }
42 />
43 { props.attributes.isLink ? (
44 <ToggleControl
45 label={ __( 'Open is new tab', 'learnpress' ) }
46 checked={ !! target }
47 onChange={ ( value ) => {
48 props.setAttributes( {
49 target: value,
50 } );
51 } }
52 />
53 ) : (
54 ''
55 ) }
56 </PanelBody>
57 </InspectorControls>
58
59 { props.attributes.isLink ? (
60 <TagName { ...blockProps }>
61 <a
62 dangerouslySetInnerHTML={ {
63 __html: courseTitle,
64 } }
65 ></a>
66 </TagName>
67 ) : (
68 <TagName
69 { ...blockProps }
70 dangerouslySetInnerHTML={ {
71 __html: courseTitle,
72 } }
73 />
74 ) }
75 </>
76 );
77 };
78
79 export default Edit;
80