Skip to content

UI Api

Functions for interacting with user interfaces

toast: ToastType

The toast api exposed by svelte-sonner

get message(): AntdMessage

Gimkit’s message object

https://ant.design/components/message#api

AntdMessage


get modal(): AntdModal

Gimkit’s modal object

https://ant.design/components/modal#modalmethod

AntdModal


get notification(): AntdNotification

Gimkit’s notification object, only available when joining or playing a game

https://ant.design/components/notification#api

AntdNotification

addStyles(style): () => void

Adds a style to the DOM

Parameter Type
style string

A function to remove the styles

() => void

const styles = `#element {
color: red;
}`;
api.UI.addStyles(styles);

alert(title, text?): Promise<void>

Shows an alert message. Resolves once the message is dismissed.

Parameter Type Default value
title string undefined
text string ""

Promise<void>

api.UI.alert("Something happened", "This is an alert")
.then(() => console.log("Alert dismissed"));

confirm(title, text?): Promise<boolean>

Shows a prompt asking the user to confirm an action. Resolves to a boolean containing their choice.

Parameter Type Default value
title string undefined
text string ""

Promise<boolean>

api.UI.confirm("Are you sure?", "This cannot be undone")
.then((confirmed) => console.log("Confirmation:", confirmed));

forceReactUpdate(): void

Forces Gimkit’s react tree to fully rerender

void


onComponentLoad<K>(type, callback): () => void

Waits for a component to load, and calls the callback with the component as an argument. If the component has already loaded the callback will be fired immediately. The available components are “notification”, “message”, and “modal”.

Type Parameter
K extends "message" | "notification" | "modal"
Parameter Type
type K
callback (component) => void

A function that cancels waiting

() => void

api.UI.onComponentLoad("message", (message) => {
message.success({ content: "This is a message!" });
});

prompt(title, options?): Promise<string | null>

Shows a prompt asking for user input. Resolves to null if cancelled.

Parameter Type
title string
options? PromptOptions

Promise<string | null>

api.UI.prompt("Name your character", {
text: "This can be changed later",
placeholder: "Character name",
defaultVal: "Player"
}).then((name) => {
if(name === null) console.log("User cancelled");
else console.log("User entered:", name);
});

showModal(element, options?): void

Shows a customizable modal to the user

Parameter Type
element HTMLElement | ReactElement<any, string | JSXElementConstructor<any>>
options { buttons?: readonly ModalButton[]; className?: string; closeOnBackgroundClick?: boolean; id?: string; onClosed?: () => void; style?: string; title?: string; }
options.buttons? readonly ModalButton[]
options.className? string
options.closeOnBackgroundClick? boolean
options.id? string
options.onClosed? () => void
options.style? string
options.title? string

void

const element = document.createElement("div");
element.textContent = "Hello, world!";
api.UI.showModal(element, {
id: "my-modal",
title: "My Modal",
style: "width: 300px;",
className: "someClass",
closeOnBackgroundClick: true,
onClosed: () => {},
buttons: [
{ text: "OK", style: "primary", onClick: () => {} },
{ text: "Cancel", style: "close" },
{ text: "Revert", style: "danger", onClick: () => {} }
]
});