|
@@ -216,12 +216,12 @@ function quickSort(a) {
|
|
return a.length <= 1 ? a : quickSort(a.slice(1).filter(item => item <= a[0])).concat(a[0], quickSort(a.slice(1).filter(item => item > a[0])));
|
|
return a.length <= 1 ? a : quickSort(a.slice(1).filter(item => item <= a[0])).concat(a[0], quickSort(a.slice(1).filter(item => item > a[0])));
|
|
}
|
|
}
|
|
|
|
|
|
-const getMaxContainerHeight = (layout, elementHeight) => {
|
|
|
|
|
|
+const getMaxContainerHeight = (layout, elementHeight = 30, elementMarginBottom = 10) => {
|
|
const ar = layout.map((item) => {
|
|
const ar = layout.map((item) => {
|
|
return item.GridY + item.h
|
|
return item.GridY + item.h
|
|
})
|
|
})
|
|
const h = quickSort(ar)[ar.length - 1];
|
|
const h = quickSort(ar)[ar.length - 1];
|
|
- const height = h * (30 + 10) + 10
|
|
|
|
|
|
+ const height = h * (elementHeight + elementMarginBottom) + elementMarginBottom
|
|
return height
|
|
return height
|
|
}
|
|
}
|
|
|
|
|
|
@@ -311,7 +311,7 @@ class DraggerLayout extends React.Component {
|
|
GridXMoving: layoutItem.GridX,
|
|
GridXMoving: layoutItem.GridX,
|
|
GridYMoving: layoutItem.GridY,
|
|
GridYMoving: layoutItem.GridY,
|
|
layout: compactedLayout,
|
|
layout: compactedLayout,
|
|
- containerHeight: getMaxContainerHeight(compactedLayout)
|
|
|
|
|
|
+ containerHeight: getMaxContainerHeight(compactedLayout, this.props.rowHeight, this.props.margin[1])
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
@@ -320,16 +320,17 @@ class DraggerLayout extends React.Component {
|
|
this.setState({
|
|
this.setState({
|
|
placeholderShow: false,
|
|
placeholderShow: false,
|
|
layout: compactedLayout,
|
|
layout: compactedLayout,
|
|
- containerHeight: getMaxContainerHeight(compactedLayout)
|
|
|
|
|
|
+ containerHeight: getMaxContainerHeight(compactedLayout, this.props.rowHeight, this.props.margin[1])
|
|
})
|
|
})
|
|
}
|
|
}
|
|
placeholder() {
|
|
placeholder() {
|
|
if (!this.state.placeholderShow) return null
|
|
if (!this.state.placeholderShow) return null
|
|
- const { col, width, padding, rowHeight } = this.props
|
|
|
|
|
|
+ const { col, width, padding, rowHeight, margin } = this.props
|
|
const { GridXMoving, GridYMoving, wMoving, hMoving, placeholderMoving } = this.state
|
|
const { GridXMoving, GridYMoving, wMoving, hMoving, placeholderMoving } = this.state
|
|
|
|
|
|
return (
|
|
return (
|
|
<GridItem
|
|
<GridItem
|
|
|
|
+ margin={margin}
|
|
col={col}
|
|
col={col}
|
|
containerWidth={width}
|
|
containerWidth={width}
|
|
containerPadding={padding}
|
|
containerPadding={padding}
|
|
@@ -350,17 +351,18 @@ class DraggerLayout extends React.Component {
|
|
const compacted = compactLayout(layout);
|
|
const compacted = compactLayout(layout);
|
|
this.setState({
|
|
this.setState({
|
|
layout: compacted,
|
|
layout: compacted,
|
|
- containerHeight: getMaxContainerHeight(compacted)
|
|
|
|
|
|
+ containerHeight: getMaxContainerHeight(compacted, this.props.rowHeight, this.props.margin[1])
|
|
})
|
|
})
|
|
}, 1);
|
|
}, 1);
|
|
}
|
|
}
|
|
|
|
|
|
getGridItem(child, index) {
|
|
getGridItem(child, index) {
|
|
const { layout } = this.state
|
|
const { layout } = this.state
|
|
- const { col, width, padding, rowHeight } = this.props
|
|
|
|
|
|
+ const { col, width, padding, rowHeight, margin } = this.props
|
|
const renderItem = layoutItemForkey(layout, child.key)
|
|
const renderItem = layoutItemForkey(layout, child.key)
|
|
return (
|
|
return (
|
|
<GridItem
|
|
<GridItem
|
|
|
|
+ margin={margin}
|
|
col={col}
|
|
col={col}
|
|
containerWidth={width}
|
|
containerWidth={width}
|
|
containerPadding={padding}
|
|
containerPadding={padding}
|
|
@@ -403,9 +405,9 @@ export default class LayoutDemo extends React.Component {
|
|
|
|
|
|
render() {
|
|
render() {
|
|
return (
|
|
return (
|
|
- <DraggerLayout width={800} col={16} >
|
|
|
|
- {[1, 2, 3, 4, 5].map((el, index) => {
|
|
|
|
- return (<div key={index} data-set={{ GridX: index, GridY: index, w: 5, h: 5 }}>{index}</div>)
|
|
|
|
|
|
+ <DraggerLayout width={800} col={12} rowHeight={800 / 12} margin={[5, 5]}>
|
|
|
|
+ {['我', '叫', '做', '方', '正'].map((el, index) => {
|
|
|
|
+ return (<div key={index} data-set={{ GridX: index * 2, GridY: index, w: 2, h: 2 }}>{el}</div>)
|
|
})}
|
|
})}
|
|
</DraggerLayout>
|
|
</DraggerLayout>
|
|
)
|
|
)
|