Skip to content

ui

Enables the extension to interact with the command bar window.

Functions

ui.createToast

ui.createToast(options: ToastOptions): Toast

Create a toast instance.

Example

import { _extension } from '@altdot/extension';
export default function Command() {
const toast = _extension.ui.createToast({
title: 'Hello world',
});
toast.show();
setTimeout(() => {
toast.hide();
}, 1000);
}

ui.showToast

ui.showToast(options: ToastOptions): void

Create and show toast

Example

import { _extension } from '@altdot/extension';
export default function Command() {
_extension.ui.showToast({
title: 'Hello world',
});
}

ui.closeWindow

ui.closeWindow(): Promise<void>

Close the command bar window

Example

import { _extension } from '@altdot/extension';
export default function Command() {
_extension.ui.closeWindow();
}

ui.searchPanel.clearValue

ui.searchPanel.clearValue(): void

Clear the command bar search panel value.

Example

import { _extension } from '@altdot/extension';
export default function Command() {
_extension.ui.searchPanel.clearValue();
}

ui.searchPanel.updatePlaceholder

ui.searchPanel.updatePlaceholder(placeholder: string): void

Update the command bar search panel placeholder.

Example

import { _extension } from '@altdot/extension';
export default function Command() {
_extension.ui.searchPanel.updatePlaceholder('Search items...');
}

ui.alert.confirm

ui.alert.confirm(options: ConfirmOptions): Promise<boolean>

Show confirmation alert.

Example

import { _extension } from '@altdot/extension';
export default async function Command() {
const isConfirmed = await _extension.ui.alert.confirm({
title: 'Are you sure you want to continue?',
body: "You can't undo this action",
okText: 'Continue'
});
if (isConfirmed) {
console.log('Hello world!');
}
}

Events

ui.searchPanel.onChanged

Events.Event<(value: string) => void>

Fired when the command bar search panel value is changed.

Example

import { useEffect, useState } from 'react';
import { _extension } from '@altdot/extension';
export default function Command() {
const [value, setValue] = useState('');
useEffect(
() =>
_extension.ui.searchPanel.onChanged.addListener((search) =>
setValue(search),
),
[],
);
return <>{value}</>;
}

ui.searchPanel.onKeydown

Events.Event<(event: KeydownEvent) => void>

Fired when a keys is pressed on the command bar search panel.

Example

import { useEffect, useState } from 'react';
import { _extension } from '@altdot/extension';
export default function Command() {
const [value, setValue] = useState('');
useEffect(
() =>
_extension.ui.searchPanel.onKeydown.addListener((event) => {
if (event.key === 'Enter' && event.ctrlKey) {
setValue('Hello world!');
}
}),
[],
);
return <>{value}</>;
}

Types

ui.ToastOptions

Options for the ui.createToast method.

interface ToastOptions {
title: string;
timeout?: number;
description?: string;
type?: 'loading' | 'error' | 'success';
}
PropertyTypeDescription
titlestringThe toast’s title
description?stringThe toast’s description
type?('loading' | 'error' | 'success')The toast’s type
timeout?numberHow long to display the toast in milliseconds. Default to 3000

ui.Toast

The toast instance.

interface Toast extends ToastOptions {
hide(): void;
show(options?: Partial<ToastOptions>): void;
}
PropertyTypeDescription
hide() => voidHide the toast
hide(options: Partial<ToastOptions>) => voidShow the toast

ui.searchPanel.KeyDownEvent

Event when key is pressed on the command bar search panel.

interface KeydownEvent {
key: string;
altKey: boolean;
ctrlKey: boolean;
metaKey: boolean;
shiftKey: boolean;
}
PropertyTypeDescription
keystringThe pressed key
altKeybooleanWhether the alt key is pressed
ctrlKeybooleanWhether the ctrl key is pressed
metaKeybooleanWhether the meta key is pressed
shiftKeybooleanWhether the shift key is pressed

ui.alert.ConfirmOptions

Options for the ui.alert.confirm method.

interface ConfirmOptions {
title: string;
body?: string;
okText?: string;
cancelText?: string;
okVariant?: ButtonVariant;
}
PropertyTypeDescription
titlestringThe confirm title
body?stringThe confirm body
okText?stringThe confirm ok text button
cancelText?stringThe confirm cancel text button
okText?ButtonVariantThe confirm ok button variant

ui.alert.ButtonVariant

The alert button variant.

type ButtonVariant = 'default' | 'secondary' | 'destructive';