UNPKG

react-antd-admin-panel

Version:

Modern TypeScript-first React admin panel builder with Ant Design 6

66 lines 2.01 kB
import React, { ReactNode } from 'react'; /** * Props for the AccessGuard component */ export interface AccessGuardProps { /** Children to render when access is granted */ children: ReactNode; /** Fallback content when access is denied (optional) */ fallback?: ReactNode; /** Single role to check */ role?: string; /** Multiple roles to check (user needs any one) */ roles?: string[]; /** Single permission to check */ permission?: string; /** Multiple permissions to check (user needs all) */ permissions?: string[]; /** Feature name for feature-based access */ feature?: string; /** Required access level for feature (default: 1) */ level?: number; /** Whether user must be authenticated (default: true when using any check) */ requireAuth?: boolean; } /** * AccessGuard - Component for conditional rendering based on access control * * Wraps children and only renders them if the user has the required * role, permission, or feature access level. * * @example * ```tsx * // Role-based protection * <Protected role="admin"> * <DeleteButton /> * </Protected> * * // Permission-based protection * <Protected permission="users.delete"> * <DeleteButton /> * </Protected> * * // Feature with level * <Protected feature="Users" level={3}> * <DeleteButton /> * </Protected> * * // Multiple roles (any match) * <Protected roles={['admin', 'manager']}> * <ManagePanel /> * </Protected> * * // With fallback content * <Protected role="admin" fallback={<span>Admin only</span>}> * <AdminPanel /> * </Protected> * * // Multiple permissions (all required) * <Protected permissions={['users.read', 'users.write']}> * <EditForm /> * </Protected> * ``` */ export declare function AccessGuard({ children, fallback, role, roles, permission, permissions, feature, level, requireAuth, }: AccessGuardProps): React.ReactElement | null; export default AccessGuard; //# sourceMappingURL=Protected.d.ts.map