# vue-spruce
**Repository Path**: mirrors_crishellco/vue-spruce
## Basic Information
- **Project Name**: vue-spruce
- **Description**: A collection of useful Vue 2 renderless components.
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2023-09-07
- **Last Updated**: 2025-12-04
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# Vue Spruce

[](https://codecov.io/gh/crishellco/vue-spruce)
[](https://codeclimate.com/github/crishellco/vue-spruce/maintainability)
A collection of useful Vue 2 renderless components.
Check out the [demo](https://vue-spruce.netlify.app/)
- [Install](#install)
- [The Components](#the-components)
- [SpruceAtLeast](#spruceatleast)
- [SpruceCling](#sprucecling)
- [SpruceEvent](#spruceevent)
- [SpruceFetch](#sprucefetch)
- [SpruceFunction](#sprucefunction)
- [SprucePaginate](#sprucepaginate)
- [SpruceSearch](#sprucesearch)
- [SpruceSort](#sprucesort)
- [SpruceState](#sprucestate)
- [SpruceTagInput](#sprucetaginput)
- [SpruceToggle](#sprucetoggle)
- [SpruceWatch](#sprucewatch)
- [Examples](#examples)
- [Development](#development)
- [How to Contribute](#how-to-contribute)
- [Pull Requests](#pull-requests)
- [License](#license)
## Install
### Package
```bash
yarn add -D @crishellco/vue-spruce
# or
npm i -D @crishellco/vue-spruce
```
### Vue Plugin
Installs all components globally.
```javascript
import Vue from 'vue';
import VueSpruce from '@crishellco/vue-spruce';
Vue.use(VueSpruce);
// or with options
Vue.use(VueSpruce, { componentPrefix: 's' });
```
### Nuxt Module
Installs all components globally.
```javascript
// nuxt.config.js
{
modules: [['@crishellco/vue-spruce/nuxt', { componentPrefix: 's' }]];
}
```
#### Options
| Name | Description | Default |
|-------------------|-----------------------------------------------------|----------|
| `componentPrefix` | The prefix used when installing components globally | `spruce` |
### Named Imports
Alternatively, use only the components you need.
```javascript
import {
SpruceAtLeast,
SpruceCling,
SpruceEvent,
SpruceFetch,
SpruceFunction,
SprucePaginate,
SpruceSearch,
SpruceSort,
SpruceState,
SpruceToggle,
SpruceWatch,
} from '@crishellco/vue-spruce';
export default {
components: {
SpruceAtLeast,
SpruceCling,
SpruceEvent,
SpruceFetch,
SpruceFunction,
SprucePaginate,
SpruceSearch,
SpruceSort,
SpruceState,
SpruceToggle,
SpruceWatch,
},
};
```
## The Components
### SpruceAtLeast
Ensures a component shows for at least a given amount of time, in milliseconds, before hiding.
```html
```
#### Props
| Name | Description | Type | Required | Default |
|--------|--------------------------------------------------------------------|---------|----------|---------|
| `ms` | Minimum amount of time to show, in milliseconds | Number | Yes | |
| `show` | Weather or not to show the contents (given enough time has passed) | Boolean | No | `true` |
#### Slots
| Name | Required |
|-----------|----------|
| `default` | Yes |
#### Slot Scope
| Slot | Name | Description | Type |
|-----------|------------|------------------------------------------------------------|---------|
| `default` | `disabled` | True if waiting to hide content after `ms` time has passed | Boolean |
| `default` | `show` | If the contents should be shown | Boolean |
### SpruceCling
Clings the `clinger` slot's contents to the `anchor` slot's contents using `popper.js`. Great for things like dropdown menus. _See the [demo](https://vue-spruce.netlify.app/) for more context._
```html
i'm a clinger!
```
#### Props
| Name | Description | Type | Required | Default |
|-------------|------------------------------------------------------------------------------------------------------------------------------|--------|----------|---------|
| `modifiers` | The [popper.js modifiers](https://popper.js.org/docs/v2/modifiers/) | Array | No | `[]` |
| `placement` | The [popper.js placement](https://popper.js.org/docs/v2/constructors//#options) of the `clinger` in relation to the `anchor` | String | No | `auto` |
#### Slots
| Name | Required |
|-----------|----------|
| `anchor` | Yes |
| `clinger` | Yes |
#### Slot Scope
| Slot | Name | Description | Type |
|-----------|----------|-----------------------------|----------|
| `anchor` | `update` | Updates the popper instance | Function |
| `clinger` | `update` | Updates the popper instance | Function |
### SpruceEvent
Track any `window` event occurance inside or outside of `SpruceEvent`'s default slot.
```html
```
#### Props
| Name | Description | Type | Required | Default |
|-------------|---------------------------------------------------------------|---------|----------|---------|
| `event` | The event to listen to | String | Yes | |
| `immediate` | First event immediately (in `mounted`) | Boolean | No | `false` |
| `outside` | Listen for the even only outside of the default slot elements | Boolean | No | `false` |
#### Events
| Name | Description | Payload |
|----------------------------|-------------------------------|---------|
| _Same as the `event` prop_ | Fired when the event happens. | -- |
#### Slots
| Name | Required |
|-----------|----------|
| `default` | No |
### SpruceFetch
Make asynchronous API fetch calls.
```html
Errors! {{ error.status }}
Data: {{ data }}
```
#### Props
| Name | Description | Type | Required | Default |
|-------------|------------------------------------------------------------|---------|----------|---------|
| `url` | The API url (changing this will refetch and rest all data) | String | Yes | |
| `immediate` | Weather to immediate make the request on mount | Boolean | No | `true` |
#### Events
| Name | Description | Payload |
|-----------|--------------------------------------|-----------------------------------|
| `success` | Fires when the request is successful | `{data: Object, fetch: Function}` |
| `error` | Fires when the request fails | `{data: Object, fetch: Function}` |
#### Slots
| Name | Required |
|-----------|----------|
| `default` | Yes |
#### Slot Scope
| Slot | Name | Description | Type |
|-----------|-----------|--------------------------------------|------------------------------------|
| `default` | `calls` | Number of calls made | Number |
| `default` | `data` | The response on a successful request | Object |
| `default` | `error` | The response on a failed request | `{ data: Object, status: Number }` |
| `default` | `loading` | Whether a request is in progress | Boolean |
| `default` | `fetch` | Makes another request | Function |
### SpruceFunction
Create reusable functions on the fly (great for lists!).
```html
```
#### Props
| Name | Description | Type | Required | Default |
|------|--------------|----------|----------|---------|
| `fn` | The function | Function | Yes | |
#### Slots
| Name | Required |
|-----------|----------|
| `default` | Yes |
#### Slot Scope
| Slot | Name | Description | Type |
|-----------|------|--------------|----------|
| `default` | `fn` | The function | Function |
### SprucePaginate
Paginate an array and navigate through it's chunks.
```html
```
#### Props
| Name | Description | Type | Required | Default |
|--------|-----------------------|------------|----------|---------|
| `size` | Page size | Number | Yes | |
| `list` | The items to paginate | Array | Yes | |
#### Slots
| Name | Required |
|-----------|----------|
| `default` | Yes |
#### Slot Scope
| Slot | Name | Description | Type |
|-----------|--------------|-----------------------------------------------------------------------------------------------|----------|
| `default` | `first` | Go to first page | Function |
| `default` | `go` | Go to specific page | Function |
| `default` | `isFirst` | If currently on first page | Boolean |
| `default` | `isLast` | If currently on last page | Boolean |
| `default` | `last` | Go to last page | Function |
| `default` | `next` | Go to next page | Function |
| `default` | `page` | The current page | any |
| `default` | `pages` | The chunked pages | Array |
| `default` | `links` | A calculated array of specific page numbers that can be used for links `[1, 2, 3, '...', 40]` | Array |
| `default` | `pageNum` | The current page number | Number |
| `default` | `prev` | Go to previous page | Function |
| `default` | `rangeEnd` | The end of the current page | Number |
| `default` | `rangeStart` | The start of the current page | Number |
| `default` | `reset` | Reset the state of pagination | Function |
| `default` | `totalPages` | Total number of pages | Number |
### SpruceSearch
Search an array of strings or objects by keys using [fuse.js](https://fusejs.io/).
```html
{{ item }}
```
#### Props
| Name | Description | Type | Required | Default |
|-------------|-------------------------|--------|----------|-----------------------------------------------------------------------------------|
| `keys` | The keys to search in | Array | No | If `list` is `Array