UNPKG

react-permissions-dynamic

Version:
24 lines (23 loc) 1.5 kB
import React from 'react'; import type { CheckResult, ActionStatusType, OnCheckPermissionsType, PermissionsContainerType } from './types'; export declare type PermissionsContextType<T extends string = string> = { permissions: PermissionsContainerType<T>; check: (actions: T[] | T) => Promise<CheckResult<T> | null> | CheckResult<T> | null; allowed: (actions: T) => ActionStatusType<T>; }; export declare type PermissionsProps<T extends string = string> = { children: React.ReactNode; permissions?: CheckResult<T>; initialPermissions?: CheckResult<T>; onCheckPermissions?: OnCheckPermissionsType<T>; isAllowed?: (action: T, allowed: T[]) => boolean; }; declare const Permissions: <T extends string = string>({ children, initialPermissions, permissions: valuePermissions, onCheckPermissions, isAllowed, }: PermissionsProps<T>) => React.ReactElement; export default Permissions; export declare const usePermissions: <T extends string = string>() => PermissionsContextType<T>; export declare const PermissionsProvider: <T extends string = string>({ children, initialPermissions, permissions: valuePermissions, onCheckPermissions, isAllowed, }: PermissionsProps<T>) => React.ReactElement; export { useAllowed } from './useAllowed'; export { PermissionCheck } from './PermissionCheck'; export { useCheckPermission } from './useCheckPermission'; export { useCheckPermissions } from './useCheckPermissions'; export type { PermissionCheckProps } from './PermissionCheck';