index.tsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import *as React from 'react';
  2. import { Dragact } from '../../src/lib/dragact'
  3. import { DragactLayoutItem, GridItemProvided } from '../../src/lib/dragact-type'
  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 LayoutDemo extends React.Component<{}, {}> {
  44. render() {
  45. const margin: [number, number] = [5, 5];
  46. const dragactInit = {
  47. width: 600,
  48. col: 16,
  49. rowHeight: 40,
  50. margin: margin,
  51. className: 'normal-layout',
  52. layout: fakeData()
  53. }
  54. return (
  55. <div
  56. style={{
  57. display: 'flex',
  58. justifyContent: 'center'
  59. }}
  60. >
  61. <div>
  62. <h1 style={{ textAlign: 'center' }}>
  63. 普通布局demo
  64. </h1>
  65. <Dragact
  66. {...dragactInit}
  67. placeholder={true}
  68. style={{
  69. background: '#003A8C'
  70. }}
  71. >
  72. {(item: DragactLayoutItem, provided: GridItemProvided) => {
  73. return <Card
  74. item={item}
  75. provided={provided}
  76. />
  77. }}
  78. </Dragact>
  79. </div>
  80. </div>
  81. )
  82. }
  83. }