nsc-permission-control

0.1.1 • Public • Published

nsc-permission-control

permission controlled react component

NPM JavaScript Style Guide

Install

npm install --save nsc-permission-control

Usage

The permission controlled component will be rendered only when granted covers required:

import Permission from 'nsc-permission-control'

<Permission required="B001" granted="B001">
  <button>permission B001 controlled button</button>
</Permission>

You can customize what to be rendered when not granted:

import Permission from 'nsc-permission-control'

<Permission required="B001" granted="B001" mode="advance">
  {hasPermission => <button disabled={!hasPermission}>permission btn</button>}
</Permission>

'*' is a special permission code, which allows to access all.

You can define client side permission code, like:

import Permission, { defPermission } from 'nsc-permission-control'
defPermission('LOGIN', () => {
  return window.isLogined
})

<Permission required="LOGIN">
  <div>login protected content</div>
</Permission>

You can use hasPermission alone:

import { hasPermission } from 'nsc-permission-control'
hasPermission(required, granted) // return true or false

props

  • required
  • granted
  • mode

required can be a string of permission code, or an array of permission code strings. So does granted.

utils

  • hasPermission
  • defPermission

License

MIT © nsc-open

Dependencies (0)

    Dev Dependencies (19)

    Package Sidebar

    Install

    npm i nsc-permission-control

    Weekly Downloads

    1

    Version

    0.1.1

    License

    MIT

    Unpacked Size

    14 kB

    Total Files

    7

    Last publish

    Collaborators

    • ygjack