@zohodesk/hooks
Version:
Unified Component Library - Hooks
23 lines (22 loc) • 726 B
JavaScript
export default function getMatchedQuery(queries) {
let observedSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
let matchedQuery = {};
let {
inlineSize: observedWidth,
blockSize: observedHeight
} = observedSize;
Object.keys(queries).forEach(queryKey => {
let {
minWidth = 0,
maxWidth = Infinity,
minHeight = 0,
maxHeight = Infinity
} = queries[queryKey]; // query...
let widthMatch = minWidth <= observedWidth && observedWidth <= maxWidth;
let heightMatch = minHeight <= observedHeight && observedHeight <= maxHeight;
let fullMatch = widthMatch && heightMatch;
matchedQuery[queryKey] = fullMatch;
});
return matchedQuery;
}
;