diff --git a/README.md b/README.md index cff8fa9..c9c0520 100644 --- a/README.md +++ b/README.md @@ -203,6 +203,9 @@ The [angle](https://developer.mozilla.org/en-US/docs/Web/CSS/angle) unit. Affect Configuration of the React-Motion spring. See the [React-Motion docs](https://github.com/chenglou/react-motion#helpers) for more info. Default: `{ stiffness: 60, damping: 14, precision: 0.1 }`. +**sorted={`Boolean`}** +Items in the sorted order. Default: `false`. + ### CSSGrid only props **duration={`Number`}** diff --git a/demo/src/components/App.jsx b/demo/src/components/App.jsx index 7665891..6f85e8d 100644 --- a/demo/src/components/App.jsx +++ b/demo/src/components/App.jsx @@ -44,6 +44,7 @@ export default class extends Component { data: this.generateData(), useCSS: false, responsive: false, + sorted: false, layout: camelCase(layouts[0]), enterExitStyle: camelCase(enterExitStyles[0]), duration: 800, @@ -77,6 +78,7 @@ export default class extends Component { layout, enterExitStyle, responsive, + sorted, columns, gutters, stiffness, @@ -181,6 +183,16 @@ export default class extends Component { onChange={ev => this.setState({ responsive: ev.target.checked })} />Responsive + { + layout !== 'simple' ? + : null + }
{'Columns '}
diff --git a/demo/src/components/Grid.jsx b/demo/src/components/Grid.jsx index 89a010d..4bd5427 100644 --- a/demo/src/components/Grid.jsx +++ b/demo/src/components/Grid.jsx @@ -48,6 +48,7 @@ export default class extends Component { useCSS, responsive, layout, + sorted, enterExitStyle, duration, easing, @@ -73,6 +74,7 @@ export default class extends Component { gutterWidth={gutters} gutterHeight={gutters} layout={gridLayout} + sorted={sorted} enter={gridEnterExitStyle.enter} entered={gridEnterExitStyle.entered} exit={gridEnterExitStyle.exit} diff --git a/src/components/SpringGrid.jsx b/src/components/SpringGrid.jsx index 81ed21f..cfe627b 100644 --- a/src/components/SpringGrid.jsx +++ b/src/components/SpringGrid.jsx @@ -123,6 +123,7 @@ export default class extends Component { 'gutterWidth', 'gutterHeight', 'layout', + 'sorted', 'enter', 'entered', 'exit', diff --git a/src/layouts/pinterest.js b/src/layouts/pinterest.js index 84f076c..5918285 100644 --- a/src/layouts/pinterest.js +++ b/src/layouts/pinterest.js @@ -1,7 +1,7 @@ /* eslint-disable no-mixed-operators */ export default function(items, props) { const { - columns, columnWidth, gutterWidth, gutterHeight + columns, columnWidth, gutterWidth, gutterHeight, sorted } = props; const columnHeights = []; @@ -9,8 +9,10 @@ export default function(items, props) { columnHeights.push(0); } - const positions = items.map((itemProps) => { - const column = columnHeights.indexOf(Math.min.apply(null, columnHeights)); + const positions = items.map((itemProps, i) => { + const column = sorted + ? i % columns + : columnHeights.indexOf(Math.min.apply(null, columnHeights)); const height = itemProps.itemHeight || (itemProps.itemRect && itemProps.itemRect.height); diff --git a/src/utils/commonProps.js b/src/utils/commonProps.js index c3262e6..f09c979 100644 --- a/src/utils/commonProps.js +++ b/src/utils/commonProps.js @@ -9,6 +9,7 @@ export const commonPropTypes = { gutterHeight: PropTypes.number, component: PropTypes.string, layout: PropTypes.func, + sorted: PropTypes.bool, enter: PropTypes.func, entered: PropTypes.func, exit: PropTypes.func, @@ -24,6 +25,7 @@ export const commonDefaultProps = { gutterWidth: 0, gutterHeight: 0, layout: simpleLayout, + sorted: false, enter: simpleEnterExit.enter, entered: simpleEnterExit.entered, exit: simpleEnterExit.exit