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