react-native-ui-lib
Version:
[](https://stand-with-ukraine.pp.ua)
30 lines • 932 B
JavaScript
import _lowerCase from "lodash/lowerCase";
import _includes from "lodash/includes";
import _find from "lodash/find";
import React from 'react';
export function extractPickerItems(props) {
const {
children
} = props;
const items = React.Children.map(children, child => ({
// @ts-expect-error handle use PickerItemProps once exist
value: child?.props.value,
// @ts-expect-error handle use PickerItemProps once exist
label: child?.props.label
}));
return items ?? [];
}
export function isItemSelected(childValue, selectedValue) {
let isSelected = false;
if (Array.isArray(selectedValue)) {
isSelected = _find(selectedValue, v => {
return v === childValue;
}) !== undefined;
} else {
isSelected = childValue === selectedValue;
}
return isSelected;
}
export function shouldFilterOut(searchValue, itemLabel) {
return !_includes(_lowerCase(itemLabel), _lowerCase(searchValue));
}