Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…-timeline into TechExMachina-master
  • Loading branch information
rcdexta committed Feb 20, 2018
2 parents e4df4ee + b4f17ac commit 4c4445e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 22 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ Please refer to [story description](https://github.com/rcdexta/react-event-timel
This is the wrapper component that creates the infinite vertical timeline
| Name | Type | Description |
| --------- | ------ | ---------------------------------------- |
| className | string | The css class name of timeline container|
| style | object | Override inline styles of timeline container |
| Name | Type | Description |
| -------------- | ------ | ---------------------------------------- |
| className | string | The css class name of timeline container|
| style | object | Override inline styles of timeline container |
| bubblePosition | string | Display the timeline at `right` or `left`. Default: `left` |
### TimelineEvent
Expand Down
14 changes: 9 additions & 5 deletions components/Timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import PropTypes from 'prop-types'
import s from './styles'

class Timeline extends Component {

render () {
const { bubblePosition = 'left', children, style = {}, ...otherProps } = this.props
const childrenWithProps = React.Children.map(children, child => React.cloneElement(child, { bubblePosition }))
const leftOrRight = (bubblePosition === 'right') ? {...s['containerBefore--right']} : {...s['containerBefore--left']}
return (
<div>
<section style={s.container} {...this.props}>
<div style={s.containerBefore} />
{this.props.children}
<section style={{...s.container, ...style}} {...otherProps}>
<div style={{...s.containerBefore, ...leftOrRight}} />
{childrenWithProps}
<div style={s.containerAfter} />
</section >
</div>
Expand All @@ -18,7 +20,9 @@ class Timeline extends Component {
}

Timeline.propTypes = {
children: PropTypes.node.isRequired
children: PropTypes.node.isRequired,
bubblePosition: PropTypes.string,
style: PropTypes.object
}

export default Timeline
19 changes: 12 additions & 7 deletions components/TimelineEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import PropTypes from 'prop-types'
import s from './styles'

class TimelineEvent extends Component {

mergeNotificationStyle(iconColor, bubbleStyle) {
mergeNotificationStyle(iconColor, bubbleStyle, bubblePosition) {
const iconColorStyle = iconColor ? {...s.eventType, ...{color: iconColor, borderColor: iconColor}} : s.eventType
return {...iconColorStyle, ...bubbleStyle}
const leftOrRight = (bubblePosition === 'right') ? {...s['eventType--right']} : {...s['eventType--left']}
return {...iconColorStyle, ...bubbleStyle, ...leftOrRight}
}

mergeContentStyle(contentStyle) {
Expand Down Expand Up @@ -44,11 +44,14 @@ class TimelineEvent extends Component {
cardHeaderStyle,
titleStyle,
subtitleStyle,
bubblePosition,
...otherProps
} = this.props
const leftOrRightEvent = (bubblePosition === 'right') ? {...s['event--right']} : {...s['event--left']}
const leftOrRightButton = (bubblePosition === 'left') ? {...s['actionButtons--right']} : {...s['actionButtons--left']}
return (
<div style={s.event}>
<div style={this.mergeNotificationStyle(iconColor, bubbleStyle)}>
<div style={{...s.event, ...leftOrRightEvent}}>
<div style={this.mergeNotificationStyle(iconColor, bubbleStyle, bubblePosition)}>
<span style={{...s.materialIcons, ...iconStyle}}>
{icon}
</span>
Expand All @@ -67,7 +70,7 @@ class TimelineEvent extends Component {
<div style={{...s.subtitle, ...subtitleStyle}}>
{subtitle}
</div>}
<div style={s.actionButtons}>
<div style={{...s.actionButtons, ...leftOrRightButton}}>
{buttons}
</div>
</div>
Expand All @@ -94,6 +97,7 @@ TimelineEvent.propTypes = {
iconColor: PropTypes.string,
iconStyle: PropTypes.object,
bubbleStyle: PropTypes.object,
bubblePosition: PropTypes.string,
contentStyle: PropTypes.object,
cardHeaderStyle: PropTypes.object,
style: PropTypes.object,
Expand All @@ -109,7 +113,8 @@ TimelineEvent.defaultProps = {
cardHeaderStyle: {},
style: {},
titleStyle: {},
subtitleStyle: {}
subtitleStyle: {},
bubblePosition: 'left'
}

export default TimelineEvent
35 changes: 29 additions & 6 deletions components/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,32 @@ let style = {
content: '',
position: 'absolute',
top: 0,
left: 18,
height: '100%',
width: 2,
background: '#a0b2b8'
},
'containerBefore--left': {
left: '16px'
},
'containerBefore--right': {
right: '14px'
},
containerAfter: {
content: '',
display: 'table',
clear: 'both'
},
event: {
position: 'relative',
margin: '10px 0',
paddingLeft: 45
margin: '10px 0'
},
'event--left': {
paddingLeft: 45,
textAlign: 'left'
},
'event--right': {
paddingRight: 45,
textAlign: 'right'
},
eventAfter: {
clear: 'both',
Expand All @@ -35,7 +47,6 @@ let style = {
eventType: {
position: 'absolute',
top: 0,
left: 0,
borderRadius: '50%',
width: 30,
height: 30,
Expand All @@ -44,6 +55,12 @@ let style = {
border: '2px solid #6fba1c',
display: 'flex'
},
'eventType--left': {
left: 0
},
'eventType--right': {
right: 0
},
materialIcons: {
display: 'flex',
width: 32,
Expand Down Expand Up @@ -85,10 +102,16 @@ let style = {
display: 'table'
},
actionButtons: {
float: 'right',
textAlign: 'right',
marginTop: -20
},
'actionButtons--left': {
float: 'left',
textAlign: 'left'
},
'actionButtons--right': {
float: 'right',
textAlign: 'right'
},
card: {
boxShadow: 'rgba(0, 0, 0, 0.117647) 0px 1px 6px, rgba(0, 0, 0, 0.117647) 0px 1px 4px',
backgroundColor: 'rgb(255, 255, 255)'
Expand Down

0 comments on commit 4c4445e

Please sign in to comment.