-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThemeSwitcher.jsx
102 lines (97 loc) · 3.93 KB
/
ThemeSwitcher.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
* Copyright 2016-2021 Sourcepole AG
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import PropTypes from 'prop-types';
import {connect} from 'react-redux';
import Icon from '../components/Icon';
import InputContainer from '../components/InputContainer';
import SideBar from '../components/SideBar';
import ThemeList from '../components/ThemeList';
import ConfigUtils from '../utils/ConfigUtils';
import LocaleUtils from '../utils/LocaleUtils';
import ThemeLayersListWindow from '../components/ThemeLayersListWindow';
import './style/ThemeSwitcher.css';
/**
* Theme switcher panel.
*/
class ThemeSwitcher extends React.Component {
static propTypes = {
activeTheme: PropTypes.object,
/** Whether to allow collapsing theme groups. */
collapsibleGroups: PropTypes.bool,
currentTask: PropTypes.object,
/** Whether to show the LayerTree by default after switching the theme. */
showLayerAfterChangeTheme: PropTypes.bool,
/** Wether to show the theme filter field in the top bar. **/
showThemeFilter: PropTypes.bool,
/** The side of the application on which to display the sidebar. */
side: PropTypes.string,
/** The default window size for the theme layers dialog. */
themeLayersListWindowSize: PropTypes.shape({
width: PropTypes.number,
height: PropTypes.number
}),
/** Default width as a CSS string. */
width: PropTypes.string
};
static defaultProps = {
width: "50%",
showThemeFilter: true,
showLayerAfterChangeTheme: false,
themeLayersListWindowSize: {width: 400, height: 300},
side: 'right'
};
state = {
filter: ""
};
render() {
const allowAddingOtherThemes = ConfigUtils.getConfigProp("allowAddingOtherThemes", this.props.activeTheme) === true;
const themeFilter = this.props.showThemeFilter ? (
<InputContainer className="theme-switcher-filter">
<input onChange={ev => this.setState({filter: ev.target.value})}
placeholder={LocaleUtils.tr("themeswitcher.filter")}
ref={this.focusFilterField} role="input"
type="text" value={this.state.filter}/>
<Icon icon="remove" onClick={() => this.setState({filter: ""})} role="suffix" />
</InputContainer>
) : null;
const extraTitlebarContent = (themeFilter)
return (
<div>
<SideBar extraTitlebarContent={extraTitlebarContent} icon="themes" id="ThemeSwitcher" minWidth="16em" side={this.props.side}
title="appmenu.items.ThemeSwitcher" width={this.props.width}>
{() => ({
body: (
<ThemeList
activeTheme={this.props.activeTheme}
allowAddingOtherThemes={allowAddingOtherThemes}
collapsibleGroups={this.props.collapsibleGroups}
filter={this.state.filter}
showLayerAfterChangeTheme={this.props.showLayerAfterChangeTheme} />
)
})}
</SideBar>
<ThemeLayersListWindow windowSize={this.props.themeLayersListWindowSize} />
</div>
);
}
focusFilterField = (el) => {
if (el) {
// Need to wait until slide in transition is over
setTimeout(() => {
if (this.props.currentTask && this.props.currentTask.id === "ThemeSwitcher") {
el.focus();
}
}, 500);
}
};
}
const selector = (state) => ({
activeTheme: state.theme.current
});
export default connect(selector, {})(ThemeSwitcher);