1
0
mirror of synced 2024-11-22 13:06:08 +03:00

define data format, separate options into multi and single to make them more clear

This commit is contained in:
Igor Vaynberg 2019-06-27 16:48:13 -07:00
parent 6c00b633fc
commit 767d01984b
11 changed files with 411 additions and 426 deletions

1
.ignore Normal file
View File

@ -0,0 +1 @@
dist/*

View File

@ -1,6 +1,6 @@
/** jsx:pragma h */ /** jsx:pragma h */
import { Component, h, render } from 'preact'; import { Component, h, render } from 'preact';
import { ItemRenderer, QueryFunction } from '../../control/src/abstract-select'; import { DataItem, DataItemRenderer, QueryFunction } from '../../control/src/abstract-select';
import { Dictionary } from '../../control/src/dictionary'; import { Dictionary } from '../../control/src/dictionary';
import { MultiSelect } from '../../control/src/multi-select'; import { MultiSelect } from '../../control/src/multi-select';
import '../../control/src/select25.scss'; import '../../control/src/select25.scss';
@ -16,16 +16,12 @@ enum StoreKeys {
targetElement = 'te' targetElement = 'te'
} }
export interface Options { interface BaseSelectOptions {
multiple: boolean;
containerStyle?: string; containerStyle?: string;
containerClass?: string; containerClass?: string;
hiddenValue?: (values: any, options: Options) => string;
tabIndex?: number; tabIndex?: number;
itemId: ((item: any) => string) | string; valueContent?: DataItemRenderer;
itemLabel: ((item: any) => string) | string; resultContent?: DataItemRenderer;
valueContent?: ItemRenderer;
resultContent?: ItemRenderer;
query?: QueryFunction; query?: QueryFunction;
data?: DataFunction; data?: DataFunction;
ajax?: Ajax; ajax?: Ajax;
@ -33,55 +29,50 @@ export interface Options {
minimumCharacters?: number; minimumCharacters?: number;
openOnFocus?: boolean; openOnFocus?: boolean;
dictionary?: string | Dictionary; dictionary?: string | Dictionary;
value: any;
values: any[];
allowClear?: boolean;
placeholder?: string;
/** Single Select Label */
label?: string;
/** Multi Select Selected Values Listbox Label */
valuesLabel?: string;
/** Multi Select Add Value Combobox Label */
comboboxLabel?: string;
allowDuplicates: boolean;
} }
const DEFAULT_OPTIONS = { interface MultiSelectOptions extends BaseSelectOptions {
allowClear: false, hiddenValue?: (values: DataItem[], options: MultiSelectOptions) => string;
dictionary: 'en_us', valuesLabel?: string;
hiddenValue: (values: any, options: Options) => { comboboxLabel?: string;
const id = (item: any) => { allowDuplicates: boolean;
if (typeof options.itemId === 'function') { values: DataItem[];
return options.itemId(item); }
} else {
return '' + item[options.itemId];
}
};
if (values) { interface SingleSelectOptions extends BaseSelectOptions {
if (Array.isArray(values)) { hiddenValue?: (value: DataItem, options: SingleSelectOptions) => string;
if (values.length > 0) { label?: string;
return values.map(id).join(','); value: DataItem;
} else { allowClear?: boolean;
return ''; placeholder?: string;
} }
} else {
return id(values); const BASE_DEFAULT_OPTIONS = {
} dictionary: 'en_us',
minimumCharacters: 0,
openOnFocus: false
};
const DEFAULT_MULTI_SELECT_OPTIONS = extend({}, BASE_DEFAULT_OPTIONS, {
hiddenValue: (values: DataItem[], options: MultiSelectOptions) => {
if (values && values.length > 0) {
return values.map(item => item.id).join(',');
} else { } else {
return ''; return '';
} }
}, }
itemId: 'id', });
itemLabel: 'text',
minimumCharacters: 0, const DEFAULT_SINGLE_SELECT_OPTIONS = extend({}, BASE_DEFAULT_OPTIONS, {
multiple: false, allowClear: false,
openOnFocus: false hiddenValue: (value: DataItem, options: SingleSelectOptions) => {
}; if (value) {
return value.id;
} else {
return '';
}
}
});
function triggerOnChange(element: HTMLElement, data: any) { function triggerOnChange(element: HTMLElement, data: any) {
const event = document.createEvent('HTMLEvents'); const event = document.createEvent('HTMLEvents');
@ -93,13 +84,13 @@ function triggerOnChange(element: HTMLElement, data: any) {
class MultiSelectWrapper extends Component< class MultiSelectWrapper extends Component<
{ {
element: HTMLInputElement; element: HTMLInputElement;
options: Options; options: MultiSelectOptions;
}, },
{ values: any } { values?: DataItem[] }
> { > {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { values: props.options.values }; this.state = { values: props.options.values || [] };
} }
public componentDidUpdate() { public componentDidUpdate() {
@ -118,8 +109,6 @@ class MultiSelectWrapper extends Component<
containerStyle={opts.containerStyle} containerStyle={opts.containerStyle}
valuesLabel={opts.valuesLabel} valuesLabel={opts.valuesLabel}
comboboxLabel={opts.comboboxLabel} comboboxLabel={opts.comboboxLabel}
itemId={opts.itemId}
itemLabel={opts.itemLabel}
valueContent={opts.valueContent} valueContent={opts.valueContent}
resultContent={opts.resultContent} resultContent={opts.resultContent}
query={opts.query} query={opts.query}
@ -149,10 +138,10 @@ class MultiSelectWrapper extends Component<
class SingleSelectWrapper extends Component< class SingleSelectWrapper extends Component<
{ {
options: Options; options: SingleSelectOptions;
element: HTMLInputElement; element: HTMLInputElement;
}, },
{ value: any } { value?: DataItem }
> { > {
constructor(props) { constructor(props) {
super(props); super(props);
@ -172,13 +161,10 @@ class SingleSelectWrapper extends Component<
return ( return (
<SingleSelect <SingleSelect
label={opts.label} label={opts.label}
comboboxLabel={opts.comboboxLabel}
containerClass={opts.containerClass} containerClass={opts.containerClass}
containerStyle={opts.containerStyle} containerStyle={opts.containerStyle}
allowClear={opts.allowClear} allowClear={opts.allowClear}
placeholder={opts.placeholder} placeholder={opts.placeholder}
itemId={opts.itemId}
itemLabel={opts.itemLabel}
valueContent={opts.valueContent} valueContent={opts.valueContent}
resultContent={opts.resultContent} resultContent={opts.resultContent}
query={opts.query} query={opts.query}
@ -187,31 +173,55 @@ class SingleSelectWrapper extends Component<
openOnFocus={opts.openOnFocus} // TODO openOnFocus={opts.openOnFocus} // TODO
dictionary={opts.dictionary} dictionary={opts.dictionary}
tabIndex={opts.tabIndex} tabIndex={opts.tabIndex}
allowDuplicates={opts.allowDuplicates}
value={this.state.value} value={this.state.value}
onChange={this.onChange} onChange={this.onChange}
/> />
); );
} }
public onChange = (value: any) => { public onChange = (value: DataItem) => {
this.setState({ value }); this.setState({ value });
this.setHiddenValue(value); this.setHiddenValue(value);
triggerOnChange(this.props.element, value); triggerOnChange(this.props.element, value);
}; };
private setHiddenValue(value: any) { private setHiddenValue(value: DataItem) {
const { element, options } = this.props; const { element, options } = this.props;
element.value = options.hiddenValue(value, options); element.value = options.hiddenValue(value, options);
} }
} }
function create<T>(element: HTMLInputElement, options: Options) { function createSingleSelect(element: HTMLInputElement, options: SingleSelectOptions) {
// TODO make sure we are attached to hidden input options = extend({}, DEFAULT_SINGLE_SELECT_OPTIONS, options);
fillBaseOptions(element, options);
const store = Store.getStore(element); const store = Store.getStore(element);
options = extend({}, DEFAULT_OPTIONS, options); // create placeholder element into which the control will be rendered
const parentElement = element.parentElement;
const targetElement = document.createElement('div');
parentElement.insertBefore(targetElement, element);
store.set(StoreKeys.targetElement, targetElement);
render(<SingleSelectWrapper element={element} options={options} />, parentElement, targetElement);
}
function createMultiSelect(element: HTMLInputElement, options: SingleSelectOptions) {
options = extend({}, DEFAULT_SINGLE_SELECT_OPTIONS, options);
fillBaseOptions(element, options);
const store = Store.getStore(element);
// create placeholder element into which the control will be rendered
const parentElement = element.parentElement;
const targetElement = document.createElement('div');
parentElement.insertBefore(targetElement, element);
store.set(StoreKeys.targetElement, targetElement);
render(<MultiSelectWrapper element={element} options={options} />, parentElement, targetElement);
}
function fillBaseOptions(element: HTMLInputElement, options: BaseSelectOptions) {
if (!options.query) { if (!options.query) {
if (options.ajax) { if (options.ajax) {
options.query = createQueryFromAjax(options.ajax); options.query = createQueryFromAjax(options.ajax);
@ -241,20 +251,6 @@ function create<T>(element: HTMLInputElement, options: Options) {
clazz += element.getAttribute('data-s25-container-class'); clazz += element.getAttribute('data-s25-container-class');
options.containerClass = clazz; options.containerClass = clazz;
} }
// create placeholder element into which the control will be rendered
const parentElement = element.parentElement;
const targetElement = document.createElement('div');
parentElement.insertBefore(targetElement, element);
store.set(StoreKeys.targetElement, targetElement);
// render the replacement
if (options.multiple) {
render(<MultiSelectWrapper element={element} options={options} />, parentElement, targetElement);
} else {
render(<SingleSelectWrapper element={element} options={options} />, parentElement, targetElement);
}
} }
function destroy(element: HTMLElement) { function destroy(element: HTMLElement) {
@ -270,7 +266,8 @@ function destroy(element: HTMLElement) {
} }
const select25 = { const select25 = {
create, createMultiSelect,
createSingleSelect,
destroy destroy
}; };

View File

@ -6,12 +6,17 @@ const forceImportOfH = h;
type ToString = (item: any) => string; type ToString = (item: any) => string;
export type ItemRenderer = (string) | ((item: any, h: typeof createElement) => ComponentChild); export type DataItemRenderer = (string) | ((item: any, h: typeof createElement) => ComponentChild);
export type QueryFunction = (search: string, page: number, token: string) => Promise<QueryResult>; export type QueryFunction = (search: string, page: number, token: string) => Promise<QueryResult>;
export interface DataItem {
id: any;
text: string;
}
export interface QueryResult { export interface QueryResult {
values: any[]; values: DataItem[];
more: boolean; more: boolean;
token: string; token: string;
} }
@ -38,10 +43,8 @@ export interface Props {
containerStyle?: string; containerStyle?: string;
containerClass?: string; containerClass?: string;
tabIndex?: number; tabIndex?: number;
itemId: ToString | string; valueContent?: DataItemRenderer;
itemLabel: ToString | string; resultContent?: DataItemRenderer;
valueContent?: ItemRenderer;
resultContent?: ItemRenderer;
query: QueryFunction; query: QueryFunction;
quiet?: number; quiet?: number;
@ -57,8 +60,6 @@ function MarkupRenderer({ markup }) {
export const DEFAULT_PROPS: Partial<Props> = { export const DEFAULT_PROPS: Partial<Props> = {
allowDuplicates: false, allowDuplicates: false,
itemId: 'id',
itemLabel: 'text',
minimumCharacters: 0, minimumCharacters: 0,
quiet: 50, quiet: 50,
tabIndex: 0 tabIndex: 0
@ -91,34 +92,25 @@ export abstract class AbstractSelect<P extends Props, S extends State> extends C
}; };
} }
public getItemId = (item: any): string => { public getItemId = (item: DataItem): string => {
const id = this.props.itemId; return item.id;
if (typeof id === 'function') {
return (id as ToString)(item);
} else {
return '' + item[id];
}
}; };
public getItemLabel = (item: any): string => { public getItemLabel = (item: DataItem): string => {
const label = this.props.itemLabel; const label = item.text;
if (typeof label === 'function') { return item.text;
return (label as ToString)(item);
} else {
return '' + item[label];
}
}; };
public renderValue = (item: any): ComponentChild => { public renderValue = (item: DataItem): ComponentChild => {
return this.renderItem(item, 'valueContent'); return this.renderItem(item, 'valueContent');
}; };
public renderResult = (item: any): ComponentChild => { public renderResult = (item: DataItem): ComponentChild => {
return this.renderItem(item, 'resultContent'); return this.renderItem(item, 'resultContent');
}; };
private renderItem = (item: any, rendererName: keyof Props): ComponentChild => { private renderItem = (item: DataItem, rendererName: (keyof Props) & DataItemRenderer): ComponentChild => {
const renderer = this.props[rendererName] as ItemRenderer; const renderer = this.props[rendererName] as DataItemRenderer;
if (renderer) { if (renderer) {
if (typeof renderer === 'function') { if (typeof renderer === 'function') {
const render = renderer(item, createElement); const render = renderer(item, createElement);

View File

@ -1,6 +1,7 @@
import { createRef, Fragment, h, RefObject } from 'preact'; import { createRef, Fragment, h, RefObject } from 'preact';
import { import {
AbstractSelect, AbstractSelect,
DataItem,
DEFAULT_PROPS as ABSTRACT_DEFAULT_PROPS, DEFAULT_PROPS as ABSTRACT_DEFAULT_PROPS,
Props as SearchControllerProps, Props as SearchControllerProps,
State as AbstractSelectState State as AbstractSelectState
@ -17,8 +18,8 @@ const forceImportOfH = h;
export interface Props extends SearchControllerProps { export interface Props extends SearchControllerProps {
valuesLabel: string; valuesLabel: string;
comboboxLabel: string; comboboxLabel: string;
values: any[]; values: DataItem[];
onChange: (values: any[]) => void; onChange: (values: DataItem[]) => void;
} }
interface ValueListState { interface ValueListState {
@ -115,7 +116,7 @@ export class MultiSelect extends AbstractSelect<Props, State> {
onBlur={this.onValuesBlur} onBlur={this.onValuesBlur}
onKeyDown={this.onValuesKeyDown} onKeyDown={this.onValuesKeyDown}
> >
{values.map((value: any, index: number) => { {values.map((value: DataItem, index: number) => {
const isSelected = selected[index]; const isSelected = selected[index];
const isActive = active === index; const isActive = active === index;
const css = cn(style.item, { const css = cn(style.item, {

View File

@ -35,14 +35,14 @@ exports[`MultiSelect renders with values 1`] = `
<div class="s25-multi-values" tabIndex="0" <div class="s25-multi-values" tabIndex="0"
role="listbox" aria-orientation="vertical" aria-multiselectable="true" role="listbox" aria-orientation="vertical" aria-multiselectable="true"
aria-label="Selected Values" aria-describedby="s25-1-instructions"> aria-label="Selected Values" aria-describedby="s25-1-instructions">
<div id="s25-1-vl-0" class="s25-item" role="option" aria-label="undefined"> <div id="s25-1-vl-0" class="s25-item" role="option" aria-label="United States">
<div class="s25-content"> <div class="s25-content">
<MarkupRenderer markup="undefined"></MarkupRenderer> <MarkupRenderer markup="United States"></MarkupRenderer>
</div> </div>
</div> </div>
<div id="s25-1-vl-1" class="s25-item" role="option" aria-label="undefined"> <div id="s25-1-vl-1" class="s25-item" role="option" aria-label="Mexico">
<div class="s25-content"> <div class="s25-content">
<MarkupRenderer markup="undefined"></MarkupRenderer> <MarkupRenderer markup="Mexico"></MarkupRenderer>
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,245 +1,245 @@
export const countries = [ export const countries = [
{ name: 'United States', code: 'US' }, { text: 'United States', id: 'US' },
{ name: 'Mexico', code: 'MX' }, { text: 'Mexico', id: 'MX' },
{ name: 'Afghanistan', code: 'AF' }, { text: 'Afghanistan', id: 'AF' },
{ name: 'Aland Islands', code: 'AX' }, { text: 'Aland Islands', id: 'AX' },
{ name: 'Albania', code: 'AL' }, { text: 'Albania', id: 'AL' },
{ name: 'Algeria', code: 'DZ' }, { text: 'Algeria', id: 'DZ' },
{ name: 'American Samoa', code: 'AS' }, { text: 'American Samoa', id: 'AS' },
{ name: 'Andorra', code: 'AD' }, { text: 'Andorra', id: 'AD' },
{ name: 'Angola', code: 'AO' }, { text: 'Angola', id: 'AO' },
{ name: 'Anguilla', code: 'AI' }, { text: 'Anguilla', id: 'AI' },
{ name: 'Antarctica', code: 'AQ' }, { text: 'Antarctica', id: 'AQ' },
{ name: 'Antigua and Barbuda', code: 'AG' }, { text: 'Antigua and Barbuda', id: 'AG' },
{ name: 'Argentina', code: 'AR' }, { text: 'Argentina', id: 'AR' },
{ name: 'Armenia', code: 'AM' }, { text: 'Armenia', id: 'AM' },
{ name: 'Aruba', code: 'AW' }, { text: 'Aruba', id: 'AW' },
{ name: 'Australia', code: 'AU' }, { text: 'Australia', id: 'AU' },
{ name: 'Austria', code: 'AT' }, { text: 'Austria', id: 'AT' },
{ name: 'Azerbaijan', code: 'AZ' }, { text: 'Azerbaijan', id: 'AZ' },
{ name: 'Bahamas', code: 'BS' }, { text: 'Bahamas', id: 'BS' },
{ name: 'Bahrain', code: 'BH' }, { text: 'Bahrain', id: 'BH' },
{ name: 'Bangladesh', code: 'BD' }, { text: 'Bangladesh', id: 'BD' },
{ name: 'Barbados', code: 'BB' }, { text: 'Barbados', id: 'BB' },
{ name: 'Belarus', code: 'BY' }, { text: 'Belarus', id: 'BY' },
{ name: 'Belgium', code: 'BE' }, { text: 'Belgium', id: 'BE' },
{ name: 'Belize', code: 'BZ' }, { text: 'Belize', id: 'BZ' },
{ name: 'Benin', code: 'BJ' }, { text: 'Benin', id: 'BJ' },
{ name: 'Bermuda', code: 'BM' }, { text: 'Bermuda', id: 'BM' },
{ name: 'Bhutan', code: 'BT' }, { text: 'Bhutan', id: 'BT' },
{ name: 'Bolivia', code: 'BO' }, { text: 'Bolivia', id: 'BO' },
{ name: 'Bosnia and Herzegovina', code: 'BA' }, { text: 'Bosnia and Herzegovina', id: 'BA' },
{ name: 'Botswana', code: 'BW' }, { text: 'Botswana', id: 'BW' },
{ name: 'Bouvet Island', code: 'BV' }, { text: 'Bouvet Island', id: 'BV' },
{ name: 'Brazil', code: 'BR' }, { text: 'Brazil', id: 'BR' },
{ name: 'British Indian Ocean Territory', code: 'IO' }, { text: 'British Indian Ocean Territory', id: 'IO' },
{ name: 'Brunei Darussalam', code: 'BN' }, { text: 'Brunei Darussalam', id: 'BN' },
{ name: 'Bulgaria', code: 'BG' }, { text: 'Bulgaria', id: 'BG' },
{ name: 'Burkina Faso', code: 'BF' }, { text: 'Burkina Faso', id: 'BF' },
{ name: 'Burundi', code: 'BI' }, { text: 'Burundi', id: 'BI' },
{ name: 'Cambodia', code: 'KH' }, { text: 'Cambodia', id: 'KH' },
{ name: 'Cameroon', code: 'CM' }, { text: 'Cameroon', id: 'CM' },
{ name: 'Canada', code: 'CA' }, { text: 'Canada', id: 'CA' },
{ name: 'Cape Verde', code: 'CV' }, { text: 'Cape Verde', id: 'CV' },
{ name: 'Cayman Islands', code: 'KY' }, { text: 'Cayman Islands', id: 'KY' },
{ name: 'Central African Republic', code: 'CF' }, { text: 'Central African Republic', id: 'CF' },
{ name: 'Chad', code: 'TD' }, { text: 'Chad', id: 'TD' },
{ name: 'Chile', code: 'CL' }, { text: 'Chile', id: 'CL' },
{ name: 'China', code: 'CN' }, { text: 'China', id: 'CN' },
{ name: 'Christmas Island', code: 'CX' }, { text: 'Christmas Island', id: 'CX' },
{ name: 'Cocos (Keeling) Islands', code: 'CC' }, { text: 'Cocos (Keeling) Islands', id: 'CC' },
{ name: 'Colombia', code: 'CO' }, { text: 'Colombia', id: 'CO' },
{ name: 'Comoros', code: 'KM' }, { text: 'Comoros', id: 'KM' },
{ name: 'Congo', code: 'CG' }, { text: 'Congo', id: 'CG' },
{ name: 'Congo, The Democratic Republic of the', code: 'CD' }, { text: 'Congo, The Democratic Republic of the', id: 'CD' },
{ name: 'Cook Islands', code: 'CK' }, { text: 'Cook Islands', id: 'CK' },
{ name: 'Costa Rica', code: 'CR' }, { text: 'Costa Rica', id: 'CR' },
{ name: "Cote D'Ivoire", code: 'CI' }, { text: "Cote D'Ivoire", id: 'CI' },
{ name: 'Croatia', code: 'HR' }, { text: 'Croatia', id: 'HR' },
{ name: 'Cuba', code: 'CU' }, { text: 'Cuba', id: 'CU' },
{ name: 'Cyprus', code: 'CY' }, { text: 'Cyprus', id: 'CY' },
{ name: 'Czech Republic', code: 'CZ' }, { text: 'Czech Republic', id: 'CZ' },
{ name: 'Denmark', code: 'DK' }, { text: 'Denmark', id: 'DK' },
{ name: 'Djibouti', code: 'DJ' }, { text: 'Djibouti', id: 'DJ' },
{ name: 'Dominica', code: 'DM' }, { text: 'Dominica', id: 'DM' },
{ name: 'Dominican Republic', code: 'DO' }, { text: 'Dominican Republic', id: 'DO' },
{ name: 'Ecuador', code: 'EC' }, { text: 'Ecuador', id: 'EC' },
{ name: 'Egypt', code: 'EG' }, { text: 'Egypt', id: 'EG' },
{ name: 'El Salvador', code: 'SV' }, { text: 'El Salvador', id: 'SV' },
{ name: 'Equatorial Guinea', code: 'GQ' }, { text: 'Equatorial Guinea', id: 'GQ' },
{ name: 'Eritrea', code: 'ER' }, { text: 'Eritrea', id: 'ER' },
{ name: 'Estonia', code: 'EE' }, { text: 'Estonia', id: 'EE' },
{ name: 'Ethiopia', code: 'ET' }, { text: 'Ethiopia', id: 'ET' },
{ name: 'Falkland Islands (Malvinas)', code: 'FK' }, { text: 'Falkland Islands (Malvinas)', id: 'FK' },
{ name: 'Faroe Islands', code: 'FO' }, { text: 'Faroe Islands', id: 'FO' },
{ name: 'Fiji', code: 'FJ' }, { text: 'Fiji', id: 'FJ' },
{ name: 'Finland', code: 'FI' }, { text: 'Finland', id: 'FI' },
{ name: 'France', code: 'FR' }, { text: 'France', id: 'FR' },
{ name: 'French Guiana', code: 'GF' }, { text: 'French Guiana', id: 'GF' },
{ name: 'French Polynesia', code: 'PF' }, { text: 'French Polynesia', id: 'PF' },
{ name: 'French Southern Territories', code: 'TF' }, { text: 'French Southern Territories', id: 'TF' },
{ name: 'Gabon', code: 'GA' }, { text: 'Gabon', id: 'GA' },
{ name: 'Gambia', code: 'GM' }, { text: 'Gambia', id: 'GM' },
{ name: 'Georgia', code: 'GE' }, { text: 'Georgia', id: 'GE' },
{ name: 'Germany', code: 'DE' }, { text: 'Germany', id: 'DE' },
{ name: 'Ghana', code: 'GH' }, { text: 'Ghana', id: 'GH' },
{ name: 'Gibraltar', code: 'GI' }, { text: 'Gibraltar', id: 'GI' },
{ name: 'Greece', code: 'GR' }, { text: 'Greece', id: 'GR' },
{ name: 'Greenland', code: 'GL' }, { text: 'Greenland', id: 'GL' },
{ name: 'Grenada', code: 'GD' }, { text: 'Grenada', id: 'GD' },
{ name: 'Guadeloupe', code: 'GP' }, { text: 'Guadeloupe', id: 'GP' },
{ name: 'Guam', code: 'GU' }, { text: 'Guam', id: 'GU' },
{ name: 'Guatemala', code: 'GT' }, { text: 'Guatemala', id: 'GT' },
{ name: 'Guernsey', code: 'GG' }, { text: 'Guernsey', id: 'GG' },
{ name: 'Guinea', code: 'GN' }, { text: 'Guinea', id: 'GN' },
{ name: 'Guinea-Bissau', code: 'GW' }, { text: 'Guinea-Bissau', id: 'GW' },
{ name: 'Guyana', code: 'GY' }, { text: 'Guyana', id: 'GY' },
{ name: 'Haiti', code: 'HT' }, { text: 'Haiti', id: 'HT' },
{ name: 'Heard Island and Mcdonald Islands', code: 'HM' }, { text: 'Heard Island and Mcdonald Islands', id: 'HM' },
{ name: 'Holy See (Vatican City State)', code: 'VA' }, { text: 'Holy See (Vatican City State)', id: 'VA' },
{ name: 'Honduras', code: 'HN' }, { text: 'Honduras', id: 'HN' },
{ name: 'Hong Kong', code: 'HK' }, { text: 'Hong Kong', id: 'HK' },
{ name: 'Hungary', code: 'HU' }, { text: 'Hungary', id: 'HU' },
{ name: 'Iceland', code: 'IS' }, { text: 'Iceland', id: 'IS' },
{ name: 'India', code: 'IN' }, { text: 'India', id: 'IN' },
{ name: 'Indonesia', code: 'ID' }, { text: 'Indonesia', id: 'ID' },
{ name: 'Iran, Islamic Republic Of', code: 'IR' }, { text: 'Iran, Islamic Republic Of', id: 'IR' },
{ name: 'Iraq', code: 'IQ' }, { text: 'Iraq', id: 'IQ' },
{ name: 'Ireland', code: 'IE' }, { text: 'Ireland', id: 'IE' },
{ name: 'Isle of Man', code: 'IM' }, { text: 'Isle of Man', id: 'IM' },
{ name: 'Israel', code: 'IL' }, { text: 'Israel', id: 'IL' },
{ name: 'Italy', code: 'IT' }, { text: 'Italy', id: 'IT' },
{ name: 'Jamaica', code: 'JM' }, { text: 'Jamaica', id: 'JM' },
{ name: 'Japan', code: 'JP' }, { text: 'Japan', id: 'JP' },
{ name: 'Jersey', code: 'JE' }, { text: 'Jersey', id: 'JE' },
{ name: 'Jordan', code: 'JO' }, { text: 'Jordan', id: 'JO' },
{ name: 'Kazakhstan', code: 'KZ' }, { text: 'Kazakhstan', id: 'KZ' },
{ name: 'Kenya', code: 'KE' }, { text: 'Kenya', id: 'KE' },
{ name: 'Kiribati', code: 'KI' }, { text: 'Kiribati', id: 'KI' },
{ name: "Korea, Democratic People'S Republic of", code: 'KP' }, { text: "Korea, Democratic People'S Republic of", id: 'KP' },
{ name: 'Korea, Republic of', code: 'KR' }, { text: 'Korea, Republic of', id: 'KR' },
{ name: 'Kuwait', code: 'KW' }, { text: 'Kuwait', id: 'KW' },
{ name: 'Kyrgyzstan', code: 'KG' }, { text: 'Kyrgyzstan', id: 'KG' },
{ name: "Lao People'S Democratic Republic", code: 'LA' }, { text: "Lao People'S Democratic Republic", id: 'LA' },
{ name: 'Latvia', code: 'LV' }, { text: 'Latvia', id: 'LV' },
{ name: 'Lebanon', code: 'LB' }, { text: 'Lebanon', id: 'LB' },
{ name: 'Lesotho', code: 'LS' }, { text: 'Lesotho', id: 'LS' },
{ name: 'Liberia', code: 'LR' }, { text: 'Liberia', id: 'LR' },
{ name: 'Libyan Arab Jamahiriya', code: 'LY' }, { text: 'Libyan Arab Jamahiriya', id: 'LY' },
{ name: 'Liechtenstein', code: 'LI' }, { text: 'Liechtenstein', id: 'LI' },
{ name: 'Lithuania', code: 'LT' }, { text: 'Lithuania', id: 'LT' },
{ name: 'Luxembourg', code: 'LU' }, { text: 'Luxembourg', id: 'LU' },
{ name: 'Macao', code: 'MO' }, { text: 'Macao', id: 'MO' },
{ name: 'Macedonia, The Former Yugoslav Republic of', code: 'MK' }, { text: 'Macedonia, The Former Yugoslav Republic of', id: 'MK' },
{ name: 'Madagascar', code: 'MG' }, { text: 'Madagascar', id: 'MG' },
{ name: 'Malawi', code: 'MW' }, { text: 'Malawi', id: 'MW' },
{ name: 'Malaysia', code: 'MY' }, { text: 'Malaysia', id: 'MY' },
{ name: 'Maldives', code: 'MV' }, { text: 'Maldives', id: 'MV' },
{ name: 'Mali', code: 'ML' }, { text: 'Mali', id: 'ML' },
{ name: 'Malta', code: 'MT' }, { text: 'Malta', id: 'MT' },
{ name: 'Marshall Islands', code: 'MH' }, { text: 'Marshall Islands', id: 'MH' },
{ name: 'Martinique', code: 'MQ' }, { text: 'Martinique', id: 'MQ' },
{ name: 'Mauritania', code: 'MR' }, { text: 'Mauritania', id: 'MR' },
{ name: 'Mauritius', code: 'MU' }, { text: 'Mauritius', id: 'MU' },
{ name: 'Mayotte', code: 'YT' }, { text: 'Mayotte', id: 'YT' },
{ name: 'Micronesia, Federated States of', code: 'FM' }, { text: 'Micronesia, Federated States of', id: 'FM' },
{ name: 'Moldova, Republic of', code: 'MD' }, { text: 'Moldova, Republic of', id: 'MD' },
{ name: 'Monaco', code: 'MC' }, { text: 'Monaco', id: 'MC' },
{ name: 'Mongolia', code: 'MN' }, { text: 'Mongolia', id: 'MN' },
{ name: 'Montserrat', code: 'MS' }, { text: 'Montserrat', id: 'MS' },
{ name: 'Morocco', code: 'MA' }, { text: 'Morocco', id: 'MA' },
{ name: 'Mozambique', code: 'MZ' }, { text: 'Mozambique', id: 'MZ' },
{ name: 'Myanmar', code: 'MM' }, { text: 'Myanmar', id: 'MM' },
{ name: 'Namibia', code: 'NA' }, { text: 'Namibia', id: 'NA' },
{ name: 'Nauru', code: 'NR' }, { text: 'Nauru', id: 'NR' },
{ name: 'Nepal', code: 'NP' }, { text: 'Nepal', id: 'NP' },
{ name: 'Netherlands', code: 'NL' }, { text: 'Netherlands', id: 'NL' },
{ name: 'Netherlands Antilles', code: 'AN' }, { text: 'Netherlands Antilles', id: 'AN' },
{ name: 'New Caledonia', code: 'NC' }, { text: 'New Caledonia', id: 'NC' },
{ name: 'New Zealand', code: 'NZ' }, { text: 'New Zealand', id: 'NZ' },
{ name: 'Nicaragua', code: 'NI' }, { text: 'Nicaragua', id: 'NI' },
{ name: 'Niger', code: 'NE' }, { text: 'Niger', id: 'NE' },
{ name: 'Nigeria', code: 'NG' }, { text: 'Nigeria', id: 'NG' },
{ name: 'Niue', code: 'NU' }, { text: 'Niue', id: 'NU' },
{ name: 'Norfolk Island', code: 'NF' }, { text: 'Norfolk Island', id: 'NF' },
{ name: 'Northern Mariana Islands', code: 'MP' }, { text: 'Northern Mariana Islands', id: 'MP' },
{ name: 'Norway', code: 'NO' }, { text: 'Norway', id: 'NO' },
{ name: 'Oman', code: 'OM' }, { text: 'Oman', id: 'OM' },
{ name: 'Pakistan', code: 'PK' }, { text: 'Pakistan', id: 'PK' },
{ name: 'Palau', code: 'PW' }, { text: 'Palau', id: 'PW' },
{ name: 'Palestinian Territory, Occupied', code: 'PS' }, { text: 'Palestinian Territory, Occupied', id: 'PS' },
{ name: 'Panama', code: 'PA' }, { text: 'Panama', id: 'PA' },
{ name: 'Papua New Guinea', code: 'PG' }, { text: 'Papua New Guinea', id: 'PG' },
{ name: 'Paraguay', code: 'PY' }, { text: 'Paraguay', id: 'PY' },
{ name: 'Peru', code: 'PE' }, { text: 'Peru', id: 'PE' },
{ name: 'Philippines', code: 'PH' }, { text: 'Philippines', id: 'PH' },
{ name: 'Pitcairn', code: 'PN' }, { text: 'Pitcairn', id: 'PN' },
{ name: 'Poland', code: 'PL' }, { text: 'Poland', id: 'PL' },
{ name: 'Portugal', code: 'PT' }, { text: 'Portugal', id: 'PT' },
{ name: 'Puerto Rico', code: 'PR' }, { text: 'Puerto Rico', id: 'PR' },
{ name: 'Qatar', code: 'QA' }, { text: 'Qatar', id: 'QA' },
{ name: 'Reunion', code: 'RE' }, { text: 'Reunion', id: 'RE' },
{ name: 'Romania', code: 'RO' }, { text: 'Romania', id: 'RO' },
{ name: 'Russian Federation', code: 'RU' }, { text: 'Russian Federation', id: 'RU' },
{ name: 'RWANDA', code: 'RW' }, { text: 'RWANDA', id: 'RW' },
{ name: 'Saint Helena', code: 'SH' }, { text: 'Saint Helena', id: 'SH' },
{ name: 'Saint Kitts and Nevis', code: 'KN' }, { text: 'Saint Kitts and Nevis', id: 'KN' },
{ name: 'Saint Lucia', code: 'LC' }, { text: 'Saint Lucia', id: 'LC' },
{ name: 'Saint Pierre and Miquelon', code: 'PM' }, { text: 'Saint Pierre and Miquelon', id: 'PM' },
{ name: 'Saint Vincent and the Grenadines', code: 'VC' }, { text: 'Saint Vincent and the Grenadines', id: 'VC' },
{ name: 'Samoa', code: 'WS' }, { text: 'Samoa', id: 'WS' },
{ name: 'San Marino', code: 'SM' }, { text: 'San Marino', id: 'SM' },
{ name: 'Sao Tome and Principe', code: 'ST' }, { text: 'Sao Tome and Principe', id: 'ST' },
{ name: 'Saudi Arabia', code: 'SA' }, { text: 'Saudi Arabia', id: 'SA' },
{ name: 'Senegal', code: 'SN' }, { text: 'Senegal', id: 'SN' },
{ name: 'Serbia and Montenegro', code: 'CS' }, { text: 'Serbia and Montenegro', id: 'CS' },
{ name: 'Seychelles', code: 'SC' }, { text: 'Seychelles', id: 'SC' },
{ name: 'Sierra Leone', code: 'SL' }, { text: 'Sierra Leone', id: 'SL' },
{ name: 'Singapore', code: 'SG' }, { text: 'Singapore', id: 'SG' },
{ name: 'Slovakia', code: 'SK' }, { text: 'Slovakia', id: 'SK' },
{ name: 'Slovenia', code: 'SI' }, { text: 'Slovenia', id: 'SI' },
{ name: 'Solomon Islands', code: 'SB' }, { text: 'Solomon Islands', id: 'SB' },
{ name: 'Somalia', code: 'SO' }, { text: 'Somalia', id: 'SO' },
{ name: 'South Africa', code: 'ZA' }, { text: 'South Africa', id: 'ZA' },
{ name: 'South Georgia and the South Sandwich Islands', code: 'GS' }, { text: 'South Georgia and the South Sandwich Islands', id: 'GS' },
{ name: 'Spain', code: 'ES' }, { text: 'Spain', id: 'ES' },
{ name: 'Sri Lanka', code: 'LK' }, { text: 'Sri Lanka', id: 'LK' },
{ name: 'Sudan', code: 'SD' }, { text: 'Sudan', id: 'SD' },
{ name: 'Suriname', code: 'SR' }, { text: 'Suriname', id: 'SR' },
{ name: 'Svalbard and Jan Mayen', code: 'SJ' }, { text: 'Svalbard and Jan Mayen', id: 'SJ' },
{ name: 'Swaziland', code: 'SZ' }, { text: 'Swaziland', id: 'SZ' },
{ name: 'Sweden', code: 'SE' }, { text: 'Sweden', id: 'SE' },
{ name: 'Switzerland', code: 'CH' }, { text: 'Switzerland', id: 'CH' },
{ name: 'Syrian Arab Republic', code: 'SY' }, { text: 'Syrian Arab Republic', id: 'SY' },
{ name: 'Taiwan, Province of China', code: 'TW' }, { text: 'Taiwan, Province of China', id: 'TW' },
{ name: 'Tajikistan', code: 'TJ' }, { text: 'Tajikistan', id: 'TJ' },
{ name: 'Tanzania, United Republic of', code: 'TZ' }, { text: 'Tanzania, United Republic of', id: 'TZ' },
{ name: 'Thailand', code: 'TH' }, { text: 'Thailand', id: 'TH' },
{ name: 'Timor-Leste', code: 'TL' }, { text: 'Timor-Leste', id: 'TL' },
{ name: 'Togo', code: 'TG' }, { text: 'Togo', id: 'TG' },
{ name: 'Tokelau', code: 'TK' }, { text: 'Tokelau', id: 'TK' },
{ name: 'Tonga', code: 'TO' }, { text: 'Tonga', id: 'TO' },
{ name: 'Trinidad and Tobago', code: 'TT' }, { text: 'Trinidad and Tobago', id: 'TT' },
{ name: 'Tunisia', code: 'TN' }, { text: 'Tunisia', id: 'TN' },
{ name: 'Turkey', code: 'TR' }, { text: 'Turkey', id: 'TR' },
{ name: 'Turkmenistan', code: 'TM' }, { text: 'Turkmenistan', id: 'TM' },
{ name: 'Turks and Caicos Islands', code: 'TC' }, { text: 'Turks and Caicos Islands', id: 'TC' },
{ name: 'Tuvalu', code: 'TV' }, { text: 'Tuvalu', id: 'TV' },
{ name: 'Uganda', code: 'UG' }, { text: 'Uganda', id: 'UG' },
{ name: 'Ukraine', code: 'UA' }, { text: 'Ukraine', id: 'UA' },
{ name: 'United Arab Emirates', code: 'AE' }, { text: 'United Arab Emirates', id: 'AE' },
{ name: 'United Kingdom', code: 'GB' }, { text: 'United Kingdom', id: 'GB' },
{ name: 'United States Minor Outlying Islands', code: 'UM' }, { text: 'United States Minor Outlying Islands', id: 'UM' },
{ name: 'Uruguay', code: 'UY' }, { text: 'Uruguay', id: 'UY' },
{ name: 'Uzbekistan', code: 'UZ' }, { text: 'Uzbekistan', id: 'UZ' },
{ name: 'Vanuatu', code: 'VU' }, { text: 'Vanuatu', id: 'VU' },
{ name: 'Venezuela', code: 'VE' }, { text: 'Venezuela', id: 'VE' },
{ name: 'Viet Nam', code: 'VN' }, { text: 'Viet Nam', id: 'VN' },
{ name: 'Virgin Islands, British', code: 'VG' }, { text: 'Virgin Islands, British', id: 'VG' },
{ name: 'Virgin Islands, U.S.', code: 'VI' }, { text: 'Virgin Islands, U.S.', id: 'VI' },
{ name: 'Wallis and Futuna', code: 'WF' }, { text: 'Wallis and Futuna', id: 'WF' },
{ name: 'Western Sahara', code: 'EH' }, { text: 'Western Sahara', id: 'EH' },
{ name: 'Yemen', code: 'YE' }, { text: 'Yemen', id: 'YE' },
{ name: 'Zambia', code: 'ZM' }, { text: 'Zambia', id: 'ZM' },
{ name: 'Zimbabwe', code: 'ZW' } { text: 'Zimbabwe', id: 'ZW' }
]; ];

View File

@ -9,13 +9,11 @@ describe('MultiSelect', () => {
it('renders with empty values', () => { it('renders with empty values', () => {
const tree = shallow( const tree = shallow(
<MultiSelect <MultiSelect
itemId='id'
itemLabel='text'
valuesLabel='Selected Values' valuesLabel='Selected Values'
comboboxLabel='Add Value' comboboxLabel='Add Value'
values={[]} values={[]}
query={query} query={query}
onChange={() => { onChange={values => {
/* noop */ /* noop */
}} }}
/> />
@ -26,13 +24,11 @@ describe('MultiSelect', () => {
it('renders with values', () => { it('renders with values', () => {
const tree = shallow( const tree = shallow(
<MultiSelect <MultiSelect
itemId='id'
itemLabel='text'
valuesLabel='Selected Values' valuesLabel='Selected Values'
comboboxLabel='Add Value' comboboxLabel='Add Value'
values={[countries[0], countries[1]]} values={[countries[0], countries[1]]}
query={query} query={query}
onChange={() => { onChange={values => {
/* noop */ /* noop */
}} }}
/> />

View File

@ -18,7 +18,7 @@ export const query: QueryFunction = (search, page, token) =>
const limit = 10; const limit = 10;
const offset = page * limit; const offset = page * limit;
for (const country of countries) { for (const country of countries) {
if (country.name.toLowerCase().indexOf(search.toLowerCase()) >= 0) { if (country.text.toLowerCase().indexOf(search.toLowerCase()) >= 0) {
if (count >= offset) { if (count >= offset) {
results.push(country); results.push(country);
} }

View File

@ -57,6 +57,11 @@
</body> </body>
<script> <script>
function countryToDataItem(c) {
return {id:c.code, text:c.name};
}
var query = (function () { var query = (function () {
// local implementation of query that simulates network delay // local implementation of query that simulates network delay
var countries = window.select2countries; var countries = window.select2countries;
@ -93,7 +98,7 @@
previousTimeout = undefined; previousTimeout = undefined;
previousReject = undefined; previousReject = undefined;
resolve({ resolve({
values: results, values: results.map(countryToDataItem),
more: results.length >= limit, more: results.length >= limit,
token: token token: token
}); });
@ -106,17 +111,14 @@
console.log("onchange fired on countries1", event); console.log("onchange fired on countries1", event);
}) })
window.select25.create( window.select25.createMultiSelect(
document.getElementById('countries1'), { document.getElementById('countries1'), {
valuesLabel: "Selected Countries", valuesLabel: "Selected Countries",
comboboxLabel: "Add Country", comboboxLabel: "Add Country",
itemId: 'code',
itemLabel: 'name',
minimumCharacters: 2, minimumCharacters: 2,
multiple: true,
query: query, query: query,
quiet: 100, quiet: 100,
values: [window.select2countries[0], window.select2countries[1], window.select2countries[1]], values: [window.select2countries[0], window.select2countries[1], window.select2countries[1]].map(countryToDataItem),
}, },
); );
@ -124,23 +126,20 @@
window.select25.destroy(document.getElementById("countries1")); window.select25.destroy(document.getElementById("countries1"));
}); });
window.select25.create( window.select25.createSingleSelect(
document.getElementById('countries2'), { document.getElementById('countries2'), {
allowClear: true, allowClear: true,
placeholder: "Select Country", placeholder: "Select Country",
itemId: 'code',
itemLabel: 'name',
minimumCharacters: 2, minimumCharacters: 2,
query: query, query: query,
quiet: 100, quiet: 100,
value: window.select2countries[0] value: countryToDataItem(window.select2countries[0])
}, },
); );
window.select25.create( window.select25.createMultiSelect(
document.getElementById("colors"), { document.getElementById("colors"), {
multiple: true,
minimumCharacters: 0, minimumCharacters: 0,
data: function (params) { data: function (params) {
var term = params.term ? params.term.trim() : ""; var term = params.term ? params.term.trim() : "";

95
dist/select25.js vendored
View File

@ -225,7 +225,7 @@
var t = l(e.type, e.props, e.key, null); var t = l(e.type, e.props, e.key, null);
return (t.__e = e.__e), t; return (t.__e = e.__e), t;
} }
function I(e, t) { function x(e, t) {
(this.props = e), (this.context = t); (this.props = e), (this.context = t);
} }
function s(e) { function s(e) {
@ -242,7 +242,7 @@
) )
e.__d && e.forceUpdate(!1); e.__d && e.forceUpdate(!1);
} }
function x(e, t, n, o, r, s, a, i) { function I(e, t, n, o, r, s, a, i) {
var l, var l,
u, u,
c, c,
@ -251,7 +251,7 @@
f, f,
h, h,
v, v,
m = t.__k || L(t.props.children, (t.__k = []), M, !0), m = t.__k || E(t.props.children, (t.__k = []), M, !0),
g = (n && n.__k) || R, g = (n && n.__k) || R,
y = g.length; y = g.length;
if (i == w) if (i == w)
@ -292,13 +292,13 @@
for (u = y; u--; ) null != g[u] && F(g[u], t); for (u = y; u--; ) null != g[u] && F(g[u], t);
if (v) for (u = 0; u < v.length; u++) A(v[u], v[++u], t); if (v) for (u = 0; u < v.length; u++) A(v[u], v[++u], t);
} }
function L(e, t, n, o) { function E(e, t, n, o) {
if ((null == t && (t = []), null == e || 'boolean' == typeof e)) o && t.push(null); if ((null == t && (t = []), null == e || 'boolean' == typeof e)) o && t.push(null);
else if (Array.isArray(e)) for (var r = 0; r < e.length; r++) L(e[r], t, n, o); else if (Array.isArray(e)) for (var r = 0; r < e.length; r++) E(e[r], t, n, o);
else t.push(n ? n(e) : e); else t.push(n ? n(e) : e);
return t; return t;
} }
function E(e, t, n, o, r) { function L(e, t, n, o, r) {
var s, a, i, l; var s, a, i, l;
if ('style' === (t = r ? ('className' === t ? 'class' : t) : 'class' === t ? 'className' : t)) if ('style' === (t = r ? ('className' === t ? 'class' : t) : 'class' === t ? 'className' : t))
for (a in (s = S(S({}, o), n))) for (a in (s = S(S({}, o), n)))
@ -352,7 +352,7 @@
? (v = (c = t.__c = n.__c).__p = c.__E) ? (v = (c = t.__c = n.__c).__p = c.__E)
: (_.prototype && _.prototype.render : (_.prototype && _.prototype.render
? (t.__c = c = new _(m, y)) ? (t.__c = c = new _(m, y))
: ((t.__c = c = new I(m, y)), (c.constructor = _), (c.render = O)), : ((t.__c = c = new x(m, y)), (c.constructor = _), (c.render = O)),
g && g.sub(c), g && g.sub(c),
(c.props = m), (c.props = m),
c.state || (c.state = {}), c.state || (c.state = {}),
@ -390,7 +390,7 @@
(c.__v = t), (c.__v = t),
(c.__P = e); (c.__P = e);
try { try {
L( E(
null != (u = c.render(c.props, c.state, c.context)) && u.type == k && null == u.key null != (u = c.render(c.props, c.state, c.context)) && u.type == k && null == u.key
? u.props.children ? u.props.children
: u, : u,
@ -405,7 +405,7 @@
for ( for (
null != c.getChildContext && (o = S(S({}, o), c.getChildContext())), null != c.getChildContext && (o = S(S({}, o), c.getChildContext())),
p || null == c.getSnapshotBeforeUpdate || (h = c.getSnapshotBeforeUpdate(d, f)), p || null == c.getSnapshotBeforeUpdate || (h = c.getSnapshotBeforeUpdate(d, f)),
x(e, t, n, o, r, s, a, l), I(e, t, n, o, r, s, a, l),
c.base = t.__e; c.base = t.__e;
(u = c.__h.pop()); (u = c.__h.pop());
@ -444,7 +444,7 @@
null == s && null == s &&
((c && u && c.__html == u.__html) || (e.innerHTML = (c && c.__html) || '')), ((c && u && c.__html == u.__html) || (e.innerHTML = (c && c.__html) || '')),
d.multiple && (e.multiple = d.multiple), d.multiple && (e.multiple = d.multiple),
x(e, t, n, o, 'foreignObject' !== t.type && r, s, a, w), I(e, t, n, o, 'foreignObject' !== t.type && r, s, a, w),
(function(e, t, n, o) { (function(e, t, n, o) {
var r, var r,
s, s,
@ -453,8 +453,8 @@
'children' === (s = a[r]) || 'children' === (s = a[r]) ||
'key' === s || 'key' === s ||
(n && ('value' === s || 'checked' === s ? e : n)[s] === t[s]) || (n && ('value' === s || 'checked' === s ? e : n)[s] === t[s]) ||
E(e, s, t[s], n[s], o); L(e, s, t[s], n[s], o);
for (r in n) 'children' === r || 'key' === r || r in t || E(e, r, null, n[r], o); for (r in n) 'children' === r || 'key' === r || r in t || L(e, r, null, n[r], o);
})(e, d, p, r)), })(e, d, p, r)),
e e
); );
@ -571,12 +571,12 @@
})(e, document.getElementById('s25-live-polite')); })(e, document.getElementById('s25-live-polite'));
} }
(b = {}), (b = {}),
(I.prototype.setState = function(e, t) { (x.prototype.setState = function(e, t) {
var n = (this.__s !== this.state && this.__s) || (this.__s = S({}, this.state)); var n = (this.__s !== this.state && this.__s) || (this.__s = S({}, this.state));
('function' == typeof e && !(e = e(n, this.props))) || S(n, e), ('function' == typeof e && !(e = e(n, this.props))) || S(n, e),
null != e && this.__v && (t && this.__h.push(t), s(this)); null != e && this.__v && (t && this.__h.push(t), s(this));
}), }),
(I.prototype.forceUpdate = function(e) { (x.prototype.forceUpdate = function(e) {
var t, var t,
n, n,
o, o,
@ -619,7 +619,7 @@
})(r)), })(r)),
e && e(); e && e();
}), }),
(I.prototype.render = k), (x.prototype.render = k),
(n = []), (n = []),
(r = 'function' == typeof Promise ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout), (r = 'function' == typeof Promise ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout),
(u = /[A-Z]/g), (u = /[A-Z]/g),
@ -729,8 +729,8 @@
return D('div', { dangerouslySetInnerHTML: { __html: e.markup } }, ' '); return D('div', { dangerouslySetInnerHTML: { __html: e.markup } }, ' ');
} }
var Y, var Y,
G = { allowDuplicates: !1, itemId: 'id', itemLabel: 'text', minimumCharacters: 0, quiet: 50, tabIndex: 0 }, G = { allowDuplicates: !1, minimumCharacters: 0, quiet: 50, tabIndex: 0 },
$ = (t(J, (Y = I)), $ = (t(J, (Y = x)),
Object.defineProperty(J.prototype, 'dictionary', { Object.defineProperty(J.prototype, 'dictionary', {
get: function() { get: function() {
var e = this.props.dictionary; var e = this.props.dictionary;
@ -831,12 +831,10 @@
var f = Y.call(this, e) || this; var f = Y.call(this, e) || this;
return ( return (
(f.getItemId = function(e) { (f.getItemId = function(e) {
var t = f.props.itemId; return e.id;
return 'function' == typeof t ? t(e) : '' + e[t];
}), }),
(f.getItemLabel = function(e) { (f.getItemLabel = function(e) {
var t = f.props.itemLabel; return e.text;
return 'function' == typeof t ? t(e) : '' + e[t];
}), }),
(f.renderValue = function(e) { (f.renderValue = function(e) {
return f.renderItem(e, 'valueContent'); return f.renderItem(e, 'valueContent');
@ -952,7 +950,7 @@
); );
} }
var Z, var Z,
Q = (t(ee, (Z = I)), Q = (t(ee, (Z = x)),
(ee.prototype.getChildContext = function() { (ee.prototype.getChildContext = function() {
return this.props.context; return this.props.context;
}), }),
@ -969,7 +967,7 @@
return f(D(Q, { context: this.context }, t), n), null; return f(D(Q, { context: this.context }, t), n), null;
} }
var ne, var ne,
oe = (t(re, (ne = I)), oe = (t(re, (ne = x)),
(re.prototype.componentWillMount = function() { (re.prototype.componentWillMount = function() {
(this.container = document.createElement('div')), (this.container = document.createElement('div')),
this.props.class && (this.container.className = this.props.class), this.props.class && (this.container.className = this.props.class),
@ -1118,7 +1116,7 @@
(le.placeholder = 's25-placeholder'), (le.placeholder = 's25-placeholder'),
(le.scroll = 's25-scroll'); (le.scroll = 's25-scroll');
var ue, var ue,
ce = (t(pe, (ue = I)), ce = (t(pe, (ue = x)),
(pe.prototype.getResultDomId = function(e) { (pe.prototype.getResultDomId = function(e) {
return this.props.namespace + e; return this.props.namespace + e;
}), }),
@ -1887,14 +1885,19 @@
var Ce = { var Ce = {
allowClear: !((be || (be = {})).targetElement = 'te'), allowClear: !((be || (be = {})).targetElement = 'te'),
dictionary: 'en_us', dictionary: 'en_us',
hiddenValue: function(e, t) { hiddenValue: function(e) {
function n(e) { return e
return 'function' == typeof t.itemId ? t.itemId(e) : '' + e[t.itemId]; ? Array.isArray(e)
} ? 0 < e.length
return e ? (Array.isArray(e) ? (0 < e.length ? e.map(n).join(',') : '') : n(e)) : ''; ? e
.map(function(e) {
return e.id;
})
.join(',')
: ''
: e.id
: '';
}, },
itemId: 'id',
itemLabel: 'text',
minimumCharacters: 0, minimumCharacters: 0,
multiple: !1, multiple: !1,
openOnFocus: !1 openOnFocus: !1
@ -1904,7 +1907,7 @@
n.initEvent('change', !1, !0), (n[t] = t), e.dispatchEvent(n); n.initEvent('change', !1, !0), (n[t] = t), e.dispatchEvent(n);
} }
var De, var De,
ke = (t(Me, (De = I)), ke = (t(Me, (De = x)),
(Me.prototype.componentDidUpdate = function() { (Me.prototype.componentDidUpdate = function() {
this.setHiddenValue(this.state.values); this.setHiddenValue(this.state.values);
}), }),
@ -1918,8 +1921,6 @@
containerStyle: e.containerStyle, containerStyle: e.containerStyle,
valuesLabel: e.valuesLabel, valuesLabel: e.valuesLabel,
comboboxLabel: e.comboboxLabel, comboboxLabel: e.comboboxLabel,
itemId: e.itemId,
itemLabel: e.itemLabel,
valueContent: e.valueContent, valueContent: e.valueContent,
resultContent: e.resultContent, resultContent: e.resultContent,
query: e.query, query: e.query,
@ -1950,15 +1951,15 @@
t t
); );
} }
var Ie, var xe,
xe = (t(Le, (Ie = I)), Ie = (t(Ee, (xe = x)),
(Le.prototype.componentDidMount = function() { (Ee.prototype.componentDidMount = function() {
this.setHiddenValue(this.state.value); this.setHiddenValue(this.state.value);
}), }),
(Le.prototype.componentDidUpdate = function() { (Ee.prototype.componentDidUpdate = function() {
this.setHiddenValue(this.state.value); this.setHiddenValue(this.state.value);
}), }),
(Le.prototype.render = function() { (Ee.prototype.render = function() {
var e = this.props.options; var e = this.props.options;
return D(ye, { return D(ye, {
label: e.label, label: e.label,
@ -1967,8 +1968,6 @@
containerStyle: e.containerStyle, containerStyle: e.containerStyle,
allowClear: e.allowClear, allowClear: e.allowClear,
placeholder: e.placeholder, placeholder: e.placeholder,
itemId: e.itemId,
itemLabel: e.itemLabel,
valueContent: e.valueContent, valueContent: e.valueContent,
resultContent: e.resultContent, resultContent: e.resultContent,
query: e.query, query: e.query,
@ -1982,15 +1981,15 @@
onChange: this.onChange onChange: this.onChange
}); });
}), }),
(Le.prototype.setHiddenValue = function(e) { (Ee.prototype.setHiddenValue = function(e) {
var t = this.props, var t = this.props,
n = t.element, n = t.element,
o = t.options; o = t.options;
n.value = o.hiddenValue(e, o); n.value = o.hiddenValue(e, o);
}), }),
Le); Ee);
function Le(e) { function Ee(e) {
var t = Ie.call(this, e) || this; var t = xe.call(this, e) || this;
return ( return (
(t.onChange = function(e) { (t.onChange = function(e) {
t.setState({ value: e }), t.setHiddenValue(e), Se(t.props.element, e); t.setState({ value: e }), t.setHiddenValue(e), Se(t.props.element, e);
@ -1999,7 +1998,7 @@
t t
); );
} }
var Ee = { var Le = {
create: function(e, t) { create: function(e, t) {
var n = we.getStore(e); var n = we.getStore(e);
if ( if (
@ -2067,7 +2066,7 @@
a = document.createElement('div'); a = document.createElement('div');
s.insertBefore(a, e), s.insertBefore(a, e),
n.set(be.targetElement, a), n.set(be.targetElement, a),
t.multiple ? f(D(ke, { element: e, options: t }), s, a) : f(D(xe, { element: e, options: t }), s, a); t.multiple ? f(D(ke, { element: e, options: t }), s, a) : f(D(Ie, { element: e, options: t }), s, a);
}, },
destroy: function(e) { destroy: function(e) {
if (we.hasStore(e)) { if (we.hasStore(e)) {
@ -2077,6 +2076,6 @@
} }
} }
}; };
(window.select25 = Ee), (e.select25 = Ee), Object.defineProperty(e, '__esModule', { value: !0 }); (window.select25 = Le), (e.select25 = Le), Object.defineProperty(e, '__esModule', { value: !0 });
}); });
//# sourceMappingURL=select25.js.map //# sourceMappingURL=select25.js.map

File diff suppressed because one or more lines are too long