Advertisement
Guest User

Untitled

a guest
May 25th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. const React = require('react');
  2. const ReactDOM = require('react-dom');
  3. const Format = require('d3-format');
  4. const Drag = require('d3-drag');
  5. const Selection = require('d3-selection');
  6.  
  7. class ArrayDynamic extends React.PureComponent {
  8.  
  9. componentDidMount() {
  10. let node;
  11. try {
  12. node = ReactDOM.findDOMNode(this);
  13. } catch(e) {};
  14. if (!node) {
  15. return;
  16. }
  17. this.drag = Drag.drag().on('drag', () => {
  18. const dx = Selection.event.dx;
  19. var { step, value, interval, array, min, max } = this.props;
  20. min = Math.min(min, 0);
  21. max = Math.min(max, array.length - 1);
  22. step = Math.round(step); // Must be an integer
  23. const newValue = Math.max(Math.min(value + (step || interval) * dx, max), min);
  24. this.props.updateProps({ value: newValue });
  25. });
  26. this.drag(Selection.select(node));
  27. }
  28.  
  29. render() {
  30. const { format, value, array } = this.props;
  31. const formatter = Format.format(format);
  32. return (
  33. <span className="idyll-dynamic">
  34. {array[value]}
  35. </span>
  36. );
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement