--- /dev/null
+<?php
+
+namespace Cube\Elementor\Widgets;
+
+use Elementor\Widget_Base;
+use Elementor\Controls_Manager;
+
+use function Roots\view;
+
+
+class DynamicTable extends Widget_Base {
+
+ // Widget name / ID
+ public function get_name() {
+ return 'cube-dynamic-table';
+ }
+
+ // Elementor widget title
+ public function get_title() {
+ return __( 'Tableau de comparison', 'cube' );
+ }
+
+ // Elementor interface icon
+ public function get_icon() {
+ return 'eicon-table';
+ }
+
+ // Where to display the widget in the Elementor interface
+ public function get_categories() {
+ return [ 'theme-elements' ];
+ }
+
+ /**
+ * List of scripts the widget depends on.
+ * Used to set scripts dependencies required to run the widget.
+ *
+ * @since 1.0.0
+ * @access public
+ * @return array Widget scripts dependencies.
+ */
+ public function get_script_depends() {
+ return [];
+ }
+ /**
+ * Register the widget controls.
+ * Adds different input fields to allow the user to change and customize the widget settings.
+ *
+ * @since 1.0.0
+ * @access protected
+ */
+ protected function _register_controls() {
+
+ $this->start_controls_section(
+ 'section_content',
+ [
+ 'label' => __( 'Tableau de comparison', 'cube' ),
+ ]
+ );
+
+ $this->add_control(
+ 'column_headings',
+ [
+ 'label' => __( 'En-têtes de colonne (un par ligne)', 'cube' ),
+ 'type' => Controls_Manager::TEXTAREA,
+ 'default' => '',
+ 'placeholder' => __("Titre 1\nTitre 2\nTitre 3\n...", 'cube'),
+ ]
+ );
+
+ $this->add_control(
+ 'rows',
+ [
+ 'label' => __( 'Lignes du tableau', 'cube' ),
+ 'type' => Controls_Manager::REPEATER,
+ 'fields' => [
+ [
+ 'name' => 'cells',
+ 'label' => __( 'Cellules du tableau (une valeur par ligne)', 'cube' ),
+ 'placeholder' => __("Valeur 1\nValeur 2\nValeur 3\n...", 'cube'),
+ 'type' => Controls_Manager::TEXTAREA,
+ 'default' => '',
+ 'label_block' => true,
+ ],
+ [
+ 'name' => 'bg_color',
+ 'label' => __( 'Couleur de fond', 'cube' ),
+ 'type' => Controls_Manager::SELECT,
+ 'options' => [
+ '' => __( 'Défaut', 'cube' ),
+ 'bg-light' => __( 'Gris clair', 'cube' ),
+ ],
+ ],
+ [
+ 'name' => 'text_align',
+ 'label' => __( 'Alignement du texte', 'cube' ),
+ 'type' => Controls_Manager::SELECT,
+ 'options' => [
+ '' => __( 'Défaut', 'cube' ),
+ 'text-left' => __( 'Gauche', 'cube' ),
+ 'text-center' => __( 'Centré', 'cube' ),
+ 'text-right' => __( 'Droit', 'cube' ),
+ ],
+ ],
+ [
+ 'name' => 'font_style',
+ 'label' => __( 'Style de police', 'cube' ),
+ 'type' => Controls_Manager::SELECT,
+ 'options' => [
+ '' => __( 'Défaut', 'cube' ),
+ 'font-bold' => __( 'Gras', 'cube' ),
+ ],
+ ],
+ ],
+ 'title_field' => '{{{ cells }}}',
+ ]
+ );
+
+
+ $this->end_controls_section();
+ }
+ /**
+ * Render the widget output on the frontend.
+ * Written in PHP and used to generate the final HTML.
+ *
+ * @since 1.0.0
+ * @access protected
+ */
+ protected function render() {
+
+ $column_headings = trim($this->get_settings('column_headings'));
+ $headings = explode(PHP_EOL, $column_headings);
+ $column_count = count($headings);
+ $rows = $this->get_settings('rows');
+
+ // It's possible that there are no headings, so get column count from first row's cells
+ if (empty($column_headings) && isset($rows[0]['cells'])) {
+ $column_count = count(explode(PHP_EOL, trim($rows[0]['cells'])));
+ }
+
+ // Regex replacements for "-" and "+". We have to use regex so it will only replace exact/full matches
+ $substitutions = [
+ '/^-$/' => '<img src="'. \Roots\asset('images/table-dash.svg') .'" class="dynamic-table-icon inline-block sm:w-6e">',
+ '/^\+$/' => '<img src="'. \Roots\asset('images/table-tick.svg') .'" class="dynamic-table-icon inline-block sm:w-6e">',
+ ];
+
+ // Split row data into cells but only up to however many columns there are
+ foreach ($rows as $index => $row) {
+ $row['cells'] = explode(PHP_EOL, trim($row['cells']), $column_count);
+ $row['cells'] = array_map('trim', $row['cells']); // Trim each cell so we don't miss any substitutions
+
+ // Also replace "-" and "+" with their image counterparts
+ $row['cells'] = preg_replace(array_keys($substitutions), array_values($substitutions), $row['cells']);
+
+ $rows[$index] = $row;
+ }
+
+ echo view('widgets/dynamic-table', compact('column_count', 'headings', 'rows'));
+ }
+
+}
--- /dev/null
+<?php
+
+namespace Cube\Elementor\Widgets;
+
+use Elementor\Widget_Base;
+use Elementor\Controls_Manager;
+
+use function Roots\view;
+
+class FancyList extends Widget_Base {
+
+ // Widget name / ID
+ public function get_name() {
+ return 'cube-fancy-list';
+ }
+
+ // Elementor widget title
+ public function get_title() {
+ return __( 'Liste Formatée', 'cube' );
+ }
+
+ // Elementor interface icon
+ public function get_icon() {
+ return 'eicon-bullet-list';
+ }
+
+ // Where to display the widget in the Elementor interface
+ public function get_categories() {
+ return [ 'theme-elements' ];
+ }
+
+ /**
+ * List of scripts the widget depends on.
+ * Used to set scripts dependencies required to run the widget.
+ *
+ * @since 1.0.0
+ * @access public
+ * @return array Widget scripts dependencies.
+ */
+ public function get_script_depends() {
+ return [];
+ }
+ /**
+ * Register the widget controls.
+ * Adds different input fields to allow the user to change and customize the widget settings.
+ *
+ * @since 1.0.0
+ * @access protected
+ */
+ protected function _register_controls() {
+
+ $this->start_controls_section(
+ 'section_content',
+ [
+ 'label' => __( 'Liste formatée', 'cube' ),
+ ]
+ );
+
+ $this->add_control(
+ 'title',
+ [
+ 'label' => __( 'Titre de liste', 'cube' ),
+ 'type' => Controls_Manager::TEXT,
+ 'default' => '',
+ ]
+ );
+
+ $this->add_control(
+ 'items',
+ [
+ 'label' => __( 'Éléments', 'cube' ),
+ 'type' => Controls_Manager::REPEATER,
+ 'fields' => [
+ [
+ 'name' => 'content',
+ 'default' => '',
+ 'label' => __( 'Contenus', 'cube' ),
+ 'type' => Controls_Manager::WYSIWYG,
+ 'label_block' => true,
+ ],
+ ],
+ 'title_field' => '{{{ content }}}',
+ ]
+ );
+
+ $this->end_controls_section();
+ }
+ /**
+ * Render the widget output on the frontend.
+ * Written in PHP and used to generate the final HTML.
+ *
+ * @since 1.0.0
+ * @access protected
+ */
+ protected function render() {
+
+ $title = $this->get_settings('title');
+ $items = $this->get_settings('items');
+
+ echo view('widgets/fancy-list', compact('title', 'items'));
+ }
+
+}