@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/esm/index.js
CHANGED
|
@@ -1,148 +1,85 @@
|
|
|
1
|
-
import
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
-
import _inherits from "@babel/runtime/helpers/inherits";
|
|
4
|
-
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
5
|
-
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
6
|
-
|
|
7
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
8
|
-
|
|
9
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
10
|
-
|
|
11
|
-
import coreUtils from "@opentripplanner/core-utils";
|
|
1
|
+
import flatten from "flat";
|
|
12
2
|
import LocationIcon from "@opentripplanner/location-icon";
|
|
13
|
-
import
|
|
14
|
-
import React
|
|
15
|
-
import
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
3
|
+
import { FormattedMessage } from "react-intl";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import * as S from "./styled"; // eslint-disable-next-line prettier/prettier
|
|
6
|
+
|
|
7
|
+
// Load the default messages.
|
|
8
|
+
import defaultEnglishMessages from "../i18n/en-US.yml";
|
|
9
|
+
var iconSize = "0.9em"; // HACK: We should flatten the messages loaded above because
|
|
10
|
+
// the YAML loaders behave differently between webpack and our version of jest:
|
|
11
|
+
// - the yaml loader for webpack returns a nested object,
|
|
12
|
+
// - the yaml loader for jest returns messages with flattened ids.
|
|
13
|
+
|
|
14
|
+
var defaultMessages = flatten(defaultEnglishMessages);
|
|
15
|
+
|
|
16
|
+
var FromToLocationPicker = function FromToLocationPicker(_ref) {
|
|
17
|
+
var _ref$label = _ref.label,
|
|
18
|
+
label = _ref$label === void 0 ? null : _ref$label,
|
|
19
|
+
_ref$location = _ref.location,
|
|
20
|
+
location = _ref$location === void 0 ? null : _ref$location,
|
|
21
|
+
_ref$onFromClick = _ref.onFromClick,
|
|
22
|
+
onFromClick = _ref$onFromClick === void 0 ? null : _ref$onFromClick,
|
|
23
|
+
_ref$onToClick = _ref.onToClick,
|
|
24
|
+
onToClick = _ref$onToClick === void 0 ? null : _ref$onToClick,
|
|
25
|
+
_ref$setLocation = _ref.setLocation,
|
|
26
|
+
setLocation = _ref$setLocation === void 0 ? null : _ref$setLocation,
|
|
27
|
+
_ref$showIcons = _ref.showIcons,
|
|
28
|
+
showIcons = _ref$showIcons === void 0 ? true : _ref$showIcons;
|
|
29
|
+
|
|
30
|
+
var handleFromClick = function handleFromClick() {
|
|
31
|
+
if (onFromClick) {
|
|
32
|
+
onFromClick();
|
|
33
|
+
return;
|
|
30
34
|
}
|
|
31
35
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
setLocation({
|
|
46
|
-
location: location,
|
|
47
|
-
locationType: "from",
|
|
48
|
-
reverseGeocode: false
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
_this.onToClick = function () {
|
|
53
|
-
var _this$props2 = _this.props,
|
|
54
|
-
location = _this$props2.location,
|
|
55
|
-
onToClick = _this$props2.onToClick,
|
|
56
|
-
setLocation = _this$props2.setLocation;
|
|
57
|
-
|
|
58
|
-
if (onToClick) {
|
|
59
|
-
onToClick();
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
setLocation({
|
|
64
|
-
location: location,
|
|
65
|
-
locationType: "to",
|
|
66
|
-
reverseGeocode: false
|
|
67
|
-
});
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
return _this;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
_createClass(FromToLocationPicker, [{
|
|
74
|
-
key: "render",
|
|
75
|
-
value: function render() {
|
|
76
|
-
var _this$props3 = this.props,
|
|
77
|
-
fromText = _this$props3.fromText,
|
|
78
|
-
showIcons = _this$props3.showIcons,
|
|
79
|
-
toText = _this$props3.toText;
|
|
80
|
-
return /*#__PURE__*/React.createElement(FromToPickerSpan, null, /*#__PURE__*/React.createElement(LocationPickerSpan, null, showIcons && /*#__PURE__*/React.createElement(LocationIcon, {
|
|
81
|
-
type: "from",
|
|
82
|
-
size: iconSize
|
|
83
|
-
}), /*#__PURE__*/React.createElement(Button, {
|
|
84
|
-
onClick: this.onFromClick
|
|
85
|
-
}, fromText)), /*#__PURE__*/React.createElement(LocationPickerSpan, null, showIcons && /*#__PURE__*/React.createElement(LocationIcon, {
|
|
86
|
-
type: "to",
|
|
87
|
-
size: iconSize
|
|
88
|
-
}), /*#__PURE__*/React.createElement(Button, {
|
|
89
|
-
onClick: this.onToClick
|
|
90
|
-
}, toText)));
|
|
36
|
+
setLocation({
|
|
37
|
+
location: location,
|
|
38
|
+
locationType: "from",
|
|
39
|
+
reverseGeocode: false
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
var handleToClick = function handleToClick() {
|
|
44
|
+
if (onToClick) {
|
|
45
|
+
onToClick();
|
|
46
|
+
return;
|
|
91
47
|
}
|
|
92
|
-
}]);
|
|
93
|
-
|
|
94
|
-
return FromToLocationPicker;
|
|
95
|
-
}(Component);
|
|
96
|
-
|
|
97
|
-
FromToLocationPicker.propTypes = {
|
|
98
|
-
/**
|
|
99
|
-
* The text to display on the "from" button for setting the origin of a trip.
|
|
100
|
-
*/
|
|
101
|
-
fromText: PropTypes.string,
|
|
102
48
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
49
|
+
setLocation({
|
|
50
|
+
location: location,
|
|
51
|
+
locationType: "to",
|
|
52
|
+
reverseGeocode: false
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
var labelIfAny = label === true ? /*#__PURE__*/React.createElement("strong", null, /*#__PURE__*/React.createElement(FormattedMessage, {
|
|
57
|
+
defaultMessage: defaultMessages["otpUi.FromToLocationPicker.planATrip"],
|
|
58
|
+
description: "Label to prompt the user to plan a trip",
|
|
59
|
+
id: "otpUi.FromToLocationPicker.planATrip"
|
|
60
|
+
})) : label;
|
|
61
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, labelIfAny, /*#__PURE__*/React.createElement(S.FromToPickerSpan, null, /*#__PURE__*/React.createElement(S.LocationPickerSpan, null, showIcons && /*#__PURE__*/React.createElement(LocationIcon, {
|
|
62
|
+
type: "from",
|
|
63
|
+
size: iconSize
|
|
64
|
+
}), /*#__PURE__*/React.createElement(S.Button, {
|
|
65
|
+
onClick: handleFromClick
|
|
66
|
+
}, /*#__PURE__*/React.createElement(FormattedMessage, {
|
|
67
|
+
defaultMessage: defaultMessages["otpUi.FromToLocationPicker.from"],
|
|
68
|
+
description: "Text for the 'from' button of the picker",
|
|
69
|
+
id: "otpUi.FromToLocationPicker.from"
|
|
70
|
+
}))), /*#__PURE__*/React.createElement(S.LocationPickerSpan, null, showIcons && /*#__PURE__*/React.createElement(LocationIcon, {
|
|
71
|
+
type: "to",
|
|
72
|
+
size: iconSize
|
|
73
|
+
}), /*#__PURE__*/React.createElement(S.Button, {
|
|
74
|
+
onClick: handleToClick
|
|
75
|
+
}, /*#__PURE__*/React.createElement(FormattedMessage, {
|
|
76
|
+
defaultMessage: defaultMessages["otpUi.FromToLocationPicker.to"],
|
|
77
|
+
description: "Text for the 'to' button of the picker",
|
|
78
|
+
id: "otpUi.FromToLocationPicker.to"
|
|
79
|
+
})))));
|
|
80
|
+
};
|
|
123
81
|
|
|
124
|
-
|
|
125
|
-
* Triggered when the user clicks either the "from" or "to" button and there
|
|
126
|
-
* are no from/to specific handler functions defined as props.
|
|
127
|
-
*
|
|
128
|
-
* Passes an argument as follows:
|
|
129
|
-
* { locationType: "from/to", location, reverseGeocode: false }
|
|
130
|
-
*/
|
|
131
|
-
setLocation: PropTypes.func,
|
|
82
|
+
export default FromToLocationPicker; // Rename styled components for export
|
|
132
83
|
|
|
133
|
-
|
|
134
|
-
* Determines whether icons are shown on the "from" and "to" buttons.
|
|
135
|
-
*/
|
|
136
|
-
showIcons: PropTypes.bool
|
|
137
|
-
};
|
|
138
|
-
FromToLocationPicker.defaultProps = {
|
|
139
|
-
fromText: "From here",
|
|
140
|
-
location: null,
|
|
141
|
-
onFromClick: null,
|
|
142
|
-
onToClick: null,
|
|
143
|
-
setLocation: null,
|
|
144
|
-
showIcons: true,
|
|
145
|
-
toText: "To here"
|
|
146
|
-
};
|
|
147
|
-
export default FromToLocationPicker;
|
|
84
|
+
export { S as Styled };
|
|
148
85
|
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":["flatten","LocationIcon","FormattedMessage","React","S","defaultEnglishMessages","iconSize","defaultMessages","FromToLocationPicker","label","location","onFromClick","onToClick","setLocation","showIcons","handleFromClick","locationType","reverseGeocode","handleToClick","labelIfAny","Styled"],"mappings":"AAAA,OAAOA,OAAP,MAAoB,MAApB;AACA,OAAOC,YAAP,MAAyB,gCAAzB;AACA,SAASC,gBAAT,QAAiC,YAAjC;AACA,OAAOC,KAAP,MAAoC,OAApC;AAEA,OAAO,KAAKC,CAAZ,MAAmB,UAAnB,C,CAEA;;AAGA;AACA,OAAOC,sBAAP,MAAmC,mBAAnC;AAEA,IAAMC,QAAQ,GAAG,OAAjB,C,CAEA;AACA;AACA;AACA;;AACA,IAAMC,eAAuC,GAAGP,OAAO,CAACK,sBAAD,CAAvD;;AAEA,IAAMG,oBAAoB,GAAG,SAAvBA,oBAAuB,OAOU;AAAA,wBANrCC,KAMqC;AAAA,MANrCA,KAMqC,2BAN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AAG,MAAH;AAAU,IAAA,OAAO,EAAES;AAAnB,kBACE,oBAAC,gBAAD;AACE,IAAA,cAAc,EAAER,eAAe,CAAC,iCAAD,CADjC;AAEE,IAAA,WAAW,EAAC,0CAFd;AAGE,IAAA,EAAE,EAAC;AAHL,IADF,CAFF,CADF,eAWE,oBAAC,CAAD,CAAG,kBAAH,QACGO,SAAS,iBAAI,oBAAC,YAAD;AAAc,IAAA,IAAI,EAAC,IAAnB;AAAwB,IAAA,IAAI,EAAER;AAA9B,IADhB,eAEE,oBAAC,CAAD,CAAG,MAAH;AAAU,IAAA,OAAO,EAAEY;AAAnB,kBACE,oBAAC,gBAAD;AACE,IAAA,cAAc,EAAEX,eAAe,CAAC,+BAAD,CADjC;AAEE,IAAA,WAAW,EAAC,wCAFd;AAGE,IAAA,EAAE,EAAC;AAHL,IADF,CAFF,CAXF,CAFF,CADF;AA2BD,CAvED;;AAyEA,eAAeC,oBAAf,C,CAEA;;AACA,SAASJ,CAAC,IAAIgB,MAAd","sourcesContent":["import flatten from \"flat\";\nimport LocationIcon from \"@opentripplanner/location-icon\";\nimport { FormattedMessage } from \"react-intl\";\nimport React, { ReactElement } from \"react\";\n\nimport * as S from \"./styled\";\n\n// eslint-disable-next-line prettier/prettier\nimport type { FromToPickerProps } from \"./types\";\n\n// Load the default messages.\nimport defaultEnglishMessages from \"../i18n/en-US.yml\";\n\nconst iconSize = \"0.9em\";\n\n// HACK: We should flatten the messages loaded above because\n// the YAML loaders behave differently between webpack and our version of jest:\n// - the yaml loader for webpack returns a nested object,\n// - the yaml loader for jest returns messages with flattened ids.\nconst defaultMessages: Record<string, string> = flatten(defaultEnglishMessages);\n\nconst FromToLocationPicker = ({\n label = null,\n location = null,\n onFromClick = null,\n onToClick = null,\n setLocation = null,\n showIcons = true\n}: FromToPickerProps): ReactElement => {\n const handleFromClick = () => {\n if (onFromClick) {\n onFromClick();\n return;\n }\n setLocation({\n location,\n locationType: \"from\",\n reverseGeocode: false\n });\n };\n\n const handleToClick = () => {\n if (onToClick) {\n onToClick();\n return;\n }\n setLocation({\n location,\n locationType: \"to\",\n reverseGeocode: false\n });\n };\n\n const labelIfAny = label === true\n ? (\n <strong>\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.FromToLocationPicker.planATrip\"]}\n description=\"Label to prompt the user to plan a trip\"\n id=\"otpUi.FromToLocationPicker.planATrip\"\n />\n </strong>\n )\n : label\n\n return (\n <>\n {labelIfAny}\n <S.FromToPickerSpan>\n <S.LocationPickerSpan>\n {showIcons && <LocationIcon type=\"from\" size={iconSize} />}\n <S.Button onClick={handleFromClick}>\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.FromToLocationPicker.from\"]}\n description=\"Text for the 'from' button of the picker\"\n id=\"otpUi.FromToLocationPicker.from\"\n />\n </S.Button>\n </S.LocationPickerSpan>\n <S.LocationPickerSpan>\n {showIcons && <LocationIcon type=\"to\" size={iconSize} />}\n <S.Button onClick={handleToClick}>\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.FromToLocationPicker.to\"]}\n description=\"Text for the 'to' button of the picker\"\n id=\"otpUi.FromToLocationPicker.to\"\n />\n </S.Button>\n </S.LocationPickerSpan>\n </S.FromToPickerSpan>\n </>\n );\n};\n\nexport default FromToLocationPicker;\n\n// Rename styled components for export\nexport { S as Styled };\n"],"file":"index.js"}
|
package/esm/styled.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import styled from "styled-components";
|
|
2
2
|
export var LocationPickerSpan = styled.span.withConfig({
|
|
3
3
|
displayName: "styled__LocationPickerSpan",
|
|
4
|
-
componentId: "
|
|
4
|
+
componentId: "vb4790-0"
|
|
5
5
|
})([":first-of-type{border-left:none;}"]);
|
|
6
6
|
export var FromToPickerSpan = styled.span.withConfig({
|
|
7
7
|
displayName: "styled__FromToPickerSpan",
|
|
8
|
-
componentId: "
|
|
8
|
+
componentId: "vb4790-1"
|
|
9
9
|
})(["> *{padding-left:0.4em;border-left:1px solid black;}"]);
|
|
10
10
|
export var Button = styled.button.withConfig({
|
|
11
11
|
displayName: "styled__Button",
|
|
12
|
-
componentId: "
|
|
12
|
+
componentId: "vb4790-2"
|
|
13
13
|
})(["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;}"]);
|
|
14
14
|
//# sourceMappingURL=styled.js.map
|
package/esm/styled.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/styled.
|
|
1
|
+
{"version":3,"sources":["../src/styled.ts"],"names":["styled","LocationPickerSpan","span","FromToPickerSpan","Button","button"],"mappings":"AAAA,OAAOA,MAAP,MAAmB,mBAAnB;AAEA,OAAO,IAAMC,kBAAkB,GAAGD,MAAM,CAACE,IAAV;AAAA;AAAA;AAAA,yCAAxB;AAMP,OAAO,IAAMC,gBAAgB,GAAGH,MAAM,CAACE,IAAV;AAAA;AAAA;AAAA,4DAAtB;AAOP,OAAO,IAAME,MAAM,GAAGJ,MAAM,CAACK,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/esm/types.js
ADDED
package/esm/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"types.js"}
|
package/i18n/en-US.yml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Default messages for the FromToLocationPicker component.
|
|
2
|
+
# To use from a react-intl application:
|
|
3
|
+
# - merge the content of this file into the messages object
|
|
4
|
+
# that has your other localized strings,
|
|
5
|
+
# - flatten the ids, i.e. convert a structure such as
|
|
6
|
+
# otpUi > FromToLocationPicker > from
|
|
7
|
+
# into "otpUi.FromToLocationPicker.from" (see FromToLocationPicker story for an example),
|
|
8
|
+
# - pass the resulting object to the messages prop of IntlProvider.
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
otpUi:
|
|
12
|
+
FromToLocationPicker:
|
|
13
|
+
from: From here
|
|
14
|
+
planATrip: "Plan a trip:"
|
|
15
|
+
to: To here
|
package/i18n/fr.yml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Default messages for the FromToLocationPicker component.
|
|
2
|
+
# To use from a react-intl application:
|
|
3
|
+
# - merge the content of this file into the messages object
|
|
4
|
+
# that has your other localized strings,
|
|
5
|
+
# - flatten the ids, i.e. convert a structure such as
|
|
6
|
+
# otpUi > FromToLocationPicker > from
|
|
7
|
+
# into "otpUi.FromToLocationPicker.from" (see FromToLocationPicker story for an example),
|
|
8
|
+
# - pass the resulting object to the messages prop of IntlProvider.
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
otpUi:
|
|
12
|
+
FromToLocationPicker:
|
|
13
|
+
from: Départ
|
|
14
|
+
planATrip: "Plannifier un trajet :"
|
|
15
|
+
to: Arrivée
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ReactElement } from "react";
|
|
2
|
+
import * as S from "./styled";
|
|
3
|
+
import type { FromToPickerProps } from "./types";
|
|
4
|
+
declare const FromToLocationPicker: ({ label, location, onFromClick, onToClick, setLocation, showIcons }: FromToPickerProps) => ReactElement;
|
|
5
|
+
export default FromToLocationPicker;
|
|
6
|
+
export { S as Styled };
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAGA,OAAc,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAG9B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAajD,QAAA,MAAM,oBAAoB,wEAOvB,iBAAiB,KAAG,YAgEtB,CAAC;AAEF,eAAe,oBAAoB,CAAC;AAGpC,OAAO,EAAE,CAAC,IAAI,MAAM,EAAE,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -5,138 +5,95 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.default = void 0;
|
|
8
|
+
exports.Styled = exports.default = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _flat = _interopRequireDefault(require("flat"));
|
|
11
11
|
|
|
12
12
|
var _locationIcon = _interopRequireDefault(require("@opentripplanner/location-icon"));
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _reactIntl = require("react-intl");
|
|
15
15
|
|
|
16
|
-
var _react =
|
|
16
|
+
var _react = _interopRequireDefault(require("react"));
|
|
17
17
|
|
|
18
|
-
var
|
|
18
|
+
var S = _interopRequireWildcard(require("./styled"));
|
|
19
|
+
|
|
20
|
+
exports.Styled = S;
|
|
21
|
+
|
|
22
|
+
var _enUS = _interopRequireDefault(require("../i18n/en-US.yml"));
|
|
19
23
|
|
|
20
24
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
21
25
|
|
|
22
26
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
FromToLocationPicker.propTypes = {
|
|
91
|
-
/**
|
|
92
|
-
* The text to display on the "from" button for setting the origin of a trip.
|
|
93
|
-
*/
|
|
94
|
-
fromText: _propTypes.default.string,
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* A specific location to associate with this. This is only used when combined
|
|
98
|
-
* with the setLocation prop.
|
|
99
|
-
*/
|
|
100
|
-
location: _coreUtils.default.types.locationType,
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Triggered when the user clicks on the "from" button.
|
|
104
|
-
*/
|
|
105
|
-
onFromClick: _propTypes.default.func,
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Triggered when the user clicks on the "to" button.
|
|
109
|
-
*/
|
|
110
|
-
onToClick: _propTypes.default.func,
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* The text to display on the "to" button for setting the destination of a trip.
|
|
114
|
-
*/
|
|
115
|
-
toText: _propTypes.default.string,
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Triggered when the user clicks either the "from" or "to" button and there
|
|
119
|
-
* are no from/to specific handler functions defined as props.
|
|
120
|
-
*
|
|
121
|
-
* Passes an argument as follows:
|
|
122
|
-
* { locationType: "from/to", location, reverseGeocode: false }
|
|
123
|
-
*/
|
|
124
|
-
setLocation: _propTypes.default.func,
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Determines whether icons are shown on the "from" and "to" buttons.
|
|
128
|
-
*/
|
|
129
|
-
showIcons: _propTypes.default.bool
|
|
130
|
-
};
|
|
131
|
-
FromToLocationPicker.defaultProps = {
|
|
132
|
-
fromText: "From here",
|
|
133
|
-
location: null,
|
|
134
|
-
onFromClick: null,
|
|
135
|
-
onToClick: null,
|
|
136
|
-
setLocation: null,
|
|
137
|
-
showIcons: true,
|
|
138
|
-
toText: "To here"
|
|
28
|
+
// Load the default messages.
|
|
29
|
+
const iconSize = "0.9em"; // HACK: We should flatten the messages loaded above because
|
|
30
|
+
// the YAML loaders behave differently between webpack and our version of jest:
|
|
31
|
+
// - the yaml loader for webpack returns a nested object,
|
|
32
|
+
// - the yaml loader for jest returns messages with flattened ids.
|
|
33
|
+
|
|
34
|
+
const defaultMessages = (0, _flat.default)(_enUS.default);
|
|
35
|
+
|
|
36
|
+
const FromToLocationPicker = ({
|
|
37
|
+
label = null,
|
|
38
|
+
location = null,
|
|
39
|
+
onFromClick = null,
|
|
40
|
+
onToClick = null,
|
|
41
|
+
setLocation = null,
|
|
42
|
+
showIcons = true
|
|
43
|
+
}) => {
|
|
44
|
+
const handleFromClick = () => {
|
|
45
|
+
if (onFromClick) {
|
|
46
|
+
onFromClick();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
setLocation({
|
|
51
|
+
location,
|
|
52
|
+
locationType: "from",
|
|
53
|
+
reverseGeocode: false
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const handleToClick = () => {
|
|
58
|
+
if (onToClick) {
|
|
59
|
+
onToClick();
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
setLocation({
|
|
64
|
+
location,
|
|
65
|
+
locationType: "to",
|
|
66
|
+
reverseGeocode: false
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const labelIfAny = label === true ? /*#__PURE__*/_react.default.createElement("strong", null, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
|
|
71
|
+
defaultMessage: defaultMessages["otpUi.FromToLocationPicker.planATrip"],
|
|
72
|
+
description: "Label to prompt the user to plan a trip",
|
|
73
|
+
id: "otpUi.FromToLocationPicker.planATrip"
|
|
74
|
+
})) : label;
|
|
75
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, labelIfAny, /*#__PURE__*/_react.default.createElement(S.FromToPickerSpan, null, /*#__PURE__*/_react.default.createElement(S.LocationPickerSpan, null, showIcons && /*#__PURE__*/_react.default.createElement(_locationIcon.default, {
|
|
76
|
+
type: "from",
|
|
77
|
+
size: iconSize
|
|
78
|
+
}), /*#__PURE__*/_react.default.createElement(S.Button, {
|
|
79
|
+
onClick: handleFromClick
|
|
80
|
+
}, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
|
|
81
|
+
defaultMessage: defaultMessages["otpUi.FromToLocationPicker.from"],
|
|
82
|
+
description: "Text for the 'from' button of the picker",
|
|
83
|
+
id: "otpUi.FromToLocationPicker.from"
|
|
84
|
+
}))), /*#__PURE__*/_react.default.createElement(S.LocationPickerSpan, null, showIcons && /*#__PURE__*/_react.default.createElement(_locationIcon.default, {
|
|
85
|
+
type: "to",
|
|
86
|
+
size: iconSize
|
|
87
|
+
}), /*#__PURE__*/_react.default.createElement(S.Button, {
|
|
88
|
+
onClick: handleToClick
|
|
89
|
+
}, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
|
|
90
|
+
defaultMessage: defaultMessages["otpUi.FromToLocationPicker.to"],
|
|
91
|
+
description: "Text for the 'to' button of the picker",
|
|
92
|
+
id: "otpUi.FromToLocationPicker.to"
|
|
93
|
+
})))));
|
|
139
94
|
};
|
|
140
|
-
|
|
95
|
+
|
|
96
|
+
var _default = FromToLocationPicker; // Rename styled components for export
|
|
97
|
+
|
|
141
98
|
exports.default = _default;
|
|
142
99
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":["iconSize","defaultMessages","defaultEnglishMessages","FromToLocationPicker","label","location","onFromClick","onToClick","setLocation","showIcons","handleFromClick","locationType","reverseGeocode","handleToClick","labelIfAny"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAEA;;;;AAMA;;;;;;AADA;AAGA,MAAMA,QAAQ,GAAG,OAAjB,C,CAEA;AACA;AACA;AACA;;AACA,MAAMC,eAAuC,GAAG,mBAAQC,aAAR,CAAhD;;AAEA,MAAMC,oBAAoB,GAAG,CAAC;AAC5BC,EAAAA,KAAK,GAAG,IADoB;AAE5BC,EA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,eAWE,6BAAC,CAAD,CAAG,kBAAH,QACGQ,SAAS,iBAAI,6BAAC,qBAAD;AAAc,IAAA,IAAI,EAAC,IAAnB;AAAwB,IAAA,IAAI,EAAET;AAA9B,IADhB,eAEE,6BAAC,CAAD,CAAG,MAAH;AAAU,IAAA,OAAO,EAAEa;AAAnB,kBACE,6BAAC,2BAAD;AACE,IAAA,cAAc,EAAEZ,eAAe,CAAC,+BAAD,CADjC;AAEE,IAAA,WAAW,EAAC,wCAFd;AAGE,IAAA,EAAE,EAAC;AAHL,IADF,CAFF,CAXF,CAFF,CADF;AA2BD,CAvED;;eAyEeE,oB,EAEf","sourcesContent":["import flatten from \"flat\";\nimport LocationIcon from \"@opentripplanner/location-icon\";\nimport { FormattedMessage } from \"react-intl\";\nimport React, { ReactElement } from \"react\";\n\nimport * as S from \"./styled\";\n\n// eslint-disable-next-line prettier/prettier\nimport type { FromToPickerProps } from \"./types\";\n\n// Load the default messages.\nimport defaultEnglishMessages from \"../i18n/en-US.yml\";\n\nconst iconSize = \"0.9em\";\n\n// HACK: We should flatten the messages loaded above because\n// the YAML loaders behave differently between webpack and our version of jest:\n// - the yaml loader for webpack returns a nested object,\n// - the yaml loader for jest returns messages with flattened ids.\nconst defaultMessages: Record<string, string> = flatten(defaultEnglishMessages);\n\nconst FromToLocationPicker = ({\n label = null,\n location = null,\n onFromClick = null,\n onToClick = null,\n setLocation = null,\n showIcons = true\n}: FromToPickerProps): ReactElement => {\n const handleFromClick = () => {\n if (onFromClick) {\n onFromClick();\n return;\n }\n setLocation({\n location,\n locationType: \"from\",\n reverseGeocode: false\n });\n };\n\n const handleToClick = () => {\n if (onToClick) {\n onToClick();\n return;\n }\n setLocation({\n location,\n locationType: \"to\",\n reverseGeocode: false\n });\n };\n\n const labelIfAny = label === true\n ? (\n <strong>\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.FromToLocationPicker.planATrip\"]}\n description=\"Label to prompt the user to plan a trip\"\n id=\"otpUi.FromToLocationPicker.planATrip\"\n />\n </strong>\n )\n : label\n\n return (\n <>\n {labelIfAny}\n <S.FromToPickerSpan>\n <S.LocationPickerSpan>\n {showIcons && <LocationIcon type=\"from\" size={iconSize} />}\n <S.Button onClick={handleFromClick}>\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.FromToLocationPicker.from\"]}\n description=\"Text for the 'from' button of the picker\"\n id=\"otpUi.FromToLocationPicker.from\"\n />\n </S.Button>\n </S.LocationPickerSpan>\n <S.LocationPickerSpan>\n {showIcons && <LocationIcon type=\"to\" size={iconSize} />}\n <S.Button onClick={handleToClick}>\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.FromToLocationPicker.to\"]}\n description=\"Text for the 'to' button of the picker\"\n id=\"otpUi.FromToLocationPicker.to\"\n />\n </S.Button>\n </S.LocationPickerSpan>\n </S.FromToPickerSpan>\n </>\n );\n};\n\nexport default FromToLocationPicker;\n\n// Rename styled components for export\nexport { S as Styled };\n"],"file":"index.js"}
|
package/lib/styled.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const LocationPickerSpan: import("styled-components").StyledComponent<"span", any, {}, never>;
|
|
2
|
+
export declare const FromToPickerSpan: import("styled-components").StyledComponent<"span", any, {}, never>;
|
|
3
|
+
export declare const Button: import("styled-components").StyledComponent<"button", any, {}, never>;
|
|
4
|
+
//# sourceMappingURL=styled.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styled.d.ts","sourceRoot":"","sources":["../src/styled.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB,qEAI9B,CAAC;AAEF,eAAO,MAAM,gBAAgB,qEAK5B,CAAC;AAEF,eAAO,MAAM,MAAM,uEAalB,CAAC"}
|