Skip to content

Commit

Permalink
add stripes-core useNamespace (#65)
Browse files Browse the repository at this point in the history
* add stripes-core useNamespace

* commit the rest of the changes
  • Loading branch information
ncovercash authored Sep 26, 2024
1 parent 91da77e commit c4aea45
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions core/src/components/Namespace/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as useNamespace } from './useNamespace';
export const withNamespace: any;
32 changes: 32 additions & 0 deletions core/src/components/Namespace/useNamespace.d.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit c4aea45

Please sign in to comment.