FunctionEditorControls.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import React from 'react';
  2. export interface FunctionDescriptor {
  3. text: string;
  4. params: string[];
  5. def: {
  6. category: string;
  7. defaultParams: string[];
  8. description?: string;
  9. fake: boolean;
  10. name: string;
  11. params: string[];
  12. };
  13. }
  14. export interface FunctionEditorControlsProps {
  15. onMoveLeft: (func: FunctionDescriptor) => void;
  16. onMoveRight: (func: FunctionDescriptor) => void;
  17. onRemove: (func: FunctionDescriptor) => void;
  18. }
  19. const FunctionHelpButton = (props: { description: string; name: string; onDescriptionShow: () => void }) => {
  20. if (props.description) {
  21. return <span className="pointer fa fa-question-circle" onClick={props.onDescriptionShow} />;
  22. }
  23. return (
  24. <span
  25. className="pointer fa fa-question-circle"
  26. onClick={() => {
  27. window.open(
  28. 'http://graphite.readthedocs.org/en/latest/functions.html#graphite.render.functions.' + props.name,
  29. '_blank'
  30. );
  31. }}
  32. />
  33. );
  34. };
  35. export const FunctionEditorControls = (
  36. props: FunctionEditorControlsProps & {
  37. func: FunctionDescriptor;
  38. onDescriptionShow: () => void;
  39. }
  40. ) => {
  41. const { func, onMoveLeft, onMoveRight, onRemove, onDescriptionShow } = props;
  42. return (
  43. <div
  44. style={{
  45. display: 'flex',
  46. width: '60px',
  47. justifyContent: 'space-between',
  48. }}
  49. >
  50. <span className="pointer fa fa-arrow-left" onClick={() => onMoveLeft(func)} />
  51. <FunctionHelpButton
  52. name={func.def.name}
  53. description={func.def.description}
  54. onDescriptionShow={onDescriptionShow}
  55. />
  56. <span className="pointer fa fa-remove" onClick={() => onRemove(func)} />
  57. <span className="pointer fa fa-arrow-right" onClick={() => onMoveRight(func)} />
  58. </div>
  59. );
  60. };