index.tsx 2.3 KB

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