From e4b031ae5baa46cb1b07d19aa8d47e3fc2719eda Mon Sep 17 00:00:00 2001 From: Noah Overcash Date: Thu, 26 Sep 2024 12:47:05 -0400 Subject: [PATCH] commit the rest of the changes --- core/src/components/Namespace/index.d.ts | 2 ++ .../components/Namespace/useNamespace.d.ts | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 core/src/components/Namespace/index.d.ts create mode 100644 core/src/components/Namespace/useNamespace.d.ts diff --git a/core/src/components/Namespace/index.d.ts b/core/src/components/Namespace/index.d.ts new file mode 100644 index 0000000..1ba151e --- /dev/null +++ b/core/src/components/Namespace/index.d.ts @@ -0,0 +1,2 @@ +export { default as useNamespace } from './useNamespace'; +export const withNamespace: any; diff --git a/core/src/components/Namespace/useNamespace.d.ts b/core/src/components/Namespace/useNamespace.d.ts new file mode 100644 index 0000000..d0f1a32 --- /dev/null +++ b/core/src/components/Namespace/useNamespace.d.ts @@ -0,0 +1,32 @@ +export interface UseNamespaceOpts { + ignoreParents?: boolean; + key?: string; +} + +/** + * A hook which returns module namespace as a string + * https://issues.folio.org/browse/STCOR-537 + * + * @example const [namespace, getNamespace] = useNamespace(); + * + * @example // from app module (e.g. ui-users) + * const [namespace] = useNamespace(); // "@folio/users" + * + * @example // from app module (e.g. ui-users) via getNamespace + * const [_, getNamespace] = useNamespace(); + * const namespace = getNamespace({ key: 'test-key' }) // "@folio/users:test-key" + * + * @example // from plugin embedded in app module (e.g. ui-plugin-find-order executing in ui-agreements) + * const [namespace] = useNamespace(); // "@folio/agreements:@folio/plugin-find-order" + * + * @example // from plugin embedded in app module with `ignoreParents` option (e.g. plugin ui-plugin-find-order executing in ui-agreements) + * const [namespace] = useNamespace({ ignoreParents: true }); // "@folio/plugin-find-order" + * + * @example // from plugin embedded in app module with `key` option present (e.g. ui-plugin-find-order executing in ui-agreements) + * const [namespace] = useNamespace({ key: "filters-pane" }); // "@folio/agreements:@folio/plugin-find-order:filters-pane" + */ +declare function useNamespace( + options?: UseNamespaceOpts, +): [string, (opts: UseNamespaceOpts) => string]; + +export default useNamespace;