Git Product home page Git Product logo

smart-tagz's Introduction


Build Status Codacy Badge DeepScan grade Language grade: JavaScript Snyk Vulnerabilities for GitHub Repo Depfu

Edit smart-tagz

✨ Features

  • Autosuggest with support for keyboard selection.
  • ✏️ Edit the tags inline by double clicking them.
  • 🏷️ Paste strings with delimiters of your choice and the component will create the tags for you.
  • 🗑️ Quickly delete the tags with a visual confirmation before removing a tag.
  • 🧹 Quickly clear all tags with quick-delete mode.
  • 🔒  Lock the component using the readonly mode.
  • ✋  Restrict the number of tags and Handle duplicates gracefully.
  • 🌈 Customize the colors.

Table of Contents

⚡ Installation

yarn install smart-tagz

🚀 Getting Started

smart-tagz has some great defaults to get you started quickly. Please check the props list for all options.

<template>
  <smart-tagz
    autosuggest
    editable
    inputPlaceholder="Select Countries ..."
    :sources="sources"
    :allowPaste="{delimiter: ','}"
    :allowDuplicates="false"
    :maxTags="20"
    :defaultTags="['United Kingdom', 'Uruguay', 'Uzbekistan']"
  />
</template>

<script>
import { SmartTagz } from "smart-tagz";
import "smart-tagz/dist/smart-tagz.css";

import { defineComponent } from "vue";

export default defineComponent({
  name: "Basic",
  components: {
    SmartTagz,
  }
});
</script>

🍬 Demos

Head to our demo page for examples showcasing all the features.

https://smart-tagz.vercel.app/

Props

Prop Type Description Default
defaultTags Array initialize with a default set of tags []
width String width of the container 100%
autosuggest Boolean Enables the autosuggest feature. you also need to set the sources for the autosuggest to work. false
sources Array Works as the datasource for the autosuggest feature []
allowPaste { delimiter: String } Parses the pasted string based on the passed delimiter and creates tags automatically {delimiter: ","}
editable Boolean makes the tags editable false
allowDuplicates Boolean allows/disallows duplicate tag entries while pasted or entered manually. true
maxTags Number sets the Maximum number of tags 10
inputPlaceholder String Placeholder for the input box. "Enter tag..."
readOnly Boolean Makes the whole component readOnly. ideal for display only purposes. false
quick-delete Boolean When enabled all the tags can be cleared by CTRL + A, DEL false
on-changed Function callback that gets called when a new tag is added or an existing tag is deleted false

Default Tags

We can initialize smart-tagz with some default tags. This setting will mostly be used along with the readonly prop to create tags for display only purposes.

<smart-tagz :default-tags="['United Kingdom', 'Uruguay', 'Uzbekistan']" />

Duplicates

You can decide how to manage duplicate tags by either allowing or disallowing them completely. When set to false no duplicate values are allowed.

<smart-tagz :allow-duplicates="false" />

Auto Suggest

Whe set to true, the autosuggest prop suggests values in a dropdown. You also need to set the sources prop for this to work. The sources prop can be an Array of strings.

 <smart-tagz autosuggest :sources="['India', 'Brazil', 'China', 'United Kingdom']" />

Max Tags

The component can also be configured to accept the Maximum number of tags that can be created. Once the threshold is reached, the input will be hidden from the user.

Here we restrict the tags to 3

<smart-tagz :max-tags="3" />

Paste

The component can parse strings and automatically create tags for you. The default delimiter is "," but you can override this setting by manually setting the delimiter option.

<smart-tagz :allow-paste="{delimiter: ';'}" />

Editable Tags

The Tags are not editable by default, but you can change this setting with the editable prop. Simply double click a tag, make the changes and hit enter to save.

<smart-tagz editable />

Readonly Tags

You can lock the component with readonly mode. All interactions are disabled in read-only mode.

<smart-tagz read-only />

Theme

The components color scheme can be customized by passing a custom theme prop.

  <smart-tagz
    :theme="{
      primary: '#545454',
      background: '#bdbdbd',
      tagTextColor: '#fff',
    }"
  />

Custom Class names

If you are looking for more control in terms of customizing the style of the tags, you can make use of the classNames prop to apply custom classes to the different elements within the component.

<smart-tagz
  input-placeholder="Select Countries ..."
  :class-names="{
    wrapper: 'tags_wrapper_custom',
    tag_name: 'tag_name_custom',
    tag_container: 'tag_container_custom',
    tag_close_btn: 'tag_close_btn_custom',
  }"
  :default-tags="[
    'United Kingdom',
    'Uruguay',
    'Uzbekistan',
    'Venezuela'
  ]"
/>

📦 Build Setup

# install dependencies
yarn install

# start dev
yarn run dev

# package lib
npm run rollup

# run css linting
yarn run lint:css

🔨 Contributing

  1. Fork it ( https://github.com/prabhuignoto/smart-tagz/fork )
  2. Create your feature branch (git checkout -b new-feature)
  3. Commit your changes (git commit -am 'Add feature')
  4. Push to the branch (git push origin new-feature)
  5. Create a new Pull Request

Notes

The project uses vite instead of @vue/cli. I choose vite for speed and i also believe vite will be the future.

Meta

Prabhu Murthy – @prabhumurthy2[email protected]

Distributed under the MIT license. See LICENSE for more information.

https://github.com/prabhuingoto/

smart-tagz's People

Contributors

deepsourcebot avatar imgbotapp avatar maitkaa avatar prabhuignoto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

smart-tagz's Issues

:source is reactive?

I want to dynamically update my source array, but in the tests, I did looks like the :source isn't reactive or I'm missing something?

Setting Focus

I am trying have the smart-tagz input area get focus when the component is being displayed (via v-if). With the following code snippets, the console.log shows the component was found but the cursor doesn't go to the input area:

<script setup lang="ts">
[snip]
const editTags = (photoId: number, event: any) => {
  editing.value = photoId
  const element = document.getElementById('tagEditor');
  console.log(element)
  if (element) {
    element.focus();
  }
}
[snip]
</script>
<template>
[snip]
            <smart-tagz
                v-if="editing == photo['photo_id']"
                id="tagEditor"
                :on-changed="tagChanged"
                editable
                inputPlaceholder="Enter tags ..."
                :allowPaste="{delimiter: ','}"
                :allowDuplicates="false"
                :maxTags="20"
                :defaultTags="photo['tags']"
                :class-names="{
                  tag_name: 'tag_name_custom'
                }"
              />
[snip]
</template>

In the log output of element I can drill down into tagEditor. Is the input area something I can/should explicitly address in the .focus()?

typescript support?

Hi!, thanks for sharing!

I try with your work in ts...
I have this error:

image

image

Invalid regular expression

smart-tagz.esm.js:4 Uncaught (in promise) SyntaxError: Invalid regular expression: /^c++$/: Nothing to repeat at new RegExp (<anonymous>)

Trying to add a tag: c++ throws me an error, also unable to select c++ from sources

bug in default-tags when passing vue data

i have an array name defaultData , i tried to do sth like :default-tags = "defaultData" , i noticed that it read the array into default-tags , but the tagsData doesnt read the data
Screenshot 2021-08-19 113427

CSS file is missing for newer version (0.4.0)

When trying to import the css file like the documentation suggests:

import "smart-tagz/dist/smart-tagz.css";

The import fails and the file is not found. Upon inspecting the node_modules directory, the css file is not there, instead the only css file is in the assets/ directory, called output-{hash}.css

Downgrading to version 0.3.2 fixed this for me

A bug with enter key

When I use smart-tagz in the form of elementPlus, adding a tag with the Enter key will replace the previous tag. My code:

<el-form
:label-position="labelPosition"
label-width="100px"
:model="formLabelAlign"

<el-form-item label="Tag">
  <smart-tagz
input-placeholder="Select Countries ..."
:default-tags="['United Kingdom', 'Uruguay', 'Uzbekistan', 'Venezuela', 'Vietnam', 'Virgin Islands (US)', 'Yemen', 'Zambia', 'Zimbabwe']"

/>

Pasting text makes the component crash

How to reproduce
Paste the following text on the codesandbox
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam congue massa accumsan accumsan fringilla. Fusce tempor, ipsum non mollis pellentesque, lorem mauris posuere sapien, lacinia placerat metus enim et nulla. Donec lacinia purus vel blandit dictum. Quisque gravida dictum sagittis. Curabitur vitae nulla magna. Integer fringilla nisi eget tellus laoreet dignissim vitae eget est. Vestibulum facilisis ultrices magna, sit amet convallis neque scelerisque id. Nulla accumsan velit sit amet vestibulum condimentum. Proin vel lorem id ipsum convallis porta non sed enim. Nunc faucibus odio scelerisque tortor interdum hendrerit. Sed consequat nisi non eleifend sodales.

It throws the following error:

TypeError:
Cannot read property 'delimiter' of null
Proxy.handlePaste
https://pd32g.csb.app/node_modules/smart-tagz/dist/smart-tagz.esm.js:527:72
e.tagsData.length.e.maxTags.e.readOnly.onPaste.n.<computed>.n.<computed>
https://pd32g.csb.app/node_modules/smart-tagz/dist/smart-tagz.esm.js:611:49
    at callWithErrorHandling (https://pd32g.csb.app/node_modules/
vue/runtime-core/dist/runtime-core.esm-bundler.js:801:18
    at callWithAsyncErrorHandling (https://pd32g.csb.app/node_modules/
vue/runtime-core/dist/runtime-core.esm-bundler.js:809:17
    at HTMLInputElement.invoker (https://pd32g.csb.app/node_modules/
vue/runtime-dom/dist/runtime-dom.esm-bundler.js:346:56

How to determine which smart-tagz caused the change

I have this function which will tell me every time any smart-tagz changes:

function tagChanged(result: string[]) {
  console.log('tags changed: ' + result)
}

I have many smart-tagz on the page. How do I determine which one caused the change? I tried passing additional arguments in the tagChanged call but had no success and am not clear if that is the path to take.

Let me know how to accomplish this.

How get data ?

Hi, i'm new with vue but i tried to use your component and I don't understand how I can get data when I add a new tag.
can you explain how we can do that please ?

Changing size of tags

I expect this is a general html/css question so please feel free to give general pointers.

Ideally I want to make the tags smaller but starting with color changing. I have this in my .vue file but nothing changes in the <smart-tagz> in the template:

<style scoped>
.smart-tagz {
  color: green;
  background-color: orange;
}
</style>

What am I missing?

How to access tags?

Excellent library, but I cannot for the life of me figure out how to access the tags that are created. There seem to be no examples in the documentation or examples where the tags are exposed to the external application.

I figured I could write something like <smart-tagz v-model="tags" /> and this would update my application's local tags variable, but this doesn't seem to be the case. Looking through the source code, I cannot figure out what prop (if any) exposes the tag contents.

Could you provide an example of how to get a two-way binding with an external tags array?

Depfu Error: No dependency files found

Hello,

We've tried to activate or update your repository on Depfu and couldn't find any supported dependency files. If we were to guess, we would say that this is not actually a project Depfu supports and has probably been activated by error.

Monorepos

Please note that Depfu currently only searches for your dependency files in the root folder. We do support monorepos and non-root files, but don't auto-detect them. If that's the case with this repo, please send us a quick email with the folder you want Depfu to work on and we'll set it up right away!

How to deactivate the project

  • Go to the Settings page of either your own account or the organization you've used
  • Go to "Installed Integrations"
  • Click the "Configure" button on the Depfu integration
  • Remove this repo (prabhuignoto/smart-tagz) from the list of accessible repos.

Please note that using the "All Repositories" setting doesn't make a lot of sense with Depfu.

If you think that this is a mistake

Please let us know by sending an email to [email protected].


This is an automated issue by Depfu. You're getting it because someone configured Depfu to automatically update dependencies on this project.

an event is needed when value changed

I thought on-changed was an event so I made this:

:on-changed="tagsChanged(locale, $event)"

then I realized the on-changed is a prop...

I would need an event with tags value, so I can handle value changes according to locale..

Thank you in advance

Styling Props

Do we have more options for the styling props other than the mentioned ones here?
<smart-tagz class="form-control keyword-input" input-placeholder="Search For Keywords" :on-changed="handleChangeTag" :theme="{ primary: '#f1f5f9', background: '#bdbdbd', tagTextColor: '#000', }" />
Currently, we have only these 3 styling props.

Trying to update the tags from code and nothing.

<smart-tagz
    input-placeholder="Enter names ..."
    editable
    :default-tags="names_list"
    :on-changed="updateNames"
    @keypress.enter.prevent
    @click.prevent
/>

also added a button to add names

<button @click.prevent="addNewName" >TEST</button>

names_list is just an [] declared in the data section.

with the handler being

methods: {
    addAltName() {
        this.names_list.push("TEST NAME")
    },
}

When I press TEST.....the list updates, but smart-tagz does not show any changes.

Did I miss something here?

How to set and retrieve tags with autocomplete

Hi,
thanks for making the library it seems nice and easy to use, other than this one hiccup

I am creating a site to store properties and want tags with them using Vue.js 3

If loading a new property i have a list of autocomplete entries to select from prefilled into :sources="existingtags" this gets set after the page is loaded in the created() method

if loading an existing entry I have the same list of autocomplete entries and a potential list of 0-many already selected tags into :defaultTags="selectedtags"

This doesn't seem to work at all, I can add items through the gui from the list of autocomplete entries though

When trying to upsert(insert or update) i try to retrieve the list of currently selected items using this.selectedtags which is always empty

Can you tell me what I'm doing wrong here? as it seems to be basic functionality to be able to set and retrieve existing tags, I did see a similar issue where it was suggested to use onChanged event but I need the existing values when no change is detected as well as they could change something else on the form I still need the current tag values when onChanged wouldn't have triggered and I need to be able to manually in code set the current values that are selected

I'm using the component implementation, below is a simplified version of the code with just the smart-tags content

<template>
    <div class="col-10">
        <div class='col-9' id='add-property-example'>
            <h3>New Property</h3>
            <form id="add-a-property">
                <label for="tags">Tags</label>
                <smart-tagz 
                    @keypress.enter.prevent 
                    @click.prevent 
                     autosuggest
                     editable
                     inputPlaceholder="Select features ..." 
                     :allowPaste="{delimiter: ','}" 
                     :allowDuplicates="false" 
                     :defaultTags="selectedtags"
                     :sources="existingtags"
                     :maxTags="20" 
                     :theme="{
                        primary: '#545454',
                        background: '#bdbdbd',
                        tagTextColor: '#fff',
                     }" />
                <button type='button' class='btn btn-warning save-property' @click='upsertProperty'>Save</button>
            </form>
        </div>
    </div>
</template>
<script>
import axios from 'axios'
import { SmartTagz } from "smart-tagz";
import "smart-tagz/dist/smart-tagz.css";

export default {
  name: 'main',
  components: {
    SmartTagz,
  },  
  data() {
        return {
            existingtags: [],
            selectedtags: []
        }
    }
  },
  created() {
    this.getAvailableTags();
  },
    methods: {
      getAvailableTags() {     
        axios.get('house/includes/server_processing.php?attributes=true').then((response) => {
            console.log("Main: "+response);
            for (let i = 0; i < response.data.length; ++i)
            {
                var item = response.data[i];
                this.existingtags.push(item.name);
            }            
        }).catch(function(error) {
            // handle error
            console.log(error);
        });
    },
        addNewHouse() {
            console.log("Main: add new house");
            this.selectedtags = [];
        },
        removeProperty(id) {
            this.deleteHouse(id);
            this.emitter.emit("deleteHouse", id);
        },
        openHouse(id) {
            if (id > 0) {
                console.log("Main: open house for id " + id);
                axios.get('house/includes/server_processing.php?houseid=' + id).then((response) => {
                    console.log("Main: "+response);
                    if (response.data != null) {                       
                        this.selectedtags = response.data.tags ?? [];
                    }                    
                }).catch(function(error) {
                    // handle error
                    console.log("Main: "+error);
                });
            }
        },
        upsertProperty() {
            if (isEmpty(this.name) == false) {
                var data = {                    
                    tags: this.selectedtags?.join(",") ?? [],
                };
                axios.post('house/includes/server_processing.php?upsertproperty=true', data).then((response) => {
                    if (response.data.saved == true) {
                        console.log("Main: House saved, refreshing left nav and hiding house form");
                        
                       console.log("Main: Update property list in left nav now");
                    }
                    console.log("Main: "+response);
                }).catch(function(error) {
                    // handle error
                    console.log("Main: "+error);
                });
            }
        },
        tagsOnChanged(tags) {
            console.log("Main: tags changed " + tags);
        }
    }
}
</script>

Thanks for any help

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.