11import React from 'react' ;
22import PropTypes from 'prop-types' ;
3+ import { omit } from 'ramda' ;
34
45import { PopoverTemplate } from '../../private/OverlayTemplates' ;
56import Overlay from '../../private/Overlay' ;
@@ -52,7 +53,10 @@ const Popover = props => {
5253 }
5354 defaultShow = { is_open }
5455 popperConfig = { popperConfig }
55- { ...otherProps }
56+ { ...omit (
57+ [ 'persistence' , 'persisted_props' , 'persistence_type' ] ,
58+ otherProps
59+ ) }
5660 >
5761 < PopoverTemplate
5862 // to ensure proper backwards compatibility, the toggle function is only
@@ -73,7 +77,9 @@ Popover.defaultProps = {
7377 delay : { show : 0 , hide : 50 } ,
7478 placement : 'right' ,
7579 flip : true ,
76- autohide : false
80+ autohide : false ,
81+ persisted_props : [ 'is_open' ] ,
82+ persistence_type : 'local'
7783} ;
7884
7985Popover . propTypes = {
@@ -230,7 +236,36 @@ Popover.propTypes = {
230236 * Holds the name of the component that is loading
231237 */
232238 component_name : PropTypes . string
233- } )
239+ } ) ,
240+
241+ /**
242+ * Used to allow user interactions in this component to be persisted when
243+ * the component - or the page - is refreshed. If `persisted` is truthy and
244+ * hasn't changed from its previous value, a `value` that the user has
245+ * changed while using the app will keep that change, as long as
246+ * the new `value` also matches what was given originally.
247+ * Used in conjunction with `persistence_type`.
248+ */
249+ persistence : PropTypes . oneOfType ( [
250+ PropTypes . bool ,
251+ PropTypes . string ,
252+ PropTypes . number
253+ ] ) ,
254+
255+ /**
256+ * Properties whose user interactions will persist after refreshing the
257+ * component or the page. Since only `value` is allowed this prop can
258+ * normally be ignored.
259+ */
260+ persisted_props : PropTypes . arrayOf ( PropTypes . oneOf ( [ 'is_open' ] ) ) ,
261+
262+ /**
263+ * Where persisted user changes will be stored:
264+ * memory: only kept in memory, reset on page refresh.
265+ * local: window.localStorage, data is kept after the browser quit.
266+ * session: window.sessionStorage, data is cleared once the browser quit.
267+ */
268+ persistence_type : PropTypes . oneOf ( [ 'local' , 'session' , 'memory' ] )
234269} ;
235270
236271export default Popover ;
0 commit comments