PluginProbe
Extendify / 1.9.0
Extendify v1.9.0
3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 0.7.0 All 126 releases
extendify / src / Draft / components / Input.js

Input.js in Extendify 1.9.0, at src/Draft/components/Input.js

84 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { Spinner } from '@wordpress/components'
2 import { __ } from '@wordpress/i18n'
3 import { arrowRight, Icon } from '@wordpress/icons'
4 import { DynamicTextarea } from '@draft/components/DynamicTextarea'
5 import { magic } from '@draft/svg'
6 import classnames from 'classnames'
7
8 export const Input = ({
9 inputText,
10 setInputText,
11 ready,
12 setReady,
13 setPrompt,
14 loading,
15 }) => {
16 const submit = (event) => {
17 event.preventDefault()
18
19 if (!ready || loading) return
20
21 setPrompt({
22 text: inputText,
23 promptType: 'create',
24 systemMessageKey: 'generate',
25 })
26 setInputText('')
27 setReady(false)
28 }
29
30 return (
31 <form className="relative flex items-start" onSubmit={submit}>
32 <Icon
33 icon={magic}
34 className="text-design-main fill-current w-5 h-5 absolute left-2 top-3"
35 />
36 <DynamicTextarea
37 disabled={loading}
38 placeholder={
39 loading
40 ? __('AI is writing...', 'extendify')
41 : __('Ask AI to generate text', 'extendify')
42 }
43 value={inputText}
44 className="bg-transparent border-none shadow-none w-full h-full px-10 py-3 overflow-hidden resize-none"
45 onChange={(event) => {
46 setInputText(event.target.value)
47 setReady(event.target.value.length > 0)
48 }}
49 onKeyDown={(event) => {
50 if (event.key === 'Enter' && !event.shiftKey) {
51 event.preventDefault()
52 submit(event)
53 }
54 }}
55 />
56 {loading && (
57 <div className="text-gray-700 absolute right-4 w-4 h-4 p-1 mt-2.5">
58 <Spinner style={{ margin: '0' }} />
59 </div>
60 )}
61 {!loading && (
62 <button
63 type="submit"
64 disabled={!ready}
65 aria-label={__('Submit', 'extendify')}
66 className={classnames(
67 'bg-transparent border-none absolute right-2 p-0 mt-2.5',
68 {
69 'cursor-pointer text-gray-700 hover:text-design-main':
70 ready,
71 'text-gray-500': !ready,
72 },
73 )}>
74 <Icon
75 icon={arrowRight}
76 onClick={submit}
77 className="fill-current w-6 h-6"
78 />
79 </button>
80 )}
81 </form>
82 )
83 }
84