-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprice-block.js
95 lines (81 loc) · 1.62 KB
/
price-block.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
( function( blocks, editor, i18n, element ) {
var el = element.createElement;
var __ = i18n.__;
blocks.registerBlockType( 'gpress-block/price', {
title: i18n.__( 'Price list', 'gp-price-block' ),
description: i18n.__( 'Easy way to bring price list in Gutenberg. Just click the button in the block manager and fill the inputs with product name and cost', 'gp-price-block' ),
icon: {
background: '#f7f6fb',
foreground: '#333',
src: 'editor-table',
},
category: 'common',
attributes: {
content: {
type: 'string'
},
num: {
type: 'string'
}
},
edit: function(props) {
function updatecontent(event) {
props.setAttributes({
content: event.target.value
})
}
function updatenum(event) {
props.setAttributes({
num: event.target.value
})
}
return wp.element.createElement(
"div",
{className: 'gp-block-price' },
wp.element.createElement(
"input",
{
type: "text",
placeholder: i18n.__( 'Product or service name', 'gp-price-block' ),
value: props.attributes.content,
onChange: updatecontent
}
),
wp.element.createElement(
"input",
{
type: "text",
placeholder: i18n.__( 'Price', 'gp-price-block' ),
value: props.attributes.num,
onChange: updatenum
}
),
)
},
save: function(props) {
return wp.element.createElement(
"div",
{
className: "gpress-block-price",
},
wp.element.createElement(
"p", {
className: "gpress-block-name"
},
props.attributes.content
),
wp.element.createElement(
"span", {
className: "gp-block-num"
},
props.attributes.num
)
)
}
})
}(
window.wp.blocks,
window.wp.editor,
window.wp.i18n,
window.wp.element
) );