Skip to content
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

Feature/10 inherit class name and children #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/Rect/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ const zoomableMap = {

export default class Rect extends PureComponent {
static propTypes = {
styles: PropTypes.object,
zoomable: PropTypes.string,
rotatable: PropTypes.bool,
className: PropTypes.string,
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node
]),
onResizeStart: PropTypes.func,
onResize: PropTypes.func,
onResizeEnd: PropTypes.func,
Expand All @@ -28,7 +30,14 @@ export default class Rect extends PureComponent {
onDragStart: PropTypes.func,
onDrag: PropTypes.func,
onDragEnd: PropTypes.func,
parentRotateAngle: PropTypes.number
parentRotateAngle: PropTypes.number,
rotatable: PropTypes.bool,
styles: PropTypes.object,
zoomable: PropTypes.string
}

static defaultProps = {
className: ''
}

setElementRef = (ref) => { this.$element = ref }
Expand Down Expand Up @@ -133,6 +142,8 @@ export default class Rect extends PureComponent {

render () {
const {
children,
className,
styles: {
position: { centerX, centerY },
size: { width, height },
Expand All @@ -155,7 +166,7 @@ export default class Rect extends PureComponent {
<StyledRect
ref={this.setElementRef}
onMouseDown={this.startDrag}
className="rect single-resizer"
className={`rect single-resizer ${className}`}
style={style}
>
{
Expand Down Expand Up @@ -187,6 +198,7 @@ export default class Rect extends PureComponent {
)
})
}
{children}
</StyledRect>
)
}
Expand Down
9 changes: 8 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { centerToTL, tLToCenter, getNewStyle, degToRadian } from './utils'

export default class ResizableRect extends Component {
static propTypes = {
className: PropTypes.string,
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node
]),
left: PropTypes.number.isRequired,
top: PropTypes.number.isRequired,
width: PropTypes.number.isRequired,
Expand Down Expand Up @@ -80,14 +85,16 @@ export default class ResizableRect extends Component {

render () {
const {
top, left, width, height, rotateAngle, parentRotateAngle, zoomable, rotatable,
children, className, top, left, width, height, rotateAngle, parentRotateAngle, zoomable, rotatable,
onRotate, onResizeStart, onResizeEnd, onRotateStart, onRotateEnd, onDragStart, onDragEnd
} = this.props

const styles = tLToCenter({ top, left, width, height, rotateAngle })

return (
<Rect
children={children}
className={className}
styles={styles}
zoomable={zoomable}
rotatable={Boolean(rotatable && onRotate)}
Expand Down