fields-errors
4 years ago
base-module.php
4 years ago
general-style-functions.php
4 years ago
general-style.php
4 years ago
general-style.php
556 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Blocks\Modules; |
| 5 | |
| 6 | |
| 7 | trait General_Style { |
| 8 | |
| 9 | use General_Style_Functions; |
| 10 | |
| 11 | public function general_style_manager_options() { |
| 12 | $this->maybe_add_controls_type( 'wrap' ); |
| 13 | $this->maybe_add_controls_type( 'input' ); |
| 14 | $this->maybe_add_controls_type( 'label' ); |
| 15 | $this->maybe_add_controls_type( 'required' ); |
| 16 | $this->maybe_add_controls_type( 'description' ); |
| 17 | } |
| 18 | |
| 19 | public function general_css_scheme() { |
| 20 | return array( |
| 21 | 'wrap' => $this->get_field_wrap(), |
| 22 | 'label' => $this->get_label_selector(), |
| 23 | 'input' => $this->get_field_input(), |
| 24 | 'required' => $this->get_required_selector(), |
| 25 | 'description' => $this->get_description_selector() |
| 26 | ); |
| 27 | } |
| 28 | |
| 29 | public function general_controls_callbacks() { |
| 30 | return array( |
| 31 | 'wrap' => array( $this, 'add_content_controls' ), |
| 32 | 'label' => array( $this, 'add_label_controls' ), |
| 33 | 'input' => array( $this, 'add_input_controls' ), |
| 34 | 'required' => array( $this, 'add_required_mark_controls' ), |
| 35 | 'description' => array( $this, 'add_description_controls' ), |
| 36 | ); |
| 37 | } |
| 38 | |
| 39 | public function general_style_unregister() { |
| 40 | return array( 'input' ); |
| 41 | } |
| 42 | |
| 43 | public function get_label_selector() { |
| 44 | return '__label.%1$s__label.%1$s__label'; |
| 45 | } |
| 46 | |
| 47 | public function get_required_selector() { |
| 48 | return '__label span.%1$s__required.%1$s__required.%1$s__required'; |
| 49 | } |
| 50 | |
| 51 | public function get_description_selector() { |
| 52 | return '__desc.%1$s__desc.%1$s__desc'; |
| 53 | } |
| 54 | |
| 55 | public function get_field_wrap() { |
| 56 | return '-row.%1$s-row.%1$s-row.%1$s-row'; |
| 57 | } |
| 58 | |
| 59 | public function get_field_input() { |
| 60 | return '-row.%1$s-row.%1$s-row input'; |
| 61 | } |
| 62 | |
| 63 | |
| 64 | public function general_style_attributes() { |
| 65 | return array( |
| 66 | 'label_margin' => array( |
| 67 | 'type' => 'object' |
| 68 | ), |
| 69 | 'label_padding' => array( |
| 70 | 'type' => 'object' |
| 71 | ), |
| 72 | 'label_typography' => array( |
| 73 | 'type' => 'object' |
| 74 | ), |
| 75 | 'label_color' => array( |
| 76 | 'type' => 'object' |
| 77 | ), |
| 78 | 'label_border' => array( |
| 79 | 'type' => 'object' |
| 80 | ), |
| 81 | 'label_alignment' => array( |
| 82 | 'type' => 'object' |
| 83 | ), |
| 84 | 'label_background_color' => array( |
| 85 | 'type' => 'object' |
| 86 | ), |
| 87 | 'description_margin' => array( |
| 88 | 'type' => 'object' |
| 89 | ), |
| 90 | 'description_padding' => array( |
| 91 | 'type' => 'object' |
| 92 | ), |
| 93 | 'description_typography' => array( |
| 94 | 'type' => 'object' |
| 95 | ), |
| 96 | 'description_color' => array( |
| 97 | 'type' => 'object' |
| 98 | ), |
| 99 | 'description_background_color' => array( |
| 100 | 'type' => 'object' |
| 101 | ), |
| 102 | 'description_border' => array( |
| 103 | 'type' => 'object' |
| 104 | ), |
| 105 | 'description_alignment' => array( |
| 106 | 'type' => 'object' |
| 107 | ), |
| 108 | 'required_color' => array( |
| 109 | 'type' => 'object' |
| 110 | ), |
| 111 | 'required_background_color' => array( |
| 112 | 'type' => 'object' |
| 113 | ), |
| 114 | 'required_typography' => array( |
| 115 | 'type' => 'object' |
| 116 | ), |
| 117 | ); |
| 118 | } |
| 119 | |
| 120 | public function _get_default_control( $selector ) { |
| 121 | return array( |
| 122 | 'padding' => array( |
| 123 | 'type' => 'dimensions', |
| 124 | 'label' => __( 'Padding', 'jet-form-builder' ), |
| 125 | 'units' => array( 'px', '%' ), |
| 126 | 'css_selector' => array( |
| 127 | $selector => 'padding: {{TOP}} {{RIGHT}} {{BOTTOM}} {{LEFT}};', |
| 128 | ), |
| 129 | ), |
| 130 | 'margin' => array( |
| 131 | 'type' => 'dimensions', |
| 132 | 'label' => __( 'Margin', 'jet-form-builder' ), |
| 133 | 'units' => array( 'px', '%' ), |
| 134 | 'css_selector' => array( |
| 135 | $selector => 'margin: {{TOP}} {{RIGHT}} {{BOTTOM}} {{LEFT}};', |
| 136 | ), |
| 137 | ) |
| 138 | ); |
| 139 | } |
| 140 | |
| 141 | public function add_margin_padding( $selector, $control_options, $responsive = array() ) { |
| 142 | foreach ( $control_options as $type => $options ) { |
| 143 | $options = $this->merge_controls_or_add_id( $this->_get_default_control( $selector )[ $type ], $options ); |
| 144 | |
| 145 | if ( in_array( $type, $responsive ) ) { |
| 146 | $this->controls_manager->add_responsive_control( $options ); |
| 147 | } else { |
| 148 | $this->controls_manager->add_control( $options ); |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | public function merge_controls_or_add_id( $control, $options ) { |
| 154 | if ( is_array( $options ) ) { |
| 155 | return array_merge( $control, $options ); |
| 156 | |
| 157 | } elseif ( is_string( $options ) ) { |
| 158 | |
| 159 | $control['id'] = $options; |
| 160 | |
| 161 | return $control; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | |
| 166 | private function add_content_controls() { |
| 167 | $this->controls_manager->start_section( |
| 168 | 'style_controls', |
| 169 | [ |
| 170 | 'id' => 'content_style', |
| 171 | 'title' => __( 'Content', 'jet-form-builder' ) |
| 172 | ] |
| 173 | ); |
| 174 | |
| 175 | $this->add_margin_padding( |
| 176 | $this->selector( 'wrap' ), |
| 177 | array( |
| 178 | 'margin' => array( |
| 179 | 'id' => 'field_margin', |
| 180 | 'separator' => 'after', |
| 181 | ), |
| 182 | 'padding' => array( |
| 183 | 'id' => 'field_padding', |
| 184 | 'separator' => 'after', |
| 185 | ) |
| 186 | ), |
| 187 | array( 'padding', 'margin' ) |
| 188 | ); |
| 189 | |
| 190 | $this->controls_manager->add_control( [ |
| 191 | 'id' => 'field_alignment', |
| 192 | 'type' => 'choose', |
| 193 | 'label' => __( 'Alignment', 'jet-form-builder' ), |
| 194 | 'separator' => 'after', |
| 195 | 'options' => [ |
| 196 | 'left' => [ |
| 197 | 'shortcut' => __( 'Left', 'jet-form-builder' ), |
| 198 | 'icon' => 'dashicons-editor-alignleft', |
| 199 | ], |
| 200 | 'center' => [ |
| 201 | 'shortcut' => __( 'Center', 'jet-form-builder' ), |
| 202 | 'icon' => 'dashicons-editor-aligncenter', |
| 203 | ], |
| 204 | 'right' => [ |
| 205 | 'shortcut' => __( 'Right', 'jet-form-builder' ), |
| 206 | 'icon' => 'dashicons-editor-alignright', |
| 207 | ], |
| 208 | ], |
| 209 | 'css_selector' => [ |
| 210 | $this->selector( 'wrap' ) => 'text-align: {{VALUE}};', |
| 211 | ], |
| 212 | ] ); |
| 213 | |
| 214 | |
| 215 | $this->controls_manager->add_control( [ |
| 216 | 'id' => 'field_border', |
| 217 | 'type' => 'border', |
| 218 | 'label' => __( 'Border', 'jet-form-builder' ), |
| 219 | 'separator' => 'after', |
| 220 | 'css_selector' => array( |
| 221 | $this->selector( 'wrap' ) => 'border-style:{{STYLE}};border-width:{{WIDTH}};border-radius:{{RADIUS}};border-color:{{COLOR}};', |
| 222 | ), |
| 223 | ] ); |
| 224 | |
| 225 | $this->controls_manager->add_control( [ |
| 226 | 'id' => 'field_background_color', |
| 227 | 'type' => 'color-picker', |
| 228 | 'label' => __( 'Background Color', 'jet-form-builder' ), |
| 229 | 'css_selector' => array( |
| 230 | $this->selector( 'wrap' ) => 'background-color: {{VALUE}}', |
| 231 | ), |
| 232 | ] ); |
| 233 | |
| 234 | $this->controls_manager->end_section(); |
| 235 | } |
| 236 | |
| 237 | private function add_label_controls() { |
| 238 | $this->controls_manager->start_section( |
| 239 | 'style_controls', |
| 240 | [ |
| 241 | 'id' => 'label_style', |
| 242 | 'title' => __( 'Label', 'jet-form-builder' ) |
| 243 | ] |
| 244 | ); |
| 245 | |
| 246 | $this->add_margin_padding( |
| 247 | $this->selector( 'label' ), |
| 248 | array( |
| 249 | 'margin' => array( |
| 250 | 'id' => 'label_margin', |
| 251 | 'separator' => 'after', |
| 252 | ), |
| 253 | 'padding' => array( |
| 254 | 'id' => 'label_padding', |
| 255 | 'separator' => 'after', |
| 256 | ) |
| 257 | ) |
| 258 | ); |
| 259 | |
| 260 | $this->controls_manager->add_control( [ |
| 261 | 'id' => 'label_alignment', |
| 262 | 'type' => 'choose', |
| 263 | 'label' => __( 'Alignment', 'jet-form-builder' ), |
| 264 | 'separator' => 'after', |
| 265 | 'options' => [ |
| 266 | 'left' => [ |
| 267 | 'shortcut' => __( 'Left', 'jet-form-builder' ), |
| 268 | 'icon' => 'dashicons-editor-alignleft', |
| 269 | ], |
| 270 | 'center' => [ |
| 271 | 'shortcut' => __( 'Center', 'jet-form-builder' ), |
| 272 | 'icon' => 'dashicons-editor-aligncenter', |
| 273 | ], |
| 274 | 'right' => [ |
| 275 | 'shortcut' => __( 'Right', 'jet-form-builder' ), |
| 276 | 'icon' => 'dashicons-editor-alignright', |
| 277 | ], |
| 278 | ], |
| 279 | 'css_selector' => [ |
| 280 | $this->selector( 'label' ) => 'text-align: {{VALUE}};', |
| 281 | ], |
| 282 | ] ); |
| 283 | |
| 284 | $this->controls_manager->add_control( [ |
| 285 | 'id' => 'label_typography', |
| 286 | 'type' => 'typography', |
| 287 | 'separator' => 'after', |
| 288 | 'css_selector' => [ |
| 289 | $this->selector( 'label' ) => 'font-family: {{FAMILY}}; font-weight: {{WEIGHT}}; text-transform: {{TRANSFORM}}; font-style: {{STYLE}}; text-decoration: {{DECORATION}}; line-height: {{LINEHEIGHT}}{{LH_UNIT}}; letter-spacing: {{LETTERSPACING}}{{LS_UNIT}}; font-size: {{SIZE}}{{S_UNIT}};', |
| 290 | ], |
| 291 | ] ); |
| 292 | |
| 293 | $this->controls_manager->add_control( [ |
| 294 | 'id' => 'label_border', |
| 295 | 'type' => 'border', |
| 296 | 'label' => __( 'Border', 'jet-form-builder' ), |
| 297 | 'separator' => 'after', |
| 298 | 'css_selector' => array( |
| 299 | $this->selector( 'label' ) => 'border-style:{{STYLE}};border-width:{{WIDTH}};border-radius:{{RADIUS}};border-color:{{COLOR}};', |
| 300 | ), |
| 301 | ] ); |
| 302 | |
| 303 | $this->controls_manager->add_control( [ |
| 304 | 'id' => 'label_color', |
| 305 | 'type' => 'color-picker', |
| 306 | 'separator' => 'after', |
| 307 | 'label' => __( 'Text Color', 'jet-form-builder' ), |
| 308 | 'css_selector' => array( |
| 309 | $this->selector( 'label' ) => 'color: {{VALUE}}', |
| 310 | ), |
| 311 | ] ); |
| 312 | |
| 313 | $this->controls_manager->add_control( [ |
| 314 | 'id' => 'label_background_color', |
| 315 | 'type' => 'color-picker', |
| 316 | 'label' => __( 'Background Color', 'jet-form-builder' ), |
| 317 | 'css_selector' => array( |
| 318 | $this->selector( 'label' ) => 'background-color: {{VALUE}}', |
| 319 | ), |
| 320 | ] ); |
| 321 | |
| 322 | $this->controls_manager->end_section(); |
| 323 | } |
| 324 | |
| 325 | private function add_description_controls() { |
| 326 | $this->controls_manager->start_section( |
| 327 | 'style_controls', |
| 328 | [ |
| 329 | 'id' => 'description_style', |
| 330 | 'title' => __( 'Description', 'jet-form-builder' ), |
| 331 | /*'condition' => array( |
| 332 | 'desc' => true |
| 333 | ),*/ |
| 334 | ] |
| 335 | ); |
| 336 | |
| 337 | $this->add_margin_padding( |
| 338 | $this->selector( 'description' ), |
| 339 | array( |
| 340 | 'margin' => array( |
| 341 | 'id' => 'description_margin', |
| 342 | 'separator' => 'after', |
| 343 | ), |
| 344 | 'padding' => array( |
| 345 | 'id' => 'description_padding', |
| 346 | 'separator' => 'after', |
| 347 | ) |
| 348 | ) |
| 349 | ); |
| 350 | |
| 351 | $this->controls_manager->add_control( [ |
| 352 | 'id' => 'description_alignment', |
| 353 | 'type' => 'choose', |
| 354 | 'label' => __( 'Alignment', 'jet-form-builder' ), |
| 355 | 'separator' => 'after', |
| 356 | 'options' => [ |
| 357 | 'left' => [ |
| 358 | 'shortcut' => __( 'Left', 'jet-form-builder' ), |
| 359 | 'icon' => 'dashicons-editor-alignleft', |
| 360 | ], |
| 361 | 'center' => [ |
| 362 | 'shortcut' => __( 'Center', 'jet-form-builder' ), |
| 363 | 'icon' => 'dashicons-editor-aligncenter', |
| 364 | ], |
| 365 | 'right' => [ |
| 366 | 'shortcut' => __( 'Right', 'jet-form-builder' ), |
| 367 | 'icon' => 'dashicons-editor-alignright', |
| 368 | ], |
| 369 | ], |
| 370 | 'css_selector' => [ |
| 371 | $this->selector( 'description' ) => 'text-align: {{VALUE}};', |
| 372 | ], |
| 373 | ] ); |
| 374 | |
| 375 | $this->controls_manager->add_control( [ |
| 376 | 'id' => 'description_border', |
| 377 | 'type' => 'border', |
| 378 | 'label' => __( 'Border', 'jet-form-builder' ), |
| 379 | 'separator' => 'after', |
| 380 | 'css_selector' => array( |
| 381 | $this->selector( 'description' ) => 'border-style:{{STYLE}};border-width:{{WIDTH}};border-radius:{{RADIUS}};border-color:{{COLOR}};', |
| 382 | ), |
| 383 | ] ); |
| 384 | |
| 385 | $this->controls_manager->add_control( [ |
| 386 | 'id' => 'description_typography', |
| 387 | 'type' => 'typography', |
| 388 | 'separator' => 'after', |
| 389 | 'css_selector' => [ |
| 390 | $this->selector( 'description' ) => 'font-family: {{FAMILY}}; font-weight: {{WEIGHT}}; text-transform: {{TRANSFORM}}; font-style: {{STYLE}}; text-decoration: {{DECORATION}}; line-height: {{LINEHEIGHT}}{{LH_UNIT}}; letter-spacing: {{LETTERSPACING}}{{LS_UNIT}}; font-size: {{SIZE}}{{S_UNIT}};', |
| 391 | ], |
| 392 | ] ); |
| 393 | |
| 394 | $this->controls_manager->add_control( [ |
| 395 | 'id' => 'description_color', |
| 396 | 'type' => 'color-picker', |
| 397 | 'separator' => 'after', |
| 398 | 'label' => __( 'Text Color', 'jet-form-builder' ), |
| 399 | 'css_selector' => array( |
| 400 | $this->selector( 'description' ) => 'color: {{VALUE}}', |
| 401 | ), |
| 402 | ] ); |
| 403 | |
| 404 | $this->controls_manager->add_control( [ |
| 405 | 'id' => 'description_background_color', |
| 406 | 'type' => 'color-picker', |
| 407 | 'label' => __( 'Background Color', 'jet-form-builder' ), |
| 408 | 'css_selector' => array( |
| 409 | $this->selector( 'description' ) => 'background-color: {{VALUE}}', |
| 410 | ), |
| 411 | ] ); |
| 412 | |
| 413 | $this->controls_manager->end_section(); |
| 414 | } |
| 415 | |
| 416 | private function add_required_mark_controls() { |
| 417 | $this->controls_manager->start_section( |
| 418 | 'style_controls', |
| 419 | [ |
| 420 | 'id' => 'required_style', |
| 421 | 'title' => __( 'Required Mark', 'jet-form-builder' ) |
| 422 | ] |
| 423 | ); |
| 424 | |
| 425 | $this->controls_manager->add_control( [ |
| 426 | 'id' => 'required_typography', |
| 427 | |
| 428 | 'disable_line_height' => true, |
| 429 | 'disable_family' => true, |
| 430 | 'disable_transform' => true, |
| 431 | 'disable_style' => true, |
| 432 | 'disable_decoration' => true, |
| 433 | 'disable_letter_spacing' => true, |
| 434 | 'separator' => 'after', |
| 435 | 'type' => 'typography', |
| 436 | 'css_selector' => [ |
| 437 | $this->selector( 'required' ) => 'font-weight: {{WEIGHT}}; font-size: {{SIZE}}{{S_UNIT}};', |
| 438 | ], |
| 439 | ] ); |
| 440 | |
| 441 | $this->controls_manager->add_control( [ |
| 442 | 'id' => 'required_color', |
| 443 | 'type' => 'color-picker', |
| 444 | 'separator' => 'after', |
| 445 | 'label' => __( 'Text Color', 'jet-form-builder' ), |
| 446 | 'css_selector' => array( |
| 447 | $this->selector( 'required' ) => 'color: {{VALUE}}', |
| 448 | ), |
| 449 | ] ); |
| 450 | |
| 451 | $this->controls_manager->add_control( [ |
| 452 | 'id' => 'required_background_color', |
| 453 | 'type' => 'color-picker', |
| 454 | 'label' => __( 'Background Color', 'jet-form-builder' ), |
| 455 | 'css_selector' => array( |
| 456 | $this->selector( 'required' ) => 'background-color: {{VALUE}}', |
| 457 | ), |
| 458 | ] ); |
| 459 | |
| 460 | |
| 461 | $this->controls_manager->end_section(); |
| 462 | } |
| 463 | |
| 464 | private function add_input_controls() { |
| 465 | $this->controls_manager->start_section( |
| 466 | 'style_controls', |
| 467 | [ |
| 468 | 'id' => 'input_style', |
| 469 | 'title' => __( 'Field', 'jet-form-builder' ) |
| 470 | ] |
| 471 | ); |
| 472 | |
| 473 | $this->add_margin_padding( |
| 474 | $this->selector( 'input' ), |
| 475 | array( |
| 476 | 'margin' => array( |
| 477 | 'id' => 'input_margin', |
| 478 | 'separator' => 'after', |
| 479 | ), |
| 480 | 'padding' => array( |
| 481 | 'id' => 'input_padding', |
| 482 | 'separator' => 'after', |
| 483 | ) |
| 484 | ) |
| 485 | ); |
| 486 | |
| 487 | $this->controls_manager->add_control( $this->merge_controls_or_add_id( |
| 488 | array( |
| 489 | 'id' => 'input_alignment', |
| 490 | 'type' => 'choose', |
| 491 | 'label' => __( 'Alignment', 'jet-form-builder' ), |
| 492 | 'separator' => 'after', |
| 493 | 'options' => [ |
| 494 | 'left' => [ |
| 495 | 'shortcut' => __( 'Left', 'jet-form-builder' ), |
| 496 | 'icon' => 'dashicons-editor-alignleft', |
| 497 | ], |
| 498 | 'center' => [ |
| 499 | 'shortcut' => __( 'Center', 'jet-form-builder' ), |
| 500 | 'icon' => 'dashicons-editor-aligncenter', |
| 501 | ], |
| 502 | 'right' => [ |
| 503 | 'shortcut' => __( 'Right', 'jet-form-builder' ), |
| 504 | 'icon' => 'dashicons-editor-alignright', |
| 505 | ], |
| 506 | ], |
| 507 | 'css_selector' => array( |
| 508 | $this->selector( 'input' ) => 'text-align: {{VALUE}};', |
| 509 | ), |
| 510 | ), |
| 511 | $this->get_additional_styles( 'input_alignment' ) |
| 512 | ) ); |
| 513 | |
| 514 | $this->controls_manager->add_control( [ |
| 515 | 'id' => 'input_typography', |
| 516 | 'type' => 'typography', |
| 517 | 'separator' => 'after', |
| 518 | 'css_selector' => [ |
| 519 | $this->selector( 'input' ) => 'font-family: {{FAMILY}}; font-weight: {{WEIGHT}}; text-transform: {{TRANSFORM}}; font-style: {{STYLE}}; text-decoration: {{DECORATION}}; line-height: {{LINEHEIGHT}}{{LH_UNIT}}; letter-spacing: {{LETTERSPACING}}{{LS_UNIT}}; font-size: {{SIZE}}{{S_UNIT}};', |
| 520 | ], |
| 521 | ] ); |
| 522 | |
| 523 | $this->controls_manager->add_control( [ |
| 524 | 'id' => 'input_border', |
| 525 | 'type' => 'border', |
| 526 | 'label' => __( 'Border', 'jet-form-builder' ), |
| 527 | 'separator' => 'after', |
| 528 | 'css_selector' => array( |
| 529 | $this->selector( 'input' ) => 'border-style:{{STYLE}};border-width:{{WIDTH}};border-radius:{{RADIUS}};border-color:{{COLOR}};', |
| 530 | ), |
| 531 | ] ); |
| 532 | |
| 533 | $this->controls_manager->add_control( [ |
| 534 | 'id' => 'input_color', |
| 535 | 'type' => 'color-picker', |
| 536 | 'separator' => 'after', |
| 537 | 'label' => __( 'Text Color', 'jet-form-builder' ), |
| 538 | 'css_selector' => array( |
| 539 | $this->selector( 'input' ) => 'color: {{VALUE}}', |
| 540 | ), |
| 541 | ] ); |
| 542 | |
| 543 | $this->controls_manager->add_control( [ |
| 544 | 'id' => 'input_background_color', |
| 545 | 'type' => 'color-picker', |
| 546 | 'label' => __( 'Background Color', 'jet-form-builder' ), |
| 547 | 'css_selector' => array( |
| 548 | $this->selector( 'input' ) => 'background-color: {{VALUE}}', |
| 549 | ), |
| 550 | ] ); |
| 551 | |
| 552 | $this->controls_manager->end_section(); |
| 553 | } |
| 554 | |
| 555 | |
| 556 | } |