Skip to content

Commit

Permalink
feat: adds currentTimeIndicator component to Calendar (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
PagingMatt authored May 16, 2022
1 parent 3a1a21b commit e3eed70
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ class Calendar extends React.Component {
* timeSlotWrapper: MyTimeSlotWrapper,
* timeGutterHeader: MyTimeGutterWrapper,
* resourceHeader: MyResourceHeader,
* currentTimeIndicator: MyCurrentTimeIndicator,
* toolbar: MyToolbar,
* agenda: {
* event: MyAgendaEvent, // with the agenda view use a different component to render events
Expand Down Expand Up @@ -764,6 +765,8 @@ class Calendar extends React.Component {
timeGutterHeader: PropTypes.elementType,
resourceHeader: PropTypes.elementType,

currentTimeIndicator: PropTypes.elementType,

toolbar: PropTypes.elementType,

agenda: PropTypes.shape({
Expand Down
12 changes: 12 additions & 0 deletions src/CurrentTimeIndicator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import PropTypes from 'prop-types'
import React from 'react'

const CurrentTimeIndicator = ({ position }) => (
<div className="rbc-current-time-indicator" style={{ top: `${position}%` }} />
)

CurrentTimeIndicator.propTypes = {
position: PropTypes.number,
}

export default CurrentTimeIndicator
9 changes: 6 additions & 3 deletions src/DayColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import TimeSlotGroup from './TimeSlotGroup'
import TimeGridEvent from './TimeGridEvent'
import { DayLayoutAlgorithmPropType } from './utils/propTypes'

import CurrentTimeIndicator from './CurrentTimeIndicator'
import DayColumnWrapper from './DayColumnWrapper'

class DayColumn extends React.Component {
Expand Down Expand Up @@ -124,6 +125,9 @@ class DayColumn extends React.Component {

const { className, style } = dayProp(max)

const CurrentTimeIndicatorComponent =
components.currentTimeIndicator || CurrentTimeIndicator

const DayColumnWrapperComponent =
components.dayColumnWrapper || DayColumnWrapper

Expand Down Expand Up @@ -173,9 +177,8 @@ class DayColumn extends React.Component {
</div>
)}
{isNow && this.intervalTriggered && (
<div
className="rbc-current-time-indicator"
style={{ top: `${this.state.timeIndicatorPosition}%` }}
<CurrentTimeIndicatorComponent
position={this.state.timeIndicatorPosition}
/>
)}
</DayColumnWrapperComponent>
Expand Down

0 comments on commit e3eed70

Please sign in to comment.