0.1.51 ā€¢ Published 5 years ago

dropdownue v0.1.51

Weekly downloads
21
License
-
Repository
-
Last release
5 years ago

Dropdownue

contributions welcome

A renderless vue dropdown component

Why?

Almost every project needs a dropdown somewhere, And If you are like me, you just don't like to use UI frameworks and their made ready DOM and style and bullshits. So, I made a renderless component to abstract the usual logic behind dropdowns.

šŸ› This may be unstable for now. I'm working on it. And there certainly will be some breaking changes.

Installation

yarn add dropdownue uuid
# OR
npm i dropdownue uuid

Usage

Register

import { Dropdownue, DropdownueItem } from "dropdownue";

export default {
  ...
  components: {
    Dropdownue,
    DropdownueItem
  }
  ...
};

<dropdownue>

You can use <dropdownue> like this. required props are listed on API section

<dropdownue
  :list="list"
  default-value="value"
  v-slot="{ instanceId, isOpen, value: providedValue, listItems, toggle }"
  @change="handleValueChange"
>
  ...
</dropdownue>

And in you script section...

export default {
	...
    data() {
        return {
	        list: [
                {
                    name: 'draft',
                    id: 1
                },
                {
                    name: 'published',
                    id: 2
                },
                {
                    name: 'archive',
                    id: 3,
                }
            ],
            value: 1
        }
    },
    methods: {
	    handleValueChange(newValue) {
		    ...
	    }
	}

<dropdownue-item>

Inside your <dropdownue>, there it goes a <dropdownue-item> with v-for on it.
:bangbang: You have to get instanceId from <dropdown> and pass it to <dropdown-item>
:exclamation: Remember to attach itemEvents to v-on of your list items

<dropdownue-item
  :instance-id="instanceId"
  v-slot="{ isHighlighted, isSelected, itemEvents }"
  v-for="item in listItems"
  :key="item.id"
  :list="listItems"
  :item="item"
>
  <li v-on="itemEvents(item)">
    {{ item.name }}
  </li>
</dropdownue-item>

API

This is the list of all APIs and Props you may want to know about.

Props

<dropdownue> ... </dropdwonue>

NameDescriptionTypeDefaultis Required
listArray of your items. Should contain idArray---true
defaultValueid of pre selected itemStringundefinedfalse
filterQueryThe query that listItems gets generated based onString''false
closeOnSelectShould or should not change state to close after item selectionBooleantruefalse
closeOnClickawayShould or should not change state to close after clickaway or esc keydownBooleantruefalse
resetOnSelectShould or should not reset filterQuery and listItems on item selectBooleantruefalse

<dropdownue-item> ... </dropdwonue-item>

NameDescriptionTypeDefaultis Required
listThe list that <dropdownue> provides for youArray---true
itemAn item of your list---true

Provides

The API mostly contains Functions for you to call, Events to listen on, and Flags to check, plus a listItem to be rendered. use these in v-slot

<dropdownue> ... </dropdwonue>

NameIntensionType
listItemCopy of your passed list, plus some goodiesdata
valueID of current selected itemdata
isClosedFlag for state being closeflag
isOpenFlag for state being openflag
openChanges state to openfunction
closeChanges state to closedfunction
toggleToggle statefunction (Boolean)
filterFilters listItemsfunction (String)

<dropdownue-item> ... </dropdwonue-item>

NameIntensionType
isSelectedCopy of your passed list, plus some goodiesflag
isHighlightedID of current selected itemflag
itemEventsEvents to be attached to list item DOMdata
highlightHighlights the item via IDfunstion (item)

Caveats

  • You can use either filterQuery prop or filter function. whichever you want.
0.1.51

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago