# psk-inputsearch

> Input Vue component for searching data in an API.

Latest version **0.3.8** (published 2021-05-27) · GPLv3 license · 0 weekly downloads

## Install

```sh
npm install psk-inputsearch
pnpm add psk-inputsearch
yarn add psk-inputsearch
bun add psk-inputsearch
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.8 |
| Published | 2021-05-27 |
| First published | 2021-02-11 |
| Weekly downloads | 0 |
| License | GPLv3 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 355 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Paulo Sergio Klaus |
| Maintainers | pauloklaus |
| Keywords | input, vue, search, api, autocomplete |

## Links

- npm: https://www.npmjs.com/package/psk-inputsearch
- Repository: https://github.com/pauloklaus/psk-inputsearch
- Homepage: https://github.com/pauloklaus/psk-inputsearch#readme
- Issues: https://github.com/pauloklaus/psk-inputsearch/issues
- npm.io page: https://npm.io/package/psk-inputsearch

## Dependencies (2)

- [vue](https://npm.io/package/vue.md) ^2.6.11
- [core-js](https://npm.io/package/core-js.md) ^3.6.5

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 0.3.8 (latest) — 2021-05-27
- 0.3.7 — 2021-04-26
- 0.3.6 — 2021-04-26
- 0.3.5 — 2021-04-26
- 0.3.4 — 2021-04-16
- 0.3.3 — 2021-04-16
- 0.3.2 — 2021-04-16
- 0.3.1 — 2021-04-16
- 0.3.0 — 2021-04-16
- 0.2.1 — 2021-02-20
- 0.2.0 — 2021-02-18
- 0.1.11 — 2021-02-11
- 0.1.10 — 2021-02-11
- 0.1.8 — 2021-02-11
- 0.1.7 — 2021-02-11
- … 1 more at https://npm.io/package/psk-inputsearch/versions

## README

# psk-inputsearch

Input Vue component for search and filtering data in an API or a static list.

* Report bugs: <https://github.com/pauloklaus/psk-inputsearch/issues>
* Live test: <https://pauloklaus.com.br/playground>

## Install

Create a new vue project:

```shell
vue create
```

Install component and dependencies:

```shell
npm install --save bootstrap bootstrap-vue psk-inputsearch
```

## Environment setting

Make a src/resources folder at the root:

```shell
mkdir src/resources
```

### Configure the bootstrap

Create the src/resources/bootstrap-vue.js:

```javascript
import Vue from "vue";
import { BootstrapVue, BootstrapVueIcons } from "bootstrap-vue";

import "bootstrap/dist/css/bootstrap.css";
import "bootstrap-vue/dist/bootstrap-vue.css";

Vue.use(BootstrapVue);
Vue.use(BootstrapVueIcons);
```

### Configure the psk-inputsearch

Create the src/resources/psk-inputsearch.js:

```javascript
import Vue from "vue";
import InputSearch from "psk-inputsearch";
import "psk-inputsearch/dist/InputSearch.css";

Vue.use(InputSearch, { InputSearchName: "MyInputSearch" });
```

### Import psk-inputsearch and dependencies

The "src/main.js" file should look like this:

```javascript
import Vue from "vue";
import App from "./App.vue";

import "./resources/bootstrap-vue";
import "./resources/psk-inputsearch";

Vue.config.productionTip = false;

new Vue({
    render: h => h(App),
}).$mount("#app");

```

## How to use (example in App.vue)

```vue
<template>
    <div>
        <p>My Input Search in API
        <br><my-input-search text-field="title" v-model="value" placeholder="Find a product..." :searchMethod="searchInAPI" />
        <br>{{ error }}</p>

        <p>My Input Search in static list
        <br><my-input-search text-field="title" v-model="value" placeholder="Find a person..." :searchMethod="searchInStaticList" /></p>
    </div>
</template>

<script>
export default {
    data() {
        return {
            people: [
                { id: 4, description: "Dennis Ritchie" },
                { id: 3, description: "Grace Hopper" },
                { id: 2, description: "John Backus" },
                { id: 1, description: "John McCarthy" },
                { id: 6, description: "Ken Thompson" },
                { id: 5, description: "Robin Milner" },
            ],
            error: null,
            value: {}
        }
    },
    methods: {
        async searchInApi(term) {
            try {
                const searchResponse = await this.$axios.get("https://fakestoreapi.com/products", { params: { term: term }});
                return Array.isArray(searchResponse.data) ? searchResponse.data : null;
            }
            catch (error) {
                this.$emit("error", error);
            }
            return null;
        },
        searchInStaticList(term) {
            return term ? this.people.filter(item => item.description.toLowerCase().indexOf(term) > -1 ) : this.people;
        }
    }
}
</script>

<style>
* {
    border-radius: 0 !important;
}
input:focus,
button:focus {
    outline: none;
}
</style>
```

## Default JSON format

```json
[
    { id: 1, description: "Test 1" },
    { id: 2, description: "Test 2" }
]
```

## Properties

Property | Description | Required | Default
-|-|-|-
searchMethod | Method to start search and return a filtered array. Has a term parameter with the typed text. | yes |
inputId | html id to the input element | no | random id
autofocus | Focus on load page | no | false
disabled | To disable user input | no | false
debouce | Time to start the search when the user stops typing | no | 500
placeholder | Text to display when the input is empty | no | null
description | Explanation of use, displayed discreetly below the input | no | null
idField | JSON id field | no | id
textField | JSON field with description to display in the input when a list item is selected | no | description
customText | Function to customize text to display in the input | no | null
customFormatResult | Function to customize the result object | no | null
value | Value (an object like this { id: 1, descript: "Test 1" }) to bind selection | no | null
showActionButton | Display a button at the end of the input | no | false
actionButtonIcon | Action button icon (from <https://bootstrap-vue.org/docs/icons>) | no | box-arrow-up-right
buttonVariant | Variant bootstrap color to the button: primary, secondary, success, warning, danger, info, light, dark | no | null
waitingText | Text to display while searching | no | Searching...
notFoundText | Text to display when nothing was found | no | Not found.
containerClass | Class of container div | no | -
resultClass | Class of result div | no | -
messageClass | Class of "searching" message | no | -
itemClass | Class of item | no | -
selectedClass | Class of selected item | no | -

Instead of informing the CSS classes via property, it is possible to redefine them:

* inputsearch-container
* inputsearch-result
* inputsearch-message
* inputsearch-item
* inputsearch-selected
* inputsearch-item:hover
* inputsearch-selected

## Events

Event | Description
-|-
change | When there is change
keydown | When a key is pressed
actionButtonClick | When a button is clicked

## Using in the browser

To use directly in the browser, import bootstrap-vue before psk-inputsearch:

```html
<script src="https://unpkg.com/vue-boostrap" />
<script src="https://unpkg.com/psk-inputsearch" />
```

## Thanks

For the support, friendship and knowledge they always share!

* Marlon Dauernheimer, https://github.com/DMarlon
* Álisson Bertochi, https://github.com/gnxbr

Marlon was essential to optimize and simplify the source code.

---
_Source: https://npm.io/package/psk-inputsearch · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
