Choices/src/scripts/actions/items.js

53 lines
908 B
JavaScript
Raw Normal View History

import { ACTION_TYPES } from '../constants';
2017-10-10 16:30:06 +02:00
/**
* @typedef {import('../../../types/index').Choices.Item} Item
*/
/**
* @param {Item} item
* @returns {{ type: string } & Item}
*/
2018-05-29 20:55:33 +02:00
export const addItem = ({
2017-10-10 16:26:38 +02:00
value,
label,
id,
choiceId,
groupId,
customProperties,
placeholder,
keyCode,
2018-05-29 20:55:33 +02:00
}) => ({
2017-10-10 16:30:06 +02:00
type: ACTION_TYPES.ADD_ITEM,
2017-10-10 16:26:38 +02:00
value,
label,
id,
choiceId,
groupId,
customProperties,
placeholder,
keyCode,
});
/**
* @param {string} id
* @param {string} choiceId
* @returns {{ type: string, id: string, choiceId: string }}
*/
2017-10-10 16:26:38 +02:00
export const removeItem = (id, choiceId) => ({
2017-10-10 16:30:06 +02:00
type: ACTION_TYPES.REMOVE_ITEM,
2017-10-10 16:26:38 +02:00
id,
choiceId,
});
/**
* @param {string} id
* @param {boolean} highlighted
* @returns {{ type: string, id: string, highlighted: boolean }}
*/
2017-10-10 16:26:38 +02:00
export const highlightItem = (id, highlighted) => ({
2017-10-10 16:30:06 +02:00
type: ACTION_TYPES.HIGHLIGHT_ITEM,
2017-10-10 16:26:38 +02:00
id,
highlighted,
});