Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ElementChildren.js 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. exports.__esModule = true;
  4. exports.map = map;
  5. exports.forEach = forEach;
  6. var _react = _interopRequireDefault(require("react"));
  7. /**
  8. * Iterates through children that are typically specified as `props.children`,
  9. * but only maps over children that are "valid elements".
  10. *
  11. * The mapFunction provided index will be normalised to the components mapped,
  12. * so an invalid component would not increase the index.
  13. *
  14. */
  15. function map(children, func) {
  16. var index = 0;
  17. return _react.default.Children.map(children, function (child) {
  18. return _react.default.isValidElement(child) ? func(child, index++) : child;
  19. });
  20. }
  21. /**
  22. * Iterates through children that are "valid elements".
  23. *
  24. * The provided forEachFunc(child, index) will be called for each
  25. * leaf child with the index reflecting the position relative to "valid components".
  26. */
  27. function forEach(children, func) {
  28. var index = 0;
  29. _react.default.Children.forEach(children, function (child) {
  30. if (_react.default.isValidElement(child)) func(child, index++);
  31. });
  32. }