Skip to content

Commit

Permalink
Fix grid layout types and defaults (react-grid-layout#673)
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound authored and STRML committed Dec 10, 2017
1 parent 1550308 commit ada960f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[version]
0.55.0
0.59.0

[ignore]
.*test
Expand Down
8 changes: 4 additions & 4 deletions lib/GridItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,25 @@ export default class GridItem extends React.Component<Props, State> {
h: PropTypes.number.isRequired,

// All optional
minW: function (props, propName) {
minW: function (props: Props, propName: string) {
const value = props[propName];
if (typeof value !== 'number') return new Error('minWidth not Number');
if (value > props.w || value > props.maxW) return new Error('minWidth larger than item width/maxWidth');
},

maxW: function (props, propName) {
maxW: function (props: Props, propName: string) {
const value = props[propName];
if (typeof value !== 'number') return new Error('maxWidth not Number');
if (value < props.w || value < props.minW) return new Error('maxWidth smaller than item width/minWidth');
},

minH: function (props, propName) {
minH: function (props: Props, propName: string) {
const value = props[propName];
if (typeof value !== 'number') return new Error('minHeight not Number');
if (value > props.h || value > props.maxH) return new Error('minHeight larger than item height/maxHeight');
},

maxH: function (props, propName) {
maxH: function (props: Props, propName: string) {
const value = props[propName];
if (typeof value !== 'number') return new Error('maxHeight not Number');
if (value < props.h || value < props.minH) return new Error('maxHeight smaller than item height/minHeight');
Expand Down
12 changes: 8 additions & 4 deletions lib/ReactGridLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export type Props = {
compactType: ?('horizontal' | 'vertical'),
layout: Layout,
margin: [number, number],
containerPadding: [number, number],
containerPadding: [number, number] | null,
rowHeight: number,
maxRows: number,
isDraggable: boolean,
Expand Down Expand Up @@ -83,7 +83,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
draggableHandle: PropTypes.string,

// Deprecated
verticalCompact: function(props) {
verticalCompact: function(props: Props) {
if (props.verticalCompact === false && process.env.NODE_ENV !== 'production') {
console.warn( // eslint-disable-line no-console
'`verticalCompact` on <ReactGridLayout> is deprecated and will be removed soon. ' +
Expand All @@ -95,7 +95,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {

// layout is an array of object with the format:
// {x: Number, y: Number, w: Number, h: Number, i: String}
layout: function (props) {
layout: function (props: Props) {
var layout = props.layout;
// I hope you're setting the data-grid property on the grid items
if (layout === undefined) return;
Expand Down Expand Up @@ -155,7 +155,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
//

// Children must not have duplicate keys.
children: function (props, propName, _componentName) {
children: function (props: Props, propName: string) {
var children = props[propName];

// Check children keys for duplicates. Throw if found.
Expand All @@ -173,6 +173,10 @@ export default class ReactGridLayout extends React.Component<Props, State> {
autoSize: true,
cols: 12,
className: '',
style: {},
draggableHandle: '',
draggableCancel: '',
containerPadding: null,
rowHeight: 150,
maxRows: Infinity, // infinite vertical growth
layout: [],
Expand Down
4 changes: 2 additions & 2 deletions lib/ResponsiveReactGridLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Props<Breakpoint: string = string> = {
onBreakpointChange: (Breakpoint, cols: number) => void,
onLayoutChange: (Layout, {[key: Breakpoint]: Layout}) => void,
onWidthChange:
(containerWidth: number, margin: [number, number], cols: number, containerPadding: [number, number]) => void
(containerWidth: number, margin: [number, number], cols: number, containerPadding: [number, number] | null) => void
};

export default class ResponsiveReactGridLayout extends React.Component<Props<>, State> {
Expand All @@ -57,7 +57,7 @@ export default class ResponsiveReactGridLayout extends React.Component<Props<>,

// layouts is an object mapping breakpoints to layouts.
// e.g. {lg: Layout, md: Layout, ...}
layouts(props, propName) {
layouts(props: Props<>, propName: string) {
if (type(props[propName]) !== '[object Object]') {
throw new Error('Layout property must be an object. Received: ' + type(props[propName]));
}
Expand Down

0 comments on commit ada960f

Please sign in to comment.