@mui/x-charts 8.0.0-alpha.2 → 8.0.0-alpha.4

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 (90) hide show
  1. package/CHANGELOG.md +376 -0
  2. package/ChartsAxis/ChartsAxis.js +0 -4
  3. package/ChartsLabel/ChartsLabel.d.ts +19 -0
  4. package/ChartsLabel/ChartsLabel.js +58 -0
  5. package/ChartsLabel/ChartsLabelGradient.d.ts +40 -0
  6. package/ChartsLabel/ChartsLabelGradient.js +133 -0
  7. package/ChartsLabel/ChartsLabelMark.d.ts +27 -0
  8. package/ChartsLabel/ChartsLabelMark.js +108 -0
  9. package/ChartsLabel/labelClasses.d.ts +9 -0
  10. package/ChartsLabel/labelClasses.js +13 -0
  11. package/ChartsLabel/labelGradientClasses.d.ts +15 -0
  12. package/ChartsLabel/labelGradientClasses.js +17 -0
  13. package/ChartsLabel/labelMarkClasses.d.ts +17 -0
  14. package/ChartsLabel/labelMarkClasses.js +17 -0
  15. package/ChartsLegend/useAxis.js +3 -3
  16. package/ChartsTooltip/ChartsAxisTooltipContent.js +5 -3
  17. package/ChartsTooltip/ChartsTooltipTable.js +16 -14
  18. package/ChartsTooltip/chartsTooltipClasses.d.ts +3 -1
  19. package/ChartsTooltip/chartsTooltipClasses.js +3 -2
  20. package/ChartsTooltip/useAxisTooltip.js +2 -3
  21. package/ChartsTooltip/useItemTooltip.js +2 -3
  22. package/PieChart/PieArc.js +11 -5
  23. package/PieChart/PieArcPlot.js +9 -13
  24. package/PieChart/PiePlot.js +2 -2
  25. package/README.md +1 -1
  26. package/ScatterChart/ScatterPlot.js +2 -2
  27. package/ScatterChart/extremums.js +1 -3
  28. package/ScatterChart/formatter.js +2 -2
  29. package/hooks/useChartId.d.ts +1 -1
  30. package/hooks/useColorScale.js +2 -3
  31. package/hooks/useZAxis.d.ts +6 -0
  32. package/hooks/useZAxis.js +8 -0
  33. package/index.js +1 -1
  34. package/internals/consumeThemeProps.d.ts +54 -0
  35. package/internals/consumeThemeProps.js +79 -0
  36. package/internals/plugins/corePlugins/useChartId/useChartId.js +1 -1
  37. package/internals/plugins/corePlugins/useChartId/useChartId.selectors.d.ts +6 -6
  38. package/internals/plugins/corePlugins/useChartId/useChartId.types.d.ts +3 -3
  39. package/internals/store/useCharts.js +8 -2
  40. package/modern/ChartsAxis/ChartsAxis.js +0 -4
  41. package/modern/ChartsLabel/ChartsLabel.js +58 -0
  42. package/modern/ChartsLabel/ChartsLabelGradient.js +133 -0
  43. package/modern/ChartsLabel/ChartsLabelMark.js +108 -0
  44. package/modern/ChartsLabel/labelClasses.js +13 -0
  45. package/modern/ChartsLabel/labelGradientClasses.js +17 -0
  46. package/modern/ChartsLabel/labelMarkClasses.js +17 -0
  47. package/modern/ChartsLegend/useAxis.js +3 -3
  48. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +5 -3
  49. package/modern/ChartsTooltip/ChartsTooltipTable.js +16 -14
  50. package/modern/ChartsTooltip/chartsTooltipClasses.js +3 -2
  51. package/modern/ChartsTooltip/useAxisTooltip.js +2 -3
  52. package/modern/ChartsTooltip/useItemTooltip.js +2 -3
  53. package/modern/PieChart/PieArc.js +11 -5
  54. package/modern/PieChart/PieArcPlot.js +9 -13
  55. package/modern/PieChart/PiePlot.js +2 -2
  56. package/modern/ScatterChart/ScatterPlot.js +2 -2
  57. package/modern/ScatterChart/extremums.js +1 -3
  58. package/modern/ScatterChart/formatter.js +2 -2
  59. package/modern/hooks/useColorScale.js +2 -3
  60. package/modern/hooks/useZAxis.js +8 -0
  61. package/modern/index.js +1 -1
  62. package/modern/internals/consumeThemeProps.js +79 -0
  63. package/modern/internals/plugins/corePlugins/useChartId/useChartId.js +1 -1
  64. package/modern/internals/store/useCharts.js +8 -2
  65. package/node/ChartsAxis/ChartsAxis.js +0 -4
  66. package/node/ChartsLabel/ChartsLabel.js +64 -0
  67. package/node/ChartsLabel/ChartsLabelGradient.js +139 -0
  68. package/node/ChartsLabel/ChartsLabelMark.js +114 -0
  69. package/node/ChartsLabel/labelClasses.js +22 -0
  70. package/node/ChartsLabel/labelGradientClasses.js +26 -0
  71. package/node/ChartsLabel/labelMarkClasses.js +26 -0
  72. package/node/ChartsLegend/useAxis.js +2 -4
  73. package/node/ChartsTooltip/ChartsAxisTooltipContent.js +5 -3
  74. package/node/ChartsTooltip/ChartsTooltipTable.js +16 -14
  75. package/node/ChartsTooltip/chartsTooltipClasses.js +3 -2
  76. package/node/ChartsTooltip/useAxisTooltip.js +2 -4
  77. package/node/ChartsTooltip/useItemTooltip.js +2 -4
  78. package/node/PieChart/PieArc.js +11 -5
  79. package/node/PieChart/PieArcPlot.js +9 -13
  80. package/node/PieChart/PiePlot.js +2 -2
  81. package/node/ScatterChart/ScatterPlot.js +2 -2
  82. package/node/ScatterChart/extremums.js +1 -3
  83. package/node/ScatterChart/formatter.js +2 -2
  84. package/node/hooks/useColorScale.js +2 -4
  85. package/node/hooks/useZAxis.js +15 -0
  86. package/node/index.js +1 -1
  87. package/node/internals/consumeThemeProps.js +87 -0
  88. package/node/internals/plugins/corePlugins/useChartId/useChartId.js +1 -1
  89. package/node/internals/store/useCharts.js +9 -2
  90. package/package.json +5 -4
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.consumeThemeProps = void 0;
9
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
+ var _styles = require("@mui/material/styles");
11
+ var _resolveProps = _interopRequireDefault(require("@mui/utils/resolveProps"));
12
+ var React = _interopRequireWildcard(require("react"));
13
+ var ReactIs = _interopRequireWildcard(require("react-is"));
14
+ var _jsxRuntime = require("react/jsx-runtime");
15
+ /**
16
+ * A higher order component that consumes and merges the theme `defaultProps` and handles the `classes` and renders the component.
17
+ *
18
+ * This HOC will wrap a single component.
19
+ * If you need to render multiple components, you can manually consume the theme and render them in your component instead of using this HOC.
20
+ *
21
+ * In the example below, `MyComponent` will render the `DefaultComponent` with the `direction` prop set to `'row'` and the className set to `'my-custom-root'`.
22
+ *
23
+ * @example
24
+ * ```tsx
25
+ * createTheme({
26
+ * components: {
27
+ * MuiMyComponent: {
28
+ * defaultProps: {
29
+ * direction: 'row',
30
+ * },
31
+ * },
32
+ * },
33
+ * })
34
+ *
35
+ * type MyComponentProps = {
36
+ * direction: 'row' | 'column';
37
+ * classes?: Record<'root', string>;
38
+ * };
39
+ *
40
+ * const MyComponent = consumeThemeProps(
41
+ * 'MuiMyComponent',
42
+ * function DefaultComponent(props: MyComponentProps) {
43
+ * return (
44
+ * <div className={props.classes.root}>
45
+ * {props.direction}
46
+ * </div>
47
+ * );
48
+ * }
49
+ * );
50
+ *
51
+ * render(<MyComponent classes={{ root: 'my-custom-root' }} />);
52
+ * ```
53
+ *
54
+ * @param {string} name The mui component name.
55
+ * @param {object} options Options for the HOC.
56
+ * @param {Record<string, any>} options.defaultProps A set of defaults for the component, will be deep merged with the props.
57
+ * @param {Function} options.classesResolver A function that returns the classes for the component. It receives the props, after theme props and defaults have been applied. And the theme object as the second argument.
58
+ * @param InComponent The component to render if the slot is not provided.
59
+ */
60
+ const consumeThemeProps = (name, options, InComponent) => {
61
+ function InternalComponent(props, ref) {
62
+ const themedProps = (0, _styles.useThemeProps)({
63
+ props,
64
+ // eslint-disable-next-line material-ui/mui-name-matches-component-name
65
+ name
66
+ });
67
+ const defaultProps = typeof options.defaultProps === 'function' ? options.defaultProps(themedProps) : options.defaultProps ?? {};
68
+ const outProps = (0, _resolveProps.default)(defaultProps, themedProps);
69
+ const theme = (0, _styles.useTheme)();
70
+ const classes = options.classesResolver?.(outProps, theme);
71
+ if (process.env.NODE_ENV !== 'production') {
72
+ // eslint-disable-next-line react-compiler/react-compiler
73
+ InComponent.displayName = name;
74
+ }
75
+ const OutComponent = ReactIs.isForwardRef(InComponent) ? InComponent :
76
+ /*#__PURE__*/
77
+ // InComponent needs to be a function that accepts `(props, ref)`
78
+ // @ts-expect-error
79
+ React.forwardRef(InComponent);
80
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(OutComponent, (0, _extends2.default)({}, outProps, {
81
+ classes: classes,
82
+ ref: ref
83
+ }));
84
+ }
85
+ return /*#__PURE__*/React.forwardRef(InternalComponent);
86
+ };
87
+ exports.consumeThemeProps = consumeThemeProps;
@@ -35,7 +35,7 @@ useChartId.getInitialState = ({
35
35
  id
36
36
  }) => ({
37
37
  id: {
38
- chartId: (0, _useChartId.createChartDefaultId)(),
38
+ chartId: id,
39
39
  providedChartId: id
40
40
  }
41
41
  });
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
3
4
  var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
@@ -7,6 +8,7 @@ Object.defineProperty(exports, "__esModule", {
7
8
  exports.useChartApiInitialization = useChartApiInitialization;
8
9
  exports.useCharts = useCharts;
9
10
  var React = _interopRequireWildcard(require("react"));
11
+ var _useId = _interopRequireDefault(require("@mui/utils/useId"));
10
12
  var _ChartStore = require("../plugins/utils/ChartStore");
11
13
  var _corePlugins = require("../plugins/corePlugins");
12
14
  function useChartApiInitialization(inputApiRef) {
@@ -23,7 +25,10 @@ function useChartApiInitialization(inputApiRef) {
23
25
  let globalId = 0;
24
26
  function useCharts(inPlugins, props) {
25
27
  const plugins = React.useMemo(() => [..._corePlugins.CHART_CORE_PLUGINS, ...inPlugins], [inPlugins]);
26
- const pluginParams = {}; // To generate when plugins use params.
28
+ const defaultChartId = (0, _useId.default)();
29
+ const pluginParams = {
30
+ id: defaultChartId
31
+ }; // To generate when plugins use params.
27
32
  const instanceRef = React.useRef({});
28
33
  const instance = instanceRef.current;
29
34
  const publicAPI = useChartApiInitialization(props.apiRef);
@@ -47,7 +52,9 @@ function useCharts(inPlugins, props) {
47
52
  };
48
53
  plugins.forEach(plugin => {
49
54
  if (plugin.getInitialState) {
50
- Object.assign(initialState, plugin.getInitialState({}));
55
+ Object.assign(initialState, plugin.getInitialState({
56
+ id: defaultChartId
57
+ }));
51
58
  }
52
59
  });
53
60
  storeRef.current = new _ChartStore.ChartStore(initialState);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-charts",
3
- "version": "8.0.0-alpha.2",
3
+ "version": "8.0.0-alpha.4",
4
4
  "description": "The community edition of the Charts components (MUI X).",
5
5
  "author": "MUI Team",
6
6
  "main": "./node/index.js",
@@ -35,10 +35,11 @@
35
35
  "@react-spring/web": "^9.7.5",
36
36
  "clsx": "^2.1.1",
37
37
  "prop-types": "^15.8.1",
38
+ "react-is": "^18.3.1",
38
39
  "reselect": "^5.1.1",
39
- "use-sync-external-store": "^1.2.2",
40
- "@mui/x-internals": "8.0.0-alpha.2",
41
- "@mui/x-charts-vendor": "8.0.0-alpha.1"
40
+ "use-sync-external-store": "^1.4.0",
41
+ "@mui/x-charts-vendor": "8.0.0-alpha.4",
42
+ "@mui/x-internals": "8.0.0-alpha.2"
42
43
  },
43
44
  "peerDependencies": {
44
45
  "@emotion/react": "^11.9.0",