| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPDeveloper\BetterDocs\Editors\Elementor\Widget; |
| 4 |
|
| 5 |
use WPDeveloper\BetterDocs\Editors\Elementor\BaseWidget; |
| 6 |
use Elementor\Controls_Manager; |
| 7 |
use Elementor\Group_Control_Typography; |
| 8 |
use Elementor\Repeater; |
| 9 |
|
| 10 |
class CodeSnippet extends BaseWidget { |
| 11 |
|
| 12 |
public function get_name() { |
| 13 |
return 'betterdocs-code-snippet'; |
| 14 |
} |
| 15 |
|
| 16 |
public function get_title() { |
| 17 |
return __( 'BetterDocs Code Snippet', 'betterdocs' ); |
| 18 |
} |
| 19 |
|
| 20 |
public function get_categories() { |
| 21 |
return [ 'betterdocs-elements' ]; |
| 22 |
} |
| 23 |
|
| 24 |
public function get_keywords() { |
| 25 |
return [ 'betterdocs-elements', 'code', 'snippet', 'syntax', 'highlight', 'programming', 'betterdocs' ]; |
| 26 |
} |
| 27 |
|
| 28 |
public function get_icon() { |
| 29 |
return 'betterdocs-icon-code-snippet'; |
| 30 |
} |
| 31 |
|
| 32 |
public function get_style_depends() { |
| 33 |
return [ 'betterdocs-code-snippet' ]; |
| 34 |
} |
| 35 |
|
| 36 |
public function get_script_depends() { |
| 37 |
return [ 'betterdocs-code-snippet' ]; |
| 38 |
} |
| 39 |
|
| 40 |
public function get_custom_help_url() { |
| 41 |
return 'https://betterdocs.co/docs/configure-code-snippet-in-betterdocs/'; |
| 42 |
} |
| 43 |
|
| 44 |
protected function register_controls() { |
| 45 |
// Content Tab |
| 46 |
$this->start_controls_section( |
| 47 |
'content_section', |
| 48 |
[ |
| 49 |
'label' => __( 'Code Snippet', 'betterdocs' ), |
| 50 |
'tab' => Controls_Manager::TAB_CONTENT, |
| 51 |
] |
| 52 |
); |
| 53 |
|
| 54 |
$this->add_control( |
| 55 |
'code_content', |
| 56 |
[ |
| 57 |
'label' => __( 'Code', 'betterdocs' ), |
| 58 |
'type' => Controls_Manager::CODE, |
| 59 |
'language' => 'html', // Default language for CodeMirror |
| 60 |
'rows' => 15, |
| 61 |
'default' => "// Paste or type your code here…", |
| 62 |
'placeholder' => __( 'Enter your code snippet here...', 'betterdocs' ), |
| 63 |
'description' => __( 'Enter your code snippet. Use Tab for indentation and enjoy syntax highlighting in the editor.', 'betterdocs' ), |
| 64 |
] |
| 65 |
); |
| 66 |
|
| 67 |
$this->add_control( |
| 68 |
'language', |
| 69 |
[ |
| 70 |
'label' => __( 'Language', 'betterdocs' ), |
| 71 |
'type' => Controls_Manager::SELECT, |
| 72 |
'default' => 'javascript', |
| 73 |
'options' => [ |
| 74 |
'javascript' => __( 'JavaScript', 'betterdocs' ), |
| 75 |
'php' => __( 'PHP', 'betterdocs' ), |
| 76 |
'python' => __( 'Python', 'betterdocs' ), |
| 77 |
'java' => __( 'Java', 'betterdocs' ), |
| 78 |
'ruby' => __( 'Ruby', 'betterdocs' ), |
| 79 |
'curl' => __( 'cURL', 'betterdocs' ), |
| 80 |
'bash' => __( 'Bash', 'betterdocs' ), |
| 81 |
'json' => __( 'JSON', 'betterdocs' ), |
| 82 |
'yaml' => __( 'YAML', 'betterdocs' ), |
| 83 |
'html' => __( 'HTML', 'betterdocs' ), |
| 84 |
'css' => __( 'CSS', 'betterdocs' ), |
| 85 |
'sql' => __( 'SQL', 'betterdocs' ), |
| 86 |
'xml' => __( 'XML', 'betterdocs' ), |
| 87 |
'cpp' => __( 'C++', 'betterdocs' ), |
| 88 |
'csharp' => __( 'C#', 'betterdocs' ), |
| 89 |
'go' => __( 'Go', 'betterdocs' ), |
| 90 |
'rust' => __( 'Rust', 'betterdocs' ), |
| 91 |
'swift' => __( 'Swift', 'betterdocs' ), |
| 92 |
'kotlin' => __( 'Kotlin', 'betterdocs' ), |
| 93 |
'typescript' => __( 'TypeScript', 'betterdocs' ), |
| 94 |
], |
| 95 |
'description' => __( 'Choose language for syntax highlighting.', 'betterdocs' ), |
| 96 |
] |
| 97 |
); |
| 98 |
|
| 99 |
// Additional languages → renders a Mintlify-style language dropdown. |
| 100 |
$variant_repeater = new Repeater(); |
| 101 |
|
| 102 |
$variant_repeater->add_control( |
| 103 |
'variant_language', |
| 104 |
[ |
| 105 |
'label' => __( 'Language', 'betterdocs' ), |
| 106 |
'type' => Controls_Manager::SELECT, |
| 107 |
'default' => 'php', |
| 108 |
'options' => [ |
| 109 |
'javascript' => __( 'JavaScript', 'betterdocs' ), |
| 110 |
'php' => __( 'PHP', 'betterdocs' ), |
| 111 |
'python' => __( 'Python', 'betterdocs' ), |
| 112 |
'java' => __( 'Java', 'betterdocs' ), |
| 113 |
'ruby' => __( 'Ruby', 'betterdocs' ), |
| 114 |
'curl' => __( 'cURL', 'betterdocs' ), |
| 115 |
'bash' => __( 'Bash', 'betterdocs' ), |
| 116 |
'json' => __( 'JSON', 'betterdocs' ), |
| 117 |
'yaml' => __( 'YAML', 'betterdocs' ), |
| 118 |
'html' => __( 'HTML', 'betterdocs' ), |
| 119 |
'css' => __( 'CSS', 'betterdocs' ), |
| 120 |
'sql' => __( 'SQL', 'betterdocs' ), |
| 121 |
'xml' => __( 'XML', 'betterdocs' ), |
| 122 |
'cpp' => __( 'C++', 'betterdocs' ), |
| 123 |
'csharp' => __( 'C#', 'betterdocs' ), |
| 124 |
'go' => __( 'Go', 'betterdocs' ), |
| 125 |
'rust' => __( 'Rust', 'betterdocs' ), |
| 126 |
'swift' => __( 'Swift', 'betterdocs' ), |
| 127 |
'kotlin' => __( 'Kotlin', 'betterdocs' ), |
| 128 |
'typescript' => __( 'TypeScript', 'betterdocs' ), |
| 129 |
], |
| 130 |
] |
| 131 |
); |
| 132 |
|
| 133 |
$variant_repeater->add_control( |
| 134 |
'variant_code', |
| 135 |
[ |
| 136 |
'label' => __( 'Code', 'betterdocs' ), |
| 137 |
'type' => Controls_Manager::CODE, |
| 138 |
'language' => 'html', |
| 139 |
'rows' => 10, |
| 140 |
'default' => '', |
| 141 |
'placeholder' => __( 'Paste or type your code here…', 'betterdocs' ), |
| 142 |
] |
| 143 |
); |
| 144 |
|
| 145 |
$this->add_control( |
| 146 |
'code_variants', |
| 147 |
[ |
| 148 |
'label' => __( 'Additional Languages', 'betterdocs' ), |
| 149 |
'type' => Controls_Manager::REPEATER, |
| 150 |
'fields' => $variant_repeater->get_controls(), |
| 151 |
'default' => [], |
| 152 |
'title_field' => '{{{ variant_language }}}', |
| 153 |
'description' => __( 'Add the same snippet in other languages. A language dropdown appears when you add one or more.', 'betterdocs' ), |
| 154 |
] |
| 155 |
); |
| 156 |
|
| 157 |
$this->end_controls_section(); |
| 158 |
|
| 159 |
// Display Options Section |
| 160 |
$this->start_controls_section( |
| 161 |
'display_options_section', |
| 162 |
[ |
| 163 |
'label' => __( 'Appearance', 'betterdocs' ), |
| 164 |
'tab' => Controls_Manager::TAB_CONTENT, |
| 165 |
] |
| 166 |
); |
| 167 |
|
| 168 |
$this->add_control( |
| 169 |
'theme', |
| 170 |
[ |
| 171 |
'label' => __( 'Theme', 'betterdocs' ), |
| 172 |
'type' => Controls_Manager::SELECT, |
| 173 |
'default' => 'light', |
| 174 |
'options' => [ |
| 175 |
'light' => __( 'Light', 'betterdocs' ), |
| 176 |
'dark' => __( 'Dark', 'betterdocs' ), |
| 177 |
], |
| 178 |
'description' => __( 'Choose light or dark styling for the code snippet block.', 'betterdocs' ), |
| 179 |
] |
| 180 |
); |
| 181 |
|
| 182 |
$this->add_control( |
| 183 |
'show_header', |
| 184 |
[ |
| 185 |
'label' => __( 'Show header bar', 'betterdocs' ), |
| 186 |
'type' => Controls_Manager::SWITCHER, |
| 187 |
'label_on' => __( 'Show', 'betterdocs' ), |
| 188 |
'label_off' => __( 'Hide', 'betterdocs' ), |
| 189 |
'return_value' => 'yes', |
| 190 |
'default' => 'yes', |
| 191 |
'description' => __( 'Toggle the filename header and copy button.', 'betterdocs' ), |
| 192 |
] |
| 193 |
); |
| 194 |
|
| 195 |
$this->add_control( |
| 196 |
'show_copy_button', |
| 197 |
[ |
| 198 |
'label' => __( 'Enable copy button', 'betterdocs' ), |
| 199 |
'type' => Controls_Manager::SWITCHER, |
| 200 |
'label_on' => __( 'Show', 'betterdocs' ), |
| 201 |
'label_off' => __( 'Hide', 'betterdocs' ), |
| 202 |
'return_value' => 'yes', |
| 203 |
'default' => 'yes', |
| 204 |
'description' => __( 'Show a one-click copy-to-clipboard icon.', 'betterdocs' ), |
| 205 |
'condition' => [ |
| 206 |
'show_header' => 'yes', |
| 207 |
], |
| 208 |
] |
| 209 |
); |
| 210 |
|
| 211 |
$this->add_control( |
| 212 |
'show_line_numbers', |
| 213 |
[ |
| 214 |
'label' => __( 'Show line numbers', 'betterdocs' ), |
| 215 |
'type' => Controls_Manager::SWITCHER, |
| 216 |
'label_on' => __( 'Show', 'betterdocs' ), |
| 217 |
'label_off' => __( 'Hide', 'betterdocs' ), |
| 218 |
'return_value' => 'yes', |
| 219 |
'default' => 'no', |
| 220 |
'description' => __( 'Display line numbers in the code block.', 'betterdocs' ), |
| 221 |
] |
| 222 |
); |
| 223 |
|
| 224 |
$this->end_controls_section(); |
| 225 |
|
| 226 |
// File Preview Header Section |
| 227 |
$this->start_controls_section( |
| 228 |
'file_preview_section', |
| 229 |
[ |
| 230 |
'label' => __( 'File Preview Header', 'betterdocs' ), |
| 231 |
'tab' => Controls_Manager::TAB_CONTENT, |
| 232 |
'condition' => [ |
| 233 |
'show_header' => 'yes', |
| 234 |
], |
| 235 |
] |
| 236 |
); |
| 237 |
|
| 238 |
$this->add_control( |
| 239 |
'show_language_label', |
| 240 |
[ |
| 241 |
'label' => __( 'Show Language Label', 'betterdocs' ), |
| 242 |
'type' => Controls_Manager::SWITCHER, |
| 243 |
'label_on' => __( 'Show', 'betterdocs' ), |
| 244 |
'label_off' => __( 'Hide', 'betterdocs' ), |
| 245 |
'return_value' => 'yes', |
| 246 |
'default' => 'yes', |
| 247 |
'description' => __( 'Display the programming language label in the header.', 'betterdocs' ), |
| 248 |
] |
| 249 |
); |
| 250 |
|
| 251 |
$this->add_control( |
| 252 |
'file_name', |
| 253 |
[ |
| 254 |
'label' => __( 'File Name', 'betterdocs' ), |
| 255 |
'type' => Controls_Manager::TEXT, |
| 256 |
'default' => 'filename.js', |
| 257 |
'placeholder' => __( 'Enter filename with extension', 'betterdocs' ), |
| 258 |
'description' => __( 'Enter the filename to display in the header (e.g., hero-section.tsx)', 'betterdocs' ), |
| 259 |
] |
| 260 |
); |
| 261 |
|
| 262 |
$this->add_control( |
| 263 |
'show_traffic_lights', |
| 264 |
[ |
| 265 |
'label' => __( 'Show window buttons', 'betterdocs' ), |
| 266 |
'type' => Controls_Manager::SWITCHER, |
| 267 |
'label_on' => __( 'Show', 'betterdocs' ), |
| 268 |
'label_off' => __( 'Hide', 'betterdocs' ), |
| 269 |
'return_value' => 'yes', |
| 270 |
'default' => 'yes', |
| 271 |
'description' => __( 'Display macOS-style close/minimize/maximize circles.', 'betterdocs' ), |
| 272 |
] |
| 273 |
); |
| 274 |
|
| 275 |
$this->add_control( |
| 276 |
'show_file_icon', |
| 277 |
[ |
| 278 |
'label' => __( 'Show language icon', 'betterdocs' ), |
| 279 |
'type' => Controls_Manager::SWITCHER, |
| 280 |
'label_on' => __( 'Show', 'betterdocs' ), |
| 281 |
'label_off' => __( 'Hide', 'betterdocs' ), |
| 282 |
'return_value' => 'yes', |
| 283 |
'default' => 'yes', |
| 284 |
'description' => __( 'Display the default icon for this file type.', 'betterdocs' ), |
| 285 |
] |
| 286 |
); |
| 287 |
|
| 288 |
$this->add_control( |
| 289 |
'file_icon', |
| 290 |
[ |
| 291 |
'label' => __( 'Custom language icon', 'betterdocs' ), |
| 292 |
'type' => Controls_Manager::MEDIA, |
| 293 |
'media_types' => [ 'image' ], |
| 294 |
'description' => __( 'Upload a custom icon to override the default.', 'betterdocs' ), |
| 295 |
'condition' => [ |
| 296 |
'show_file_icon' => 'yes', |
| 297 |
], |
| 298 |
] |
| 299 |
); |
| 300 |
|
| 301 |
$this->end_controls_section(); |
| 302 |
|
| 303 |
// Style Tab - Wrapper |
| 304 |
$this->start_controls_section( |
| 305 |
'wrapper_style_section', |
| 306 |
[ |
| 307 |
'label' => __( 'Wrapper', 'betterdocs' ), |
| 308 |
'tab' => Controls_Manager::TAB_STYLE, |
| 309 |
] |
| 310 |
); |
| 311 |
|
| 312 |
$this->add_responsive_control( |
| 313 |
'wrapper_margin', |
| 314 |
[ |
| 315 |
'label' => __( 'Margin', 'betterdocs' ), |
| 316 |
'type' => Controls_Manager::DIMENSIONS, |
| 317 |
'size_units' => [ 'px', 'em', '%' ], |
| 318 |
'selectors' => [ |
| 319 |
'{{WRAPPER}} .betterdocs-code-snippet-wrapper' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 320 |
], |
| 321 |
] |
| 322 |
); |
| 323 |
|
| 324 |
$this->add_responsive_control( |
| 325 |
'wrapper_padding', |
| 326 |
[ |
| 327 |
'label' => __( 'Padding', 'betterdocs' ), |
| 328 |
'type' => Controls_Manager::DIMENSIONS, |
| 329 |
'size_units' => [ 'px', 'em', '%' ], |
| 330 |
'selectors' => [ |
| 331 |
'{{WRAPPER}} .betterdocs-code-snippet-wrapper' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 332 |
], |
| 333 |
] |
| 334 |
); |
| 335 |
|
| 336 |
$this->add_control( |
| 337 |
'wrapper_background_color', |
| 338 |
[ |
| 339 |
'label' => __( 'Background Color', 'betterdocs' ), |
| 340 |
'type' => Controls_Manager::COLOR, |
| 341 |
'selectors' => [ |
| 342 |
'{{WRAPPER}} .betterdocs-code-snippet-wrapper' => 'background-color: {{VALUE}};', |
| 343 |
], |
| 344 |
] |
| 345 |
); |
| 346 |
|
| 347 |
$this->add_control( |
| 348 |
'wrapper_border_color', |
| 349 |
[ |
| 350 |
'label' => __( 'Border Color', 'betterdocs' ), |
| 351 |
'type' => Controls_Manager::COLOR, |
| 352 |
'selectors' => [ |
| 353 |
'{{WRAPPER}} .betterdocs-code-snippet-wrapper' => 'border-color: {{VALUE}};', |
| 354 |
], |
| 355 |
] |
| 356 |
); |
| 357 |
|
| 358 |
$this->add_responsive_control( |
| 359 |
'wrapper_border_width', |
| 360 |
[ |
| 361 |
'label' => __( 'Border Width', 'betterdocs' ), |
| 362 |
'type' => Controls_Manager::SLIDER, |
| 363 |
'size_units' => [ 'px' ], |
| 364 |
'range' => [ |
| 365 |
'px' => [ |
| 366 |
'min' => 0, |
| 367 |
'max' => 10, |
| 368 |
], |
| 369 |
], |
| 370 |
'selectors' => [ |
| 371 |
'{{WRAPPER}} .betterdocs-code-snippet-wrapper' => 'border-width: {{SIZE}}{{UNIT}}; border-style: solid;', |
| 372 |
], |
| 373 |
] |
| 374 |
); |
| 375 |
|
| 376 |
$this->add_responsive_control( |
| 377 |
'wrapper_border_radius', |
| 378 |
[ |
| 379 |
'label' => __( 'Border Radius', 'betterdocs' ), |
| 380 |
'type' => Controls_Manager::SLIDER, |
| 381 |
'size_units' => [ 'px' ], |
| 382 |
'range' => [ |
| 383 |
'px' => [ |
| 384 |
'min' => 0, |
| 385 |
'max' => 50, |
| 386 |
], |
| 387 |
], |
| 388 |
'selectors' => [ |
| 389 |
'{{WRAPPER}} .betterdocs-code-snippet-wrapper' => 'border-radius: {{SIZE}}{{UNIT}};', |
| 390 |
], |
| 391 |
] |
| 392 |
); |
| 393 |
|
| 394 |
$this->end_controls_section(); |
| 395 |
|
| 396 |
// Style Tab - Header |
| 397 |
$this->start_controls_section( |
| 398 |
'header_style_section', |
| 399 |
[ |
| 400 |
'label' => __( 'Header', 'betterdocs' ), |
| 401 |
'tab' => Controls_Manager::TAB_STYLE, |
| 402 |
'condition' => [ |
| 403 |
'show_header' => 'yes', |
| 404 |
], |
| 405 |
] |
| 406 |
); |
| 407 |
|
| 408 |
$this->add_responsive_control( |
| 409 |
'header_padding', |
| 410 |
[ |
| 411 |
'label' => __( 'Padding', 'betterdocs' ), |
| 412 |
'type' => Controls_Manager::DIMENSIONS, |
| 413 |
'size_units' => [ 'px', 'em', '%' ], |
| 414 |
'selectors' => [ |
| 415 |
'{{WRAPPER}} .betterdocs-code-snippet-header.betterdocs-file-preview-header' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 416 |
], |
| 417 |
] |
| 418 |
); |
| 419 |
|
| 420 |
$this->add_control( |
| 421 |
'header_background_color', |
| 422 |
[ |
| 423 |
'label' => __( 'Background Color', 'betterdocs' ), |
| 424 |
'type' => Controls_Manager::COLOR, |
| 425 |
'selectors' => [ |
| 426 |
'{{WRAPPER}} .betterdocs-code-snippet-header.betterdocs-file-preview-header' => 'background-color: {{VALUE}};', |
| 427 |
], |
| 428 |
] |
| 429 |
); |
| 430 |
|
| 431 |
$this->add_control( |
| 432 |
'header_border_color', |
| 433 |
[ |
| 434 |
'label' => __( 'Border Color', 'betterdocs' ), |
| 435 |
'type' => Controls_Manager::COLOR, |
| 436 |
'selectors' => [ |
| 437 |
'{{WRAPPER}} .betterdocs-code-snippet-header.betterdocs-file-preview-header' => 'border-bottom-color: {{VALUE}};', |
| 438 |
], |
| 439 |
] |
| 440 |
); |
| 441 |
|
| 442 |
$this->add_responsive_control( |
| 443 |
'header_border_width', |
| 444 |
[ |
| 445 |
'label' => __( 'Border Width', 'betterdocs' ), |
| 446 |
'type' => Controls_Manager::SLIDER, |
| 447 |
'size_units' => [ 'px' ], |
| 448 |
'range' => [ |
| 449 |
'px' => [ |
| 450 |
'min' => 0, |
| 451 |
'max' => 10, |
| 452 |
], |
| 453 |
], |
| 454 |
'selectors' => [ |
| 455 |
'{{WRAPPER}} .betterdocs-code-snippet-header.betterdocs-file-preview-header' => 'border-bottom-width: {{SIZE}}{{UNIT}}; border-bottom-style: solid;', |
| 456 |
], |
| 457 |
'description' => __( 'Controls border bottom width', 'betterdocs' ), |
| 458 |
] |
| 459 |
); |
| 460 |
|
| 461 |
$this->add_group_control( |
| 462 |
Group_Control_Typography::get_type(), |
| 463 |
[ |
| 464 |
'name' => 'file_name_typography', |
| 465 |
'label' => __( 'File Name Typography', 'betterdocs' ), |
| 466 |
'selector' => '{{WRAPPER}} .betterdocs-code-snippet-header .file-name-text', |
| 467 |
] |
| 468 |
); |
| 469 |
|
| 470 |
$this->add_control( |
| 471 |
'file_name_color', |
| 472 |
[ |
| 473 |
'label' => __( 'File Name Color', 'betterdocs' ), |
| 474 |
'type' => Controls_Manager::COLOR, |
| 475 |
'selectors' => [ |
| 476 |
'{{WRAPPER}} .betterdocs-code-snippet-header .file-name-text' => 'color: {{VALUE}};', |
| 477 |
], |
| 478 |
] |
| 479 |
); |
| 480 |
|
| 481 |
$this->add_control( |
| 482 |
'copy_button_color', |
| 483 |
[ |
| 484 |
'label' => __( 'Copy Button Color', 'betterdocs' ), |
| 485 |
'type' => Controls_Manager::COLOR, |
| 486 |
'selectors' => [ |
| 487 |
'{{WRAPPER}} .betterdocs-code-snippet-copy-button' => 'color: {{VALUE}};', |
| 488 |
], |
| 489 |
'condition' => [ |
| 490 |
'show_copy_button' => 'yes', |
| 491 |
], |
| 492 |
] |
| 493 |
); |
| 494 |
|
| 495 |
$this->add_control( |
| 496 |
'copy_button_border_color', |
| 497 |
[ |
| 498 |
'label' => __( 'Copy Button Border Color', 'betterdocs' ), |
| 499 |
'type' => Controls_Manager::COLOR, |
| 500 |
'selectors' => [ |
| 501 |
'{{WRAPPER}} .betterdocs-code-snippet-copy-button' => 'border-color: {{VALUE}};', |
| 502 |
], |
| 503 |
'condition' => [ |
| 504 |
'show_copy_button' => 'yes', |
| 505 |
], |
| 506 |
] |
| 507 |
); |
| 508 |
|
| 509 |
$this->end_controls_section(); |
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
// Style Tab - Line Numbers |
| 514 |
$this->start_controls_section( |
| 515 |
'line_numbers_style_section', |
| 516 |
[ |
| 517 |
'label' => __( 'Line Numbers', 'betterdocs' ), |
| 518 |
'tab' => Controls_Manager::TAB_STYLE, |
| 519 |
'condition' => [ |
| 520 |
'show_line_numbers' => 'yes', |
| 521 |
], |
| 522 |
] |
| 523 |
); |
| 524 |
|
| 525 |
$this->add_responsive_control( |
| 526 |
'line_numbers_padding', |
| 527 |
[ |
| 528 |
'label' => __( 'Padding', 'betterdocs' ), |
| 529 |
'type' => Controls_Manager::DIMENSIONS, |
| 530 |
'size_units' => [ 'px', 'em', '%' ], |
| 531 |
'selectors' => [ |
| 532 |
'{{WRAPPER}} .betterdocs-code-snippet-line-numbers' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 533 |
], |
| 534 |
] |
| 535 |
); |
| 536 |
|
| 537 |
$this->add_control( |
| 538 |
'line_numbers_color', |
| 539 |
[ |
| 540 |
'label' => __( 'Line Number Color', 'betterdocs' ), |
| 541 |
'type' => Controls_Manager::COLOR, |
| 542 |
'selectors' => [ |
| 543 |
'{{WRAPPER}} .betterdocs-code-snippet-line-numbers .line-number' => 'color: {{VALUE}};', |
| 544 |
], |
| 545 |
] |
| 546 |
); |
| 547 |
|
| 548 |
$this->add_control( |
| 549 |
'line_numbers_background_color', |
| 550 |
[ |
| 551 |
'label' => __( 'Line Number Background', 'betterdocs' ), |
| 552 |
'type' => Controls_Manager::COLOR, |
| 553 |
'selectors' => [ |
| 554 |
'{{WRAPPER}} .betterdocs-code-snippet-line-numbers' => 'background-color: {{VALUE}};', |
| 555 |
], |
| 556 |
] |
| 557 |
); |
| 558 |
|
| 559 |
$this->add_control( |
| 560 |
'line_numbers_border_color', |
| 561 |
[ |
| 562 |
'label' => __( 'Border Color', 'betterdocs' ), |
| 563 |
'type' => Controls_Manager::COLOR, |
| 564 |
'selectors' => [ |
| 565 |
'{{WRAPPER}} .betterdocs-code-snippet-line-numbers' => 'border-right-color: {{VALUE}};', |
| 566 |
], |
| 567 |
] |
| 568 |
); |
| 569 |
|
| 570 |
$this->add_responsive_control( |
| 571 |
'line_numbers_border_width', |
| 572 |
[ |
| 573 |
'label' => __( 'Border Width', 'betterdocs' ), |
| 574 |
'type' => Controls_Manager::SLIDER, |
| 575 |
'size_units' => [ 'px' ], |
| 576 |
'range' => [ |
| 577 |
'px' => [ |
| 578 |
'min' => 0, |
| 579 |
'max' => 10, |
| 580 |
], |
| 581 |
], |
| 582 |
'selectors' => [ |
| 583 |
'{{WRAPPER}} .betterdocs-code-snippet-line-numbers' => 'border-right-width: {{SIZE}}{{UNIT}}; border-right-style: solid;', |
| 584 |
], |
| 585 |
'description' => __( 'Controls border right width', 'betterdocs' ), |
| 586 |
] |
| 587 |
); |
| 588 |
|
| 589 |
$this->end_controls_section(); |
| 590 |
|
| 591 |
// Style Tab - Code Content Area |
| 592 |
$this->start_controls_section( |
| 593 |
'code_content_style_section', |
| 594 |
[ |
| 595 |
'label' => __( 'Code Content Area', 'betterdocs' ), |
| 596 |
'tab' => Controls_Manager::TAB_STYLE, |
| 597 |
] |
| 598 |
); |
| 599 |
|
| 600 |
$this->add_responsive_control( |
| 601 |
'code_content_padding', |
| 602 |
[ |
| 603 |
'label' => __( 'Padding', 'betterdocs' ), |
| 604 |
'type' => Controls_Manager::DIMENSIONS, |
| 605 |
'size_units' => [ 'px', 'em', '%' ], |
| 606 |
'selectors' => [ |
| 607 |
'{{WRAPPER}} .betterdocs-code-snippet-code' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 608 |
], |
| 609 |
] |
| 610 |
); |
| 611 |
|
| 612 |
$this->add_control( |
| 613 |
'code_content_background_color', |
| 614 |
[ |
| 615 |
'label' => __( 'Background Color', 'betterdocs' ), |
| 616 |
'type' => Controls_Manager::COLOR, |
| 617 |
'selectors' => [ |
| 618 |
'{{WRAPPER}} .betterdocs-code-snippet-code' => 'background-color: {{VALUE}};', |
| 619 |
], |
| 620 |
] |
| 621 |
); |
| 622 |
|
| 623 |
$this->end_controls_section(); |
| 624 |
} |
| 625 |
|
| 626 |
public function view_params() { |
| 627 |
$settings = $this->get_settings_for_display(); |
| 628 |
|
| 629 |
// Combined [primary + additional] language list — the shared template |
| 630 |
// renders a dropdown when it holds more than one entry. |
| 631 |
$variants = []; |
| 632 |
if ( ! empty( $settings['code_content'] ) ) { |
| 633 |
$variants[] = [ |
| 634 |
'language' => $settings['language'], |
| 635 |
'code' => $settings['code_content'], |
| 636 |
'file_name' => isset( $settings['file_name'] ) ? $settings['file_name'] : '' |
| 637 |
]; |
| 638 |
} |
| 639 |
if ( ! empty( $settings['code_variants'] ) && is_array( $settings['code_variants'] ) ) { |
| 640 |
foreach ( $settings['code_variants'] as $variant ) { |
| 641 |
$code = isset( $variant['variant_code'] ) ? (string) $variant['variant_code'] : ''; |
| 642 |
if ( '' === $code ) { |
| 643 |
continue; |
| 644 |
} |
| 645 |
$variants[] = [ |
| 646 |
'language' => isset( $variant['variant_language'] ) ? $variant['variant_language'] : 'javascript', |
| 647 |
'code' => $code, |
| 648 |
'file_name' => '' |
| 649 |
]; |
| 650 |
} |
| 651 |
} |
| 652 |
|
| 653 |
return [ |
| 654 |
'code_content' => $settings['code_content'], |
| 655 |
'language' => $settings['language'], |
| 656 |
'code_variants' => $variants, |
| 657 |
'show_language_label' => $settings['show_language_label'] === 'yes', |
| 658 |
'show_copy_button' => $settings['show_copy_button'] === 'yes', |
| 659 |
'show_header' => isset( $settings['show_header'] ) ? $settings['show_header'] === 'yes' : true, |
| 660 |
'show_line_numbers' => $settings['show_line_numbers'] === 'yes', |
| 661 |
'theme' => $settings['theme'], |
| 662 |
'widget_type' => 'elementor', |
| 663 |
// File Preview Header |
| 664 |
'file_name' => $settings['file_name'], |
| 665 |
'show_traffic_lights' => $settings['show_traffic_lights'] === 'yes', |
| 666 |
'show_file_icon' => $settings['show_file_icon'] === 'yes', |
| 667 |
'file_icon' => isset( $settings['file_icon']['url'] ) ? $settings['file_icon']['url'] : '', |
| 668 |
]; |
| 669 |
} |
| 670 |
|
| 671 |
protected function render_callback() { |
| 672 |
$this->views( 'widgets/code-snippet' ); |
| 673 |
} |
| 674 |
} |
| 675 |
|