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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 4x 4x 1x 1x | // @flow import React, { Component } from 'react'; import PropTypes from 'prop-types'; import Drawer from 'material-ui/Drawer'; import lightBaseTheme from 'material-ui/styles/baseThemes/lightBaseTheme'; import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'; import getMuiTheme from 'material-ui/styles/getMuiTheme'; type Props = { children?: Node, className?: string, containerclassName?: string, containerStyle?: Object, disableSwipeToOpen?: boolean, docked?: boolean, id: string, open?: boolean, openSecondary?: boolean, overlayClassName?: string, overlayStyle?: Object, setProps?: () => void, style?: Object, swipeAreaWidth?: number, width?: string | number, zDepth?: number, } const propTypes = { /** * The contents of the Drawer */ children: PropTypes.node, /** * The CSS class name of the root element. */ className: PropTypes.string, /** * The CSS class name of the container element. */ containerclassName: PropTypes.string, /** * Override the inline-styles of the container element. */ containerStyle: PropTypes.objectOf(PropTypes.any), /** * If true, swiping sideways when the Drawer is closed will not open it. */ disableSwipeToOpen: PropTypes.bool, /** * If true, the Drawer will be docked. In this state, the overlay won't show and clicking on a * menu item will not close the Drawer. */ docked: PropTypes.bool, /** * */ id: PropTypes.string.isRequired, /** * If true, the Drawer is opened. Whether true or false, ensures that the drawer is a controlled * component. */ open: PropTypes.bool, /** * If true, the Drawer is positioned to open from the opposite side. */ openSecondary: PropTypes.bool, /** * The CSS class name to add to the Overlay component that is rendered behind the Drawer. */ overlayClassName: PropTypes.string, /** * Override the inline-styles of the Overlay component that is rendered behind the Drawer. */ overlayStyle: PropTypes.objectOf(PropTypes.any), /** * Dash callback to update props on the server. */ setProps: PropTypes.func, /** * Override the inline-styles of the root element. */ style: PropTypes.objectOf(PropTypes.any), /** * The width of the left most (or right most) area in pixels where the Drawer can be swiped * open from. Setting this to null spans that area to the entire page (CAUTION! Setting this * property to null might cause issues with sliders and swipeable Tabs: use at your own risk). */ swipeAreaWidth: PropTypes.number, /** * The width of the Drawer in pixels or percentage in string format ex. 50% to fill half of the * window or 100% and so on. Defaults to using the values from theme. */ width: PropTypes.oneOf([PropTypes.string, PropTypes.number]), /** * The zDepth of the Drawer. */ zDepth: PropTypes.number, }; type State = { open: boolean, }; const defaultProps = { children: [], className: '', containerclassName: '', containerStyle: {}, disableSwipeToOpen: false, docked: true, open: false, openSecondary: false, overlayClassName: '', overlayStyle: {}, setProps: () => {}, style: {}, swipeAreaWidth: 30, width: null, zDepth: 2, }; export default class SDDrawer extends Component<Props, State> { constructor(props: Props) { super(props); this.state = {open: props.open}; } componentWillReceiveProps(nextProps: Props): void { Eif (nextProps.open !== null && nextProps.open !== this.props.open) { this.changeDrawerStatus(nextProps.open); } } changeDrawerStatus = (open: boolean) => { const { setProps } = this.props; Eif (typeof setProps === 'function') setProps({open}); this.setState({open}); }; render() { const { className, containerclassName, containerStyle, disableSwipeToOpen, docked, id, openSecondary, overlayClassName, overlayStyle, style, swipeAreaWidth, width, zDepth } = this.props; return ( <div id={id}> <MuiThemeProvider muiTheme={getMuiTheme(lightBaseTheme)}> <Drawer className={className} containerClassName={containerclassName} containerStyle={containerStyle} disableSwipeToOpen={disableSwipeToOpen} docked={docked} onRequestChange={(openStatus: boolean) => this.changeDrawerStatus(openStatus)} open={this.state.open} openSecondary={openSecondary} overlayClassName={overlayClassName} overlayStyle={overlayStyle} style={style} swipeAreaWidth={swipeAreaWidth} width={width} zDepth={zDepth} > {this.props.children} </Drawer> </MuiThemeProvider> </div> ); } } SDDrawer.propTypes = propTypes; SDDrawer.defaultProps = defaultProps; |