UNPKG

@blockly/field-grid-dropdown

Version:
80 lines 2.72 kB
/** * @license * Copyright 2025 Google LLC * SPDX-License-Identifier: Apache-2.0 */ /** * Class representing an item in a grid. */ export declare class GridItem { private readonly value; /** The DOM element for the grid item. */ private element; /** Identifier for a click handler to unregister during dispose(). */ private clickHandler; /** Callback to invoke when this item is selected. */ private selectionCallback; /** Whether or not this item is currently selected. */ private selected; /** * Creates a new GridItem. * * @param container The parent element of this grid item in the DOM. * @param content The content to display in this grid item. * @param value The programmatic value of this grid item. * @param selectionCallback Function to call when this item is selected. */ constructor(container: HTMLElement, content: string | HTMLElement, value: string, selectionCallback: (selectedItem: GridItem) => void); /** * Disposes of this grid item. */ dispose(): void; /** * Gets the unique (within the grid) ID for this grid item. * * @returns This item's unique ID. */ getId(): string; /** * Gets the value associated with this grid item. * * @returns Value associated with this grid item. */ getValue(): string; /** * Returns whether or not this grid item is selected. * * @returns True if this grid item is selected, otherwise false. */ isSelected(): boolean; /** * Sets whether or not this grid item is selected. * * @param selected True if this grid item should be selected, otherwise false. */ setSelected(selected: boolean): void; /** * Handles clicks on this grid item by marking it as selected. */ private onClick; /** * Makes this grid item the browser focus target, and scrolls it into view * if needed. */ focus(): void; /** * Returns the vertical spacing between grid items in pixels. * * This value can be specified by the user in CSS, so we can't just use a * hardcoded value. Moreover, while we could check our computed style, the * grid gap can be specified in several units. Instead, this somewhat hackily * finds all the sibling items in this grid and loops through them until it * encounters one with a different vertical location from its predecessor, * then computes the effective gap based on their relative position and * height. * * @returns The vertical distance between items in this grid. */ private getInterItemSpacing; } //# sourceMappingURL=grid_item.d.ts.map