forked from opentripplanner/otp-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move TripDetail component to its own file.
- Loading branch information
1 parent
76f4a41
commit cb9e7ea
Showing
2 changed files
with
73 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import PropTypes from "prop-types"; | ||
import React, { Component } from "react"; | ||
import { QuestionCircle, TimesCircle } from "styled-icons/fa-solid"; | ||
import { VelocityTransitionGroup } from "velocity-react"; | ||
|
||
import * as Styled from "./styled"; | ||
|
||
export default class TripDetail extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
expanded: false | ||
}; | ||
} | ||
|
||
toggle = () => { | ||
const { expanded } = this.state; | ||
if (expanded) this.onHideClick(); | ||
else this.onExpandClick(); | ||
}; | ||
|
||
onExpandClick = () => { | ||
this.setState({ expanded: true }); | ||
}; | ||
|
||
onHideClick = () => { | ||
this.setState({ expanded: false }); | ||
}; | ||
|
||
render() { | ||
const { icon, summary, description } = this.props; | ||
const { expanded } = this.state; | ||
return ( | ||
<Styled.TripDetail> | ||
<Styled.TripDetailIcon>{icon}</Styled.TripDetailIcon> | ||
<Styled.TripDetailSummary> | ||
{summary} | ||
{description && ( | ||
<Styled.ExpandButton onClick={this.toggle}> | ||
<QuestionCircle size={17} /> | ||
</Styled.ExpandButton> | ||
)} | ||
<VelocityTransitionGroup | ||
enter={{ animation: "slideDown" }} | ||
leave={{ animation: "slideUp" }} | ||
> | ||
{expanded && ( | ||
<Styled.TripDetailDescription> | ||
<Styled.HideButton onClick={this.onHideClick}> | ||
<TimesCircle size={17} /> | ||
</Styled.HideButton> | ||
{description} | ||
</Styled.TripDetailDescription> | ||
)} | ||
</VelocityTransitionGroup> | ||
</Styled.TripDetailSummary> | ||
</Styled.TripDetail> | ||
); | ||
} | ||
} | ||
|
||
TripDetail.propTypes = { | ||
icon: PropTypes.node.isRequired, | ||
summary: PropTypes.node.isRequired, | ||
description: PropTypes.node | ||
}; | ||
|
||
TripDetail.defaultProps = { | ||
description: undefined | ||
}; |