| 1 |
import { useUserSelectionStore } from '@launch/state/user-selections.js'; |
| 2 |
import { __ } from '@wordpress/i18n'; |
| 3 |
import classNames from 'classnames'; |
| 4 |
|
| 5 |
export const TONES = [ |
| 6 |
{ |
| 7 |
label: __('Professional', 'extendify-local'), |
| 8 |
value: 'professional', |
| 9 |
}, |
| 10 |
{ |
| 11 |
label: __('Friendly', 'extendify-local'), |
| 12 |
value: 'friendly', |
| 13 |
}, |
| 14 |
{ |
| 15 |
label: __('Inspirational', 'extendify-local'), |
| 16 |
value: 'inspirational', |
| 17 |
}, |
| 18 |
{ |
| 19 |
label: __('Informative', 'extendify-local'), |
| 20 |
value: 'informative', |
| 21 |
}, |
| 22 |
{ |
| 23 |
label: __('Persuasive', 'extendify-local'), |
| 24 |
value: 'persuasive', |
| 25 |
}, |
| 26 |
]; |
| 27 |
|
| 28 |
export const SiteTones = () => { |
| 29 |
const { businessInformation, setBusinessInformation } = |
| 30 |
useUserSelectionStore(); |
| 31 |
|
| 32 |
const handleTonesToggle = (tone) => { |
| 33 |
const { tones } = businessInformation; |
| 34 |
const isSelected = !!tones?.find(({ value }) => value === tone.value); |
| 35 |
const newTones = isSelected |
| 36 |
? tones?.filter(({ value }) => value !== tone.value) |
| 37 |
: [...tones, tone]; |
| 38 |
setBusinessInformation('tones', newTones); |
| 39 |
}; |
| 40 |
|
| 41 |
return ( |
| 42 |
<div> |
| 43 |
<p className="m-0 text-lg font-medium leading-8 text-gray-900 md:text-base md:leading-10"> |
| 44 |
{__("Select your site's tone", 'extendify-local')} |
| 45 |
</p> |
| 46 |
<div className="justify-left flex w-full flex-wrap gap-2"> |
| 47 |
{TONES.map((tone) => { |
| 48 |
const selected = businessInformation?.tones?.find( |
| 49 |
({ value }) => value === tone.value, |
| 50 |
); |
| 51 |
|
| 52 |
return ( |
| 53 |
<div |
| 54 |
key={tone.value} |
| 55 |
className={classNames( |
| 56 |
'relative rounded-sm border border-gray-300', |
| 57 |
{ |
| 58 |
'bg-gray-100': selected, |
| 59 |
'border-gray-300': !selected, |
| 60 |
}, |
| 61 |
)} |
| 62 |
> |
| 63 |
<label |
| 64 |
htmlFor={tone.value} |
| 65 |
className="flex h-full w-full cursor-pointer items-center justify-between rounded-xs p-2 text-gray-900 focus-within:ring-wp" |
| 66 |
> |
| 67 |
<div className="flex flex-auto items-center"> |
| 68 |
<span className="relative mr-1 inline-block h-4 w-4 align-middle rtl:ml-1 rtl:mr-0"> |
| 69 |
<input |
| 70 |
id={tone.value} |
| 71 |
className="h-4 w-4 rounded-xs focus:ring-0 focus:ring-offset-0" |
| 72 |
type="checkbox" |
| 73 |
onChange={() => handleTonesToggle(tone)} |
| 74 |
checked={ |
| 75 |
!!businessInformation.tones?.find( |
| 76 |
({ value }) => value === tone.value, |
| 77 |
) |
| 78 |
} |
| 79 |
/> |
| 80 |
<svg |
| 81 |
className={classNames( |
| 82 |
'absolute inset-0 -mt-px block h-4 w-4', |
| 83 |
{ |
| 84 |
'text-white': selected, |
| 85 |
'text-transparent': !selected, |
| 86 |
}, |
| 87 |
)} |
| 88 |
viewBox="1 0 20 20" |
| 89 |
fill="none" |
| 90 |
xmlns="http://www.w3.org/2000/svg" |
| 91 |
role="presentation" |
| 92 |
> |
| 93 |
<path |
| 94 |
d="M8.72912 13.7449L5.77536 10.7911L4.76953 11.7899L8.72912 15.7495L17.2291 7.24948L16.2304 6.25073L8.72912 13.7449Z" |
| 95 |
fill="currentColor" |
| 96 |
/> |
| 97 |
</svg> |
| 98 |
</span> |
| 99 |
<span className="font-small text-sm">{tone.label}</span> |
| 100 |
</div> |
| 101 |
</label> |
| 102 |
</div> |
| 103 |
); |
| 104 |
})} |
| 105 |
</div> |
| 106 |
</div> |
| 107 |
); |
| 108 |
}; |
| 109 |
|