@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 CHANGED
@@ -1,149 +1,84 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
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 PropTypes from "prop-types";
14
- import React, { Component } from "react";
15
- import * as S from "./styled";
16
- var iconSize = "0.9em";
17
-
18
- var FromToLocationPicker = /*#__PURE__*/function (_Component) {
19
- _inherits(FromToLocationPicker, _Component);
20
-
21
- var _super = _createSuper(FromToLocationPicker);
22
-
23
- function FromToLocationPicker() {
24
- var _this;
25
-
26
- _classCallCheck(this, FromToLocationPicker);
27
-
28
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
29
- args[_key] = arguments[_key];
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
- _this = _super.call.apply(_super, [this].concat(args));
33
-
34
- _this.onFromClick = function () {
35
- var _this$props = _this.props,
36
- location = _this$props.location,
37
- onFromClick = _this$props.onFromClick,
38
- setLocation = _this$props.setLocation;
39
-
40
- if (onFromClick) {
41
- onFromClick();
42
- return;
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(S.FromToPickerSpan, null, /*#__PURE__*/React.createElement(S.LocationPickerSpan, null, showIcons && /*#__PURE__*/React.createElement(LocationIcon, {
81
- type: "from",
82
- size: iconSize
83
- }), /*#__PURE__*/React.createElement(S.Button, {
84
- onClick: this.onFromClick
85
- }, fromText)), /*#__PURE__*/React.createElement(S.LocationPickerSpan, null, showIcons && /*#__PURE__*/React.createElement(LocationIcon, {
86
- type: "to",
87
- size: iconSize
88
- }), /*#__PURE__*/React.createElement(S.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
-
103
- /**
104
- * A specific location to associate with this. This is only used when combined
105
- * with the setLocation prop.
106
- */
107
- location: coreUtils.types.locationType,
108
48
 
109
- /**
110
- * Triggered when the user clicks on the "from" button.
111
- */
112
- onFromClick: PropTypes.func,
113
-
114
- /**
115
- * Triggered when the user clicks on the "to" button.
116
- */
117
- onToClick: PropTypes.func,
118
-
119
- /**
120
- * The text to display on the "to" button for setting the destination of a trip.
121
- */
122
- toText: PropTypes.string,
123
-
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,
132
-
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"
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
+ })))));
146
80
  };
81
+
147
82
  export default FromToLocationPicker; // Rename styled components for export
148
83
 
149
84
  export { S as Styled };
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["coreUtils","LocationIcon","PropTypes","React","Component","S","iconSize","FromToLocationPicker","onFromClick","props","location","setLocation","locationType","reverseGeocode","onToClick","fromText","showIcons","toText","propTypes","string","types","func","bool","defaultProps","Styled"],"mappings":";;;;;;;;;;AAAA,OAAOA,SAAP,MAAsB,6BAAtB;AACA,OAAOC,YAAP,MAAyB,gCAAzB;AACA,OAAOC,SAAP,MAAsB,YAAtB;AACA,OAAOC,KAAP,IAAgBC,SAAhB,QAAiC,OAAjC;AAEA,OAAO,KAAKC,CAAZ,MAAmB,UAAnB;AAEA,IAAMC,QAAQ,GAAG,OAAjB;;IAEMC,oB;;;;;;;;;;;;;;;;UACJC,W,GAAc,YAAM;AAClB,wBAA+C,MAAKC,KAApD;AAAA,UAAQC,QAAR,eAAQA,QAAR;AAAA,UAAkBF,WAAlB,eAAkBA,WAAlB;AAAA,UAA+BG,WAA/B,eAA+BA,WAA/B;;AACA,UAAIH,WAAJ,EAAiB;AACfA,QAAAA,WAAW;AACX;AACD;;AACDG,MAAAA,WAAW,CAAC;AACVD,QAAAA,QAAQ,EAARA,QADU;AAEVE,QAAAA,YAAY,EAAE,MAFJ;AAGVC,QAAAA,cAAc,EAAE;AAHN,OAAD,CAAX;AAKD,K;;UAEDC,S,GAAY,YAAM;AAChB,yBAA6C,MAAKL,KAAlD;AAAA,UAAQC,QAAR,gBAAQA,QAAR;AAAA,UAAkBI,SAAlB,gBAAkBA,SAAlB;AAAA,UAA6BH,WAA7B,gBAA6BA,WAA7B;;AACA,UAAIG,SAAJ,EAAe;AACbA,QAAAA,SAAS;AACT;AACD;;AACDH,MAAAA,WAAW,CAAC;AACVD,QAAAA,QAAQ,EAARA,QADU;AAEVE,QAAAA,YAAY,EAAE,IAFJ;AAGVC,QAAAA,cAAc,EAAE;AAHN,OAAD,CAAX;AAKD,K;;;;;;;WAED,kBAAS;AACP,yBAAwC,KAAKJ,KAA7C;AAAA,UAAQM,QAAR,gBAAQ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EAAAA,QAAQ,EAAE,IAFwB;AAGlCF,EAAAA,WAAW,EAAE,IAHqB;AAIlCM,EAAAA,SAAS,EAAE,IAJuB;AAKlCH,EAAAA,WAAW,EAAE,IALqB;AAMlCK,EAAAA,SAAS,EAAE,IANuB;AAOlCC,EAAAA,MAAM,EAAE;AAP0B,CAApC;AAUA,eAAeV,oBAAf,C,CAEA;;AACA,SAASF,CAAC,IAAImB,MAAd","sourcesContent":["import coreUtils from \"@opentripplanner/core-utils\";\nimport LocationIcon from \"@opentripplanner/location-icon\";\nimport PropTypes from \"prop-types\";\nimport React, { Component } from \"react\";\n\nimport * as S from \"./styled\";\n\nconst iconSize = \"0.9em\";\n\nclass FromToLocationPicker extends Component {\n onFromClick = () => {\n const { location, onFromClick, setLocation } = this.props;\n if (onFromClick) {\n onFromClick();\n return;\n }\n setLocation({\n location,\n locationType: \"from\",\n reverseGeocode: false\n });\n };\n\n onToClick = () => {\n const { location, onToClick, setLocation } = this.props;\n if (onToClick) {\n onToClick();\n return;\n }\n setLocation({\n location,\n locationType: \"to\",\n reverseGeocode: false\n });\n };\n\n render() {\n const { fromText, showIcons, toText } = this.props;\n return (\n <S.FromToPickerSpan>\n <S.LocationPickerSpan>\n {showIcons && <LocationIcon type=\"from\" size={iconSize} />}\n <S.Button onClick={this.onFromClick}>{fromText}</S.Button>\n </S.LocationPickerSpan>\n <S.LocationPickerSpan>\n {showIcons && <LocationIcon type=\"to\" size={iconSize} />}\n <S.Button onClick={this.onToClick}>{toText}</S.Button>\n </S.LocationPickerSpan>\n </S.FromToPickerSpan>\n );\n }\n}\n\nFromToLocationPicker.propTypes = {\n /**\n * The text to display on the \"from\" button for setting the origin of a trip.\n */\n fromText: PropTypes.string,\n /**\n * A specific location to associate with this. This is only used when combined\n * with the setLocation prop.\n */\n location: coreUtils.types.locationType,\n /**\n * Triggered when the user clicks on the \"from\" button.\n */\n onFromClick: PropTypes.func,\n /**\n * Triggered when the user clicks on the \"to\" button.\n */\n onToClick: PropTypes.func,\n /**\n * The text to display on the \"to\" button for setting the destination of a trip.\n */\n toText: PropTypes.string,\n /**\n * Triggered when the user clicks either the \"from\" or \"to\" button and there\n * are no from/to specific handler functions defined as props.\n *\n * Passes an argument as follows:\n * { locationType: \"from/to\", location, reverseGeocode: false }\n */\n setLocation: PropTypes.func,\n /**\n * Determines whether icons are shown on the \"from\" and \"to\" buttons.\n */\n showIcons: PropTypes.bool\n};\n\nFromToLocationPicker.defaultProps = {\n fromText: \"From here\",\n location: null,\n onFromClick: null,\n onToClick: null,\n setLocation: null,\n showIcons: true,\n toText: \"To here\"\n};\n\nexport default FromToLocationPicker;\n\n// Rename styled components for export\nexport { S as Styled };\n"],"file":"index.js"}
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,2BAN7B,IAM6B;AAAA,2BALrCC,QAKqC;AAAA,MALrCA,QAKqC,8BAL1B,IAK0B;AAAA,8BAJrCC,WAIqC;AAAA,MAJrCA,WAIqC,iCAJvB,IAIuB;AAAA,4BAHrCC,SAGqC;AAAA,MAHrCA,SAGqC,+BAHzB,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,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: "p56b41-0"
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: "p56b41-1"
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: "p56b41-2"
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.js"],"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"}
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
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=types.js.map
@@ -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
@@ -7,138 +7,92 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.Styled = exports.default = void 0;
9
9
 
10
- var _coreUtils = _interopRequireDefault(require("@opentripplanner/core-utils"));
10
+ var _flat = _interopRequireDefault(require("flat"));
11
11
 
12
12
  var _locationIcon = _interopRequireDefault(require("@opentripplanner/location-icon"));
13
13
 
14
- var _propTypes = _interopRequireDefault(require("prop-types"));
14
+ var _reactIntl = require("react-intl");
15
15
 
16
- var _react = _interopRequireWildcard(require("react"));
16
+ var _react = _interopRequireDefault(require("react"));
17
17
 
18
18
  var S = _interopRequireWildcard(require("./styled"));
19
19
 
20
20
  exports.Styled = S;
21
21
 
22
+ var _enUS = _interopRequireDefault(require("../i18n/en-US.yml"));
23
+
22
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); }
23
25
 
24
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; }
25
27
 
26
- const iconSize = "0.9em";
27
-
28
- class FromToLocationPicker extends _react.Component {
29
- constructor(...args) {
30
- super(...args);
31
-
32
- this.onFromClick = () => {
33
- const {
34
- location,
35
- onFromClick,
36
- setLocation
37
- } = this.props;
38
-
39
- if (onFromClick) {
40
- onFromClick();
41
- return;
42
- }
43
-
44
- setLocation({
45
- location,
46
- locationType: "from",
47
- reverseGeocode: false
48
- });
49
- };
50
-
51
- this.onToClick = () => {
52
- const {
53
- location,
54
- onToClick,
55
- setLocation
56
- } = this.props;
57
-
58
- if (onToClick) {
59
- onToClick();
60
- return;
61
- }
62
-
63
- setLocation({
64
- location,
65
- locationType: "to",
66
- reverseGeocode: false
67
- });
68
- };
69
- }
70
-
71
- render() {
72
- const {
73
- fromText,
74
- showIcons,
75
- toText
76
- } = this.props;
77
- return /*#__PURE__*/_react.default.createElement(S.FromToPickerSpan, null, /*#__PURE__*/_react.default.createElement(S.LocationPickerSpan, null, showIcons && /*#__PURE__*/_react.default.createElement(_locationIcon.default, {
78
- type: "from",
79
- size: iconSize
80
- }), /*#__PURE__*/_react.default.createElement(S.Button, {
81
- onClick: this.onFromClick
82
- }, fromText)), /*#__PURE__*/_react.default.createElement(S.LocationPickerSpan, null, showIcons && /*#__PURE__*/_react.default.createElement(_locationIcon.default, {
83
- type: "to",
84
- size: iconSize
85
- }), /*#__PURE__*/_react.default.createElement(S.Button, {
86
- onClick: this.onToClick
87
- }, toText)));
88
- }
89
-
90
- }
91
-
92
- FromToLocationPicker.propTypes = {
93
- /**
94
- * The text to display on the "from" button for setting the origin of a trip.
95
- */
96
- fromText: _propTypes.default.string,
97
-
98
- /**
99
- * A specific location to associate with this. This is only used when combined
100
- * with the setLocation prop.
101
- */
102
- location: _coreUtils.default.types.locationType,
103
-
104
- /**
105
- * Triggered when the user clicks on the "from" button.
106
- */
107
- onFromClick: _propTypes.default.func,
108
-
109
- /**
110
- * Triggered when the user clicks on the "to" button.
111
- */
112
- onToClick: _propTypes.default.func,
113
-
114
- /**
115
- * The text to display on the "to" button for setting the destination of a trip.
116
- */
117
- toText: _propTypes.default.string,
118
-
119
- /**
120
- * Triggered when the user clicks either the "from" or "to" button and there
121
- * are no from/to specific handler functions defined as props.
122
- *
123
- * Passes an argument as follows:
124
- * { locationType: "from/to", location, reverseGeocode: false }
125
- */
126
- setLocation: _propTypes.default.func,
127
-
128
- /**
129
- * Determines whether icons are shown on the "from" and "to" buttons.
130
- */
131
- showIcons: _propTypes.default.bool
132
- };
133
- FromToLocationPicker.defaultProps = {
134
- fromText: "From here",
135
- location: null,
136
- onFromClick: null,
137
- onToClick: null,
138
- setLocation: null,
139
- showIcons: true,
140
- 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
+ })))));
141
94
  };
95
+
142
96
  var _default = FromToLocationPicker; // Rename styled components for export
143
97
 
144
98
  exports.default = _default;
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["iconSize","FromToLocationPicker","Component","onFromClick","location","setLocation","props","locationType","reverseGeocode","onToClick","render","fromText","showIcons","toText","propTypes","PropTypes","string","coreUtils","types","func","bool","defaultProps"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAEA;;;;;;;;AA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AAI,EAAC,IAAnB;AAAwB,MAAA,IAAI,EAAEZ;AAA9B,MADhB,eAEE,6BAAC,CAAD,CAAG,MAAH;AAAU,MAAA,OAAO,EAAE,KAAKS;AAAxB,OAAoCI,MAApC,CAFF,CALF,CADF;AAYD;;AAzC0C;;AA4C7CZ,oBAAoB,CAACa,SAArB,GAAiC;AAC/B;AACF;AACA;AACEH,EAAAA,QAAQ,EAAEI,mBAAUC,MAJW;;AAK/B;AACF;AACA;AACA;AACEZ,EAAAA,QAAQ,EAAEa,mBAAUC,KAAV,CAAgBX,YATK;;AAU/B;AACF;AACA;AACEJ,EAAAA,WAAW,EAAEY,mBAAUI,IAbQ;;AAc/B;AACF;AACA;AACEV,EAAAA,SAAS,EAAEM,mBAAUI,IAjBU;;AAkB/B;AACF;AACA;AACEN,EAAAA,MAAM,EAAEE,mBAAUC,MArBa;;AAsB/B;AACF;AACA;AACA;AACA;AACA;AACA;AACEX,EAAAA,WAAW,EAAEU,mBAAUI,IA7BQ;;AA8B/B;AACF;AACA;AACEP,EAAAA,SAAS,EAAEG,mBAAUK;AAjCU,CAAjC;AAoCAnB,oBAAoB,CAACoB,YAArB,GAAoC;AAClCV,EAAAA,QAAQ,EAAE,WADwB;AAElCP,EAAAA,QAAQ,EAAE,IAFwB;AAGlCD,EAAAA,WAAW,EAAE,IAHqB;AAIlCM,EAAAA,SAAS,EAAE,IAJuB;AAKlCJ,EAAAA,WAAW,EAAE,IALqB;AAMlCO,EAAAA,SAAS,EAAE,IANuB;AAOlCC,EAAAA,MAAM,EAAE;AAP0B,CAApC;eAUeZ,oB,EAEf","sourcesContent":["import coreUtils from \"@opentripplanner/core-utils\";\nimport LocationIcon from \"@opentripplanner/location-icon\";\nimport PropTypes from \"prop-types\";\nimport React, { Component } from \"react\";\n\nimport * as S from \"./styled\";\n\nconst iconSize = \"0.9em\";\n\nclass FromToLocationPicker extends Component {\n onFromClick = () => {\n const { location, onFromClick, setLocation } = this.props;\n if (onFromClick) {\n onFromClick();\n return;\n }\n setLocation({\n location,\n locationType: \"from\",\n reverseGeocode: false\n });\n };\n\n onToClick = () => {\n const { location, onToClick, setLocation } = this.props;\n if (onToClick) {\n onToClick();\n return;\n }\n setLocation({\n location,\n locationType: \"to\",\n reverseGeocode: false\n });\n };\n\n render() {\n const { fromText, showIcons, toText } = this.props;\n return (\n <S.FromToPickerSpan>\n <S.LocationPickerSpan>\n {showIcons && <LocationIcon type=\"from\" size={iconSize} />}\n <S.Button onClick={this.onFromClick}>{fromText}</S.Button>\n </S.LocationPickerSpan>\n <S.LocationPickerSpan>\n {showIcons && <LocationIcon type=\"to\" size={iconSize} />}\n <S.Button onClick={this.onToClick}>{toText}</S.Button>\n </S.LocationPickerSpan>\n </S.FromToPickerSpan>\n );\n }\n}\n\nFromToLocationPicker.propTypes = {\n /**\n * The text to display on the \"from\" button for setting the origin of a trip.\n */\n fromText: PropTypes.string,\n /**\n * A specific location to associate with this. This is only used when combined\n * with the setLocation prop.\n */\n location: coreUtils.types.locationType,\n /**\n * Triggered when the user clicks on the \"from\" button.\n */\n onFromClick: PropTypes.func,\n /**\n * Triggered when the user clicks on the \"to\" button.\n */\n onToClick: PropTypes.func,\n /**\n * The text to display on the \"to\" button for setting the destination of a trip.\n */\n toText: PropTypes.string,\n /**\n * Triggered when the user clicks either the \"from\" or \"to\" button and there\n * are no from/to specific handler functions defined as props.\n *\n * Passes an argument as follows:\n * { locationType: \"from/to\", location, reverseGeocode: false }\n */\n setLocation: PropTypes.func,\n /**\n * Determines whether icons are shown on the \"from\" and \"to\" buttons.\n */\n showIcons: PropTypes.bool\n};\n\nFromToLocationPicker.defaultProps = {\n fromText: \"From here\",\n location: null,\n onFromClick: null,\n onToClick: null,\n setLocation: null,\n showIcons: true,\n toText: \"To here\"\n};\n\nexport default FromToLocationPicker;\n\n// Rename styled components for export\nexport { S as Styled };\n"],"file":"index.js"}
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,EAAAA,QAAQ,GAAG,IAFiB;AAG5BC,EAAAA,WAAW,GAAG,IAHc;AAI5BC,EAAAA,SAAS,GAAG,IAJgB;AAK5BC,EAAAA,WAAW,GAAG,IALc;AAM5BC,EAAAA,SAAS,GAAG;AANgB,CAAD,KAOU;AACrC,QAAMC,eAAe,GAAG,MAAM;AAC5B,QAAIJ,WAAJ,EAAiB;AACfA,MAAAA,WAAW;AACX;AACD;;AACDE,IAAAA,WAAW,CAAC;AACVH,MAAAA,QADU;AAEVM,MAAAA,YAAY,EAAE,MAFJ;AAGVC,MAAAA,cAAc,EAAE;AAHN,KAAD,CAAX;AAKD,GAVD;;AAYA,QAAMC,aAAa,GAAG,MAAM;AAC1B,QAAIN,SAAJ,EAAe;AACbA,MAAAA,SAAS;AACT;AACD;;AACDC,IAAAA,WAAW,CAAC;AACVH,MAAAA,QADU;AAEVM,MAAAA,YAAY,EAAE,IAFJ;AAGVC,MAAAA,cAAc,EAAE;AAHN,KAAD,CAAX;AAKD,GAVD;;AAYA,QAAME,UAAU,GAAGV,KAAK,KAAK,IAAV,gBAEjB,0DACE,6BAAC,2BAAD;AACE,IAAA,cAAc,EAAEH,eAAe,CAAC,sCAAD,CADjC;AAEE,IAAA,WAAW,EAAC,yCAFd;AAGE,IAAA,EAAE,EAAC;AAHL,IADF,CAFiB,GAUfG,KAVJ;AAYA,sBACE,4DACGU,UADH,eAEE,6BAAC,CAAD,CAAG,gBAAH,qBACE,6BAAC,CAAD,CAAG,kBAAH,QACGL,SAAS,iBAAI,6BAAC,qBAAD;AAAc,IAAA,IAAI,EAAC,MAAnB;AAA0B,IAAA,IAAI,EAAET;AAAhC,IADhB,eAEE,6BAAC,CAAD,CAAG,MAAH;AAAU,IAAA,OAAO,EAAEU;AAAnB,kBACE,6BAAC,2BAAD;AACE,IAAA,cAAc,EAAET,eAAe,CAAC,iCAAD,CADjC;AAEE,IAAA,WAAW,EAAC,0CAFd;AAGE,IAAA,EAAE,EAAC;AAHL,IADF,CAFF,CADF,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"}
@@ -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"}
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: "p56b41-0"
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: "p56b41-1"
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: "p56b41-2"
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;