Skip to content

Commit fef0ff7

Browse files
committed
feat(Section): support onSizeChanged callback
fix(Section): make onSizeChanged optional
1 parent 4278327 commit fef0ff7

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Section.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import { ChildProps, SizeInfo } from './types';
66
import { withResizerContext } from './context';
77
import { isValidNumber, omit } from './utils';
88

9-
type Props = ChildProps & React.HTMLAttributes<HTMLDivElement>;
9+
type Props = ChildProps &
10+
React.HTMLAttributes<HTMLDivElement> & {
11+
onSizeChanged?: (currentSize: number) => void;
12+
};
1013

1114
class SectionComponent extends React.PureComponent<Props> {
1215
private readonly defaultInnerRef = React.createRef<HTMLDivElement>();
@@ -32,6 +35,7 @@ class SectionComponent extends React.PureComponent<Props> {
3235
const { flexGrow, flexBasis } = this.getStyle(sizeInfo, flexGrowRatio);
3336
this.ref.current.style.flexBasis = `${flexBasis}px`;
3437
this.ref.current.style.flexGrow = `${flexGrow}`;
38+
this.onSizeChanged(sizeInfo.currentSize);
3539
}
3640
}),
3741
);
@@ -83,6 +87,12 @@ class SectionComponent extends React.PureComponent<Props> {
8387
return <div {...props} style={style} ref={this.ref} />;
8488
}
8589

90+
private onSizeChanged(currentSize: number) {
91+
if (typeof this.props.onSizeChanged === 'function') {
92+
this.props.onSizeChanged(currentSize);
93+
}
94+
}
95+
8696
private getStyle(
8797
sizeInfo: SizeInfo | undefined = this.sizeInfo,
8898
flexGrowRatio: number = this.flexGrowRatio,

0 commit comments

Comments
 (0)