Code Monkey home page Code Monkey logo

vue-restricted-access's Introduction

vue-restricted-access

This package is useful when you need to block certain elements/components on the page from the user to access it. This package is fully customizable, you can change the background color, blur, opacity, status message etc by passing apropriate values to the settings object. The package also allows the users to implement their own custom status box.

Codesandbox Demo

Edit Vue-restricted-access-demo

Example usecases:

  1. lock components and force user to login/signup to vue
  2. Users with insufficient permissions

How to install

npm install --save vue-restricted-access

How to use

Import in Components where you want to use the package
import VueRestrictedAccess from 'vue-restricted-access'
import "vue-restricted-access/dist/vue-restricted-access.css";
Register it as a component:
components: {
  RestrictedAccess: VueRestrictedAccess
}
Usage

Just wrap the component which you need to restrict the users from viewing and pass the restricted param as true

<resrticted-access :restricted="true">
  <my-component></my-component>
</restricted-access>

Customizable settings

You can also send an additional settings object with any of these parameters

<restricted-access :restricted="true" :settings="mySettingsObj">

settings object will take the following properties:

Property Required Type Default Description
strict false Boolean false strict mode will fully remove the element from DOM instead of blurring it (for more sensitive contents)
opacity false Number 0.5 Opacity of the overlay
blur false Number 3 Blur radius
showLock false Boolean true show lock icon
statusText false String '' Status text to display on the restricted access component
statusTextColor false String #000 Status text color
showStatusText false Boolean true show status text
customStatusBox false Boolean false If you set custom status to true then you need use scoped slot with name custom-message to pass your own component
customStatusPositionCenter false Boolean true If this is passed true then your custom status box will be in the center

Example settings object

mySettingsObj = {
  strict: false,
  opacity: 0.5,
  blur: 3,
  showStatusText: true,
  statusText: 'Signup to access this content',
  statusTextColor: '#000',
  showLock: true,
  customStatusBox: false,
  customStatusPositionCenter: true
}

Notes:

  1. On strict mode, use a wrapper component over the <restricted-access> component and set width and height or override the CSS

vue-restricted-access's People

Contributors

preetishhs avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.