@bigbinary/neeto-commons-frontend 2.1.12 → 2.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/react-utils.d.ts CHANGED
@@ -4,6 +4,8 @@ import { Notice } from "@honeybadger-io/js/dist/server/types/core/types";
4
4
  import { History } from "history";
5
5
  import { StoreApi, UseBoundStore } from "zustand";
6
6
  import { UseQueryOptions, UseQueryResult, UseMutationOptions, UseMutationResult } from "react-query";
7
+ import { KeyPrefix, Namespace } from "i18next";
8
+ import { DefaultNamespace } from "react-i18next/TransWithoutContext";
7
9
  import { qsOptionsType, QueryParamsType } from "./utils";
8
10
  /**
9
11
  *
@@ -331,7 +333,9 @@ export function useLocalStorage<T>(key: string, initialValue?: T): [T, (value: T
331
333
  * };
332
334
  * @endexample
333
335
  */
334
- export function useOnClickOutside<T>(ref: React.MutableRefObject<T>, handler: (event: MouseEvent | TouchEvent) => any);
336
+ export function useOnClickOutside<T>(ref: React.MutableRefObject<T>, handler: (event: MouseEvent | TouchEvent) => any, options: {
337
+ enabled: boolean;
338
+ });
335
339
  /**
336
340
  *
337
341
  * The usePrevious hook is a convenient utility to track the previous value of
@@ -1315,13 +1319,35 @@ export function useFetchNeetoApps(options?: UseQueryOptions): ReturnType<typeof
1315
1319
  *
1316
1320
  * // Example usage of withT:
1317
1321
  * const ComponentWithTranslation = withT(({ t }) => <div>{t("some.key")}</div>);
1322
+ *
1323
+ * // Example usage of withT with forwarded ref:
1324
+ * const ComponentWithRef = withT(
1325
+ * React.forwardRef(({ t }, ref) => <div ref={ref}>{t("some.key")}</div>),
1326
+ * {
1327
+ * withRef: true,
1328
+ * }
1329
+ * );
1330
+ *
1331
+ * // Example usage of withT with keyPrefix:
1332
+ * const ComponentWithTranslation = withT(
1333
+ * ({ t }) => (
1334
+ * // t function will be called with the key "very.nested.key.some.key"
1335
+ * <div ref={ref}>{t("some.key")}</div>
1336
+ * ),
1337
+ * {
1338
+ * keyPrefix: "very.nested.key",
1339
+ * }
1340
+ * );
1318
1341
  * @endexample
1319
1342
  */
1320
1343
  export const withT: <Props extends {
1321
1344
  [key: string]: any;
1322
- }>(Component: React.ComponentType<Props & {
1345
+ }, N extends Namespace = DefaultNamespace, TKPrefix extends KeyPrefix<N> = undefined>(Component: React.ComponentType<Props & {
1323
1346
  t: TFunction;
1324
- }>) => React.ComponentType<Props>;
1347
+ }>, options?: {
1348
+ withRef?: boolean;
1349
+ keyPrefix?: TKPrefix;
1350
+ }, ns?: N) => React.ComponentType<Props>;
1325
1351
  /**
1326
1352
  *
1327
1353
  * useMutationWithInvalidation is a wrapper function around the
package/react-utils.js CHANGED
@@ -3590,6 +3590,9 @@ var useMutationWithInvalidation = function useMutationWithInvalidation(mutationF
3590
3590
  };
3591
3591
 
3592
3592
  var useOnClickOutside = function useOnClickOutside(ref, handler) {
3593
+ var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
3594
+ _ref$enabled = _ref.enabled,
3595
+ enabled = _ref$enabled === void 0 ? true : _ref$enabled;
3593
3596
  useEffect(function () {
3594
3597
  var listener = function listener(event) {
3595
3598
  // Do nothing if clicking ref's element or descendent elements
@@ -3598,13 +3601,15 @@ var useOnClickOutside = function useOnClickOutside(ref, handler) {
3598
3601
  }
3599
3602
  handler(event);
3600
3603
  };
3601
- document.addEventListener("mousedown", listener);
3602
- document.addEventListener("touchstart", listener);
3604
+ if (enabled) {
3605
+ document.addEventListener("mousedown", listener);
3606
+ document.addEventListener("touchstart", listener);
3607
+ }
3603
3608
  return function () {
3604
3609
  document.removeEventListener("mousedown", listener);
3605
3610
  document.removeEventListener("touchstart", listener);
3606
3611
  };
3607
- }, [handler]);
3612
+ }, [handler, enabled]);
3608
3613
  };
3609
3614
 
3610
3615
  var usePrevious = function usePrevious(value) {
@@ -6281,7 +6286,10 @@ var isMetaKeyPressed = function isMetaKeyPressed(event) {
6281
6286
  return !!(event !== null && event !== void 0 && event.ctrlKey || event !== null && event !== void 0 && event.metaKey);
6282
6287
  };
6283
6288
 
6284
- var withT = withTranslation();
6289
+ var withT = function withT(Component, options) {
6290
+ var namespace = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
6291
+ return withTranslation(namespace, options)(Component);
6292
+ };
6285
6293
 
6286
6294
  var withTitle = function withTitle(Component) {
6287
6295
  var title = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;