Skip to content

Commit

Permalink
Move TripDetail component to its own file.
Browse files Browse the repository at this point in the history
  • Loading branch information
evansiroky committed Feb 13, 2020
1 parent 76f4a41 commit cb9e7ea
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 73 deletions.
76 changes: 3 additions & 73 deletions packages/trip-details/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@ import {
} from "@opentripplanner/core-utils/lib/types";
import moment from "moment";
import PropTypes from "prop-types";
import React, { Component } from "react";
import {
CalendarAlt,
Heartbeat,
MoneyBillAlt,
QuestionCircle,
TimesCircle
} from "styled-icons/fa-solid";
import { VelocityTransitionGroup } from "velocity-react";
import React from "react";
import { CalendarAlt, Heartbeat, MoneyBillAlt } from "styled-icons/fa-solid";

import * as Styled from "./styled";
import TripDetail from "./trip-detail";

export default function TripDetails({
className,
Expand Down Expand Up @@ -149,67 +143,3 @@ TripDetails.defaultProps = {
routingType: "ITINERARY",
timeOptions: null
};

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
};
70 changes: 70 additions & 0 deletions packages/trip-details/src/trip-detail.js
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
};

0 comments on commit cb9e7ea

Please sign in to comment.