@blockly/field-grid-dropdown
Version:
A Blockly dropdown field with grid layout.
96 lines • 3.41 kB
TypeScript
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Grid dropdown field.
* @author kozbial@google.com (Monica Kozbial)
*/
import * as Blockly from 'blockly/core';
/**
* A config object for defining a field grid dropdown.
*/
export interface FieldGridDropdownConfig extends Blockly.FieldDropdownConfig {
columns?: string | number;
primaryColour?: string;
borderColour?: string;
}
/**
* Construct a FieldGridDropdown from a JSON arg object.
*/
export interface FieldGridDropdownFromJsonConfig extends FieldGridDropdownConfig {
options?: Blockly.MenuGenerator;
}
type FieldGridDropdownValidator = Blockly.FieldDropdownValidator;
/**
* Grid dropdown field.
*/
export declare class FieldGridDropdown extends Blockly.FieldDropdown {
/**
* The number of columns in the dropdown grid. Must be an integer value
* greater than 0. Defaults to 3.
*/
private columns;
private primaryColour?;
private borderColour?;
/** Object representing the grid of choices show in the dropdown. */
private grid?;
/**
* Class for an grid dropdown field.
*
* @param menuGenerator A non-empty array of options for a dropdown list,
* or a function which generates these options.
* @param validator A function that is called to validate
* changes to the field's value. Takes in a language-neutral dropdown
* option & returns a validated language-neutral dropdown option, or null
* to abort the change.
* @param config A map of options used to configure the field.
* See the [field creation documentation]{@link
* https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/dropdown#creation}
* for a list of properties this parameter supports.
* @extends {Blockly.Field}
* @constructor
* @throws {TypeError} If `menuGenerator` options are incorrectly structured.
*/
constructor(menuGenerator: Blockly.MenuGenerator, validator?: FieldGridDropdownValidator, config?: FieldGridDropdownConfig);
/**
* Constructs a FieldGridDropdown from a JSON arg object.
*
* @param config A JSON object with options.
* @returns The new field instance.
* @package
* @nocollapse
*/
static fromJson(config: FieldGridDropdownFromJsonConfig): FieldGridDropdown;
/**
* Sets the number of columns on the grid. Updates the styling to reflect.
*
* @param columns The number of columns. Is rounded to
* an integer value and must be greater than 0. Invalid
* values are ignored.
*/
setColumns(columns: number): void;
/**
* Create a dropdown menu under the text.
*
* @param e Optional mouse event that triggered the field to open, or
* undefined if triggered programmatically.
*/
protected showEditor_(e?: MouseEvent): void;
/**
* Updates the field's value to the given value.
*
* @param newValue The new value for this field.
*/
protected doValueUpdate_(newValue: string): void;
/**
* Determine the colours for the dropdowndiv. The dropdown should match block
* colour unless other colours are specified in the config.
*
* @returns The colours to set for the dropdowndiv.
*/
private getColours;
}
export {};
//# sourceMappingURL=index.d.ts.map