@coinbase/cds-mobile 9.12.3 → 9.14.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.
Files changed (33) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dts/visualizations/chart/CartesianChart.d.ts +2 -1
  3. package/dts/visualizations/chart/CartesianChart.d.ts.map +1 -1
  4. package/dts/visualizations/chart/Path.d.ts +4 -0
  5. package/dts/visualizations/chart/Path.d.ts.map +1 -1
  6. package/dts/visualizations/chart/axis/Axis.d.ts +12 -0
  7. package/dts/visualizations/chart/axis/Axis.d.ts.map +1 -1
  8. package/dts/visualizations/chart/axis/AxisTickLabelOverflowMask.d.ts +11 -0
  9. package/dts/visualizations/chart/axis/AxisTickLabelOverflowMask.d.ts.map +1 -0
  10. package/dts/visualizations/chart/axis/XAxis.d.ts.map +1 -1
  11. package/dts/visualizations/chart/axis/YAxis.d.ts.map +1 -1
  12. package/dts/visualizations/chart/axis/index.d.ts +1 -0
  13. package/dts/visualizations/chart/axis/index.d.ts.map +1 -1
  14. package/dts/visualizations/chart/line/LineChart.d.ts +4 -0
  15. package/dts/visualizations/chart/line/LineChart.d.ts.map +1 -1
  16. package/dts/visualizations/chart/line/ReferenceLine.d.ts +6 -0
  17. package/dts/visualizations/chart/line/ReferenceLine.d.ts.map +1 -1
  18. package/dts/visualizations/chart/scrubber/ScrubberProvider.d.ts.map +1 -1
  19. package/dts/visualizations/chart/text/ChartText.d.ts +20 -3
  20. package/dts/visualizations/chart/text/ChartText.d.ts.map +1 -1
  21. package/esm/visualizations/chart/Path.js +105 -31
  22. package/esm/visualizations/chart/axis/AxisTickLabelOverflowMask.js +44 -0
  23. package/esm/visualizations/chart/axis/XAxis.js +23 -10
  24. package/esm/visualizations/chart/axis/YAxis.js +23 -10
  25. package/esm/visualizations/chart/axis/__stories__/Axis.stories.js +276 -121
  26. package/esm/visualizations/chart/axis/index.js +1 -0
  27. package/esm/visualizations/chart/line/LineChart.js +4 -0
  28. package/esm/visualizations/chart/line/ReferenceLine.js +5 -2
  29. package/esm/visualizations/chart/line/__stories__/LineChart.stories.js +21 -0
  30. package/esm/visualizations/chart/scrubber/DefaultScrubberBeaconLabel.js +1 -1
  31. package/esm/visualizations/chart/scrubber/ScrubberProvider.js +40 -24
  32. package/esm/visualizations/chart/text/ChartText.js +21 -19
  33. package/package.json +2 -2
@@ -1,3 +1,4 @@
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); }
1
2
  import React, { useCallback, useMemo } from 'react';
2
3
  import { Platform } from 'react-native';
3
4
  import { Gesture, GestureDetector } from 'react-native-gesture-handler';
@@ -8,14 +9,10 @@ import { ScrubberContext } from '../utils/context';
8
9
  import { getPointOnSerializableScale } from '../utils/point';
9
10
  import { invertSerializableScale } from '../utils/scale';
10
11
  import { jsx as _jsx } from "react/jsx-runtime";
11
- /**
12
- * A component which encapsulates the ScrubberContext.
13
- * It depends on a ChartContext in order to provide accurate touch tracking.
14
- */
15
- export const ScrubberProvider = _ref => {
12
+ // Sets up the pan gesture + animated reaction. Only mounted when scrubbing is enabled.
13
+ const EnabledScrubberProvider = _ref => {
16
14
  let {
17
15
  children,
18
- enableScrubbing,
19
16
  onScrubberPositionChange,
20
17
  allowOverflowGestures
21
18
  } = _ref;
@@ -119,31 +116,50 @@ export const ScrubberProvider = _ref => {
119
116
  scrubberPosition.value = newScrubberPosition;
120
117
  }
121
118
  }).onEnd(function onEnd() {
122
- if (enableScrubbing) {
123
- runOnJS(handleStartEndHaptics)();
124
- scrubberPosition.value = undefined;
125
- }
119
+ runOnJS(handleStartEndHaptics)();
120
+ scrubberPosition.value = undefined;
126
121
  }).onTouchesCancelled(function onTouchesCancelled() {
127
- if (enableScrubbing) {
128
- scrubberPosition.value = undefined;
129
- }
122
+ scrubberPosition.value = undefined;
130
123
  });
131
- }, [allowOverflowGestures, handleStartEndHaptics, getDataIndexFromPosition, categoryAxisIsX, scrubberPosition, enableScrubbing]);
124
+ }, [allowOverflowGestures, handleStartEndHaptics, getDataIndexFromPosition, categoryAxisIsX, scrubberPosition]);
132
125
  const contextValue = useMemo(() => ({
133
- enableScrubbing: !!enableScrubbing,
126
+ enableScrubbing: true,
134
127
  scrubberPosition
135
- }), [enableScrubbing, scrubberPosition]);
136
- const content = /*#__PURE__*/_jsx(ScrubberContext.Provider, {
128
+ }), [scrubberPosition]);
129
+ return /*#__PURE__*/_jsx(GestureDetector, {
130
+ gesture: longPressGesture,
131
+ children: /*#__PURE__*/_jsx(ScrubberContext.Provider, {
132
+ value: contextValue,
133
+ children: children
134
+ })
135
+ });
136
+ };
137
+
138
+ // Supplies the ScrubberContext without the gesture/animated reaction (the common, disabled case).
139
+ const DisabledScrubberProvider = _ref2 => {
140
+ let {
141
+ children
142
+ } = _ref2;
143
+ const scrubberPosition = useSharedValue(undefined);
144
+ const contextValue = useMemo(() => ({
145
+ enableScrubbing: false,
146
+ scrubberPosition
147
+ }), [scrubberPosition]);
148
+ return /*#__PURE__*/_jsx(ScrubberContext.Provider, {
137
149
  value: contextValue,
138
150
  children: children
139
151
  });
152
+ };
140
153
 
141
- // Wrap with gesture handler only if scrubbing is enabled
142
- if (enableScrubbing) {
143
- return /*#__PURE__*/_jsx(GestureDetector, {
144
- gesture: longPressGesture,
145
- children: content
146
- });
154
+ /**
155
+ * A component which encapsulates the ScrubberContext.
156
+ * It depends on a ChartContext in order to provide accurate touch tracking.
157
+ */
158
+ export const ScrubberProvider = props => {
159
+ if (props.enableScrubbing) {
160
+ return /*#__PURE__*/_jsx(EnabledScrubberProvider, _extends({}, props));
147
161
  }
148
- return content;
162
+ return /*#__PURE__*/_jsx(DisabledScrubberProvider, {
163
+ children: props.children
164
+ });
149
165
  };
@@ -34,6 +34,11 @@ const getFontWeight = (theme, font) => {
34
34
  * Vertical alignment options for chart text.
35
35
  */
36
36
 
37
+ /**
38
+ * Which axes ChartText may nudge labels along to stay in bounds.
39
+ * @default 'both'
40
+ */
41
+
37
42
  export const ChartText = /*#__PURE__*/memo(_ref => {
38
43
  var _elevationShadow$shad, _elevationShadow$shad2, _elevationShadow$shad3, _elevationShadow$shad4, _elevationShadow$shad5, _elevationShadow$shad6, _elevationShadow$shad7;
39
44
  let {
@@ -46,6 +51,7 @@ export const ChartText = /*#__PURE__*/memo(_ref => {
46
51
  verticalAlignment = 'middle',
47
52
  paragraphAlignment = TextAlign.Left,
48
53
  disableRepositioning = false,
54
+ repositionAxes = disableRepositioning ? 'none' : 'both',
49
55
  bounds,
50
56
  color,
51
57
  background: backgroundProp,
@@ -183,12 +189,8 @@ export const ChartText = /*#__PURE__*/memo(_ref => {
183
189
  height: chartHeight
184
190
  }), [chartWidth, chartHeight]);
185
191
  const overflowAmount = useDerivedValue(() => {
186
- if (disableRepositioning) {
187
- return {
188
- x: 0,
189
- y: 0
190
- };
191
- }
192
+ const repositionX = repositionAxes === 'both' || repositionAxes === 'x';
193
+ const repositionY = repositionAxes === 'both' || repositionAxes === 'y';
192
194
  const parentBounds = bounds != null ? bounds : fullChartBounds;
193
195
  if (!parentBounds || parentBounds.width <= 0 || parentBounds.height <= 0) {
194
196
  return {
@@ -198,25 +200,25 @@ export const ChartText = /*#__PURE__*/memo(_ref => {
198
200
  }
199
201
  let offsetX = 0;
200
202
  let offsetY = 0;
201
-
202
- // X-axis overflow
203
- if (backgroundRect.value.x < parentBounds.x) {
204
- offsetX = parentBounds.x - backgroundRect.value.x;
205
- } else if (backgroundRect.value.x + backgroundRect.value.width > parentBounds.x + parentBounds.width) {
206
- offsetX = parentBounds.x + parentBounds.width - (backgroundRect.value.x + backgroundRect.value.width);
203
+ if (repositionX) {
204
+ if (backgroundRect.value.x < parentBounds.x) {
205
+ offsetX = parentBounds.x - backgroundRect.value.x;
206
+ } else if (backgroundRect.value.x + backgroundRect.value.width > parentBounds.x + parentBounds.width) {
207
+ offsetX = parentBounds.x + parentBounds.width - (backgroundRect.value.x + backgroundRect.value.width);
208
+ }
207
209
  }
208
-
209
- // Y-axis overflow
210
- if (backgroundRect.value.y < parentBounds.y) {
211
- offsetY = parentBounds.y - backgroundRect.value.y;
212
- } else if (backgroundRect.value.y + backgroundRect.value.height > parentBounds.y + parentBounds.height) {
213
- offsetY = parentBounds.y + parentBounds.height - (backgroundRect.value.y + backgroundRect.value.height);
210
+ if (repositionY) {
211
+ if (backgroundRect.value.y < parentBounds.y) {
212
+ offsetY = parentBounds.y - backgroundRect.value.y;
213
+ } else if (backgroundRect.value.y + backgroundRect.value.height > parentBounds.y + parentBounds.height) {
214
+ offsetY = parentBounds.y + parentBounds.height - (backgroundRect.value.y + backgroundRect.value.height);
215
+ }
214
216
  }
215
217
  return {
216
218
  x: offsetX,
217
219
  y: offsetY
218
220
  };
219
- }, [backgroundRect, fullChartBounds, bounds, disableRepositioning]);
221
+ }, [backgroundRect, fullChartBounds, bounds, repositionAxes]);
220
222
 
221
223
  // Final adjusted positions
222
224
  const backgroundRectWithOffset = useDerivedValue(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coinbase/cds-mobile",
3
- "version": "9.12.3",
3
+ "version": "9.14.0",
4
4
  "description": "Coinbase Design System - Mobile",
5
5
  "repository": {
6
6
  "type": "git",
@@ -218,7 +218,7 @@
218
218
  "react-native-worklets": "0.5.2"
219
219
  },
220
220
  "dependencies": {
221
- "@coinbase/cds-common": "^9.12.3",
221
+ "@coinbase/cds-common": "^9.14.0",
222
222
  "@coinbase/cds-icons": "^5.21.0",
223
223
  "@coinbase/cds-illustrations": "^4.47.0",
224
224
  "@coinbase/cds-lottie-files": "^3.3.4",