Skip to content

Commit 39ce6e6

Browse files
authored
0.26.0
2 parents a3ce705 + 2f834a5 commit 39ce6e6

File tree

13 files changed

+2765
-1801
lines changed

13 files changed

+2765
-1801
lines changed

.babelrc

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
{
2-
"presets": [
3-
"env",
4-
"react"
5-
],
2+
"presets": ["@babel/preset-env", "@babel/preset-react"],
63
"plugins": [
7-
"transform-class-properties",
8-
"transform-object-rest-spread"
4+
"@babel/plugin-proposal-class-properties",
5+
"@babel/plugin-proposal-object-rest-spread"
96
],
107
"env": {
118
"production": {
129
"plugins": [
1310
[
1411
"react-remove-properties",
1512
{
16-
"properties": [
17-
"data-testid"
18-
]
13+
"properties": ["data-testid"]
1914
}
2015
]
2116
],
22-
"ignore": [
23-
"src/lib/__tests__/**"
24-
]
17+
"ignore": ["src/lib/__tests__/**"]
2518
}
2619
}
2720
}

CHANGELOG.md

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,41 @@ and this project adheres (more or less) to [Semantic Versioning](http://semver.o
77

88
## Unreleased
99

10+
## 0.26.0
11+
12+
#### Added
13+
14+
* Add `onItemDrag` prop to `<Timeline />` #517 @bettymakes
15+
* Upgrade to Babel 7.5.0, Jest 24.8.0, Enzyme 3.10.0 @trevdor
16+
17+
#### Breaking
18+
19+
* Removed `<InfoLabel />` in favour of allowing for custom component to be rendered on move or resize. Check out the demo in `demo/app/demo-custom-info-label` for an example on how to display your own custom info label or [this example](https://codesandbox.io/s/timeline-demo-info-label-neec9).
20+
21+
1022
## 0.25.4
1123

12-
- Move `classnames` to a production dependency
24+
* Move `classnames` to a production dependency
1325

1426
## 0.25.3
1527

16-
- Fixed the `undefined` classnames in TimelineHeaders #566 @trevdor
28+
* Fixed the `undefined` classnames in TimelineHeaders #566 @trevdor
1729

1830
## 0.25.2
1931

20-
- Fixed the auto-scroll right bug in a scaled browser. #528 @cw196
32+
* Fixed the auto-scroll right bug in a scaled browser. #528 @cw196
2133

2234
## 0.25.1
2335

24-
- fix error when using `week` unit causing format error in `DateHeader` #562 @dkarnutsch
25-
- fix Wheel/Mousewheel Event errors on chrome 73 #541 @ilaiwi
36+
* fix error when using `week` unit causing format error in `DateHeader` #562 @dkarnutsch
37+
* fix Wheel/Mousewheel Event errors on chrome 73 #541 @ilaiwi
2638

2739
## 0.25.0
2840

2941
### Custom Headers
3042

3143
This new feature gives more control to dev to create customizable headers to provide better UI. Now user have more control through a set of new components to render headers. This new feature came with a breaking change though.
3244

33-
3445
```jsx
3546
import Timeline, {
3647
TimelineHeaders,
@@ -93,23 +104,23 @@ import Timeline, {
93104
Check out the new docs before please [here](https://github.com/namespace-ee/react-calendar-timeline/tree/custom-headers#timeline-headers)
94105

95106
#### removed props
96-
- `stickyOffset` and `stickyHeader` now you can make your header sticky by following this [examples](https://github.com/namespace-ee/react-calendar-timeline/tree/master/examples#custom-item-rendering)
97-
- `headerRef` to get the headerRef you need to pass ref callback to `TimelineHeader` component
98-
- `headerLabelGroupHeight` and `headerLabelHeight` now you can pass a `height` prop to both `CustomHeader` and `DateHeader`
99-
- `headerLabelFormats` and `subHeaderLabelFormats` not you can pass `formatLabel` function to `DateHeader` with label width and start and end time of intervals
100107

108+
* `stickyOffset` and `stickyHeader` now you can make your header sticky by following this [examples](https://github.com/namespace-ee/react-calendar-timeline/tree/master/examples#custom-item-rendering)
109+
* `headerRef` to get the headerRef you need to pass ref callback to `TimelineHeader` component
110+
* `headerLabelGroupHeight` and `headerLabelHeight` now you can pass a `height` prop to both `CustomHeader` and `DateHeader`
111+
* `headerLabelFormats` and `subHeaderLabelFormats` not you can pass `formatLabel` function to `DateHeader` with label width and start and end time of intervals
101112

102113
## 0.23.1
103114

104-
- fix height calculation of stacked items is off if no item is visible in a line @Felix-N
105-
- fix Unsubscribing markers correctly when unmounted @gaston-niglia
115+
* fix height calculation of stacked items is off if no item is visible in a line @Felix-N
116+
* fix Unsubscribing markers correctly when unmounted @gaston-niglia
106117

107118
## 0.23.0
108119

109-
- improve unit tests coverage #426 - @ilaiwi
110-
- stack items by group #384 - @acemac
111-
- fix bug where `canMove` prop gets ignored #484 - @acemac + @ilaiwi
112-
- fix sidebar re-render when groupHeights do not change #478 - @SDupZ
120+
* improve unit tests coverage #426 - @ilaiwi
121+
* stack items by group #384 - @acemac
122+
* fix bug where `canMove` prop gets ignored #484 - @acemac + @ilaiwi
123+
* fix sidebar re-render when groupHeights do not change #478 - @SDupZ
113124

114125
### Stack per group
115126

@@ -156,7 +167,6 @@ ReactDOM.render(
156167
)
157168
```
158169

159-
160170
## 0.22.0
161171

162172
### Fixed
@@ -181,9 +191,11 @@ ReactDOM.render(
181191
### 0.20.0
182192

183193
### improvements
194+
184195
* eliminate extra renders on every scroll - #357 [acemac](https://github.com/acemac)
185196

186197
### Fixed
198+
187199
* When the `date` prop on a `CustomMarker` changes the marker will now move on the timeline - #421 [kevinmanncito](https://github.com/kevinmanncito) [ilaiwi](https://github.com/ilaiwi)
188200
* Header has a bounce effect - #311 [acemac](https://github.com/acemac)
189201

@@ -192,8 +204,6 @@ ReactDOM.render(
192204
* update to `react-testing-library` version 5
193205
* remove deprecated `toBeInDom`
194206

195-
196-
197207
### 0.19.0
198208

199209
### Added
@@ -232,7 +242,7 @@ ReactDOM.render(
232242

233243
### Breaking
234244

235-
* Removed support for React 15 and lower. This is due to the fact that 16+ supports returning arrays from render, something that the TimelineMarker feature relies on.
245+
* Removed support for React 15 and lower. This is due to the fact that 16+ supports returning arrays from render, something that the TimelineMarker feature relies on.
236246
* removed `showCursorLine` prop in favor of using the `CursorMarker` component. See `TimelineMarkers` section of README for documentation.
237247

238248
```diff
@@ -256,6 +266,7 @@ from 'react-calendar-timeline'
256266
### 0.17.3
257267

258268
### Added
269+
259270
* fix issue with single row header - #359
260271

261272
### 0.17.2

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ An array specifying keys in the `items` and `groups` objects. Defaults to
153153
groupIdKey: 'id',
154154
groupTitleKey: 'title',
155155
groupRightTitleKey: 'rightTitle',
156-
groupLabelKey: 'title', // key for what to show in `InfoLabel`
157156
itemIdKey: 'id',
158157
itemTitleKey: 'title', // key for item div content
159158
itemDivTitleKey: 'title', // key for item div title (<div title="text"/>)
@@ -256,6 +255,19 @@ Default:
256255

257256
Ref callback that gets a DOM reference to the scroll body element. Can be useful to programmatically scroll.
258257

258+
## onItemDrag(itemDragObject)
259+
260+
Called when an item is moving or resizing. Returns an object with the following properties:
261+
262+
| property | type | description |
263+
| ------------------ | -------- | ---------------------------------------------------------------------- |
264+
| `eventType` | `string` | retuns either `move` or `resize` |
265+
| `itemId` | `number` | ID of the item being moved or resized |
266+
| `time` | `number` | UNIX timestamp in milliseconds |
267+
| `edge` | `string` | on `resize`, returns a value of either `left` or `right` |
268+
| `newGroupOrder` | `number` | on `move`, index position of the new group that the item is moving to |
269+
270+
259271
## onItemMove(itemId, dragTime, newGroupOrder)
260272

261273
Callback when an item is moved. Returns 1) the item's ID, 2) the new start time and 3) the index of the new group in the `groups` array.

config/jest-setup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'regenerator-runtime/runtime'
12
const Enzyme = require('enzyme')
23
const Adapter = require('enzyme-adapter-react-16')
34

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React from 'react'
2+
import PropTypes from 'prop-types'
3+
4+
export default function CustomInfoLabel(props) {
5+
const { time, groupTitle, heading } = props
6+
7+
return (
8+
<div
9+
style={{
10+
position: 'fixed',
11+
bottom: '100px',
12+
left: '100px',
13+
backgroundColor: '#E3F1DF',
14+
color: '#212B36',
15+
padding: '6px 12px',
16+
fontSize: '16px',
17+
borderRadius: '8px',
18+
boxShadow:
19+
'0 1px 3px rgba(0, 0, 0, 0.2), 0 10px 20px rgba(0, 0, 0, 0.05)'
20+
}}
21+
>
22+
<div
23+
style={{
24+
fontWeight: 'bold',
25+
borderBottom: '1px solid #ccc',
26+
paddingBottom: '3px',
27+
marginBottom: '3px'
28+
}}
29+
>
30+
<span>
31+
{heading} {groupTitle}
32+
</span>
33+
</div>
34+
{time}
35+
</div>
36+
)
37+
}
38+
39+
CustomInfoLabel.propTypes = {
40+
time: PropTypes.string,
41+
groupTitle: PropTypes.string,
42+
heading: PropTypes.string
43+
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import React, { Component } from 'react'
2+
import moment from 'moment'
3+
4+
import Timeline from 'react-calendar-timeline'
5+
import CustomInfoLabel from './CustomInfoLabel'
6+
7+
import generateFakeData from '../generate-fake-data'
8+
9+
var keys = {
10+
groupIdKey: 'id',
11+
groupTitleKey: 'title',
12+
groupRightTitleKey: 'rightTitle',
13+
itemIdKey: 'id',
14+
itemTitleKey: 'title',
15+
itemDivTitleKey: 'title',
16+
itemGroupKey: 'group',
17+
itemTimeStartKey: 'start',
18+
itemTimeEndKey: 'end',
19+
groupLabelKey: 'title'
20+
}
21+
22+
export default class App extends Component {
23+
constructor(props) {
24+
super(props)
25+
26+
const { groups, items } = generateFakeData(5, 20)
27+
const defaultTimeStart = moment()
28+
.startOf('day')
29+
.toDate()
30+
const defaultTimeEnd = moment()
31+
.startOf('day')
32+
.add(1, 'day')
33+
.toDate()
34+
35+
this.state = {
36+
groups,
37+
items,
38+
defaultTimeStart,
39+
defaultTimeEnd,
40+
showInfoLabel: false,
41+
infoLabelTime: '',
42+
infoLabelGroupTitle: '',
43+
infoLabelHeading: ''
44+
}
45+
}
46+
47+
handleItemMove = (itemId, dragTime, newGroupOrder) => {
48+
const { items, groups } = this.state
49+
50+
const group = groups[newGroupOrder]
51+
52+
this.setState({
53+
items: items.map(
54+
item =>
55+
item.id === itemId
56+
? Object.assign({}, item, {
57+
start: dragTime,
58+
end: dragTime + (item.end - item.start),
59+
group: group.id
60+
})
61+
: item
62+
),
63+
showInfoLabel: false,
64+
infoLabelTime: ''
65+
})
66+
}
67+
68+
handleItemResize = (itemId, time, edge) => {
69+
const { items } = this.state
70+
71+
this.setState({
72+
items: items.map(
73+
item =>
74+
item.id === itemId
75+
? Object.assign({}, item, {
76+
start: edge === 'left' ? time : item.start,
77+
end: edge === 'left' ? item.end : time
78+
})
79+
: item
80+
),
81+
showInfoLabel: false,
82+
infoLabelTime: ''
83+
})
84+
}
85+
86+
handleItemDrag = ({ eventType, itemId, time, edge, newGroupOrder }) => {
87+
const group = this.state.groups[newGroupOrder]
88+
const infoLabelGroupTitle = group ? group.title : ''
89+
const infoLabelTime = moment(time).format('dddd, MMMM Do YYYY')
90+
let heading = ''
91+
switch (eventType) {
92+
case 'move':
93+
heading = '🚚 Moving'
94+
break
95+
case 'resize':
96+
heading = '📅 Resizing'
97+
break
98+
}
99+
100+
if (
101+
this.state.infoLabelTime !== infoLabelTime ||
102+
this.state.infoLabelGroupTitle !== infoLabelGroupTitle
103+
) {
104+
this.setState({
105+
showInfoLabel: true,
106+
infoLabelTime,
107+
infoLabelGroupTitle,
108+
infoLabelHeading: heading
109+
})
110+
}
111+
}
112+
113+
render() {
114+
const {
115+
groups,
116+
items,
117+
defaultTimeStart,
118+
defaultTimeEnd,
119+
showInfoLabel,
120+
infoLabelTime,
121+
infoLabelGroupTitle,
122+
infoLabelHeading
123+
} = this.state
124+
125+
const customInfoLabelMarkup = showInfoLabel ? (
126+
<CustomInfoLabel
127+
time={infoLabelTime}
128+
groupTitle={infoLabelGroupTitle}
129+
heading={infoLabelHeading}
130+
/>
131+
) : null
132+
133+
return (
134+
<div>
135+
{customInfoLabelMarkup}
136+
<Timeline
137+
groups={groups}
138+
items={items}
139+
keys={keys}
140+
fullUpdate
141+
itemTouchSendsClick={false}
142+
stackItems
143+
itemHeightRatio={0.75}
144+
canMove={true}
145+
canResize={'both'}
146+
defaultTimeStart={defaultTimeStart}
147+
defaultTimeEnd={defaultTimeEnd}
148+
onItemMove={this.handleItemMove}
149+
onItemResize={this.handleItemResize}
150+
onItemDrag={this.handleItemDrag}
151+
/>
152+
</div>
153+
)
154+
}
155+
}

0 commit comments

Comments
 (0)