UNPKG

react-elegant-ui

Version:

Elegant UI components, made by BEM best practices for react

53 lines 1.43 kB
var __assign = this && this.__assign || function () { __assign = Object.assign || function (t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __read = this && this.__read || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; import React, { useState } from 'react'; import { withHOCConstructor } from '../../../lib/compose'; // TODO: unify it, make interface and move to HOC `withCursorStateManager` /** * HOC for control cursor state by default */ export var withCursorState = withHOCConstructor({ matchProps: { setCursorIndex: undefined } }, function (Menu) { return function (props) { var _a = __read(useState(props.cursorIndex), 2), index = _a[0], setIndex = _a[1]; return /*#__PURE__*/React.createElement(Menu, __assign({}, props, { cursorIndex: index, setCursorIndex: setIndex })); }; });