| 1 |
<?php |
| 2 |
namespace YayMail\Elements; |
| 3 |
|
| 4 |
use YayMail\Abstracts\BaseElement; |
| 5 |
use YayMail\Utils\SingletonTrait; |
| 6 |
|
| 7 |
/** |
| 8 |
* OrderProgress element. |
| 9 |
*/ |
| 10 |
class OrderProgress extends BaseElement { |
| 11 |
|
| 12 |
use SingletonTrait; |
| 13 |
|
| 14 |
protected static $type = 'order_progress'; |
| 15 |
|
| 16 |
public $available_email_ids = [ YAYMAIL_WITH_ORDER_EMAILS ]; |
| 17 |
|
| 18 |
public static function get_data( $attributes = [] ) { |
| 19 |
self::$icon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path d="M3,2.5h14v1.75H3Z"/><path fill-rule="evenodd" d="M3.5,4.25h13v6.5h-13ZM4.25,5h11.5v5h-11.5Z"/><path d="M9.5,2.5h1v8.25h-1Z"/><path d="M4,15.5h12v.6H4Z"/><path d="M2.5,15.8a1.8,1.8 0 1,0 3.6,0a1.8,1.8 0 1,0 -3.6,0Z"/><path fill-rule="evenodd" d="M8.2,15.8a1.8,1.8 0 1,0 3.6,0a1.8,1.8 0 1,0 -3.6,0ZM9.15,15.8a.85,.85 0 1,1 1.7,0a.85,.85 0 1,1 -1.7,0Z"/><path fill-rule="evenodd" d="M13.7,15.8a1.8,1.8 0 1,0 3.6,0a1.8,1.8 0 1,0 -3.6,0ZM14.65,15.8a.85,.85 0 1,1 1.7,0a.85,.85 0 1,1 -1.7,0Z"/></svg>'; |
| 20 |
|
| 21 |
$default_icon = esc_url( YAYMAIL_PLUGIN_URL . 'assets/images/check.png' ); |
| 22 |
|
| 23 |
$inactive_step_fields = [ |
| 24 |
'image_url' => $default_icon, |
| 25 |
'image_bg_color' => '#E2E6EE', |
| 26 |
'icon_border_color' => '#E2E6EE', |
| 27 |
'icon_border_style' => 'solid', |
| 28 |
'icon_border_width' => 2, |
| 29 |
]; |
| 30 |
|
| 31 |
$active_step_fields = [ |
| 32 |
'image_url' => $default_icon, |
| 33 |
'image_bg_color' => '#873eff', |
| 34 |
'icon_border_color' => '#873eff', |
| 35 |
'icon_border_style' => 'solid', |
| 36 |
'icon_border_width' => 2, |
| 37 |
]; |
| 38 |
|
| 39 |
$default_steps = [ |
| 40 |
array_merge( |
| 41 |
[ |
| 42 |
'title' => __( 'Ordered', 'yaymail' ), |
| 43 |
], |
| 44 |
$active_step_fields |
| 45 |
), |
| 46 |
array_merge( |
| 47 |
[ |
| 48 |
'title' => __( 'Processing', 'yaymail' ), |
| 49 |
], |
| 50 |
$inactive_step_fields |
| 51 |
), |
| 52 |
array_merge( |
| 53 |
[ |
| 54 |
'title' => __( 'Completed', 'yaymail' ), |
| 55 |
], |
| 56 |
$inactive_step_fields |
| 57 |
), |
| 58 |
]; |
| 59 |
|
| 60 |
return [ |
| 61 |
'id' => uniqid(), |
| 62 |
'type' => self::$type, |
| 63 |
'name' => __( 'Order Progress', 'yaymail' ), |
| 64 |
'icon' => self::$icon, |
| 65 |
'group' => 'woocommerce', |
| 66 |
'available' => true, |
| 67 |
'position' => 152, |
| 68 |
'status_info' => [ |
| 69 |
'text' => __( 'New', 'yaymail' ), |
| 70 |
], |
| 71 |
'data' => [ |
| 72 |
'container_group_definition' => [ |
| 73 |
'component' => 'GroupDefinition', |
| 74 |
'title' => __( 'Container settings', 'yaymail' ), |
| 75 |
'description' => __( 'Handle container layout settings', 'yaymail' ), |
| 76 |
], |
| 77 |
'padding' => [ |
| 78 |
'value_path' => 'padding', |
| 79 |
'component' => 'Spacing', |
| 80 |
'title' => __( 'Padding', 'yaymail' ), |
| 81 |
'default_value' => isset( $attributes['padding'] ) ? $attributes['padding'] : [ |
| 82 |
'top' => '10', |
| 83 |
'right' => '50', |
| 84 |
'bottom' => '10', |
| 85 |
'left' => '50', |
| 86 |
], |
| 87 |
'type' => 'style', |
| 88 |
], |
| 89 |
'background_color' => ElementsHelper::get_color( |
| 90 |
$attributes, |
| 91 |
[ |
| 92 |
'default_value' => isset( $attributes['background_color'] ) ? $attributes['background_color'] : '#ffffff', |
| 93 |
] |
| 94 |
), |
| 95 |
'quick_presets' => [ |
| 96 |
'component' => 'OrderProgressQuickPresets', |
| 97 |
'title' => __( 'Quick presets', 'yaymail' ), |
| 98 |
'type' => 'style', |
| 99 |
], |
| 100 |
'display_style' => [ |
| 101 |
'value_path' => 'display_style', |
| 102 |
'component' => 'Selector', |
| 103 |
'title' => __( 'Display style', 'yaymail' ), |
| 104 |
'default_value' => isset( $attributes['display_style'] ) ? $attributes['display_style'] : 'step_marker', |
| 105 |
'options' => [ |
| 106 |
[ |
| 107 |
'value' => 'step_marker', |
| 108 |
'label' => __( 'Step marker', 'yaymail' ), |
| 109 |
], |
| 110 |
[ |
| 111 |
'value' => 'filled_bar', |
| 112 |
'label' => __( 'Filled bar', 'yaymail' ), |
| 113 |
], |
| 114 |
], |
| 115 |
'type' => 'style', |
| 116 |
], |
| 117 |
'content_breaker' => [ |
| 118 |
'component' => 'LineBreaker', |
| 119 |
], |
| 120 |
'content_group_definition' => [ |
| 121 |
'component' => 'GroupDefinition', |
| 122 |
'title' => __( 'Content settings', 'yaymail' ), |
| 123 |
'description' => __( 'Handle content settings', 'yaymail' ), |
| 124 |
], |
| 125 |
'current_step_index' => [ |
| 126 |
'value_path' => 'current_step_index', |
| 127 |
'component' => 'OrderProgressCurrentStep', |
| 128 |
'title' => __( 'Active step', 'yaymail' ), |
| 129 |
'description' => __( 'Choose the active step.', 'yaymail' ), |
| 130 |
'default_value' => isset( $attributes['current_step_index'] ) ? $attributes['current_step_index'] : 0, |
| 131 |
'type' => 'content', |
| 132 |
], |
| 133 |
'connector_height' => ElementsHelper::get_dimension( |
| 134 |
$attributes, |
| 135 |
[ |
| 136 |
'value_path' => 'connector_height', |
| 137 |
'title' => __( 'Connector height', 'yaymail' ), |
| 138 |
'default_value' => isset( $attributes['connector_height'] ) ? $attributes['connector_height'] : '4', |
| 139 |
'min' => 1, |
| 140 |
'max' => 10, |
| 141 |
'unit' => 'px', |
| 142 |
'type' => 'style', |
| 143 |
] |
| 144 |
), |
| 145 |
'connector_active_color' => ElementsHelper::get_color( |
| 146 |
$attributes, |
| 147 |
[ |
| 148 |
'value_path' => 'connector_active_color', |
| 149 |
'title' => __( 'Connector color (active)', 'yaymail' ), |
| 150 |
'default_value' => isset( $attributes['connector_active_color'] ) ? $attributes['connector_active_color'] : '#873eff', |
| 151 |
] |
| 152 |
), |
| 153 |
'connector_inactive_color' => ElementsHelper::get_color( |
| 154 |
$attributes, |
| 155 |
[ |
| 156 |
'value_path' => 'connector_inactive_color', |
| 157 |
'title' => __( 'Connector color (inactive)', 'yaymail' ), |
| 158 |
'default_value' => isset( $attributes['connector_inactive_color'] ) ? $attributes['connector_inactive_color'] : '#E2E6EE', |
| 159 |
] |
| 160 |
), |
| 161 |
'label_active_color' => ElementsHelper::get_color( |
| 162 |
$attributes, |
| 163 |
[ |
| 164 |
'value_path' => 'label_active_color', |
| 165 |
'title' => __( 'Label color (active)', 'yaymail' ), |
| 166 |
'default_value' => isset( $attributes['label_active_color'] ) ? $attributes['label_active_color'] : '#111827', |
| 167 |
] |
| 168 |
), |
| 169 |
'label_inactive_color' => ElementsHelper::get_color( |
| 170 |
$attributes, |
| 171 |
[ |
| 172 |
'value_path' => 'label_inactive_color', |
| 173 |
'title' => __( 'Label color (inactive)', 'yaymail' ), |
| 174 |
'default_value' => isset( $attributes['label_inactive_color'] ) ? $attributes['label_inactive_color'] : '#9CA3AF', |
| 175 |
] |
| 176 |
), |
| 177 |
'icon_size' => ElementsHelper::get_dimension( |
| 178 |
$attributes, |
| 179 |
[ |
| 180 |
'value_path' => 'icon_size', |
| 181 |
'title' => __( 'Icon size', 'yaymail' ), |
| 182 |
'default_value' => isset( $attributes['icon_size'] ) ? $attributes['icon_size'] : '18', |
| 183 |
'min' => 10, |
| 184 |
'max' => 80, |
| 185 |
'unit' => 'px', |
| 186 |
'type' => 'style', |
| 187 |
] |
| 188 |
), |
| 189 |
'filled_bar_icon_border_radius' => [ |
| 190 |
'value_path' => 'filled_bar_icon_border_radius', |
| 191 |
'component' => 'OrderProgressFilledBarBorderRadius', |
| 192 |
'title' => __( 'Icon border radius', 'yaymail' ), |
| 193 |
'default_value' => isset( $attributes['filled_bar_icon_border_radius'] ) ? $attributes['filled_bar_icon_border_radius'] : '50', |
| 194 |
'min' => 0, |
| 195 |
'max' => 50, |
| 196 |
'unit' => 'px', |
| 197 |
'type' => 'style', |
| 198 |
], |
| 199 |
'label_font_size' => ElementsHelper::get_dimension( |
| 200 |
$attributes, |
| 201 |
[ |
| 202 |
'value_path' => 'label_font_size', |
| 203 |
'title' => __( 'Label font size', 'yaymail' ), |
| 204 |
'default_value' => isset( $attributes['label_font_size'] ) ? $attributes['label_font_size'] : '14', |
| 205 |
'min' => 8, |
| 206 |
'max' => 24, |
| 207 |
'unit' => 'px', |
| 208 |
'type' => 'style', |
| 209 |
] |
| 210 |
), |
| 211 |
'font_family' => [ |
| 212 |
'value_path' => 'font_family', |
| 213 |
'component' => 'FontFamilySelector', |
| 214 |
'title' => __( 'Label font family', 'yaymail' ), |
| 215 |
'default_value' => isset( $attributes['font_family'] ) ? $attributes['font_family'] : 'Georgia, "Times New Roman", Times, serif', |
| 216 |
'type' => 'style', |
| 217 |
], |
| 218 |
'appearance_breaker' => [ |
| 219 |
'component' => 'LineBreaker', |
| 220 |
], |
| 221 |
'appearance_group_definition' => [ |
| 222 |
'component' => 'GroupDefinition', |
| 223 |
'title' => __( 'Appearance', 'yaymail' ), |
| 224 |
'description' => __( 'Handle per-step icon and background colors.', 'yaymail' ), |
| 225 |
], |
| 226 |
'steps' => [ |
| 227 |
'value_path' => 'steps', |
| 228 |
'component' => 'OrderProgressSteps', |
| 229 |
'title' => __( 'Steps', 'yaymail' ), |
| 230 |
'default_value' => isset( $attributes['steps'] ) && is_array( $attributes['steps'] ) ? $attributes['steps'] : $default_steps, |
| 231 |
'type' => 'content', |
| 232 |
], |
| 233 |
], |
| 234 |
]; |
| 235 |
} |
| 236 |
} |