1.0.0 • Published 9 months ago

@sunfy/authorized v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

权限组件,通过比对现有权限与准入权限,决定相关元素的展示

API

参数类型

/**
 * @param { string | array | Promise | Function } authority 权限判定
 * @param { string | string[]} currentAuthority 当前权限
 * @param { ReactNode } target 通过组件
 * @param { ReactNode } Exception 未通过组件
 * /

renderPermission

  renderPermissions: (authority: Authority, currentAuthority: CurrentAuthority, target: ReactNode, Exception: ReactNode) => string | number | boolean | Iterable<ReactNode> | JSX.Element | null | undefined

renderAuthorize

Props

  currentAuthority: string | string[]

使用方式一

import { renderPermission } from '@sunfy/authorized'

function App(){

  const permissionA = renderPermission(['admin'], ['admin'], 'ok', 'error')
  const permissionB = renderPermission(['admin','user'], 'user', 'ok', 'error')

  return (
    <>
      {permissionA}
      {permissionB}
    </>
  )
}

使用方式二

import renderAuthorize from '@sunfy/authorized'

const Admin = renderAuthorize('admin')
const User = renderAuthorize('user')

function App(){
  return (
    <>
      <Admin authority={'admin'} noMatch={<>Error</>}>
        I am admin
      </Admin>
      <User authority={'user'} noMatch={<>Error</>}>
        I am user
      </User>
    </>
  )
}