1.0.11 • Published 3 years ago

vue-simple-custom-select v1.0.11

Weekly downloads
-
License
-
Repository
github
Last release
3 years ago

Vue Simple Custom Select

A simple Vue component that allows you to create a custom select without any efforts.

Demo available here

Get started

npm i vue-simple-custom-select

You can then use it by importing it in your chosen Vue project.

<template>
 <vue-simple-select 
   v-model="selected"
   :options="options" 
 />
</template>

<script>
import VueSimpleSelect from 'vue-simple-custom-select'

export default {
  name:  'Your component',
  components: {
    VueSimpleSelect 
  },
  data() {
    return {
      selected: {},
      options: [
        {
          label: 'Label',
          value: 'value'
        }
      ]
    }
  }
}
</script>

Props

NameDefaultDescriptionRequired
valuenullThe default selected valuetrue
options[]The options displaying inside the dropdowntrue
no-click-outsidefalseIf the select should not be closed when clicking outsidefalse
openedfalseAbility to open the dropdown by defaultfalse
multiplefalseIf the select allows multiple items to be selectedfalse
placeholder''The value to be displayed when nothing is selectedfalse
title''Ability to place a title on the select buttonfalse
transition'slide-fade'Used to change the transition when showing or hiding the dropdowm.false
labelledby''Can be used to specify what element labels the button.false

V-model

The component uses a custom model, it is binded to the value prop and to the change event.

Therefore you do not have to use the prop value or listen to change, simply bind a v-model like in this example.

Slots

This custom select can be customised through slots.

NameValuesDescription
button{ handleClick, showSelect, hideSelect }Can be used to replace the button trigerring the dropdown
inner-buttonnullRight inside the button, can be used to add content
before-iconnullOn the left of the icon, can be used to add content
icon{ show }Can be used to change the icon
after-iconnullOn the right of the icon, can be used to add content
dropdown{ selectValue, isSelected, show }Can be used to replace the default dropdown
dropdown-content{ selectValue, isSelected }Can be used to replace the content of the dropdown
single-option{ option, index, selectValue, isSelected }"Can be used to change a single option in the dropdown, keep in mind, this slot is inside of a v-for

Methods

This component's slots give acces to differents methods allowing you to customize its behavior.

NameParamsReturnsEmitsDescription
showSelectvoidvoidshowIs used to show the dropdown
hideSelectvoidvoidhideIs used to hide the dropdown
handleClickvoidvoidshowIs used to toggle between showing and hiding the dropdown
selectValueoption: OptionvoidchangeIs used to select (or remove) an option, an option has to be passed in
isSelectedoption: OptionbooleanvoidDetermines if the passed in option is selected

Styles

The components uses only a few styles that can be easily changed and adapted. You can even add your own classes using slots.

Every class is nested inside .vue-simple-select-container.

Every class is prefixed by vue-simple-select-.

NameDescription
buttonRefers to the button tiggering the dropdown
dropdownRefers to the dropdown, containing the list of options
optionRefers to a single option in the the list of options
option.selectedRefers to a single selected option in the the list of options
iconRefers to the arrow icon in the button
icon.reverseRefers to the arrow icon in the button, has a transform: rotate(180deg);
placeholderRefers to the placeholder showing when nothing is selected
selectedRefers to the content of the button if it contains a list of selected options (in multiple mode)
selected-optionRefers to the content of the button (in single mode)
labelRefers to the amount of selected option (in multiple mode)

Side notes

The component is originally made for my personnal use and therefore may contain bugs (that can be reported on the GitHub repo).

Finding documentation on how to use a preprocessor and install TailwindCSS with Vue-Rollup wasn't an easy task. So I decided to use laravel-mix to build a simple css file that is then used in the component. I am definetly open for suggestions on how to improve this process or any other aspect of the component.

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago