index.tsx 2.6 KB

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