| 1 |
import "./editor.scss"; |
| 2 |
import Popup from "../popup/popup"; |
| 3 |
|
| 4 |
const SelectDropdown = ({ |
| 5 |
label, |
| 6 |
options, |
| 7 |
attributes, |
| 8 |
setAttributes, |
| 9 |
attributesKey, |
| 10 |
onClick = null, |
| 11 |
className = "", |
| 12 |
onClose, |
| 13 |
}) => { |
| 14 |
return ( |
| 15 |
<> |
| 16 |
<Popup label={label}> |
| 17 |
{/* <ul |
| 18 |
className={ `sp-smart-post-select-dropdown ${ className }` } |
| 19 |
> |
| 20 |
{ options?.map( ( option, index ) => ( |
| 21 |
<li |
| 22 |
key={ index } |
| 23 |
className={ `sp-smart-post-select-dropdown-option ${ |
| 24 |
attributes === option.value ? 'active' : '' |
| 25 |
} ` } |
| 26 |
onClick={ () => { |
| 27 |
selectHandler( option.value ); |
| 28 |
if ( typeof onClose === 'function' ) { |
| 29 |
onClose(); |
| 30 |
console.log( 'hello' ) |
| 31 |
} |
| 32 |
} } |
| 33 |
> |
| 34 |
{ option.label && <span>{ option.label }</span> } |
| 35 |
{ option.icon && <span>{ option.icon }</span> } |
| 36 |
</li> |
| 37 |
) ) } |
| 38 |
</ul> */} |
| 39 |
<SelectDropField |
| 40 |
options={options} |
| 41 |
attributes={attributes} |
| 42 |
setAttributes={setAttributes} |
| 43 |
attributesKey={attributesKey} |
| 44 |
className={className} |
| 45 |
onClick={onClick} |
| 46 |
onClose={onClose} |
| 47 |
/> |
| 48 |
</Popup> |
| 49 |
</> |
| 50 |
); |
| 51 |
}; |
| 52 |
|
| 53 |
export default SelectDropdown; |
| 54 |
|
| 55 |
const SelectDropField = ({ |
| 56 |
options, |
| 57 |
attributes, |
| 58 |
setAttributes, |
| 59 |
attributesKey, |
| 60 |
onClick = null, |
| 61 |
className = "", |
| 62 |
onClose, |
| 63 |
}) => { |
| 64 |
const selectHandler = (value) => { |
| 65 |
if (onClick) { |
| 66 |
onClick(value); |
| 67 |
} else { |
| 68 |
setAttributes({ [attributesKey]: value }); |
| 69 |
} |
| 70 |
}; |
| 71 |
|
| 72 |
return ( |
| 73 |
<ul className={`sp-smart-post-select-dropdown ${className}`}> |
| 74 |
{options?.map(({value, label, icon, disabled, type = ""}, index) => ( |
| 75 |
<li |
| 76 |
key={index} |
| 77 |
className={`sp-smart-post-select-dropdown-option${attributes === value ? " active" : ""}${disabled ? " disabled" : ""}`} |
| 78 |
disabled={disabled} |
| 79 |
onClick={() => { |
| 80 |
selectHandler(value); |
| 81 |
if (typeof onClose === "function") { |
| 82 |
onClose(); |
| 83 |
} |
| 84 |
}} |
| 85 |
> |
| 86 |
{label && <span> {`${label}`} |
| 87 |
{"pro" === type && <a target="_blank" href="https://wpsmartpost.com/pricing/?ref=1" className="sp-smart-pro-text"> (Pro) </a>} |
| 88 |
</span>} |
| 89 |
{icon && <span>{icon}</span>} |
| 90 |
</li> |
| 91 |
))} |
| 92 |
</ul> |
| 93 |
); |
| 94 |
}; |
| 95 |
|