@coinbase/cds-mobile-visualization 0.0.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dts/index.d.ts +2 -0
- package/dts/index.d.ts.map +1 -0
- package/dts/sparkline/Counter.d.ts +3 -0
- package/dts/sparkline/Counter.d.ts.map +1 -0
- package/dts/sparkline/Sparkline.d.ts +22 -0
- package/dts/sparkline/Sparkline.d.ts.map +1 -0
- package/dts/sparkline/SparklineArea.d.ts +8 -0
- package/dts/sparkline/SparklineArea.d.ts.map +1 -0
- package/dts/sparkline/SparklineAreaPattern.d.ts +6 -0
- package/dts/sparkline/SparklineAreaPattern.d.ts.map +1 -0
- package/dts/sparkline/SparklineGradient.d.ts +12 -0
- package/dts/sparkline/SparklineGradient.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/__stories__/Sparkline.stories.d.ts +3 -0
- package/dts/sparkline/__stories__/Sparkline.stories.d.ts.map +1 -0
- package/dts/sparkline/__stories__/SparklineGradient.stories.d.ts +3 -0
- package/dts/sparkline/__stories__/SparklineGradient.stories.d.ts.map +1 -0
- package/dts/sparkline/generateSparklineWithId.d.ts +5 -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/SparklineAccessibleView.d.ts +18 -0
- package/dts/sparkline/sparkline-interactive/SparklineAccessibleView.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts +162 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts +12 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts +17 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.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 +12 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMinMax.d.ts +9 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMinMax.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePanGestureHandler.d.ts +14 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePanGestureHandler.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts +11 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts +20 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts +33 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts +23 -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/__stories__/SparklineInteractive.stories.d.ts +3 -0
- package/dts/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractive.test.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractive.test.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveHoverDate.test.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveHoverDate.test.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePanGestureHandler.test.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePanGestureHandler.test.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePeriodSelector.test.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePeriodSelector.test.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveTimeseriesPaths.test.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveTimeseriesPaths.test.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/__tests__/useMinMaxTransform.test.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive/__tests__/useMinMaxTransform.test.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.d.ts +9 -0
- package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.test.disable.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.test.disable.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/useMinMaxTransform.d.ts +11 -0
- package/dts/sparkline/sparkline-interactive/useMinMaxTransform.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/useOpacityAnimation.d.ts +3 -0
- package/dts/sparkline/sparkline-interactive/useOpacityAnimation.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts +22 -0
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveLineStyles.d.ts +31 -0
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveLineStyles.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts +110 -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/dts/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.d.ts +4 -0
- package/dts/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive-header/__tests__/SparklineInteractiveHeader.test.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive-header/__tests__/SparklineInteractiveHeader.test.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive-header/__tests__/useSparklineInteractiveHeaderStyles.test.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive-header/__tests__/useSparklineInteractiveHeaderStyles.test.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive-header/useSparklineInteractiveHeaderStyles.d.ts +26 -0
- package/dts/sparkline/sparkline-interactive-header/useSparklineInteractiveHeaderStyles.d.ts.map +1 -0
- package/esm/index.js +1 -0
- package/esm/sparkline/Counter.js +45 -0
- package/esm/sparkline/Sparkline.js +51 -0
- package/esm/sparkline/SparklineArea.js +14 -0
- package/esm/sparkline/SparklineAreaPattern.js +36 -0
- package/esm/sparkline/SparklineGradient.js +72 -0
- package/esm/sparkline/__figma__/Sparkline.figma.js +22 -0
- package/esm/sparkline/__stories__/Sparkline.stories.js +120 -0
- package/esm/sparkline/__stories__/SparklineGradient.stories.js +123 -0
- package/esm/sparkline/generateSparklineWithId.js +6 -0
- package/esm/sparkline/index.js +5 -0
- package/esm/sparkline/sparkline-interactive/SparklineAccessibleView.js +75 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractive.js +303 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.js +113 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.js +131 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.js +99 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.js +82 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveMinMax.js +103 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePanGestureHandler.js +104 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePaths.js +53 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.js +124 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveProvider.js +80 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.js +109 -0
- package/esm/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.js +85 -0
- package/esm/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.js +474 -0
- package/esm/sparkline/sparkline-interactive/useInterruptiblePathAnimation.js +58 -0
- package/esm/sparkline/sparkline-interactive/useInterruptiblePathAnimation.test.disable.js +37 -0
- package/esm/sparkline/sparkline-interactive/useMinMaxTransform.js +56 -0
- package/esm/sparkline/sparkline-interactive/useOpacityAnimation.js +23 -0
- package/esm/sparkline/sparkline-interactive/useSparklineInteractiveConstants.js +47 -0
- package/esm/sparkline/sparkline-interactive/useSparklineInteractiveLineStyles.js +34 -0
- package/esm/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.js +233 -0
- package/esm/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.js +104 -0
- package/esm/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.js +555 -0
- package/esm/sparkline/sparkline-interactive-header/useSparklineInteractiveHeaderStyles.js +117 -0
- package/package.json +64 -5
- package/index.js +0 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
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); }
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { borderWidth, lineDashArray, lineOpacity } from '@coinbase/cds-common/tokens/sparkline';
|
|
4
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
5
|
+
const staticLineProps = {
|
|
6
|
+
x1: 0,
|
|
7
|
+
x2: 0,
|
|
8
|
+
y1: 0,
|
|
9
|
+
y2: 0,
|
|
10
|
+
strokeDasharray: lineDashArray
|
|
11
|
+
};
|
|
12
|
+
export function useSparklineInteractiveLineStyles() {
|
|
13
|
+
const theme = useTheme();
|
|
14
|
+
return useMemo(() => {
|
|
15
|
+
const chartLineSize = theme.space[0.5];
|
|
16
|
+
return {
|
|
17
|
+
dotStyle: [{
|
|
18
|
+
backgroundColor: theme.color.fgMuted
|
|
19
|
+
}, {
|
|
20
|
+
position: 'absolute',
|
|
21
|
+
top: -chartLineSize / 2,
|
|
22
|
+
left: -chartLineSize / 2,
|
|
23
|
+
height: chartLineSize,
|
|
24
|
+
width: chartLineSize,
|
|
25
|
+
borderRadius: chartLineSize / 2,
|
|
26
|
+
opacity: lineOpacity
|
|
27
|
+
}],
|
|
28
|
+
lineProps: _extends({}, staticLineProps, {
|
|
29
|
+
strokeWidth: borderWidth,
|
|
30
|
+
stroke: theme.color.fgMuted
|
|
31
|
+
})
|
|
32
|
+
};
|
|
33
|
+
}, [theme.color.fgMuted, theme.space]);
|
|
34
|
+
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
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); }
|
|
2
|
+
import React, { forwardRef, memo, useCallback, useImperativeHandle, useRef } from 'react';
|
|
3
|
+
import { TextInput, View } from 'react-native';
|
|
4
|
+
import { subheadIconSignMap } from '@coinbase/cds-common/tokens/sparkline';
|
|
5
|
+
import { HStack, VStack } from '@coinbase/cds-mobile/layout';
|
|
6
|
+
import { useSparklineInteractiveHeaderStyles } from './useSparklineInteractiveHeaderStyles';
|
|
7
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
8
|
+
export * from '@coinbase/cds-common/types/SparklineInteractiveHeaderBaseProps';
|
|
9
|
+
export const interpolateSubHeadText = subHead => {
|
|
10
|
+
if (subHead.priceChange && subHead.percent) {
|
|
11
|
+
return subHead.priceChange + " (" + subHead.percent + ")";
|
|
12
|
+
}
|
|
13
|
+
if (subHead.priceChange) {
|
|
14
|
+
return subHead.priceChange;
|
|
15
|
+
}
|
|
16
|
+
return '';
|
|
17
|
+
};
|
|
18
|
+
const Trailing = _ref => {
|
|
19
|
+
let {
|
|
20
|
+
children
|
|
21
|
+
} = _ref;
|
|
22
|
+
if (children) {
|
|
23
|
+
return /*#__PURE__*/_jsx(VStack, {
|
|
24
|
+
alignItems: "center",
|
|
25
|
+
flexShrink: 0,
|
|
26
|
+
justifyContent: "center",
|
|
27
|
+
paddingStart: 2,
|
|
28
|
+
children: children
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
};
|
|
33
|
+
const SparklineInteractiveHeaderStable = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref2, forwardedRef) => {
|
|
34
|
+
let {
|
|
35
|
+
defaultLabel,
|
|
36
|
+
defaultTitle,
|
|
37
|
+
defaultSubHead,
|
|
38
|
+
testID,
|
|
39
|
+
trailing,
|
|
40
|
+
labelNode
|
|
41
|
+
} = _ref2;
|
|
42
|
+
const labelRef = useRef(null);
|
|
43
|
+
const titleRef = useRef(null);
|
|
44
|
+
const subHeadRef = useRef(null);
|
|
45
|
+
const subHeadIconRef = useRef(null);
|
|
46
|
+
const subHeadAccessoryRef = useRef(null);
|
|
47
|
+
const valuesRef = useRef({
|
|
48
|
+
title: defaultTitle,
|
|
49
|
+
label: defaultLabel,
|
|
50
|
+
subHead: defaultSubHead
|
|
51
|
+
});
|
|
52
|
+
const styles = useSparklineInteractiveHeaderStyles();
|
|
53
|
+
const updateLabel = useCallback(label => {
|
|
54
|
+
var _valuesRef$current;
|
|
55
|
+
const prevLabel = (_valuesRef$current = valuesRef.current) == null ? void 0 : _valuesRef$current.label;
|
|
56
|
+
if (prevLabel !== label) {
|
|
57
|
+
var _labelRef$current;
|
|
58
|
+
// BAD: We only disabled this lint rule to enable eslint upgrade after this component was implemented. These apis should never be used.
|
|
59
|
+
// Usage in this component are known making this a high risk component. Contact team for more information.
|
|
60
|
+
|
|
61
|
+
(_labelRef$current = labelRef.current) == null || _labelRef$current.setNativeProps({
|
|
62
|
+
text: label
|
|
63
|
+
});
|
|
64
|
+
valuesRef.current = _extends({}, valuesRef.current, {
|
|
65
|
+
label
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}, []);
|
|
69
|
+
const updateTitle = useCallback(title => {
|
|
70
|
+
var _valuesRef$current2;
|
|
71
|
+
const prevTitle = (_valuesRef$current2 = valuesRef.current) == null ? void 0 : _valuesRef$current2.title;
|
|
72
|
+
if (prevTitle !== title && typeof title === 'string') {
|
|
73
|
+
var _titleRef$current;
|
|
74
|
+
// BAD: We only disabled this lint rule to enable eslint upgrade after this component was implemented. These apis should never be used.
|
|
75
|
+
// Usage in this component are known making this a high risk component. Contact team for more information.
|
|
76
|
+
|
|
77
|
+
(_titleRef$current = titleRef.current) == null || _titleRef$current.setNativeProps({
|
|
78
|
+
text: title,
|
|
79
|
+
style: styles.title(title)
|
|
80
|
+
});
|
|
81
|
+
valuesRef.current = _extends({}, valuesRef.current, {
|
|
82
|
+
title
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}, [styles]);
|
|
86
|
+
const updateSubHead = useCallback(subHead => {
|
|
87
|
+
var _valuesRef$current3;
|
|
88
|
+
const prevSubHead = (_valuesRef$current3 = valuesRef.current) == null ? void 0 : _valuesRef$current3.subHead;
|
|
89
|
+
if (prevSubHead !== subHead) {
|
|
90
|
+
var _subHeadIconRef$curre, _subHeadRef$current, _subHeadAccessoryRef$, _subHead$accessoryTex;
|
|
91
|
+
// BAD: We only disabled this lint rule to enable eslint upgrade after this component was implemented. These apis should never be used.
|
|
92
|
+
// Usage in this component are known making this a high risk component. Contact team for more information.
|
|
93
|
+
|
|
94
|
+
(_subHeadIconRef$curre = subHeadIconRef.current) == null || _subHeadIconRef$curre.setNativeProps({
|
|
95
|
+
text: subheadIconSignMap[subHead.sign],
|
|
96
|
+
style: styles.subHeadIcon(subHead.variant)
|
|
97
|
+
});
|
|
98
|
+
// BAD: We only disabled this lint rule to enable eslint upgrade after this component was implemented. These apis should never be used.
|
|
99
|
+
// Usage in this component are known making this a high risk component. Contact team for more information.
|
|
100
|
+
|
|
101
|
+
(_subHeadRef$current = subHeadRef.current) == null || _subHeadRef$current.setNativeProps({
|
|
102
|
+
text: interpolateSubHeadText(subHead),
|
|
103
|
+
style: styles.subHead(subHead.variant, subHead.accessoryText === undefined)
|
|
104
|
+
});
|
|
105
|
+
// BAD: We only disabled this lint rule to enable eslint upgrade after this component was implemented. These apis should never be used.
|
|
106
|
+
// Usage in this component are known making this a high risk component. Contact team for more information.
|
|
107
|
+
|
|
108
|
+
(_subHeadAccessoryRef$ = subHeadAccessoryRef.current) == null || _subHeadAccessoryRef$.setNativeProps({
|
|
109
|
+
text: (_subHead$accessoryTex = subHead.accessoryText) != null ? _subHead$accessoryTex : '',
|
|
110
|
+
style: styles.subHeadAccessory()
|
|
111
|
+
});
|
|
112
|
+
valuesRef.current = _extends({}, valuesRef.current, {
|
|
113
|
+
subHead
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}, [styles]);
|
|
117
|
+
|
|
118
|
+
// update is triggered from a parent component.
|
|
119
|
+
// We track the values of each input in a valuesRef object
|
|
120
|
+
// so that we can avoid updating unnecessarily if previous
|
|
121
|
+
// value is the same as the new value
|
|
122
|
+
const update = useCallback(_ref3 => {
|
|
123
|
+
let {
|
|
124
|
+
label,
|
|
125
|
+
title,
|
|
126
|
+
subHead
|
|
127
|
+
} = _ref3;
|
|
128
|
+
if (label) {
|
|
129
|
+
updateLabel(label);
|
|
130
|
+
}
|
|
131
|
+
if (title) {
|
|
132
|
+
updateTitle(title);
|
|
133
|
+
}
|
|
134
|
+
if (subHead) {
|
|
135
|
+
updateSubHead(subHead);
|
|
136
|
+
}
|
|
137
|
+
}, [updateLabel, updateSubHead, updateTitle]);
|
|
138
|
+
useImperativeHandle(forwardedRef, () => {
|
|
139
|
+
return {
|
|
140
|
+
update
|
|
141
|
+
};
|
|
142
|
+
}, [update]);
|
|
143
|
+
const label = !!defaultLabel && /*#__PURE__*/_jsx(TextInput, {
|
|
144
|
+
ref: labelRef,
|
|
145
|
+
defaultValue: defaultLabel,
|
|
146
|
+
editable: false,
|
|
147
|
+
pointerEvents: "none",
|
|
148
|
+
style: styles.label,
|
|
149
|
+
testID: "SparklineInteractiveHeaderLabel"
|
|
150
|
+
});
|
|
151
|
+
const title = /*#__PURE__*/_jsxs(_Fragment, {
|
|
152
|
+
children: [/*#__PURE__*/_jsx(View, {
|
|
153
|
+
children: typeof defaultTitle === 'string' ? /*#__PURE__*/_jsx(TextInput, {
|
|
154
|
+
ref: titleRef,
|
|
155
|
+
defaultValue: defaultTitle,
|
|
156
|
+
editable: false,
|
|
157
|
+
pointerEvents: "none",
|
|
158
|
+
style: styles.title(defaultTitle),
|
|
159
|
+
testID: "SparklineInteractiveHeaderTitle"
|
|
160
|
+
}) : defaultTitle
|
|
161
|
+
}), !!defaultSubHead && /*#__PURE__*/_jsxs(HStack, {
|
|
162
|
+
accessible: true,
|
|
163
|
+
alignItems: "center",
|
|
164
|
+
padding: 0,
|
|
165
|
+
children: [/*#__PURE__*/_jsx(TextInput, {
|
|
166
|
+
ref: subHeadIconRef,
|
|
167
|
+
defaultValue: subheadIconSignMap[defaultSubHead.sign],
|
|
168
|
+
editable: false,
|
|
169
|
+
pointerEvents: "none",
|
|
170
|
+
style: styles.subHeadIcon(defaultSubHead.variant),
|
|
171
|
+
testID: "SparklineInteractiveHeaderSubHeadIcon"
|
|
172
|
+
}), /*#__PURE__*/_jsx(TextInput, {
|
|
173
|
+
ref: subHeadRef,
|
|
174
|
+
defaultValue: interpolateSubHeadText(defaultSubHead),
|
|
175
|
+
editable: false,
|
|
176
|
+
pointerEvents: "none",
|
|
177
|
+
style: styles.subHead(defaultSubHead.variant, defaultSubHead.accessoryText === undefined),
|
|
178
|
+
testID: "SparklineInteractiveHeaderSubHead"
|
|
179
|
+
}), !!defaultSubHead.accessoryText && /*#__PURE__*/_jsx(TextInput, {
|
|
180
|
+
ref: subHeadAccessoryRef,
|
|
181
|
+
defaultValue: defaultSubHead.accessoryText,
|
|
182
|
+
editable: false,
|
|
183
|
+
pointerEvents: "none",
|
|
184
|
+
style: styles.subHeadAccessory(),
|
|
185
|
+
testID: "SparklineInteractiveHeaderSubHead"
|
|
186
|
+
})]
|
|
187
|
+
})]
|
|
188
|
+
});
|
|
189
|
+
const trendA11yLabel = defaultSubHead ? "" + ((defaultSubHead == null ? void 0 : defaultSubHead.variant) === 'positive' ? 'up' : 'down') : '';
|
|
190
|
+
const headerA11yLabel = defaultLabel + ", " + defaultTitle + ", " + trendA11yLabel + " " + (defaultSubHead == null ? void 0 : defaultSubHead.priceChange) + ", " + (defaultSubHead == null ? void 0 : defaultSubHead.percent);
|
|
191
|
+
return /*#__PURE__*/_jsxs(HStack, {
|
|
192
|
+
accessibilityHint: "The price and difference for this time period",
|
|
193
|
+
accessibilityLabel: "Asset summary",
|
|
194
|
+
accessibilityRole: "header",
|
|
195
|
+
"aria-live": "polite",
|
|
196
|
+
justifyContent: "space-between",
|
|
197
|
+
padding: 0,
|
|
198
|
+
testID: testID,
|
|
199
|
+
children: [/*#__PURE__*/_jsxs(VStack, {
|
|
200
|
+
accessible: true,
|
|
201
|
+
accessibilityLabel: headerA11yLabel,
|
|
202
|
+
flexShrink: 1,
|
|
203
|
+
padding: 0,
|
|
204
|
+
children: [labelNode != null ? labelNode : label, title]
|
|
205
|
+
}), /*#__PURE__*/_jsx(Trailing, {
|
|
206
|
+
children: trailing
|
|
207
|
+
})]
|
|
208
|
+
});
|
|
209
|
+
}));
|
|
210
|
+
export const SparklineInteractiveHeader = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref4, ref) => {
|
|
211
|
+
let {
|
|
212
|
+
defaultLabel,
|
|
213
|
+
defaultTitle,
|
|
214
|
+
defaultSubHead,
|
|
215
|
+
testID,
|
|
216
|
+
trailing,
|
|
217
|
+
labelNode
|
|
218
|
+
} = _ref4;
|
|
219
|
+
return /*#__PURE__*/_jsx(SparklineInteractiveHeaderStable
|
|
220
|
+
// All updates after initial load should be handled imperatively
|
|
221
|
+
// via update function in forwarded ref to prevent overriding
|
|
222
|
+
// values unexpectedly. This is why we use ref here so that the
|
|
223
|
+
// default value is stable and never updates on re-renders
|
|
224
|
+
, {
|
|
225
|
+
ref: ref,
|
|
226
|
+
defaultLabel: useRef(defaultLabel).current,
|
|
227
|
+
defaultSubHead: useRef(defaultSubHead).current,
|
|
228
|
+
defaultTitle: useRef(defaultTitle).current,
|
|
229
|
+
labelNode: labelNode,
|
|
230
|
+
testID: testID,
|
|
231
|
+
trailing: trailing
|
|
232
|
+
});
|
|
233
|
+
}));
|
package/esm/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
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); }
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { figma } from '@figma/code-connect';
|
|
4
|
+
import { SparklineInteractive } from '../../sparkline-interactive/SparklineInteractive';
|
|
5
|
+
import { SparklineInteractiveHeader } from '../SparklineInteractiveHeader';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
figma.connect(SparklineInteractiveHeader, 'https://www.figma.com/design/k5CtyJccNQUGMI5bI4lJ2g/✨-CDS-Components?node-id=320-14931&m=dev', {
|
|
8
|
+
imports: ["import { SparklineInteractiveHeader } from '@coinbase/cds-web-visualization';", "import { SparklineInteractive } from '@coinbase/cds-web-visualization';"],
|
|
9
|
+
props: {
|
|
10
|
+
compact: figma.boolean('compact'),
|
|
11
|
+
disableScrubbing: figma.boolean('scrubbing', {
|
|
12
|
+
false: true,
|
|
13
|
+
true: false
|
|
14
|
+
})
|
|
15
|
+
},
|
|
16
|
+
example: props => {
|
|
17
|
+
const periods = [{
|
|
18
|
+
label: '1H',
|
|
19
|
+
value: 'hour'
|
|
20
|
+
}, {
|
|
21
|
+
label: '1D',
|
|
22
|
+
value: 'day'
|
|
23
|
+
}, {
|
|
24
|
+
label: '1W',
|
|
25
|
+
value: 'week'
|
|
26
|
+
}, {
|
|
27
|
+
label: '1M',
|
|
28
|
+
value: 'month'
|
|
29
|
+
}, {
|
|
30
|
+
label: '1Y',
|
|
31
|
+
value: 'year'
|
|
32
|
+
}, {
|
|
33
|
+
label: 'All',
|
|
34
|
+
value: 'all'
|
|
35
|
+
}];
|
|
36
|
+
const data = {
|
|
37
|
+
hour: [],
|
|
38
|
+
day: [{
|
|
39
|
+
value: 49259.38,
|
|
40
|
+
date: new Date('2021-12-05T04:00:00.000Z')
|
|
41
|
+
}, {
|
|
42
|
+
value: 49163.79,
|
|
43
|
+
date: new Date('2021-12-05T04:05:00.000Z')
|
|
44
|
+
}, {
|
|
45
|
+
value: 49146.66,
|
|
46
|
+
date: new Date('2021-12-05T04:10:00.000Z')
|
|
47
|
+
}, {
|
|
48
|
+
value: 49083.92,
|
|
49
|
+
date: new Date('2021-12-05T04:15:00.000Z')
|
|
50
|
+
}, {
|
|
51
|
+
value: 49115.3,
|
|
52
|
+
date: new Date('2021-12-05T04:20:00.000Z')
|
|
53
|
+
}, {
|
|
54
|
+
value: 48992.14,
|
|
55
|
+
date: new Date('2021-12-05T04:25:00.000Z')
|
|
56
|
+
}, {
|
|
57
|
+
value: 49075.75,
|
|
58
|
+
date: new Date('2021-12-05T04:30:00.000Z')
|
|
59
|
+
}, {
|
|
60
|
+
value: 49025.78,
|
|
61
|
+
date: new Date('2021-12-05T04:35:00.000Z')
|
|
62
|
+
}, {
|
|
63
|
+
value: 49066.23,
|
|
64
|
+
date: new Date('2021-12-05T04:40:00.000Z')
|
|
65
|
+
}, {
|
|
66
|
+
value: 49247.82,
|
|
67
|
+
date: new Date('2021-12-05T04:45:00.000Z')
|
|
68
|
+
}],
|
|
69
|
+
week: [],
|
|
70
|
+
month: [],
|
|
71
|
+
year: [],
|
|
72
|
+
all: []
|
|
73
|
+
};
|
|
74
|
+
const defaultSubHead = {
|
|
75
|
+
percent: '1.35%',
|
|
76
|
+
sign: 'upwardTrend',
|
|
77
|
+
variant: 'positive',
|
|
78
|
+
accessibilityLabel: 'on Sunday, December 5, 2021 at 10:55 PM, up',
|
|
79
|
+
priceChange: '$21.36'
|
|
80
|
+
};
|
|
81
|
+
const header = /*#__PURE__*/_jsx(SparklineInteractiveHeader, {
|
|
82
|
+
defaultLabel: "Portfolio balance"
|
|
83
|
+
// @ts-expect-error: defaultSubHead is not part of the type definition
|
|
84
|
+
,
|
|
85
|
+
defaultSubHead: defaultSubHead,
|
|
86
|
+
defaultTitle: "$10,023.82"
|
|
87
|
+
});
|
|
88
|
+
return /*#__PURE__*/_jsx(SparklineInteractive, _extends({
|
|
89
|
+
data: data,
|
|
90
|
+
defaultPeriod: "day",
|
|
91
|
+
formatDate: date => date.toLocaleString('en-US', {
|
|
92
|
+
timeZone: 'America/New_York',
|
|
93
|
+
hour: 'numeric',
|
|
94
|
+
minute: 'numeric'
|
|
95
|
+
}),
|
|
96
|
+
headerNode: header,
|
|
97
|
+
onPeriodChanged: () => {},
|
|
98
|
+
onScrub: () => {},
|
|
99
|
+
onScrubEnd: () => {},
|
|
100
|
+
periods: periods,
|
|
101
|
+
strokeColor: "#cb51bb"
|
|
102
|
+
}, props));
|
|
103
|
+
}
|
|
104
|
+
});
|