Coder Social home page Coder Social logo

hrankit / vue-mentionable Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tunayagci/vue-mentionable

0.0 1.0 0.0 2.21 MB

A collection of Vue components where user can mention anything with any identifier.

Home Page: https://tunayagci.github.io/vue-mentionable/

JavaScript 14.39% HTML 2.49% Vue 83.11%

vue-mentionable's Introduction

vue-mentionable

npm

Vue-mentionable is a series of Vue components where users can mention with any identifier, like @admin or #156, etc.

Roadmap

  1. Mentionable Textarea โœ…
  2. Mentionable Input ๐Ÿ”œ

Installation

  • npm i vue-mentionable
  • (optional) Add fontawesome to your `index.html for loading icon

Register in main.js

import vueMentionable from 'vue-mentionable';

Vue.use(vueMentionable);

Use in any component

<mentionable-textarea :modeIdentifiers="modeIdentifiers" />

See here for examples

Docs

For props and events, see: https://tunayagci.github.io/vue-mentionable/#/docs

1. Mode Identifiers

  • A mode is simply which suggestion component is being displayed.
  • You have to register your modes to mentionable-textarea.
  • A simple example follows:
{
  mode: 0, // a unique id
  key: '@', // the actual identifier
  comp: MentionableUser // suggestion component
}
import MentionableIncident from "./MentionableIncident.vue";
import MentionableUser from "./MentionableUser.vue";

const MODE_USER = 0;
const MODE_INCIDENT = 1;

const userMention = {
    mode: MODE_USER,
    key: '@',
    comp: MentionableUser,
    valueKey: 'name'
};

const incidentMention = {
    mode: MODE_INCIDENT,
    key: '#',
    comp: MentionableIncident,
    valueKey: 'serial'
};

export {userMention, incidentMention, MODE_INCIDENT, MODE_USER};

2. Listening mention events

  • Mention events are triggered whenever user inputs while any mode is active.
  • You are expected to update your suggestions in this lifecycle.

Here is an example:

<mentionable-textarea onMention="onMention" />
onMention(event) {
    this.currentMode = event.mode;
    this.searchParam = event.searchParam;
    if (this.currentMode === MODE_INCIDENT) {
        this.searchTvSeries();
    }
}
  • event is of type {mode: <number>, searchParam: <string>}
  • mode is a number which is described a little above.
  • In above code you can see I'm not updating user suggestion component. This is because user suggestion component is reactive and it is watching this.searchParam.
  • Fetching tv series in this case is not reactive since I need to make an http call.

Note: you should most likely use debounce for user inputs. See here for example

Example

See the source code for live example

Keyboard Shortcuts

  • Up/Down arrow key to highlight suggestion
  • Escape key to close suggestions list
  • Enter/Tab key to select current highlighted suggestion

vue-mentionable's People

Contributors

dependabot[bot] avatar tunayagci avatar

Watchers

 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.