@opentripplanner/from-to-location-picker 1.2.2 → 2.1.0
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 +77 -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 +78 -121
- 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 +47 -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 +48 -0
- package/tsconfig.json +15 -0
- package/tsconfig.tsbuildinfo +4315 -0
- package/src/index.js +0 -100
- package/src/index.story.js +0 -37
package/lib/styled.js
CHANGED
|
@@ -11,21 +11,21 @@ var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
|
11
11
|
|
|
12
12
|
const LocationPickerSpan = _styledComponents.default.span.withConfig({
|
|
13
13
|
displayName: "styled__LocationPickerSpan",
|
|
14
|
-
componentId: "
|
|
14
|
+
componentId: "vb4790-0"
|
|
15
15
|
})([":first-of-type{border-left:none;}"]);
|
|
16
16
|
|
|
17
17
|
exports.LocationPickerSpan = LocationPickerSpan;
|
|
18
18
|
|
|
19
19
|
const FromToPickerSpan = _styledComponents.default.span.withConfig({
|
|
20
20
|
displayName: "styled__FromToPickerSpan",
|
|
21
|
-
componentId: "
|
|
21
|
+
componentId: "vb4790-1"
|
|
22
22
|
})(["> *{padding-left:0.4em;border-left:1px solid black;}"]);
|
|
23
23
|
|
|
24
24
|
exports.FromToPickerSpan = FromToPickerSpan;
|
|
25
25
|
|
|
26
26
|
const Button = _styledComponents.default.button.withConfig({
|
|
27
27
|
displayName: "styled__Button",
|
|
28
|
-
componentId: "
|
|
28
|
+
componentId: "vb4790-2"
|
|
29
29
|
})(["background:none;border:none;color:navy;font-family:inherit;font-size:inherit;line-height:inherit;padding-left:0.2em;:hover{text-decoration:underline;cursor:pointer;}"]);
|
|
30
30
|
|
|
31
31
|
exports.Button = Button;
|
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,47 @@
|
|
|
1
|
+
import { ReactElement } from "react";
|
|
2
|
+
export declare type Location = {
|
|
3
|
+
lat: number;
|
|
4
|
+
lon: number;
|
|
5
|
+
name: string;
|
|
6
|
+
/**
|
|
7
|
+
* This is only used for locations that a user has saved. Can be either:
|
|
8
|
+
* "home" or "work"
|
|
9
|
+
*/
|
|
10
|
+
type?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare type FromToPickerProps = {
|
|
13
|
+
/**
|
|
14
|
+
* Specifies the label to be rendered, or if set to true, renders the default label "Plan a trip:".
|
|
15
|
+
*/
|
|
16
|
+
label?: boolean | ReactElement | string;
|
|
17
|
+
/**
|
|
18
|
+
* A specific location to associate with this. This is only used when combined
|
|
19
|
+
* with the setLocation prop.
|
|
20
|
+
*/
|
|
21
|
+
location?: Location;
|
|
22
|
+
/**
|
|
23
|
+
* Triggered when the user clicks on the "from" button.
|
|
24
|
+
*/
|
|
25
|
+
onFromClick?: () => void;
|
|
26
|
+
/**
|
|
27
|
+
* Triggered when the user clicks on the "to" button.
|
|
28
|
+
*/
|
|
29
|
+
onToClick?: () => void;
|
|
30
|
+
/**
|
|
31
|
+
* Triggered when the user clicks either the "from" or "to" button and there
|
|
32
|
+
* are no from/to specific handler functions defined as props.
|
|
33
|
+
*
|
|
34
|
+
* Passes an argument as follows:
|
|
35
|
+
* { locationType: "from/to", location, reverseGeocode: false }
|
|
36
|
+
*/
|
|
37
|
+
setLocation?: ({ locationType: string, location: Location, reverseGeocode: boolean }: {
|
|
38
|
+
locationType: any;
|
|
39
|
+
location: any;
|
|
40
|
+
reverseGeocode: any;
|
|
41
|
+
}) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Determines whether icons are shown on the "from" and "to" buttons.
|
|
44
|
+
*/
|
|
45
|
+
showIcons?: boolean;
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAErC,oBAAY,QAAQ,GAAG;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,oBAAY,iBAAiB,GAAG;IAC9B;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,YAAY,GAAG,MAAM,CAAC;IACxC;;;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,EACpB,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.0",
|
|
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 && echo Remove the @ts-expect-error exception in index.tsx once core-utils is typed!"
|
|
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,48 @@
|
|
|
1
|
+
import { ReactElement } from "react";
|
|
2
|
+
|
|
3
|
+
export type Location = {
|
|
4
|
+
lat: number;
|
|
5
|
+
lon: number;
|
|
6
|
+
name: string;
|
|
7
|
+
/**
|
|
8
|
+
* This is only used for locations that a user has saved. Can be either:
|
|
9
|
+
* "home" or "work"
|
|
10
|
+
*/
|
|
11
|
+
type?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type FromToPickerProps = {
|
|
15
|
+
/**
|
|
16
|
+
* Specifies the label to be rendered, or if set to true, renders the default label "Plan a trip:".
|
|
17
|
+
*/
|
|
18
|
+
label?: boolean | ReactElement | string;
|
|
19
|
+
/**
|
|
20
|
+
* A specific location to associate with this. This is only used when combined
|
|
21
|
+
* with the setLocation prop.
|
|
22
|
+
*/
|
|
23
|
+
location?: Location;
|
|
24
|
+
/**
|
|
25
|
+
* Triggered when the user clicks on the "from" button.
|
|
26
|
+
*/
|
|
27
|
+
onFromClick?: () => void;
|
|
28
|
+
/**
|
|
29
|
+
* Triggered when the user clicks on the "to" button.
|
|
30
|
+
*/
|
|
31
|
+
onToClick?: () => void;
|
|
32
|
+
/**
|
|
33
|
+
* Triggered when the user clicks either the "from" or "to" button and there
|
|
34
|
+
* are no from/to specific handler functions defined as props.
|
|
35
|
+
*
|
|
36
|
+
* Passes an argument as follows:
|
|
37
|
+
* { locationType: "from/to", location, reverseGeocode: false }
|
|
38
|
+
*/
|
|
39
|
+
setLocation?: ({
|
|
40
|
+
locationType: string,
|
|
41
|
+
location: Location,
|
|
42
|
+
reverseGeocode: boolean
|
|
43
|
+
}) => void;
|
|
44
|
+
/**
|
|
45
|
+
* Determines whether icons are shown on the "from" and "to" buttons.
|
|
46
|
+
*/
|
|
47
|
+
showIcons?: boolean;
|
|
48
|
+
};
|
package/tsconfig.json
ADDED