| 1 |
(function () { |
| 2 |
var el = wp.element.createElement; |
| 3 |
var registerBlockType = wp.blocks.registerBlockType; |
| 4 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 5 |
var PanelBody = wp.components.PanelBody; |
| 6 |
var TextControl = wp.components.TextControl; |
| 7 |
var RangeControl = wp.components.RangeControl; |
| 8 |
var SelectControl = wp.components.SelectControl; |
| 9 |
var ToggleControl = wp.components.ToggleControl; |
| 10 |
var __ = wp.i18n.__; |
| 11 |
|
| 12 |
function ActivityEdit(props) { |
| 13 |
var attributes = props.attributes; |
| 14 |
var setAttributes = props.setAttributes; |
| 15 |
|
| 16 |
return el( |
| 17 |
wp.element.Fragment, |
| 18 |
null, |
| 19 |
el( |
| 20 |
InspectorControls, |
| 21 |
null, |
| 22 |
el( |
| 23 |
PanelBody, |
| 24 |
{ |
| 25 |
title: __("Activity Settings", "yatra"), |
| 26 |
initialOpen: true, |
| 27 |
}, |
| 28 |
el(TextControl, { |
| 29 |
label: __("Title", "yatra"), |
| 30 |
value: attributes.title, |
| 31 |
onChange: function (value) { |
| 32 |
setAttributes({ title: value }); |
| 33 |
}, |
| 34 |
__next40pxDefaultSize: true, |
| 35 |
__nextHasNoMarginBottom: true, |
| 36 |
}), |
| 37 |
el(SelectControl, { |
| 38 |
label: __("Order", "yatra"), |
| 39 |
value: attributes.order, |
| 40 |
options: [ |
| 41 |
{ label: __("Ascending", "yatra"), value: "asc" }, |
| 42 |
{ label: __("Descending", "yatra"), value: "desc" }, |
| 43 |
], |
| 44 |
onChange: function (value) { |
| 45 |
setAttributes({ order: value }); |
| 46 |
}, |
| 47 |
__next40pxDefaultSize: true, |
| 48 |
__nextHasNoMarginBottom: true, |
| 49 |
}), |
| 50 |
el(RangeControl, { |
| 51 |
label: __("Number of Activities", "yatra"), |
| 52 |
value: attributes.per_page, |
| 53 |
onChange: function (value) { |
| 54 |
setAttributes({ |
| 55 |
per_page: value !== undefined && value !== null ? value : 10, |
| 56 |
}); |
| 57 |
}, |
| 58 |
min: 1, |
| 59 |
max: 50, |
| 60 |
__next40pxDefaultSize: true, |
| 61 |
__nextHasNoMarginBottom: true, |
| 62 |
}), |
| 63 |
el(RangeControl, { |
| 64 |
label: __("Columns", "yatra"), |
| 65 |
value: attributes.columns, |
| 66 |
onChange: function (value) { |
| 67 |
setAttributes({ columns: value || 4 }); |
| 68 |
}, |
| 69 |
min: 1, |
| 70 |
max: 6, |
| 71 |
__next40pxDefaultSize: true, |
| 72 |
__nextHasNoMarginBottom: true, |
| 73 |
}), |
| 74 |
el(ToggleControl, { |
| 75 |
label: __("Show pagination", "yatra"), |
| 76 |
checked: attributes.show_pagination, |
| 77 |
onChange: function (value) { |
| 78 |
setAttributes({ show_pagination: value }); |
| 79 |
}, |
| 80 |
__nextHasNoMarginBottom: true, |
| 81 |
}), |
| 82 |
), |
| 83 |
), |
| 84 |
el(wp.serverSideRender, { |
| 85 |
block: "yatra/activity", |
| 86 |
attributes: attributes, |
| 87 |
urlQueryArgs: { |
| 88 |
preview: true, |
| 89 |
}, |
| 90 |
}), |
| 91 |
); |
| 92 |
} |
| 93 |
|
| 94 |
registerBlockType("yatra/activity", { |
| 95 |
apiVersion: 3, |
| 96 |
title: "Activity", |
| 97 |
icon: "heart", |
| 98 |
category: "yatra", |
| 99 |
attributes: { |
| 100 |
order: { |
| 101 |
type: "string", |
| 102 |
default: "asc", |
| 103 |
}, |
| 104 |
columns: { |
| 105 |
type: "number", |
| 106 |
default: 4, |
| 107 |
}, |
| 108 |
per_page: { |
| 109 |
type: "number", |
| 110 |
default: 10, |
| 111 |
}, |
| 112 |
title: { |
| 113 |
type: "string", |
| 114 |
default: "Activity Listings", |
| 115 |
}, |
| 116 |
show_pagination: { |
| 117 |
type: "boolean", |
| 118 |
default: true, |
| 119 |
}, |
| 120 |
}, |
| 121 |
edit: ActivityEdit, |
| 122 |
save: function () { |
| 123 |
return null; // Server-side rendered |
| 124 |
}, |
| 125 |
}); |
| 126 |
})(); |
| 127 |
|