mirror of
https://github.com/facebook/docusaurus.git
synced 2025-12-30 05:52:50 +00:00
* 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>
28 lines
807 B
JavaScript
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;
|
|
}
|
|
}
|