index.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. import { Words } from './largedata';
  22. import './index.css';
  23. var fakeData = function () {
  24. var Y = 0;
  25. return Words.map(function (item, index) {
  26. if (index % 4 === 0)
  27. Y++;
  28. return __assign({}, item, { GridX: index % 4 * 4, GridY: Y * 4, w: 4, h: 3, key: index + '' });
  29. });
  30. };
  31. export var Card = function (_a) {
  32. var item = _a.item, provided = _a.provided;
  33. return (React.createElement("div", __assign({ className: 'layout-Item' }, provided.props, provided.dragHandle, { style: __assign({}, provided.props.style, { background: "" + (provided.isDragging ? '#eaff8f' : 'white') }) }),
  34. React.createElement("div", { style: { padding: 5, textAlign: 'center', color: '#595959' } },
  35. React.createElement("span", null, "title"),
  36. React.createElement("div", { style: { borderBottom: '1px solid rgba(120,120,120,0.1)' } }),
  37. item.content),
  38. React.createElement("span", __assign({}, provided.resizeHandle, { style: {
  39. position: 'absolute',
  40. width: 10, height: 10, right: 2, bottom: 2, cursor: 'se-resize',
  41. borderRight: '2px solid rgba(15,15,15,0.2)',
  42. borderBottom: '2px solid rgba(15,15,15,0.2)'
  43. } }))));
  44. };
  45. var LayoutDemo = /** @class */ (function (_super) {
  46. __extends(LayoutDemo, _super);
  47. function LayoutDemo() {
  48. return _super !== null && _super.apply(this, arguments) || this;
  49. }
  50. LayoutDemo.prototype.render = function () {
  51. var margin = [5, 5];
  52. var dragactInit = {
  53. width: 600,
  54. col: 16,
  55. rowHeight: 40,
  56. margin: margin,
  57. className: 'normal-layout',
  58. layout: fakeData()
  59. };
  60. return (React.createElement("div", { style: {
  61. display: 'flex',
  62. justifyContent: 'center'
  63. } },
  64. React.createElement("div", null,
  65. React.createElement("h1", { style: { textAlign: 'center' } }, "\u666E\u901A\u5E03\u5C40demo"),
  66. React.createElement(Dragact, __assign({}, dragactInit, { placeholder: true, style: {
  67. background: '#003A8C'
  68. } }), function (item, provided) {
  69. return React.createElement(Card, { item: item, provided: provided });
  70. }))));
  71. };
  72. return LayoutDemo;
  73. }(React.Component));
  74. export { LayoutDemo };