| 1 |
import { InspectorControls } from "@wordpress/block-editor"; |
| 2 |
import { |
| 3 |
PanelBody, |
| 4 |
TextControl, |
| 5 |
RangeControl, |
| 6 |
SelectControl, |
| 7 |
ToggleControl, |
| 8 |
} from "@wordpress/components"; |
| 9 |
import { __ } from "@wordpress/i18n"; |
| 10 |
import ServerSideRender from "@wordpress/server-side-render"; |
| 11 |
|
| 12 |
interface TourBlockAttributes { |
| 13 |
order: "desc" | "asc"; |
| 14 |
featured: boolean; |
| 15 |
per_page: number; |
| 16 |
columns: number; |
| 17 |
title: string; |
| 18 |
show_pagination: boolean; |
| 19 |
} |
| 20 |
|
| 21 |
interface EditProps { |
| 22 |
attributes: TourBlockAttributes; |
| 23 |
setAttributes: (attrs: Partial<TourBlockAttributes>) => void; |
| 24 |
} |
| 25 |
|
| 26 |
export default function Edit({ attributes, setAttributes }: EditProps) { |
| 27 |
return ( |
| 28 |
<> |
| 29 |
<InspectorControls> |
| 30 |
<PanelBody title={__("Trip Settings", "yatra")} initialOpen={true}> |
| 31 |
<TextControl |
| 32 |
label={__("Title", "yatra")} |
| 33 |
value={attributes.title} |
| 34 |
onChange={(value) => setAttributes({ title: value })} |
| 35 |
/> |
| 36 |
<SelectControl |
| 37 |
label={__("Order", "yatra")} |
| 38 |
value={attributes.order} |
| 39 |
options={[ |
| 40 |
{ label: __("Descending", "yatra"), value: "desc" }, |
| 41 |
{ label: __("Ascending", "yatra"), value: "asc" }, |
| 42 |
]} |
| 43 |
onChange={(value: string) => |
| 44 |
setAttributes({ order: value as "asc" | "desc" }) |
| 45 |
} |
| 46 |
/> |
| 47 |
<RangeControl |
| 48 |
label={__("Number of Tours", "yatra")} |
| 49 |
value={attributes.per_page} |
| 50 |
onChange={(value) => setAttributes({ per_page: value || 10 })} |
| 51 |
min={1} |
| 52 |
max={50} |
| 53 |
/> |
| 54 |
<RangeControl |
| 55 |
label={__("Columns", "yatra")} |
| 56 |
value={attributes.columns} |
| 57 |
onChange={(value) => |
| 58 |
setAttributes({ |
| 59 |
columns: value !== undefined && value !== null ? value : 3, |
| 60 |
}) |
| 61 |
} |
| 62 |
min={1} |
| 63 |
max={6} |
| 64 |
/> |
| 65 |
<ToggleControl |
| 66 |
label={__("Show only featured tours", "yatra")} |
| 67 |
checked={attributes.featured} |
| 68 |
onChange={(value) => setAttributes({ featured: value })} |
| 69 |
/> |
| 70 |
<ToggleControl |
| 71 |
label={__("Show pagination", "yatra")} |
| 72 |
checked={attributes.show_pagination} |
| 73 |
onChange={(value) => setAttributes({ show_pagination: value })} |
| 74 |
/> |
| 75 |
</PanelBody> |
| 76 |
</InspectorControls> |
| 77 |
|
| 78 |
<div className="yatra-block-editor-preview"> |
| 79 |
<ServerSideRender |
| 80 |
block="yatra/tour" |
| 81 |
attributes={attributes} |
| 82 |
key={JSON.stringify(attributes)} |
| 83 |
/> |
| 84 |
</div> |
| 85 |
</> |
| 86 |
); |
| 87 |
} |
| 88 |
|