carbon-custom-elements
Version:
A Carbon Design System variant that's as easy to use as native HTML elements, with no framework tax, no framework silo.
1 lines • 2.18 kB
Source Map (JSON)
{"version":3,"sources":["components/date-picker/append-to-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C;;OAEG;IACH,QAAQ,EAAE,WAAW,CAAC;CACvB;;AAED;;;GAGG;AACH,wBA6BE","file":"append-to-plugin.d.ts","sourcesContent":["/**\n * @license\n *\n * Copyright IBM Corp. 2019\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport { Instance as FlatpickrInstance } from 'flatpickr/dist/types/instance';\nimport { Plugin } from 'flatpickr/dist/types/options';\n\n/**\n * The configuration for the Flatpickr plugin to put the calendar dropdown in shadow DOM.\n */\nexport interface DatePickerAppendToPluginConfig {\n /**\n * The floating menu container.\n */\n appendTo: HTMLElement;\n}\n\n/**\n * @param config Plugin configuration.\n * @returns A Flatpickr plugin to put the calendar dropdown in shadow DOM.\n */\nexport default (config: DatePickerAppendToPluginConfig): Plugin => (fp: FlatpickrInstance) => {\n /**\n * Adjusts the floating meun position after Flatpicker sets it.\n */\n const handlePreCalendarPosition = async () => {\n await Promise.resolve();\n const { calendarContainer, config: fpConfig, _positionElement: positionElement } = fp;\n const { appendTo } = fpConfig;\n const { top: containerTop } = appendTo!.getBoundingClientRect();\n const { bottom: refBottom } = positionElement.getBoundingClientRect();\n const isRtl = appendTo!.ownerDocument!.defaultView!.getComputedStyle(appendTo!).getPropertyValue('direction') === 'rtl';\n calendarContainer.style.top = `${refBottom - containerTop}px`;\n calendarContainer.style.left = !isRtl ? '0' : 'auto';\n calendarContainer.style.right = !isRtl ? 'auto' : '0';\n };\n\n /**\n * Registers this Flatpickr plugin.\n * @param calendar The Flatpickr instance.\n */\n const register = () => {\n fp.loadedPlugins.push('carbonFlatpickrAppendToPlugin');\n };\n\n return {\n appendTo: config.appendTo,\n onReady: register,\n onPreCalendarPosition: handlePreCalendarPosition,\n };\n};\n"]}