@coinbase/cds-web-visualization 0.0.0 → 3.4.0-beta.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/CHANGELOG.md +26 -0
- package/README.md +3 -0
- package/dts/chart/CartesianChart.d.ts +36 -0
- package/dts/chart/CartesianChart.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 +34 -0
- package/dts/chart/Path.d.ts.map +1 -0
- package/dts/chart/PeriodSelector.d.ts +61 -0
- package/dts/chart/PeriodSelector.d.ts.map +1 -0
- package/dts/chart/Point.d.ts +153 -0
- package/dts/chart/Point.d.ts.map +1 -0
- package/dts/chart/area/Area.d.ts +48 -0
- package/dts/chart/area/Area.d.ts.map +1 -0
- package/dts/chart/area/AreaChart.d.ts +52 -0
- package/dts/chart/area/AreaChart.d.ts.map +1 -0
- package/dts/chart/area/DottedArea.d.ts +68 -0
- package/dts/chart/area/DottedArea.d.ts.map +1 -0
- package/dts/chart/area/GradientArea.d.ts +30 -0
- package/dts/chart/area/GradientArea.d.ts.map +1 -0
- package/dts/chart/area/SolidArea.d.ts +8 -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 +208 -0
- package/dts/chart/axis/Axis.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 +4 -0
- package/dts/chart/axis/index.d.ts.map +1 -0
- package/dts/chart/bar/Bar.d.ts +91 -0
- package/dts/chart/bar/Bar.d.ts.map +1 -0
- package/dts/chart/bar/BarChart.d.ts +53 -0
- package/dts/chart/bar/BarChart.d.ts.map +1 -0
- package/dts/chart/bar/BarPlot.d.ts +29 -0
- package/dts/chart/bar/BarPlot.d.ts.map +1 -0
- package/dts/chart/bar/BarStack.d.ts +111 -0
- package/dts/chart/bar/BarStack.d.ts.map +1 -0
- package/dts/chart/bar/BarStackGroup.d.ts +35 -0
- package/dts/chart/bar/BarStackGroup.d.ts.map +1 -0
- package/dts/chart/bar/DefaultBar.d.ts +17 -0
- package/dts/chart/bar/DefaultBar.d.ts.map +1 -0
- package/dts/chart/bar/DefaultBarStack.d.ts +16 -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/index.d.ts +13 -0
- package/dts/chart/index.d.ts.map +1 -0
- package/dts/chart/line/DottedLine.d.ts +14 -0
- package/dts/chart/line/DottedLine.d.ts.map +1 -0
- package/dts/chart/line/GradientLine.d.ts +42 -0
- package/dts/chart/line/GradientLine.d.ts.map +1 -0
- package/dts/chart/line/Line.d.ts +80 -0
- package/dts/chart/line/Line.d.ts.map +1 -0
- package/dts/chart/line/LineChart.d.ts +59 -0
- package/dts/chart/line/LineChart.d.ts.map +1 -0
- package/dts/chart/line/ReferenceLine.d.ts +131 -0
- package/dts/chart/line/ReferenceLine.d.ts.map +1 -0
- package/dts/chart/line/SolidLine.d.ts +14 -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/scrubber/Scrubber.d.ts +149 -0
- package/dts/chart/scrubber/Scrubber.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberBeacon.d.ts +93 -0
- package/dts/chart/scrubber/ScrubberBeacon.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberBeaconLabel.d.ts +7 -0
- package/dts/chart/scrubber/ScrubberBeaconLabel.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberProvider.d.ts +17 -0
- package/dts/chart/scrubber/ScrubberProvider.d.ts.map +1 -0
- package/dts/chart/scrubber/index.d.ts +2 -0
- package/dts/chart/scrubber/index.d.ts.map +1 -0
- package/dts/chart/text/ChartText.d.ts +114 -0
- package/dts/chart/text/ChartText.d.ts.map +1 -0
- package/dts/chart/text/SmartChartTextGroup.d.ts +55 -0
- package/dts/chart/text/SmartChartTextGroup.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 +97 -0
- package/dts/chart/utils/chart.d.ts.map +1 -0
- package/dts/chart/utils/context.d.ts +95 -0
- package/dts/chart/utils/context.d.ts.map +1 -0
- package/dts/chart/utils/index.d.ts +8 -0
- package/dts/chart/utils/index.d.ts.map +1 -0
- package/dts/chart/utils/path.d.ts +107 -0
- package/dts/chart/utils/path.d.ts.map +1 -0
- package/dts/chart/utils/point.d.ts +75 -0
- package/dts/chart/utils/point.d.ts.map +1 -0
- package/dts/chart/utils/scale.d.ts +43 -0
- package/dts/chart/utils/scale.d.ts.map +1 -0
- package/dts/index.d.ts +3 -0
- package/dts/index.d.ts.map +1 -0
- package/dts/sparkline/Counter.d.ts +8 -0
- package/dts/sparkline/Counter.d.ts.map +1 -0
- package/dts/sparkline/Sparkline.d.ts +67 -0
- package/dts/sparkline/Sparkline.d.ts.map +1 -0
- package/dts/sparkline/SparklineArea.d.ts +15 -0
- package/dts/sparkline/SparklineArea.d.ts.map +1 -0
- package/dts/sparkline/SparklineAreaPattern.d.ts +14 -0
- package/dts/sparkline/SparklineAreaPattern.d.ts.map +1 -0
- package/dts/sparkline/SparklineGradient.d.ts +23 -0
- package/dts/sparkline/SparklineGradient.d.ts.map +1 -0
- package/dts/sparkline/SparklinePath.d.ts +12 -0
- package/dts/sparkline/SparklinePath.d.ts.map +1 -0
- package/dts/sparkline/__figma__/Sparkline.figma.d.ts +2 -0
- package/dts/sparkline/__figma__/Sparkline.figma.d.ts.map +1 -0
- package/dts/sparkline/generateSparklineWithId.d.ts +11 -0
- package/dts/sparkline/generateSparklineWithId.d.ts.map +1 -0
- package/dts/sparkline/index.d.ts +6 -0
- package/dts/sparkline/index.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/InnerSparklineInteractiveProvider.d.ts +13 -0
- package/dts/sparkline/sparkline-interactive/InnerSparklineInteractiveProvider.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts +199 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts +26 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts +5 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.d.ts +5 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts +8 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts +17 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts +25 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts +25 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts +25 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.d.ts +30 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubProvider.d.ts +18 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubProvider.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts +31 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/fade.d.ts +3 -0
- package/dts/sparkline/sparkline-interactive/fade.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts +13 -0
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts +112 -0
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts.map +1 -0
- package/esm/chart/CartesianChart.css +1 -0
- package/esm/chart/CartesianChart.js +258 -0
- package/esm/chart/ChartProvider.js +10 -0
- package/esm/chart/Path.js +89 -0
- package/esm/chart/PeriodSelector.css +1 -0
- package/esm/chart/PeriodSelector.js +126 -0
- package/esm/chart/Point.css +2 -0
- package/esm/chart/Point.js +171 -0
- package/esm/chart/area/Area.js +85 -0
- package/esm/chart/area/AreaChart.js +164 -0
- package/esm/chart/area/DottedArea.js +141 -0
- package/esm/chart/area/GradientArea.js +111 -0
- package/esm/chart/area/SolidArea.js +29 -0
- package/esm/chart/area/index.js +7 -0
- package/esm/chart/axis/Axis.js +46 -0
- package/esm/chart/axis/XAxis.css +2 -0
- package/esm/chart/axis/XAxis.js +195 -0
- package/esm/chart/axis/YAxis.css +2 -0
- package/esm/chart/axis/YAxis.js +183 -0
- package/esm/chart/axis/index.js +5 -0
- package/esm/chart/bar/Bar.js +59 -0
- package/esm/chart/bar/BarChart.js +147 -0
- package/esm/chart/bar/BarPlot.js +96 -0
- package/esm/chart/bar/BarStack.js +519 -0
- package/esm/chart/bar/BarStackGroup.js +96 -0
- package/esm/chart/bar/DefaultBar.js +64 -0
- package/esm/chart/bar/DefaultBarStack.js +60 -0
- package/esm/chart/bar/index.js +9 -0
- package/esm/chart/index.js +14 -0
- package/esm/chart/line/DottedLine.js +38 -0
- package/esm/chart/line/GradientLine.js +58 -0
- package/esm/chart/line/Line.js +159 -0
- package/esm/chart/line/LineChart.js +120 -0
- package/esm/chart/line/ReferenceLine.js +142 -0
- package/esm/chart/line/SolidLine.js +34 -0
- package/esm/chart/line/index.js +8 -0
- package/esm/chart/scrubber/Scrubber.js +483 -0
- package/esm/chart/scrubber/ScrubberBeacon.js +195 -0
- package/esm/chart/scrubber/ScrubberBeaconLabel.js +33 -0
- package/esm/chart/scrubber/ScrubberProvider.js +228 -0
- package/esm/chart/scrubber/index.js +2 -0
- package/esm/chart/text/ChartText.js +236 -0
- package/esm/chart/text/SmartChartTextGroup.js +226 -0
- package/esm/chart/text/index.js +4 -0
- package/esm/chart/utils/axis.js +593 -0
- package/esm/chart/utils/bar.js +24 -0
- package/esm/chart/utils/chart.js +229 -0
- package/esm/chart/utils/context.js +15 -0
- package/esm/chart/utils/index.js +9 -0
- package/esm/chart/utils/path.js +204 -0
- package/esm/chart/utils/point.js +118 -0
- package/esm/chart/utils/scale.js +48 -0
- package/esm/index.js +4 -0
- package/esm/sparkline/Counter.css +3 -0
- package/esm/sparkline/Counter.js +35 -0
- package/esm/sparkline/Sparkline.js +164 -0
- package/esm/sparkline/SparklineArea.js +18 -0
- package/esm/sparkline/SparklineAreaPattern.js +37 -0
- package/esm/sparkline/SparklineGradient.js +30 -0
- package/esm/sparkline/SparklinePath.js +19 -0
- package/esm/sparkline/__figma__/Sparkline.figma.js +24 -0
- package/esm/sparkline/generateSparklineWithId.js +7 -0
- package/esm/sparkline/index.js +5 -0
- package/esm/sparkline/sparkline-interactive/InnerSparklineInteractiveProvider.js +21 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractive.js +317 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.js +108 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.css +2 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.js +26 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.css +2 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.js +24 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.css +4 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.js +65 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.css +1 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.js +80 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePaths.js +56 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.js +70 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveProvider.js +45 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.css +5 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.js +199 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveScrubProvider.js +39 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.js +92 -0
- package/esm/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.js +89 -0
- package/esm/sparkline/sparkline-interactive/fade.css +2 -0
- package/esm/sparkline/sparkline-interactive/fade.js +14 -0
- package/esm/sparkline/sparkline-interactive/useSparklineInteractiveConstants.js +28 -0
- package/esm/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.js +225 -0
- package/esm/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.js +108 -0
- package/package.json +68 -6
- package/index.js +0 -1
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type {
|
|
3
|
+
SharedProps,
|
|
4
|
+
SparklineInteractiveHeaderSignVariant,
|
|
5
|
+
SparklineInteractiveHeaderVariant,
|
|
6
|
+
} from '@coinbase/cds-common/types';
|
|
7
|
+
export * from '@coinbase/cds-common/types/SparklineInteractiveHeaderBaseProps';
|
|
8
|
+
export type SparklineInteractiveSubHead = {
|
|
9
|
+
/**
|
|
10
|
+
* Free form percentage change
|
|
11
|
+
*/
|
|
12
|
+
percent: string;
|
|
13
|
+
/**
|
|
14
|
+
* Sign to denote the change in price
|
|
15
|
+
*/
|
|
16
|
+
sign: SparklineInteractiveHeaderSignVariant;
|
|
17
|
+
/**
|
|
18
|
+
* The variant to use for the price and percentage change
|
|
19
|
+
*/
|
|
20
|
+
variant: SparklineInteractiveHeaderVariant;
|
|
21
|
+
/**
|
|
22
|
+
* Show the dollar amount of price change
|
|
23
|
+
*/
|
|
24
|
+
priceChange?: string;
|
|
25
|
+
/**
|
|
26
|
+
* The accessoryText to show after the price and / or percentage change. An example is "All time"
|
|
27
|
+
*/
|
|
28
|
+
accessoryText?: string;
|
|
29
|
+
/**
|
|
30
|
+
* The accessibilityLabel to show for the price and / or percentage change. This should be localized
|
|
31
|
+
* @example
|
|
32
|
+
* // First, configure your i18n strings
|
|
33
|
+
* const messages = defineMessages({
|
|
34
|
+
* subHeadPrefix: {
|
|
35
|
+
* id: `${i18nKey}.subHeadPrefix`,
|
|
36
|
+
* defaultMessage: 'Price increase in the amount of',
|
|
37
|
+
* description: 'A prefix to make it clear which direction the price action was moving',
|
|
38
|
+
* }
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* // then provide the translated string the accessibilityLabel prop
|
|
42
|
+
* messages.subHeadPrefix
|
|
43
|
+
*/
|
|
44
|
+
accessibilityLabel?: string;
|
|
45
|
+
};
|
|
46
|
+
export type SparklineInteractiveHeaderValues = {
|
|
47
|
+
/**
|
|
48
|
+
* Describes what the Header represents e.g. Bitcoin Price
|
|
49
|
+
*/
|
|
50
|
+
label?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Main content of header, this is usually the price
|
|
53
|
+
*/
|
|
54
|
+
title?: React.ReactNode;
|
|
55
|
+
/**
|
|
56
|
+
* Provides additional information about the title, such as a price change
|
|
57
|
+
*/
|
|
58
|
+
subHead?: SparklineInteractiveSubHead;
|
|
59
|
+
};
|
|
60
|
+
export type SparklineInteractiveHeaderRef = {
|
|
61
|
+
update: (params: SparklineInteractiveHeaderValues) => void;
|
|
62
|
+
};
|
|
63
|
+
export type SparklineInteractiveHeaderProps = SharedProps & {
|
|
64
|
+
/**
|
|
65
|
+
* Default title, changing this prop has no effect once the default is rendered. If you use a ReactNode that is not a string, then you cannot use the text based label that supports updates.
|
|
66
|
+
*/
|
|
67
|
+
defaultTitle: React.ReactNode;
|
|
68
|
+
/**
|
|
69
|
+
* Default label, changing this prop has no effect once the default is rendered.
|
|
70
|
+
*/
|
|
71
|
+
defaultLabel?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Default SubHead, changing this prop has no effect once the default is rendered.
|
|
74
|
+
*/
|
|
75
|
+
defaultSubHead?: SparklineInteractiveSubHead;
|
|
76
|
+
/**
|
|
77
|
+
* Adds a label node that allows React components. If you use this node then you cannot use the text based label that supports updates.
|
|
78
|
+
*/
|
|
79
|
+
labelNode?: React.ReactNode;
|
|
80
|
+
/**
|
|
81
|
+
* Reduce the font size used for the header itself.
|
|
82
|
+
*/
|
|
83
|
+
compact?: boolean;
|
|
84
|
+
};
|
|
85
|
+
export declare const interpolateSubHeadText: (subHead: SparklineInteractiveSubHead) => string;
|
|
86
|
+
export declare const SparklineInteractiveHeader: React.MemoExoticComponent<
|
|
87
|
+
React.ForwardRefExoticComponent<
|
|
88
|
+
SharedProps & {
|
|
89
|
+
/**
|
|
90
|
+
* Default title, changing this prop has no effect once the default is rendered. If you use a ReactNode that is not a string, then you cannot use the text based label that supports updates.
|
|
91
|
+
*/
|
|
92
|
+
defaultTitle: React.ReactNode;
|
|
93
|
+
/**
|
|
94
|
+
* Default label, changing this prop has no effect once the default is rendered.
|
|
95
|
+
*/
|
|
96
|
+
defaultLabel?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Default SubHead, changing this prop has no effect once the default is rendered.
|
|
99
|
+
*/
|
|
100
|
+
defaultSubHead?: SparklineInteractiveSubHead;
|
|
101
|
+
/**
|
|
102
|
+
* Adds a label node that allows React components. If you use this node then you cannot use the text based label that supports updates.
|
|
103
|
+
*/
|
|
104
|
+
labelNode?: React.ReactNode;
|
|
105
|
+
/**
|
|
106
|
+
* Reduce the font size used for the header itself.
|
|
107
|
+
*/
|
|
108
|
+
compact?: boolean;
|
|
109
|
+
} & React.RefAttributes<SparklineInteractiveHeaderRef>
|
|
110
|
+
>
|
|
111
|
+
>;
|
|
112
|
+
//# sourceMappingURL=SparklineInteractiveHeader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SparklineInteractiveHeader.d.ts","sourceRoot":"","sources":["../../../src/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8E,MAAM,OAAO,CAAC;AAGnG,OAAO,KAAK,EACV,WAAW,EACX,qCAAqC,EACrC,iCAAiC,EAClC,MAAM,4BAA4B,CAAC;AAMpC,cAAc,gEAAgE,CAAC;AAQ/E,MAAM,MAAM,2BAA2B,GAAG;IACxC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,IAAI,EAAE,qCAAqC,CAAC;IAC5C;;OAEG;IACH,OAAO,EAAE,iCAAiC,CAAC;IAC3C;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;;;;;;;;;;OAcG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG;IAC7C;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACxB;;OAEG;IACH,OAAO,CAAC,EAAE,2BAA2B,CAAC;CACvC,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,MAAM,EAAE,CAAC,MAAM,EAAE,gCAAgC,KAAK,IAAI,CAAC;CAC5D,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG,WAAW,GAAG;IAC1D;;OAEG;IACH,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC;IAC9B;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,cAAc,CAAC,EAAE,2BAA2B,CAAC;IAC7C;;OAEG;IACH,SAAS,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC5B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,SAAS,2BAA2B,WAQ1E,CAAC;AA8KF,eAAO,MAAM,0BAA0B;IA5MrC;;OAEG;kBACW,KAAK,CAAC,SAAS;IAC7B;;OAEG;mBACY,MAAM;IACrB;;OAEG;qBACc,2BAA2B;IAC5C;;OAEG;gBACS,KAAK,CAAC,SAAS;IAC3B;;OAEG;cACO,OAAO;wDA6MlB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SparklineInteractiveHeader.figma.d.ts","sourceRoot":"","sources":["../../../../src/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.cds-focusStylesCss-f4oy7ru:focus{outline:none;}.cds-focusStylesCss-f4oy7ru:focus-visible{outline:2px solid var(--color-bgPrimary);outline-offset:2px;}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
const _excluded = ["series", "children", "animate", "xAxis", "yAxis", "inset", "enableScrubbing", "onScrubberPositionChange", "width", "height", "className", "style"];
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
8
|
+
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; }
|
|
9
|
+
import React, { forwardRef, memo, useCallback, useMemo, useRef } from 'react';
|
|
10
|
+
import { cx } from '@coinbase/cds-web';
|
|
11
|
+
import { useDimensions } from '@coinbase/cds-web/hooks/useDimensions';
|
|
12
|
+
import { Box } from '@coinbase/cds-web/layout';
|
|
13
|
+
import { ScrubberProvider } from './scrubber/ScrubberProvider';
|
|
14
|
+
import { CartesianChartProvider } from './ChartProvider';
|
|
15
|
+
import { defaultAxisId, defaultChartInset, getAxisConfig, getAxisDomain, getAxisRange, getAxisScale, getChartInset, getStackedSeriesData as calculateStackedSeriesData, useTotalAxisPadding } from './utils';
|
|
16
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
|
+
const focusStylesCss = "cds-focusStylesCss-f4oy7ru";
|
|
18
|
+
export const CartesianChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
19
|
+
let {
|
|
20
|
+
series,
|
|
21
|
+
children,
|
|
22
|
+
animate = true,
|
|
23
|
+
xAxis: xAxisConfigInput,
|
|
24
|
+
yAxis: yAxisConfigInput,
|
|
25
|
+
inset: insetInput,
|
|
26
|
+
enableScrubbing,
|
|
27
|
+
onScrubberPositionChange,
|
|
28
|
+
width = '100%',
|
|
29
|
+
height = '100%',
|
|
30
|
+
className,
|
|
31
|
+
style
|
|
32
|
+
} = _ref,
|
|
33
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
34
|
+
const {
|
|
35
|
+
observe,
|
|
36
|
+
width: chartWidth,
|
|
37
|
+
height: chartHeight
|
|
38
|
+
} = useDimensions();
|
|
39
|
+
const internalSvgRef = useRef(null);
|
|
40
|
+
const userInset = useMemo(() => {
|
|
41
|
+
return getChartInset(insetInput, defaultChartInset);
|
|
42
|
+
}, [insetInput]);
|
|
43
|
+
|
|
44
|
+
// Axis configs store the properties of each axis, such as id, scale type, domain limit, etc.
|
|
45
|
+
// We only support 1 x axis but allow for multiple y axes.
|
|
46
|
+
const xAxisConfig = useMemo(() => getAxisConfig('x', xAxisConfigInput)[0], [xAxisConfigInput]);
|
|
47
|
+
const yAxisConfig = useMemo(() => getAxisConfig('y', yAxisConfigInput), [yAxisConfigInput]);
|
|
48
|
+
const {
|
|
49
|
+
renderedAxes,
|
|
50
|
+
registerAxis,
|
|
51
|
+
unregisterAxis,
|
|
52
|
+
axisPadding
|
|
53
|
+
} = useTotalAxisPadding();
|
|
54
|
+
const chartRect = useMemo(() => {
|
|
55
|
+
if (chartWidth <= 0 || chartHeight <= 0) return {
|
|
56
|
+
x: 0,
|
|
57
|
+
y: 0,
|
|
58
|
+
width: 0,
|
|
59
|
+
height: 0
|
|
60
|
+
};
|
|
61
|
+
const totalInset = {
|
|
62
|
+
top: userInset.top + axisPadding.top,
|
|
63
|
+
right: userInset.right + axisPadding.right,
|
|
64
|
+
bottom: userInset.bottom + axisPadding.bottom,
|
|
65
|
+
left: userInset.left + axisPadding.left
|
|
66
|
+
};
|
|
67
|
+
const availableWidth = chartWidth - totalInset.left - totalInset.right;
|
|
68
|
+
const availableHeight = chartHeight - totalInset.top - totalInset.bottom;
|
|
69
|
+
return {
|
|
70
|
+
x: totalInset.left,
|
|
71
|
+
y: totalInset.top,
|
|
72
|
+
width: availableWidth > 0 ? availableWidth : 0,
|
|
73
|
+
height: availableHeight > 0 ? availableHeight : 0
|
|
74
|
+
};
|
|
75
|
+
}, [chartHeight, chartWidth, userInset, axisPadding]);
|
|
76
|
+
|
|
77
|
+
// Axes contain the config along with domain and range, which get calculated here.
|
|
78
|
+
const xAxis = useMemo(() => {
|
|
79
|
+
if (!chartRect || chartRect.width <= 0 || chartRect.height <= 0) return undefined;
|
|
80
|
+
const domain = getAxisDomain(xAxisConfig, series !== null && series !== void 0 ? series : [], 'x');
|
|
81
|
+
const range = getAxisRange(xAxisConfig, chartRect, 'x');
|
|
82
|
+
const axisConfig = {
|
|
83
|
+
scaleType: xAxisConfig.scaleType,
|
|
84
|
+
domain,
|
|
85
|
+
range,
|
|
86
|
+
data: xAxisConfig.data,
|
|
87
|
+
categoryPadding: xAxisConfig.categoryPadding,
|
|
88
|
+
domainLimit: xAxisConfig.domainLimit
|
|
89
|
+
};
|
|
90
|
+
return axisConfig;
|
|
91
|
+
}, [xAxisConfig, series, chartRect]);
|
|
92
|
+
const yAxes = useMemo(() => {
|
|
93
|
+
const axes = new Map();
|
|
94
|
+
if (!chartRect || chartRect.width <= 0 || chartRect.height <= 0) return axes;
|
|
95
|
+
yAxisConfig.forEach(axisParam => {
|
|
96
|
+
var _axisParam$id, _series$filter, _axisParam$domainLimi;
|
|
97
|
+
const axisId = (_axisParam$id = axisParam.id) !== null && _axisParam$id !== void 0 ? _axisParam$id : defaultAxisId;
|
|
98
|
+
|
|
99
|
+
// Get relevant series data
|
|
100
|
+
const relevantSeries = (_series$filter = series === null || series === void 0 ? void 0 : series.filter(s => {
|
|
101
|
+
var _s$yAxisId;
|
|
102
|
+
return ((_s$yAxisId = s.yAxisId) !== null && _s$yAxisId !== void 0 ? _s$yAxisId : defaultAxisId) === axisId;
|
|
103
|
+
})) !== null && _series$filter !== void 0 ? _series$filter : [];
|
|
104
|
+
|
|
105
|
+
// Calculate domain and range in one pass
|
|
106
|
+
const domain = getAxisDomain(axisParam, relevantSeries, 'y');
|
|
107
|
+
const range = getAxisRange(axisParam, chartRect, 'y');
|
|
108
|
+
axes.set(axisId, {
|
|
109
|
+
scaleType: axisParam.scaleType,
|
|
110
|
+
domain,
|
|
111
|
+
range,
|
|
112
|
+
data: axisParam.data,
|
|
113
|
+
categoryPadding: axisParam.categoryPadding,
|
|
114
|
+
domainLimit: (_axisParam$domainLimi = axisParam.domainLimit) !== null && _axisParam$domainLimi !== void 0 ? _axisParam$domainLimi : 'nice'
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
return axes;
|
|
118
|
+
}, [yAxisConfig, series, chartRect]);
|
|
119
|
+
|
|
120
|
+
// Scales are the functions that convert data values to visual positions.
|
|
121
|
+
// They are calculated here based on the above axes.
|
|
122
|
+
const xScale = useMemo(() => {
|
|
123
|
+
if (!chartRect || chartRect.width <= 0 || chartRect.height <= 0 || xAxis === undefined) return undefined;
|
|
124
|
+
return getAxisScale({
|
|
125
|
+
config: xAxis,
|
|
126
|
+
type: 'x',
|
|
127
|
+
range: xAxis.range,
|
|
128
|
+
dataDomain: xAxis.domain
|
|
129
|
+
});
|
|
130
|
+
}, [chartRect, xAxis]);
|
|
131
|
+
const yScales = useMemo(() => {
|
|
132
|
+
const scales = new Map();
|
|
133
|
+
if (!chartRect || chartRect.width <= 0 || chartRect.height <= 0) return scales;
|
|
134
|
+
yAxes.forEach((axisConfig, axisId) => {
|
|
135
|
+
const scale = getAxisScale({
|
|
136
|
+
config: axisConfig,
|
|
137
|
+
type: 'y',
|
|
138
|
+
range: axisConfig.range,
|
|
139
|
+
dataDomain: axisConfig.domain
|
|
140
|
+
});
|
|
141
|
+
if (scale) {
|
|
142
|
+
scales.set(axisId, scale);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
return scales;
|
|
146
|
+
}, [chartRect, yAxes]);
|
|
147
|
+
const getXAxis = useCallback(() => xAxis, [xAxis]);
|
|
148
|
+
const getYAxis = useCallback(id => yAxes.get(id !== null && id !== void 0 ? id : defaultAxisId), [yAxes]);
|
|
149
|
+
const getXScale = useCallback(() => xScale, [xScale]);
|
|
150
|
+
const getYScale = useCallback(id => yScales.get(id !== null && id !== void 0 ? id : defaultAxisId), [yScales]);
|
|
151
|
+
const getSeries = useCallback(seriesId => series === null || series === void 0 ? void 0 : series.find(s => s.id === seriesId), [series]);
|
|
152
|
+
const stackedDataMap = useMemo(() => {
|
|
153
|
+
if (!series) return new Map();
|
|
154
|
+
return calculateStackedSeriesData(series);
|
|
155
|
+
}, [series]);
|
|
156
|
+
const getStackedSeriesData = useCallback(seriesId => {
|
|
157
|
+
if (!seriesId) return undefined;
|
|
158
|
+
return stackedDataMap.get(seriesId);
|
|
159
|
+
}, [stackedDataMap]);
|
|
160
|
+
const getAxisBounds = useCallback(axisId => {
|
|
161
|
+
const axis = renderedAxes.get(axisId);
|
|
162
|
+
if (!axis || !chartRect) return;
|
|
163
|
+
const axesAtPosition = Array.from(renderedAxes.values()).filter(a => a.position === axis.position).sort((a, b) => a.id.localeCompare(b.id));
|
|
164
|
+
const axisIndex = axesAtPosition.findIndex(a => a.id === axisId);
|
|
165
|
+
if (axisIndex === -1) return;
|
|
166
|
+
|
|
167
|
+
// Calculate offset from previous axes at the same position
|
|
168
|
+
const offsetFromPreviousAxes = axesAtPosition.slice(0, axisIndex).reduce((sum, a) => sum + a.size, 0);
|
|
169
|
+
if (axis.position === 'top') {
|
|
170
|
+
// Position above the chart rect, accounting for user inset
|
|
171
|
+
const startY = userInset.top + offsetFromPreviousAxes;
|
|
172
|
+
return {
|
|
173
|
+
x: chartRect.x,
|
|
174
|
+
y: startY,
|
|
175
|
+
width: chartRect.width,
|
|
176
|
+
height: axis.size
|
|
177
|
+
};
|
|
178
|
+
} else if (axis.position === 'bottom') {
|
|
179
|
+
// Position below the chart rect, accounting for user inset
|
|
180
|
+
const startY = chartRect.y + chartRect.height + offsetFromPreviousAxes;
|
|
181
|
+
return {
|
|
182
|
+
x: chartRect.x,
|
|
183
|
+
y: startY,
|
|
184
|
+
width: chartRect.width,
|
|
185
|
+
height: axis.size
|
|
186
|
+
};
|
|
187
|
+
} else if (axis.position === 'left') {
|
|
188
|
+
// Position to the left of the chart rect, accounting for user inset
|
|
189
|
+
const startX = userInset.left + offsetFromPreviousAxes;
|
|
190
|
+
return {
|
|
191
|
+
x: startX,
|
|
192
|
+
y: chartRect.y,
|
|
193
|
+
width: axis.size,
|
|
194
|
+
height: chartRect.height
|
|
195
|
+
};
|
|
196
|
+
} else {
|
|
197
|
+
// right - position to the right of the chart rect, accounting for user inset
|
|
198
|
+
const startX = chartRect.x + chartRect.width + offsetFromPreviousAxes;
|
|
199
|
+
return {
|
|
200
|
+
x: startX,
|
|
201
|
+
y: chartRect.y,
|
|
202
|
+
width: axis.size,
|
|
203
|
+
height: chartRect.height
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
}, [renderedAxes, chartRect, userInset]);
|
|
207
|
+
const contextValue = useMemo(() => ({
|
|
208
|
+
series: series !== null && series !== void 0 ? series : [],
|
|
209
|
+
getSeries,
|
|
210
|
+
getSeriesData: getStackedSeriesData,
|
|
211
|
+
animate,
|
|
212
|
+
width: chartWidth,
|
|
213
|
+
height: chartHeight,
|
|
214
|
+
getXAxis,
|
|
215
|
+
getYAxis,
|
|
216
|
+
getXScale,
|
|
217
|
+
getYScale,
|
|
218
|
+
drawingArea: chartRect,
|
|
219
|
+
registerAxis,
|
|
220
|
+
unregisterAxis,
|
|
221
|
+
getAxisBounds
|
|
222
|
+
}), [series, getSeries, getStackedSeriesData, animate, chartWidth, chartHeight, getXAxis, getYAxis, getXScale, getYScale, chartRect, registerAxis, unregisterAxis, getAxisBounds]);
|
|
223
|
+
return /*#__PURE__*/_jsx(Box, _objectSpread(_objectSpread({
|
|
224
|
+
ref: node => {
|
|
225
|
+
// Handle the observe ref, internal ref, and forwarded ref
|
|
226
|
+
observe(node);
|
|
227
|
+
if (internalSvgRef.current !== node) {
|
|
228
|
+
internalSvgRef.current = node;
|
|
229
|
+
}
|
|
230
|
+
if (ref) {
|
|
231
|
+
if (typeof ref === 'function') {
|
|
232
|
+
ref(node);
|
|
233
|
+
} else {
|
|
234
|
+
ref.current = node;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
"aria-live": "polite",
|
|
239
|
+
as: "svg",
|
|
240
|
+
className: cx(enableScrubbing && focusStylesCss, className),
|
|
241
|
+
height: height,
|
|
242
|
+
role: "figure",
|
|
243
|
+
style: style,
|
|
244
|
+
tabIndex: enableScrubbing ? 0 : undefined,
|
|
245
|
+
width: width
|
|
246
|
+
}, props), {}, {
|
|
247
|
+
children: /*#__PURE__*/_jsx(CartesianChartProvider, {
|
|
248
|
+
value: contextValue,
|
|
249
|
+
children: /*#__PURE__*/_jsx(ScrubberProvider, {
|
|
250
|
+
enableScrubbing: !!enableScrubbing,
|
|
251
|
+
onScrubberPositionChange: onScrubberPositionChange,
|
|
252
|
+
svgRef: internalSvgRef,
|
|
253
|
+
children: children
|
|
254
|
+
})
|
|
255
|
+
})
|
|
256
|
+
}));
|
|
257
|
+
}));
|
|
258
|
+
import "./CartesianChart.css";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
const CartesianChartContext = /*#__PURE__*/createContext(undefined);
|
|
3
|
+
export const useCartesianChartContext = () => {
|
|
4
|
+
const context = useContext(CartesianChartContext);
|
|
5
|
+
if (!context) {
|
|
6
|
+
throw new Error('useCartesianChartContext must be used within a CartesianChart component. See http://cds.coinbase.com/components/graphs/CartesianChart.');
|
|
7
|
+
}
|
|
8
|
+
return context;
|
|
9
|
+
};
|
|
10
|
+
export const CartesianChartProvider = CartesianChartContext.Provider;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
const _excluded = ["animate", "clipRect", "clipOffset", "d"];
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
8
|
+
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; }
|
|
9
|
+
import 'd3-transition';
|
|
10
|
+
import { memo, useCallback, useEffect, useId, useRef } from 'react';
|
|
11
|
+
import { useValueChanges } from '@coinbase/cds-common/hooks/useValueChanges';
|
|
12
|
+
import { interpolatePath } from 'd3-interpolate-path';
|
|
13
|
+
import { select } from 'd3-selection';
|
|
14
|
+
import { m as motion } from 'framer-motion';
|
|
15
|
+
import { useCartesianChartContext } from './ChartProvider';
|
|
16
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
+
export const Path = /*#__PURE__*/memo(_ref => {
|
|
18
|
+
let {
|
|
19
|
+
animate: animateProp,
|
|
20
|
+
clipRect,
|
|
21
|
+
clipOffset = 0,
|
|
22
|
+
d = ''
|
|
23
|
+
} = _ref,
|
|
24
|
+
pathProps = _objectWithoutProperties(_ref, _excluded);
|
|
25
|
+
const pathRef = useRef(null);
|
|
26
|
+
const clipPathId = useId();
|
|
27
|
+
const context = useCartesianChartContext();
|
|
28
|
+
const rect = clipRect !== null && clipRect !== void 0 ? clipRect : context.drawingArea;
|
|
29
|
+
const animate = animateProp !== null && animateProp !== void 0 ? animateProp : context.animate;
|
|
30
|
+
const {
|
|
31
|
+
previousValue: previousPath,
|
|
32
|
+
newValue: newPath,
|
|
33
|
+
hasChanged,
|
|
34
|
+
addPreviousValue
|
|
35
|
+
} = useValueChanges(d);
|
|
36
|
+
const morphPath = useCallback(() => {
|
|
37
|
+
if (!pathRef.current || !newPath || !previousPath) return;
|
|
38
|
+
select(pathRef.current).transition().duration(300).attrTween('d', function tween() {
|
|
39
|
+
return interpolatePath(previousPath, newPath);
|
|
40
|
+
});
|
|
41
|
+
}, [previousPath, newPath]);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
addPreviousValue(newPath);
|
|
44
|
+
if (animate && hasChanged && previousPath) {
|
|
45
|
+
morphPath();
|
|
46
|
+
}
|
|
47
|
+
}, [addPreviousValue, newPath, animate, hasChanged, previousPath, morphPath]);
|
|
48
|
+
|
|
49
|
+
// The clip offset provides extra padding to prevent path from being cut off
|
|
50
|
+
// Area charts typically use offset=0 for exact clipping, while lines use offset=2 for breathing room
|
|
51
|
+
const totalOffset = clipOffset * 2; // Applied on both sides
|
|
52
|
+
|
|
53
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
54
|
+
children: [/*#__PURE__*/_jsx("defs", {
|
|
55
|
+
children: /*#__PURE__*/_jsx("clipPath", {
|
|
56
|
+
id: clipPathId,
|
|
57
|
+
children: !animate ? /*#__PURE__*/_jsx("rect", {
|
|
58
|
+
height: rect.height + totalOffset,
|
|
59
|
+
width: rect.width + totalOffset,
|
|
60
|
+
x: rect.x - clipOffset,
|
|
61
|
+
y: rect.y - clipOffset
|
|
62
|
+
}) : /*#__PURE__*/_jsx(motion.rect, {
|
|
63
|
+
animate: "visible",
|
|
64
|
+
height: rect.height + totalOffset,
|
|
65
|
+
initial: "hidden",
|
|
66
|
+
variants: {
|
|
67
|
+
hidden: {
|
|
68
|
+
width: 0
|
|
69
|
+
},
|
|
70
|
+
visible: {
|
|
71
|
+
width: rect.width + totalOffset,
|
|
72
|
+
transition: {
|
|
73
|
+
type: 'spring',
|
|
74
|
+
duration: 1,
|
|
75
|
+
bounce: 0
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
x: rect.x - clipOffset,
|
|
80
|
+
y: rect.y - clipOffset
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
}), /*#__PURE__*/_jsx("path", _objectSpread({
|
|
84
|
+
ref: pathRef,
|
|
85
|
+
clipPath: "url(#".concat(clipPathId, ")"),
|
|
86
|
+
d: d
|
|
87
|
+
}, pathProps))]
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.cds-dotBaseCss-dfbcvh4{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;width:var(--space-1);height:var(--space-1);background:currentColor;border-radius:1000px;margin-inline-end:var(--space-0_75);}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
const _excluded = ["as", "color", "label", "display", "alignItems", "font", "hideDot", "disablePulse"],
|
|
2
|
+
_excluded2 = ["background", "activeBackground", "width", "justifyContent", "TabComponent", "TabsActiveIndicatorComponent"];
|
|
3
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
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
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
8
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
9
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
10
|
+
import React, { forwardRef, memo, useMemo } from 'react';
|
|
11
|
+
import { Box } from '@coinbase/cds-web/layout';
|
|
12
|
+
import { SegmentedTabs, tabsTransitionConfig } from '@coinbase/cds-web/tabs';
|
|
13
|
+
import { SegmentedTab } from '@coinbase/cds-web/tabs/SegmentedTab';
|
|
14
|
+
import { Text } from '@coinbase/cds-web/typography';
|
|
15
|
+
import { m as motion } from 'framer-motion';
|
|
16
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
+
const MotionBox = motion(Box);
|
|
18
|
+
const pulseTransitionConfig = {
|
|
19
|
+
duration: 2,
|
|
20
|
+
repeat: Infinity,
|
|
21
|
+
ease: 'easeInOut'
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// Animated active indicator to support smooth transition of background color
|
|
25
|
+
export const PeriodSelectorActiveIndicator = /*#__PURE__*/memo(_ref => {
|
|
26
|
+
let {
|
|
27
|
+
activeTabRect,
|
|
28
|
+
background = 'bgPrimaryWash',
|
|
29
|
+
position = 'absolute',
|
|
30
|
+
borderRadius = 1000,
|
|
31
|
+
style
|
|
32
|
+
} = _ref;
|
|
33
|
+
const {
|
|
34
|
+
width,
|
|
35
|
+
height,
|
|
36
|
+
x
|
|
37
|
+
} = activeTabRect;
|
|
38
|
+
const activeAnimation = useMemo(() => ({
|
|
39
|
+
width,
|
|
40
|
+
x
|
|
41
|
+
}), [width, x]);
|
|
42
|
+
if (!width) return null;
|
|
43
|
+
return /*#__PURE__*/_jsx(MotionBox, {
|
|
44
|
+
animate: activeAnimation,
|
|
45
|
+
borderRadius: borderRadius,
|
|
46
|
+
"data-testid": "period-selector-active-indicator",
|
|
47
|
+
height: height,
|
|
48
|
+
initial: false,
|
|
49
|
+
position: position,
|
|
50
|
+
role: "none",
|
|
51
|
+
style: _objectSpread({
|
|
52
|
+
backgroundColor: "var(--color-".concat(background, ")"),
|
|
53
|
+
transition: 'background-color 0.2s ease'
|
|
54
|
+
}, style),
|
|
55
|
+
transition: tabsTransitionConfig
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
export const liveTabLabelDefaultElement = 'span';
|
|
59
|
+
// is this bad to use var(--space-1) for height and width?
|
|
60
|
+
const dotBaseCss = "cds-dotBaseCss-dfbcvh4";
|
|
61
|
+
export const LiveTabLabel = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref2, ref) => {
|
|
62
|
+
let {
|
|
63
|
+
as,
|
|
64
|
+
color = 'fgNegative',
|
|
65
|
+
label = 'LIVE',
|
|
66
|
+
display = 'inline-flex',
|
|
67
|
+
alignItems = 'center',
|
|
68
|
+
font = 'label1',
|
|
69
|
+
hideDot,
|
|
70
|
+
disablePulse
|
|
71
|
+
} = _ref2,
|
|
72
|
+
props = _objectWithoutProperties(_ref2, _excluded);
|
|
73
|
+
const Component = as !== null && as !== void 0 ? as : liveTabLabelDefaultElement;
|
|
74
|
+
const pulseAnimation = !disablePulse ? {
|
|
75
|
+
opacity: [1, 0, 1],
|
|
76
|
+
transition: pulseTransitionConfig
|
|
77
|
+
} : undefined;
|
|
78
|
+
return /*#__PURE__*/_jsxs(Text, _objectSpread(_objectSpread({
|
|
79
|
+
ref: ref,
|
|
80
|
+
alignItems: alignItems,
|
|
81
|
+
as: Component,
|
|
82
|
+
color: color,
|
|
83
|
+
display: display,
|
|
84
|
+
font: font
|
|
85
|
+
}, props), {}, {
|
|
86
|
+
children: [!hideDot && /*#__PURE__*/_jsx(motion.span, {
|
|
87
|
+
animate: !disablePulse && pulseAnimation,
|
|
88
|
+
className: dotBaseCss,
|
|
89
|
+
initial: {
|
|
90
|
+
opacity: 1
|
|
91
|
+
}
|
|
92
|
+
}), label]
|
|
93
|
+
}));
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
// Custom tab component with primary color for active state
|
|
97
|
+
const PeriodSelectorTab = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((props, ref) => /*#__PURE__*/_jsx(SegmentedTab, _objectSpread({
|
|
98
|
+
ref: ref,
|
|
99
|
+
activeColor: "fgPrimary",
|
|
100
|
+
font: "label1"
|
|
101
|
+
}, props))));
|
|
102
|
+
/**
|
|
103
|
+
* PeriodSelector is a specialized version of SegmentedTabs optimized for chart period selection.
|
|
104
|
+
* It provides transparent background, primary wash active state, and full-width layout by default.
|
|
105
|
+
*/
|
|
106
|
+
export const PeriodSelector = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref3, ref) => {
|
|
107
|
+
let {
|
|
108
|
+
background = 'transparent',
|
|
109
|
+
activeBackground = 'bgPrimaryWash',
|
|
110
|
+
width = '100%',
|
|
111
|
+
justifyContent = 'space-between',
|
|
112
|
+
TabComponent = PeriodSelectorTab,
|
|
113
|
+
TabsActiveIndicatorComponent = PeriodSelectorActiveIndicator
|
|
114
|
+
} = _ref3,
|
|
115
|
+
props = _objectWithoutProperties(_ref3, _excluded2);
|
|
116
|
+
return /*#__PURE__*/_jsx(SegmentedTabs, _objectSpread({
|
|
117
|
+
ref: ref,
|
|
118
|
+
TabComponent: TabComponent,
|
|
119
|
+
TabsActiveIndicatorComponent: TabsActiveIndicatorComponent,
|
|
120
|
+
activeBackground: activeBackground,
|
|
121
|
+
background: background,
|
|
122
|
+
justifyContent: justifyContent,
|
|
123
|
+
width: width
|
|
124
|
+
}, props));
|
|
125
|
+
}));
|
|
126
|
+
import "./PeriodSelector.css";
|