diff --git a/core/index.d.ts b/core/index.d.ts index bfa235e..f12114d 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -32,7 +32,7 @@ export const Redirect: any; export const ModuleHierarchyContext: any; export const ModuleHierarchyProvider: any; export const useModuleHierarchy: any; -export const useNamespace: any; +export * from './src/components/Namespace'; export const withNamespace: any; export const tVisitedContext: any; export const tVisited: any; 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;