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');
|
|
|
|
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
|
|
|
type StyleProps = any;
|
|
|
|
|
2020-10-09 19:35:46 +02:00
|
|
|
interface Props {
|
2020-11-12 21:29:22 +02:00
|
|
|
buttons: ButtonSpec[];
|
2020-10-09 19:35:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const StyledRoot = styled.div`
|
|
|
|
display: flex;
|
|
|
|
width: 100%;
|
|
|
|
box-sizing: border-box;
|
|
|
|
justify-content: flex-end;
|
2024-04-05 13:16:49 +02:00
|
|
|
padding-top: ${(props: StyleProps) => props.theme.mainPadding}px;
|
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 (
|
|
|
|
<StyledRoot>
|
|
|
|
{renderButtons()}
|
|
|
|
</StyledRoot>
|
|
|
|
);
|
|
|
|
}
|