UNPKG

react-select-search-nextjs

Version:

Lightweight select component for React with support for NextJS

34 lines (29 loc) 1.09 kB
"use strict"; exports.__esModule = true; exports["default"] = groupOptions; function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function groupOptions(options) { var nextOptions = []; options.forEach(function (option, i) { if ('groupId' in option) { var nextOption = _extends({}, option); var groupIndex = nextOptions.findIndex(function (el) { return 'groupId' in el && el.groupId === nextOption.groupId; }); nextOption.index = i; if (groupIndex > -1) { nextOptions[groupIndex].items.push(nextOption); } else { nextOptions.push({ items: [nextOption], groupId: option.groupId, type: 'group', name: option.groupName }); } } else { nextOptions.push(option); } }); return nextOptions; }