mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-04 06:43:15 +02:00
ab22347d7b
* Add placeholder options to demo page * Use constant types in components * Refactor adding predefined groups/items/choices * Add 'highlighted' flag to Item type * Fix dispatch param type * Build * Add jsdoc comments to utils * Remove unused file * Add default values to js doc comments * Use Redux Action type * Housekeeping * Increase utils coverage * Apply suggestions from code review * Add _getTemplate unit tests
54 lines
932 B
JavaScript
54 lines
932 B
JavaScript
import { ACTION_TYPES } from '../constants';
|
|
|
|
/**
|
|
* @typedef {import('redux').Action} Action
|
|
* @typedef {import('../../../types/index').Choices.Item} Item
|
|
*/
|
|
|
|
/**
|
|
* @param {Item} item
|
|
* @returns {Action & Item}
|
|
*/
|
|
export const addItem = ({
|
|
value,
|
|
label,
|
|
id,
|
|
choiceId,
|
|
groupId,
|
|
customProperties,
|
|
placeholder,
|
|
keyCode,
|
|
}) => ({
|
|
type: ACTION_TYPES.ADD_ITEM,
|
|
value,
|
|
label,
|
|
id,
|
|
choiceId,
|
|
groupId,
|
|
customProperties,
|
|
placeholder,
|
|
keyCode,
|
|
});
|
|
|
|
/**
|
|
* @param {string} id
|
|
* @param {string} choiceId
|
|
* @returns {Action & { id: string, choiceId: string }}
|
|
*/
|
|
export const removeItem = (id, choiceId) => ({
|
|
type: ACTION_TYPES.REMOVE_ITEM,
|
|
id,
|
|
choiceId,
|
|
});
|
|
|
|
/**
|
|
* @param {string} id
|
|
* @param {boolean} highlighted
|
|
* @returns {Action & { id: string, highlighted: boolean }}
|
|
*/
|
|
export const highlightItem = (id, highlighted) => ({
|
|
type: ACTION_TYPES.HIGHLIGHT_ITEM,
|
|
id,
|
|
highlighted,
|
|
});
|