index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = void 0;
  4. var _utils = require("../utils");
  5. var _relation = require("../mixins/relation");
  6. var _createNamespace = (0, _utils.createNamespace)('row'),
  7. createComponent = _createNamespace[0],
  8. bem = _createNamespace[1];
  9. var _default = createComponent({
  10. mixins: [(0, _relation.ParentMixin)('vanRow')],
  11. props: {
  12. type: String,
  13. align: String,
  14. justify: String,
  15. tag: {
  16. type: String,
  17. default: 'div'
  18. },
  19. gutter: {
  20. type: [Number, String],
  21. default: 0
  22. }
  23. },
  24. computed: {
  25. spaces: function spaces() {
  26. var gutter = Number(this.gutter);
  27. if (!gutter) {
  28. return;
  29. }
  30. var spaces = [];
  31. var groups = [[]];
  32. var totalSpan = 0;
  33. this.children.forEach(function (item, index) {
  34. totalSpan += Number(item.span);
  35. if (totalSpan > 24) {
  36. groups.push([index]);
  37. totalSpan -= 24;
  38. } else {
  39. groups[groups.length - 1].push(index);
  40. }
  41. });
  42. groups.forEach(function (group) {
  43. var averagePadding = gutter * (group.length - 1) / group.length;
  44. group.forEach(function (item, index) {
  45. if (index === 0) {
  46. spaces.push({
  47. right: averagePadding
  48. });
  49. } else {
  50. var left = gutter - spaces[item - 1].right;
  51. var right = averagePadding - left;
  52. spaces.push({
  53. left: left,
  54. right: right
  55. });
  56. }
  57. });
  58. });
  59. return spaces;
  60. }
  61. },
  62. methods: {
  63. onClick: function onClick(event) {
  64. this.$emit('click', event);
  65. }
  66. },
  67. render: function render() {
  68. var _bem;
  69. var h = arguments[0];
  70. var align = this.align,
  71. justify = this.justify;
  72. var flex = this.type === 'flex';
  73. return h(this.tag, {
  74. "class": bem((_bem = {
  75. flex: flex
  76. }, _bem["align-" + align] = flex && align, _bem["justify-" + justify] = flex && justify, _bem)),
  77. "on": {
  78. "click": this.onClick
  79. }
  80. }, [this.slots()]);
  81. }
  82. });
  83. exports.default = _default;