@night-owl-elite/vue-select 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -95
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,121 +1,102 @@
|
|
|
1
|
-
Vue 3 Tree Select Component
|
|
1
|
+
# Vue 3 Tree Select Component
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@night-owl-elite/vue-select)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
2
6
|
A feature-rich, accessible, and customizable tree-select component for Vue 3.
|
|
3
7
|
|
|
4
8
|
This component provides a powerful and flexible way to select single or multiple items from a hierarchical (tree) data structure. It includes searching, custom item rendering, "select all" functionality, and is styled with Bootstrap 5 and uses Font Awesome for icons.
|
|
5
9
|
|
|
6
|
-
|
|
7
|
-
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
✅ **Single & Multiple Selection**: Easily switch between modes with the `multiple` prop.
|
|
15
|
+
|
|
16
|
+
✅ **Two Selection UIs**: Choose between `checkbox` or `highlight` styles for selection.
|
|
17
|
+
|
|
18
|
+
✅ **Search & Filtering**: A built-in search bar to filter tree nodes in real-time.
|
|
8
19
|
|
|
9
|
-
✅
|
|
20
|
+
✅ **"Select All" Children**: In `multiple` mode, click a parent to select/deselect all its descendants.
|
|
10
21
|
|
|
11
|
-
✅
|
|
22
|
+
✅ **Customizable Data Keys**: Specify which properties in your data objects to use for labels, values, and disabled states.
|
|
12
23
|
|
|
13
|
-
✅
|
|
24
|
+
✅ **Customizable Items**: Use scoped slots to take full control over how each tree item is rendered.
|
|
14
25
|
|
|
15
|
-
✅
|
|
26
|
+
✅ **Built with Bootstrap 5**: Seamlessly integrates with projects using the Bootstrap 5 framework.
|
|
16
27
|
|
|
17
|
-
|
|
28
|
+
---
|
|
18
29
|
|
|
19
|
-
|
|
30
|
+
### Installation
|
|
20
31
|
|
|
32
|
+
1. **Install the package from npm:**
|
|
33
|
+
```bash
|
|
34
|
+
npm install @night-owl-elite/vue-select
|
|
35
|
+
```
|
|
21
36
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
37
|
+
2. **Install Peer Dependencies:**
|
|
38
|
+
This component relies on Bootstrap for styling and dropdown functionality.
|
|
39
|
+
```bash
|
|
40
|
+
npm install bootstrap @popperjs/core
|
|
41
|
+
```
|
|
27
42
|
|
|
28
|
-
|
|
43
|
+
3. **Import CSS & JS:**
|
|
44
|
+
Make sure to import Bootstrap's CSS and JS in your main entry file (e.g., `main.js` or `main.ts`):
|
|
45
|
+
```javascript
|
|
46
|
+
// main.js or main.ts
|
|
47
|
+
import 'bootstrap/dist/css/bootstrap.min.css';
|
|
48
|
+
import 'bootstrap/dist/js/bootstrap.bundle.min.js';
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
### Usage
|
|
54
|
+
|
|
55
|
+
Here is a basic example of how to use the `TreeSelect` component.
|
|
56
|
+
|
|
57
|
+
```vue
|
|
58
|
+
<template>
|
|
59
|
+
<div class="container mt-5">
|
|
60
|
+
<TreeSelect
|
|
61
|
+
v-model="selectedValue"
|
|
62
|
+
:items="treeData"
|
|
63
|
+
:multiple="true"
|
|
64
|
+
:select-all="true"
|
|
65
|
+
:searchable="true"
|
|
66
|
+
placeholder="Select categories..."
|
|
67
|
+
option-label="value"
|
|
68
|
+
option-value="code"
|
|
69
|
+
disabled-key="isDisabled"
|
|
70
|
+
exclude-from-selected-list-key="excludeFromSelectedList"
|
|
71
|
+
/>
|
|
72
|
+
<p class="mt-3"><strong>Selected:</strong> {{ selectedValue }}</p>
|
|
73
|
+
</div>
|
|
74
|
+
</template>
|
|
29
75
|
|
|
30
76
|
<script setup>
|
|
31
77
|
import { ref } from 'vue';
|
|
32
|
-
import
|
|
33
|
-
|
|
34
|
-
const selectedItem = ref(null);
|
|
78
|
+
import TreeSelect from '@night-owl-elite/vue-select';
|
|
35
79
|
|
|
36
|
-
|
|
37
|
-
const selectedItems = ref(['APPLE']); // Pre-select an item
|
|
80
|
+
const selectedValue = ref([]);
|
|
38
81
|
|
|
39
|
-
const treeData =
|
|
82
|
+
const treeData = [
|
|
40
83
|
{
|
|
41
|
-
code: '
|
|
42
|
-
value: '
|
|
43
|
-
//
|
|
44
|
-
|
|
84
|
+
code: 'electronics',
|
|
85
|
+
value: 'Electronics',
|
|
86
|
+
// This node won't be added to the modelValue, useful for grouping
|
|
87
|
+
excludeFromSelectedList: true,
|
|
45
88
|
children: [
|
|
46
|
-
{ code: '
|
|
47
|
-
{ code: '
|
|
48
|
-
{
|
|
49
|
-
code: 'BERRY',
|
|
50
|
-
value: 'Berries',
|
|
51
|
-
excludeFromList: true,
|
|
52
|
-
children: [
|
|
53
|
-
{ code: 'STRAWBERRY', value: 'Strawberry' },
|
|
54
|
-
{ code: 'RASPBERRY', value: 'Raspberry', isDisabled: true }, // Disabled item
|
|
55
|
-
]
|
|
56
|
-
},
|
|
89
|
+
{ code: 'smartphones', value: 'Smartphones' },
|
|
90
|
+
{ code: 'laptops', value: 'Laptops' },
|
|
57
91
|
],
|
|
58
92
|
},
|
|
59
93
|
{
|
|
60
|
-
code: '
|
|
61
|
-
value: '
|
|
94
|
+
code: 'furniture',
|
|
95
|
+
value: 'Furniture',
|
|
62
96
|
children: [
|
|
63
|
-
{ code: '
|
|
64
|
-
{ code: '
|
|
97
|
+
{ code: 'tables', value: 'Tables' },
|
|
98
|
+
{ code: 'chairs', value: 'Chairs', isDisabled: true },
|
|
65
99
|
],
|
|
66
100
|
},
|
|
67
|
-
]
|
|
68
|
-
</script>
|
|
69
|
-
|
|
70
|
-
<template>
|
|
71
|
-
<div class="container py-5">
|
|
72
|
-
<div class="row justify-content-center">
|
|
73
|
-
<div class="col-md-6">
|
|
74
|
-
<h3>Multiple Selection with Checkboxes</h3>
|
|
75
|
-
<VSelect
|
|
76
|
-
v-model="selectedItems"
|
|
77
|
-
:items="treeData"
|
|
78
|
-
:multiple="true"
|
|
79
|
-
:select-all="true"
|
|
80
|
-
select-mode="checkbox"
|
|
81
|
-
placeholder="Select multiple items..."
|
|
82
|
-
disabled-key="isDisabled"
|
|
83
|
-
exclude-from-selected-list-key="excludeFromList"
|
|
84
|
-
/>
|
|
85
|
-
<pre class="mt-2 bg-light p-2 rounded">v-model: {{ selectedItems }}</pre>
|
|
86
|
-
|
|
87
|
-
<h3 class="mt-5">Single Selection with Highlight</h3>
|
|
88
|
-
<VSelect
|
|
89
|
-
v-model="selectedItem"
|
|
90
|
-
:items="treeData"
|
|
91
|
-
:multiple="false"
|
|
92
|
-
select-mode="highlight"
|
|
93
|
-
placeholder="Select a single item..."
|
|
94
|
-
/>
|
|
95
|
-
<pre class="mt-2 bg-light p-2 rounded">v-model: {{ selectedItem }}</pre>
|
|
96
|
-
</div>
|
|
97
|
-
</div>
|
|
98
|
-
</div>
|
|
99
|
-
</template>
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
API Reference
|
|
103
|
-
Prop Type Default Description
|
|
104
|
-
modelValue [String, Number, Array] null The selected value(s). Use v-model to bind.
|
|
105
|
-
items Array [] The array of hierarchical data to display. Each item is an object.
|
|
106
|
-
multiple Boolean false If true, allows multiple items to be selected.
|
|
107
|
-
selectMode String 'checkbox' The UI style for selection. Can be 'checkbox' or 'highlight'.
|
|
108
|
-
placeholder String 'Select item...' The text displayed when no items are selected.
|
|
109
|
-
isInvalid Boolean false If true, applies a red border for validation feedback.
|
|
110
|
-
disabled Boolean false If true, disables the entire component.
|
|
111
|
-
searchable Boolean true If true, shows a search input in the dropdown.
|
|
112
|
-
isLoading Boolean false If true, shows a loading spinner and disables the component.
|
|
113
|
-
showClearButton Boolean true If true, shows a button to clear the current selection.
|
|
114
|
-
selectAll Boolean false When multiple is true, enables selecting a parent to automatically select all its enabled children.
|
|
115
|
-
optionLabel String 'value' The key in your item objects that holds the display text.
|
|
116
|
-
optionValue String 'code' The key in your item objects that holds the unique value for v-model.
|
|
117
|
-
disabledKey String null The key in your item objects that, if present and not null, disables that item.
|
|
118
|
-
excludeFromSelectedListKey String null If an item object has this key set to true, its value won't be included in the final emitted modelValue. Useful for parent group labels.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
101
|
+
];
|
|
102
|
+
</script>
|