ButtonGroupEvents

The ButtonGroupEvents interface defines the event map for a button group component in ts-better-console. It describes the events that can be emitted by a button group, allowing you to listen and respond to user interactions such as clicking a button or exiting the button group.

Type Definition

The ButtonGroupEvents interface includes the following events:

  • click: Emitted when a button in the group is clicked. Provides the label (string) of the clicked button and its index (number) within the group.
  • exit: Emitted when the user exits the button group. No arguments are passed.
interface ButtonGroupEvents {
  click: [label: string, index: number];
  exit: [];
}

Usage

You can listen to ButtonGroupEvents when using a button group to handle user interactions:

import { ButtonGroup } from "ts-better-console";

const group = new ButtonGroup([
{ label: "Option A", onClick: () => {} },
{ label: "Option B", onClick: () => {} },
]);

group.on("click", (label, index) => {
console.log(`Clicked: ${label} at index ${index}`);
group.destroy();
});

group.on("exit", () => {
console.log("Exited button group");
});

group.show();

Want to support this project?

If you find ts-better-console useful and want to support its development, consider starring the GitHub repository or buying me a coffee! Your support helps me dedicate more time to improving the library and adding new features.

Want to contribute to this project?

Contributions are welcome! If you're interested in improving the library, fixing bugs, or adding new features, feel free to check out the GitHub repository and submit a pull request. Whether you're a seasoned developer or new to open source, your contributions can make a difference!