index.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 '../lib/dragact';
  21. import './index.css';
  22. var Words = [
  23. { content: 'You can do anything, but not everything.', img: 'http://pic.sc.chinaz.com/files/pic/pic9/201303/xpic10472.jpg' },
  24. { content: 'Those who dare to fail miserably can achieve greatly.', img: 'https://img00.deviantart.net/1163/i/2013/059/d/7/irish_views_by_ssquared_photography-d5wjnsk.jpg' },
  25. { content: 'You miss 100 percent of the shots you never take.', img: 'http://www.landsendhotel.co.uk/uploads/gallery/gallery/coastal_scenery_seascapes_6.jpg' },
  26. { content: 'Those who believe in telekinetics, raise my hand.', img: 'https://tctechcrunch2011.files.wordpress.com/2017/10/26099344353_18cd6fabb8_k.jpg?w=738' },
  27. { content: 'I’d rather live with a good question than a bad answer.', img: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQVa26cLzh6PYUwY4LMpwbHyDHFmWi_w2JuqDzeOdm1IIEbBZO0Vg' }
  28. ];
  29. var Card = function (props) {
  30. var item = props.item;
  31. var dataSet = props['data-set'];
  32. return (React.createElement("div", { className: 'layout-Item' },
  33. React.createElement("img", { src: item.img, style: { width: '100%', height: '60%' }, draggable: false, alt: 'card' }),
  34. React.createElement("div", { style: { padding: 5, textAlign: 'center', color: '#595959' } }, dataSet.handle ? React.createElement("div", { className: 'card-handle', id: "dragact-handle" }, "\u70B9\u6211\u62D6\u52A8") : item.content)));
  35. };
  36. var HandleLayout = /** @class */ (function (_super) {
  37. __extends(HandleLayout, _super);
  38. function HandleLayout() {
  39. var _this = _super !== null && _super.apply(this, arguments) || this;
  40. _this.state = {
  41. layout: [1]
  42. };
  43. _this.handleClick = function () {
  44. _this.setState({
  45. layout: _this.state.layout.concat([1])
  46. });
  47. console.log(_this.state.layout);
  48. };
  49. _this.handleDeleteClick = function () {
  50. _this.state.layout.shift();
  51. _this.setState({
  52. layout: _this.state.layout.slice()
  53. });
  54. };
  55. return _this;
  56. }
  57. HandleLayout.prototype.componentDidMount = function () {
  58. this.setState({
  59. layout: this.dragactNode.getLayout()
  60. });
  61. };
  62. HandleLayout.prototype.render = function () {
  63. var _this = this;
  64. var margin = [5, 5];
  65. var dragactInit = {
  66. width: 800,
  67. col: 12,
  68. rowHeight: 800 / 12,
  69. margin: margin,
  70. className: 'normal-layout'
  71. };
  72. return (React.createElement("div", null,
  73. React.createElement("div", { style: { display: 'flex', justifyContent: 'center' } },
  74. React.createElement("div", null,
  75. React.createElement("h1", { style: { textAlign: 'center' } }, "Handle Layout Demo"),
  76. React.createElement(Dragact, __assign({}, dragactInit, { ref: function (node) { return node ? _this.dragactNode = node : null; } }),
  77. React.createElement(Card, { item: Words[0], key: 0, "data-set": { GridX: 0 * 3, GridY: 0, w: 3, h: 3 } }),
  78. React.createElement(Card, { item: Words[1], key: 1, "data-set": { GridX: 1 * 3, GridY: 0, w: 3, h: 3 } }),
  79. React.createElement(Card, { item: Words[2], key: 2, "data-set": { GridX: 2 * 3, GridY: 0, w: 3, h: 3, handle: true } }),
  80. React.createElement(Card, { item: Words[3], key: 3, "data-set": { GridX: 3 * 3, GridY: 0, w: 3, h: 3 } }))))));
  81. };
  82. return HandleLayout;
  83. }(React.Component));
  84. export { HandleLayout };