1.0.0 • Published 5 years ago

sky-list v1.0.0

Weekly downloads
5
License
MIT
Repository
github
Last release
5 years ago

sky-list

Vue module for requesting search API (via axios) and displaying result with different pagination options

List of content

Installation

npm install sky-list
yarn add sky-list

Usage

Import

import Vue from 'vue';

Different import approaches. The First provides the minified and compiled dist version, the other the raw .vue file.

import SkyList from 'sky-list';
import SkyList from '${YOUR-PROJECT-ROOT-PATH}/node_modules/sky-list/src/';

Install plugin

Vue.use(SkyList);

Option tables

SkyList options

NameTypeDefaultOptionsDescription
parametersObject{ keywords: '' }Parameters to use in query declared with initial value
optionsObject{ api: '/umbraco/api/site/search/', limit: 10, showCount: false, paginationType: 'more', loadFetch: false, }paginationType navigation numeric pagination more allChange custom request setup. loadFetch: enables/disables fetch on page load. showCount: enables/disables "x" results found. api: your prefered endpoint
filterObject{}Declare query properties to be handled as filters eg: { fitlerName: initialValue }
value-mapObject{}If a v-model returns a object and a prop is needed, it can be declared with initial value eg: { nestedPropName: initialValue }
validate-queryFunctionquery => query.keywords
live-searchBooleantrueEnable/disable search on query change

Slots options

NameSlot-scopeDescription
listFormquery ObjectSlot for custom form setup to be v-model'ed against SkyList query
listItemindex Number listItem ObjectSlot for custom item markup
resultMessagequery Object pagination ObjectSlot for custom message when results are found
noResultMessagequery ObjectSlot for custom message when no results are found
listMoreitemsLeft NumberSlot for custom show more button
listPrevSlot for custom previous button
listNextSlot for custom next button
paginationBulletcount NumberSlot for custom pagination bullets

Examples

<sky-list>
	<div
		slot="listForm"
		slot-scope="{ query }"
	>
		<input type="text" v-model="query['keywords']" placeholder="Type your search query">
	</div>


	<div
		slot="listItem"
		slot-scope="{ index, item }"
		:item="item"
	>
	    Custom handling of list item
	</div>
</sky-list>

Component options (with default values)

<sky-list
    :parameters="{ keywords: '' }" || Add your own key/value pair with initial values
    :options="{
    	api: '/umbraco/api/site/search/',
    	limit: 10,
    	showCount: false, || true |false
    	paginationType: 'more', || 'navigation' | 'pagination' | 'more' | 'all' | 'numeric'
    	loadFetch: false,
    }"
    :validate-query="query => query.keywords" || parse in your own query validation
    :live-search="true" || true/false
    :value-map="{}" || If v-model returns an object setup rule for which prop to use eg. { nestedPropName: initialValue }
>
    <!-- content config here -->
    <!-- pagination config here -->
</sky-list>

Content slots (with default values)

Sky-list exposes different slot which can be customized

Message slots

resultMessage: custom message displayed when results are found

<sky-list ... >
    <span
        slot="resultMessage"
        slot-scope="{ query, pagination }"
    >
    	Your search for <em>"{{query.keywords}}"</em> returned <em>{{pagination.total}} {{(pagination.total === 1) ? 'result' : 'results'}}</em>
    </span>
</sky-list>

noResultMessage: custom message displayed when no results are found

<sky-list ... >
    <span
        slot="noResultMessage"
        slot-scope="{ query }"
        v-text="'Your search for ${query.keywords} returned no results'"
    />
</sky-list>

List item slot

listItem: Slot for customizing list items. exposes item object and list index

<sky-list ...>
	<div
		slot="listItem"
		slot-scope="{ item, index }"
	>
	    <small v-text="`No. ${index + 1}`"
	    <h2 v-text="item.title" />
	    <p v-text="item.teaser" />
	</div>
</sky-list>

Preferably this can be used with custom components like this

<sky-list ...>
    <MyComponent
        slot="listItem"
		slot-scope="{ item, index }"
		:my-prop-for-data="item"
		:my-prop-for-index="index"
	/>
</sky-list>

Pagination slot options (with default values)

paginationType: 'more' | 'all'

Slot for customizing show more / all button

<sky-list ... >
	<span
	    slot="listMore"
	    slot-scope="{ itemsLeft }"
	    v-text="`${itemsLeft} not displayed`"
    />
</sky-list>
paginationType: 'navigation' | 'pagination'

listPrev: Slot for customizing previous button nextPrev: Slot for customizing next button

<sky-list ... >
    <span slot="listPrev">Previous</span>
    <span slot="listNext">Next</span>
</sky-list>
paginationType: 'numeric' | 'pagination'

paginationBullet: Slot for customizing bullets

<sky-list ... >
	<span
	    slot="paginationBullet"
	    slot-scope=" { count }"
	    v-text="`Page ${count}`"
    />
</sky-list>

API Response Setup

API Response Setup

SkyList expects a response with the following setup

{
    "meta":{
        "code":200
    },
    "pagination":{
        "total":1,
        "limit":10,
        "offset":0
    },
    "data":[
        {
            title: 'item1',
            teaser: 'lorem ipsum',
        },
        {
            title: 'item2',
            teaser: '',
        },
        {
            title: 'item3',
            teaser: null,
        },
        ...
    ]
}

Credits

This module is made by the Frontenders at skybrud.dk. Feel free to use it in any way you want. Feedback, questions and bugreports should be posted as issues. Pull-requests appreciated!

2.0.0-7

5 years ago

2.0.0-6

5 years ago

0.7.1

5 years ago

2.0.0-5

5 years ago

2.0.0-4

5 years ago

2.0.0-3

5 years ago

2.0.0-2

5 years ago

2.0.0-1

5 years ago

2.0.0-0

5 years ago

1.0.0

5 years ago

0.7.0

6 years ago

0.7.0-4

6 years ago

0.7.0-3

6 years ago

0.7.0-2

6 years ago

0.7.0-1

6 years ago

0.7.0-0

6 years ago

0.6.0

6 years ago

0.6.0-1

6 years ago

0.6.0-0

6 years ago

0.5.1-0

6 years ago

0.5.0

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.3.0-4

6 years ago

0.3.0-3

6 years ago

0.3.0-2

6 years ago

0.3.0-1

6 years ago

0.3.0-0

6 years ago

0.2.1

6 years ago

0.2.1-7

6 years ago

0.2.1-6

6 years ago

0.2.1-5

6 years ago

0.2.1-4

6 years ago

0.2.1-3

6 years ago

0.2.1-2

6 years ago

0.2.1-1

6 years ago

0.2.1-0

6 years ago

0.2.0-0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.1.0-2

6 years ago

0.1.0-1

6 years ago

0.1.0-0

6 years ago

0.0.1

6 years ago