2023-01-19 19:19:06 +02:00
|
|
|
import * as React from 'react';
|
2019-05-06 22:35:29 +02:00
|
|
|
const { connect } = require('react-redux');
|
2023-01-19 19:19:06 +02:00
|
|
|
import { themeStyle } from '@joplin/lib/theme';
|
|
|
|
import { AppState } from '../app.reducer';
|
2024-08-05 20:37:23 +02:00
|
|
|
import { _ } from '@joplin/lib/locale';
|
2019-05-06 22:35:29 +02:00
|
|
|
|
2023-01-19 19:19:06 +02:00
|
|
|
interface Props {
|
|
|
|
tip: string;
|
2023-06-30 11:30:29 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-types -- Old code before rule was applied
|
2023-01-19 19:19:06 +02:00
|
|
|
onClick: Function;
|
|
|
|
themeId: number;
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2023-01-19 19:19:06 +02:00
|
|
|
style: any;
|
2024-08-05 20:37:23 +02:00
|
|
|
|
|
|
|
'aria-controls'?: string;
|
|
|
|
'aria-expanded'?: string;
|
2023-01-19 19:19:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class HelpButtonComponent extends React.Component<Props> {
|
2023-03-06 16:22:01 +02:00
|
|
|
public constructor(props: Props) {
|
2023-01-19 19:19:06 +02:00
|
|
|
super(props);
|
2019-05-06 22:35:29 +02:00
|
|
|
|
|
|
|
this.onClick = this.onClick.bind(this);
|
|
|
|
}
|
|
|
|
|
2023-03-06 16:22:01 +02:00
|
|
|
public onClick() {
|
2019-05-06 22:35:29 +02:00
|
|
|
if (this.props.onClick) this.props.onClick();
|
|
|
|
}
|
|
|
|
|
2023-03-06 16:22:01 +02:00
|
|
|
public render() {
|
2020-09-15 15:01:07 +02:00
|
|
|
const theme = themeStyle(this.props.themeId);
|
2023-06-01 13:02:36 +02:00
|
|
|
const style = { ...this.props.style, color: theme.color, textDecoration: 'none' };
|
2019-07-29 14:13:23 +02:00
|
|
|
const helpIconStyle = { flex: 0, width: 16, height: 16, marginLeft: 10 };
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2023-01-19 19:19:06 +02:00
|
|
|
const extraProps: any = {};
|
2024-08-05 20:37:23 +02:00
|
|
|
if (this.props.tip) {
|
|
|
|
extraProps['data-tip'] = this.props.tip;
|
|
|
|
extraProps['aria-description'] = this.props.tip;
|
|
|
|
}
|
2019-07-29 14:13:23 +02:00
|
|
|
return (
|
2024-08-05 20:37:23 +02:00
|
|
|
<button
|
|
|
|
style={style}
|
|
|
|
onClick={this.onClick}
|
|
|
|
className='flat-button'
|
|
|
|
aria-controls={this.props['aria-controls']}
|
|
|
|
aria-expanded={this.props['aria-expanded']}
|
|
|
|
{...extraProps}
|
|
|
|
>
|
|
|
|
<i style={helpIconStyle} className={'fa fa-question-circle'} role='img' aria-label={_('Help')}></i>
|
|
|
|
</button>
|
2019-07-29 14:13:23 +02:00
|
|
|
);
|
2019-05-06 22:35:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-19 19:19:06 +02:00
|
|
|
const mapStateToProps = (state: AppState) => {
|
2019-05-06 22:35:29 +02:00
|
|
|
return {
|
2020-09-15 15:01:07 +02:00
|
|
|
themeId: state.settings.theme,
|
2019-05-06 22:35:29 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const HelpButton = connect(mapStateToProps)(HelpButtonComponent);
|
|
|
|
|
2023-01-19 19:19:06 +02:00
|
|
|
export default HelpButton;
|