UNPKG

@bigbinary/neetoui

Version:

neetoUI drives the experience at all neeto products

192 lines (189 loc) 8.8 kB
import _slicedToArray from '@babel/runtime/helpers/slicedToArray'; import '@babel/runtime/helpers/defineProperty'; import _classCallCheck from '@babel/runtime/helpers/classCallCheck'; import _createClass from '@babel/runtime/helpers/createClass'; import { preprocessForSerialization } from '@bigbinary/neeto-cist'; import { stringify } from 'qs'; import { isEmpty, equals, complement, toPairs, pipe, omit } from 'ramda'; import { e as enTranslations } from './en-DVlE9xuu.js'; import { d as dayjs } from './index-DyUNP5G9.js'; import i18next from 'i18next'; var getEnTranslationValue = function getEnTranslationValue(translationKey) { return translationKey.split(".").reduce(function (acc, key) { return acc[key]; }, enTranslations); }; var getScrollbarWidth = function getScrollbarWidth() { var _parentDiv$parentNode; var parentDiv = document.createElement("div"); parentDiv.style.visibility = "hidden"; parentDiv.style.overflow = "scroll"; document.body.appendChild(parentDiv); var childDiv = document.createElement("div"); parentDiv.appendChild(childDiv); var scrollbarWidth = parentDiv.offsetWidth - childDiv.offsetWidth; parentDiv === null || parentDiv === void 0 ? void 0 : (_parentDiv$parentNode = parentDiv.parentNode) === null || _parentDiv$parentNode === void 0 ? void 0 : _parentDiv$parentNode.removeChild(parentDiv); return scrollbarWidth; }; var getTimezoneAppliedDateTime = function getTimezoneAppliedDateTime(inputDateTime) { var timezoneAppliedDateTime = function timezoneAppliedDateTime(date) { return date && typeof date.format === "function" ? dayjs(date.format("YYYY-MM-DD HH:mm:ss")) : null; }; return Array.isArray(inputDateTime) ? inputDateTime.map(timezoneAppliedDateTime) : timezoneAppliedDateTime(inputDateTime); }; var noop = function noop() {}; var hyphenize = function hyphenize(input) { var fallbackString = "nui"; if (typeof input === "number") return String(input); if (input && typeof input === "string" && input.replace) { return input.replace(/[\s_]/g, "-").replace(/([a-z])([A-Z])/g, "$1-$2").replace(/-+/g, "-").toLowerCase(); } return fallbackString; }; var getValidDayjsValue = function getValidDayjsValue(value) { if (Array.isArray(value)) { return value.map(function (date) { if (!date) return null; var parsed = dayjs(date); return parsed.isValid() ? parsed : null; }); } if (!value) return value; var parsed = dayjs(value); return parsed.isValid() ? parsed : null; }; var UniqueArray = /*#__PURE__*/function () { function UniqueArray() { _classCallCheck(this, UniqueArray); this.array = []; } return _createClass(UniqueArray, [{ key: "add", value: function add(item) { if (this.array.some(equals(item))) return false; this.array.push(item); return true; } }, { key: "remove", value: function remove(item) { this.array = this.array.filter(complement(equals(item))); } }]); }(); var trapFocusOnFocusableElements = function trapFocusOnFocusableElements(ref) { var _ref$current, _ref$current2; var focusableElements = 'button,[href], input, select, textarea, [tabindex]:not([tabindex="-1"])'; var firstFocusableElement = ref === null || ref === void 0 ? void 0 : (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.querySelectorAll(focusableElements)[0]; var focusableContent = ref === null || ref === void 0 ? void 0 : (_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.querySelectorAll(focusableElements); var lastFocusableElement = focusableContent[(focusableContent === null || focusableContent === void 0 ? void 0 : focusableContent.length) - 1]; var onKeyDown = function onKeyDown(e) { var isTabPressed = e.key === "Tab" || e.keyCode === 9; if (!isTabPressed) { return; } if (e.shiftKey) { if (document.activeElement === firstFocusableElement) { lastFocusableElement.focus(); e.preventDefault(); } } else { if (document.activeElement === lastFocusableElement) { firstFocusableElement.focus(); e.preventDefault(); } } }; document.addEventListener("keydown", onKeyDown); return function () { return document.removeEventListener("keydown", onKeyDown); }; }; var focusFirstFocusableElement = function focusFirstFocusableElement(ref) { var _ref$current3; var focusableElements = 'button,[href], input, select, textarea, [tabindex]:not([tabindex="-1"])'; var firstFocusableElement = ref === null || ref === void 0 ? void 0 : (_ref$current3 = ref.current) === null || _ref$current3 === void 0 ? void 0 : _ref$current3.querySelectorAll(focusableElements)[0]; firstFocusableElement === null || firstFocusableElement === void 0 ? void 0 : firstFocusableElement.focus(); }; var hideScrollAndAddMargin = function hideScrollAndAddMargin() { if (!document.body) return; var scrollbarWidth = getScrollbarWidth(); document.body.style.overflow = "hidden"; document.body.style.marginRight = "".concat(scrollbarWidth, "px"); }; var showScrollAndRemoveMargin = function showScrollAndRemoveMargin() { if (!document.body) return; document.body.style.overflow = "auto"; document.body.style.marginRight = "0px"; }; var ANT_DESIGN_GLOBAL_TOKEN_OVERRIDES = { colorBgContainer: "rgb(var(--neeto-ui-white))", colorBorder: "rgb(var(--neeto-ui-gray-300))", colorBorderSecondary: "rgb(var(--neeto-ui-gray-200))", colorFillAlter: "rgb(var(--neeto-ui-gray-100))", colorFillContent: "rgb(var(--neeto-ui-gray-100))", colorFillSecondary: "rgb(var(--neeto-ui-gray-100))", colorIcon: "rgb(var(--neeto-ui-gray-700))", colorIconHover: "rgb(var(--neeto-ui-gray-800))", colorLink: "rgb(var(--neeto-ui-primary-500))", colorLinkActive: "rgb(var(--neeto-ui-primary-800))", colorLinkHover: "rgb(var(--neeto-ui-primary-600))", colorPrimary: "rgb(var(--neeto-ui-primary-500))", colorSplit: "rgb(var(--neeto-ui-gray-100))", colorText: "rgb(var(--neeto-ui-gray-800))", colorTextDescription: "rgb(var(--neeto-ui-gray-700))", colorTextDisabled: "rgb(var(--neeto-ui-gray-600))", colorTextHeading: "rgb(var(--neeto-ui-black))", colorTextPlaceholder: "rgb(var(--neeto-ui-gray-500))", controlItemBgActive: "rgb(var(--neeto-ui-primary-100))", controlItemBgActiveHover: "rgb(var(--neeto-ui-pastel-purple))", controlItemBgHover: "rgb(var(--neeto-ui-gray-100))" }; var buildUrl = function buildUrl(route, params) { var placeHolders = []; toPairs(params).forEach(function (_ref) { var _ref2 = _slicedToArray(_ref, 2), key = _ref2[0], value = _ref2[1]; if (!route.includes(":".concat(key))) return; placeHolders.push(key); route = route.replace(":".concat(key), encodeURIComponent(value)); }); var queryParams = pipe(omit(placeHolders), preprocessForSerialization, stringify)(params); return isEmpty(queryParams) ? route : "".concat(route, "?").concat(queryParams); }; var getLocale = function getLocale(i18n, t, translationKey) { if (isEmpty(i18n)) return getEnTranslationValue(translationKey); return i18n.exists(translationKey) ? t(translationKey) : getEnTranslationValue(translationKey); }; var setToLocalStorage = function setToLocalStorage(key, value) { try { // eslint-disable-next-line @bigbinary/neeto/no-local-storage localStorage.setItem(key, JSON.stringify(value)); } catch (_unused) { // localStorage access can fail due to private browsing mode or storage restrictions } }; var removeFromLocalStorage = function removeFromLocalStorage(key) { try { // eslint-disable-next-line @bigbinary/neeto/no-local-storage localStorage.removeItem(key); } catch (_unused2) { // localStorage access can fail due to private browsing mode or storage restrictions } }; var getFromLocalStorage = function getFromLocalStorage(key, defaultValue) { try { // eslint-disable-next-line @bigbinary/neeto/no-local-storage var storedValue = localStorage.getItem(key); return storedValue ? JSON.parse(storedValue) : defaultValue; } catch (_unused3) { // localStorage access can fail due to private browsing mode or storage restrictions return defaultValue; } }; var getContentDir = function getContentDir() { return i18next.language ? i18next.dir() : "ltr"; }; export { ANT_DESIGN_GLOBAL_TOKEN_OVERRIDES as A, UniqueArray as U, getLocale as a, getFromLocalStorage as b, buildUrl as c, hideScrollAndAddMargin as d, showScrollAndRemoveMargin as e, focusFirstFocusableElement as f, getContentDir as g, hyphenize as h, getValidDayjsValue as i, getTimezoneAppliedDateTime as j, noop as n, removeFromLocalStorage as r, setToLocalStorage as s, trapFocusOnFocusableElements as t }; //# sourceMappingURL=index-DzZtLRHp.js.map