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

Add minHeight Props to Timeline to set the minimum height of the timeline scroll body #724

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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres (more or less) to [Semantic Versioning](http://semver.o

* Add `className` prop to Timeline component to override `react-calendar-timeline` class #682

## 0.26.8

* add minHeight props for Component Timeline @markstock7

## 0.26.7

* fix scrolling with trackpad @ilaiwi #679
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ Everything passed here will be displayed above the right sidebar. Use this to di

Snapping unit when dragging items. Defaults to `15 * 60 * 1000` or 15min. When so, the items will snap to 15min intervals when dragging.

# minHeight
The minimum height, in pixels, of a timeline body. Default to `20`.

## minResizeWidth

The minimum width, in pixels, of a timeline entry when it's possible to resize. If not reached, you must zoom in to resize more. Default to `20`.
Expand Down
1 change: 1 addition & 0 deletions __fixtures__/stateAndProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const visibleTimeEnd = 1540587600000
export const props = {
keys: defaultKeys,
lineHeight: 30,
minHeight: 0,
stackItems: true,
itemHeightRatio: 0.75,
visibleTimeEnd,
Expand Down
34 changes: 17 additions & 17 deletions __tests__/utils/calendar/__snapshots__/stack-items.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ Object {
"dimensionItems": Array [
Object {
"dimensions": Object {
"collisionLeft": 1540543600000,
"collisionLeft": 1540540000000,
"collisionWidth": 6803877,
"height": 22.5,
"left": 4472.222222222223,
"height": 0,
"left": 4347.222222222223,
"order": Object {
"group": Object {
"id": "1",
},
"index": 0,
},
"stack": true,
"top": 3.75,
"top": 15,
"width": 236.24572916666602,
},
"id": "0",
Expand All @@ -25,7 +25,7 @@ Object {
"dimensions": Object {
"collisionLeft": 1540532800000,
"collisionWidth": 21203877,
"height": 22.5,
"height": 0,
"left": 4097.222222222223,
"order": Object {
"group": Object {
Expand All @@ -34,7 +34,7 @@ Object {
"index": 0,
},
"stack": true,
"top": 33.75,
"top": 15,
"width": 736.245729166666,
},
"id": "5",
Expand All @@ -43,7 +43,7 @@ Object {
"dimensions": Object {
"collisionLeft": 1540550800000,
"collisionWidth": 24803877,
"height": 22.5,
"height": 0,
"left": 4722.222222222223,
"order": Object {
"group": Object {
Expand All @@ -52,7 +52,7 @@ Object {
"index": 0,
},
"stack": true,
"top": 3.75,
"top": 15,
"width": 861.245729166666,
},
"id": "6",
Expand All @@ -61,7 +61,7 @@ Object {
"dimensions": Object {
"collisionLeft": 1540570000000,
"collisionWidth": 14875919,
"height": 22.5,
"height": 0,
"left": 5388.888888888889,
"order": Object {
"group": Object {
Expand All @@ -70,7 +70,7 @@ Object {
"index": 0,
},
"stack": true,
"top": 33.75,
"top": 15,
"width": 516.5249652777784,
},
"id": "1",
Expand All @@ -79,7 +79,7 @@ Object {
"dimensions": Object {
"collisionLeft": 1540620000000,
"collisionWidth": 20397548,
"height": 22.5,
"height": 0,
"left": 7125,
"order": Object {
"group": Object {
Expand All @@ -88,7 +88,7 @@ Object {
"index": 0,
},
"stack": true,
"top": 3.75,
"top": 15,
"width": 708.2481944444444,
},
"id": "2",
Expand All @@ -97,7 +97,7 @@ Object {
"dimensions": Object {
"collisionLeft": 1540656000000,
"collisionWidth": 20397548,
"height": 22.5,
"height": 0,
"left": 8375,
"order": Object {
"group": Object {
Expand All @@ -106,23 +106,23 @@ Object {
"index": 2,
},
"stack": true,
"top": 93.75,
"top": 75,
"width": 625,
},
"id": "3",
},
],
"groupHeights": Array [
60,
30,
30,
30,
],
"groupTops": Array [
0,
30,
60,
90,
],
"height": 120,
"height": 90,
}
`;

Expand Down
7 changes: 7 additions & 0 deletions __tests__/utils/calendar/stack-items.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('stackItems', () => {
state.canvasTimeStart,
state.canvasTimeEnd,
props.keys,
props.minHeight,
props.lineHeight,
props.itemHeightRatio,
props.stackItems,
Expand All @@ -39,6 +40,7 @@ describe('stackItems', () => {
state.canvasTimeStart,
state.canvasTimeEnd,
propsNoStack.keys,
propsNoStack.minHeight,
propsNoStack.lineHeight,
propsNoStack.itemHeightRatio,
propsNoStack.stackItems,
Expand All @@ -60,7 +62,9 @@ describe('stackItems', () => {
stateMoveItem.canvasTimeStart,
stateMoveItem.canvasTimeEnd,
props.keys,
props.minHeight,
props.lineHeight,
props.minHeight,
props.itemHeightRatio,
props.stackItems,
stateMoveItem.draggingItem,
Expand All @@ -81,6 +85,7 @@ describe('stackItems', () => {
stateResizeItemLeft.canvasTimeStart,
stateResizeItemLeft.canvasTimeEnd,
props.keys,
props.minHeight,
props.lineHeight,
props.itemHeightRatio,
props.stackItems,
Expand All @@ -102,6 +107,7 @@ describe('stackItems', () => {
stateResizeItemRight.canvasTimeStart,
stateResizeItemRight.canvasTimeEnd,
props.keys,
props.minHeight,
props.lineHeight,
props.itemHeightRatio,
props.stackItems,
Expand All @@ -123,6 +129,7 @@ describe('stackItems', () => {
state.canvasTimeStart,
state.canvasTimeEnd,
props.keys,
props.minHeight,
props.lineHeight,
props.itemHeightRatio,
props.stackItems,
Expand Down
1 change: 1 addition & 0 deletions demo/app/demo-main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export default class App extends Component {
<Timeline
groups={groups}
items={items}
minHeight={1500}
keys={keys}
sidebarWidth={150}
sidebarContent={<div>Above The Left</div>}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-calendar-timeline",
"version": "0.26.7",
"version": "0.26.8",
"description": "react calendar timeline",
"main": "lib/index.js",
"scripts": {
Expand Down
7 changes: 7 additions & 0 deletions src/lib/Timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default class ReactCalendarTimeline extends Component {
lineHeight: PropTypes.number,
itemHeightRatio: PropTypes.number,

minHeight: PropTypes.number,
minZoom: PropTypes.number,
maxZoom: PropTypes.number,

Expand Down Expand Up @@ -169,6 +170,8 @@ export default class ReactCalendarTimeline extends Component {
lineHeight: 30,
itemHeightRatio: 0.65,

minHeight: 0,

minZoom: 60 * 60 * 1000, // 1 hour
maxZoom: 5 * 365.24 * 86400 * 1000, // 5 years

Expand Down Expand Up @@ -322,6 +325,7 @@ export default class ReactCalendarTimeline extends Component {
this.state.canvasTimeStart,
this.state.canvasTimeEnd,
props.keys,
props.minHeight,
props.lineHeight,
props.itemHeightRatio,
props.stackItems,
Expand Down Expand Up @@ -399,6 +403,7 @@ export default class ReactCalendarTimeline extends Component {
prevState.canvasTimeStart,
prevState.canvasTimeEnd,
nextProps.keys,
nextProps.minHeight,
nextProps.lineHeight,
nextProps.itemHeightRatio,
nextProps.stackItems,
Expand Down Expand Up @@ -469,6 +474,7 @@ export default class ReactCalendarTimeline extends Component {
this.state.canvasTimeStart,
this.state.canvasTimeEnd,
props.keys,
props.minHeight,
props.lineHeight,
props.itemHeightRatio,
props.stackItems,
Expand Down Expand Up @@ -1001,6 +1007,7 @@ export default class ReactCalendarTimeline extends Component {
this.state.canvasTimeStart,
this.state.canvasTimeEnd,
this.props.keys,
this.props.minHeight,
this.props.lineHeight,
this.props.itemHeightRatio,
this.props.stackItems,
Expand Down
6 changes: 4 additions & 2 deletions src/lib/utility/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ export function stackTimelineItems(
canvasTimeStart,
canvasTimeEnd,
keys,
minHeight,
lineHeight,
itemHeightRatio,
stackItems,
Expand Down Expand Up @@ -501,7 +502,7 @@ export function stackTimelineItems(
if (groups.length === 0) {
return {
dimensionItems: [],
height: 0,
height: minHeight,
groupHeights: [],
groupTops: []
}
Expand Down Expand Up @@ -530,7 +531,7 @@ export function stackTimelineItems(
lineHeight,
stackItems
)
return { dimensionItems, height, groupHeights, groupTops }
return { dimensionItems, height: height > minHeight ? height : minHeight, groupHeights, groupTops }
}

/**
Expand Down Expand Up @@ -704,6 +705,7 @@ export function calculateScrollCanvas(
mergedState.canvasTimeStart,
mergedState.canvasTimeEnd,
props.keys,
props.minHeight,
props.lineHeight,
props.itemHeightRatio,
props.stackItems,
Expand Down