fis-component 0.1.21 → 0.1.23
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/cjs/index.js +546 -8
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/src/components/ApiSelect/ApiSelect.stories.d.ts +23 -0
- package/dist/cjs/types/src/components/ApiSelect/index.d.ts +7 -0
- package/dist/cjs/types/src/components/ApiSelect/styles.d.ts +2 -0
- package/dist/cjs/types/src/components/ApiSelect/types.d.ts +109 -0
- package/dist/cjs/types/src/components/ApiSelect/useApiSelect.d.ts +52 -0
- package/dist/cjs/types/src/components/MenuSelect/styles.d.ts +1 -0
- package/dist/cjs/types/src/components/MenuSelect/types.d.ts +20 -0
- package/dist/cjs/types/src/index.d.ts +2 -0
- package/dist/esm/index.js +546 -9
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/src/components/ApiSelect/ApiSelect.stories.d.ts +23 -0
- package/dist/esm/types/src/components/ApiSelect/index.d.ts +7 -0
- package/dist/esm/types/src/components/ApiSelect/styles.d.ts +2 -0
- package/dist/esm/types/src/components/ApiSelect/types.d.ts +109 -0
- package/dist/esm/types/src/components/ApiSelect/useApiSelect.d.ts +52 -0
- package/dist/esm/types/src/components/MenuSelect/styles.d.ts +1 -0
- package/dist/esm/types/src/components/MenuSelect/types.d.ts +20 -0
- package/dist/esm/types/src/index.d.ts +2 -0
- package/dist/index.d.ts +135 -2
- package/package.json +1 -1
- package/src/styles/fonts.css +1 -1
|
@@ -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";
|