1
1
import PropTypes from 'prop-types' ;
2
- import isFunction from 'lodash.isfunction' ;
3
2
4
3
let globalCssModule ;
5
4
@@ -57,19 +56,6 @@ export const TransitionStatuses = {
57
56
EXITED : 'exited' ,
58
57
} ;
59
58
60
- export const keyCodes = {
61
- esc : 27 ,
62
- space : 32 ,
63
- enter : 13 ,
64
- tab : 9 ,
65
- up : 38 ,
66
- down : 40 ,
67
- home : 36 ,
68
- end : 35 ,
69
- n : 78 ,
70
- p : 80 ,
71
- } ;
72
-
73
59
export const canUseDOM = ! ! (
74
60
typeof window !== 'undefined' &&
75
61
window . document &&
@@ -94,23 +80,6 @@ const tagPropType = PropTypes.oneOfType([
94
80
] ) )
95
81
] ) ;
96
82
97
- export const focusableElements = [
98
- 'a[href]' ,
99
- 'area[href]' ,
100
- 'input:not([disabled]):not([type=hidden])' ,
101
- 'select:not([disabled])' ,
102
- 'textarea:not([disabled])' ,
103
- 'button:not([disabled])' ,
104
- 'object' ,
105
- 'embed' ,
106
- '[tabindex]:not(.modal)' ,
107
- 'audio[controls]' ,
108
- 'video[controls]' ,
109
- '[contenteditable]:not([contenteditable="false"])' ,
110
- ] ;
111
-
112
- export const defaultToggleEvents = [ 'touchstart' , 'click' ] ;
113
-
114
83
export function omit ( obj , omitKeys ) {
115
84
const result = { } ;
116
85
Object . keys ( obj ) . forEach ( key => {
@@ -135,20 +104,6 @@ export function pick(obj, keys) {
135
104
return result ;
136
105
}
137
106
138
- export function conditionallyUpdateScrollbar ( ) {
139
- const scrollbarWidth = getScrollbarWidth ( ) ;
140
- // https://github.com/twbs/bootstrap/blob/v4.0.0-alpha.6/js/src/modal.js#L433
141
- const fixedContent = document . querySelectorAll (
142
- '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top'
143
- ) [ 0 ] ;
144
- const bodyPadding = fixedContent
145
- ? parseInt ( fixedContent . style . paddingRight || 0 , 10 )
146
- : 0 ;
147
-
148
- if ( isBodyOverflowing ( ) ) {
149
- setScrollbarWidth ( bodyPadding + scrollbarWidth ) ;
150
- }
151
- }
152
107
153
108
export function DOMElement ( props , propName , componentName ) {
154
109
if ( ! ( props [ propName ] instanceof Element ) ) {
@@ -162,49 +117,6 @@ export function DOMElement(props, propName, componentName) {
162
117
}
163
118
}
164
119
165
- export function isReactRefObj ( target ) {
166
- if ( target && typeof target === 'object' ) {
167
- return 'current' in target ;
168
- }
169
- return false ;
170
- }
171
-
172
- export function findDOMElements ( target ) {
173
- if ( isReactRefObj ( target ) ) {
174
- return target . current ;
175
- }
176
- if ( isFunction ( target ) ) {
177
- return target ( ) ;
178
- }
179
- if ( typeof target === 'string' && canUseDOM ) {
180
- let selection = document . querySelectorAll ( target ) ;
181
- if ( ! selection . length ) {
182
- selection = document . querySelectorAll ( `#${ target } ` ) ;
183
- }
184
- if ( ! selection . length ) {
185
- throw new Error (
186
- `The target '${ target } ' could not be identified in the dom, tip: check spelling`
187
- ) ;
188
- }
189
- return selection ;
190
- }
191
- return target ;
192
- }
193
-
194
- export function isArrayOrNodeList ( els ) {
195
- if ( els === null ) {
196
- return false ;
197
- }
198
- return Array . isArray ( els ) || ( canUseDOM && typeof els . length === 'number' ) ;
199
- }
200
-
201
- export function getTarget ( target ) {
202
- const els = findDOMElements ( target ) ;
203
- if ( isArrayOrNodeList ( els ) ) {
204
- return els [ 0 ] ;
205
- }
206
- return els ;
207
- }
208
120
209
121
const mapToCssModules = ( className = '' , cssModule = globalCssModule ) => {
210
122
if ( ! cssModule ) return className ;
@@ -214,108 +126,16 @@ const mapToCssModules = (className = '', cssModule = globalCssModule)=>{
214
126
. join ( ' ' ) ;
215
127
}
216
128
217
- export function colog ( ) {
218
- if ( process . env . NODE_ENV === 'development' )
219
- console . log . apply ( this , arguments ) ;
220
- }
221
-
222
- let warned = { } ;
223
- export function warnOnce ( message ) {
224
- if ( ! warned [ message ] ) {
225
- /* istanbul ignore else */
226
- if ( typeof console !== 'undefined' ) {
227
- console . error ( message ) ; // eslint-disable-line no-console
228
- }
229
- warned [ message ] = true ;
230
- }
231
- }
232
129
233
130
function deprecated ( propType , explanation ) {
234
131
return function validate ( props , propName , componentName , ...rest ) {
235
132
if ( props [ propName ] !== null && typeof props [ propName ] !== 'undefined' ) {
236
133
warnOnce (
237
134
`"${ propName } " property of "${ componentName } " has been deprecated.\n${ explanation } `
238
- ) ;
135
+ )
239
136
}
240
137
return propType ( props , propName , componentName , ...rest ) ;
241
- } ;
242
- }
243
-
244
- export { tagPropType , mapToCssModules , deprecated } ;
245
-
246
- export function getOriginalBodyPadding ( ) {
247
- const style = window . getComputedStyle ( document . body , null ) ;
248
-
249
- return parseInt ( ( style && style . getPropertyValue ( 'padding-right' ) ) || 0 , 10 ) ;
250
- }
251
-
252
- // https://github.com/twbs/bootstrap/blob/v4.0.0-alpha.4/js/src/modal.js#L436-L443
253
- export function getScrollbarWidth ( ) {
254
- let scrollDiv = document . createElement ( 'div' ) ;
255
- // .modal-scrollbar-measure styles // https://github.com/twbs/bootstrap/blob/v4.0.0-alpha.4/scss/_modal.scss#L106-L113
256
- scrollDiv . style . position = 'absolute' ;
257
- scrollDiv . style . top = '-9999px' ;
258
- scrollDiv . style . width = '50px' ;
259
- scrollDiv . style . height = '50px' ;
260
- scrollDiv . style . overflow = 'scroll' ;
261
- document . body . appendChild ( scrollDiv ) ;
262
- const scrollbarWidth = scrollDiv . offsetWidth - scrollDiv . clientWidth ;
263
- document . body . removeChild ( scrollDiv ) ;
264
- return scrollbarWidth ;
265
- }
266
-
267
- export function setScrollbarWidth ( padding ) {
268
- document . body . style . paddingRight = padding > 0 ? `${ padding } px` : null ;
269
- }
270
-
271
- export function isBodyOverflowing ( ) {
272
- return document . body . clientWidth < window . innerWidth ;
273
- }
274
-
275
- export function addMultipleEventListeners ( _els , handler , _events , useCapture ) {
276
- let els = _els ;
277
- if ( ! isArrayOrNodeList ( els ) ) {
278
- els = [ els ] ;
279
138
}
280
- let events = _events ;
281
- if ( typeof events === 'string' ) {
282
- events = events . split ( / \s + / ) ;
283
- }
284
- if (
285
- ! isArrayOrNodeList ( els ) ||
286
- typeof handler !== 'function' ||
287
- ! Array . isArray ( events )
288
- ) {
289
- throw new Error ( `
290
- The first argument of this function must be DOM node or an array on DOM nodes or NodeList.
291
- The second must be a function.
292
- The third is a string or an array of strings that represents DOM events
293
- ` ) ;
294
- }
295
- Array . prototype . forEach . call ( events , event => {
296
- Array . prototype . forEach . call ( els , el => {
297
- el . addEventListener ( event , handler , useCapture ) ;
298
- } ) ;
299
- } ) ;
300
- return function removeEvents ( ) {
301
- Array . prototype . forEach . call ( events , event => {
302
- Array . prototype . forEach . call ( els , el => {
303
- el . removeEventListener ( event , handler , useCapture ) ;
304
- } ) ;
305
- } ) ;
306
- } ;
307
139
}
308
140
309
- export function toggleClasses ( toggleClass , classList , force ) {
310
- const level = classList . indexOf ( toggleClass )
311
- const removeClassList = classList . slice ( 0 , level )
312
- removeClassList . map ( ( className ) => document . body . classList . remove ( className ) )
313
- if ( force === true ) {
314
- document . body . classList . add ( toggleClass ) ;
315
- } else if ( force === false ) {
316
- document . body . classList . remove ( toggleClass ) ;
317
- } else {
318
- document . body . classList . toggle ( toggleClass ) ;
319
- }
320
- return document . body . classList . contains ( toggleClass ) ;
321
- }
141
+ export { tagPropType , mapToCssModules , deprecated }
0 commit comments