fis-component 0.1.21 → 0.1.22

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.
@@ -0,0 +1,23 @@
1
+ import { Meta } from "@storybook/react";
2
+ import { ApiSelectProps } from "./types";
3
+ type PlaygroundProps = ApiSelectProps<string, number>;
4
+ declare const _default: Meta<PlaygroundProps>;
5
+ export default _default;
6
+ export declare const Playground: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, PlaygroundProps>;
7
+ export declare const LoadMore_ServerSearch: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, import("@storybook/react").Args>;
8
+ export declare const LoadAll_ClientSearch: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, import("@storybook/react").Args>;
9
+ export declare const MultiSelect: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, import("@storybook/react").Args>;
10
+ export declare const LoadMore_CursorPagination: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, import("@storybook/react").Args>;
11
+ export declare const Cascading: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, import("@storybook/react").Args>;
12
+ export declare const ErrorAndRetry: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, import("@storybook/react").Args>;
13
+ export declare const Preselected_DefaultOptions: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, import("@storybook/react").Args>;
14
+ export declare const Preselected_FetchByIds: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, import("@storybook/react").Args>;
15
+ export declare const SearchDebounce: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, import("@storybook/react").Args>;
16
+ export declare const PrefetchOnMount: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, import("@storybook/react").Args>;
17
+ export declare const ReuseAndRefresh: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, import("@storybook/react").Args>;
18
+ export declare const AutoFill: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, import("@storybook/react").Args>;
19
+ export declare const ReopenClearsMoreError: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, import("@storybook/react").Args>;
20
+ export declare const PinSelectedOnTop: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, import("@storybook/react").Args>;
21
+ export declare const Virtualized: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, import("@storybook/react").Args>;
22
+ export declare const RealApi_LoadMore: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, import("@storybook/react").Args>;
23
+ export declare const RealApi_LoadAll: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, import("@storybook/react").Args>;
@@ -0,0 +1,7 @@
1
+ import { ForwardedRef } from "react";
2
+ import { ApiSelectProps, ApiSelectRef } from "./types";
3
+ declare function ApiSelectInner<T extends string | number, P = unknown>(props: ApiSelectProps<T, P>, ref: ForwardedRef<ApiSelectRef<T>>): import("react/jsx-runtime").JSX.Element;
4
+ declare const FISApiSelect: <T extends string | number = string, P = unknown>(props: ApiSelectProps<T, P> & {
5
+ ref?: ForwardedRef<ApiSelectRef<T>>;
6
+ }) => ReturnType<typeof ApiSelectInner>;
7
+ export default FISApiSelect;
@@ -0,0 +1,2 @@
1
+ export declare const DivFooterRowSC: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
2
+ export declare const ButtonRetrySC: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, never>> & string;
@@ -0,0 +1,109 @@
1
+ import { FISSelectRef, SelectProps, SelectOptionItem } from "../Select/types";
2
+ export type ApiSelectMode = "loadmore" | "all";
3
+ export type ApiSearchMode = "server" | "client";
4
+ /** Tham số backend cần (query filter, id cha cho cascading, ...). */
5
+ export type ApiSelectParams = Record<string, unknown>;
6
+ /** Tham số truyền vào fetcher ở chế độ "all" (API trả hết trong 1 lần). */
7
+ export interface FetchAllParams {
8
+ search: string;
9
+ params?: ApiSelectParams;
10
+ signal: AbortSignal;
11
+ }
12
+ /** fetcher cho mode="all": trả về toàn bộ options. */
13
+ export type FetchAll<T extends string | number> = (params: FetchAllParams) => Promise<SelectOptionItem<T>[]>;
14
+ /** Tham số truyền vào fetcher ở chế độ "loadmore" (phân trang). */
15
+ export interface FetchPageParams<P = unknown> {
16
+ search: string;
17
+ params?: ApiSelectParams;
18
+ /** undefined ở lần load đầu; sau đó là nextPageParam của kỳ trước. */
19
+ pageParam?: P;
20
+ signal: AbortSignal;
21
+ }
22
+ /** Kết quả 1 trang. pageParam gói được page/offset/cursor tuỳ backend. */
23
+ export interface FetchPageResult<T extends string | number, P = unknown> {
24
+ options: SelectOptionItem<T>[];
25
+ hasMore: boolean;
26
+ nextPageParam?: P;
27
+ }
28
+ /** fetcher cho mode="loadmore". */
29
+ export type FetchPage<T extends string | number, P = unknown> = (params: FetchPageParams<P>) => Promise<FetchPageResult<T, P>>;
30
+ export type ApiSelectFetcher<T extends string | number, P = unknown> = FetchAll<T> | FetchPage<T, P>;
31
+ /** Pha đang tải: lần đầu hay tải thêm. */
32
+ export type ApiSelectPhase = "initial" | "more";
33
+ interface ApiSelectOwnProps<T extends string | number, P = unknown> {
34
+ /** "loadmore" (phân trang, mặc định) hoặc "all" (API trả hết trong 1 lần). */
35
+ mode?: ApiSelectMode;
36
+ /** Hàm gọi API. Ký hiệu tuỳ mode (FetchAll hoặc FetchPage). */
37
+ fetcher: ApiSelectFetcher<T, P>;
38
+ /** "server" gửi keyword lên API; "client" lọc trên options đã tải.
39
+ * Mặc định: all -> client, loadmore -> server. */
40
+ searchMode?: ApiSearchMode;
41
+ /** Debounce (ms) cho search server. Mặc định 300. */
42
+ searchDebounce?: number;
43
+ /** Tham số động cho fetcher. Đổi -> reset + refetch (dùng cho cascading). */
44
+ params?: ApiSelectParams;
45
+ /** false -> không gọi API (vd chưa chọn điều kiện cha). Mặc định true. */
46
+ fetchEnabled?: boolean;
47
+ /** true -> chỉ gọi API khi mở dropdown; false -> prefetch khi mount. Mặc định true. */
48
+ fetchOnOpen?: boolean;
49
+ /** true (mặc định): đã tải cho query hiện tại thì mở lại không gọi lại API.
50
+ * false: mỗi lần mở dropdown đều gọi API lại. */
51
+ reuseOnReopen?: boolean;
52
+ /** true (mặc định, chỉ mode="loadmore"): tự tải thêm trang cho tới khi đủ item
53
+ * để dropdown cuộn được (tránh kẹt loadmore khi trang đầu quá ngắn). */
54
+ autoFill?: boolean;
55
+ /**
56
+ * Số item TỐI THIỂU cần có thì mới dừng auto-fill. Mặc định 12.
57
+ *
58
+ * ⚠️ Đây là ước lượng theo SỐ ITEM, KHÔNG đo chiều cao container/item thật. Vì
59
+ * dropdown render trong portal nên hook không đo được DOM. Bạn phải tự truyền số
60
+ * phù hợp với `maxHeight` và `size` của mình.
61
+ *
62
+ * Công thức chọn số (mục tiêu: "vừa đủ để có thanh cuộn"):
63
+ * autoFillMinItems ≈ ceil(chiềuCaoVùngList / chiềuCao1Item) + 1
64
+ * • chiềuCaoVùngList = `maxHeight` bạn truyền cho Select (token mặc định 780px
65
+ * nhưng thực tế bị giới hạn bởi viewport/popper). Trừ ~40px nếu có ô search.
66
+ * • chiềuCao1Item ≈ min-height MenuItem + gap 4px:
67
+ * size="md" → ~40px (36 + 4)
68
+ * size="lg" → ~48px (44 + 4)
69
+ *
70
+ * Ví dụ: maxHeight=320, có search, size md → ceil((320-40)/40)+1 ≈ 8 → truyền 8–9.
71
+ * Nên truyền DƯ một chút (chắc chắn có scroll); truyền THIẾU có thể vẫn kẹt loadmore.
72
+ * Lưu ý: số càng lớn thì lần mở đầu tải càng nhiều trang.
73
+ */
74
+ autoFillMinItems?: number;
75
+ /**
76
+ * true: ghim option ĐÃ CHỌN nhưng chưa có trong list API (resolve qua
77
+ * `defaultSelectedOptions`/`fetchByIds`) lên ĐẦU dropdown. Mặc định false (đưa
78
+ * xuống cuối). Ở multi-select `MenuSelect` vốn tự gom nhóm "Selected" lên đầu
79
+ * nên prop này chủ yếu tác động tới single-select. */
80
+ pinSelectedOnTop?: boolean;
81
+ /** Options đã biết trước cho value đã chọn (form edit) -> hiện label đúng. */
82
+ defaultSelectedOptions?: SelectOptionItem<T>[];
83
+ /** Gọi API lấy option theo id khi thiếu label của value đã chọn. */
84
+ fetchByIds?: (ids: T[]) => Promise<SelectOptionItem<T>[]>;
85
+ /** Callback khi tải xong (danh sách hiện có). */
86
+ onLoaded?: (options: SelectOptionItem<T>[], phase: ApiSelectPhase) => void;
87
+ /** Callback khi lỗi. (Tên `onFetchError` để tránh đụng handler `onError` của input.) */
88
+ onFetchError?: (error: unknown, phase: ApiSelectPhase) => void;
89
+ /** Text tuỳ biến (i18n). */
90
+ loadingMoreText?: string;
91
+ errorText?: string;
92
+ retryText?: string;
93
+ }
94
+ /** Omit phân phối trên union single/multi để giữ discriminant `multi`. */
95
+ type DistributiveOmit<T, K extends keyof T> = T extends unknown ? Omit<T, K> : never;
96
+ export type ApiSelectProps<T extends string | number = string, P = unknown> = DistributiveOmit<SelectProps<T>, "options" | "searchValue" | "onSearchChange" | "onPopupScroll" | "onOpen" | "loading" | "noData" | "noResult" | "footer"> & ApiSelectOwnProps<T, P>;
97
+ export interface ApiSelectRef<T extends string | number = string> extends FISSelectRef {
98
+ /** Tải lại theo search/params hiện tại (giữ nguyên keyword đang gõ). */
99
+ refresh: () => void;
100
+ /**
101
+ * Reset về trạng thái đầu: xoá keyword tìm kiếm rồi tải lại trang 1.
102
+ * Muốn đổi params (cascading) thì cập nhật prop `params` — component tự
103
+ * reset + refetch, không cần truyền qua `reload`.
104
+ */
105
+ reload: () => void;
106
+ /** Lấy danh sách options hiện có. */
107
+ getOptions: () => SelectOptionItem<T>[];
108
+ }
109
+ export {};
@@ -0,0 +1,52 @@
1
+ import { SelectOption, SelectOptionItem } from "../Select/types";
2
+ import { ApiSelectMode, ApiSelectParams, ApiSearchMode, ApiSelectPhase, FetchPageParams } from "./types";
3
+ /**
4
+ * Ngưỡng auto-fill mặc định: số item tối thiểu để dropdown chắc chắn có thanh cuộn.
5
+ * Đây là ước lượng CỐ ĐỊNH (không đo DOM). Hợp với dropdown thấp (~maxHeight 320-420,
6
+ * item size md). Nếu maxHeight lớn / item cao, truyền `autoFillMinItems` lớn hơn.
7
+ * Xem công thức chọn số trong JSDoc của prop `autoFillMinItems` (types.ts).
8
+ */
9
+ export declare const DEFAULT_AUTO_FILL_MIN_ITEMS = 12;
10
+ export interface UseApiSelectOptions<T extends string | number, P = unknown> {
11
+ mode: ApiSelectMode;
12
+ fetcher: (params: FetchPageParams<P>) => Promise<unknown>;
13
+ searchMode: ApiSearchMode;
14
+ params?: ApiSelectParams;
15
+ fetchEnabled: boolean;
16
+ fetchOnOpen: boolean;
17
+ /** true (mặc định): đã tải cho query hiện tại thì mở lại không gọi lại API. */
18
+ reuseOnReopen: boolean;
19
+ /** true (mặc định): loadmore tự tải thêm trang cho tới khi đủ item để cuộn. */
20
+ autoFill: boolean;
21
+ /** Số item tối thiểu để dừng auto-fill (xem DEFAULT_AUTO_FILL_MIN_ITEMS). */
22
+ autoFillMinItems: number;
23
+ /** true: ghim option đã chọn (chưa có trong list) lên ĐẦU thay vì cuối. */
24
+ pinSelectedOnTop: boolean;
25
+ defaultSelectedOptions?: SelectOptionItem<T>[];
26
+ fetchByIds?: (ids: T[]) => Promise<SelectOptionItem<T>[]>;
27
+ onLoaded?: (options: SelectOptionItem<T>[], phase: ApiSelectPhase) => void;
28
+ onFetchError?: (error: unknown, phase: ApiSelectPhase) => void;
29
+ /** Giá trị đang chọn (single: 1 phần tử; multi: nhiều) để giữ label. */
30
+ selectedValues: T[];
31
+ }
32
+ export declare function useApiSelect<T extends string | number, P = unknown>(opts: UseApiSelectOptions<T, P>): {
33
+ groups: SelectOption<T>[];
34
+ loading: boolean;
35
+ inFlightInitial: boolean;
36
+ inFlightMore: boolean;
37
+ errorInitial: unknown;
38
+ errorMore: unknown;
39
+ hasMore: boolean;
40
+ noData: boolean;
41
+ noResult: boolean;
42
+ serverSearch: string;
43
+ handleOpen: () => void;
44
+ handlePopupScroll: (e: React.UIEvent<HTMLElement>) => void;
45
+ handleServerSearch: (value: string) => void;
46
+ handleUiSearch: (value: string) => void;
47
+ refresh: () => void;
48
+ reload: () => void;
49
+ getOptions: () => SelectOptionItem<T>[];
50
+ retryInitial: () => undefined;
51
+ retryMore: () => undefined;
52
+ };
@@ -11,6 +11,7 @@ export declare const MenuContent: import("styled-components/dist/types").IStyled
11
11
  $removeSelectedGroup?: boolean;
12
12
  }>> & string;
13
13
  export declare const FixedBottomSection: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
14
+ export declare const DivFooterSC: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
14
15
  export declare const PGroupLabel: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, never>> & string;
15
16
  export declare const MenuSelectDropdownGlobalStyle: import("react").NamedExoticComponent<import("styled-components").ExecutionProps & {
16
17
  theme: import("../..").ThemeType;
@@ -34,6 +34,26 @@ export interface MenuProps {
34
34
  onPopupScroll?: (e: React.UIEvent<HTMLElement>) => void;
35
35
  normalizeTextSearch?: boolean;
36
36
  renderOption?: (item: MenuItem) => React.ReactNode;
37
+ /** Debounce (ms) trước khi phát onSearchChange. Mặc định 300. */
38
+ searchDebounce?: number;
39
+ /** Nội dung hiển thị ở đáy danh sách (loadmore spinner / dòng lỗi + retry). */
40
+ footer?: React.ReactNode;
41
+ /** Ép hiện/ẩn ô tìm kiếm, ghi đè logic tự động theo số lượng item. */
42
+ showSearch?: boolean;
43
+ /** Quan sát text search đã debounce (không ảnh hưởng việc lọc client). */
44
+ onSearchInput?: (value: string) => void;
45
+ /**
46
+ * Bật windowing thật cho list dài: chỉ render các item trong viewport (giống
47
+ * virtual list của antd). Giảm mạnh số DOM node/Tooltip khi có vài nghìn item.
48
+ * Yêu cầu chiều cao item ĐỒNG NHẤT (xem `virtualItemHeight`). Mặc định false.
49
+ */
50
+ virtualized?: boolean;
51
+ /**
52
+ * Chiều cao CỐ ĐỊNH mỗi hàng (px) khi `virtualized` — dùng để tính vị trí. Mặc
53
+ * định = item + gap: md 40 (36+4), lg 48 (44+4). Phải khớp chiều cao thực của
54
+ * item (item nhiều dòng/description cần tăng giá trị này để không chồng/lệch).
55
+ */
56
+ virtualItemHeight?: number;
37
57
  }
38
58
  export interface MenuState {
39
59
  search: string;
@@ -43,6 +43,8 @@ export { default as FISProgressCircular } from "./components/ProgressCircular";
43
43
  export { default as FISProgressLinear } from "./components/ProgressLinear";
44
44
  export { default as FISSplitButton } from "./components/SplitButton";
45
45
  export { default as FISSelect } from "./components/Select";
46
+ export { default as FISApiSelect } from "./components/ApiSelect";
47
+ export type { ApiSelectProps, ApiSelectRef, FetchAll, FetchPage, FetchPageParams, FetchPageResult, FetchAllParams, } from "./components/ApiSelect/types";
46
48
  export { default as FISSelectItem } from "./components/SelectItem";
47
49
  export { default as useNotification } from "./components/Notification/useNotification";
48
50
  export { default as useToast } from "./components/Toast/useToast";
package/dist/index.d.ts CHANGED
@@ -4048,6 +4048,26 @@ interface MenuProps {
4048
4048
  onPopupScroll?: (e: React.UIEvent<HTMLElement>) => void;
4049
4049
  normalizeTextSearch?: boolean;
4050
4050
  renderOption?: (item: MenuItem) => React.ReactNode;
4051
+ /** Debounce (ms) trước khi phát onSearchChange. Mặc định 300. */
4052
+ searchDebounce?: number;
4053
+ /** Nội dung hiển thị ở đáy danh sách (loadmore spinner / dòng lỗi + retry). */
4054
+ footer?: React.ReactNode;
4055
+ /** Ép hiện/ẩn ô tìm kiếm, ghi đè logic tự động theo số lượng item. */
4056
+ showSearch?: boolean;
4057
+ /** Quan sát text search đã debounce (không ảnh hưởng việc lọc client). */
4058
+ onSearchInput?: (value: string) => void;
4059
+ /**
4060
+ * Bật windowing thật cho list dài: chỉ render các item trong viewport (giống
4061
+ * virtual list của antd). Giảm mạnh số DOM node/Tooltip khi có vài nghìn item.
4062
+ * Yêu cầu chiều cao item ĐỒNG NHẤT (xem `virtualItemHeight`). Mặc định false.
4063
+ */
4064
+ virtualized?: boolean;
4065
+ /**
4066
+ * Chiều cao CỐ ĐỊNH mỗi hàng (px) khi `virtualized` — dùng để tính vị trí. Mặc
4067
+ * định = item + gap: md 40 (36+4), lg 48 (44+4). Phải khớp chiều cao thực của
4068
+ * item (item nhiều dòng/description cần tăng giá trị này để không chồng/lệch).
4069
+ */
4070
+ virtualItemHeight?: number;
4051
4071
  }
4052
4072
 
4053
4073
  declare const FISMenuSelect: React__default.FC<MenuProps>;
@@ -4544,6 +4564,119 @@ interface FISSelectRef {
4544
4564
 
4545
4565
  declare const FISSelect: React$1.ForwardRefExoticComponent<SelectProps<string | number> & React$1.RefAttributes<FISSelectRef>>;
4546
4566
 
4567
+ type ApiSelectMode = "loadmore" | "all";
4568
+ type ApiSearchMode = "server" | "client";
4569
+ /** Tham số backend cần (query filter, id cha cho cascading, ...). */
4570
+ type ApiSelectParams = Record<string, unknown>;
4571
+ /** Tham số truyền vào fetcher ở chế độ "all" (API trả hết trong 1 lần). */
4572
+ interface FetchAllParams {
4573
+ search: string;
4574
+ params?: ApiSelectParams;
4575
+ signal: AbortSignal;
4576
+ }
4577
+ /** fetcher cho mode="all": trả về toàn bộ options. */
4578
+ type FetchAll<T extends string | number> = (params: FetchAllParams) => Promise<SelectOptionItem<T>[]>;
4579
+ /** Tham số truyền vào fetcher ở chế độ "loadmore" (phân trang). */
4580
+ interface FetchPageParams<P = unknown> {
4581
+ search: string;
4582
+ params?: ApiSelectParams;
4583
+ /** undefined ở lần load đầu; sau đó là nextPageParam của kỳ trước. */
4584
+ pageParam?: P;
4585
+ signal: AbortSignal;
4586
+ }
4587
+ /** Kết quả 1 trang. pageParam gói được page/offset/cursor tuỳ backend. */
4588
+ interface FetchPageResult<T extends string | number, P = unknown> {
4589
+ options: SelectOptionItem<T>[];
4590
+ hasMore: boolean;
4591
+ nextPageParam?: P;
4592
+ }
4593
+ /** fetcher cho mode="loadmore". */
4594
+ type FetchPage<T extends string | number, P = unknown> = (params: FetchPageParams<P>) => Promise<FetchPageResult<T, P>>;
4595
+ type ApiSelectFetcher<T extends string | number, P = unknown> = FetchAll<T> | FetchPage<T, P>;
4596
+ /** Pha đang tải: lần đầu hay tải thêm. */
4597
+ type ApiSelectPhase = "initial" | "more";
4598
+ interface ApiSelectOwnProps<T extends string | number, P = unknown> {
4599
+ /** "loadmore" (phân trang, mặc định) hoặc "all" (API trả hết trong 1 lần). */
4600
+ mode?: ApiSelectMode;
4601
+ /** Hàm gọi API. Ký hiệu tuỳ mode (FetchAll hoặc FetchPage). */
4602
+ fetcher: ApiSelectFetcher<T, P>;
4603
+ /** "server" gửi keyword lên API; "client" lọc trên options đã tải.
4604
+ * Mặc định: all -> client, loadmore -> server. */
4605
+ searchMode?: ApiSearchMode;
4606
+ /** Debounce (ms) cho search server. Mặc định 300. */
4607
+ searchDebounce?: number;
4608
+ /** Tham số động cho fetcher. Đổi -> reset + refetch (dùng cho cascading). */
4609
+ params?: ApiSelectParams;
4610
+ /** false -> không gọi API (vd chưa chọn điều kiện cha). Mặc định true. */
4611
+ fetchEnabled?: boolean;
4612
+ /** true -> chỉ gọi API khi mở dropdown; false -> prefetch khi mount. Mặc định true. */
4613
+ fetchOnOpen?: boolean;
4614
+ /** true (mặc định): đã tải cho query hiện tại thì mở lại không gọi lại API.
4615
+ * false: mỗi lần mở dropdown đều gọi API lại. */
4616
+ reuseOnReopen?: boolean;
4617
+ /** true (mặc định, chỉ mode="loadmore"): tự tải thêm trang cho tới khi đủ item
4618
+ * để dropdown cuộn được (tránh kẹt loadmore khi trang đầu quá ngắn). */
4619
+ autoFill?: boolean;
4620
+ /**
4621
+ * Số item TỐI THIỂU cần có thì mới dừng auto-fill. Mặc định 12.
4622
+ *
4623
+ * ⚠️ Đây là ước lượng theo SỐ ITEM, KHÔNG đo chiều cao container/item thật. Vì
4624
+ * dropdown render trong portal nên hook không đo được DOM. Bạn phải tự truyền số
4625
+ * phù hợp với `maxHeight` và `size` của mình.
4626
+ *
4627
+ * Công thức chọn số (mục tiêu: "vừa đủ để có thanh cuộn"):
4628
+ * autoFillMinItems ≈ ceil(chiềuCaoVùngList / chiềuCao1Item) + 1
4629
+ * • chiềuCaoVùngList = `maxHeight` bạn truyền cho Select (token mặc định 780px
4630
+ * nhưng thực tế bị giới hạn bởi viewport/popper). Trừ ~40px nếu có ô search.
4631
+ * • chiềuCao1Item ≈ min-height MenuItem + gap 4px:
4632
+ * size="md" → ~40px (36 + 4)
4633
+ * size="lg" → ~48px (44 + 4)
4634
+ *
4635
+ * Ví dụ: maxHeight=320, có search, size md → ceil((320-40)/40)+1 ≈ 8 → truyền 8–9.
4636
+ * Nên truyền DƯ một chút (chắc chắn có scroll); truyền THIẾU có thể vẫn kẹt loadmore.
4637
+ * Lưu ý: số càng lớn thì lần mở đầu tải càng nhiều trang.
4638
+ */
4639
+ autoFillMinItems?: number;
4640
+ /**
4641
+ * true: ghim option ĐÃ CHỌN nhưng chưa có trong list API (resolve qua
4642
+ * `defaultSelectedOptions`/`fetchByIds`) lên ĐẦU dropdown. Mặc định false (đưa
4643
+ * xuống cuối). Ở multi-select `MenuSelect` vốn tự gom nhóm "Selected" lên đầu
4644
+ * nên prop này chủ yếu tác động tới single-select. */
4645
+ pinSelectedOnTop?: boolean;
4646
+ /** Options đã biết trước cho value đã chọn (form edit) -> hiện label đúng. */
4647
+ defaultSelectedOptions?: SelectOptionItem<T>[];
4648
+ /** Gọi API lấy option theo id khi thiếu label của value đã chọn. */
4649
+ fetchByIds?: (ids: T[]) => Promise<SelectOptionItem<T>[]>;
4650
+ /** Callback khi tải xong (danh sách hiện có). */
4651
+ onLoaded?: (options: SelectOptionItem<T>[], phase: ApiSelectPhase) => void;
4652
+ /** Callback khi lỗi. (Tên `onFetchError` để tránh đụng handler `onError` của input.) */
4653
+ onFetchError?: (error: unknown, phase: ApiSelectPhase) => void;
4654
+ /** Text tuỳ biến (i18n). */
4655
+ loadingMoreText?: string;
4656
+ errorText?: string;
4657
+ retryText?: string;
4658
+ }
4659
+ /** Omit phân phối trên union single/multi để giữ discriminant `multi`. */
4660
+ type DistributiveOmit<T, K extends keyof T> = T extends unknown ? Omit<T, K> : never;
4661
+ type ApiSelectProps<T extends string | number = string, P = unknown> = DistributiveOmit<SelectProps<T>, "options" | "searchValue" | "onSearchChange" | "onPopupScroll" | "onOpen" | "loading" | "noData" | "noResult" | "footer"> & ApiSelectOwnProps<T, P>;
4662
+ interface ApiSelectRef<T extends string | number = string> extends FISSelectRef {
4663
+ /** Tải lại theo search/params hiện tại (giữ nguyên keyword đang gõ). */
4664
+ refresh: () => void;
4665
+ /**
4666
+ * Reset về trạng thái đầu: xoá keyword tìm kiếm rồi tải lại trang 1.
4667
+ * Muốn đổi params (cascading) thì cập nhật prop `params` — component tự
4668
+ * reset + refetch, không cần truyền qua `reload`.
4669
+ */
4670
+ reload: () => void;
4671
+ /** Lấy danh sách options hiện có. */
4672
+ getOptions: () => SelectOptionItem<T>[];
4673
+ }
4674
+
4675
+ declare function ApiSelectInner<T extends string | number, P = unknown>(props: ApiSelectProps<T, P>, ref: ForwardedRef<ApiSelectRef<T>>): react_jsx_runtime.JSX.Element;
4676
+ declare const FISApiSelect: <T extends string | number = string, P = unknown>(props: ApiSelectProps<T, P> & {
4677
+ ref?: ForwardedRef<ApiSelectRef<T>>;
4678
+ }) => ReturnType<typeof ApiSelectInner>;
4679
+
4547
4680
  type NotificationBaseProps = {
4548
4681
  title: string | React.ReactElement;
4549
4682
  description: string | React.ReactElement;
@@ -4604,5 +4737,5 @@ interface FISTextPropsI extends React__default.HTMLAttributes<HTMLElement> {
4604
4737
  }
4605
4738
  declare const FISText: React__default.ForwardRefExoticComponent<FISTextPropsI & React__default.RefAttributes<any>>;
4606
4739
 
4607
- export { FISAlertBanner, FISAvatar, FISBadge, FISBreadcrumb, FISButton, FISButtonGroup, FISCheckbox, FISCheckboxGroup, FISChipButton, FISCollapse, FISCombobox, FISDateRange, FISDivider, FISIconButton, FISInputArea, FISInputDate, FISInputField, FISInputLabel, FISInputStepper, FISInputText, FISInputTime, FISLinkButton, FISMenuItem, FISMenuSection, FISMenuSelect, FISMenuSelectDropdown, FISPagination, FISProgressCircular, FISProgressLinear, FISRadio, RadioGroup as FISRadioGroup, FISSegmented, FISSelect, FISSelectItem, FISSorter, FISSplitButton, FISSwitch, FISTab, FISTable, FISTableCell, FISTableHeaderCell, FISText, FISThemeProvider, FISToast, FISTooltip, SegmentedPanelItem, TabPanelItem, useNotification, useToast };
4608
- export type { FISMenuData, FISMenuSelectDropdownProps, PaginationProps as FISPaginationProps, TableProps as FISTableProps, FISTableRef, ThemeType$2 as ThemeType };
4740
+ export { FISAlertBanner, FISApiSelect, FISAvatar, FISBadge, FISBreadcrumb, FISButton, FISButtonGroup, FISCheckbox, FISCheckboxGroup, FISChipButton, FISCollapse, FISCombobox, FISDateRange, FISDivider, FISIconButton, FISInputArea, FISInputDate, FISInputField, FISInputLabel, FISInputStepper, FISInputText, FISInputTime, FISLinkButton, FISMenuItem, FISMenuSection, FISMenuSelect, FISMenuSelectDropdown, FISPagination, FISProgressCircular, FISProgressLinear, FISRadio, RadioGroup as FISRadioGroup, FISSegmented, FISSelect, FISSelectItem, FISSorter, FISSplitButton, FISSwitch, FISTab, FISTable, FISTableCell, FISTableHeaderCell, FISText, FISThemeProvider, FISToast, FISTooltip, SegmentedPanelItem, TabPanelItem, useNotification, useToast };
4741
+ export type { ApiSelectProps, ApiSelectRef, FISMenuData, FISMenuSelectDropdownProps, PaginationProps as FISPaginationProps, TableProps as FISTableProps, FISTableRef, FetchAll, FetchAllParams, FetchPage, FetchPageParams, FetchPageResult, ThemeType$2 as ThemeType };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "homepage": "https://vietdiemtran.github.io/fis-component/",
3
3
  "name": "fis-component",
4
- "version": "0.1.21",
4
+ "version": "0.1.22",
5
5
  "description": "",
6
6
  "main": "dist/cjs/index.js",
7
7
  "module": "dist/esm/index.js",