@opentripplanner/trip-details 1.5.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -56,6 +56,12 @@ export const TransitFare = styled.details`
56
56
  `;
57
57
  export const TransitFareSingle = styled.span``;
58
58
 
59
+ export const FlexSummary = styled.span``;
60
+
61
+ export const FlexPickupSummary = styled.span``;
62
+
63
+ export const FlexDropOffSummary = styled.span``;
64
+
59
65
  export const TripDetail = styled.div`
60
66
  margin-top: 6px;
61
67
  `;
@@ -1,34 +1,43 @@
1
- import PropTypes from "prop-types";
2
- import React, { Component } from "react";
1
+ import React, { Component, ReactElement } from "react";
3
2
  import { QuestionCircle } from "@styled-icons/fa-solid/QuestionCircle";
4
3
  import { TimesCircle } from "@styled-icons/fa-solid/TimesCircle";
5
4
  import { VelocityTransitionGroup } from "velocity-react";
6
5
 
7
6
  import * as S from "./styled";
8
7
 
9
- export default class TripDetail extends Component {
10
- constructor(props) {
8
+ type Props = {
9
+ description?: ReactElement | string;
10
+ icon: ReactElement;
11
+ summary: ReactElement | string;
12
+ };
13
+
14
+ type State = {
15
+ expanded: boolean;
16
+ };
17
+
18
+ export default class TripDetail extends Component<Props, State> {
19
+ constructor(props: Props) {
11
20
  super(props);
12
21
  this.state = {
13
22
  expanded: false
14
23
  };
15
24
  }
16
25
 
17
- toggle = () => {
26
+ toggle = (): void => {
18
27
  const { expanded } = this.state;
19
28
  if (expanded) this.onHideClick();
20
29
  else this.onExpandClick();
21
30
  };
22
31
 
23
- onExpandClick = () => {
32
+ onExpandClick = (): void => {
24
33
  this.setState({ expanded: true });
25
34
  };
26
35
 
27
- onHideClick = () => {
36
+ onHideClick = (): void => {
28
37
  this.setState({ expanded: false });
29
38
  };
30
39
 
31
- render() {
40
+ render(): ReactElement {
32
41
  const { icon, summary, description } = this.props;
33
42
  const { expanded } = this.state;
34
43
  return (
@@ -59,13 +68,3 @@ export default class TripDetail extends Component {
59
68
  );
60
69
  }
61
70
  }
62
-
63
- TripDetail.propTypes = {
64
- icon: PropTypes.node.isRequired,
65
- summary: PropTypes.node.isRequired,
66
- description: PropTypes.node
67
- };
68
-
69
- TripDetail.defaultProps = {
70
- description: undefined
71
- };
package/src/types.ts ADDED
@@ -0,0 +1,74 @@
1
+ // Prettier does not recognize the import type syntax.
2
+ // eslint-disable-next-line prettier/prettier
3
+ import type { Itinerary } from "@opentripplanner/types";
4
+ import type { ReactElement } from "react";
5
+
6
+ export interface CaloriesDetailsProps {
7
+ bikeSeconds: number;
8
+ calories: number;
9
+ walkSeconds: number;
10
+ }
11
+
12
+ export interface DepartureDetailsProps {
13
+ departureDate: Date;
14
+ }
15
+
16
+ export interface TransitFareData {
17
+ [key: string]: {
18
+ currency: {
19
+ currencyCode: string
20
+ defaultFractionDigits: number
21
+ currency: string
22
+ symbol: string
23
+ };
24
+ cents: number;
25
+ }
26
+ }
27
+
28
+ export interface FareDetailsProps {
29
+ maxTNCFare: number;
30
+ minTNCFare: number;
31
+ transitFares: TransitFareData;
32
+ }
33
+
34
+ export interface TransitFareProps {
35
+ fareKey: string;
36
+ fareNameFallback?: ReactElement;
37
+ fareKeyNameMap: {
38
+ [key: string]: string;
39
+ };
40
+ transitFares: TransitFareData;
41
+ }
42
+
43
+ export interface TripDetailsProps {
44
+ /**
45
+ * Slot for a custom component to render the expandable section for calories.
46
+ */
47
+ CaloriesDetails?: React.ElementType<CaloriesDetailsProps>;
48
+ /**
49
+ * Used for additional styling with styled components for example.
50
+ */
51
+ className?: string;
52
+ /**
53
+ * Determines which transit fare should be displayed by default, should there be multiple transit fare types.
54
+ */
55
+ defaultFareKey?: string;
56
+ /**
57
+ * Slot for a custom component to render the expandable section for departure.
58
+ */
59
+ DepartureDetails?: React.ElementType<DepartureDetailsProps>;
60
+ /**
61
+ * Slot for a custom component to render the expandable section for fares.
62
+ */
63
+ FareDetails?: React.ElementType<FareDetailsProps>;
64
+ /**
65
+ * Mapping between fare keys and human-readable names for them.
66
+ */
67
+ fareKeyNameMap?: {
68
+ [name: string]: string;
69
+ };
70
+ /**
71
+ * Itinerary that the user has selected to view, contains multiple legs.
72
+ */
73
+ itinerary: Itinerary;
74
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "composite": true,
5
+ "outDir": "./lib",
6
+ "rootDir": "./src",
7
+ "skipLibCheck": true
8
+ },
9
+ "include": ["src/**/*"],
10
+ "references": [
11
+ {
12
+ "path": "../types"
13
+ }
14
+ ]
15
+ }