index.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. exports.__esModule = true;
  4. exports.default = void 0;
  5. var _babelHelperVueJsxMergeProps = _interopRequireDefault(require("@vue/babel-helper-vue-jsx-merge-props"));
  6. var _utils = require("../utils");
  7. var _functional = require("../utils/functional");
  8. var _constant = require("../utils/constant");
  9. // Utils
  10. var _createNamespace = (0, _utils.createNamespace)('password-input'),
  11. createComponent = _createNamespace[0],
  12. bem = _createNamespace[1];
  13. function PasswordInput(h, props, slots, ctx) {
  14. var _ref2;
  15. var mask = props.mask,
  16. value = props.value,
  17. length = props.length,
  18. gutter = props.gutter,
  19. focused = props.focused,
  20. errorInfo = props.errorInfo;
  21. var info = errorInfo || props.info;
  22. var Points = [];
  23. for (var i = 0; i < length; i++) {
  24. var _ref;
  25. var _char = value[i];
  26. var showBorder = i !== 0 && !gutter;
  27. var showCursor = focused && i === value.length;
  28. var style = void 0;
  29. if (i !== 0 && gutter) {
  30. style = {
  31. marginLeft: (0, _utils.addUnit)(gutter)
  32. };
  33. }
  34. Points.push(h("li", {
  35. "class": [(_ref = {}, _ref[_constant.BORDER_LEFT] = showBorder, _ref), bem('item', {
  36. focus: showCursor
  37. })],
  38. "style": style
  39. }, [mask ? h("i", {
  40. "style": {
  41. visibility: _char ? 'visible' : 'hidden'
  42. }
  43. }) : _char, showCursor && h("div", {
  44. "class": bem('cursor')
  45. })]));
  46. }
  47. return h("div", {
  48. "class": bem()
  49. }, [h("ul", (0, _babelHelperVueJsxMergeProps.default)([{
  50. "class": [bem('security'), (_ref2 = {}, _ref2[_constant.BORDER_SURROUND] = !gutter, _ref2)],
  51. "on": {
  52. "touchstart": function touchstart(event) {
  53. event.stopPropagation();
  54. (0, _functional.emit)(ctx, 'focus', event);
  55. }
  56. }
  57. }, (0, _functional.inherit)(ctx, true)]), [Points]), info && h("div", {
  58. "class": bem(errorInfo ? 'error-info' : 'info')
  59. }, [info])]);
  60. }
  61. PasswordInput.props = {
  62. info: String,
  63. gutter: [Number, String],
  64. focused: Boolean,
  65. errorInfo: String,
  66. mask: {
  67. type: Boolean,
  68. default: true
  69. },
  70. value: {
  71. type: String,
  72. default: ''
  73. },
  74. length: {
  75. type: [Number, String],
  76. default: 6
  77. }
  78. };
  79. var _default = createComponent(PasswordInput);
  80. exports.default = _default;