From dc0b07f791016a852aaceca3ca0b67138e50ddc3 Mon Sep 17 00:00:00 2001 From: Andrei Zhaleznichenka Date: Fri, 10 Jul 2026 15:30:31 +0200 Subject: [PATCH] chore: Split public and internal interface --- .../__snapshots__/documenter.test.ts.snap | 20 ++++++------ src/__tests__/utils.ts | 1 + src/cartesian-chart/interfaces.ts | 2 +- src/core/interfaces.ts | 31 +++++++++++++------ src/internal/events/index.ts | 7 ++--- src/pie-chart/interfaces.ts | 2 +- src/types/events.ts | 7 +++++ 7 files changed, 45 insertions(+), 25 deletions(-) create mode 100644 src/types/events.ts diff --git a/src/__tests__/__snapshots__/documenter.test.ts.snap b/src/__tests__/__snapshots__/documenter.test.ts.snap index 4b6863fc..c4af9741 100644 --- a/src/__tests__/__snapshots__/documenter.test.ts.snap +++ b/src/__tests__/__snapshots__/documenter.test.ts.snap @@ -1167,7 +1167,7 @@ exports[`internal core API matches snapshot > internal-core-chart 1`] = ` "properties": [ { "inlineType": { - "name": "LegendItem", + "name": "CoreChartProps.LegendItem", "properties": [ { "name": "highlighted", @@ -1204,7 +1204,7 @@ exports[`internal core API matches snapshot > internal-core-chart 1`] = ` }, "name": "item", "optional": false, - "type": "LegendItem", + "type": "CoreChartProps.LegendItem", }, ], "type": "object", @@ -1222,10 +1222,10 @@ exports[`internal core API matches snapshot > internal-core-chart 1`] = ` "type": "union", "valueDescriptions": undefined, "values": [ - "{ items: ReadonlyArray; } & CoreChartProps.ApiInteraction", - "{ items: ReadonlyArray; } & CoreChartProps.FilterInteraction", - "{ items: ReadonlyArray; } & CoreChartProps.ToggleInteraction", - "{ items: ReadonlyArray; } & CoreChartProps.SelectInteraction", + "{ items: ReadonlyArray; } & CoreChartProps.ApiInteraction", + "{ items: ReadonlyArray; } & CoreChartProps.FilterInteraction", + "{ items: ReadonlyArray; } & CoreChartProps.ToggleInteraction", + "{ items: ReadonlyArray; } & CoreChartProps.SelectInteraction", ], }, "detailType": "CoreChartProps.VisibleItemsChangeDetail", @@ -1455,20 +1455,20 @@ minimum width, the horizontal scrollbar is automatically added.", If not provided, no tooltip will be displayed.", "i18nTag": undefined, "inlineType": { - "name": "GetLegendTooltipContent", + "name": "CoreChartProps.GetLegendTooltipContent", "parameters": [ { "name": "props", - "type": "GetLegendTooltipContentProps", + "type": "CoreChartProps.GetLegendTooltipContentProps", }, ], - "returnType": "LegendTooltipContent", + "returnType": "CoreChartProps.LegendTooltipContent", "type": "function", }, "name": "getLegendTooltipContent", "optional": true, "systemTags": undefined, - "type": "GetLegendTooltipContent", + "type": "CoreChartProps.GetLegendTooltipContent", "visualRefreshTag": undefined, }, { diff --git a/src/__tests__/utils.ts b/src/__tests__/utils.ts index 76f2fa42..397236d3 100644 --- a/src/__tests__/utils.ts +++ b/src/__tests__/utils.ts @@ -16,6 +16,7 @@ export function getAllComponents(): string[] { name !== "internal" && name !== "internal-do-not-use" && name !== "test-utils" && + name !== "types" && !name.includes(".") && !name.includes("LICENSE") && !name.includes("NOTICE"), diff --git a/src/cartesian-chart/interfaces.ts b/src/cartesian-chart/interfaces.ts index e5203545..87bc0210 100644 --- a/src/cartesian-chart/interfaces.ts +++ b/src/cartesian-chart/interfaces.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import * as CoreTypes from "../core/interfaces"; -import { NonCancelableEventHandler } from "../internal/events"; +import { NonCancelableEventHandler } from "../types/events"; // CartesianChartProps is the type for CartesianChart React component properties. Unlike in Highcharts API, // we pass options directly to the component, instead of grouping them all into a single "options" property. diff --git a/src/core/interfaces.ts b/src/core/interfaces.ts index e337f21b..9c910817 100644 --- a/src/core/interfaces.ts +++ b/src/core/interfaces.ts @@ -3,9 +3,9 @@ import type Highcharts from "highcharts"; -import type * as InternalComponentTypes from "../internal/components/interfaces"; -import { ChartSeriesMarkerStatus } from "../internal/components/series-marker/interfaces"; -import { type NonCancelableEventHandler } from "../internal/events"; +import { type NonCancelableEventHandler } from "../types/events"; + +export type ChartSeriesMarkerStatus = "warning" | "default"; // All charts take `highcharts` instance, that can be served statically or dynamically. // Although it has to be of type Highcharts, the TS type we use is `null | object`, so @@ -527,10 +527,23 @@ export namespace CoreChartProps { export type LegendOptionsHorizontalAlignment = "start" | "center"; - export type LegendItem = InternalComponentTypes.LegendItem; - export type LegendTooltipContent = InternalComponentTypes.LegendTooltipContent; - export type GetLegendTooltipContent = InternalComponentTypes.GetLegendTooltipContent; - export type GetLegendTooltipContentProps = InternalComponentTypes.GetLegendTooltipContentProps; + export interface LegendItem { + id: string; + name: string; + marker: React.ReactNode; + visible: boolean; + highlighted: boolean; + isSecondary?: boolean; + } + export interface LegendTooltipContent { + header: React.ReactNode; + body: React.ReactNode; + footer?: React.ReactNode; + } + export type GetLegendTooltipContent = (props: GetLegendTooltipContentProps) => LegendTooltipContent; + export interface GetLegendTooltipContentProps { + legendItem: LegendItem; + } export interface TooltipOptions { enabled?: boolean; @@ -624,8 +637,8 @@ export interface CoreLegendProps { } export namespace CoreLegendProps { - export type Item = InternalComponentTypes.LegendItem; - export type GetTooltipContent = InternalComponentTypes.GetLegendTooltipContent; + export type Item = CoreChartProps.LegendItem; + export type GetTooltipContent = CoreChartProps.GetLegendTooltipContent; export interface ItemHighlightDetail { item: Item; } diff --git a/src/internal/events/index.ts b/src/internal/events/index.ts index 2bca327c..0a4b33ec 100644 --- a/src/internal/events/index.ts +++ b/src/internal/events/index.ts @@ -1,12 +1,11 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -export type CancelableEventHandler = (event: CustomEvent) => void; +import { NonCancelableEventHandler } from "../../types/events"; -// eslint-disable-next-line @typescript-eslint/no-empty-object-type -export type NonCancelableEventHandler = (event: NonCancelableCustomEvent) => void; +export type { NonCancelableCustomEvent, NonCancelableEventHandler } from "../../types/events"; -export type NonCancelableCustomEvent = Omit, "preventDefault">; +export type CancelableEventHandler = (event: CustomEvent) => void; export interface ClickDetail { button: number; diff --git a/src/pie-chart/interfaces.ts b/src/pie-chart/interfaces.ts index 08f3cd1e..5d53360b 100644 --- a/src/pie-chart/interfaces.ts +++ b/src/pie-chart/interfaces.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import * as CoreTypes from "../core/interfaces"; -import { NonCancelableEventHandler } from "../internal/events"; +import { NonCancelableEventHandler } from "../types/events"; // PieChartProps is the type for PieChart React component properties. Unlike in Highcharts API, // we pass options directly to the component, instead of grouping them all into a single "options" property. diff --git a/src/types/events.ts b/src/types/events.ts new file mode 100644 index 00000000..06ad03fa --- /dev/null +++ b/src/types/events.ts @@ -0,0 +1,7 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +export type NonCancelableCustomEvent = Omit, "preventDefault">; + +// eslint-disable-next-line @typescript-eslint/no-empty-object-type +export type NonCancelableEventHandler = (event: NonCancelableCustomEvent) => void;