diff options
Diffstat (limited to 'src/components/settings/SettingsLayout.jsx')
-rw-r--r-- | src/components/settings/SettingsLayout.jsx | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/components/settings/SettingsLayout.jsx b/src/components/settings/SettingsLayout.jsx new file mode 100644 index 000000000..dea4bb387 --- /dev/null +++ b/src/components/settings/SettingsLayout.jsx | |||
@@ -0,0 +1,80 @@ | |||
1 | import { Component } from 'react'; | ||
2 | import PropTypes from 'prop-types'; | ||
3 | import { observer } from 'mobx-react'; | ||
4 | import { defineMessages, injectIntl } from 'react-intl'; | ||
5 | |||
6 | import { mdiClose } from '@mdi/js'; | ||
7 | import { Outlet } from 'react-router-dom'; | ||
8 | import ErrorBoundary from '../util/ErrorBoundary'; | ||
9 | import Appear from '../ui/effects/Appear'; | ||
10 | import Icon from '../ui/icon'; | ||
11 | |||
12 | const messages = defineMessages({ | ||
13 | closeSettings: { | ||
14 | id: 'settings.app.closeSettings', | ||
15 | defaultMessage: 'Close settings', | ||
16 | }, | ||
17 | }); | ||
18 | |||
19 | class SettingsLayout extends Component { | ||
20 | static propTypes = { | ||
21 | navigation: PropTypes.element.isRequired, | ||
22 | closeSettings: PropTypes.func.isRequired, | ||
23 | }; | ||
24 | |||
25 | componentDidMount() { | ||
26 | document.addEventListener('keydown', this.handleKeyDown.bind(this), false); | ||
27 | } | ||
28 | |||
29 | componentWillUnmount() { | ||
30 | document.removeEventListener( | ||
31 | 'keydown', | ||
32 | // eslint-disable-next-line unicorn/no-invalid-remove-event-listener | ||
33 | this.handleKeyDown.bind(this), | ||
34 | false, | ||
35 | ); | ||
36 | } | ||
37 | |||
38 | handleKeyDown(e) { | ||
39 | if (e.keyCode === 27) { | ||
40 | // escape key | ||
41 | this.props.closeSettings(); | ||
42 | } | ||
43 | } | ||
44 | |||
45 | render() { | ||
46 | const { navigation, closeSettings } = this.props; | ||
47 | |||
48 | const { intl } = this.props; | ||
49 | |||
50 | return ( | ||
51 | <Appear transitionName="fadeIn-fast"> | ||
52 | <div className="settings-wrapper"> | ||
53 | <ErrorBoundary> | ||
54 | <button | ||
55 | type="button" | ||
56 | className="settings-wrapper__action" | ||
57 | onClick={closeSettings} | ||
58 | aria-label={intl.formatMessage(messages.closeSettings)} | ||
59 | /> | ||
60 | <div className="settings franz-form"> | ||
61 | {navigation} | ||
62 | |||
63 | <Outlet /> | ||
64 | <button | ||
65 | type="button" | ||
66 | className="settings__close" | ||
67 | onClick={closeSettings} | ||
68 | aria-label={intl.formatMessage(messages.closeSettings)} | ||
69 | > | ||
70 | <Icon icon={mdiClose} size={1.35} /> | ||
71 | </button> | ||
72 | </div> | ||
73 | </ErrorBoundary> | ||
74 | </div> | ||
75 | </Appear> | ||
76 | ); | ||
77 | } | ||
78 | } | ||
79 | |||
80 | export default injectIntl(observer(SettingsLayout)); | ||