-
-
Notifications
You must be signed in to change notification settings - Fork 231
Support stretch porp #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
14d763f
add stretch
zombieJ 1db3a73
support stretch prop
zombieJ 7180d6e
add test case
zombieJ e4c3883
add readme
zombieJ 95e6efd
use full words instead of abbr & use offset instead of client
zombieJ 33e17d5
remove default value of stretch
zombieJ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,17 +20,31 @@ class Popup extends Component { | |
className: PropTypes.string, | ||
prefixCls: PropTypes.string, | ||
onMouseLeave: PropTypes.func, | ||
stretch: PropTypes.string, | ||
children: PropTypes.node, | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
// Used for stretch | ||
stretchChecked: false, | ||
targetWidth: undefined, | ||
targetHeight: undefined, | ||
}; | ||
|
||
this.savePopupRef = saveRef.bind(this, 'popupInstance'); | ||
this.saveAlignRef = saveRef.bind(this, 'alignInstance'); | ||
} | ||
|
||
componentDidMount() { | ||
this.rootNode = this.getPopupDomNode(); | ||
this.setStretchSize(); | ||
} | ||
|
||
componentDidUpdate() { | ||
this.setStretchSize(); | ||
} | ||
|
||
onAlign = (popupDomNode, align) => { | ||
|
@@ -45,6 +59,33 @@ class Popup extends Component { | |
props.onAlign(popupDomNode, align); | ||
} | ||
|
||
// Record size if stretch needed | ||
setStretchSize = () => { | ||
const { stretch, getRootDomNode, visible } = this.props; | ||
const { stretchChecked, targetHeight, targetWidth } = this.state; | ||
|
||
if (!stretch || !visible) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
if (stretchChecked) { | ||
this.setState({ stretchChecked: false }); | ||
} | ||
return; | ||
} | ||
|
||
const $ele = getRootDomNode(); | ||
if (!$ele) return; | ||
|
||
const height = $ele.clientHeight; | ||
const width = $ele.clientWidth; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 要用 |
||
|
||
if (targetHeight !== height || targetWidth !== width || !stretchChecked) { | ||
this.setState({ | ||
stretchChecked: true, | ||
targetHeight: height, | ||
targetWidth: width, | ||
}); | ||
} | ||
}; | ||
|
||
getPopupDomNode() { | ||
return ReactDOM.findDOMNode(this.popupInstance); | ||
} | ||
|
@@ -77,24 +118,50 @@ class Popup extends Component { | |
} | ||
|
||
getPopupElement() { | ||
const { savePopupRef, props } = this; | ||
const { align, style, visible, prefixCls, destroyPopupOnHide } = props; | ||
const { savePopupRef } = this; | ||
const { stretchChecked, targetHeight, targetWidth } = this.state; | ||
const { | ||
align, visible, | ||
prefixCls, style, getClassNameFromAlign, | ||
destroyPopupOnHide, stretch, children, | ||
onMouseEnter, onMouseLeave, | ||
} = this.props; | ||
const className = this.getClassName(this.currentAlignClassName || | ||
props.getClassNameFromAlign(align)); | ||
getClassNameFromAlign(align)); | ||
const hiddenClassName = `${prefixCls}-hidden`; | ||
|
||
if (!visible) { | ||
this.currentAlignClassName = null; | ||
} | ||
|
||
const sizeStyle = {}; | ||
if (stretch) { | ||
if (stretchChecked) { | ||
// Stretch with target | ||
if (stretch.indexOf('h') !== -1) { | ||
sizeStyle.minHeight = targetHeight; | ||
} | ||
if (stretch.indexOf('w') !== -1) { | ||
sizeStyle.minWidth = targetWidth; | ||
} | ||
} else { | ||
// Do nothing when stretch not ready | ||
return null; | ||
} | ||
} | ||
|
||
const newStyle = { | ||
...sizeStyle, | ||
...style, | ||
...this.getZIndexStyle(), | ||
}; | ||
|
||
const popupInnerProps = { | ||
className, | ||
prefixCls, | ||
ref: savePopupRef, | ||
onMouseEnter: props.onMouseEnter, | ||
onMouseLeave: props.onMouseLeave, | ||
onMouseEnter, | ||
onMouseLeave, | ||
style: newStyle, | ||
}; | ||
if (destroyPopupOnHide) { | ||
|
@@ -118,7 +185,7 @@ class Popup extends Component { | |
visible | ||
{...popupInnerProps} | ||
> | ||
{props.children} | ||
{children} | ||
</PopupInner> | ||
</Align> | ||
) : null} | ||
|
@@ -148,7 +215,7 @@ class Popup extends Component { | |
hiddenClassName={hiddenClassName} | ||
{...popupInnerProps} | ||
> | ||
{props.children} | ||
{children} | ||
</PopupInner> | ||
</Align> | ||
</Animate> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
还是不要用缩写吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
align 里面也是缩写,觉得一个缩写一个不缩写很怪异: