|
| 1 | +import React from "react"; |
| 2 | +import { ScrollStory } from "./"; |
| 3 | +import { ScrollTo } from "../src/index"; |
| 4 | +import { Object } from "es6-shim"; |
| 5 | + |
| 6 | +const refDOM = React.createRef(); |
| 7 | +const mockData = { |
| 8 | + region: ["East", "West", "Central"], |
| 9 | + color: ["red", "green", "blue"], |
| 10 | + item: ["pencil", "paper", "pen", "globe", "cup", "candy"], |
| 11 | + qty: [1, 200, 3.2, 4, 5, 6.55, 7, 8] |
| 12 | +}; |
| 13 | + |
| 14 | +ScrollStory.add("Scroll by Ref", () => { |
| 15 | + return ( |
| 16 | + <div style={{ overflow: "auto", padding: 20 }}> |
| 17 | + <ScrollTo> |
| 18 | + {({ scrollTo }) => ( |
| 19 | + <React.Fragment> |
| 20 | + <button |
| 21 | + type="button" |
| 22 | + onClick={() => scrollTo({ ref: refDOM, y: 700, smooth: true })} |
| 23 | + > |
| 24 | + Scroll Ref Down |
| 25 | + </button> |
| 26 | + |
| 27 | + <button |
| 28 | + type="button" |
| 29 | + style={{ marginLeft: 5 }} |
| 30 | + onClick={() => scrollTo({ ref: refDOM, y: 0, smooth: true })} |
| 31 | + > |
| 32 | + Scroll Ref Up |
| 33 | + </button> |
| 34 | + </React.Fragment> |
| 35 | + )} |
| 36 | + </ScrollTo> |
| 37 | + |
| 38 | + <div |
| 39 | + ref={refDOM} |
| 40 | + style={{ |
| 41 | + marginTop: 20, |
| 42 | + background: "#F1F1F1", |
| 43 | + height: 1000, |
| 44 | + maxHeight: 300, |
| 45 | + overflow: "auto", |
| 46 | + position: "relative" |
| 47 | + }} |
| 48 | + > |
| 49 | + <div style={{ height: 1000, padding: 20 }}> |
| 50 | + <table> |
| 51 | + <thead> |
| 52 | + <tr> |
| 53 | + {Object.keys(mockData).map(key => ( |
| 54 | + <th key={key}>{key}</th> |
| 55 | + ))} |
| 56 | + </tr> |
| 57 | + </thead> |
| 58 | + <tbody> |
| 59 | + {Array.from({ length: 40 }).map((_, i) => { |
| 60 | + return ( |
| 61 | + <tr key={i}> |
| 62 | + {Object.keys(mockData).map(key => ( |
| 63 | + <td key={key + i}> |
| 64 | + {mockData[key][i % mockData[key].length]} |
| 65 | + </td> |
| 66 | + ))} |
| 67 | + </tr> |
| 68 | + ); |
| 69 | + })} |
| 70 | + </tbody> |
| 71 | + </table> |
| 72 | + </div> |
| 73 | + </div> |
| 74 | + </div> |
| 75 | + ); |
| 76 | +}); |
0 commit comments