Skip to content

Commit 08360d2

Browse files
jsilllpan-kot
andauthored
fix: export missing types from core/interfaces (#37)
* fix: export missing types from core/interfaces * address comments * chore: Export core types ext (#52) * address comments * refactor and export core types --------- Co-authored-by: Joao Silveira <[email protected]> --------- Co-authored-by: Andrei Zhaleznichenka <[email protected]>
1 parent de54003 commit 08360d2

File tree

17 files changed

+211
-215
lines changed

17 files changed

+211
-215
lines changed

pages/03-core/simple-zooming.page.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Checkbox from "@cloudscape-design/components/checkbox";
1111
import SpaceBetween from "@cloudscape-design/components/space-between";
1212
import { colorChartsBlue1400, colorChartsLineTick } from "@cloudscape-design/design-tokens";
1313

14-
import { CoreChartAPI, CoreChartProps } from "../../lib/components/core/interfaces";
14+
import { CoreChartProps } from "../../lib/components/core/interfaces";
1515
import CoreChart from "../../lib/components/internal-do-not-use/core-chart";
1616
import { dateFormatter } from "../common/formatters";
1717
import { PageSettings, PageSettingsForm, useChartSettings } from "../common/page-settings";
@@ -135,9 +135,9 @@ function Charts() {
135135
chartProps,
136136
} = useChartSettings<ThisPageSettings>({ more: true });
137137
const commonProps = omit(chartProps.cartesian, ["ref"]);
138-
const scatterChartRef = useRef<CoreChartAPI>(null) as React.MutableRefObject<CoreChartAPI>;
138+
const scatterChartRef = useRef<CoreChartProps.ChartAPI>(null) as React.MutableRefObject<CoreChartProps.ChartAPI>;
139139
const getScatterChart = () => scatterChartRef.current!;
140-
const navigatorChartRef = useRef<CoreChartAPI>(null) as React.MutableRefObject<CoreChartAPI>;
140+
const navigatorChartRef = useRef<CoreChartProps.ChartAPI>(null) as React.MutableRefObject<CoreChartProps.ChartAPI>;
141141
const getNavigatorChart = () => navigatorChartRef.current!;
142142

143143
const [zoomRange, setZoomRange] = useState<null | [number, number]>(null);
@@ -314,7 +314,7 @@ function Charts() {
314314
);
315315
}
316316

317-
function highlightChartGroup(targetPoint: Highcharts.Point, api: CoreChartAPI) {
317+
function highlightChartGroup(targetPoint: Highcharts.Point, api: CoreChartProps.ChartAPI) {
318318
const group: Highcharts.Point[] = [];
319319
for (const s of api.chart.series) {
320320
for (const p of s.data) {

src/__tests__/__snapshots__/documenter.test.ts.snap

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ minimum width, the horizontal scrollbar is automatically added.",
9090
},
9191
{
9292
"description": "Defines options for filtering in the chart, including:
93-
* \`seriesFilter\` (otpional, boolean) - Displays default series filter at the top of the chart.
94-
* \`additionalFilters\` (otpional, slot) - A slot for custom chart filters at the top of the chart.",
93+
* \`seriesFilter\` (optional, boolean) - Displays default series filter at the top of the chart.
94+
* \`additionalFilters\` (optional, slot) - A slot for custom chart filters at the top of the chart.",
9595
"inlineType": {
9696
"name": "BaseFilterOptions",
9797
"properties": [
@@ -351,7 +351,7 @@ This property corresponds to "normal" stacking type in Highcharts ([plotOptions.
351351
{
352352
"name": "point",
353353
"optional": true,
354-
"type": "((props: CartesianChartProps.TooltipPointRenderProps) => TooltipPointFormatted)",
354+
"type": "((props: CartesianChartProps.TooltipPointRenderProps) => BaseTooltipPointFormatted)",
355355
},
356356
{
357357
"name": "size",
@@ -370,11 +370,11 @@ This property corresponds to "normal" stacking type in Highcharts ([plotOptions.
370370
"description": "Controls the placement of the vertical axis title.
371371
When set to "side", displays the title along the axis line.",
372372
"inlineType": {
373-
"name": ""side" | "top"",
373+
"name": ""top" | "side"",
374374
"type": "union",
375375
"values": [
376-
"side",
377376
"top",
377+
"side",
378378
],
379379
},
380380
"name": "verticalAxisTitlePlacement",
@@ -615,8 +615,8 @@ minimum width, the horizontal scrollbar is automatically added.",
615615
},
616616
{
617617
"description": "Defines options for filtering in the chart, including:
618-
* \`seriesFilter\` (otpional, boolean) - Displays default series filter at the top of the chart.
619-
* \`additionalFilters\` (otpional, slot) - A slot for custom chart filters at the top of the chart.",
618+
* \`seriesFilter\` (optional, boolean) - Displays default series filter at the top of the chart.
619+
* \`additionalFilters\` (optional, slot) - A slot for custom chart filters at the top of the chart.",
620620
"inlineType": {
621621
"name": "BaseFilterOptions",
622622
"properties": [

src/cartesian-chart/chart-cartesian-internal.tsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@ import { forwardRef, useImperativeHandle, useRef, useState } from "react";
66
import { useControllableState } from "@cloudscape-design/component-toolkit";
77

88
import { InternalCoreChart } from "../core/chart-core";
9-
import {
10-
CoreChartAPI,
11-
CoreChartProps,
12-
ErrorBarSeriesOptions,
13-
TooltipContentItem,
14-
TooltipPointProps,
15-
TooltipSlotProps,
16-
} from "../core/interfaces";
9+
import { CoreChartProps, ErrorBarSeriesOptions } from "../core/interfaces";
1710
import { getOptionsId, isXThreshold } from "../core/utils";
1811
import { InternalBaseComponentProps } from "../internal/base-component/use-base-component";
1912
import { fireNonCancelableEvent } from "../internal/events";
@@ -30,7 +23,7 @@ interface InternalCartesianChartProps extends InternalBaseComponentProps, Cartes
3023

3124
export const InternalCartesianChart = forwardRef(
3225
({ tooltip, ...props }: InternalCartesianChartProps, ref: React.Ref<CartesianChartProps.Ref>) => {
33-
const apiRef = useRef<null | CoreChartAPI>(null);
26+
const apiRef = useRef<null | CoreChartProps.ChartAPI>(null);
3427

3528
// When visibleSeries and onVisibleSeriesChange are provided - the series visibility can be controlled from the outside.
3629
// Otherwise - the component handles series visibility using its internal state.
@@ -59,7 +52,7 @@ export const InternalCartesianChart = forwardRef(
5952
// assuming Highcharts makes no modifications for those. These options are not referentially equal
6053
// to the ones we get from the consumer due to the internal validation/transformation we run on them.
6154
// See: https://api.highcharts.com/class-reference/Highcharts.Chart#userOptions.
62-
const transformItem = (item: TooltipContentItem): CartesianChartProps.TooltipPointItem => ({
55+
const transformItem = (item: CoreChartProps.TooltipContentItem): CartesianChartProps.TooltipPointItem => ({
6356
x: item.point.x,
6457
y: isXThreshold(item.point.series) ? null : (item.point.y ?? null),
6558
series: item.point.series.userOptions as NonErrorBarSeriesOptions,
@@ -69,10 +62,14 @@ export const InternalCartesianChart = forwardRef(
6962
series: point.series.userOptions as ErrorBarSeriesOptions,
7063
})),
7164
});
72-
const transformSeriesProps = (props: TooltipPointProps): CartesianChartProps.TooltipPointRenderProps => ({
65+
const transformSeriesProps = (
66+
props: CoreChartProps.TooltipPointProps,
67+
): CartesianChartProps.TooltipPointRenderProps => ({
7368
item: transformItem(props.item),
7469
});
75-
const transformSlotProps = (props: TooltipSlotProps): CartesianChartProps.TooltipSlotRenderProps => ({
70+
const transformSlotProps = (
71+
props: CoreChartProps.TooltipSlotProps,
72+
): CartesianChartProps.TooltipSlotRenderProps => ({
7673
x: props.x,
7774
items: props.items.map(transformItem),
7875
});

src/cartesian-chart/interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export namespace CartesianChartProps {
183183
errorRanges: { low: number; high: number; series: CartesianChartProps.ErrorBarSeriesOptions }[];
184184
series: NonErrorBarSeriesOptions;
185185
}
186-
export type TooltipPointFormatted = CoreTypes.TooltipPointFormatted;
186+
export type TooltipPointFormatted = CoreTypes.BaseTooltipPointFormatted;
187187

188188
export type LegendOptions = CoreTypes.BaseLegendOptions;
189189

src/core/chart-api/chart-extra-context.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type Highcharts from "highcharts";
55

66
import { getChartSeries } from "../../internal/utils/chart-series";
77
import { ChartLabels } from "../i18n-utils";
8-
import { HighlightChangeDetail, HighlightClearDetail, Rect, VisibleItemsChangeDetail } from "../interfaces";
8+
import { CoreChartProps, Rect } from "../interfaces";
99
import { getGroupRect, isSeriesStacked } from "../utils";
1010

1111
// Chart API context is used for dependency injection for chart utilities.
@@ -33,9 +33,9 @@ export namespace ChartExtraContext {
3333
}
3434

3535
export interface Handlers {
36-
onHighlight?(detail: HighlightChangeDetail): void;
37-
onClearHighlight?(detail: HighlightClearDetail): void;
38-
onVisibleItemsChange?: (detail: VisibleItemsChangeDetail) => void;
36+
onHighlight?(detail: CoreChartProps.HighlightChangeDetail): void;
37+
onClearHighlight?(detail: CoreChartProps.HighlightClearDetail): void;
38+
onVisibleItemsChange?: (detail: CoreChartProps.VisibleItemsChangeDetail) => void;
3939
}
4040

4141
export interface State {

src/core/chart-api/chart-extra-legend.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import { ChartSeriesMarker, ChartSeriesMarkerType } from "../../internal/compone
77
import AsyncStore from "../../internal/utils/async-store";
88
import { getChartSeries } from "../../internal/utils/chart-series";
99
import { isEqualArrays } from "../../internal/utils/utils";
10-
import { CoreLegendItem } from "../interfaces";
10+
import { CoreChartProps } from "../interfaces";
1111
import { getChartLegendItems, getPointId, getSeriesId } from "../utils";
1212
import { ChartExtraContext } from "./chart-extra-context";
1313

1414
// The reactive state is used to propagate changes in legend items to the core legend React component.
1515
export interface ReactiveLegendState {
16-
items: readonly CoreLegendItem[];
16+
items: readonly CoreChartProps.LegendItem[];
1717
}
1818

1919
// Chart helper that implements custom legend behaviors.
@@ -88,8 +88,8 @@ export class ChartExtraLegend extends AsyncStore<ReactiveLegendState> {
8888
this.updateLegendItems(legendItems);
8989
};
9090

91-
private updateLegendItems = (nextItems: CoreLegendItem[]) => {
92-
function isLegendItemsEqual(a: CoreLegendItem, b: CoreLegendItem) {
91+
private updateLegendItems = (nextItems: CoreChartProps.LegendItem[]) => {
92+
function isLegendItemsEqual(a: CoreChartProps.LegendItem, b: CoreChartProps.LegendItem) {
9393
return (
9494
a.id === b.id &&
9595
a.name === b.name &&
@@ -116,7 +116,7 @@ export class ChartExtraLegend extends AsyncStore<ReactiveLegendState> {
116116

117117
function updateItemsVisibility(
118118
chart: Highcharts.Chart,
119-
legendItems: readonly CoreLegendItem[],
119+
legendItems: readonly CoreChartProps.LegendItem[],
120120
visibleItems?: readonly string[],
121121
) {
122122
const availableItemsSet = new Set(legendItems.map((i) => i.id));

src/core/components/core-legend.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useInternalI18n } from "@cloudscape-design/components/internal/do-not-u
66
import { ChartLegend as ChartLegendComponent } from "../../internal/components/chart-legend";
77
import { useSelector } from "../../internal/utils/async-store";
88
import { ChartAPI } from "../chart-api";
9-
import { BaseI18nStrings, GetLegendTooltipContent } from "../interfaces";
9+
import { BaseI18nStrings, CoreChartProps } from "../interfaces";
1010

1111
export function ChartLegend({
1212
api,
@@ -21,7 +21,7 @@ export function ChartLegend({
2121
actions?: React.ReactNode;
2222
position: "bottom" | "side";
2323
i18nStrings?: BaseI18nStrings;
24-
getLegendTooltipContent?: GetLegendTooltipContent;
24+
getLegendTooltipContent?: CoreChartProps.GetLegendTooltipContent;
2525
}) {
2626
const i18n = useInternalI18n("[charts]");
2727
const ariaLabel = i18n("i18nStrings.legendAriaLabel", i18nStrings?.legendAriaLabel);

src/core/components/core-tooltip.tsx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,7 @@ import { useSelector } from "../../internal/utils/async-store";
1313
import { getChartSeries } from "../../internal/utils/chart-series";
1414
import { ChartAPI } from "../chart-api";
1515
import { getFormatter } from "../formatters";
16-
import {
17-
BaseI18nStrings,
18-
CoreTooltipContent,
19-
CoreTooltipOptions,
20-
GetTooltipContent,
21-
GetTooltipContentProps,
22-
TooltipSlotProps,
23-
} from "../interfaces";
16+
import { BaseI18nStrings, CoreChartProps } from "../interfaces";
2417
import { getPointColor, getSeriesColor, getSeriesId, getSeriesMarkerType, isXThreshold } from "../utils";
2518

2619
import styles from "../styles.css.js";
@@ -51,9 +44,9 @@ export function ChartTooltip({
5144
getTooltipContent: getTooltipContentOverrides,
5245
api,
5346
i18nStrings,
54-
}: CoreTooltipOptions & {
47+
}: CoreChartProps.TooltipOptions & {
5548
i18nStrings?: BaseI18nStrings;
56-
getTooltipContent?: GetTooltipContent;
49+
getTooltipContent?: CoreChartProps.GetTooltipContent;
5750
api: ChartAPI;
5851
}) {
5952
const [expandedSeries, setExpandedSeries] = useState<ExpandedSeriesState>({});
@@ -122,7 +115,9 @@ function getTrackKey(point: null | Highcharts.Point, group: readonly Highcharts.
122115

123116
function getTooltipContent(
124117
api: ChartAPI,
125-
props: GetTooltipContentProps & { renderers?: CoreTooltipContent } & ExpandedSeriesStateProps,
118+
props: CoreChartProps.GetTooltipContentProps & {
119+
renderers?: CoreChartProps.TooltipContentRenderer;
120+
} & ExpandedSeriesStateProps,
126121
): null | RenderedTooltipContent {
127122
if (props.point && props.point.series.type === "pie") {
128123
return getTooltipContentPie(api, { ...props, point: props.point });
@@ -141,7 +136,9 @@ function getTooltipContentCartesian(
141136
expandedSeries,
142137
renderers = {},
143138
setExpandedSeries,
144-
}: GetTooltipContentProps & { renderers?: CoreTooltipContent } & ExpandedSeriesStateProps,
139+
}: CoreChartProps.GetTooltipContentProps & {
140+
renderers?: CoreChartProps.TooltipContentRenderer;
141+
} & ExpandedSeriesStateProps,
145142
): RenderedTooltipContent {
146143
// The cartesian tooltip might or might not have a selected point, but it always has a non-empty group.
147144
// By design, every point of the group has the same x value.
@@ -179,7 +176,7 @@ function getTooltipContentCartesian(
179176
});
180177
// We only support cartesian charts with a single x axis.
181178
const titleFormatter = getFormatter(chart.xAxis[0]);
182-
const slotRenderProps: TooltipSlotProps = { x, items: matchedItems };
179+
const slotRenderProps: CoreChartProps.TooltipSlotProps = { x, items: matchedItems };
183180
return {
184181
header: renderers.header?.(slotRenderProps) ?? titleFormatter(x),
185182
body: renderers.body?.(slotRenderProps) ?? (
@@ -205,9 +202,9 @@ function getTooltipContentCartesian(
205202

206203
function getTooltipContentPie(
207204
api: ChartAPI,
208-
{ point, renderers = {} }: { point: Highcharts.Point } & { renderers?: CoreTooltipContent },
205+
{ point, renderers = {} }: { point: Highcharts.Point } & { renderers?: CoreChartProps.TooltipContentRenderer },
209206
): RenderedTooltipContent {
210-
const tooltipDetails: TooltipSlotProps = { x: point.x, items: [{ point, errorRanges: [] }] };
207+
const tooltipDetails: CoreChartProps.TooltipSlotProps = { x: point.x, items: [{ point, errorRanges: [] }] };
211208
return {
212209
header: renderers.header?.(tooltipDetails) ?? (
213210
<div className={styles["tooltip-default-header"]}>

src/core/formatters.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import type Highcharts from "highcharts";
55

6-
import { InternalXAxisOptions, InternalYAxisOptions } from "./interfaces";
6+
import { CoreChartProps } from "./interfaces";
77

88
// Takes value formatter from the axis options (InternalXAxisOptions.valueFormatter or InternalYAxisOptions.valueFormatter),
99
// or provides a default formatter for numeric and datetime values.
@@ -21,7 +21,7 @@ export function getFormatter(axis?: Highcharts.Axis) {
2121
if (axis.options.type === "category") {
2222
return axis.categories?.[value] ?? value.toString();
2323
}
24-
const axisOptions = axis.userOptions as InternalXAxisOptions | InternalYAxisOptions;
24+
const axisOptions = axis.userOptions as CoreChartProps.XAxisOptions | CoreChartProps.YAxisOptions;
2525
if (axisOptions.valueFormatter) {
2626
return axisOptions.valueFormatter(value);
2727
}

src/core/i18n-utils.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import { useInternalI18n } from "@cloudscape-design/components/internal/do-not-use/i18n";
55

6-
import { CoreI18nStrings } from "./interfaces";
6+
import { CoreChartProps } from "./interfaces";
77

88
export interface ChartLabels {
99
chartLabel?: string;
@@ -21,7 +21,7 @@ export function useChartI18n({
2121
}: {
2222
ariaLabel?: string;
2323
ariaDescription?: string;
24-
i18nStrings?: CoreI18nStrings;
24+
i18nStrings?: CoreChartProps.I18nStrings;
2525
}) {
2626
const i18n = useInternalI18n("[charts]");
2727
const i18nPie = useInternalI18n("pie-chart");

0 commit comments

Comments
 (0)