This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
index.js
82 lines (69 loc) · 2.54 KB
/
index.js
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
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Card, Tabs, Tab, InitialTab, CardContent } from './styled'
// material-ui-icons
import LayersIcon from '@material-ui/icons/Layers'
import IconButton from '@material-ui/core/IconButton'
import CloseIcon from '@material-ui/icons/Close'
import Typography from '@material-ui/core/Typography'
import { connectToContext } from 'Provider'
/**
* @component
* @category LayerPanel
* @since 0.5.0
*/
class LayerPanelBase extends Component {
constructor (props) {
super(props)
this.state = {
activeIndex: 0,
showLayerPanel: false
}
}
handleChange = (_, activeIndex) => {
this.setState({ activeIndex })
}
showLayerPanel = () => {
this.setState({ showLayerPanel: true })
}
hideLayerPanel = () => {
this.setState({ showLayerPanel: false })
}
render () {
const { inline, style, children, translations, layerPanelTitle } = this.props
const { activeIndex, showLayerPanel } = this.state
const tabDataTestId = showLayerPanel ? 'LayerPanel.close' : 'LayerPanel.open'
return (
<>
{!showLayerPanel && <InitialTab id='initialtab' onClick={this.showLayerPanel} icon={<LayersIcon data-testid={tabDataTestId} />} />}
<Card open={showLayerPanel} styles={style} numoftabs={children.length || 1} inline={inline} className='_popup_boundary' >
<CardContent>
<Typography variant='h5' component='h5'>{layerPanelTitle}</Typography>
<IconButton onClick={this.hideLayerPanel}><CloseIcon /></IconButton>
</CardContent>
<Tabs open={showLayerPanel} value={activeIndex} onChange={this.handleChange} >
{showLayerPanel &&
React.Children.map(children, (child, i) => {
if (child) return <Tab key={i} label={child.props.tabIcon || child.props.label} />
})
}
</Tabs>
{translations && React.Children.toArray(children)[activeIndex]}
</Card>
</>
)
}
}
LayerPanelBase.propTypes = {
/** Render the component inline (without absolute positioning) */
inline: PropTypes.bool,
/** The content of the layer panel (likely a set of `LayerPanelPage` components) */
children: PropTypes.node.isRequired,
/** An object of styles spread on the layerpanel */
style: PropTypes.object,
/** Title of the LayerPanel */
layerPanelTitle: PropTypes.string,
/** Object with key/value pairs for translated strings */
translations: PropTypes.object
}
export default connectToContext(LayerPanelBase)