index.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import *as React from 'react';
  2. import { Dragact, DragactLayoutItem, GridItemProvided } from '../lib/dragact'
  3. import { Words } from './largedata'
  4. import './index.css';
  5. interface CardItem {
  6. content: string,
  7. img: string
  8. }
  9. const fakeData = () => {
  10. var Y = 0;
  11. return Words.map((item, index) => {
  12. if (index % 4 === 0) Y++;
  13. return { ...item, GridX: index % 4 * 4, GridY: Y * 4, w: 4, h: 3, key: index + '' }
  14. })
  15. }
  16. const Card = (props: any) => {
  17. const item: CardItem = props.item;
  18. const provided: any = props.provided;
  19. console.log(...provided.draggerProps)
  20. return (
  21. <div
  22. className='layout-Item'
  23. {...provided.draggerProps}
  24. style={{
  25. ...provided.draggerProps.style,
  26. background: `${provided.isDragging ? '#eaff8f' : 'white'}`
  27. }}
  28. {...provided.handle}
  29. >
  30. <div
  31. style={{ padding: 5, textAlign: 'center', color: '#595959' }}
  32. >
  33. <span>title</span>
  34. <div style={{ borderBottom: '1px solid rgba(120,120,120,0.1)' }} />
  35. {item.content}
  36. </div>
  37. <span
  38. {...provided.resizerProps}
  39. style={{
  40. position: 'absolute',
  41. width: 10, height: 10, right: 2, bottom: 2, cursor: 'se-resize',
  42. borderRight: '2px solid rgba(15,15,15,0.2)',
  43. borderBottom: '2px solid rgba(15,15,15,0.2)'
  44. }}
  45. />
  46. </div>
  47. )
  48. }
  49. export class LayoutDemo extends React.Component<{}, {}> {
  50. render() {
  51. const margin: [number, number] = [5, 5];
  52. const dragactInit = {
  53. width: 600,
  54. col: 16,
  55. rowHeight: 40,
  56. margin: margin,
  57. className: 'normal-layout',
  58. layout: fakeData()
  59. }
  60. return (
  61. <div
  62. style={{
  63. display: 'flex',
  64. justifyContent: 'center'
  65. }}
  66. >
  67. <div>
  68. <h1 style={{ textAlign: 'center' }}>
  69. 普通布局demo
  70. </h1>
  71. <Dragact
  72. {...dragactInit}
  73. placeholder={true}
  74. style={{
  75. background: '#003A8C'
  76. }}
  77. >
  78. {(item: DragactLayoutItem, provided: GridItemProvided) => {
  79. return <Card
  80. item={item}
  81. provided={provided}
  82. />
  83. }}
  84. </Dragact>
  85. </div>
  86. </div>
  87. )
  88. }
  89. }