@coinbase/cds-mobile-visualization 3.3.0 → 3.4.0-beta.10
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/CHANGELOG.md +80 -0
- package/dts/chart/CartesianChart.d.ts +125 -0
- package/dts/chart/CartesianChart.d.ts.map +1 -0
- package/dts/chart/ChartContextBridge.d.ts +28 -0
- package/dts/chart/ChartContextBridge.d.ts.map +1 -0
- package/dts/chart/ChartProvider.d.ts +6 -0
- package/dts/chart/ChartProvider.d.ts.map +1 -0
- package/dts/chart/Path.d.ts +91 -0
- package/dts/chart/Path.d.ts.map +1 -0
- package/dts/chart/PeriodSelector.d.ts +85 -0
- package/dts/chart/PeriodSelector.d.ts.map +1 -0
- package/dts/chart/area/Area.d.ts +77 -0
- package/dts/chart/area/Area.d.ts.map +1 -0
- package/dts/chart/area/AreaChart.d.ts +131 -0
- package/dts/chart/area/AreaChart.d.ts.map +1 -0
- package/dts/chart/area/DottedArea.d.ts +46 -0
- package/dts/chart/area/DottedArea.d.ts.map +1 -0
- package/dts/chart/area/GradientArea.d.ts +36 -0
- package/dts/chart/area/GradientArea.d.ts.map +1 -0
- package/dts/chart/area/SolidArea.d.ts +23 -0
- package/dts/chart/area/SolidArea.d.ts.map +1 -0
- package/dts/chart/area/index.d.ts +6 -0
- package/dts/chart/area/index.d.ts.map +1 -0
- package/dts/chart/axis/Axis.d.ts +194 -0
- package/dts/chart/axis/Axis.d.ts.map +1 -0
- package/dts/chart/axis/DefaultAxisTickLabel.d.ts +8 -0
- package/dts/chart/axis/DefaultAxisTickLabel.d.ts.map +1 -0
- package/dts/chart/axis/XAxis.d.ts +16 -0
- package/dts/chart/axis/XAxis.d.ts.map +1 -0
- package/dts/chart/axis/YAxis.d.ts +21 -0
- package/dts/chart/axis/YAxis.d.ts.map +1 -0
- package/dts/chart/axis/index.d.ts +5 -0
- package/dts/chart/axis/index.d.ts.map +1 -0
- package/dts/chart/bar/Bar.d.ts +92 -0
- package/dts/chart/bar/Bar.d.ts.map +1 -0
- package/dts/chart/bar/BarChart.d.ts +113 -0
- package/dts/chart/bar/BarChart.d.ts.map +1 -0
- package/dts/chart/bar/BarPlot.d.ts +30 -0
- package/dts/chart/bar/BarPlot.d.ts.map +1 -0
- package/dts/chart/bar/BarStack.d.ts +102 -0
- package/dts/chart/bar/BarStack.d.ts.map +1 -0
- package/dts/chart/bar/BarStackGroup.d.ts +36 -0
- package/dts/chart/bar/BarStackGroup.d.ts.map +1 -0
- package/dts/chart/bar/DefaultBar.d.ts +7 -0
- package/dts/chart/bar/DefaultBar.d.ts.map +1 -0
- package/dts/chart/bar/DefaultBarStack.d.ts +7 -0
- package/dts/chart/bar/DefaultBarStack.d.ts.map +1 -0
- package/dts/chart/bar/index.d.ts +8 -0
- package/dts/chart/bar/index.d.ts.map +1 -0
- package/dts/chart/gradient/Gradient.d.ts +25 -0
- package/dts/chart/gradient/Gradient.d.ts.map +1 -0
- package/dts/chart/gradient/index.d.ts +2 -0
- package/dts/chart/gradient/index.d.ts.map +1 -0
- package/dts/chart/index.d.ts +15 -0
- package/dts/chart/index.d.ts.map +1 -0
- package/dts/chart/line/DefaultReferenceLineLabel.d.ts +9 -0
- package/dts/chart/line/DefaultReferenceLineLabel.d.ts.map +1 -0
- package/dts/chart/line/DottedLine.d.ts +20 -0
- package/dts/chart/line/DottedLine.d.ts.map +1 -0
- package/dts/chart/line/Line.d.ts +115 -0
- package/dts/chart/line/Line.d.ts.map +1 -0
- package/dts/chart/line/LineChart.d.ts +118 -0
- package/dts/chart/line/LineChart.d.ts.map +1 -0
- package/dts/chart/line/ReferenceLine.d.ts +139 -0
- package/dts/chart/line/ReferenceLine.d.ts.map +1 -0
- package/dts/chart/line/SolidLine.d.ts +15 -0
- package/dts/chart/line/SolidLine.d.ts.map +1 -0
- package/dts/chart/line/index.d.ts +7 -0
- package/dts/chart/line/index.d.ts.map +1 -0
- package/dts/chart/point/DefaultPointLabel.d.ts +10 -0
- package/dts/chart/point/DefaultPointLabel.d.ts.map +1 -0
- package/dts/chart/point/Point.d.ts +120 -0
- package/dts/chart/point/Point.d.ts.map +1 -0
- package/dts/chart/point/index.d.ts +3 -0
- package/dts/chart/point/index.d.ts.map +1 -0
- package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts +8 -0
- package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts.map +1 -0
- package/dts/chart/scrubber/DefaultScrubberBeaconLabel.d.ts +12 -0
- package/dts/chart/scrubber/DefaultScrubberBeaconLabel.d.ts.map +1 -0
- package/dts/chart/scrubber/DefaultScrubberLabel.d.ts +11 -0
- package/dts/chart/scrubber/DefaultScrubberLabel.d.ts.map +1 -0
- package/dts/chart/scrubber/Scrubber.d.ts +233 -0
- package/dts/chart/scrubber/Scrubber.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts +44 -0
- package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts +31 -0
- package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberProvider.d.ts +20 -0
- package/dts/chart/scrubber/ScrubberProvider.d.ts.map +1 -0
- package/dts/chart/scrubber/index.d.ts +5 -0
- package/dts/chart/scrubber/index.d.ts.map +1 -0
- package/dts/chart/text/ChartText.d.ts +164 -0
- package/dts/chart/text/ChartText.d.ts.map +1 -0
- package/dts/chart/text/ChartTextGroup.d.ts +61 -0
- package/dts/chart/text/ChartTextGroup.d.ts.map +1 -0
- package/dts/chart/text/index.d.ts +3 -0
- package/dts/chart/text/index.d.ts.map +1 -0
- package/dts/chart/utils/axis.d.ts +342 -0
- package/dts/chart/utils/axis.d.ts.map +1 -0
- package/dts/chart/utils/bar.d.ts +20 -0
- package/dts/chart/utils/bar.d.ts.map +1 -0
- package/dts/chart/utils/chart.d.ts +124 -0
- package/dts/chart/utils/chart.d.ts.map +1 -0
- package/dts/chart/utils/context.d.ts +116 -0
- package/dts/chart/utils/context.d.ts.map +1 -0
- package/dts/chart/utils/gradient.d.ts +117 -0
- package/dts/chart/utils/gradient.d.ts.map +1 -0
- package/dts/chart/utils/index.d.ts +11 -0
- package/dts/chart/utils/index.d.ts.map +1 -0
- package/dts/chart/utils/path.d.ts +160 -0
- package/dts/chart/utils/path.d.ts.map +1 -0
- package/dts/chart/utils/point.d.ts +134 -0
- package/dts/chart/utils/point.d.ts.map +1 -0
- package/dts/chart/utils/scale.d.ts +134 -0
- package/dts/chart/utils/scale.d.ts.map +1 -0
- package/dts/chart/utils/scrubber.d.ts +39 -0
- package/dts/chart/utils/scrubber.d.ts.map +1 -0
- package/dts/chart/utils/transition.d.ts +140 -0
- package/dts/chart/utils/transition.d.ts.map +1 -0
- package/dts/index.d.ts +2 -1
- package/dts/index.d.ts.map +1 -1
- package/dts/sparkline/Counter.d.ts +7 -2
- package/dts/sparkline/Sparkline.d.ts +67 -16
- package/dts/sparkline/Sparkline.d.ts.map +1 -1
- package/dts/sparkline/SparklineArea.d.ts +10 -4
- package/dts/sparkline/SparklineArea.d.ts.map +1 -1
- package/dts/sparkline/SparklineAreaPattern.d.ts +12 -4
- package/dts/sparkline/SparklineAreaPattern.d.ts.map +1 -1
- package/dts/sparkline/SparklineGradient.d.ts +21 -10
- package/dts/sparkline/SparklineGradient.d.ts.map +1 -1
- package/dts/sparkline/__figma__/Sparkline.figma.d.ts +1 -1
- package/dts/sparkline/generateSparklineWithId.d.ts +8 -2
- package/dts/sparkline/generateSparklineWithId.d.ts.map +1 -1
- package/dts/sparkline/index.d.ts +1 -1
- package/dts/sparkline/sparkline-interactive/SparklineAccessibleView.d.ts +8 -3
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts +132 -110
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts.map +1 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts +22 -9
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts.map +1 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts +18 -7
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts +9 -4
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts +11 -6
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMinMax.d.ts +7 -5
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePanGestureHandler.d.ts +22 -10
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts +21 -7
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts.map +1 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts +21 -16
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts +29 -23
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts +22 -14
- package/dts/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.d.ts +1 -1
- package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.d.ts +9 -5
- package/dts/sparkline/sparkline-interactive/useMinMaxTransform.d.ts +11 -6
- package/dts/sparkline/sparkline-interactive/useOpacityAnimation.d.ts +5 -2
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts +17 -17
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveLineStyles.d.ts +16 -13
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts +106 -98
- package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts +1 -1
- package/dts/sparkline/sparkline-interactive-header/useSparklineInteractiveHeaderStyles.d.ts +22 -19
- package/esm/chart/CartesianChart.js +335 -0
- package/esm/chart/ChartContextBridge.js +148 -0
- package/esm/chart/ChartProvider.js +10 -0
- package/esm/chart/Path.js +218 -0
- package/esm/chart/PeriodSelector.js +136 -0
- package/esm/chart/__stories__/CartesianChart.stories.js +723 -0
- package/esm/chart/__stories__/Chart.stories.js +77 -0
- package/esm/chart/__stories__/PeriodSelector.stories.js +322 -0
- package/esm/chart/area/Area.js +75 -0
- package/esm/chart/area/AreaChart.js +151 -0
- package/esm/chart/area/DottedArea.js +80 -0
- package/esm/chart/area/GradientArea.js +54 -0
- package/esm/chart/area/SolidArea.js +38 -0
- package/esm/chart/area/__stories__/AreaChart.stories.js +100 -0
- package/esm/chart/area/index.js +7 -0
- package/esm/chart/axis/Axis.js +45 -0
- package/esm/chart/axis/DefaultAxisTickLabel.js +11 -0
- package/esm/chart/axis/XAxis.js +188 -0
- package/esm/chart/axis/YAxis.js +177 -0
- package/esm/chart/axis/__stories__/Axis.stories.js +276 -0
- package/esm/chart/axis/index.js +6 -0
- package/esm/chart/bar/Bar.js +69 -0
- package/esm/chart/bar/BarChart.js +125 -0
- package/esm/chart/bar/BarPlot.js +102 -0
- package/esm/chart/bar/BarStack.js +551 -0
- package/esm/chart/bar/BarStackGroup.js +79 -0
- package/esm/chart/bar/DefaultBar.js +56 -0
- package/esm/chart/bar/DefaultBarStack.js +47 -0
- package/esm/chart/bar/__stories__/BarChart.stories.js +668 -0
- package/esm/chart/bar/index.js +9 -0
- package/esm/chart/gradient/Gradient.js +53 -0
- package/esm/chart/gradient/index.js +1 -0
- package/esm/chart/index.js +16 -0
- package/esm/chart/line/DefaultReferenceLineLabel.js +66 -0
- package/esm/chart/line/DottedLine.js +50 -0
- package/esm/chart/line/Line.js +178 -0
- package/esm/chart/line/LineChart.js +121 -0
- package/esm/chart/line/ReferenceLine.js +132 -0
- package/esm/chart/line/SolidLine.js +46 -0
- package/esm/chart/line/__stories__/LineChart.stories.js +2372 -0
- package/esm/chart/line/__stories__/ReferenceLine.stories.js +132 -0
- package/esm/chart/line/index.js +8 -0
- package/esm/chart/point/DefaultPointLabel.js +39 -0
- package/esm/chart/point/Point.js +188 -0
- package/esm/chart/point/index.js +2 -0
- package/esm/chart/scrubber/DefaultScrubberBeacon.js +179 -0
- package/esm/chart/scrubber/DefaultScrubberBeaconLabel.js +43 -0
- package/esm/chart/scrubber/DefaultScrubberLabel.js +28 -0
- package/esm/chart/scrubber/Scrubber.js +166 -0
- package/esm/chart/scrubber/ScrubberBeaconGroup.js +161 -0
- package/esm/chart/scrubber/ScrubberBeaconLabelGroup.js +185 -0
- package/esm/chart/scrubber/ScrubberProvider.js +135 -0
- package/esm/chart/scrubber/index.js +4 -0
- package/esm/chart/text/ChartText.js +305 -0
- package/esm/chart/text/ChartTextGroup.js +211 -0
- package/esm/chart/text/index.js +4 -0
- package/esm/chart/utils/axis.js +592 -0
- package/esm/chart/utils/bar.js +24 -0
- package/esm/chart/utils/chart.js +270 -0
- package/esm/chart/utils/context.js +15 -0
- package/esm/chart/utils/gradient.js +305 -0
- package/esm/chart/utils/index.js +12 -0
- package/esm/chart/utils/path.js +274 -0
- package/esm/chart/utils/point.js +229 -0
- package/esm/chart/utils/scale.js +277 -0
- package/esm/chart/utils/scrubber.js +139 -0
- package/esm/chart/utils/transition.js +185 -0
- package/esm/index.js +4 -1
- package/esm/sparkline/Sparkline.js +129 -16
- package/esm/sparkline/SparklineArea.js +7 -2
- package/esm/sparkline/SparklineAreaPattern.js +4 -2
- package/esm/sparkline/SparklineGradient.js +4 -0
- package/esm/sparkline/__stories__/Sparkline.stories.js +11 -7
- package/esm/sparkline/__stories__/SparklineGradient.stories.js +7 -4
- package/esm/sparkline/generateSparklineWithId.js +3 -2
- package/esm/sparkline/sparkline-interactive/SparklineInteractive.js +5 -1
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.js +5 -2
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePaths.js +4 -0
- package/esm/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.js +76 -24
- package/esm/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.js +17 -9
- package/package.json +17 -11
- package/dts/sparkline/__stories__/Sparkline.stories.d.ts +0 -3
- package/dts/sparkline/__stories__/Sparkline.stories.d.ts.map +0 -1
- package/dts/sparkline/__stories__/SparklineGradient.stories.d.ts +0 -3
- package/dts/sparkline/__stories__/SparklineGradient.stories.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.d.ts +0 -3
- package/dts/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractive.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractive.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveHoverDate.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveHoverDate.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePanGestureHandler.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePanGestureHandler.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePeriodSelector.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePeriodSelector.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveTimeseriesPaths.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveTimeseriesPaths.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__tests__/useMinMaxTransform.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/useMinMaxTransform.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.test.disable.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.test.disable.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.d.ts +0 -4
- package/dts/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive-header/__tests__/SparklineInteractiveHeader.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive-header/__tests__/SparklineInteractiveHeader.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive-header/__tests__/useSparklineInteractiveHeaderStyles.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive-header/__tests__/useSparklineInteractiveHeaderStyles.test.d.ts.map +0 -1
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
const _excluded = ["d", "initialPath", "fill", "fillOpacity", "stroke", "strokeOpacity", "strokeWidth", "strokeCap", "strokeJoin", "children", "transition"],
|
|
2
|
+
_excluded2 = ["animate", "clipRect", "clipPath", "clipOffset", "d", "initialPath", "fill", "fillOpacity", "stroke", "strokeOpacity", "strokeWidth", "strokeCap", "strokeJoin", "children", "transition"];
|
|
3
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
4
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
5
|
+
import { memo, useEffect, useMemo } from 'react';
|
|
6
|
+
import { useDerivedValue, useSharedValue, withTiming } from 'react-native-reanimated';
|
|
7
|
+
import { Group, Path as SkiaPath, Skia, usePathInterpolation } from '@shopify/react-native-skia';
|
|
8
|
+
import { usePathTransition } from './utils/transition';
|
|
9
|
+
import { useCartesianChartContext } from './ChartProvider';
|
|
10
|
+
import { unwrapAnimatedValue } from './utils';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Duration in milliseconds for path enter transition.
|
|
14
|
+
*/
|
|
15
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
|
+
export const pathEnterTransitionDuration = 500;
|
|
17
|
+
const AnimatedPath = /*#__PURE__*/memo(_ref => {
|
|
18
|
+
let {
|
|
19
|
+
d = '',
|
|
20
|
+
initialPath,
|
|
21
|
+
fill,
|
|
22
|
+
fillOpacity,
|
|
23
|
+
stroke,
|
|
24
|
+
strokeOpacity,
|
|
25
|
+
strokeWidth,
|
|
26
|
+
strokeCap,
|
|
27
|
+
strokeJoin,
|
|
28
|
+
children,
|
|
29
|
+
transition
|
|
30
|
+
} = _ref,
|
|
31
|
+
pathProps = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
32
|
+
const isDAnimated = typeof d !== 'string';
|
|
33
|
+
|
|
34
|
+
// When d is animated, usePathTransition handles static path transitions.
|
|
35
|
+
// For animated d values, we skip usePathTransition and use useDerivedValue directly.
|
|
36
|
+
const animatedPath = usePathTransition({
|
|
37
|
+
currentPath: isDAnimated ? '' : d,
|
|
38
|
+
initialPath,
|
|
39
|
+
transition
|
|
40
|
+
});
|
|
41
|
+
const isFilled = fill !== undefined && fill !== 'none';
|
|
42
|
+
const isStroked = stroke !== undefined && stroke !== 'none';
|
|
43
|
+
const activePath = useDerivedValue(() => {
|
|
44
|
+
if (isDAnimated) {
|
|
45
|
+
var _d$value;
|
|
46
|
+
return (_d$value = d.value) != null ? _d$value : Skia.Path.Make();
|
|
47
|
+
}
|
|
48
|
+
return animatedPath.value;
|
|
49
|
+
});
|
|
50
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
51
|
+
children: [isFilled && /*#__PURE__*/_jsx(SkiaPath, _extends({
|
|
52
|
+
color: fill,
|
|
53
|
+
opacity: fillOpacity,
|
|
54
|
+
path: activePath,
|
|
55
|
+
style: "fill"
|
|
56
|
+
}, pathProps, {
|
|
57
|
+
children: children
|
|
58
|
+
})), isStroked && /*#__PURE__*/_jsx(SkiaPath, _extends({
|
|
59
|
+
color: stroke,
|
|
60
|
+
opacity: strokeOpacity,
|
|
61
|
+
path: activePath,
|
|
62
|
+
strokeCap: strokeCap,
|
|
63
|
+
strokeJoin: strokeJoin,
|
|
64
|
+
strokeWidth: strokeWidth,
|
|
65
|
+
style: "stroke"
|
|
66
|
+
}, pathProps, {
|
|
67
|
+
children: children
|
|
68
|
+
}))]
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
export const Path = /*#__PURE__*/memo(props => {
|
|
72
|
+
const {
|
|
73
|
+
animate: animateProp,
|
|
74
|
+
clipRect,
|
|
75
|
+
clipPath: clipPathProp,
|
|
76
|
+
clipOffset = 0,
|
|
77
|
+
d = '',
|
|
78
|
+
initialPath,
|
|
79
|
+
fill,
|
|
80
|
+
fillOpacity,
|
|
81
|
+
stroke,
|
|
82
|
+
strokeOpacity,
|
|
83
|
+
strokeWidth,
|
|
84
|
+
strokeCap,
|
|
85
|
+
strokeJoin,
|
|
86
|
+
children,
|
|
87
|
+
transition
|
|
88
|
+
} = props,
|
|
89
|
+
pathProps = _objectWithoutPropertiesLoose(props, _excluded2);
|
|
90
|
+
const context = useCartesianChartContext();
|
|
91
|
+
const rect = clipRect != null ? clipRect : context.drawingArea;
|
|
92
|
+
const animate = animateProp != null ? animateProp : context.animate;
|
|
93
|
+
|
|
94
|
+
// The clip offset provides extra padding to prevent path from being cut off
|
|
95
|
+
// Area charts typically use offset=0 for exact clipping, while lines use offset=2 for breathing room
|
|
96
|
+
const totalOffset = clipOffset * 2; // Applied on both sides
|
|
97
|
+
|
|
98
|
+
// Animation progress for clip path reveal
|
|
99
|
+
const clipProgress = useSharedValue(animate ? 0 : 1);
|
|
100
|
+
|
|
101
|
+
// Trigger clip path animation when component mounts and animate is true
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
if (animate) {
|
|
104
|
+
clipProgress.value = withTiming(1, {
|
|
105
|
+
duration: pathEnterTransitionDuration
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}, [animate, clipProgress]);
|
|
109
|
+
|
|
110
|
+
// Create initial and target clip paths for animation
|
|
111
|
+
const {
|
|
112
|
+
initialClipPath,
|
|
113
|
+
targetClipPath
|
|
114
|
+
} = useMemo(() => {
|
|
115
|
+
if (!rect) return {
|
|
116
|
+
initialClipPath: null,
|
|
117
|
+
targetClipPath: null
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// Initial clip path (width = 0)
|
|
121
|
+
const initial = Skia.Path.Make();
|
|
122
|
+
initial.addRect({
|
|
123
|
+
x: rect.x - clipOffset,
|
|
124
|
+
y: rect.y - clipOffset,
|
|
125
|
+
width: 0,
|
|
126
|
+
height: rect.height + totalOffset
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// Target clip path (full width)
|
|
130
|
+
const target = Skia.Path.Make();
|
|
131
|
+
target.addRect({
|
|
132
|
+
x: rect.x - clipOffset,
|
|
133
|
+
y: rect.y - clipOffset,
|
|
134
|
+
width: rect.width + totalOffset,
|
|
135
|
+
height: rect.height + totalOffset
|
|
136
|
+
});
|
|
137
|
+
return {
|
|
138
|
+
initialClipPath: initial,
|
|
139
|
+
targetClipPath: target
|
|
140
|
+
};
|
|
141
|
+
}, [rect, clipOffset, totalOffset]);
|
|
142
|
+
|
|
143
|
+
// Use usePathInterpolation for animated clip path
|
|
144
|
+
const animatedClipPath = usePathInterpolation(clipProgress, [0, 1], animate && initialClipPath && targetClipPath ? [initialClipPath, targetClipPath] : targetClipPath ? [targetClipPath, targetClipPath] : [Skia.Path.Make(), Skia.Path.Make()]);
|
|
145
|
+
|
|
146
|
+
// Resolve the final clip path:
|
|
147
|
+
// 1. If clipPath prop was explicitly provided, use it (even if null = no clipping)
|
|
148
|
+
// 2. If animating, use the interpolated clip path
|
|
149
|
+
// 3. Otherwise, use static target clip path
|
|
150
|
+
const resolvedClipPath = useMemo(() => {
|
|
151
|
+
// If clipPath was explicitly provided (null or string), use it directly
|
|
152
|
+
if (clipPathProp !== undefined) {
|
|
153
|
+
return clipPathProp;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// If not animating or paths are null, return target clip path
|
|
157
|
+
if (!animate || !targetClipPath) {
|
|
158
|
+
return targetClipPath;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Return undefined here since we'll use animatedClipPath directly
|
|
162
|
+
return undefined;
|
|
163
|
+
}, [clipPathProp, animate, targetClipPath]);
|
|
164
|
+
|
|
165
|
+
// Convert SVG path string to SkPath for static rendering
|
|
166
|
+
const staticPath = useDerivedValue(() => {
|
|
167
|
+
var _Skia$Path$MakeFromSV;
|
|
168
|
+
const dValue = unwrapAnimatedValue(d);
|
|
169
|
+
if (!dValue) return Skia.Path.Make();
|
|
170
|
+
return (_Skia$Path$MakeFromSV = Skia.Path.MakeFromSVGString(dValue)) != null ? _Skia$Path$MakeFromSV : Skia.Path.Make();
|
|
171
|
+
}, [d]);
|
|
172
|
+
const isFilled = fill !== undefined && fill !== 'none';
|
|
173
|
+
const isStroked = stroke !== undefined && stroke !== 'none';
|
|
174
|
+
const content = !animate ? /*#__PURE__*/_jsxs(_Fragment, {
|
|
175
|
+
children: [isFilled && /*#__PURE__*/_jsx(SkiaPath, _extends({
|
|
176
|
+
color: fill,
|
|
177
|
+
opacity: fillOpacity,
|
|
178
|
+
path: staticPath,
|
|
179
|
+
style: "fill"
|
|
180
|
+
}, pathProps, {
|
|
181
|
+
children: children
|
|
182
|
+
})), isStroked && /*#__PURE__*/_jsx(SkiaPath, _extends({
|
|
183
|
+
color: stroke,
|
|
184
|
+
opacity: strokeOpacity,
|
|
185
|
+
path: staticPath,
|
|
186
|
+
strokeCap: strokeCap,
|
|
187
|
+
strokeJoin: strokeJoin,
|
|
188
|
+
strokeWidth: strokeWidth,
|
|
189
|
+
style: "stroke"
|
|
190
|
+
}, pathProps, {
|
|
191
|
+
children: children
|
|
192
|
+
}))]
|
|
193
|
+
}) : /*#__PURE__*/_jsx(AnimatedPath, {
|
|
194
|
+
d: d,
|
|
195
|
+
fill: fill,
|
|
196
|
+
fillOpacity: fillOpacity,
|
|
197
|
+
initialPath: initialPath,
|
|
198
|
+
stroke: stroke,
|
|
199
|
+
strokeCap: strokeCap,
|
|
200
|
+
strokeJoin: strokeJoin,
|
|
201
|
+
strokeOpacity: strokeOpacity,
|
|
202
|
+
strokeWidth: strokeWidth,
|
|
203
|
+
transition: transition,
|
|
204
|
+
children: children
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// Determine which clip path to use
|
|
208
|
+
const finalClipPath = animate && resolvedClipPath === undefined ? animatedClipPath : resolvedClipPath;
|
|
209
|
+
|
|
210
|
+
// If finalClipPath is null, render without clipping
|
|
211
|
+
if (finalClipPath === null) {
|
|
212
|
+
return content;
|
|
213
|
+
}
|
|
214
|
+
return /*#__PURE__*/_jsx(Group, {
|
|
215
|
+
clip: finalClipPath,
|
|
216
|
+
children: content
|
|
217
|
+
});
|
|
218
|
+
});
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
const _excluded = ["color", "label", "font", "hideDot", "style"],
|
|
2
|
+
_excluded2 = ["background", "activeBackground", "width", "justifyContent", "TabComponent", "TabsActiveIndicatorComponent"];
|
|
3
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
4
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
5
|
+
import React, { forwardRef, memo, useMemo } from 'react';
|
|
6
|
+
import { StyleSheet, View } from 'react-native';
|
|
7
|
+
import Animated, { useAnimatedStyle, useSharedValue, withSpring } from 'react-native-reanimated';
|
|
8
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
9
|
+
import { SegmentedTabs } from '@coinbase/cds-mobile/tabs';
|
|
10
|
+
import { SegmentedTab } from '@coinbase/cds-mobile/tabs/SegmentedTab';
|
|
11
|
+
import { tabsSpringConfig } from '@coinbase/cds-mobile/tabs/Tabs';
|
|
12
|
+
import { Text } from '@coinbase/cds-mobile/typography';
|
|
13
|
+
|
|
14
|
+
// Animated active indicator to support smooth transition of background color
|
|
15
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
|
+
export const PeriodSelectorActiveIndicator = _ref => {
|
|
17
|
+
let {
|
|
18
|
+
activeTabRect,
|
|
19
|
+
background = 'bgPrimaryWash',
|
|
20
|
+
position = 'absolute',
|
|
21
|
+
borderRadius = 1000
|
|
22
|
+
} = _ref;
|
|
23
|
+
const theme = useTheme();
|
|
24
|
+
const {
|
|
25
|
+
width,
|
|
26
|
+
height,
|
|
27
|
+
x
|
|
28
|
+
} = activeTabRect;
|
|
29
|
+
|
|
30
|
+
// Get the target background color
|
|
31
|
+
const backgroundColorKey = background;
|
|
32
|
+
const targetColor = theme.color[backgroundColorKey] || background;
|
|
33
|
+
|
|
34
|
+
// Track previous values for first render detection
|
|
35
|
+
const previousActiveTabRect = React.useRef(activeTabRect);
|
|
36
|
+
const previousColor = React.useRef(targetColor);
|
|
37
|
+
|
|
38
|
+
// Combined animated value for position, size, and color
|
|
39
|
+
const newAnimatedValues = {
|
|
40
|
+
x,
|
|
41
|
+
width,
|
|
42
|
+
backgroundColor: targetColor
|
|
43
|
+
};
|
|
44
|
+
const animatedValues = useSharedValue(newAnimatedValues);
|
|
45
|
+
const isFirstRenderWithWidth = previousActiveTabRect.current.width === 0 && activeTabRect.width > 0;
|
|
46
|
+
if (previousActiveTabRect.current !== activeTabRect || previousColor.current !== targetColor) {
|
|
47
|
+
previousActiveTabRect.current = activeTabRect;
|
|
48
|
+
previousColor.current = targetColor;
|
|
49
|
+
animatedValues.value = isFirstRenderWithWidth ? newAnimatedValues : withSpring(newAnimatedValues, tabsSpringConfig);
|
|
50
|
+
}
|
|
51
|
+
const animatedStyles = useAnimatedStyle(() => ({
|
|
52
|
+
transform: [{
|
|
53
|
+
translateX: animatedValues.value.x
|
|
54
|
+
}],
|
|
55
|
+
width: animatedValues.value.width,
|
|
56
|
+
backgroundColor: animatedValues.value.backgroundColor
|
|
57
|
+
}), [animatedValues]);
|
|
58
|
+
if (!width) return;
|
|
59
|
+
return /*#__PURE__*/_jsx(Animated.View, {
|
|
60
|
+
style: [{
|
|
61
|
+
position: position,
|
|
62
|
+
height,
|
|
63
|
+
borderRadius
|
|
64
|
+
}, animatedStyles],
|
|
65
|
+
testID: "period-selector-active-indicator"
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
const styles = StyleSheet.create({
|
|
69
|
+
liveContainer: {
|
|
70
|
+
flexDirection: 'row',
|
|
71
|
+
alignItems: 'center'
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
export const LiveTabLabel = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref2, ref) => {
|
|
75
|
+
let {
|
|
76
|
+
color = 'fgNegative',
|
|
77
|
+
label = 'LIVE',
|
|
78
|
+
font = 'label1',
|
|
79
|
+
hideDot,
|
|
80
|
+
style
|
|
81
|
+
} = _ref2,
|
|
82
|
+
props = _objectWithoutPropertiesLoose(_ref2, _excluded);
|
|
83
|
+
const theme = useTheme();
|
|
84
|
+
const colorKey = color;
|
|
85
|
+
const textColor = theme.color[colorKey] || color;
|
|
86
|
+
const dotStyle = useMemo(() => ({
|
|
87
|
+
width: theme.space[1],
|
|
88
|
+
height: theme.space[1],
|
|
89
|
+
borderRadius: 1000,
|
|
90
|
+
marginRight: theme.space[0.75],
|
|
91
|
+
backgroundColor: textColor
|
|
92
|
+
}), [theme.space, textColor]);
|
|
93
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
94
|
+
ref: ref,
|
|
95
|
+
style: [styles.liveContainer, style],
|
|
96
|
+
children: [!hideDot && /*#__PURE__*/_jsx(View, {
|
|
97
|
+
style: dotStyle
|
|
98
|
+
}), /*#__PURE__*/_jsx(Text, _extends({
|
|
99
|
+
color: color,
|
|
100
|
+
font: font
|
|
101
|
+
}, props, {
|
|
102
|
+
children: label
|
|
103
|
+
}))]
|
|
104
|
+
});
|
|
105
|
+
}));
|
|
106
|
+
|
|
107
|
+
// Custom tab component with primary color for active state
|
|
108
|
+
const PeriodSelectorTab = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((props, ref) => /*#__PURE__*/_jsx(SegmentedTab, _extends({
|
|
109
|
+
ref: ref,
|
|
110
|
+
activeColor: "fgPrimary",
|
|
111
|
+
font: "label1"
|
|
112
|
+
}, props))));
|
|
113
|
+
/**
|
|
114
|
+
* PeriodSelector is a specialized version of SegmentedTabs optimized for chart period selection.
|
|
115
|
+
* It provides transparent background, primary wash active state, and full-width layout by default.
|
|
116
|
+
*/
|
|
117
|
+
export const PeriodSelector = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref3, ref) => {
|
|
118
|
+
let {
|
|
119
|
+
background = 'transparent',
|
|
120
|
+
activeBackground = 'bgPrimaryWash',
|
|
121
|
+
width = '100%',
|
|
122
|
+
justifyContent = 'space-between',
|
|
123
|
+
TabComponent = PeriodSelectorTab,
|
|
124
|
+
TabsActiveIndicatorComponent = PeriodSelectorActiveIndicator
|
|
125
|
+
} = _ref3,
|
|
126
|
+
props = _objectWithoutPropertiesLoose(_ref3, _excluded2);
|
|
127
|
+
return /*#__PURE__*/_jsx(SegmentedTabs, _extends({
|
|
128
|
+
ref: ref,
|
|
129
|
+
TabComponent: TabComponent,
|
|
130
|
+
TabsActiveIndicatorComponent: TabsActiveIndicatorComponent,
|
|
131
|
+
activeBackground: activeBackground,
|
|
132
|
+
background: background,
|
|
133
|
+
justifyContent: justifyContent,
|
|
134
|
+
width: width
|
|
135
|
+
}, props));
|
|
136
|
+
}));
|