forked from 10up/block-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
selectors.js
55 lines (52 loc) · 1.27 KB
/
selectors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* eslint-disable no-prototype-builtins */
/**
* Returns all icons sets
*
* @param {object} state Data state.
*
* @returns {Array?} Icon Sets.
*/
export function getIconSets(state) {
const { iconSets } = state;
return Object.values(iconSets);
}
/**
* Returns an Icon Set by its name
*
* @param {object} state Data state.
* @param {string} name Name of the Icon Set.
*
* @returns {object?} Icon Set.
*/
export function getIconSet(state, name) {
const { iconSets } = state;
const iconSet = iconSets[name] ?? [];
return iconSet;
}
/**
* Returns an icon of an icon set by its name
*
* @param {object} state Data state.
* @param {string} name Name of the Icon Set.
*
* @returns {Array?} List of Icons.
*/
export function getIcons(state, name) {
const { iconSets } = state;
return iconSets?.hasOwnProperty(name) ? iconSets[name]?.icons ?? [] : [];
}
/**
* Returns an icon of an icon set by its name
*
* @param {object} state Data state.
* @param {string} name Name of the Icon Set.
* @param {string} iconName Name of the iconName.
*
* @returns {object?} Icon.
*/
export function getIcon(state, name, iconName) {
const { iconSets } = state;
return iconSets?.hasOwnProperty(name)
? iconSets[name]?.icons?.find((item) => item.name === iconName) ?? []
: undefined;
}