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.
 
 
 
 

39 line
1.2 KiB

  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  6. exports.default = getTabIndex;
  7. var _jsxAstUtils = require('jsx-ast-utils');
  8. /**
  9. * Returns the tabIndex value.
  10. */
  11. function getTabIndex(tabIndex) {
  12. var literalValue = (0, _jsxAstUtils.getLiteralPropValue)(tabIndex);
  13. // String and number values.
  14. if (['string', 'number'].indexOf(typeof literalValue === 'undefined' ? 'undefined' : _typeof(literalValue)) > -1) {
  15. // Empty string will convert to zero, so check for it explicity.
  16. if (typeof literalValue === 'string' && literalValue.length === 0) {
  17. return undefined;
  18. }
  19. var value = Number(literalValue);
  20. if (Number.isNaN(value)) {
  21. return undefined;
  22. }
  23. return Number.isInteger(value) ? value : undefined;
  24. }
  25. // Booleans are not valid values, return undefined.
  26. if (literalValue === true || literalValue === false) {
  27. return undefined;
  28. }
  29. return (0, _jsxAstUtils.getPropValue)(tabIndex);
  30. }