index.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import *as React from 'react';
  2. import { DragactLayoutItem, GridItemProvided } from '../../src/lib/dragact-type'
  3. import { HistoryDragact } from './HistoryLayout'
  4. import { Words } from './largedata';
  5. import './index.css';
  6. const fakeData = () => {
  7. var Y = 0;
  8. return Words.map((item, index) => {
  9. if (index % 4 === 0) Y++;
  10. return { ...item, GridX: index % 4 * 4, GridY: Y * 4, w: 4, h: 3, key: index + '' }
  11. })
  12. }
  13. export const Card: (any: any) => any = ({ item, provided }) => {
  14. return (
  15. <div
  16. className='layout-Item'
  17. {...provided.props}
  18. {...provided.dragHandle}
  19. style={{
  20. ...provided.props.style,
  21. background: `${provided.isDragging ? '#eaff8f' : 'white'}`
  22. }}
  23. >
  24. <div
  25. style={{ padding: 5, textAlign: 'center', color: '#595959' }}
  26. >
  27. <span>title</span>
  28. <div style={{ borderBottom: '1px solid rgba(120,120,120,0.1)' }} />
  29. {item.content}
  30. </div>
  31. <span
  32. {...provided.resizeHandle}
  33. style={{
  34. position: 'absolute',
  35. width: 10, height: 10, right: 2, bottom: 2, cursor: 'se-resize',
  36. borderRight: '2px solid rgba(15,15,15,0.2)',
  37. borderBottom: '2px solid rgba(15,15,15,0.2)'
  38. }}
  39. />
  40. </div>
  41. )
  42. }
  43. export class HistoryDemo extends React.Component<{}, {}> {
  44. drag: HistoryDragact | null
  45. render() {
  46. const margin: [number, number] = [5, 5];
  47. const dragactInit = {
  48. width: 600,
  49. col: 16,
  50. rowHeight: 40,
  51. margin: margin,
  52. className: 'normal-layout',
  53. layout: fakeData()
  54. }
  55. return (
  56. <div
  57. style={{
  58. display: 'flex',
  59. justifyContent: 'center'
  60. }}
  61. >
  62. <div>
  63. <h1 style={{ textAlign: 'center' }}>
  64. 复原操作demo
  65. </h1>
  66. <button onClick={() => {
  67. if (this.drag) {
  68. this.drag.goBack();
  69. }
  70. }}>back</button>
  71. <button onClick={() => {
  72. if (this.drag) {
  73. this.drag.reset();
  74. }
  75. }}>reset</button>
  76. <button onClick={() => {
  77. if (this.drag) {
  78. this.drag.clear();
  79. }
  80. }}>clear</button>
  81. <HistoryDragact
  82. {...dragactInit}
  83. placeholder={true}
  84. ref={n => this.drag = n}
  85. style={{
  86. background: '#003A8C'
  87. }}
  88. >
  89. {(item: DragactLayoutItem, provided: GridItemProvided) => {
  90. return <Card
  91. item={item}
  92. provided={provided}
  93. />
  94. }}
  95. </HistoryDragact>
  96. </div>
  97. </div>
  98. )
  99. }
  100. }