Skip to content

Commit 2482e20

Browse files
committed
feat: add back measureHeight/measureWidth props
1 parent 14fd709 commit 2482e20

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/index.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ export type DefaultProps = {
1313
prefixer: Prefixer
1414
style: any
1515
shouldTransition: (oldChildren?: any, newChildren?: any) => boolean
16+
measureHeight: (el: HTMLElement) => number
17+
measureWidth: (el: HTMLElement) => number
1618
}
1719

1820
export type Props = {
1921
animateHeight?: boolean | null | undefined
2022
animateWidth?: boolean | null | undefined
23+
measureHeight?: (el: HTMLElement) => number
24+
measureWidth?: (el: HTMLElement) => number
2125
innerRef?: (
2226
c?: React.ElementRef<'div'> | null | undefined
2327
) => any | null | undefined
@@ -41,6 +45,8 @@ export type Props = {
4145
export type DefaultedProps = {
4246
animateHeight?: boolean | null | undefined
4347
animateWidth?: boolean | null | undefined
48+
measureHeight: (el: HTMLElement) => number
49+
measureWidth: (el: HTMLElement) => number
4450
innerRef?: (c?: React.ElementRef<'div'> | null | undefined) => any
4551
shouldTransition: (oldChildren?: any, newChildren?: any) => boolean
4652
children?: React.ReactNode
@@ -65,6 +71,8 @@ const defaultProps: DefaultProps = {
6571
sizeTransitionTimingFunction: 'ease',
6672
prefixer: new Prefixer(),
6773
style: {},
74+
measureHeight: (el: HTMLElement) => el.clientHeight,
75+
measureWidth: (el: HTMLElement) => el.clientWidth,
6876

6977
shouldTransition(oldChildren: any, newChildren: any): boolean {
7078
if (oldChildren === newChildren) return false
@@ -190,6 +198,8 @@ export default class Fader extends React.Component<Props, State> {
190198
const {
191199
animateHeight,
192200
animateWidth,
201+
measureHeight,
202+
measureWidth,
193203
shouldTransition: _shouldTransition,
194204
fadeOutTransitionDuration,
195205
fadeInTransitionDuration,
@@ -216,11 +226,11 @@ export default class Fader extends React.Component<Props, State> {
216226
)
217227

218228
if (animateHeight && height === undefined && this.wrappedChildrenRef) {
219-
newState.height = this.wrappedChildrenRef.clientHeight
229+
newState.height = measureHeight(this.wrappedChildrenRef)
220230
}
221231

222232
if (animateWidth && width === undefined && this.wrappedChildrenRef) {
223-
newState.width = this.wrappedChildrenRef.clientWidth
233+
newState.width = measureWidth(this.wrappedChildrenRef)
224234
}
225235

226236
this.setState((state) => ({ ...state, ...newState }))
@@ -249,7 +259,7 @@ export default class Fader extends React.Component<Props, State> {
249259
)
250260
if (animateHeight) {
251261
if (this.wrappedChildrenRef) {
252-
newState.height = this.wrappedChildrenRef.clientHeight
262+
newState.height = measureHeight(this.wrappedChildrenRef)
253263
}
254264
this.setTimeout(
255265
'height',
@@ -259,7 +269,7 @@ export default class Fader extends React.Component<Props, State> {
259269
}
260270
if (animateWidth) {
261271
if (this.wrappedChildrenRef) {
262-
newState.width = this.wrappedChildrenRef.clientWidth
272+
newState.width = measureWidth(this.wrappedChildrenRef)
263273
}
264274
this.setTimeout(
265275
'width',
@@ -284,7 +294,7 @@ export default class Fader extends React.Component<Props, State> {
284294
}
285295
}
286296

287-
onTransitionEnd = (e?: Event) => {
297+
onTransitionEnd = () => {
288298
const { shouldTransition, fadeOutTransitionDuration } =
289299
this.getDefaultedProps()
290300
const { transitionState } = this.state
@@ -314,7 +324,7 @@ export default class Fader extends React.Component<Props, State> {
314324
}
315325
}
316326
}
317-
onSizeTransitionEnd = (e?: Event) => {
327+
onSizeTransitionEnd = () => {
318328
this.setState({ transitioningSize: false })
319329
}
320330

0 commit comments

Comments
 (0)