PluginProbe
Extendify / 3.2.2
Extendify v3.2.2
3.2.2 3.2.1 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 All 128 releases
extendify / src / Draft / components / image-generation / GenerateForm.jsx

GenerateForm.jsx in Extendify 3.2.2, at src/Draft/components/image-generation/GenerateForm.jsx

131 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { CreditCounter } from '@draft/components/image-generation/CreditCounter';
2 import { useImageGenerationStore } from '@shared/state/generate-images';
3 import {
4 Button,
5 CheckboxControl,
6 TextareaControl,
7 __experimentalToggleGroupControl as ToggleGroupControl,
8 __experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon,
9 } from '@wordpress/components';
10 import { __ } from '@wordpress/i18n';
11
12 export const GenerateForm = ({
13 isGenerating,
14 errorMessage,
15 disclose,
16 setDisclose,
17 }) => {
18 const { imageCredits, aiImageOptions, setAiImageOption } =
19 useImageGenerationStore();
20 const usedCredits = imageCredits.total - imageCredits.remaining;
21 const { size, prompt } = aiImageOptions;
22
23 return (
24 <>
25 {isGenerating ? null : (
26 <div className="flex flex-col gap-4">
27 <TextareaControl
28 id="draft-ai-image-textarea"
29 autoFocus
30 placeholder={__(
31 'Tell AI about the image you would like to create',
32 'extendify-local',
33 )}
34 label={__('Image Prompt', 'extendify-local')}
35 hideLabelFromVision
36 rows="7"
37 value={prompt}
38 onChange={(prompt) => setAiImageOption('prompt', prompt)}
39 />
40
41 <ToggleGroupControl
42 isBlock
43 label={__('Aspect Ratio', 'extendify-local')}
44 onChange={(size) => setAiImageOption('size', size)}
45 value={size}
46 >
47 <ToggleGroupControlOptionIcon
48 className="m-auto"
49 type="button"
50 icon={AspectRatioSquare}
51 label={__('Square: 1:1', 'extendify-local')}
52 value="1024x1024"
53 />
54 <ToggleGroupControlOptionIcon
55 className="m-auto"
56 type="button"
57 icon={AspectRatioLandscape}
58 label={__('Landscape: 4:3', 'extendify-local')}
59 value="1536x1024"
60 />
61 <ToggleGroupControlOptionIcon
62 className="m-auto"
63 type="button"
64 icon={AspectRatioPortrait}
65 label={__('Portrait: 3:4', 'extendify-local')}
66 value="1024x1536"
67 />
68 </ToggleGroupControl>
69
70 <CheckboxControl
71 __nextHasNoMarginBottom
72 // translators: Checkbox that adds a visible "AI Generated" mark onto the image.
73 label={__('Label image as AI-generated', 'extendify-local')}
74 checked={disclose}
75 onChange={setDisclose}
76 />
77 </div>
78 )}
79 {errorMessage.length > 0 && (
80 <p className="mb-0 text-red-500">{errorMessage}</p>
81 )}
82 <Button
83 type="submit"
84 className="w-full justify-center"
85 variant="primary"
86 __next40pxDefaultSize
87 disabled={isGenerating || !prompt || usedCredits >= imageCredits.total}
88 >
89 {isGenerating
90 ? __('Generating image...', 'extendify-local')
91 : __('Generate image', 'extendify-local')}
92 </Button>
93 {isGenerating ? null : (
94 <CreditCounter usedCredits={usedCredits} total={imageCredits.total} />
95 )}
96 </>
97 );
98 };
99
100 const AspectRatioLandscape = (
101 <svg xmlns="http://www.w3.org/2000/svg" style={{ padding: '7px 4px' }}>
102 <title>{__('Landscape: 4:3', 'extendify-local')}</title>
103 <path
104 fillRule="evenodd"
105 d="M0 1c0-.552285.447715-1 1-1h14c.5523 0 1 .447715 1 1v8c0 .55228-.4477 1-1 1H1c-.552285 0-1-.44772-1-1V1Z"
106 clipRule="evenodd"
107 />
108 </svg>
109 );
110
111 const AspectRatioPortrait = (
112 <svg xmlns="http://www.w3.org/2000/svg" style={{ padding: '4px 6px' }}>
113 <title>{__('Portrait: 3:4', 'extendify-local')}</title>
114 <path
115 fillRule="evenodd"
116 d="M9.66669 3.5e-7C10.219 3.7e-7 10.6667.447716 10.6667 1v14c0 .5523-.4477 1-1.00001 1h-8c-.55229 0-1.000003-.4477-1.000003-1L.666688 1C.666688.447715 1.1144-2e-8 1.66669 0l8 3.5e-7Z"
117 clipRule="evenodd"
118 />
119 </svg>
120 );
121 const AspectRatioSquare = (
122 <svg xmlns="http://www.w3.org/2000/svg" style={{ padding: '6px' }}>
123 <title>{__('Square: 1:1', 'extendify-local')}</title>
124 <path
125 fillRule="evenodd"
126 d="M11.3333-4e-8c.5523 2e-8 1 .44771504 1 1.00000004v10c0 .5523-.4477 1-1 1H1.33333c-.552283 0-.999998-.4477-.999998-1V.999999C.333332.447715.781047-5e-7 1.33333-4.8e-7L11.3333-4e-8Z"
127 clipRule="evenodd"
128 />
129 </svg>
130 );
131