index.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 { ...item, GridX: index % 4 * 4, GridY: Y * 4, w: 4, h: 2, key: index + '' }
  17. })
  18. }
  19. const Card: (item: any) => any = ({ item, provided }) => {
  20. const style = { padding: 5, textAlign: 'center', color: '#595959' }
  21. if (item.key !== '3') {
  22. return (
  23. <div className='layout-Item' {...provided.props} {...provided.dragHandle}>
  24. <div style={style}>
  25. {item.content}
  26. </div>
  27. </div>
  28. )
  29. }
  30. return (
  31. <div className='layout-Item' {...provided.props}>
  32. <div style={style}>
  33. {item.content}
  34. <div className='card-handle' {...provided.dragHandle} >点我拖动</div>
  35. </div>
  36. </div>
  37. )
  38. }
  39. export class HandleLayout extends React.Component<{}, {}> {
  40. render() {
  41. const margin: [number, number] = [5, 5];
  42. const dragactInit = {
  43. width: 600,
  44. col: 12,
  45. rowHeight: 800 / 12,
  46. margin: margin,
  47. className: 'normal-layout',
  48. layout: fakeData(),
  49. placeholder: true
  50. }
  51. return (
  52. <div>
  53. <div style={{ display: 'flex', justifyContent: 'center' }} >
  54. <div>
  55. <h1 style={{ textAlign: 'center' }}>拖拽把手 Demo</h1>
  56. <Dragact {...dragactInit} >
  57. {(item: DragactLayoutItem, provided: GridItemProvided) => {
  58. return <Card item={item} provided={provided} />
  59. }}
  60. </Dragact>
  61. </div>
  62. </div>
  63. </div>
  64. )
  65. }
  66. }