UNPKG

wix-style-react

Version:
102 lines (83 loc) 2.65 kB
import { dataHooks } from './constants'; export var floatingHelperContentDriverFactory = function floatingHelperContentDriverFactory(_ref) { var element = _ref.element, eventTrigger = _ref.eventTrigger; var getElementByDataHook = function getElementByDataHook(dataHook) { return element.querySelector("[data-hook='".concat(dataHook, "']")); }; var title = function title() { return getElementByDataHook(dataHooks.title); }; var body = function body() { return getElementByDataHook(dataHooks.body); }; var image = function image() { return getElementByDataHook(dataHooks.image); }; var actionButton = function actionButton() { return getElementByDataHook(dataHooks.actionButton); }; var footer = function footer() { return getElementByDataHook(dataHooks.footer); }; return { /** checks if the element exists */ exists: function exists() { return !!element; }, /** checks if title exists */ hasTitle: function hasTitle() { return !!title(); }, /** checks if text content exists */ hasBody: function hasBody() { return !!body(); }, /** checks if the action button exists */ hasActionButton: function hasActionButton() { return !!actionButton(); }, /** checks if the footer exists */ hasFooter: function hasFooter() { return !!footer(); }, /** checks if an image exists */ hasImage: function hasImage() { return !!image(); }, /** Get image HTML element*/ getImage: function getImage() { return image() && image().childNodes[0]; } /* as HTMLElement*/ , /** Get footer HTML element*/ getFooter: function getFooter() { return footer() && footer().childNodes[0]; } /* as HTMLElement*/ , /** Get the text content of the title */ getTitleContent: function getTitleContent() { return title().textContent; }, /** Get the text content of the helper's text */ getBodyContent: function getBodyContent() { return body().textContent; }, /** Get text of action button */ getActionButtonText: function getActionButtonText() { return actionButton().textContent; }, /** naive way to check for stylable class */ matchesActionButtonClassName: function matchesActionButtonClassName(className) { return !!Array.from(actionButton().classList).find(function (c) { return c.includes(className); }); }, /** click on the action button */ clickActionButton: function clickActionButton() { return eventTrigger.click(actionButton()); } }; };