Skip to content

Commit 513b122

Browse files
committed
feat: add README
1 parent 40023f2 commit 513b122

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

README.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Vue3-Select-Component
2+
3+
A select component for Vue 3 which helps you to develop a _simple yet powerful_ select control with ease that works out-of-the-box, while still allowing you to customize it to your needs.
4+
5+
This component includes the following features:
6+
7+
- Easy data manipulation with `v-model`
8+
- Great styling out-of-the-box, customization with CSS variables & Vue `:deep`
9+
- Single & multi-select
10+
- Deep customization with `<slot>`s
11+
12+
## Installation
13+
14+
Install the package with npm:
15+
16+
```bash
17+
npm i vue3-select-component
18+
```
19+
20+
Use it in your Vue 3 app:
21+
22+
```vue
23+
<script setup lang="ts">
24+
import { ref } from "vue";
25+
import VueSelect from "vue3-select-component";
26+
27+
const option = ref("");
28+
</script>
29+
30+
<template>
31+
<div class="my-app">
32+
<VueSelect
33+
v-model="option"
34+
:options="[
35+
{ label: 'A Wizard of Earthsea', value: 'wizard_earthsea' },
36+
{ label: 'Harry Potter and the Philosopher\'s Stone', value: 'harry_potter' },
37+
{ label: 'The Lord of the Rings', value: 'the_lord_of_the_rings' },
38+
]"
39+
/>
40+
</div>
41+
</template>
42+
```
43+
44+
## API
45+
46+
### Common types
47+
48+
Here are some common types that are used in the API:
49+
50+
```ts
51+
type Option = {
52+
label: string;
53+
value: string;
54+
[key: string]: any;
55+
};
56+
```
57+
58+
### Props
59+
60+
**v-model**: `string | string[]`
61+
62+
The value of the select. If `isMulti` is `true`, the `v-model` should be an array of string `string[]`.
63+
64+
**options**: `Option[]`
65+
66+
A list of options to choose from. Each option should have a `label` and a `value` property. You can add any other properties to the options, which will be passed to the `option` slot.
67+
68+
**autoscroll**: `boolean` (default: `true`)
69+
70+
Whether the dropdown should automatically scroll to the selected option, when using keyboard navigation.
71+
72+
**placeholder**: `string` (default: `Select an option`)
73+
74+
The placeholder text to show when no option is selected.
75+
76+
**isClearable**: `boolean` (default: `true`)
77+
78+
Whether the select should have a clear button to reset the selected value.
79+
80+
**isDisabled**: `boolean` (default: `false`)
81+
82+
Whether the select should be disabled.
83+
84+
**isSearchable**: `boolean` (default: `true`)
85+
86+
Whether the select should have a search input to filter the options.
87+
88+
**isMulti**: `boolean` (default: `false`)
89+
90+
Whether the select should allow multiple selections. If `true`, the `v-model` should be an array of string `string[]`.
91+
92+
**closeOnSelect**: `boolean` (default: `true`)
93+
94+
Whether the dropdown should close after an option is selected.
95+
96+
**getOptionLabel**: `(option: Option) => string` (default: `option => option.label`)
97+
98+
A function to get the label of an option. This is useful when you want to use a property different from `label` as the label of the option.
99+
100+
This function is used to display the options in the dropdown, and to display the selected option (**single-value**) in the select.
101+
102+
**getMultiValueLabel**: `(option: Option) => string` (default: `option => option.label`)
103+
104+
A function to get the label of an option. This is useful when you want to use a property different from `label` as the label of the option.
105+
106+
This function is used to display the selected options (**multi-value**) in the select.
107+
108+
## License
109+
110+
MIT Licensed. Copyright (c) Thomas Cazade 2024.

0 commit comments

Comments
 (0)