import React from 'react' import { useKeyboardListener, useAsyncCallback } from 'actionsack' import { COLORS, EXPORT_SIZES } from '../lib/constants' import Button from './Button' import Input from './Input' import Popout, { managePopout } from './Popout' import { Down as ArrowDown } from './svg/Arrows' const popoutStyle = { width: '256px', right: 0 } function preventDefault(fn) { return e => { e.preventDefault() return fn(e) } } function ExportMenu({ onChange, exportSize, isVisible, toggleVisibility, exportImage: exp }) { const input = React.useRef() const [exportImage, { loading }] = useAsyncCallback(exp) const handleExportSizeChange = selectedSize => () => onChange('exportSize', selectedSize) const handleExport = format => () => exportImage(format, { filename: input.current && input.current.value }) useKeyboardListener('⌘-⇧-e', preventDefault(handleExport('blob'))) useKeyboardListener('⌘-⇧-s', preventDefault(handleExport('svg'))) return (