index.tsx 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import * as React from 'react'
  2. import { Dragact } from '../../src/lib/dragact'
  3. import { DragactLayoutItem, GridItemProvided } from '../../src/lib/dragact-type'
  4. import './index.css'
  5. const Words = [
  6. { content: 'You can do anything, but not everything.' },
  7. { content: 'Those who dare to fail miserably can achieve greatly.' },
  8. { content: 'You miss 100 percent of the shots you never take.' },
  9. { content: 'Those who believe in telekinetics, raise my hand.' },
  10. { content: 'I’d rather live with a good question than a bad answer.' }
  11. ]
  12. const fakeData = () => {
  13. var Y = 0
  14. return Words.map((item, index) => {
  15. if (index % 4 === 0) Y++
  16. return {
  17. ...item,
  18. GridX: (index % 4) * 4,
  19. GridY: Y * 4,
  20. w: 4,
  21. h: 2,
  22. key: index + ''
  23. }
  24. })
  25. }
  26. const Card: (item: any) => any = ({ item, provided }) => {
  27. if (item.key !== '3') {
  28. return (
  29. <div
  30. className="layout-Item"
  31. {...provided.props}
  32. {...provided.dragHandle}
  33. >
  34. <div
  35. style={{
  36. padding: 5,
  37. textAlign: 'center',
  38. color: '#595959'
  39. }}
  40. >
  41. {item.content}
  42. </div>
  43. </div>
  44. )
  45. }
  46. return (
  47. <div className="layout-Item" {...provided.props}>
  48. <div style={{ padding: 5, textAlign: 'center', color: '#595959' }}>
  49. {item.content}
  50. <div className="card-handle" {...provided.dragHandle}>
  51. 点我拖动
  52. </div>
  53. </div>
  54. </div>
  55. )
  56. }
  57. export class HandleLayout extends React.Component<{}, {}> {
  58. render() {
  59. const margin: [number, number] = [5, 5]
  60. const dragactInit = {
  61. width: 600,
  62. col: 12,
  63. rowHeight: 800 / 12,
  64. margin: margin,
  65. className: 'normal-layout',
  66. layout: fakeData(),
  67. placeholder: true
  68. }
  69. return (
  70. <div>
  71. <div style={{ display: 'flex', justifyContent: 'center' }}>
  72. <div>
  73. <h1 style={{ textAlign: 'center' }}>拖拽把手 Demo</h1>
  74. <Dragact {...dragactInit}>
  75. {(
  76. item: DragactLayoutItem,
  77. provided: GridItemProvided
  78. ) => {
  79. return <Card item={item} provided={provided} />
  80. }}
  81. </Dragact>
  82. </div>
  83. </div>
  84. </div>
  85. )
  86. }
  87. }