mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-04 14:53:12 +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
59 lines
995 B
JavaScript
59 lines
995 B
JavaScript
/**
|
|
* @typedef {import('redux').Action} Action
|
|
* @typedef {import('../../../types/index').Choices.Choice} Choice
|
|
*/
|
|
|
|
import { ACTION_TYPES } from '../constants';
|
|
|
|
/**
|
|
* @argument {Choice} choice
|
|
* @returns {Action & Choice}
|
|
*/
|
|
export const addChoice = ({
|
|
value,
|
|
label,
|
|
id,
|
|
groupId,
|
|
disabled,
|
|
elementId,
|
|
customProperties,
|
|
placeholder,
|
|
keyCode,
|
|
}) => ({
|
|
type: ACTION_TYPES.ADD_CHOICE,
|
|
value,
|
|
label,
|
|
id,
|
|
groupId,
|
|
disabled,
|
|
elementId,
|
|
customProperties,
|
|
placeholder,
|
|
keyCode,
|
|
});
|
|
|
|
/**
|
|
* @argument {Choice[]} results
|
|
* @returns {Action & { results: Choice[] }}
|
|
*/
|
|
export const filterChoices = results => ({
|
|
type: ACTION_TYPES.FILTER_CHOICES,
|
|
results,
|
|
});
|
|
|
|
/**
|
|
* @argument {boolean} active
|
|
* @returns {Action & { active: boolean }}
|
|
*/
|
|
export const activateChoices = (active = true) => ({
|
|
type: ACTION_TYPES.ACTIVATE_CHOICES,
|
|
active,
|
|
});
|
|
|
|
/**
|
|
* @returns {Action}
|
|
*/
|
|
export const clearChoices = () => ({
|
|
type: ACTION_TYPES.CLEAR_CHOICES,
|
|
});
|