mirror of
https://github.com/Choices-js/Choices.git
synced 2026-03-15 07:05:47 +01:00
95 lines
3.1 KiB
TypeScript
95 lines
3.1 KiB
TypeScript
import { ClassNames } from './interfaces/class-names';
|
|
import { Options } from './interfaces/options';
|
|
import { sanitise, sortByAlpha } from './lib/utils';
|
|
import { EventChoice } from './interfaces';
|
|
|
|
export const DEFAULT_CLASSNAMES: ClassNames = {
|
|
containerOuter: ['choices'],
|
|
containerInner: ['choices__inner'],
|
|
input: ['choices__input'],
|
|
inputCloned: ['choices__input--cloned'],
|
|
list: ['choices__list'],
|
|
listItems: ['choices__list--multiple'],
|
|
listSingle: ['choices__list--single'],
|
|
listDropdown: ['choices__list--dropdown'],
|
|
item: ['choices__item'],
|
|
itemSelectable: ['choices__item--selectable'],
|
|
itemDisabled: ['choices__item--disabled'],
|
|
itemChoice: ['choices__item--choice'],
|
|
description: ['choices__description'],
|
|
placeholder: ['choices__placeholder'],
|
|
group: ['choices__group'],
|
|
groupHeading: ['choices__heading'],
|
|
button: ['choices__button'],
|
|
activeState: ['is-active'],
|
|
focusState: ['is-focused'],
|
|
openState: ['is-open'],
|
|
disabledState: ['is-disabled'],
|
|
highlightedState: ['is-highlighted'],
|
|
selectedState: ['is-selected'],
|
|
flippedState: ['is-flipped'],
|
|
loadingState: ['is-loading'],
|
|
notice: ['choices__notice'],
|
|
addChoice: ['choices__item--selectable', 'add-choice'],
|
|
noResults: ['has-no-results'],
|
|
noChoices: ['has-no-choices'],
|
|
} as const;
|
|
|
|
export const DEFAULT_CONFIG: Options = {
|
|
items: [],
|
|
choices: [],
|
|
silent: false,
|
|
renderChoiceLimit: -1,
|
|
maxItemCount: -1,
|
|
closeDropdownOnSelect: 'auto',
|
|
singleModeForMultiSelect: false,
|
|
addChoices: false,
|
|
addItems: true,
|
|
addItemFilter: (value: string): boolean => !!value && value !== '',
|
|
removeItems: true,
|
|
removeItemButton: false,
|
|
removeItemButtonAlignLeft: false,
|
|
editItems: false,
|
|
allowHTML: false,
|
|
allowHtmlUserInput: false,
|
|
duplicateItemsAllowed: true,
|
|
delimiter: ',',
|
|
paste: true,
|
|
searchEnabled: true,
|
|
searchChoices: true,
|
|
searchFloor: 1,
|
|
searchResultLimit: 4,
|
|
searchFields: ['label', 'value'],
|
|
position: 'auto',
|
|
resetScrollPosition: true,
|
|
shouldSort: true,
|
|
shouldSortItems: false,
|
|
sorter: sortByAlpha,
|
|
shadowRoot: null,
|
|
placeholder: true,
|
|
placeholderValue: null,
|
|
searchPlaceholderValue: null,
|
|
prependValue: null,
|
|
appendValue: null,
|
|
renderSelectedChoices: 'auto',
|
|
loadingText: 'Loading...',
|
|
noResultsText: 'No results found',
|
|
noChoicesText: 'No choices to choose from',
|
|
itemSelectText: 'Press to select',
|
|
uniqueItemText: 'Only unique values can be added',
|
|
customAddItemText: 'Only values matching specific conditions can be added',
|
|
addItemText: (value: string) => `Press Enter to add <b>"${value}"</b>`,
|
|
removeItemIconText: (): string => `Remove item`,
|
|
removeItemLabelText: (value: string, _valueRaw: string, i?: EventChoice): string =>
|
|
`Remove item: ${i ? sanitise<string>(i.label) : value}`,
|
|
maxItemText: (maxItemCount: number): string => `Only ${maxItemCount} values can be added`,
|
|
valueComparer: (value1: string, value2: string): boolean => value1 === value2,
|
|
fuseOptions: {
|
|
includeScore: true,
|
|
},
|
|
labelId: '',
|
|
callbackOnInit: null,
|
|
callbackOnCreateTemplates: null,
|
|
classNames: DEFAULT_CLASSNAMES,
|
|
appendGroupInSearch: false,
|
|
} as const;
|