| 1 |
import { __ } from '@wordpress/i18n'; |
| 2 |
import { PanelRow, SelectControl } from '@wordpress/components'; |
| 3 |
|
| 4 |
export const StyleControls = ({ attributes, onChange }) => { |
| 5 |
const { tptn_styles, post_thumb_op } = attributes; |
| 6 |
|
| 7 |
const handleStyleChange = (newStyle) => { |
| 8 |
let newPostThumbOp = post_thumb_op; |
| 9 |
|
| 10 |
if (newStyle === 'left_thumbs') { |
| 11 |
newPostThumbOp = 'inline'; |
| 12 |
} else if (newStyle === 'text_only') { |
| 13 |
newPostThumbOp = 'text_only'; |
| 14 |
} |
| 15 |
|
| 16 |
onChange('tptn_styles')(newStyle); |
| 17 |
if (newPostThumbOp !== post_thumb_op) { |
| 18 |
onChange('post_thumb_op')(newPostThumbOp); |
| 19 |
} |
| 20 |
}; |
| 21 |
|
| 22 |
const handleThumbnailOptionChange = (newThumbnailOption) => { |
| 23 |
onChange('post_thumb_op')(newThumbnailOption); |
| 24 |
|
| 25 |
if (newThumbnailOption === 'text_only' && tptn_styles !== 'text_only') { |
| 26 |
onChange('tptn_styles')('text_only'); |
| 27 |
} else if ( |
| 28 |
newThumbnailOption !== 'text_only' && |
| 29 |
tptn_styles === 'text_only' |
| 30 |
) { |
| 31 |
onChange('tptn_styles')('no_style'); |
| 32 |
} |
| 33 |
}; |
| 34 |
|
| 35 |
const styles = |
| 36 |
typeof window.top10ProBlockSettings !== 'undefined' && |
| 37 |
Array.isArray(window.top10ProBlockSettings.styles) |
| 38 |
? window.top10ProBlockSettings.styles |
| 39 |
: [ |
| 40 |
{ value: 'no_style', label: __('No styles', 'top-10') }, |
| 41 |
{ |
| 42 |
value: 'text_only', |
| 43 |
label: __('Text only', 'top-10'), |
| 44 |
}, |
| 45 |
{ |
| 46 |
value: 'left_thumbs', |
| 47 |
label: __('Left thumbnails', 'top-10'), |
| 48 |
}, |
| 49 |
]; |
| 50 |
|
| 51 |
return ( |
| 52 |
<> |
| 53 |
<PanelRow> |
| 54 |
<SelectControl |
| 55 |
label={__('Styles', 'top-10')} |
| 56 |
value={tptn_styles} |
| 57 |
onChange={handleStyleChange} |
| 58 |
help={__( |
| 59 |
'Select the style of the Popular Posts. Selecting "Text only" will change the below option for Thumbnail location to "No Thumbnail".', |
| 60 |
'top-10' |
| 61 |
)} |
| 62 |
options={[ |
| 63 |
{ |
| 64 |
value: 'select', |
| 65 |
label: __('- Select a style -', 'top-10'), |
| 66 |
}, |
| 67 |
...styles, |
| 68 |
]} |
| 69 |
/> |
| 70 |
</PanelRow> |
| 71 |
<PanelRow> |
| 72 |
<SelectControl |
| 73 |
label={__('Thumbnail location', 'top-10')} |
| 74 |
value={post_thumb_op} |
| 75 |
onChange={handleThumbnailOptionChange} |
| 76 |
help={__( |
| 77 |
'Location of the post thumbnail. Selecting "No thumbnail" will change the above option for Styles to "Text only".', |
| 78 |
'top-10' |
| 79 |
)} |
| 80 |
options={[ |
| 81 |
{ |
| 82 |
value: 'select', |
| 83 |
label: __('- Select a location -', 'top-10'), |
| 84 |
}, |
| 85 |
{ |
| 86 |
value: 'inline', |
| 87 |
label: __('Before title', 'top-10'), |
| 88 |
}, |
| 89 |
{ value: 'after', label: __('After title', 'top-10') }, |
| 90 |
{ |
| 91 |
value: 'thumbs_only', |
| 92 |
label: __('Only thumbnail', 'top-10'), |
| 93 |
}, |
| 94 |
{ |
| 95 |
value: 'text_only', |
| 96 |
label: __('No thumbnail', 'top-10'), |
| 97 |
}, |
| 98 |
]} |
| 99 |
/> |
| 100 |
</PanelRow> |
| 101 |
</> |
| 102 |
); |
| 103 |
}; |
| 104 |
|