@yamada-ui/charts 1.4.1-next-20240820155044 → 1.5.0-dev-20240822153118

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/dist/index.js CHANGED
@@ -2968,19 +2968,44 @@ var RadarChart = (0, import_core16.forwardRef)((props, ref) => {
2968
2968
  });
2969
2969
 
2970
2970
  // src/donut-chart.tsx
2971
+ var import_core20 = require("@yamada-ui/core");
2972
+ var import_utils21 = require("@yamada-ui/utils");
2973
+ var import_react17 = require("react");
2974
+ var import_recharts6 = require("recharts");
2975
+
2976
+ // src/use-chart-label.ts
2977
+ var import_core17 = require("@yamada-ui/core");
2978
+ var import_utils18 = require("@yamada-ui/utils");
2979
+ var import_react15 = require("react");
2980
+ var useChartLabel = ({ styles, ...rest }) => {
2981
+ var _a;
2982
+ const { theme } = (0, import_core17.useTheme)();
2983
+ const [labelProps, labelClassName] = getComponentProps(
2984
+ [(_a = rest.labelProps) != null ? _a : {}, labelProperties],
2985
+ styles.label
2986
+ )(theme);
2987
+ const getLabelProps = (0, import_react15.useCallback)(
2988
+ ({ className, ...props } = {}, ref = null) => {
2989
+ return {
2990
+ ref,
2991
+ className: (0, import_utils18.cx)(className, labelClassName),
2992
+ ...props,
2993
+ ...labelProps
2994
+ };
2995
+ },
2996
+ [labelClassName, labelProps]
2997
+ );
2998
+ return { getLabelProps };
2999
+ };
3000
+
3001
+ // src/use-pie-chart.ts
2971
3002
  var import_core19 = require("@yamada-ui/core");
2972
3003
  var import_utils20 = require("@yamada-ui/utils");
2973
3004
  var import_react16 = require("react");
2974
- var import_recharts6 = require("recharts");
2975
3005
 
2976
- // src/use-pie-chart.ts
3006
+ // src/pie-chart-label.tsx
2977
3007
  var import_core18 = require("@yamada-ui/core");
2978
3008
  var import_utils19 = require("@yamada-ui/utils");
2979
- var import_react15 = require("react");
2980
-
2981
- // src/pie-chart-label.tsx
2982
- var import_core17 = require("@yamada-ui/core");
2983
- var import_utils18 = require("@yamada-ui/utils");
2984
3009
  var import_jsx_runtime10 = require("react/jsx-runtime");
2985
3010
  var RADIAN = Math.PI / 180;
2986
3011
  var DEFAULT_LABEL_OFFSET = 22;
@@ -3007,16 +3032,16 @@ var pieChartLabel = ({
3007
3032
  const displayLabel = () => {
3008
3033
  if (isPercent) {
3009
3034
  return parseFloat((percent * 100).toFixed(0)) > 0 && `${(percent * 100).toFixed(0)}%`;
3010
- } else if (!(0, import_utils18.isUndefined)(labelFormatter)) {
3035
+ } else if (!(0, import_utils19.isUndefined)(labelFormatter)) {
3011
3036
  return labelFormatter(value);
3012
3037
  } else {
3013
3038
  return value;
3014
3039
  }
3015
3040
  };
3016
3041
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3017
- import_core17.ui.text,
3042
+ import_core18.ui.text,
3018
3043
  {
3019
- className: (0, import_utils18.cx)(cellClassName, "ui-chart__label"),
3044
+ className: (0, import_utils19.cx)(cellClassName, "ui-chart__label"),
3020
3045
  x,
3021
3046
  y,
3022
3047
  textAnchor,
@@ -3045,9 +3070,9 @@ var pieChartLabelLine = ({
3045
3070
  const y = cyProp + (middleRadius + labelOffset) * Math.sin(-midAngle * RADIAN);
3046
3071
  const d = `M ${points[0].x} ${points[0].y} L ${x} ${y}`;
3047
3072
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3048
- import_core17.ui.path,
3073
+ import_core18.ui.path,
3049
3074
  {
3050
- className: (0, import_utils18.cx)(cellClassName, "ui-chart__label-line"),
3075
+ className: (0, import_utils19.cx)(cellClassName, "ui-chart__label-line"),
3051
3076
  d,
3052
3077
  __css: styles,
3053
3078
  ...labelLineProps
@@ -3074,8 +3099,8 @@ var usePieChart = ({
3074
3099
  ...rest
3075
3100
  }) => {
3076
3101
  var _a, _b;
3077
- const { theme } = (0, import_core18.useTheme)();
3078
- const [highlightedArea, setHighlightedArea] = (0, import_react15.useState)(null);
3102
+ const { theme } = (0, import_core19.useTheme)();
3103
+ const [highlightedArea, setHighlightedArea] = (0, import_react16.useState)(null);
3079
3104
  const shouldHighlight = highlightedArea !== null;
3080
3105
  const { dimCell, ...computedCellProps } = (_a = rest.cellProps) != null ? _a : {};
3081
3106
  const {
@@ -3085,7 +3110,7 @@ var usePieChart = ({
3085
3110
  labelLine: labelLineProps,
3086
3111
  ...computedPieProps
3087
3112
  } = (_b = rest.pieProps) != null ? _b : {};
3088
- const cellColors = (0, import_react15.useMemo)(
3113
+ const cellColors = (0, import_react16.useMemo)(
3089
3114
  () => data.map(({ color }, index) => ({
3090
3115
  __prefix: "ui",
3091
3116
  name: `cell-${index}`,
@@ -3094,14 +3119,14 @@ var usePieChart = ({
3094
3119
  })),
3095
3120
  [data]
3096
3121
  );
3097
- const pieVars = (0, import_react15.useMemo)(
3122
+ const pieVars = (0, import_react16.useMemo)(
3098
3123
  () => [
3099
3124
  ...cellColors,
3100
3125
  { __prefix: "ui", name: "fill-opacity", value: fillOpacity }
3101
3126
  ],
3102
3127
  [fillOpacity, cellColors]
3103
3128
  );
3104
- const [chartProps, chartClassName] = (0, import_react15.useMemo)(
3129
+ const [chartProps, chartClassName] = (0, import_react16.useMemo)(
3105
3130
  () => {
3106
3131
  var _a2;
3107
3132
  return getComponentProps(
@@ -3111,14 +3136,14 @@ var usePieChart = ({
3111
3136
  },
3112
3137
  [rest.chartProps, styles.chart, theme]
3113
3138
  );
3114
- const [pieProps, pieClassName] = (0, import_react15.useMemo)(
3139
+ const [pieProps, pieClassName] = (0, import_react16.useMemo)(
3115
3140
  () => getComponentProps(
3116
3141
  [computedPieProps, pieProperties],
3117
3142
  styles.pie
3118
3143
  )(theme),
3119
3144
  [computedPieProps, styles.pie, theme]
3120
3145
  );
3121
- const cellClassName = (0, import_react15.useMemo)(() => {
3146
+ const cellClassName = (0, import_react16.useMemo)(() => {
3122
3147
  const resolvedCellProps = {
3123
3148
  fillOpacity: "var(--ui-fill-opacity)",
3124
3149
  ...styles.cell,
@@ -3126,25 +3151,25 @@ var usePieChart = ({
3126
3151
  };
3127
3152
  return getClassName(resolvedCellProps)(theme);
3128
3153
  }, [computedCellProps, styles.cell, theme]);
3129
- const dimCellClassName = (0, import_react15.useMemo)(() => {
3154
+ const dimCellClassName = (0, import_react16.useMemo)(() => {
3130
3155
  const resolvedDimCell = { fillOpacity: 0.3, strokeOpacity: 0, ...dimCell };
3131
3156
  return getClassName(resolvedDimCell)(theme);
3132
3157
  }, [dimCell, theme]);
3133
- const activeShapeProps = (0, import_react15.useMemo)(
3158
+ const activeShapeProps = (0, import_react16.useMemo)(
3134
3159
  () => getComponentProps(
3135
3160
  [{ _focus: { outline: "none" }, ...activeShape }, pieProperties],
3136
3161
  styles.activeShape
3137
3162
  )(theme, true),
3138
3163
  [activeShape, styles.activeShape, theme]
3139
3164
  );
3140
- const inactiveShapeProps = (0, import_react15.useMemo)(
3165
+ const inactiveShapeProps = (0, import_react16.useMemo)(
3141
3166
  () => getComponentProps(
3142
3167
  [inactiveShape, pieProperties],
3143
3168
  styles.inactiveShape
3144
3169
  )(theme, true),
3145
3170
  [inactiveShape, styles.inactiveShape, theme]
3146
3171
  );
3147
- const label = (0, import_react15.useCallback)(
3172
+ const label = (0, import_react16.useCallback)(
3148
3173
  (props) => pieChartLabel({
3149
3174
  labelOffset,
3150
3175
  isPercent,
@@ -3155,7 +3180,7 @@ var usePieChart = ({
3155
3180
  }),
3156
3181
  [isPercent, labelOffset, labelProps, styles.label, labelFormatter]
3157
3182
  );
3158
- const labelLine = (0, import_react15.useCallback)(
3183
+ const labelLine = (0, import_react16.useCallback)(
3159
3184
  (props) => {
3160
3185
  return pieChartLabelLine({
3161
3186
  labelOffset,
@@ -3166,7 +3191,7 @@ var usePieChart = ({
3166
3191
  },
3167
3192
  [labelLineProps, labelOffset, styles.labelLine]
3168
3193
  );
3169
- const cellPropList = (0, import_react15.useMemo)(
3194
+ const cellPropList = (0, import_react16.useMemo)(
3170
3195
  () => data.map((props, index) => {
3171
3196
  const { name, dimCell: dimCell2 = {}, ...computedProps } = props;
3172
3197
  const color = `var(--ui-cell-${index})`;
@@ -3196,19 +3221,19 @@ var usePieChart = ({
3196
3221
  theme
3197
3222
  ]
3198
3223
  );
3199
- const getPieChartProps = (0, import_react15.useCallback)(
3224
+ const getPieChartProps = (0, import_react16.useCallback)(
3200
3225
  ({ className, ...props } = {}, ref = null) => ({
3201
3226
  ref,
3202
- className: (0, import_utils19.cx)(className, chartClassName),
3227
+ className: (0, import_utils20.cx)(className, chartClassName),
3203
3228
  ...props,
3204
3229
  ...chartProps
3205
3230
  }),
3206
3231
  [chartProps, chartClassName]
3207
3232
  );
3208
- const getPieProps = (0, import_react15.useCallback)(
3233
+ const getPieProps = (0, import_react16.useCallback)(
3209
3234
  ({ className, ...props }, ref = null) => ({
3210
3235
  ref,
3211
- className: (0, import_utils19.cx)(className, pieClassName),
3236
+ className: (0, import_utils20.cx)(className, pieClassName),
3212
3237
  dataKey: "value",
3213
3238
  data,
3214
3239
  rootTabIndex: -1,
@@ -3242,12 +3267,12 @@ var usePieChart = ({
3242
3267
  pieProps
3243
3268
  ]
3244
3269
  );
3245
- const getCellProps = (0, import_react15.useCallback)(
3270
+ const getCellProps = (0, import_react16.useCallback)(
3246
3271
  ({ index, className: classNameProp, ...props }, ref = null) => {
3247
3272
  const { className, color } = cellPropList[index];
3248
3273
  return {
3249
3274
  ref,
3250
- className: (0, import_utils19.cx)(classNameProp, className),
3275
+ className: (0, import_utils20.cx)(classNameProp, className),
3251
3276
  fill: color,
3252
3277
  stroke: color,
3253
3278
  strokeWidth,
@@ -3267,8 +3292,8 @@ var usePieChart = ({
3267
3292
 
3268
3293
  // src/donut-chart.tsx
3269
3294
  var import_jsx_runtime11 = require("react/jsx-runtime");
3270
- var DonutChart = (0, import_core19.forwardRef)((props, ref) => {
3271
- const [styles, mergedProps] = (0, import_core19.useMultiComponentStyle)("DonutChart", props);
3295
+ var DonutChart = (0, import_core20.forwardRef)((props, ref) => {
3296
+ const [styles, mergedProps] = (0, import_core20.useMultiComponentStyle)("DonutChart", props);
3272
3297
  const {
3273
3298
  className,
3274
3299
  data,
@@ -3295,8 +3320,9 @@ var DonutChart = (0, import_core19.forwardRef)((props, ref) => {
3295
3320
  outerRadius,
3296
3321
  strokeWidth,
3297
3322
  legendProps,
3323
+ labelProps,
3298
3324
  ...rest
3299
- } = (0, import_core19.omitThemeProps)(mergedProps);
3325
+ } = (0, import_core20.omitThemeProps)(mergedProps);
3300
3326
  const {
3301
3327
  pieVars,
3302
3328
  getPieProps,
@@ -3330,7 +3356,8 @@ var DonutChart = (0, import_core19.forwardRef)((props, ref) => {
3330
3356
  const { legendProps: computedLegendProps, getLegendProps } = useChartLegend({
3331
3357
  legendProps
3332
3358
  });
3333
- const cells = (0, import_react16.useMemo)(
3359
+ const { getLabelProps } = useChartLabel({ labelProps, styles });
3360
+ const cells = (0, import_react17.useMemo)(
3334
3361
  () => data.map(({ name }, index) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3335
3362
  import_recharts6.Cell,
3336
3363
  {
@@ -3341,10 +3368,10 @@ var DonutChart = (0, import_core19.forwardRef)((props, ref) => {
3341
3368
  [data, getCellProps]
3342
3369
  );
3343
3370
  return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(ChartProvider, { value: { styles }, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3344
- import_core19.ui.div,
3371
+ import_core20.ui.div,
3345
3372
  {
3346
3373
  ref,
3347
- className: (0, import_utils20.cx)("ui-donut-chart", className),
3374
+ className: (0, import_utils21.cx)("ui-donut-chart", className),
3348
3375
  var: pieVars,
3349
3376
  __css: { maxW: "full", ...styles.container },
3350
3377
  ...rest,
@@ -3357,13 +3384,21 @@ var DonutChart = (0, import_core19.forwardRef)((props, ref) => {
3357
3384
  {
3358
3385
  ...getPieChartProps({ className: "ui-donut-chart__chart" }),
3359
3386
  children: [
3360
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3387
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
3361
3388
  import_recharts6.Pie,
3362
3389
  {
3363
3390
  ...getPieProps({
3364
3391
  className: "ui-donut-chart__donut"
3365
3392
  }),
3366
- children: cells
3393
+ children: [
3394
+ cells,
3395
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3396
+ import_recharts6.Label,
3397
+ {
3398
+ ...getLabelProps({ className: "ui-donut-chart__label" })
3399
+ }
3400
+ )
3401
+ ]
3367
3402
  }
3368
3403
  ),
3369
3404
  withLegend ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
@@ -3408,13 +3443,13 @@ var DonutChart = (0, import_core19.forwardRef)((props, ref) => {
3408
3443
  });
3409
3444
 
3410
3445
  // src/pie-chart.tsx
3411
- var import_core20 = require("@yamada-ui/core");
3412
- var import_utils21 = require("@yamada-ui/utils");
3413
- var import_react17 = require("react");
3446
+ var import_core21 = require("@yamada-ui/core");
3447
+ var import_utils22 = require("@yamada-ui/utils");
3448
+ var import_react18 = require("react");
3414
3449
  var import_recharts7 = require("recharts");
3415
3450
  var import_jsx_runtime12 = require("react/jsx-runtime");
3416
- var PieChart = (0, import_core20.forwardRef)((props, ref) => {
3417
- const [styles, mergedProps] = (0, import_core20.useMultiComponentStyle)("PieChart", props);
3451
+ var PieChart = (0, import_core21.forwardRef)((props, ref) => {
3452
+ const [styles, mergedProps] = (0, import_core21.useMultiComponentStyle)("PieChart", props);
3418
3453
  const {
3419
3454
  className,
3420
3455
  data,
@@ -3442,7 +3477,7 @@ var PieChart = (0, import_core20.forwardRef)((props, ref) => {
3442
3477
  strokeWidth,
3443
3478
  legendProps,
3444
3479
  ...rest
3445
- } = (0, import_core20.omitThemeProps)(mergedProps);
3480
+ } = (0, import_core21.omitThemeProps)(mergedProps);
3446
3481
  const {
3447
3482
  pieVars,
3448
3483
  getPieProps,
@@ -3476,7 +3511,7 @@ var PieChart = (0, import_core20.forwardRef)((props, ref) => {
3476
3511
  const { legendProps: computedLegendProps, getLegendProps } = useChartLegend({
3477
3512
  legendProps
3478
3513
  });
3479
- const cells = (0, import_react17.useMemo)(
3514
+ const cells = (0, import_react18.useMemo)(
3480
3515
  () => data.map(({ name }, index) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3481
3516
  import_recharts7.Cell,
3482
3517
  {
@@ -3487,10 +3522,10 @@ var PieChart = (0, import_core20.forwardRef)((props, ref) => {
3487
3522
  [data, getCellProps]
3488
3523
  );
3489
3524
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ChartProvider, { value: { styles }, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3490
- import_core20.ui.div,
3525
+ import_core21.ui.div,
3491
3526
  {
3492
3527
  ref,
3493
- className: (0, import_utils21.cx)("ui-pie-chart", className),
3528
+ className: (0, import_utils22.cx)("ui-pie-chart", className),
3494
3529
  var: pieVars,
3495
3530
  __css: { maxW: "full", ...styles.container },
3496
3531
  ...rest,