primevue-mirror/src/views/listbox/ListboxDoc.vue

267 lines
11 KiB
Vue
Raw Normal View History

2019-03-25 12:21:45 +00:00
<template>
<div class="content-section documentation">
<TabView>
<TabPanel header="Documentation">
<h3>Import</h3>
<CodeHighlight lang="javascript">
import Listbox from 'primevue/listbox';
</CodeHighlight>
<h3>Getting Started</h3>
2019-05-22 15:20:03 +00:00
<p>Listbox requires a value to bind and a collection of arbitrary objects along with the <i>optionLabel</i> property to specify the label property of the option.</p>
2019-03-25 12:21:45 +00:00
<CodeHighlight>
2019-05-22 16:30:18 +00:00
&lt;Listbox v-model="selectedCity" :options="cities" optionLabel="name" /&gt;
2019-03-25 12:21:45 +00:00
</CodeHighlight>
2019-05-22 15:20:03 +00:00
2019-03-25 12:21:45 +00:00
<CodeHighlight lang="js">
data() {
return {
selectedCity: null,
cities: [
{name: 'New York', code: 'NY'},
{name: 'Rome', code: 'RM'},
{name: 'London', code: 'LDN'},
{name: 'Istanbul', code: 'IST'},
{name: 'Paris', code: 'PRS'}
]
}
}
</CodeHighlight>
<h3>Selection</h3>
<p>Listbox allows selection of either single or multiple items. In single case, model should be a single object reference whereas in multiple case should be an array. Multiple items can either be selected
using metaKey or toggled individually depending on the value of <i>metaKeySelection</i> property value which is true by default. On touch enabled
devices metaKeySelection is turned off automatically.</p>
<CodeHighlight>
2019-05-22 16:30:18 +00:00
&lt;Listbox v-model="selectedCity" :options="cities" optionLabel="name" :multiple="true"/&gt;
2019-03-25 12:21:45 +00:00
</CodeHighlight>
<h3>Custom Content</h3>
2019-05-22 15:20:03 +00:00
<p>Label of an option is used as the display text of an item by default, for custom content support define an <i>option</i> template that gets the option instance as a parameter.</p>
2019-03-25 12:21:45 +00:00
<CodeHighlight>
<template v-pre>
2019-05-22 16:30:18 +00:00
&lt;Listbox v-model="selectedCars" :options="cars" :multiple="true" :filter="true" optionLabel="brand" listStyle="max-height:250px" style="width:15em"&gt;
&lt;template #option="slotProps"&gt;
&lt;div class="p-clearfix"&gt;
2019-05-23 14:51:56 +00:00
&lt;img :alt="slotProps.option.brand" :src="'demo/images/car/' + slotProps.option.brand + '.png'" style="display:inline-block;margin:5px 0 0 5px;width:48px" /&gt;
2019-05-22 16:30:18 +00:00
&lt;span style="float:right;margin:1.25em .5em 0 0"&gt;{{slotProps.option.brand}}&lt;/span&gt;
2019-03-25 12:21:45 +00:00
&lt;/div&gt;
&lt;/template&gt;
&lt;/Listbox&gt;
</template>
</CodeHighlight>
<h3>Filter</h3>
<p>Filtering allows searching items in the list using an input field at the header. In order to use filtering, enable <i>filter</i> property.</p>
<CodeHighlight>
2019-05-22 16:30:18 +00:00
&lt;Listbox v-model="selectedCity" :options="cities" optionLabel="name" :filter="true"/&gt;
2019-03-25 12:21:45 +00:00
</CodeHighlight>
<h3>Properties</h3>
2020-01-13 09:04:50 +00:00
<p>Any property as style and class are passed to the main container element. Following are the additional properties to configure the component.</p>
2019-03-25 12:21:45 +00:00
<div class="doc-tablewrapper">
<table class="doc-table">
<thead>
2019-05-22 15:20:03 +00:00
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
2019-03-25 12:21:45 +00:00
</thead>
<tbody>
2019-05-22 15:20:03 +00:00
<tr>
<td>value</td>
<td>any</td>
<td>null</td>
<td>Value of the component.</td>
</tr>
<tr>
<td>options</td>
<td>array</td>
<td>null</td>
<td>An array of selectitems to display as the available options.</td>
</tr>
<tr>
<td>optionLabel</td>
<td>string</td>
<td>null</td>
<td>Property name to use as the label of an option.</td>
</tr>
<tr>
<td>optionValue</td>
<td>string</td>
<td>null</td>
<td>Property name to use as the value of an option, defaults to the option itself when not defined.</td>
</tr>
<tr>
<td>optionDisabled</td>
<td>boolean</td>
<td>null</td>
<td>Property name to use as the disabled flag of an option, defaults to false when not defined.</td>
</tr>
<tr>
<td>listStyle</td>
<td>string</td>
<td>null</td>
<td>Inline style of inner list element.</td>
</tr>
<tr>
<td>disabled</td>
<td>boolean</td>
<td>false</td>
<td>When specified, disables the component.</td>
</tr>
<tr>
<td>dataKey</td>
<td>string</td>
<td>false</td>
<td>A property to uniquely match the value in options for better performance.</td>
</tr>
<tr>
<td>multiple</td>
<td>boolean</td>
<td>false</td>
<td>When specified, allows selecting multiple values.</td>
</tr>
<tr>
<td>metaKeySelection</td>
<td>boolean</td>
<td>true</td>
<td>Defines how multiple items can be selected, when true metaKey needs to be pressed to select or unselect an item and when set to false selection of each item
can be toggled individually. On touch enabled devices, metaKeySelection is turned off automatically.</td>
</tr>
<tr>
<td>filter</td>
<td>boolean</td>
<td>false</td>
<td>When specified, displays a filter input at header.</td>
</tr>
<tr>
<td>filterLocale</td>
<td>string</td>
<td>undefined</td>
<td>Locale to use in filtering. The default locale is the host environment's current locale.</td>
2019-05-22 15:20:03 +00:00
</tr>
2019-03-25 12:21:45 +00:00
</tbody>
</table>
</div>
<h3>Events</h3>
<div class="doc-tablewrapper">
<table class="doc-table">
<thead>
2019-05-22 15:20:03 +00:00
<tr>
<th>Name</th>
<th>Parameters</th>
<th>Description</th>
</tr>
2019-03-25 12:21:45 +00:00
</thead>
<tbody>
2019-05-22 15:20:03 +00:00
<tr>
<td>change</td>
<td>event.originalEvent: Original event <br />
event.value: Selected option value </td>
<td>Callback to invoke on value change.</td>
</tr>
<tr>
<td>input</td>
<td>value: New value</td>
<td>Callback to invoke on value change.</td>
</tr>
2019-03-25 12:21:45 +00:00
</tbody>
</table>
</div>
<h3>Styling</h3>
<p>Following is the list of structural style classes, for theming classes visit <router-link to="/theming">theming</router-link> page.</p>
<div class="doc-tablewrapper">
<table class="doc-table">
<thead>
2019-05-22 15:20:03 +00:00
<tr>
<th>Name</th>
<th>Element</th>
</tr>
2019-03-25 12:21:45 +00:00
</thead>
<tbody>
2019-05-22 15:20:03 +00:00
<tr>
<td>p-listbox</td>
<td>Main container element.</td>
</tr>
<tr>
<td>p-listbox-header</td>
<td>Header element.</td>
</tr>
<tr>
<td>p-listbox-list-wrapper</td>
<td>Container of list element.</td>
</tr>
<tr>
<td>p-listbox-list</td>
<td>List element.</td>
</tr>
<tr>
<td>p-listbox-item</td>
<td>An item in the list element.</td>
</tr>
2019-03-25 12:21:45 +00:00
</tbody>
</table>
</div>
<h3>Dependencies</h3>
<p>None.</p>
</TabPanel>
<TabPanel header="Source">
<a href="https://github.com/primefaces/primevue/tree/master/src/views/listbox" class="btn-viewsource" target="_blank" rel="noopener noreferrer">
<span>View on GitHub</span>
</a>
<CodeHighlight>
<template v-pre>
2019-08-04 12:19:34 +00:00
&lt;h3&gt;Single&lt;/h3&gt;
&lt;Listbox v-model="selectedCity" :options="cities" optionLabel="name" /&gt;
2019-03-25 12:21:45 +00:00
2019-08-04 12:19:34 +00:00
&lt;h3&gt;Advanced with Templating, Filtering and Multiple Selection&lt;/h3&gt;
&lt;Listbox v-model="selectedCars" :options="cars" :multiple="true" :filter="true" optionLabel="brand" listStyle="max-height:250px" style="width:15em"&gt;
&lt;template #option="slotProps"&gt;
&lt;div class="p-clearfix"&gt;
&lt;img :alt="slotProps.option.brand" :src="'demo/images/car/' + slotProps.option.brand + '.png'" style="display:inline-block;margin:5px 0 0 5px;width:48px" /&gt;
&lt;span style="float:right;margin:1.25em .5em 0 0"&gt;{{slotProps.option.brand}}&lt;/span&gt;
&lt;/div&gt;
&lt;/template&gt;
&lt;/Listbox&gt;
2019-03-25 12:21:45 +00:00
</template>
</CodeHighlight>
<CodeHighlight lang="javascript">
export default {
data() {
return {
selectedCity: null,
selectedCars: null,
cities: [
{name: 'New York', code: 'NY'},
{name: 'Rome', code: 'RM'},
{name: 'London', code: 'LDN'},
{name: 'Istanbul', code: 'IST'},
{name: 'Paris', code: 'PRS'}
],
cars: [
{brand: 'Audi', value: 'Audi'},
2019-07-02 12:59:38 +00:00
{brand: 'BMW', value: 'BMW'},
2019-03-25 12:21:45 +00:00
{brand: 'Fiat', value: 'Fiat'},
{brand: 'Honda', value: 'Honda'},
{brand: 'Jaguar', value: 'Jaguar'},
{brand: 'Mercedes', value: 'Mercedes'},
{brand: 'Renault', value: 'Renault'},
{brand: 'Volkswagen', value: 'Volkswagen'},
{brand: 'Volvo', value: 'Volvo'}
]
}
}
}
</CodeHighlight>
</TabPanel>
</TabView>
</div>
</template>