@@ -37,108 +37,108 @@ const closable = ({
3737 } ;
3838
3939 class Closable extends PureComponent {
40- static displayName = `closable(${ componentName } )` ;
41-
42- static propTypes = {
43- onClose : PropTypes . func ,
44- closable : PropTypes . shape ( {
45- onEscape : PropTypes . bool ,
46- onClickOutside : PropTypes . bool ,
47- onClickInside : PropTypes . bool ,
48- stopEventPropagation : PropTypes . bool ,
49- skip : PropTypes . bool ,
50- } ) ,
51- } ;
52-
53- static defaultProps = {
54- onClose : ( ) => { } ,
55- closable : mixinConfigs ,
56- } ;
57-
58- componentDidMount ( ) {
59- if ( ! this . props . closable . skip ) {
60- document . addEventListener ( 'keyup' , this . handleDocumentKeyup ) ;
61- }
62- }
63-
64- componentWillUnmount ( ) {
65- if ( ! this . props . closable . skip ) {
66- document . removeEventListener ( 'keyup' , this . handleDocumentKeyup ) ;
67- }
68- }
69-
70- getOptions ( ) {
71- const { closable : runtimeOptions } = this . props ;
72-
73- /** @type {typeof mixinDefaults } */
74- const actualOptions = {
75- ...mixinConfigs ,
76- ...runtimeOptions ,
77- } ;
78-
79- return actualOptions ;
80- }
81-
82- /**
83- * @param {KeyboardEvent } event
84- */
85- handleDocumentKeyup = ( event ) => {
86- const options = this . getOptions ( ) ;
87-
88- if ( options . onEscape && event . keyCode === keycode ( ESCAPE ) ) {
89- this . props . onClose ( event ) ;
90- }
91- }
92-
93- /**
94- * @param {React.MouseEvent } event
95- */
96- handleOuterLayerClick = ( event ) => {
97- const options = this . getOptions ( ) ;
98-
99- if ( options . stopEventPropagation ) {
100- event . stopPropagation ( ) ;
101- }
102-
103- if ( options . onClickOutside ) {
104- this . props . onClose ( event ) ;
105- }
106- }
107-
108- /**
109- * @param {React.MouseEvent } event
110- */
111- handleInsideClick = ( event ) => {
112- const options = this . getOptions ( ) ;
113-
114- if ( options . onClickInside ) {
115- this . props . onClose ( event ) ;
116- }
117- }
118-
119- render ( ) {
120- const {
121- onClose,
122- closable : runtimeOptions ,
123- ...otherProps
124- } = this . props ;
125-
126- return (
127- < >
128- { ! runtimeOptions . skip && (
129- < div
130- role = "presentation"
131- className = { ROOT_BEM . toString ( ) }
132- onClick = { this . handleOuterLayerClick }
133- />
134- ) }
135- < WrappedComponent
136- onInsideClick = { this . handleInsideClick }
137- { ...otherProps }
138- />
139- </ >
140- ) ;
141- }
40+ static displayName = `closable(${ componentName } )` ;
41+
42+ static propTypes = {
43+ onClose : PropTypes . func ,
44+ closable : PropTypes . shape ( {
45+ onEscape : PropTypes . bool ,
46+ onClickOutside : PropTypes . bool ,
47+ onClickInside : PropTypes . bool ,
48+ stopEventPropagation : PropTypes . bool ,
49+ skip : PropTypes . bool ,
50+ } ) ,
51+ } ;
52+
53+ static defaultProps = {
54+ onClose : ( ) => { } ,
55+ closable : mixinConfigs ,
56+ } ;
57+
58+ componentDidMount ( ) {
59+ if ( ! this . props . closable . skip ) {
60+ document . addEventListener ( 'keyup' , this . handleDocumentKeyup ) ;
61+ }
62+ }
63+
64+ componentWillUnmount ( ) {
65+ if ( ! this . props . closable . skip ) {
66+ document . removeEventListener ( 'keyup' , this . handleDocumentKeyup ) ;
67+ }
68+ }
69+
70+ getOptions ( ) {
71+ const { closable : runtimeOptions } = this . props ;
72+
73+ /** @type {typeof mixinDefaults } */
74+ const actualOptions = {
75+ ...mixinConfigs ,
76+ ...runtimeOptions ,
77+ } ;
78+
79+ return actualOptions ;
80+ }
81+
82+ /**
83+ * @param {KeyboardEvent } event
84+ */
85+ handleDocumentKeyup = ( event ) => {
86+ const options = this . getOptions ( ) ;
87+
88+ if ( options . onEscape && event . keyCode === keycode ( ESCAPE ) ) {
89+ this . props . onClose ( event ) ;
90+ }
91+ }
92+
93+ /**
94+ * @param {React.MouseEvent } event
95+ */
96+ handleOuterLayerClick = ( event ) => {
97+ const options = this . getOptions ( ) ;
98+
99+ if ( options . stopEventPropagation ) {
100+ event . stopPropagation ( ) ;
101+ }
102+
103+ if ( options . onClickOutside ) {
104+ this . props . onClose ( event ) ;
105+ }
106+ }
107+
108+ /**
109+ * @param {React.MouseEvent } event
110+ */
111+ handleInsideClick = ( event ) => {
112+ const options = this . getOptions ( ) ;
113+
114+ if ( options . onClickInside ) {
115+ this . props . onClose ( event ) ;
116+ }
117+ }
118+
119+ render ( ) {
120+ const {
121+ onClose,
122+ closable : runtimeOptions ,
123+ ...otherProps
124+ } = this . props ;
125+
126+ return (
127+ < >
128+ { ! runtimeOptions . skip && (
129+ < div
130+ role = "presentation"
131+ className = { ROOT_BEM . toString ( ) }
132+ onClick = { this . handleOuterLayerClick }
133+ />
134+ ) }
135+ < WrappedComponent
136+ onInsideClick = { this . handleInsideClick }
137+ { ...otherProps }
138+ />
139+ </ >
140+ ) ;
141+ }
142142 }
143143
144144 return Closable ;
0 commit comments