class-modal-dialog.php
2 years ago
class-notice.php
2 years ago
class-redirect-message.php
2 years ago
class-ui-elements.php
2 weeks ago
class-ui-settings.php
2 years ago
class-ui.php
2 years ago
class-ui-settings.php
333 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Preview and settings for UI elements. |
| 4 | * |
| 5 | * @package wp-job-manager |
| 6 | * @since 2.2.0 |
| 7 | */ |
| 8 | |
| 9 | namespace WP_Job_Manager\UI; |
| 10 | |
| 11 | use WP_Job_Manager\Singleton; |
| 12 | |
| 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | exit; // Exit if accessed directly. |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Preview and settings for UI elements. |
| 19 | * |
| 20 | * @access private |
| 21 | * |
| 22 | * @internal |
| 23 | */ |
| 24 | class UI_Settings { |
| 25 | |
| 26 | use Singleton; |
| 27 | |
| 28 | /** |
| 29 | * Instance constructor |
| 30 | */ |
| 31 | private function __construct() { |
| 32 | add_shortcode( 'job_manager_ui_test', [ $this, 'preview_ui_elements' ] ); |
| 33 | |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Output previews of UI elements in various scenarios. |
| 38 | * |
| 39 | * @access private |
| 40 | * |
| 41 | * @return string Generated HTML of UI elements. |
| 42 | */ |
| 43 | public function preview_ui_elements() { |
| 44 | $elements = []; |
| 45 | |
| 46 | $modal = new Modal_Dialog(); |
| 47 | $modal_content = Notice::render( |
| 48 | [ |
| 49 | 'title' => 'Test Modal Dialog', |
| 50 | 'message' => 'This is a test dialog message.', |
| 51 | 'buttons' => [ |
| 52 | [ |
| 53 | 'label' => 'Primary Button', |
| 54 | 'url' => '/', |
| 55 | ], |
| 56 | ], |
| 57 | 'links' => [ |
| 58 | [ |
| 59 | 'label' => 'Close', |
| 60 | 'onclick' => '{close}', |
| 61 | ], |
| 62 | ], |
| 63 | ] |
| 64 | ); |
| 65 | |
| 66 | $elements[] = '<h2>Modal Dialog</h2>'; |
| 67 | |
| 68 | $elements[] = Notice::dialog( |
| 69 | [ |
| 70 | 'message' => 'Test opening a modal dialog from here.', |
| 71 | 'buttons' => [ |
| 72 | [ |
| 73 | 'label' => 'Open Modal', |
| 74 | 'onclick' => $modal->open(), |
| 75 | ], |
| 76 | ], |
| 77 | ] |
| 78 | ); |
| 79 | |
| 80 | $elements[] = $modal->render( $modal_content ); |
| 81 | |
| 82 | $elements[] = '<h2>Notices</h2>'; |
| 83 | |
| 84 | $elements[] = Notice::success( 'Notice rendered successfully.' ); |
| 85 | $elements[] = Notice::error( 'Invalid notice message.' ); |
| 86 | $elements[] = Notice::error( |
| 87 | [ |
| 88 | 'classes' => [ 'actions-right' ], |
| 89 | 'message' => 'A user account already exists for this e-mail.', |
| 90 | 'buttons' => [ |
| 91 | [ |
| 92 | 'url' => '/', |
| 93 | 'label' => 'Sign in', |
| 94 | ], |
| 95 | ], |
| 96 | ] |
| 97 | ); |
| 98 | |
| 99 | $elements[] = Notice::render( |
| 100 | [ |
| 101 | 'title' => 'Job listing active', |
| 102 | 'icon' => 'info', |
| 103 | 'classes' => [ 'color-strong', 'message-icon' ], |
| 104 | 'message' => 'Expires in 25 days.', |
| 105 | ] |
| 106 | ); |
| 107 | |
| 108 | $elements[] = Notice::render( |
| 109 | [ |
| 110 | 'message' => 'This is a test notice message with a checkmark.', |
| 111 | 'icon' => 'check', |
| 112 | ] |
| 113 | ); |
| 114 | |
| 115 | $elements[] = Notice::render( |
| 116 | [ |
| 117 | 'message' => 'This is a test notice message.', |
| 118 | ] |
| 119 | ); |
| 120 | |
| 121 | $elements[] = Notice::render( |
| 122 | [ |
| 123 | 'classes' => [ 'type-hint' ], |
| 124 | 'message' => 'Already have an account?', |
| 125 | 'buttons' => [ |
| 126 | [ |
| 127 | 'label' => 'Sign In', |
| 128 | 'url' => '/', |
| 129 | ], |
| 130 | ], |
| 131 | ] |
| 132 | ); |
| 133 | |
| 134 | $elements[] = Notice::dialog( |
| 135 | [ |
| 136 | 'message' => __( 'Sign in or create an account to manage your listings.', 'wp-job-manager' ), |
| 137 | 'buttons' => [ |
| 138 | [ |
| 139 | 'url' => '/', |
| 140 | 'label' => 'Sign in', |
| 141 | ], |
| 142 | [ |
| 143 | 'url' => '/', |
| 144 | 'label' => 'Create Account', |
| 145 | ], |
| 146 | ], |
| 147 | ] |
| 148 | ); |
| 149 | |
| 150 | $elements[] = Notice::render( |
| 151 | [ |
| 152 | 'classes' => [ 'color-error' ], |
| 153 | 'message' => 'This is a test notice message with an alert icon and red colors.', |
| 154 | 'icon' => 'alert', |
| 155 | ] |
| 156 | ); |
| 157 | |
| 158 | $elements[] = Notice::render( |
| 159 | [ |
| 160 | 'classes' => [ 'color-success' ], |
| 161 | 'message' => 'This is a super green test notice message.', |
| 162 | 'icon' => 'check', |
| 163 | ] |
| 164 | ); |
| 165 | |
| 166 | $elements[] = Notice::render( |
| 167 | [ |
| 168 | 'classes' => [ 'color-info' ], |
| 169 | 'message' => 'This is an informational blue message.', |
| 170 | 'icon' => 'info', |
| 171 | ] |
| 172 | ); |
| 173 | |
| 174 | $elements[] = Notice::render( |
| 175 | [ |
| 176 | 'title' => 'Custom SVG Icon', |
| 177 | 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"> |
| 178 | <path stroke="#1E1E1E" stroke-width="1.5" d="M19.25 19.25v-9.5H4.75v9.5z"/> |
| 179 | <path fill="#1E1E1E" fill-rule="evenodd" d="M13 19V9h-1.5v10H13Z" clip-rule="evenodd"/> |
| 180 | <path stroke="#1E1E1E" stroke-width="1.5" d="M16.5 6.5c0 .97-.78 1.75-1.75 1.75H13V6.5a1.75 1.75 0 1 1 3.5 0ZM8 6.5c0 .97.78 1.75 1.75 1.75h1.75V6.5a1.75 1.75 0 1 0-3.5 0Z"/> |
| 181 | </svg> |
| 182 | ', |
| 183 | ] |
| 184 | ); |
| 185 | |
| 186 | $elements[] = Notice::render( |
| 187 | [ |
| 188 | 'title' => 'Test Notice Created', |
| 189 | 'icon' => 'check', |
| 190 | 'message' => 'This is a test Job Manager notice. Should be large with a checkmark.', |
| 191 | 'buttons' => [ |
| 192 | [ |
| 193 | 'label' => 'Primary Button', |
| 194 | 'url' => '/', |
| 195 | ], |
| 196 | [ |
| 197 | 'label' => 'Secondary Button', |
| 198 | 'url' => '/', |
| 199 | ], |
| 200 | ], |
| 201 | 'links' => [ |
| 202 | [ |
| 203 | 'label' => 'Action', |
| 204 | 'url' => '/', |
| 205 | ], |
| 206 | [ |
| 207 | 'label' => 'Action', |
| 208 | 'url' => '/', |
| 209 | ], |
| 210 | ], |
| 211 | ] |
| 212 | ); |
| 213 | |
| 214 | $elements[] = Notice::render( |
| 215 | [ |
| 216 | 'title' => 'Test Notice Created', |
| 217 | 'message' => 'This is a test Job Manager notice. Should be large with a checkmark.', |
| 218 | 'buttons' => [ |
| 219 | [ |
| 220 | 'label' => 'Light Button', |
| 221 | 'url' => '/', |
| 222 | 'primary' => false, |
| 223 | ], |
| 224 | ], |
| 225 | 'links' => [ |
| 226 | [ |
| 227 | 'label' => 'Action', |
| 228 | 'url' => '/', |
| 229 | ], |
| 230 | ], |
| 231 | ] |
| 232 | ); |
| 233 | |
| 234 | $elements[] = Notice::render( |
| 235 | [ |
| 236 | 'title' => 'Test Notice Created', |
| 237 | 'message' => 'This is a test Job Manager notice.', |
| 238 | 'links' => [ |
| 239 | [ |
| 240 | 'label' => 'Action', |
| 241 | 'url' => '/', |
| 242 | ], |
| 243 | [ |
| 244 | 'label' => 'Action', |
| 245 | 'url' => '/', |
| 246 | ], |
| 247 | ], |
| 248 | ] |
| 249 | ); |
| 250 | |
| 251 | $elements[] = Notice::render( |
| 252 | [ |
| 253 | 'title' => 'Test Notice Created', |
| 254 | 'icon' => 'check', |
| 255 | 'message' => 'This is a test Job Manager notice. Should be large with a checkmark.', |
| 256 | 'buttons' => [ |
| 257 | [ |
| 258 | 'label' => 'Primary Button', |
| 259 | 'url' => '/', |
| 260 | ], |
| 261 | ], |
| 262 | ] |
| 263 | ); |
| 264 | |
| 265 | $elements[] = Notice::render( |
| 266 | [ |
| 267 | 'icon' => 'check', |
| 268 | 'message' => 'This is a test Job Manager notice, with an icon, message and an action.', |
| 269 | 'links' => [ |
| 270 | [ |
| 271 | 'label' => 'Action', |
| 272 | 'url' => '/', |
| 273 | ], |
| 274 | ], |
| 275 | ] |
| 276 | ); |
| 277 | |
| 278 | $elements[] = Notice::render( |
| 279 | [ |
| 280 | 'icon' => 'check', |
| 281 | 'classes' => [ 'alignwide' ], |
| 282 | 'message' => 'This is a wide Job Manager notice, with an icon, message and an action. Actions are on the side.', |
| 283 | 'links' => [ |
| 284 | [ |
| 285 | 'label' => 'Action', |
| 286 | 'url' => '/', |
| 287 | ], |
| 288 | ], |
| 289 | ] |
| 290 | ); |
| 291 | |
| 292 | $elements[] = Notice::render( |
| 293 | [ |
| 294 | 'message' => 'This is a test Job Manager notice, with only a message and an action.', |
| 295 | 'links' => [ |
| 296 | [ |
| 297 | 'label' => 'Action', |
| 298 | 'url' => '/', |
| 299 | ], |
| 300 | ], |
| 301 | ] |
| 302 | ); |
| 303 | |
| 304 | $elements[] = Notice::render( |
| 305 | [ |
| 306 | 'message' => 'This is a test Job Manager notice.', |
| 307 | 'buttons' => [ |
| 308 | [ |
| 309 | 'label' => 'Primary Button', |
| 310 | 'url' => '/', |
| 311 | ], |
| 312 | ], |
| 313 | ] |
| 314 | ); |
| 315 | |
| 316 | $elements[] = Notice::render( |
| 317 | [ |
| 318 | 'message' => 'This is a test Job Manager notice.', |
| 319 | 'buttons' => [ |
| 320 | [ |
| 321 | 'label' => 'Outlined Button', |
| 322 | 'url' => '/', |
| 323 | 'primary' => false, |
| 324 | ], |
| 325 | ], |
| 326 | ] |
| 327 | ); |
| 328 | |
| 329 | return implode( '', $elements ); |
| 330 | |
| 331 | } |
| 332 | } |
| 333 |