@perses-dev/components 0.0.0-snapshot-profile-89b306f → 0.0.0-snapshot-time-zone-selector-946f408
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/README.md +1 -5
- package/dist/EChart/EChart.d.ts.map +1 -1
- package/dist/EChart/EChart.js +9 -4
- package/dist/EChart/EChart.js.map +1 -1
- package/dist/TimeRangeSelector/DateTimeRangePicker.d.ts +2 -1
- package/dist/TimeRangeSelector/DateTimeRangePicker.d.ts.map +1 -1
- package/dist/TimeRangeSelector/DateTimeRangePicker.js +5 -6
- package/dist/TimeRangeSelector/DateTimeRangePicker.js.map +1 -1
- package/dist/TimeRangeSelector/TimeRangeSelector.d.ts +5 -1
- package/dist/TimeRangeSelector/TimeRangeSelector.d.ts.map +1 -1
- package/dist/TimeRangeSelector/TimeRangeSelector.js +14 -10
- package/dist/TimeRangeSelector/TimeRangeSelector.js.map +1 -1
- package/dist/TimeSeriesTooltip/index.d.ts +0 -1
- package/dist/TimeSeriesTooltip/index.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/index.js +0 -1
- package/dist/TimeSeriesTooltip/index.js.map +1 -1
- package/dist/TimeZoneSelector/TimeZoneSelector.d.ts +10 -0
- package/dist/TimeZoneSelector/TimeZoneSelector.d.ts.map +1 -0
- package/dist/TimeZoneSelector/TimeZoneSelector.js +143 -0
- package/dist/TimeZoneSelector/TimeZoneSelector.js.map +1 -0
- package/dist/TimeZoneSelector/index.d.ts +2 -0
- package/dist/TimeZoneSelector/index.d.ts.map +1 -0
- package/dist/{LineChart → TimeZoneSelector}/index.js +2 -2
- package/dist/TimeZoneSelector/index.js.map +1 -0
- package/dist/cjs/EChart/EChart.js +7 -2
- package/dist/cjs/TimeRangeSelector/DateTimeRangePicker.js +5 -6
- package/dist/cjs/TimeRangeSelector/TimeRangeSelector.js +12 -8
- package/dist/cjs/TimeSeriesTooltip/index.js +0 -1
- package/dist/cjs/TimeZoneSelector/TimeZoneSelector.js +156 -0
- package/dist/cjs/{LineChart → TimeZoneSelector}/index.js +2 -2
- package/dist/cjs/context/index.js +0 -1
- package/dist/cjs/index.js +1 -2
- package/dist/cjs/model/index.js +1 -0
- package/dist/cjs/model/timeZoneOption.js +100 -0
- package/dist/cjs/utils/axis.js +3 -18
- package/dist/cjs/utils/format.js +0 -21
- package/dist/context/index.d.ts +0 -1
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +0 -1
- package/dist/context/index.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/model/graph.d.ts +0 -1
- package/dist/model/graph.d.ts.map +1 -1
- package/dist/model/graph.js.map +1 -1
- package/dist/model/index.d.ts +1 -0
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +1 -0
- package/dist/model/index.js.map +1 -1
- package/dist/model/timeZoneOption.d.ts +10 -0
- package/dist/model/timeZoneOption.d.ts.map +1 -0
- package/dist/model/timeZoneOption.js +79 -0
- package/dist/model/timeZoneOption.js.map +1 -0
- package/dist/utils/axis.d.ts +0 -4
- package/dist/utils/axis.d.ts.map +1 -1
- package/dist/utils/axis.js +0 -9
- package/dist/utils/axis.js.map +1 -1
- package/dist/utils/chart-actions.d.ts +0 -2
- package/dist/utils/chart-actions.d.ts.map +1 -1
- package/dist/utils/chart-actions.js.map +1 -1
- package/dist/utils/format.d.ts +0 -1
- package/dist/utils/format.d.ts.map +1 -1
- package/dist/utils/format.js +0 -20
- package/dist/utils/format.js.map +1 -1
- package/package.json +4 -7
- package/dist/LineChart/LineChart.d.ts +0 -22
- package/dist/LineChart/LineChart.d.ts.map +0 -1
- package/dist/LineChart/LineChart.js +0 -266
- package/dist/LineChart/LineChart.js.map +0 -1
- package/dist/LineChart/index.d.ts +0 -2
- package/dist/LineChart/index.d.ts.map +0 -1
- package/dist/LineChart/index.js.map +0 -1
- package/dist/TimeChart/TimeChart.d.ts +0 -24
- package/dist/TimeChart/TimeChart.d.ts.map +0 -1
- package/dist/TimeChart/TimeChart.js +0 -394
- package/dist/TimeChart/TimeChart.js.map +0 -1
- package/dist/TimeChart/index.d.ts +0 -2
- package/dist/TimeChart/index.d.ts.map +0 -1
- package/dist/TimeChart/index.js +0 -15
- package/dist/TimeChart/index.js.map +0 -1
- package/dist/TimeSeriesTooltip/LineChartTooltip.d.ts +0 -21
- package/dist/TimeSeriesTooltip/LineChartTooltip.d.ts.map +0 -1
- package/dist/TimeSeriesTooltip/LineChartTooltip.js +0 -101
- package/dist/TimeSeriesTooltip/LineChartTooltip.js.map +0 -1
- package/dist/cjs/LineChart/LineChart.js +0 -274
- package/dist/cjs/TimeChart/TimeChart.js +0 -407
- package/dist/cjs/TimeChart/index.js +0 -30
- package/dist/cjs/TimeSeriesTooltip/LineChartTooltip.js +0 -114
- package/dist/cjs/context/TimeZoneProvider.js +0 -98
- package/dist/context/TimeZoneProvider.d.ts +0 -13
- package/dist/context/TimeZoneProvider.d.ts.map +0 -1
- package/dist/context/TimeZoneProvider.js +0 -38
- package/dist/context/TimeZoneProvider.js.map +0 -1
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
"use strict";
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
_export_star(require("./TimeChart"), exports);
|
|
18
|
-
function _export_star(from, to) {
|
|
19
|
-
Object.keys(from).forEach(function(k) {
|
|
20
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
21
|
-
Object.defineProperty(to, k, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function() {
|
|
24
|
-
return from[k];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
return from;
|
|
30
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
"use strict";
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
Object.defineProperty(exports, "LineChartTooltip", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: function() {
|
|
20
|
-
return LineChartTooltip;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
const _jsxruntime = require("react/jsx-runtime");
|
|
24
|
-
const _material = require("@mui/material");
|
|
25
|
-
const _react = require("react");
|
|
26
|
-
const _useresizeobserver = /*#__PURE__*/ _interop_require_default(require("use-resize-observer"));
|
|
27
|
-
const _TooltipContent = require("./TooltipContent");
|
|
28
|
-
const _TooltipHeader = require("./TooltipHeader");
|
|
29
|
-
const _nearbyseries = require("./nearby-series");
|
|
30
|
-
const _tooltipmodel = require("./tooltip-model");
|
|
31
|
-
const _utils = require("./utils");
|
|
32
|
-
function _interop_require_default(obj) {
|
|
33
|
-
return obj && obj.__esModule ? obj : {
|
|
34
|
-
default: obj
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
const LineChartTooltip = /*#__PURE__*/ (0, _react.memo)(function LineChartTooltip({ chartRef, chartData, enablePinning = true, wrapLabels, format, onUnpinClick, pinnedPos, containerId }) {
|
|
38
|
-
const [showAllSeries, setShowAllSeries] = (0, _react.useState)(false);
|
|
39
|
-
const mousePos = (0, _tooltipmodel.useMousePosition)();
|
|
40
|
-
const { height, width, ref: tooltipRef } = (0, _useresizeobserver.default)();
|
|
41
|
-
const transform = (0, _react.useRef)();
|
|
42
|
-
const isTooltipPinned = pinnedPos !== null && enablePinning;
|
|
43
|
-
if (mousePos === null || mousePos.target === null) return null;
|
|
44
|
-
// Ensure user is hovering over a chart before checking for nearby series.
|
|
45
|
-
if (pinnedPos === null && mousePos.target.tagName !== 'CANVAS') return null;
|
|
46
|
-
const chart = chartRef.current;
|
|
47
|
-
// Get series nearby the cursor and pass into tooltip content children.
|
|
48
|
-
const nearbySeries = (0, _nearbyseries.legacyGetNearbySeriesData)({
|
|
49
|
-
mousePos,
|
|
50
|
-
chartData,
|
|
51
|
-
pinnedPos,
|
|
52
|
-
chart,
|
|
53
|
-
format,
|
|
54
|
-
showAllSeries
|
|
55
|
-
});
|
|
56
|
-
if (nearbySeries.length === 0) {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
const totalSeries = chartData.timeSeries.length;
|
|
60
|
-
const containerElement = containerId ? document.querySelector(containerId) : undefined;
|
|
61
|
-
// if tooltip is attached to a container, set max height to the height of the container so tooltip does not get cut off
|
|
62
|
-
const maxHeight = containerElement ? containerElement.getBoundingClientRect().height : undefined;
|
|
63
|
-
transform.current = (0, _utils.assembleTransform)(mousePos, pinnedPos, height ?? 0, width ?? 0, containerElement);
|
|
64
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Portal, {
|
|
65
|
-
container: containerElement,
|
|
66
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Box, {
|
|
67
|
-
ref: tooltipRef,
|
|
68
|
-
sx: (theme)=>({
|
|
69
|
-
minWidth: _tooltipmodel.TOOLTIP_MIN_WIDTH,
|
|
70
|
-
maxWidth: _tooltipmodel.TOOLTIP_MAX_WIDTH,
|
|
71
|
-
maxHeight: maxHeight ?? _tooltipmodel.TOOLTIP_MAX_HEIGHT,
|
|
72
|
-
padding: 0,
|
|
73
|
-
position: 'absolute',
|
|
74
|
-
top: 0,
|
|
75
|
-
left: 0,
|
|
76
|
-
backgroundColor: theme.palette.designSystem?.grey[800] ?? _tooltipmodel.TOOLTIP_BG_COLOR_FALLBACK,
|
|
77
|
-
borderRadius: '6px',
|
|
78
|
-
color: '#fff',
|
|
79
|
-
fontSize: '11px',
|
|
80
|
-
visibility: 'visible',
|
|
81
|
-
opacity: 1,
|
|
82
|
-
transition: 'all 0.1s ease-out',
|
|
83
|
-
// Ensure pinned tooltip shows behind edit panel drawer and sticky header
|
|
84
|
-
zIndex: pinnedPos !== null ? 'auto' : theme.zIndex.tooltip,
|
|
85
|
-
overflow: 'hidden',
|
|
86
|
-
'&:hover': {
|
|
87
|
-
overflowY: 'auto'
|
|
88
|
-
}
|
|
89
|
-
}),
|
|
90
|
-
style: {
|
|
91
|
-
transform: transform.current,
|
|
92
|
-
display: transform.current ? 'block' : 'none'
|
|
93
|
-
},
|
|
94
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
|
|
95
|
-
spacing: 0.5,
|
|
96
|
-
children: [
|
|
97
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_TooltipHeader.TooltipHeader, {
|
|
98
|
-
nearbySeries: nearbySeries,
|
|
99
|
-
totalSeries: totalSeries,
|
|
100
|
-
enablePinning: enablePinning,
|
|
101
|
-
isTooltipPinned: isTooltipPinned,
|
|
102
|
-
showAllSeries: showAllSeries,
|
|
103
|
-
onShowAllClick: (checked)=>setShowAllSeries(checked),
|
|
104
|
-
onUnpinClick: onUnpinClick
|
|
105
|
-
}),
|
|
106
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_TooltipContent.TooltipContent, {
|
|
107
|
-
series: nearbySeries,
|
|
108
|
-
wrapLabels: wrapLabels
|
|
109
|
-
})
|
|
110
|
-
]
|
|
111
|
-
})
|
|
112
|
-
})
|
|
113
|
-
});
|
|
114
|
-
});
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
"use strict";
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
function _export(target, all) {
|
|
18
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: all[name]
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
_export(exports, {
|
|
24
|
-
TimeZoneContext: function() {
|
|
25
|
-
return TimeZoneContext;
|
|
26
|
-
},
|
|
27
|
-
TimeZoneProvider: function() {
|
|
28
|
-
return TimeZoneProvider;
|
|
29
|
-
},
|
|
30
|
-
useTimeZone: function() {
|
|
31
|
-
return useTimeZone;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
const _jsxruntime = require("react/jsx-runtime");
|
|
35
|
-
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
36
|
-
const _utils = require("../utils");
|
|
37
|
-
function _getRequireWildcardCache(nodeInterop) {
|
|
38
|
-
if (typeof WeakMap !== "function") return null;
|
|
39
|
-
var cacheBabelInterop = new WeakMap();
|
|
40
|
-
var cacheNodeInterop = new WeakMap();
|
|
41
|
-
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
42
|
-
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
43
|
-
})(nodeInterop);
|
|
44
|
-
}
|
|
45
|
-
function _interop_require_wildcard(obj, nodeInterop) {
|
|
46
|
-
if (!nodeInterop && obj && obj.__esModule) {
|
|
47
|
-
return obj;
|
|
48
|
-
}
|
|
49
|
-
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
50
|
-
return {
|
|
51
|
-
default: obj
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
var cache = _getRequireWildcardCache(nodeInterop);
|
|
55
|
-
if (cache && cache.has(obj)) {
|
|
56
|
-
return cache.get(obj);
|
|
57
|
-
}
|
|
58
|
-
var newObj = {
|
|
59
|
-
__proto__: null
|
|
60
|
-
};
|
|
61
|
-
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
62
|
-
for(var key in obj){
|
|
63
|
-
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
64
|
-
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
65
|
-
if (desc && (desc.get || desc.set)) {
|
|
66
|
-
Object.defineProperty(newObj, key, desc);
|
|
67
|
-
} else {
|
|
68
|
-
newObj[key] = obj[key];
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
newObj.default = obj;
|
|
73
|
-
if (cache) {
|
|
74
|
-
cache.set(obj, newObj);
|
|
75
|
-
}
|
|
76
|
-
return newObj;
|
|
77
|
-
}
|
|
78
|
-
const TimeZoneContext = /*#__PURE__*/ (0, _react.createContext)(undefined);
|
|
79
|
-
function TimeZoneProvider(props) {
|
|
80
|
-
const { children, timeZone } = props;
|
|
81
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsx)(TimeZoneContext.Provider, {
|
|
82
|
-
value: timeZone,
|
|
83
|
-
children: children
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
function useTimeZone() {
|
|
87
|
-
const timeZone = (0, _react.useContext)(TimeZoneContext);
|
|
88
|
-
return {
|
|
89
|
-
// fallback to "local" timezone if TimeZoneProvider is not present in the React tree
|
|
90
|
-
timeZone: timeZone ?? 'local',
|
|
91
|
-
formatWithUserTimeZone (date, formatString) {
|
|
92
|
-
return (0, _utils.formatWithTimeZone)(date, formatString, timeZone);
|
|
93
|
-
},
|
|
94
|
-
dateFormatOptionsWithUserTimeZone (dateFormatOptions) {
|
|
95
|
-
return (0, _utils.dateFormatOptionsWithTimeZone)(dateFormatOptions, timeZone);
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import React, { ReactElement } from 'react';
|
|
2
|
-
export declare const TimeZoneContext: React.Context<string | undefined>;
|
|
3
|
-
export interface TimeZoneProviderProps {
|
|
4
|
-
timeZone?: string;
|
|
5
|
-
children?: React.ReactNode;
|
|
6
|
-
}
|
|
7
|
-
export declare function TimeZoneProvider(props: TimeZoneProviderProps): ReactElement;
|
|
8
|
-
export declare function useTimeZone(): {
|
|
9
|
-
timeZone: string;
|
|
10
|
-
formatWithUserTimeZone: (date: Date, formatString: string) => string;
|
|
11
|
-
dateFormatOptionsWithUserTimeZone: (dateFormatOptions: Intl.DateTimeFormatOptions) => Intl.DateTimeFormatOptions;
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=TimeZoneProvider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TimeZoneProvider.d.ts","sourceRoot":"","sources":["../../src/context/TimeZoneProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,EAAiB,YAAY,EAAc,MAAM,OAAO,CAAC;AAGvE,eAAO,MAAM,eAAe,mCAA+C,CAAC;AAE5E,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,YAAY,CAG3E;AAED,wBAAgB,WAAW,IAAI;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,sBAAsB,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,KAAK,MAAM,CAAC;IACrE,iCAAiC,EAAE,CAAC,iBAAiB,EAAE,IAAI,CAAC,qBAAqB,KAAK,IAAI,CAAC,qBAAqB,CAAC;CAClH,CAYA"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
-
import React, { createContext, useContext } from 'react';
|
|
15
|
-
import { formatWithTimeZone, dateFormatOptionsWithTimeZone } from '../utils';
|
|
16
|
-
export const TimeZoneContext = /*#__PURE__*/ createContext(undefined);
|
|
17
|
-
export function TimeZoneProvider(props) {
|
|
18
|
-
const { children, timeZone } = props;
|
|
19
|
-
return /*#__PURE__*/ _jsx(TimeZoneContext.Provider, {
|
|
20
|
-
value: timeZone,
|
|
21
|
-
children: children
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
export function useTimeZone() {
|
|
25
|
-
const timeZone = useContext(TimeZoneContext);
|
|
26
|
-
return {
|
|
27
|
-
// fallback to "local" timezone if TimeZoneProvider is not present in the React tree
|
|
28
|
-
timeZone: timeZone ?? 'local',
|
|
29
|
-
formatWithUserTimeZone (date, formatString) {
|
|
30
|
-
return formatWithTimeZone(date, formatString, timeZone);
|
|
31
|
-
},
|
|
32
|
-
dateFormatOptionsWithUserTimeZone (dateFormatOptions) {
|
|
33
|
-
return dateFormatOptionsWithTimeZone(dateFormatOptions, timeZone);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
//# sourceMappingURL=TimeZoneProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/TimeZoneProvider.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React, { createContext, ReactElement, useContext } from 'react';\nimport { formatWithTimeZone, dateFormatOptionsWithTimeZone } from '../utils';\n\nexport const TimeZoneContext = createContext<string | undefined>(undefined);\n\nexport interface TimeZoneProviderProps {\n timeZone?: string;\n children?: React.ReactNode;\n}\n\nexport function TimeZoneProvider(props: TimeZoneProviderProps): ReactElement {\n const { children, timeZone } = props;\n return <TimeZoneContext.Provider value={timeZone}>{children}</TimeZoneContext.Provider>;\n}\n\nexport function useTimeZone(): {\n timeZone: string;\n formatWithUserTimeZone: (date: Date, formatString: string) => string;\n dateFormatOptionsWithUserTimeZone: (dateFormatOptions: Intl.DateTimeFormatOptions) => Intl.DateTimeFormatOptions;\n} {\n const timeZone = useContext(TimeZoneContext);\n return {\n // fallback to \"local\" timezone if TimeZoneProvider is not present in the React tree\n timeZone: timeZone ?? 'local',\n formatWithUserTimeZone(date: Date, formatString: string): string {\n return formatWithTimeZone(date, formatString, timeZone);\n },\n dateFormatOptionsWithUserTimeZone(dateFormatOptions: Intl.DateTimeFormatOptions): Intl.DateTimeFormatOptions {\n return dateFormatOptionsWithTimeZone(dateFormatOptions, timeZone);\n },\n };\n}\n"],"names":["React","createContext","useContext","formatWithTimeZone","dateFormatOptionsWithTimeZone","TimeZoneContext","undefined","TimeZoneProvider","props","children","timeZone","Provider","value","useTimeZone","formatWithUserTimeZone","date","formatString","dateFormatOptionsWithUserTimeZone","dateFormatOptions"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,OAAOA,SAASC,aAAa,EAAgBC,UAAU,QAAQ,QAAQ;AACvE,SAASC,kBAAkB,EAAEC,6BAA6B,QAAQ,WAAW;AAE7E,OAAO,MAAMC,gCAAkBJ,cAAkCK,WAAW;AAO5E,OAAO,SAASC,iBAAiBC,KAA4B;IAC3D,MAAM,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,GAAGF;IAC/B,qBAAO,KAACH,gBAAgBM,QAAQ;QAACC,OAAOF;kBAAWD;;AACrD;AAEA,OAAO,SAASI;IAKd,MAAMH,WAAWR,WAAWG;IAC5B,OAAO;QACL,oFAAoF;QACpFK,UAAUA,YAAY;QACtBI,wBAAuBC,IAAU,EAAEC,YAAoB;YACrD,OAAOb,mBAAmBY,MAAMC,cAAcN;QAChD;QACAO,mCAAkCC,iBAA6C;YAC7E,OAAOd,8BAA8Bc,mBAAmBR;QAC1D;IACF;AACF"}
|