PluginProbe
Canvas / 2.4.9
Canvas v2.4.9
2.5.5 2.5.4 trunk 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 All 54 releases
canvas / components / basic-elements / class-block-progress.php

class-block-progress.php in Canvas 2.4.9, at components/basic-elements/class-block-progress.php

186 lines 5.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Progress Block.
4 *
5 * @package Canvas
6 */
7
8 /**
9 * Initialize Progress block.
10 */
11 class CNVS_Block_Progress {
12
13 /**
14 * Initialize
15 */
16 public function __construct() {
17 add_action( 'init', array( $this, 'init' ) );
18 add_filter( 'canvas_register_block_type', array( $this, 'register_block_type' ) );
19 }
20
21 /**
22 * Enqueue the block's assets for the editor.
23 */
24 public function init() {
25 // Editor Scripts.
26 wp_register_script(
27 'canvas-block-progress-editor-script',
28 plugins_url( 'block-progress/block.js', __FILE__ ),
29 array( 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-editor', 'lodash', 'jquery' ),
30 filemtime( plugin_dir_path( __FILE__ ) . 'block-progress/block.js' ),
31 true
32 );
33
34 wp_register_style(
35 'canvas-block-progress-editor-style',
36 plugins_url( 'block-progress/block-editor.css', __FILE__ ),
37 array(),
38 filemtime( plugin_dir_path( __FILE__ ) . 'block-progress/block-editor.css' )
39 );
40
41 // Styles.
42 wp_register_style(
43 'canvas-block-progress-style',
44 plugins_url( 'block-progress/block.css', __FILE__ ),
45 array(),
46 filemtime( plugin_dir_path( __FILE__ ) . 'block-progress/block.css' )
47 );
48
49 wp_style_add_data( 'canvas-block-progress-style', 'rtl', 'replace' );
50 }
51
52 /**
53 * Register block
54 *
55 * @param array $blocks all registered blocks.
56 * @return array
57 */
58 public function register_block_type( $blocks ) {
59 $blocks[] = array(
60 'name' => 'canvas/progress',
61 'title' => esc_html__( 'Progress', 'canvas' ),
62 'description' => '',
63 'category' => 'canvas',
64 'keywords' => array(),
65 'icon' => '<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg"><g fill="none" fill-rule="evenodd"><g transform="translate(3 5)"><rect stroke="#000" stroke-width="2" x="1" y="1" width="16" height="4" rx="1"/><path d="M1 0h9v6H1a1 1 0 01-1-1V1a1 1 0 011-1z" fill="#000"/></g><g transform="translate(3 13)"><rect stroke="#000" stroke-width="2" x="1" y="1" width="16" height="4" rx="1"/><path d="M1 0h6v6H1a1 1 0 01-1-1V1a1 1 0 011-1z" fill="#000"/></g></g></svg>',
66 'supports' => array(
67 'className' => true,
68 'anchor' => true,
69 'html' => false,
70 'canvasSpacings' => true,
71 'canvasBorder' => true,
72 'canvasResponsive' => true,
73 ),
74 'styles' => array(
75 array(
76 'name' => 'cnvs-block-progress-primary',
77 'label' => esc_html__( 'Primary', 'canvas' ),
78 ),
79 array(
80 'name' => 'cnvs-block-progress-success',
81 'label' => esc_html__( 'Success', 'canvas' ),
82 ),
83 array(
84 'name' => 'cnvs-block-progress-info',
85 'label' => esc_html__( 'Info', 'canvas' ),
86 ),
87 array(
88 'name' => 'cnvs-block-progress-warning',
89 'label' => esc_html__( 'Warning', 'canvas' ),
90 ),
91 array(
92 'name' => 'cnvs-block-progress-danger',
93 'label' => esc_html__( 'Danger', 'canvas' ),
94 ),
95 array(
96 'name' => 'cnvs-block-progress-dark',
97 'label' => esc_html__( 'Dark', 'canvas' ),
98 ),
99 ),
100 'location' => array(),
101
102 'sections' => array(
103 'general' => array(
104 'title' => esc_html__( 'Block Settings', 'canvas' ),
105 'priority' => 5,
106 'open' => true,
107 ),
108 ),
109 'layouts' => array(),
110
111 // Set fields just for add block attributes.
112 // Editor render for this block is custom JSX
113 // so we don't need to render fields automatically.
114 'fields' => array(
115 array(
116 'key' => 'width',
117 'label' => esc_html__( 'Width', 'canvas' ),
118 'type' => 'number',
119 'section' => 'general',
120 'min' => 1,
121 'max' => 100,
122 'default' => 70,
123 'output' => array(
124 array(
125 'element' => '$ .cnvs-block-progress-bar',
126 'property' => 'width',
127 'units' => '%',
128 ),
129 ),
130 ),
131 array(
132 'key' => 'height',
133 'label' => esc_html__( 'Height', 'canvas' ),
134 'type' => 'number',
135 'section' => 'general',
136 'min' => 1,
137 'max' => 20,
138 'default' => 14,
139 'output' => array(
140 array(
141 'property' => 'height',
142 'units' => 'px',
143 ),
144 ),
145 ),
146 array(
147 'key' => 'striped',
148 'label' => esc_html__( 'Striped', 'canvas' ),
149 'type' => 'toggle',
150 'section' => 'general',
151 'default' => true,
152 ),
153 array(
154 'key' => 'animated',
155 'label' => esc_html__( 'Animated', 'canvas' ),
156 'type' => 'toggle',
157 'section' => 'general',
158 'default' => false,
159 'active_callback' => array(
160 array(
161 'field' => 'striped',
162 ),
163 ),
164 ),
165 array(
166 'key' => 'displayPercent',
167 'label' => esc_html__( 'Display Percent', 'canvas' ),
168 'type' => 'toggle',
169 'section' => 'general',
170 'default' => false,
171 ),
172 ),
173 'template' => dirname( __FILE__ ) . '/block-progress/render.php',
174
175 // enqueue registered scripts/styles.
176 'style' => 'canvas-block-progress-style',
177 'editor_style' => 'canvas-block-progress-editor-style',
178 'editor_script' => 'canvas-block-progress-editor-script',
179 );
180
181 return $blocks;
182 }
183 }
184
185 new CNVS_Block_Progress();
186