ingred-ui 36.0.0 → 37.0.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.
@@ -19,6 +19,7 @@ export declare const ADVANCED_FILTER_CONSTANTS: {
19
19
  readonly CONFIG_PANEL_BUTTON_HEIGHT: 50;
20
20
  readonly CONFIG_PANEL_PADDING: 16;
21
21
  readonly CONFIG_PANEL_MIN_CONTENT_HEIGHT: 200;
22
+ readonly CONFIG_PANEL_VIEWPORT_MARGIN: 8;
22
23
  readonly TRANSITION_DURATION: 200;
23
24
  readonly MIN_VALUE_LENGTH: 1;
24
25
  };
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * このフックは、ConfigPanelでのキーボード操作ロジックを集約します。
5
5
  * - ESCキーでキャンセル
6
- * - Enterキーで適用(IME変換確定時のEnterキーは除外)
6
+ * - Enterキーで適用(IME変換確定時のEnterキーと、パネル内のリンク上のEnterキーは除外)
7
7
  * - ConfigPanel内の要素のみでEnterキーを有効化
8
8
  *
9
9
  * @example
@@ -3,8 +3,10 @@
3
3
  *
4
4
  * このフックは、Floating UIを使用したポジショニングロジックを集約します。
5
5
  * - 保存座標での仮想参照要素の作成
6
+ * - 位置と使える高さを、参照要素ごとに最初に求めた値に固定(スクロールしても再計算で動かさない。
7
+ * 保存座標が変わって参照要素を作り直したときは、その時点の値で取り直す)
6
8
  * - はみ出し防止(shift, size middleware)
7
- * - Content領域の最大高さの動的計算
9
+ * - Content領域の最大高さの動的計算(パネル自身の高さが変わったときに計算し直す)
8
10
  * - ContextMenu2と同じ方式の領域外クリック処理
9
11
  *
10
12
  * @example
@@ -15,11 +17,11 @@
15
17
  * getFloatingProps,
16
18
  * isPositioned,
17
19
  * contentMaxHeight,
18
- * } = useConfigPanelPosition({ isOpen, savedCoordinates, onCancel });
20
+ * } = useConfigPanelPosition({ isOpen, savedCoordinates, onCancel, contentRef });
19
21
  * ```
20
22
  */
21
23
  /// <reference types="react" />
22
- import { FloatingContext } from "@floating-ui/react";
24
+ import { FloatingContext, type Coords, type Middleware, type ReferenceElement } from "@floating-ui/react";
23
25
  export type MenuCoordinates = {
24
26
  x: number;
25
27
  y: number;
@@ -28,7 +30,35 @@ export type UseConfigPanelPositionProps = {
28
30
  isOpen: boolean;
29
31
  savedCoordinates?: MenuCoordinates | null;
30
32
  onCancel: () => void;
33
+ /** スクロールする Content 要素。渡すと、Content 以外の高さを実測して最大高さを決める */
34
+ contentRef?: React.RefObject<HTMLElement | null>;
31
35
  };
36
+ /**
37
+ * Content(スクロール領域)の最大高さを求める。
38
+ * ヘッダー・説明文・エラー・ボタンなど Content 以外の高さは、描画済みならパネルの実寸から求める。
39
+ * 未描画(高さ 0)のときは概算の定数で代用する。
40
+ */
41
+ export declare const calculateContentMaxHeight: ({ availableHeight, floatingHeight, contentHeight, }: {
42
+ availableHeight: number;
43
+ floatingHeight: number;
44
+ contentHeight: number | null;
45
+ }) => number;
46
+ /** 参照要素と、その参照要素で最初に求めた値の組 */
47
+ export type PinnedValue<T> = {
48
+ reference: ReferenceElement;
49
+ value: T;
50
+ };
51
+ /**
52
+ * パネルの位置を、参照要素ごとに最初に求めた位置に固定する middleware。
53
+ * 参照要素は開いた時点のビューポート座標で作った仮想要素なので、スクロールした後に位置を計算し直すと、
54
+ * パネルが開いた時点の画面位置へ戻ってしまう。基準の位置は固定し、
55
+ * 横のはみ出しの補正は後続の shift で、Content の最大高さは後続の size で求め直す
56
+ */
57
+ export declare const pinPositionAtOpen: (pinnedPositionRef: {
58
+ current: PinnedValue<Coords> | null;
59
+ }, latestReferenceRef: {
60
+ current: ReferenceElement | null;
61
+ }) => Middleware;
32
62
  export type UseConfigPanelPositionReturn = {
33
63
  refs: {
34
64
  setReference: (node: any) => void;
@@ -41,4 +71,4 @@ export type UseConfigPanelPositionReturn = {
41
71
  contentMaxHeight: number;
42
72
  context: FloatingContext;
43
73
  };
44
- export declare const useConfigPanelPosition: ({ isOpen, savedCoordinates, onCancel, }: UseConfigPanelPositionProps) => UseConfigPanelPositionReturn;
74
+ export declare const useConfigPanelPosition: ({ isOpen, savedCoordinates, onCancel, contentRef, }: UseConfigPanelPositionProps) => UseConfigPanelPositionReturn;
@@ -0,0 +1,12 @@
1
+ import React from "react";
2
+ import { FilterTypeConfig } from "../types";
3
+ export type ConfigPanelHelpProps = {
4
+ helpText: FilterTypeConfig["helpText"];
5
+ operator: string;
6
+ };
7
+ /**
8
+ * 項目の説明文を描画する。helpText が関数なら、ここで選択中のオペレーターを渡して呼ぶ。
9
+ * 関数をこのコンポーネントの中で呼ぶのは、関数の中で hooks が使われても、その hooks をこのコンポーネントに属させるため。
10
+ * ConfigPanel の中で呼ぶと、項目を切り替えたときに ConfigPanel の hooks の数が変わって落ちる
11
+ */
12
+ export declare const ConfigPanelHelp: React.FC<ConfigPanelHelpProps>;
@@ -149,6 +149,33 @@ export declare const MultiConditionLogicDividerLine: import("styled-components/d
149
149
  * セクション
150
150
  */
151
151
  export declare const Section: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never> & Partial<Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>>> & string;
152
+ /**
153
+ * 項目の説明文
154
+ * 上は Content の padding-bottom があるため margin-top を消す。下はボタン上の区切り線との間を空ける
155
+ */
156
+ export declare const ConfigPanelHelpText: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<{
157
+ className?: string | undefined;
158
+ prepend?: import("react").ReactNode;
159
+ children: import("react").ReactNode;
160
+ }, never> & Partial<Pick<{
161
+ className?: string | undefined;
162
+ prepend?: import("react").ReactNode;
163
+ children: import("react").ReactNode;
164
+ }, never>> & {
165
+ as?: import("styled-components").WebTarget | undefined;
166
+ forwardedAs?: import("styled-components").WebTarget | undefined;
167
+ }, never> & Partial<Pick<import("styled-components").FastOmit<{
168
+ className?: string | undefined;
169
+ prepend?: import("react").ReactNode;
170
+ children: import("react").ReactNode;
171
+ }, never> & Partial<Pick<{
172
+ className?: string | undefined;
173
+ prepend?: import("react").ReactNode;
174
+ children: import("react").ReactNode;
175
+ }, never>> & {
176
+ as?: import("styled-components").WebTarget | undefined;
177
+ forwardedAs?: import("styled-components").WebTarget | undefined;
178
+ }, never>>> & string;
152
179
  /**
153
180
  * エラーメッセージラッパー
154
181
  */
@@ -14,7 +14,7 @@
14
14
  * 注: FilterOperator, FilterInputType, FilterPresetType は src/utils/filterTypes.ts で
15
15
  * 定義され、本ファイルから re-export しています。
16
16
  */
17
- import type { MouseEvent } from "react";
17
+ import type { MouseEvent, ReactNode } from "react";
18
18
  import { Theme } from "../../themes";
19
19
  import type { IconName } from "../Icon";
20
20
  import type { FilterOperator, FilterInputType, FilterPresetType } from "../../utils/filterTypes";
@@ -156,6 +156,18 @@ export type FilterTypeConfig = {
156
156
  dateFormat?: string;
157
157
  /** 条件維持オプション。enabled 時のみ ConfigPanel にチェックボックスを表示 */
158
158
  persistOption?: FilterPersistOption;
159
+ /**
160
+ * ConfigPanel の入力欄の下(適用ボタンの上)に「?」アイコン付きで表示する説明文。
161
+ * multiConditionConfigs の有無に関わらず項目に 1 つ。未指定時は何も表示しない。
162
+ * `<p>` の中に描画されるため、渡せるのはインライン要素(リンク・強調など)まで。div や ul は不可。
163
+ * 関数を渡すと、選択中のオペレーターで説明文を出し分けられる。関数には、この項目の operators にあるオペレーターだけが渡る。
164
+ * ただし関数を評価するのは、multiConditionConfigs を指定していない項目だけ。multiConditionConfigs を指定した項目では、
165
+ * 条件が 1 つでも、関数を渡すと何も表示しない(条件ごとにオペレーターが違うため)。
166
+ * 関数は描画のたびに呼ばれるため、副作用のない純粋な関数にする。Promise は返さない(async 関数は渡さない。描画中にパネルごとサスペンドする)。
167
+ * 関数の中で hooks を使うときは、項目の label を一意にする。開いたまま label が同じ項目へ切り替えると、hooks の状態を持ち越す(hooks の数が違うとエラーになる)。
168
+ * 次の値は表示しない: null・undefined・false・""・0。それ以外(true・空の配列・何も描画しない要素など)は、中身が無くても「?」の行が出る
169
+ */
170
+ helpText?: ReactNode | ((operator: string) => ReactNode);
159
171
  };
160
172
  /**
161
173
  * 1つのフィルタリング条件(オペレーターと値の組み合わせ)
@@ -125,6 +125,12 @@ export declare const getTagBoldText: (filter: AppliedFilter) => string | string[
125
125
  * フィルタタイプが複数条件モードかどうかを判定
126
126
  */
127
127
  export declare const hasMultiConditions: (filterConfig?: FilterTypeConfig) => boolean;
128
+ /**
129
+ * ConfigPanel に説明文を出すかどうか。関数のときは、評価してよい場合だけ true を返す(評価は描画する側で行う)。
130
+ * 複数条件は条件ごとにオペレーターが違うため評価しない。その項目の operators にないオペレーターでも評価しない。
131
+ * 開いたまま別の項目に切り替えた直後の 1 レンダーは、前の項目のオペレーターが状態に残っているため
132
+ */
133
+ export declare const shouldRenderHelpText: (filterConfig: FilterTypeConfig | undefined, operator: string) => boolean;
128
134
  /**
129
135
  * 複数条件設定を取得する
130
136
  */
@@ -0,0 +1,4 @@
1
+ import * as React from "react";
2
+ import { PieChartProps } from "./types";
3
+ declare const PieChart: React.FC<PieChartProps>;
4
+ export default PieChart;
@@ -0,0 +1,2 @@
1
+ export { default as PieChart } from "./PieChart";
2
+ export type { PieChartProps, PieChartVariant, PieSlice, PieSliceLabel, PieSliceLabelStyle, } from "./types";
@@ -0,0 +1,79 @@
1
+ export type PieSlice = {
2
+ /** 表示名。凡例・表示切替の内部キーは index 付きで一意化する */
3
+ label: string;
4
+ /** 0 以下はスライスとして描画しない */
5
+ value: number;
6
+ /** 未指定時は theme.palette.chart の系列色を使う */
7
+ color?: string;
8
+ };
9
+ export type PieChartVariant = "pie" | "donut";
10
+ /** スライス外側ラベルの内容。none は非表示 */
11
+ export type PieSliceLabel = "none" | "value" | "percent" | "both";
12
+ /** スライス外側ラベルの見た目。未指定項目は theme.palette.chart.pie.label */
13
+ export type PieSliceLabelStyle = {
14
+ fontSize?: number;
15
+ color?: string;
16
+ };
17
+ export type PieChartProps = {
18
+ data: PieSlice[];
19
+ /** pie: 円 / donut: 穴あき。デフォルト pie */
20
+ variant?: PieChartVariant;
21
+ /**
22
+ * theme.palette.chart.colorSchemes のキー。
23
+ * 未指定時は palette.chart.series(デフォルト)を使う。
24
+ */
25
+ colorScheme?: string;
26
+ /**
27
+ * 数値の表示。tooltip のほか、外側ラベル・内側ラベル・donut 中央合計にも使う。
28
+ * 未指定時は toLocaleString()
29
+ */
30
+ valueFormatter?: (value: number) => string;
31
+ /**
32
+ * スライス外側のラベル。
33
+ * - none: 出さない(デフォルト)
34
+ * - value: 絶対値
35
+ * - percent: 構成比
36
+ * - both: 絶対値と構成比
37
+ */
38
+ sliceLabel?: PieSliceLabel;
39
+ /**
40
+ * スライス外側ラベルのフォントサイズ・色。
41
+ * 未指定項目は theme.palette.chart.pie.label を使う。
42
+ */
43
+ sliceLabelStyle?: PieSliceLabelStyle;
44
+ /**
45
+ * スライス内側のラベル。
46
+ * - none: 出さない(デフォルト)
47
+ * - value: 絶対値
48
+ * - percent: 構成比
49
+ * - both: 絶対値と構成比
50
+ */
51
+ innerLabel?: PieSliceLabel;
52
+ /**
53
+ * スライス内側ラベルのフォントサイズ・色。
54
+ * 色を省略したときはスライス色とのコントラストで白または theme 色を選ぶ。
55
+ */
56
+ innerLabelStyle?: PieSliceLabelStyle;
57
+ /** スライスが 2 個以上のとき凡例を表示。デフォルト true */
58
+ showLegend?: boolean;
59
+ /**
60
+ * donut の中央に表示中スライスの合計を出す。
61
+ * pie では無視。デフォルト true
62
+ */
63
+ showCenterTotal?: boolean;
64
+ /**
65
+ * donut 中央の合計のフォントサイズ・色。
66
+ * fontSize は数値に適用(「合計」はそれに合わせて小さめ)。
67
+ * 未指定時のサイズは穴の大きさから自動、色は theme.palette.chart.pie.centerTotal。
68
+ */
69
+ centerTotalStyle?: PieSliceLabelStyle;
70
+ /** 凡例クリックでスライスの表示/非表示を切り替え。デフォルト true */
71
+ interactiveLegend?: boolean;
72
+ /** true の間、チャートの代わりにローディング表示 */
73
+ loading?: boolean;
74
+ /** 描画可能なデータがないときのメッセージ。未指定時は「データがありません」 */
75
+ emptyMessage?: string;
76
+ "aria-label": string;
77
+ height?: number;
78
+ className?: string;
79
+ };
@@ -6,6 +6,8 @@ export { AreaChart } from "./AreaChart";
6
6
  export type { AreaChartLayout, AreaChartProps } from "./AreaChart";
7
7
  export { BarLineChart } from "./BarLineChart";
8
8
  export type { BarLineChartProps } from "./BarLineChart";
9
+ export { PieChart } from "./PieChart";
10
+ export type { PieChartProps, PieChartVariant, PieSlice, PieSliceLabel, PieSliceLabelStyle, } from "./PieChart";
9
11
  export type { BarSegment, BarChartOrientation, ChartHoverState, ChartReferenceLine, ChartReferenceLineAxis, ChartSeries, ResolvedChartSeries, } from "./types";
10
12
  export type { LinePoint, LinePathSegment, LineSeriesGeometry, } from "./internal/getLineSeries";
11
13
  export { computeYTicks, computeMaxStackedTotal } from "./internal/utils";
@@ -24,3 +26,5 @@ export { computeAreaChartMaxValue, getAreaSegments, getOverlayAreaPath, getStack
24
26
  export type { AreaPathSegment } from "./internal/getAreaPath";
25
27
  export { hasBarLineChartData } from "./internal/hasBarLineChartData";
26
28
  export { getBarLineChartAxisSeries, getBarLineChartDrawBarSeries, getBarLineChartReferenceLineLegendItems, getBarLineSeriesDisplayLabel, getBarLineSeriesKey, } from "./internal/getBarLineChartSeries";
29
+ export { describeSlicePath, formatPieSliceLabel, getPieCenterTotalValueFontSize, getPieSliceInnerLabelLayout, getPieSliceLabelGutter, getPieSliceLabelLayout, getPieDrawableSeriesLabels, getPieSliceDisplayLabel, getPieSliceKey, getPieSlices, getPieTotal, hasPieChartData, pickContrastingLabelColor, resolvePieCenterTotalStyle, resolvePieSliceLabelStyle, } from "./internal/getPieSlices";
30
+ export type { PieSliceGeometry, PieSliceInnerLabelLayout, PieSliceInput, PieSliceLabelGutterOptions, PieSliceLabelLayout, } from "./internal/getPieSlices";
@@ -0,0 +1,78 @@
1
+ export type PieSliceInput = {
2
+ /** React key / 凡例トグル用。未指定時は label */
3
+ id?: string;
4
+ label: string;
5
+ value: number;
6
+ color: string;
7
+ };
8
+ export type PieSliceGeometry = {
9
+ id: string;
10
+ label: string;
11
+ color: string;
12
+ value: number;
13
+ startAngle: number;
14
+ endAngle: number;
15
+ path: string;
16
+ };
17
+ /** 同名スライスを区別する内部キー */
18
+ export declare function getPieSliceKey(index: number, label: string): string;
19
+ export declare function getPieSliceDisplayLabel(seriesKey: string): string;
20
+ /** 凡例の last-1 ガード用。0 以下は描画しないのでカウントしない */
21
+ export declare function getPieDrawableSeriesLabels(series: readonly {
22
+ label: string;
23
+ data: readonly (number | null)[];
24
+ }[]): string[];
25
+ export declare function describeSlicePath(cx: number, cy: number, outerRadius: number, innerRadius: number, startAngle: number, endAngle: number): string;
26
+ export declare function hasPieChartData(data: readonly Pick<PieSliceInput, "value">[]): boolean;
27
+ /** 正の値だけを合計する(0 以下は無視) */
28
+ export declare function getPieTotal(data: readonly Pick<PieSliceInput, "value">[]): number;
29
+ export type PieSliceLabelGutterOptions = {
30
+ labels?: readonly string[];
31
+ fontSize?: number;
32
+ };
33
+ /** フォーマット済みラベルと fontSize から外側ラベル用の SVG 余白を取る */
34
+ export declare function getPieSliceLabelGutter(mode: "none" | "value" | "percent" | "both", options?: PieSliceLabelGutterOptions): {
35
+ x: number;
36
+ y: number;
37
+ };
38
+ export type PieSliceLabelLayout = {
39
+ midAngle: number;
40
+ lineStartX: number;
41
+ lineStartY: number;
42
+ lineEndX: number;
43
+ lineEndY: number;
44
+ textX: number;
45
+ textY: number;
46
+ textAnchor: "start" | "end";
47
+ percent: number;
48
+ };
49
+ /** スライス色に対してコントラストが高い方のラベル色を返す。解析できない色は darkColor */
50
+ export declare function pickContrastingLabelColor(background: string, lightColor: string, darkColor: string): string;
51
+ export declare function resolvePieSliceLabelStyle(themeStyle: {
52
+ fontSize: number;
53
+ color: string;
54
+ }, override?: {
55
+ fontSize?: number;
56
+ color?: string;
57
+ }): {
58
+ fontSize: number;
59
+ color: string;
60
+ };
61
+ /** donut 中央の数値サイズ。穴とフォーマット済み文字列の幅から 12〜24 に収める */
62
+ export declare function getPieCenterTotalValueFontSize(innerRadius: number, formattedValue?: string): number;
63
+ export declare function resolvePieCenterTotalStyle(themeColor: string, autoFontSize: number, override?: {
64
+ fontSize?: number;
65
+ color?: string;
66
+ }): {
67
+ fontSize: number;
68
+ color: string;
69
+ captionFontSize: number;
70
+ };
71
+ export declare function formatPieSliceLabel(value: number, total: number, mode: "value" | "percent" | "both", valueFormatter: (value: number) => string, percentFormatter: (value: number) => string): string;
72
+ export declare function getPieSliceLabelLayout(startAngle: number, endAngle: number, value: number, total: number, cx: number, cy: number, outerRadius: number): PieSliceLabelLayout | null;
73
+ export type PieSliceInnerLabelLayout = {
74
+ x: number;
75
+ y: number;
76
+ };
77
+ export declare function getPieSliceInnerLabelLayout(startAngle: number, endAngle: number, cx: number, cy: number, outerRadius: number, innerRadius: number): PieSliceInnerLabelLayout | null;
78
+ export declare function getPieSlices(data: readonly PieSliceInput[], cx: number, cy: number, outerRadius: number, innerRadius: number): PieSliceGeometry[];