gristlabs_grist-core/app/client/lib/popupControl.ts
Cyprien P 620e86a9f1 (core) New date filter with a calendar view
Summary:
Implements the new date filtering panel. Design results from long
discussion between: Alex, Anais, Cyprien and Dmitry.

Test environment: https://grist-new-date-range-filter.fly.dev/

Test Plan: Include various new tests.

Reviewers: georgegevoian

Reviewed By: georgegevoian

Differential Revision: https://phab.getgrist.com/D3720
2022-12-20 09:58:42 +01:00

35 lines
1.1 KiB
TypeScript

/**
*
* Returns a popup control allowing to open/close a popup using as content the element returned by
* the given func. Note that the `trigger` option is ignored by this function and that the default
* of the `attach` option is `body` instead of `null`.
*
* It allows you to bind the creation of the popup to a menu item as follow:
* const ctl = popupControl(triggerElem, (ctl) => buildDom(ctl));
* ...
* menuItem(elem => ctl.open(), 'do stuff...')
*/
import { domDispose } from "grainjs";
import { IOpenController, IPopupDomCreator, IPopupOptions, PopupControl } from "popweasel";
export function popupControl(reference: Element, domCreator: IPopupDomCreator, options: IPopupOptions): PopupControl {
function openFunc(openCtl: IOpenController) {
const content = domCreator(openCtl);
function dispose() { domDispose(content); }
return {content, dispose};
}
const ctl = PopupControl.create(null);
ctl.attachElem(reference, openFunc, {
attach: 'body',
boundaries: 'viewport',
...options,
trigger: undefined
});
return ctl;
}