CTA.js
5 years ago
CheckboxControl.js
5 years ago
CodeMirror.js
5 years ago
ColorPicker.js
5 years ago
ComboboxControl.js
5 years ago
Disabled.js
5 years ago
Fields.js
5 years ago
Group.js
5 years ago
Groups.js
5 years ago
Integration.js
5 years ago
Loading.js
5 years ago
Media.js
5 years ago
NullView.js
5 years ago
Page.js
5 years ago
SaveButton.js
5 years ago
SelectControl.js
5 years ago
TextControl.js
5 years ago
ToggleControl.js
5 years ago
CodeMirror.js
56 lines
| 1 | /** @jsx jsx */ |
| 2 | import { css, jsx } from "@emotion/core"; |
| 3 | const { ColorPicker, BaseControl } = wp.components; |
| 4 | const { dispatch } = wp.data; |
| 5 | const { useEffect, useRef } = wp.element; |
| 6 | import classNames from "classnames"; |
| 7 | |
| 8 | export default ({ option, value, optionName, className, disabled }) => { |
| 9 | let codeMirror; |
| 10 | |
| 11 | const handleChange = (instance) => { |
| 12 | if (disabled) { |
| 13 | return; |
| 14 | } |
| 15 | instance.save(); |
| 16 | dispatch("presto-player/settings").updateSetting( |
| 17 | option.id, |
| 18 | textRef.current.value, |
| 19 | optionName |
| 20 | ); |
| 21 | }; |
| 22 | |
| 23 | const textRef = useRef(); |
| 24 | useEffect(() => { |
| 25 | if (!wp?.CodeMirror) { |
| 26 | return; |
| 27 | } |
| 28 | codeMirror = wp.CodeMirror.fromTextArea(textRef.current, { |
| 29 | type: "text/css", |
| 30 | lineNumbers: true, |
| 31 | }); |
| 32 | |
| 33 | codeMirror.on("change", handleChange); |
| 34 | }, []); |
| 35 | |
| 36 | return ( |
| 37 | <div className={classNames(className, "presto-settings__setting")}> |
| 38 | <BaseControl |
| 39 | css={css` |
| 40 | .CodeMirror { |
| 41 | height: 200px; |
| 42 | border: 1px solid #e3e3e3; |
| 43 | border-radius: 4px; |
| 44 | } |
| 45 | `} |
| 46 | label={option?.name} |
| 47 | help={option?.help} |
| 48 | > |
| 49 | <textarea onChange={handleChange} ref={textRef} rows="5" disabled> |
| 50 | {value} |
| 51 | </textarea> |
| 52 | </BaseControl> |
| 53 | </div> |
| 54 | ); |
| 55 | }; |
| 56 |