Add color arg to /echo for custom color

This commit is contained in:
Wolfsblvt 2024-09-06 18:55:50 +02:00
parent c9ed91099f
commit a4e72da40f
1 changed files with 19 additions and 10 deletions

View File

@ -771,11 +771,6 @@ export function initDefaultSlashCommands() {
new SlashCommandEnumValue('success', 'success', enumTypes.enum, '✅'), new SlashCommandEnumValue('success', 'success', enumTypes.enum, '✅'),
], ],
}), }),
SlashCommandNamedArgument.fromProps({
name: 'cssClass',
description: 'additional css class to add to the toast message (e.g. for custom styling)',
typeList: [ARGUMENT_TYPE.STRING],
}),
SlashCommandNamedArgument.fromProps({ SlashCommandNamedArgument.fromProps({
name: 'timeout', name: 'timeout',
description: 'time in milliseconds to display the toast message. Set this and \'extendedTimeout\' to 0 to show indefinitely until dismissed.', description: 'time in milliseconds to display the toast message. Set this and \'extendedTimeout\' to 0 to show indefinitely until dismissed.',
@ -802,6 +797,15 @@ export function initDefaultSlashCommands() {
defaultValue: 'false', defaultValue: 'false',
enumList: commonEnumProviders.boolean('trueFalse')(), enumList: commonEnumProviders.boolean('trueFalse')(),
}), }),
SlashCommandNamedArgument.fromProps({
name: 'cssClass',
description: 'additional css class to add to the toast message (e.g. for custom styling)',
typeList: [ARGUMENT_TYPE.STRING],
}),
SlashCommandNamedArgument.fromProps({
name: 'color',
description: 'custom CSS color of the toast message. Accepts all valid CSS color values (e.g. \'red\', \'#FF0000\', \'rgb(255, 0, 0)\').<br />>Can be more customizable with the \'cssClass\' argument and custom classes.',
})
], ],
unnamedArgumentList: [ unnamedArgumentList: [
new SlashCommandArgument( new SlashCommandArgument(
@ -2186,7 +2190,7 @@ async function generateCallback(args, value) {
/** /**
* *
* @param {{title?: string, severity?: string, cssClass?: string, timeout?: string, extendedTimeout?: string, preventDuplicates?: string, awaitDismissal?: string}} args - named arguments from the slash command * @param {{title?: string, severity?: string, timeout?: string, extendedTimeout?: string, preventDuplicates?: string, awaitDismissal?: string, cssClass?: string, color?: string}} args - named arguments from the slash command
* @param {string} value - The string to echo (unnamed argument from the slash command) * @param {string} value - The string to echo (unnamed argument from the slash command)
* @returns {Promise<string>} The text that was echoed * @returns {Promise<string>} The text that was echoed
*/ */
@ -2226,22 +2230,27 @@ async function echoCallback(args, value) {
options.toastClass = args.cssClass; options.toastClass = args.cssClass;
} }
let toast;
switch (severity) { switch (severity) {
case 'error': case 'error':
toastr.error(value, title, options); toast = toastr.error(value, title, options);
break; break;
case 'warning': case 'warning':
toastr.warning(value, title, options); toast = toastr.warning(value, title, options);
break; break;
case 'success': case 'success':
toastr.success(value, title, options); toast = toastr.success(value, title, options);
break; break;
case 'info': case 'info':
default: default:
toastr.info(value, title, options); toast = toastr.info(value, title, options);
break; break;
} }
if (args.color) {
toast.css('background-color', args.color);
}
if (awaitDismissal) { if (awaitDismissal) {
return new Promise((resolve) => { return new Promise((resolve) => {
resolveToastDismissal = resolve; resolveToastDismissal = resolve;