UNPKG

react-widgets

Version:

An à la carte set of polished, extensible, and accessible inputs built for React

14 lines (11 loc) 466 B
export default function canShowCreate(allowCreate, { searchTerm = '', data, dataItems, accessors }) { const eq = v => accessors.text(v).toLowerCase() === searchTerm.toLowerCase(); // if there is an exact match on textFields: // "john" => { name: "john" }, don't show const hasExtactMatch = () => dataItems && dataItems.some(eq) || data.some(eq); return !!((allowCreate === true || allowCreate === 'onFilter' && searchTerm) && !hasExtactMatch()); }