2020-10-09 19:35:46 +02:00
|
|
|
import * as React from 'react';
|
|
|
|
import Button from '../../gui/Button/Button';
|
2020-11-07 17:59:37 +02:00
|
|
|
import { _ } from '@joplin/lib/locale';
|
|
|
|
import { ButtonSpec } from '@joplin/lib/services/plugins/api/types';
|
2020-10-09 19:35:46 +02:00
|
|
|
const styled = require('styled-components').default;
|
|
|
|
const { space } = require('styled-system');
|
|
|
|
|
|
|
|
interface Props {
|
2020-11-12 21:29:22 +02:00
|
|
|
buttons: ButtonSpec[];
|
2020-10-09 19:35:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const StyledButton = styled(Button)`${space}`;
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
function buttonTitle(b: ButtonSpec) {
|
2020-10-09 19:35:46 +02:00
|
|
|
if (b.title) return b.title;
|
|
|
|
|
2024-04-05 13:16:49 +02:00
|
|
|
const defaultTitles: Record<string, string> = {
|
2020-10-09 19:35:46 +02:00
|
|
|
'ok': _('OK'),
|
|
|
|
'cancel': _('Cancel'),
|
|
|
|
'yes': _('Yes'),
|
|
|
|
'no': _('No'),
|
|
|
|
'close': _('Close'),
|
|
|
|
};
|
|
|
|
|
|
|
|
return defaultTitles[b.id] ? defaultTitles[b.id] : b.id;
|
|
|
|
}
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
export default function UserWebviewDialogButtonBar(props: Props) {
|
2020-10-09 19:35:46 +02:00
|
|
|
function renderButtons() {
|
|
|
|
const output = [];
|
|
|
|
for (let i = 0; i < props.buttons.length; i++) {
|
|
|
|
const b = props.buttons[i];
|
|
|
|
const marginRight = i !== props.buttons.length - 1 ? '6px' : '0px';
|
|
|
|
output.push(<StyledButton key={b.id} onClick={b.onClick} title={buttonTitle(b)} mr={marginRight}/>);
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2024-10-11 23:03:41 +02:00
|
|
|
<div className='user-dialog-button-bar'>
|
2020-10-09 19:35:46 +02:00
|
|
|
{renderButtons()}
|
2024-10-11 23:03:41 +02:00
|
|
|
</div>
|
2020-10-09 19:35:46 +02:00
|
|
|
);
|
|
|
|
}
|