1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-12 08:54:00 +02:00
joplin/packages/app-desktop/services/plugins/UserWebviewDialogButtonBar.tsx
2020-11-05 16:58:23 +00:00

53 lines
1.3 KiB
TypeScript

import * as React from 'react';
import Button from '../../gui/Button/Button';
import { _ } from '@joplinapp/lib/locale';
import { ButtonSpec } from '@joplinapp/lib/services/plugins/api/types';
const styled = require('styled-components').default;
const { space } = require('styled-system');
interface Props {
buttons: ButtonSpec[],
}
const StyledRoot = styled.div`
display: flex;
width: 100%;
box-sizing: border-box;
justify-content: flex-end;
padding-top: ${(props:any) => props.theme.mainPadding}px;
`;
const StyledButton = styled(Button)`${space}`;
function buttonTitle(b:ButtonSpec) {
if (b.title) return b.title;
const defaultTitles:any = {
'ok': _('OK'),
'cancel': _('Cancel'),
'yes': _('Yes'),
'no': _('No'),
'close': _('Close'),
};
return defaultTitles[b.id] ? defaultTitles[b.id] : b.id;
}
export default function UserWebviewDialogButtonBar(props:Props) {
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>
);
}