| 1 |
import { WaitingOverlay } from '@auto-launch/components/Waiting'; |
| 2 |
import { ActionButton, SecondaryButton } from '@auto-launch/templates/button'; |
| 3 |
import { forwardRef } from '@wordpress/element'; |
| 4 |
import { pencil } from '@wordpress/icons'; |
| 5 |
import classNames from 'classnames'; |
| 6 |
|
| 7 |
export const DescriptionForm = ({ |
| 8 |
showTitle, |
| 9 |
title, |
| 10 |
onTitleChange, |
| 11 |
description, |
| 12 |
onDescriptionChange, |
| 13 |
descriptionRef, |
| 14 |
placeholder, |
| 15 |
submitLabel, |
| 16 |
submitDisabled, |
| 17 |
onSubmit, |
| 18 |
showEnhance, |
| 19 |
enhanceDisabled, |
| 20 |
onEnhance, |
| 21 |
consentTerms, |
| 22 |
waiting, |
| 23 |
waitingMessage, |
| 24 |
strings, |
| 25 |
autoFocus = true, |
| 26 |
}) => ( |
| 27 |
<> |
| 28 |
{/* biome-ignore lint: allow onClick without keyboard */} |
| 29 |
<form |
| 30 |
onSubmit={onSubmit} |
| 31 |
onClick={() => descriptionRef?.current?.focus()} |
| 32 |
className="relative flex w-full flex-col gap-ui-section" |
| 33 |
aria-busy={waiting} |
| 34 |
> |
| 35 |
<WaitingOverlay show={waiting} message={waitingMessage} /> |
| 36 |
{showTitle && ( |
| 37 |
<TitleField |
| 38 |
autoFocus={autoFocus} |
| 39 |
value={title} |
| 40 |
onChange={onTitleChange} |
| 41 |
label={strings.titleLabel} |
| 42 |
placeholder={strings.titlePlaceholder} |
| 43 |
/> |
| 44 |
)} |
| 45 |
<div className="flex w-full flex-col"> |
| 46 |
{showTitle && <DescriptionLabel label={strings.descriptionLabel} />} |
| 47 |
<div className="w-full rounded-ui-card border-ui border-ui-line bg-ui-surface text-ui-ink backdrop-blur-ui focus-within:border-ui-focus focus-within:ring-ui-focus shadow-ui overflow-hidden"> |
| 48 |
<DescriptionField |
| 49 |
ref={descriptionRef} |
| 50 |
value={description} |
| 51 |
onChange={onDescriptionChange} |
| 52 |
placeholder={placeholder} |
| 53 |
autoFocus={autoFocus && !showTitle} |
| 54 |
/> |
| 55 |
<div |
| 56 |
className={classNames('flex items-end gap-ui p-ui', { |
| 57 |
'justify-between': showEnhance, |
| 58 |
'justify-end': !showEnhance, |
| 59 |
})} |
| 60 |
> |
| 61 |
{showEnhance && ( |
| 62 |
<EnhanceButton |
| 63 |
disabled={enhanceDisabled} |
| 64 |
onClick={onEnhance} |
| 65 |
label={strings.enhance} |
| 66 |
/> |
| 67 |
)} |
| 68 |
<ActionButton |
| 69 |
type="submit" |
| 70 |
label={submitLabel} |
| 71 |
disabled={submitDisabled} |
| 72 |
/> |
| 73 |
</div> |
| 74 |
</div> |
| 75 |
</div> |
| 76 |
</form> |
| 77 |
<ConsentNotice terms={consentTerms} /> |
| 78 |
</> |
| 79 |
); |
| 80 |
|
| 81 |
export const TitleField = ({ |
| 82 |
value, |
| 83 |
onChange, |
| 84 |
autoFocus, |
| 85 |
label, |
| 86 |
placeholder, |
| 87 |
}) => ( |
| 88 |
<div className="w-full"> |
| 89 |
<label |
| 90 |
htmlFor="extendify-launch-site-title" |
| 91 |
className="mb-ui-label block px-2 text-ui-body font-medium leading-ui text-ui-page-text" |
| 92 |
> |
| 93 |
{label} |
| 94 |
</label> |
| 95 |
<div className="w-full rounded-ui-input border-ui border-ui-line bg-ui-surface text-ui-ink backdrop-blur-ui focus-within:border-ui-focus focus-within:ring-ui-focus shadow-ui overflow-hidden"> |
| 96 |
<input |
| 97 |
id="extendify-launch-site-title" |
| 98 |
type="text" |
| 99 |
className="w-full bg-transparent text-ui-body font-medium leading-ui font-ui-input placeholder:text-ui-ink-muted placeholder:font-normal focus:shadow-none focus:outline-hidden border-none text-ui-ink px-ui py-4" |
| 100 |
// biome-ignore lint: Allow autofocus here |
| 101 |
autoFocus={autoFocus} |
| 102 |
autoComplete="off" |
| 103 |
data-1p-ignore |
| 104 |
value={value} |
| 105 |
// the form's onClick refocuses the textarea; keep clicks here local |
| 106 |
onClick={(e) => e.stopPropagation()} |
| 107 |
onChange={(e) => onChange?.(e.target.value)} |
| 108 |
placeholder={placeholder} |
| 109 |
/> |
| 110 |
</div> |
| 111 |
</div> |
| 112 |
); |
| 113 |
|
| 114 |
export const DescriptionLabel = ({ label }) => ( |
| 115 |
<label |
| 116 |
htmlFor="extendify-launch-chat-textarea" |
| 117 |
className="mb-ui-label block px-2 text-ui-body font-medium leading-ui text-ui-page-text" |
| 118 |
> |
| 119 |
{label} |
| 120 |
</label> |
| 121 |
); |
| 122 |
|
| 123 |
export const DescriptionField = forwardRef( |
| 124 |
({ value, onChange, placeholder, autoFocus }, ref) => ( |
| 125 |
<textarea |
| 126 |
ref={ref} |
| 127 |
id="extendify-launch-chat-textarea" |
| 128 |
className="flex min-h-40 md:min-h-24 w-full resize-none bg-transparent text-ui-body leading-ui font-ui-input placeholder:text-ui-ink-muted focus:shadow-none focus:outline-hidden border-none text-ui-ink p-ui pb-0" |
| 129 |
rows="1" |
| 130 |
// biome-ignore lint: Allow autofocus here |
| 131 |
autoFocus={autoFocus} |
| 132 |
autoComplete="off" |
| 133 |
data-1p-ignore |
| 134 |
value={value} |
| 135 |
onChange={(e) => onChange?.(e.target.value)} |
| 136 |
placeholder={placeholder} |
| 137 |
/> |
| 138 |
), |
| 139 |
); |
| 140 |
|
| 141 |
export const EnhanceButton = ({ disabled, onClick, label }) => ( |
| 142 |
<SecondaryButton |
| 143 |
icon={pencil} |
| 144 |
label={label} |
| 145 |
disabled={disabled} |
| 146 |
onClick={onClick} |
| 147 |
/> |
| 148 |
); |
| 149 |
|
| 150 |
export const ConsentNotice = ({ terms }) => ( |
| 151 |
<div |
| 152 |
className="text-pretty text-center leading-4 opacity-70 text-ui-page-text [&>a]:text-ui-page-text [&>a]:underline w-full [margin-block-start:var(--ext-ui-consent-gap,16px)] [font-size:var(--ext-ui-consent-size,12px)] [&>a]:[font-size:var(--ext-ui-consent-size,12px)]" |
| 153 |
dangerouslySetInnerHTML={{ __html: terms }} |
| 154 |
/> |
| 155 |
); |
| 156 |
|