index.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import * as React from 'react';
  2. import { Dragact } from '../../src/lib/dragact'
  3. import './index.css'
  4. const Words = [
  5. { content: 'Sorry I just can not move in any circumstances', static: true },
  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: 'Sorry I just can not move in any circumstances,too' },
  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: 4, key: index + '', canResize: false }
  16. })
  17. }
  18. const Cell: (any: any) => any = ({ item, provided }) => {
  19. return (
  20. <div
  21. {...provided.props}
  22. {...provided.dragHandle}
  23. className={`layout-Cell ${item.static ? "static" : ""}`}
  24. style={{ ...provided.props.style, background: item.static ? "#e8e8e8" : "" }}
  25. >
  26. <div style={{ padding: 10, color: '#595959' }}>{item.content}</div>
  27. </div>
  28. )
  29. }
  30. export const SortedTableWithStatic = () => {
  31. return (
  32. <div style={{ display: 'flex', justifyContent: 'center' }}>
  33. <div>
  34. <h1 style={{ textAlign: 'center' }}>静态组件 Demo</h1>
  35. <Dragact
  36. width={600}
  37. col={16}
  38. rowHeight={30}
  39. margin={[2, 2]}
  40. className='normal-layout'
  41. layout={fakeData()}
  42. placeholder={true}
  43. >
  44. {(item: any, provided: any) => {
  45. return <Cell item={item} provided={provided} />
  46. }}
  47. </Dragact>
  48. </div>
  49. </div>
  50. )
  51. }