├── .gitignore
├── README.md
├── package-lock.json
├── package.json
├── src
├── Autocomplete.vue
├── index.js
├── interfaces
│ └── ComponentProps.ts
└── main.ts
└── tsconfig.json
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | /dist
4 |
5 |
6 | # local env files
7 | .env.local
8 | .env.*.local
9 |
10 | # Log files
11 | npm-debug.log*
12 | yarn-debug.log*
13 | yarn-error.log*
14 | pnpm-debug.log*
15 |
16 | # Editor directories and files
17 | .idea
18 | .vscode
19 | *.suo
20 | *.ntvs*
21 | *.njsproj
22 | *.sln
23 | *.sw?
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # vue3-autocomplete
2 |
3 | ## Table of contents
4 |
5 | * [Installation](#installation)
6 | * [Usage](#usage)
7 |
8 | ## Installation
9 |
10 | Using npm
11 | ```
12 | npm install vue3-autocomplete
13 | ```
14 |
15 | Using yarn
16 | ```
17 | yarn add vue3-autocomplete
18 | ```
19 |
20 | ## Usage
21 |
22 | Load the component globally...
23 |
24 | ```ts
25 | import App from './App.vue' // Or whatever you need
26 | import Autocomplete from 'vue3-autocomplete'
27 | // Optional: Import default CSS
28 | import 'vue3-autocomplete/dist/vue3-autocomplete.css'
29 |
30 | let app = createApp(App)
31 | app.component('Autocomplete', Autocomplete)
32 | app.mount('#app')
33 | ```
34 |
35 | ... Or locally into your component.
36 |
37 | ```ts
38 | import Autocomplete from 'vue3-autocomplete'
39 | // Optional: Import default CSS
40 | import 'vue3-autocomplete/dist/vue3-autocomplete.css'
41 |
42 | export default {
43 | name: 'YourComponentName',
44 | components: {
45 | Autocomplete
46 | }
47 | }
48 | ```
49 |
50 | Use the component into your template.
51 |
52 | ```html
53 |
54 |
60 |
61 | ```
62 |
63 | ## Properties
64 |
65 | | Property | Type | Description | Required | Default |
66 | | :------: | :---: | :---------: | :------: | :-----: |
67 | | results | Array | Items to display in the results list | No | [] |
68 | | display-item | Function | Describes how to render each item in results | No | **return** item.name |
69 | | debounce | Integer | Time to wait before each call to the ***@input*** event | No | 0 |
70 | | max | Integer | Define a render limit for **results** items | No | 10 |
71 | | placeholder | String | Default input placeholder | No | '' |
72 | | use-html-for-results | Boolean | If true, displayItem method will display results as html | No | false |
73 | | input-class | Array | Override input default classes | No | [] |
74 | | results-container-class | Array | Override results container default classes | No | [] |
75 | | results-item-class | Array | Override results item default classes | No | [] |
76 |
77 | ## Events
78 |
79 | | Event | Description |
80 | | :---: | :---------: |
81 | | **@input** | Triggered on user input, should update the local results list |
82 | | **@onSelect** | Triggered when user click on a list item and return the selected item |
83 |
84 | ## License
85 |
86 | MIT
87 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue3-autocomplete",
3 | "version": "1.0.4",
4 | "private": false,
5 | "main": "dist/vue3-autocomplete.common.js",
6 | "unpkg": "dist/vue3-autocomplete.umd.min.js",
7 | "jsdelivr": "dist/vue3-autocomplete.umd.min.js",
8 | "keywords": [
9 | "vue",
10 | "vuejs",
11 | "vue3",
12 | "autocomplete",
13 | "select",
14 | "search"
15 | ],
16 | "homepage": "",
17 | "files": [
18 | "dist/*"
19 | ],
20 | "repository": {
21 | "type": "git",
22 | "url": "https://github.com/Takachi67/vue3-autocomplete.git"
23 | },
24 | "bugs": {
25 | "url": "https://github.com/Takachi67/vue3-autocomplete/issues"
26 | },
27 | "scripts": {
28 | "serve": "vue-cli-service serve",
29 | "build": "vue-cli-service build --target lib --name vue3-autocomplete src/Autocomplete.vue",
30 | "prepublishOnly": "$npm_execpath build",
31 | "test:unit": "vue-cli-service test:unit"
32 | },
33 | "dependencies": {
34 | "@vue/cli-plugin-typescript": "^4.5.7",
35 | "axios": ">=0.21.1 <1",
36 | "sass": "^1.27.0",
37 | "sass-loader": "^10.0.3",
38 | "typescript": "^4.0.3",
39 | "vue": "^3.0.0"
40 | },
41 | "devDependencies": {
42 | "@vue/cli-plugin-unit-jest": "~4.5.0",
43 | "@vue/cli-service": "~4.5.0",
44 | "@vue/compiler-sfc": "^3.0.0",
45 | "@vue/test-utils": "^2.0.0-0",
46 | "vue-jest": "^5.0.0-0"
47 | },
48 | "browserslist": [
49 | "> 1%",
50 | "last 2 versions",
51 | "not dead"
52 | ],
53 | "jest": {
54 | "preset": "@vue/cli-plugin-unit-jest/presets/no-babel",
55 | "transform": {
56 | "^.+\\.vue$": "vue-jest"
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/Autocomplete.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
14 |
15 |
24 |
{{ displayItem(item) }}
32 |
33 |
34 |
35 |
36 |
205 |
206 |
242 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | export { default as Autocomplete } from './components/Autocomplete'
--------------------------------------------------------------------------------
/src/interfaces/ComponentProps.ts:
--------------------------------------------------------------------------------
1 | export default interface ComponentProps {
2 |
3 | debounce: number
4 | inputClass: Array
5 | results: Array
6 | resultsContainerClass: Array
7 | resultsItemClass: Array
8 | max: number,
9 | placeholder: String,
10 | useHtmlForResults: Boolean
11 |
12 | displayItem(item: Object|String): String
13 |
14 | }
--------------------------------------------------------------------------------
/src/main.ts:
--------------------------------------------------------------------------------
1 | // @ts-ignore
2 | import Autocomplete from './Autocomplete'
3 |
4 | const AutocompletePlugin = {
5 | // @ts-ignore
6 | install(Vue, options = {}) {
7 | Vue.component('Autocomplete', Autocomplete)
8 | }
9 | }
10 |
11 | export default AutocompletePlugin
12 | export { Autocomplete }
13 |
14 | // @ts-ignore
15 | if (typeof window !== 'undefined' && window.Vue) {
16 | // @ts-ignore
17 | window.Vue.use(ComponentLibrary)
18 | }
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "esnext",
4 | "module": "esnext",
5 | "strict": true,
6 | "jsx": "preserve",
7 | "moduleResolution": "node"
8 | },
9 | "include": ["src/**/*"]
10 | }
--------------------------------------------------------------------------------