All Projects → termosa → vue-uniq-ids

termosa / vue-uniq-ids

Licence: MIT license
Vue.js 2.x plugin that helps to use id-related attributes with no side-effect

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to vue-uniq-ids

sandid
Every grain of sand on Earth has its own ID.
Stars: ✭ 39 (+21.88%)
Mutual labels:  id, unique
ciid
Chronological Image Identifier – Uniquely identify image files while keeping the ability to sort them chronologically by name.
Stars: ✭ 25 (-21.87%)
Mutual labels:  unique
mongoose-slug-updater
Schema-based slug plugin for Mongoose - single/compound - unique over collection/group - nested docs/arrays - relative/abs paths - sync on change: create/save/update/updateOne/updateMany/findOneAndUpdate tracked - $set operator - counter/shortId
Stars: ✭ 37 (+15.63%)
Mutual labels:  unique
firebase-id-tokens-verifier
Code snippet to show how to verify Firebase ID tokens using Ruby
Stars: ✭ 32 (+0%)
Mutual labels:  id
shortid
Super short, fully unique, non-sequential and URL-friendly Ids
Stars: ✭ 20 (-37.5%)
Mutual labels:  id
aria disclosure widget
Progressively enhanced hide/show content areas with vanilla JS & appropriate ARIA attributes
Stars: ✭ 23 (-28.12%)
Mutual labels:  aria
aria-switch-control
ARIA Switch control component
Stars: ✭ 38 (+18.75%)
Mutual labels:  aria
stucco
An experimental adaptive UI toolkit.
Stars: ✭ 31 (-3.12%)
Mutual labels:  aria
aria-collapsible
A lightweight, dependency-free JavaScript module for generating progressively-enhanced collapsible regions using ARIA States and Properties.
Stars: ✭ 25 (-21.87%)
Mutual labels:  aria
mindpatterns
HTML Accessibility Pattern Examples
Stars: ✭ 78 (+143.75%)
Mutual labels:  aria
VFO-standards-support
Contains documentation for Vispero software support of Web standards
Stars: ✭ 95 (+196.88%)
Mutual labels:  aria
pure-uuid
Pure JavaScript Based Universally Unique Identifiers (UUID)
Stars: ✭ 60 (+87.5%)
Mutual labels:  unique
van11y-accessible-simple-tooltip-aria
ES2015 accessible simple tooltip, using ARIA
Stars: ✭ 22 (-31.25%)
Mutual labels:  aria
fastremap
Remap, mask, renumber, unique, and in-place transposition of 3D labeled images. Point cloud too.
Stars: ✭ 29 (-9.37%)
Mutual labels:  unique
aria-devtools
Easily spot missing ARIA labels, misused ARIA roles, and incomplete keyboard support in your web applications.
Stars: ✭ 69 (+115.63%)
Mutual labels:  aria
gid
Golang 分布式ID生成系统,高性能、高可用、易扩展的id生成服务
Stars: ✭ 55 (+71.88%)
Mutual labels:  id
aria-at
Assistive Technology ARIA Experience Assessment
Stars: ✭ 115 (+259.38%)
Mutual labels:  aria
platform device id
flutter plugin to get device id
Stars: ✭ 32 (+0%)
Mutual labels:  id
id-mask
IDMask is a Java library for masking internal ids (e.g. from your DB) when they need to be published to hide their actual value and to prevent forging. It has support optional randomisation has a wide support for various Java types including long, UUID and BigInteger. This library bases its security on strong cryptographic primitives.
Stars: ✭ 39 (+21.88%)
Mutual labels:  id
distributed-id
基于netty4+twitter-snowFlake分布式Id生成之服务实现
Stars: ✭ 18 (-43.75%)
Mutual labels:  id

VueUniqIds

A Vue.js plugin that helps to use id-related attributes with no side-effect

NPM version Bower version

It is a trend to use components. Components are cool, they are small, obvious, easy to use and modular. Untill it comes to the id property.

Some HTML tag attributes requires using an id property, like label[for], input[form] and many of aria-* attributes. And the problem with the id is that it is not modular. If several id properties on the page will has the same value they can affect each other.

VueUniqIds helps you to get rid of this problem. It provides the set of id-related directives which value is automatically modified by adding unique string while keeping the attrbitue easy to read.

Installation

Via NPM

Install the package

$ npm install vue-uniq-ids

Via Bower

Install the package

$ bower install vue-uniq-ids

add script on page

<script src="/bower_components/vue-uniq-ids/dist/vue-uniq-ids.js"></script>

or you can do it with RequireJS or any similar tool.

Setup

There are three ways to setup VueUniqIds:

1. As a plugin

// Import the plugin
import VueUniqIds from 'vue-uniq-ids'
// or
import { UniqIdsPlugin } from 'vue-uniq-ids'

// Install it with Vue.use()
import Vue from 'vue'
Vue.use(VueUniqIds, /* options */)

2. As a global mixin

import Vue from 'vue'

// Import the mixin generator
import { createUniqIdsMixin } from 'vue-uniq-ids'

// Create the mixin
const uniqIdsMixin = createUniqIdsMixin(/* options */)

// Install it with Vue.mixin()
Vue.mixin(uniqIdsMixin)

3. As a local mixin

import Vue from 'vue'

// Import the mixin generator
import { createUniqIdsMixin } from 'vue-uniq-ids'

// Create the mixin
const uniqIdsMixin = createUniqIdsMixin(/* options */)

// Add it to the instance
new Vue({
  mixins: [uniqIdsMixin],
  // …
})
// … or to the component
Vue.component('name', {
  mixins: [uniqIdsMixin],
  // …
})

Usage

You can use those directives at any template if you add this extension by Vue.use() or Vue.mixin(), and in the template of the component where you specify the extension by mixin: [] property.

Here is an example of using directives in *.vue file:

<template>
  <form>
    <!-- Directives are expecting the string literal or a variable -->
    <label v-uni-for="'username'">Username</label>
    <!-- As well you can pass the list of items by array or a string where ids are separated by space -->
    <input v-uni-id="'username'"
        v-uni-aria-describedby="['username-description', 'username-hint']" />
    <p v-uni-id="'username-description'">Your public name</p>
    <p v-uni-id="'username-hint'">Use only latin characters</p>
  </form>
</template>

This will generate something like an example below:

  <form>
    <label for="username-pc0k8g5b">Username</label>
    <input id="username-pc0k8g5b"
        aria-describedby="username-description-dnw4bvwy username-hint-oytscr4i" />
    <p id="username-description-dnw4bvwy">Your public name</p>
    <p id="username-hint-oytscr4i">Use only latin characters</p>
  </form>

The list of available attributes:

  • id
  • for
  • form
  • aria-activedescendant
  • aria-controls
  • aria-describedby
  • aria-flowto
  • aria-labelledby
  • aria-owns

Options and customization

There are several options to customize the behavior of directives. You can pass them in several ways:

  1. With the plugin
    import VueUniqIds from 'vue-uniq-ids'
    Vue.use(VueUniqIds, options)
  2. With the mixin
    import { createUniqIdsMixin } from 'vue-uniq-ids'
    Vue.mixin(createUniqIdsMixin(options))
    // or
    new Vue({
      mixins: [createUniqIdsMixin(options)],
      // …
    })
  3. By uniqIdsConfig property
    new Vue({
      uniqIdsConfig: options
    })

The options is an object, that can contain several properties from the example below:

const options = {

  /*
   * scope {object|boolean} — is an object to store a list of generated ids
   *
   * If object is passed it will be used to store generated ids, so you can
   * share the same scope between several components
   * If the value is not object, but it is equivalent to true, the scope
   * object will be created automatically for current instance
   * Otherwise, plugin will use the global scope if the plugin was
   * initialized by Vue.use or Vue.mixin or it will create a new scope.
   * 
   * By default it is using the global scope
   */
  scope: true,

  /*
   * prefix {string} — a prefix for directive names
   * By default it is 'uni-'
   */
  prefix: 'uni-',

  /*
   * attrs: {array} — a list of attributes for which directives will be created
   * By default it is ['id', 'for', 'form', 'aria-activedescendant', 'aria-controls', 'aria-describedby', 'aria-flowto', 'aria-labelledby', 'aria-owns']
   */
  attrs: ['id', 'for'],
  
  /*
   * The rest are options for qinu — a unique string generator
   * Check the link for more details https://www.npmjs.com/package/qinu
   */

  /*
   * template {string} — the template for unique identifiers
   * 
   * The %qinu% will be replaced with generated uniq code, and %args[N]%'s are
   * replaced by args and directive value
   * 
   * By default it is '%arg[0]%-%qinu%'
   */
  template: '%arg[0]%-%arg[1]%-%qinu%',

  /*
   * args {array} — predefined args for template string
   *
   * This are values for template string, can be useful when you want to scope
   * ids with an additional name, or to avoid using value for directives in
   * the components with one id only.
   * 
   * By default it is empty
   */
  args: [],

  /*
   * chars {string|array} — a list of characters to generate the unique string
   */
  chars: '1234567890abcdef',

  /*
   * length {integer} — a length of unique string
   */
  length: 8
}

An example of usage without specifying the value in template

Vue.use(VueUniqIds)
Vue.component('input-section', {
  props: ['label'],
  template: '\n\
    <div>\n\
      <label v-uni-for>{{label}}</label>\n\
      <input v-uni-id />\n\
    </div>',
  uniqIdsConfig: {
    args: ['input-section'],
    scope: true
  }
})

This component will be rendered to code similar to the example below:

    <div>
      <label for="input-section-97muvl55">LABEL</label>
      <input id="input-section-97muvl55" />
    </div>

License

MIT © Stanislav Termosa

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].