DynamicText.js
44 lines
| 1 | const { __ } = wp.i18n; |
| 2 | const { TextareaControl } = wp.components; |
| 3 | const { useState } = wp.element; |
| 4 | |
| 5 | export default ({ text, update, onFocus }) => { |
| 6 | const [more, setMore] = useState(false); |
| 7 | |
| 8 | return ( |
| 9 | <div style={{ display: "block", width: "100%" }}> |
| 10 | <TextareaControl |
| 11 | label="Text" |
| 12 | help={ |
| 13 | <span> |
| 14 | {__("This field accepts", "presto-player")}{" "} |
| 15 | <a |
| 16 | href="#" |
| 17 | onClick={(e) => { |
| 18 | setMore(!more); |
| 19 | e.preventDefault(); |
| 20 | }} |
| 21 | > |
| 22 | {__("Dynamic Data", "presto-player")} |
| 23 | </a> |
| 24 | {!!more && ( |
| 25 | <div style={{ marginTop: "20px" }}> |
| 26 | {__( |
| 27 | "This field will also accept dynamic values that we will replace with dynamic content: {user.user_login}, {user.user_nicename}, {user.user_email}, {user.user_url},{user.user_registered}, {user.display_name}, {site.url}, {site.name}, {ip_address}", |
| 28 | "presto-player" |
| 29 | )} |
| 30 | </div> |
| 31 | )} |
| 32 | </span> |
| 33 | } |
| 34 | className={"presto-player__overlay--text"} |
| 35 | placeholder={__("Enter some text.", "presto-player")} |
| 36 | value={text || ""} |
| 37 | onChange={(text) => update({ text })} |
| 38 | autoComplete="off" |
| 39 | onFocus={onFocus} |
| 40 | /> |
| 41 | </div> |
| 42 | ); |
| 43 | }; |
| 44 |