-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Refactor inputs, add better types. (#686)
* chore: Refactor inputs, add better types. * chore: Update Table extends annotation.
- Loading branch information
Showing
5 changed files
with
205 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,40 @@ | ||
import { coordinator } from '@uwdata/mosaic-core'; | ||
import { coordinator, MosaicClient } from '@uwdata/mosaic-core'; | ||
|
||
export function input(InputClass, options) { | ||
const input = new InputClass(options); | ||
/** | ||
* Instantiate an input, register it with the coordinator, and | ||
* return the corresponding HTML element. | ||
* @template {new (...args: any) => Input} T | ||
* @param {T} InputClass | ||
* @param {ConstructorParameters<T>} params | ||
* @returns {HTMLElement} The container element of the input. | ||
*/ | ||
export function input(InputClass, ...params) { | ||
const input = new InputClass(...params); | ||
coordinator().connect(input); | ||
return input.element; | ||
} | ||
|
||
/** | ||
* Base class for input components. | ||
* @import {Activatable} from '@uwdata/mosaic-core' | ||
* @implements {Activatable} | ||
*/ | ||
export class Input extends MosaicClient { | ||
/** | ||
* Create a new input instance. | ||
* @param {import('@uwdata/mosaic-core').Selection} [filterBy] A selection | ||
* with which to filter backing data that parameterizes this input. | ||
* @param {HTMLElement} [element] Optional container HTML element to use. | ||
* @param {string} [className] A class name to set on the container element. | ||
*/ | ||
constructor(filterBy, element, className = 'input') { | ||
super(filterBy); | ||
this.element = element || document.createElement('div'); | ||
if (className) this.element.setAttribute('class', className); | ||
Object.defineProperty(this.element, 'value', { value: this }); | ||
} | ||
|
||
activate() { | ||
// subclasses should override | ||
} | ||
} |