| @@ -30,19 +30,26 @@ | ||
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * Show a toast. |
| 33 | 33 | * |
| 34 | - * There is no tone: the shell renders every toast the same way | |
| 35 | - * (`wp.os.showToast()` takes no severity), so a `$tone` argument | |
| 36 | - * here would be a promise the platform cannot keep. Say what | |
| 37 | - * happened in the message, and use `<os-notice tone="…">` in the | |
| 38 | - * body when a state needs a colour. | |
| 34 | + * `$type` is an id from the toast-type registry the shell ships | |
| 35 | + * (`openstation_get_toast_types()`, filterable through | |
| 36 | + * `openstation_toast_types`): `success`, `warning`, `error`, | |
| 37 | + * `shell-error`, or one a plugin registered. The shell maps it to | |
| 38 | + * the tone the toast wears; an empty or unknown id is the plain | |
| 39 | + * toast, so say what happened in the message either way. | |
| 39 | 40 | * |
| 40 | 41 | * @param string $message Text. |
| 42 | + * @param string $type Toast-type id, or '' for the plain toast. | |
| 41 | 43 | * @return self |
| 42 | 44 | */ |
| 43 | - public function toast( $message ) { | |
| 44 | - return $this->add( 'toast', array( 'message' => (string) $message ) ); | |
| 45 | + public function toast( $message, $type = '' ) { | |
| 46 | + $effect = array( 'message' => (string) $message ); | |
| 47 | + if ( '' !== (string) $type ) { | |
| 48 | + // `type` is the effect kind on the wire; the toast type rides as `toastType`. | |
| 49 | + $effect['toastType'] = (string) $type; | |
| 50 | + } | |
| 51 | + return $this->add( 'toast', $effect ); | |
| 45 | 52 | } |
| 46 | 53 | |
| 47 | 54 | /** |
| 48 | 55 | * Retitle the window for this session. |