index.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. var __extends = (this && this.__extends) || (function () {
  2. var extendStatics = Object.setPrototypeOf ||
  3. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5. return function (d, b) {
  6. extendStatics(d, b);
  7. function __() { this.constructor = d; }
  8. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9. };
  10. })();
  11. var __assign = (this && this.__assign) || Object.assign || function(t) {
  12. for (var s, i = 1, n = arguments.length; i < n; i++) {
  13. s = arguments[i];
  14. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  15. t[p] = s[p];
  16. }
  17. return t;
  18. };
  19. import * as React from 'react';
  20. import { Dragact } from '../../src/lib/dragact';
  21. var Words = [
  22. { content: 'You can do anything, but not everything.' },
  23. { content: 'Those who dare to fail miserably can achieve greatly.' },
  24. { content: 'You miss 100 percent of the shots you never take.' },
  25. { content: 'Those who believe in telekinetics, raise my hand.' },
  26. { content: 'I’d rather live with a good question than a bad answer.' }
  27. ];
  28. var Card = function (_a) {
  29. var item = _a.item, provided = _a.provided, onDelete = _a.onDelete;
  30. return (React.createElement("div", __assign({ className: "layout-Item" }, provided.props, provided.dragHandle),
  31. React.createElement("div", { style: {
  32. position: 'absolute',
  33. width: 10,
  34. height: 10,
  35. right: 15,
  36. top: 5,
  37. cursor: 'pointer'
  38. }, onClick: function () { return onDelete(item.key); } }, "\u274C"),
  39. React.createElement("div", { style: { padding: 5, textAlign: 'center', color: '#595959' } }, item.content)));
  40. };
  41. var fakeData = function () {
  42. var Y = 0;
  43. return Words.map(function (item, index) {
  44. if (index % 4 === 0)
  45. Y++;
  46. return __assign({}, item, { GridX: (index % 4) * 4, GridY: Y * 4, w: 4, h: 3, key: index });
  47. });
  48. };
  49. var makeOne = function () {
  50. return { content: 'added', GridX: 0, GridY: 0, w: 4, h: 3, key: Date.now() };
  51. };
  52. var AddRemove = /** @class */ (function (_super) {
  53. __extends(AddRemove, _super);
  54. function AddRemove() {
  55. var _this = _super !== null && _super.apply(this, arguments) || this;
  56. _this.state = {
  57. layout: fakeData()
  58. };
  59. _this.handleClick = function () {
  60. var change = _this.state.layout.map(function (item) {
  61. return __assign({}, item, { content: '21312' });
  62. });
  63. _this.setState({
  64. layout: change.concat([makeOne()])
  65. });
  66. };
  67. _this.hanldeOnDelete = function (key) {
  68. var layout = _this.state.layout.filter(function (item) {
  69. if (item.key !== key) {
  70. return item;
  71. }
  72. });
  73. _this.setState({
  74. layout: layout
  75. });
  76. };
  77. return _this;
  78. }
  79. AddRemove.prototype.componentDidMount = function () { };
  80. AddRemove.prototype.render = function () {
  81. var _this = this;
  82. var margin = [5, 5];
  83. var dragactInit = {
  84. width: 600,
  85. col: 12,
  86. rowHeight: 800 / 12,
  87. margin: margin,
  88. className: 'normal-layout',
  89. layout: this.state.layout,
  90. placeholder: true
  91. };
  92. return (React.createElement("div", null,
  93. React.createElement("div", { style: { display: 'flex', justifyContent: 'center' } },
  94. React.createElement("div", null,
  95. React.createElement("h1", { style: { textAlign: 'center' } }, "AddRemove Demo"),
  96. React.createElement("h3", { style: { textAlign: 'center' } }, "\u5728\u8FD9\u4E2A\u5E03\u5C40\u4E2D\uFF0C\u65B0\u589E\u4E00\u4E2A\u5E03\u5C40\uFF0C\u4F1A\u65B0\u52A0\u5165\u4E00\u4E2A\u5E03\u5C40"),
  97. React.createElement("button", { onClick: this.handleClick }, "\u65B0\u589E"),
  98. React.createElement(Dragact, __assign({}, dragactInit), function (item, provided) {
  99. return (React.createElement(Card, { item: item, provided: provided, onDelete: _this.hanldeOnDelete }));
  100. })))));
  101. };
  102. return AddRemove;
  103. }(React.Component));
  104. export { AddRemove };