docusaurus/website/src/utils/jsUtils.js
Lisa Chandra 458af077ae
feat(v2): new showcase page with tags and filters (#4515)
* docs: add ToggleTags component for showcase

* docs: add filter functionality

* docs: remove redundant variables

* docs: use react state for selectedTags

* docs: add control to tag checkbox

* docs: use useMemo for filteredUsers

* docs: change names of tags

* revert name tag changes

* polish the showcase page

* cleanup tags on the users list

* minor polish

* add querystring filtering

* typo

* Add title/arialabel to emulate tooltip

Co-authored-by: Javid <singularity.javid@gmail.com>
Co-authored-by: slorber <lorber.sebastien@gmail.com>
2021-04-22 17:15:28 +02:00

28 lines
807 B
JavaScript

// Inspired by https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_difference
export function difference(...arrays) {
return arrays.reduce((a, b) => a.filter((c) => !b.includes(c)));
}
// Inspired by https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_sortby-and-_orderby
export function sortBy(array, getter) {
function compareBy(getter) {
return (a, b) =>
getter(a) > getter(b) ? 1 : getter(b) > getter(a) ? -1 : 0;
}
const sortedArray = [...array];
sortedArray.sort(compareBy(getter));
return sortedArray;
}
export function toggleListItem(list, item) {
const itemIndex = list.indexOf(item);
if (itemIndex === -1) {
return list.concat(item);
} else {
const newList = [...list];
newList.splice(itemIndex, 1);
return newList;
}
}