const React = require('react'); import { useMemo } from 'react'; const { _ } = require('@joplin/lib/locale'); const { themeStyle } = require('@joplin/lib/theme'); export interface ButtonSpec { name: string; label: string; } export interface ClickEvent { buttonName: string; } export type ClickEventHandler = (event: ClickEvent)=> void; interface Props { themeId: number; onClick?: ClickEventHandler; okButtonShow?: boolean; cancelButtonShow?: boolean; cancelButtonLabel?: string; okButtonRef?: any; customButtons?: ButtonSpec[]; } export default function DialogButtonRow(props: Props) { const theme = themeStyle(props.themeId); const buttonStyle = useMemo(() => { return { ...theme.buttonStyle, marginLeft: 10, }; }, [theme.buttonStyle]); const okButton_click = () => { if (props.onClick) props.onClick({ buttonName: 'ok' }); }; const cancelButton_click = () => { if (props.onClick) props.onClick({ buttonName: 'cancel' }); }; const customButton_click = (event: ClickEvent) => { if (props.onClick) props.onClick(event); }; const onKeyDown = (event: any) => { if (event.keyCode === 13) { okButton_click(); } else if (event.keyCode === 27) { cancelButton_click(); } }; const buttonComps = []; if (props.customButtons) { for (const b of props.customButtons) { buttonComps.push( ); } } if (props.okButtonShow !== false) { buttonComps.push( ); } if (props.cancelButtonShow !== false) { buttonComps.push( ); } return