Skip to content

Commit

Permalink
implement add and remove items methods
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberDex committed Jan 30, 2024
1 parent d8f2655 commit 5a4c6c3
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/Select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ type Offset = {
export type SelectItemsOptions = {
items: string[];
backgroundColor: number | string;
width: number;
height: number;
hoverColor?: number;
width?: number;
height?: number;
textStyle?: Partial<TextStyle>;
radius?: number;
};
Expand Down Expand Up @@ -193,6 +193,16 @@ export class Select extends Container
this.scrollBox.y += scrollBox.offset.y ?? 0;
}

this.addItems(items, selected);
}

/**
* Adds items to the dropdown.
* @param items
* @param selected
*/
addItems(items: SelectItemsOptions, selected = 0)
{
this.convertItemsToButtons(items).forEach((button, id) =>
{
const text = button.text;
Expand All @@ -216,6 +226,15 @@ export class Select extends Container
});
}

/**
* Remove items from the dropdown.
* @param itemID - Item to remove (starting from 0).
*/
removeItem(itemID: number)
{
this.scrollBox.removeItem(itemID);
}

/** Toggle the select state (open if closed, closes - id open). */
toggle()
{
Expand Down

0 comments on commit 5a4c6c3

Please sign in to comment.