index.tsx 2.2 KB

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