index.tsx 2.2 KB

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