@opentripplanner/from-to-location-picker 1.3.0 → 2.1.1-alpha.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.
- package/esm/index.js +75 -140
- package/esm/index.js.map +1 -1
- package/esm/styled.js +3 -3
- package/esm/styled.js.map +1 -1
- package/esm/types.js +2 -0
- package/esm/types.js.map +1 -0
- package/i18n/en-US.yml +15 -0
- package/i18n/fr.yml +15 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +72 -118
- package/lib/index.js.map +1 -1
- package/lib/styled.d.ts +4 -0
- package/lib/styled.d.ts.map +1 -0
- package/lib/styled.js +3 -3
- package/lib/styled.js.map +1 -1
- package/lib/types.d.ts +38 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/package.json +5 -5
- package/src/__unpublished__/messages.d.ts +2 -0
- package/src/index.story.tsx +48 -0
- package/src/index.tsx +98 -0
- package/src/{styled.js → styled.ts} +0 -0
- package/src/types.ts +39 -0
- package/tsconfig.json +15 -0
- package/tsconfig.tsbuildinfo +4327 -0
- package/src/index.js +0 -103
- package/src/index.story.js +0 -37
package/lib/styled.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/styled.
|
|
1
|
+
{"version":3,"sources":["../src/styled.ts"],"names":["LocationPickerSpan","styled","span","FromToPickerSpan","Button","button"],"mappings":";;;;;;;;;AAAA;;AAEO,MAAMA,kBAAkB,GAAGC,0BAAOC,IAAV;AAAA;AAAA;AAAA,yCAAxB;;;;AAMA,MAAMC,gBAAgB,GAAGF,0BAAOC,IAAV;AAAA;AAAA;AAAA,4DAAtB;;;;AAOA,MAAME,MAAM,GAAGH,0BAAOI,MAAV;AAAA;AAAA;AAAA,6KAAZ","sourcesContent":["import styled from \"styled-components\";\n\nexport const LocationPickerSpan = styled.span`\n :first-of-type {\n border-left: none;\n }\n`;\n\nexport const FromToPickerSpan = styled.span`\n > * {\n padding-left: 0.4em;\n border-left: 1px solid black;\n }\n`;\n\nexport const Button = styled.button`\n background: none;\n border: none;\n color: navy;\n font-family: inherit;\n font-size: inherit;\n line-height: inherit;\n padding-left: 0.2em;\n\n :hover {\n text-decoration: underline;\n cursor: pointer;\n }\n`;\n"],"file":"styled.js"}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { Location } from "@opentripplanner/types";
|
|
3
|
+
export declare type FromToPickerProps = {
|
|
4
|
+
/**
|
|
5
|
+
* Specifies the label to be rendered, or if set to true, renders the default label "Plan a trip:".
|
|
6
|
+
*/
|
|
7
|
+
label?: boolean | React.ReactElement | string;
|
|
8
|
+
/**
|
|
9
|
+
* A specific location to associate with this. This is only used when combined
|
|
10
|
+
* with the setLocation prop.
|
|
11
|
+
*/
|
|
12
|
+
location?: Location;
|
|
13
|
+
/**
|
|
14
|
+
* Triggered when the user clicks on the "from" button.
|
|
15
|
+
*/
|
|
16
|
+
onFromClick?: () => void;
|
|
17
|
+
/**
|
|
18
|
+
* Triggered when the user clicks on the "to" button.
|
|
19
|
+
*/
|
|
20
|
+
onToClick?: () => void;
|
|
21
|
+
/**
|
|
22
|
+
* Triggered when the user clicks either the "from" or "to" button and there
|
|
23
|
+
* are no from/to specific handler functions defined as props.
|
|
24
|
+
*
|
|
25
|
+
* Passes an argument as follows:
|
|
26
|
+
* { locationType: "from/to", location, reverseGeocode: false }
|
|
27
|
+
*/
|
|
28
|
+
setLocation?: ({ locationType: string, location: Location, reverseGeocode: boolean }: {
|
|
29
|
+
locationType: any;
|
|
30
|
+
location: any;
|
|
31
|
+
reverseGeocode: any;
|
|
32
|
+
}) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Determines whether icons are shown on the "from" and "to" buttons.
|
|
35
|
+
*/
|
|
36
|
+
showIcons?: boolean;
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAEvD,oBAAY,iBAAiB,GAAG;IAC9B;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC,YAAY,GAAG,MAAM,CAAC;IAC9C;;;OAGG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,CAAC,EACb,YAAY,EAAE,MAAM,EAEpB,QAAQ,EAAE,QAAQ,EAClB,cAAc,EAAE,OAAO,EACxB;;;;KAAA,KAAK,IAAI,CAAC;IACX;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC"}
|
package/lib/types.js
ADDED
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"types.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentripplanner/from-to-location-picker",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.1-alpha.1",
|
|
4
4
|
"description": "Location Picker Component",
|
|
5
5
|
"author": "@binh-dam-ibigroup",
|
|
6
6
|
"homepage": "https://github.com/opentripplanner/otp-ui/#readme",
|
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
"module": "esm/index.js",
|
|
10
10
|
"private": false,
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@opentripplanner/location-icon": "^1.
|
|
13
|
-
"
|
|
14
|
-
"prop-types": "^15.7.2"
|
|
12
|
+
"@opentripplanner/location-icon": "^1.4.0",
|
|
13
|
+
"flat": "^5.0.2"
|
|
15
14
|
},
|
|
16
15
|
"peerDependencies": {
|
|
17
16
|
"react": "^16.14.0",
|
|
17
|
+
"react-intl": "^5.20.4",
|
|
18
18
|
"styled-components": "^5.3.0"
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"url": "git+https://github.com/opentripplanner/otp-ui.git"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
|
-
"
|
|
25
|
+
"tsc": "tsc"
|
|
26
26
|
},
|
|
27
27
|
"bugs": {
|
|
28
28
|
"url": "https://github.com/opentripplanner/otp-ui/issues"
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import React, { ReactElement } from "react";
|
|
2
|
+
import { IntlProvider } from "react-intl";
|
|
3
|
+
import { action } from "@storybook/addon-actions";
|
|
4
|
+
|
|
5
|
+
import FromToLocationPicker from ".";
|
|
6
|
+
|
|
7
|
+
import "../__mocks__/trimet-mock.css";
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
title: "From-To-Picker",
|
|
11
|
+
component: FromToLocationPicker
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const onFromClick = action("onFromClick");
|
|
15
|
+
const onToClick = action("onToClick");
|
|
16
|
+
|
|
17
|
+
export const fromTo = (): ReactElement => (
|
|
18
|
+
<FromToLocationPicker onFromClick={onFromClick} onToClick={onToClick} />
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export const smallTextSansSerif = (): ReactElement => (
|
|
22
|
+
<span style={{ fontSize: "75%", fontFamily: "sans-serif" }}>
|
|
23
|
+
<FromToLocationPicker
|
|
24
|
+
label
|
|
25
|
+
onFromClick={onFromClick}
|
|
26
|
+
onToClick={onToClick}
|
|
27
|
+
/>
|
|
28
|
+
</span>
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
export const customStyleAndText = (): React.ReactElement => (
|
|
32
|
+
<IntlProvider
|
|
33
|
+
locale="en-US"
|
|
34
|
+
messages={{
|
|
35
|
+
"otpUi.FromToLocationPicker.from": "Start here",
|
|
36
|
+
"otpUi.FromToLocationPicker.to": "Go here"
|
|
37
|
+
}}
|
|
38
|
+
>
|
|
39
|
+
<div className="trimet-ambient">
|
|
40
|
+
<FromToLocationPicker
|
|
41
|
+
label={<i style={{ color: "#ffff00" }}>Your trip:</i>}
|
|
42
|
+
onFromClick={onFromClick}
|
|
43
|
+
onToClick={onToClick}
|
|
44
|
+
showIcons={false}
|
|
45
|
+
/>
|
|
46
|
+
</div>
|
|
47
|
+
</IntlProvider>
|
|
48
|
+
);
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import flatten from "flat";
|
|
2
|
+
import LocationIcon from "@opentripplanner/location-icon";
|
|
3
|
+
import { FormattedMessage } from "react-intl";
|
|
4
|
+
import React, { ReactElement } from "react";
|
|
5
|
+
|
|
6
|
+
import * as S from "./styled";
|
|
7
|
+
|
|
8
|
+
// eslint-disable-next-line prettier/prettier
|
|
9
|
+
import type { FromToPickerProps } from "./types";
|
|
10
|
+
|
|
11
|
+
// Load the default messages.
|
|
12
|
+
import defaultEnglishMessages from "../i18n/en-US.yml";
|
|
13
|
+
|
|
14
|
+
const iconSize = "0.9em";
|
|
15
|
+
|
|
16
|
+
// HACK: We should flatten the messages loaded above because
|
|
17
|
+
// the YAML loaders behave differently between webpack and our version of jest:
|
|
18
|
+
// - the yaml loader for webpack returns a nested object,
|
|
19
|
+
// - the yaml loader for jest returns messages with flattened ids.
|
|
20
|
+
const defaultMessages: Record<string, string> = flatten(defaultEnglishMessages);
|
|
21
|
+
|
|
22
|
+
const FromToLocationPicker = ({
|
|
23
|
+
label = null,
|
|
24
|
+
location = null,
|
|
25
|
+
onFromClick = null,
|
|
26
|
+
onToClick = null,
|
|
27
|
+
setLocation = null,
|
|
28
|
+
showIcons = true
|
|
29
|
+
}: FromToPickerProps): ReactElement => {
|
|
30
|
+
const handleFromClick = () => {
|
|
31
|
+
if (onFromClick) {
|
|
32
|
+
onFromClick();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
setLocation({
|
|
36
|
+
location,
|
|
37
|
+
locationType: "from",
|
|
38
|
+
reverseGeocode: false
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const handleToClick = () => {
|
|
43
|
+
if (onToClick) {
|
|
44
|
+
onToClick();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
setLocation({
|
|
48
|
+
location,
|
|
49
|
+
locationType: "to",
|
|
50
|
+
reverseGeocode: false
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const labelIfAny = label === true
|
|
55
|
+
? (
|
|
56
|
+
<strong>
|
|
57
|
+
<FormattedMessage
|
|
58
|
+
defaultMessage={defaultMessages["otpUi.FromToLocationPicker.planATrip"]}
|
|
59
|
+
description="Label to prompt the user to plan a trip"
|
|
60
|
+
id="otpUi.FromToLocationPicker.planATrip"
|
|
61
|
+
/>
|
|
62
|
+
</strong>
|
|
63
|
+
)
|
|
64
|
+
: label
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<>
|
|
68
|
+
{labelIfAny}
|
|
69
|
+
<S.FromToPickerSpan>
|
|
70
|
+
<S.LocationPickerSpan>
|
|
71
|
+
{showIcons && <LocationIcon type="from" size={iconSize} />}
|
|
72
|
+
<S.Button onClick={handleFromClick}>
|
|
73
|
+
<FormattedMessage
|
|
74
|
+
defaultMessage={defaultMessages["otpUi.FromToLocationPicker.from"]}
|
|
75
|
+
description="Text for the 'from' button of the picker"
|
|
76
|
+
id="otpUi.FromToLocationPicker.from"
|
|
77
|
+
/>
|
|
78
|
+
</S.Button>
|
|
79
|
+
</S.LocationPickerSpan>
|
|
80
|
+
<S.LocationPickerSpan>
|
|
81
|
+
{showIcons && <LocationIcon type="to" size={iconSize} />}
|
|
82
|
+
<S.Button onClick={handleToClick}>
|
|
83
|
+
<FormattedMessage
|
|
84
|
+
defaultMessage={defaultMessages["otpUi.FromToLocationPicker.to"]}
|
|
85
|
+
description="Text for the 'to' button of the picker"
|
|
86
|
+
id="otpUi.FromToLocationPicker.to"
|
|
87
|
+
/>
|
|
88
|
+
</S.Button>
|
|
89
|
+
</S.LocationPickerSpan>
|
|
90
|
+
</S.FromToPickerSpan>
|
|
91
|
+
</>
|
|
92
|
+
);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export default FromToLocationPicker;
|
|
96
|
+
|
|
97
|
+
// Rename styled components for export
|
|
98
|
+
export { S as Styled };
|
|
File without changes
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// eslint-disable-next-line prettier/prettier
|
|
2
|
+
import type { Location } from "@opentripplanner/types";
|
|
3
|
+
|
|
4
|
+
export type FromToPickerProps = {
|
|
5
|
+
/**
|
|
6
|
+
* Specifies the label to be rendered, or if set to true, renders the default label "Plan a trip:".
|
|
7
|
+
*/
|
|
8
|
+
label?: boolean | React.ReactElement | string;
|
|
9
|
+
/**
|
|
10
|
+
* A specific location to associate with this. This is only used when combined
|
|
11
|
+
* with the setLocation prop.
|
|
12
|
+
*/
|
|
13
|
+
location?: Location;
|
|
14
|
+
/**
|
|
15
|
+
* Triggered when the user clicks on the "from" button.
|
|
16
|
+
*/
|
|
17
|
+
onFromClick?: () => void;
|
|
18
|
+
/**
|
|
19
|
+
* Triggered when the user clicks on the "to" button.
|
|
20
|
+
*/
|
|
21
|
+
onToClick?: () => void;
|
|
22
|
+
/**
|
|
23
|
+
* Triggered when the user clicks either the "from" or "to" button and there
|
|
24
|
+
* are no from/to specific handler functions defined as props.
|
|
25
|
+
*
|
|
26
|
+
* Passes an argument as follows:
|
|
27
|
+
* { locationType: "from/to", location, reverseGeocode: false }
|
|
28
|
+
*/
|
|
29
|
+
setLocation?: ({
|
|
30
|
+
locationType: string,
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
32
|
+
location: Location,
|
|
33
|
+
reverseGeocode: boolean
|
|
34
|
+
}) => void;
|
|
35
|
+
/**
|
|
36
|
+
* Determines whether icons are shown on the "from" and "to" buttons.
|
|
37
|
+
*/
|
|
38
|
+
showIcons?: boolean;
|
|
39
|
+
};
|
package/tsconfig.json
ADDED