fis-component 0.2.0 → 0.2.2
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 +12 -9
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/src/components/Provider/ConfigContext.d.ts +13 -2
- package/dist/cjs/types/src/components/Select/Select.stories.d.ts +1 -0
- package/dist/cjs/types/src/components/Select/types.d.ts +18 -6
- package/dist/esm/index.js +12 -9
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/src/components/Provider/ConfigContext.d.ts +13 -2
- package/dist/esm/types/src/components/Select/Select.stories.d.ts +1 -0
- package/dist/esm/types/src/components/Select/types.d.ts +18 -6
- package/dist/index.d.ts +31 -8
- package/package.json +1 -1
|
@@ -8,11 +8,22 @@ export interface FISComponentConfig {
|
|
|
8
8
|
*/
|
|
9
9
|
components?: FISComponentDefaults;
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* Cấu hình nhanh cho `Select` và `ApiSelect`.
|
|
12
|
+
* `components.Select` / `components.ApiSelect` thắng nếu đặt cả hai.
|
|
13
13
|
*/
|
|
14
14
|
select?: {
|
|
15
|
+
/**
|
|
16
|
+
* Mặc định `allowClear`. Prop truyền trực tiếp > `components.Select.allowClear`
|
|
17
|
+
* > giá trị này > `false`.
|
|
18
|
+
*/
|
|
15
19
|
allowClear?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Giá trị select đơn gửi vào `onChange` khi bấm nút "×" (multi luôn gửi `[]`).
|
|
22
|
+
* Prop `clearValue` truyền trực tiếp > `components.Select.clearValue`
|
|
23
|
+
* > giá trị này > `undefined`.
|
|
24
|
+
* @example { select: { allowClear: true, clearValue: "" } }
|
|
25
|
+
*/
|
|
26
|
+
clearValue?: string | number;
|
|
16
27
|
};
|
|
17
28
|
}
|
|
18
29
|
export interface FISConfigProviderProps {
|
|
@@ -146,3 +146,4 @@ export declare const LoadMore: import("@storybook/core/csf").AnnotatedStoryFn<im
|
|
|
146
146
|
export declare const NoPortal: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, SingleSelectStoryProps>;
|
|
147
147
|
export declare const WithRef: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, SingleSelectStoryProps>;
|
|
148
148
|
export declare const AllowClear: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, SingleSelectStoryProps>;
|
|
149
|
+
export declare const ClearValueConfig: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, SingleSelectStoryProps>;
|
|
@@ -33,19 +33,31 @@ type BaseSelectProps<T extends string | number> = Partial<InputLabelProps> & Omi
|
|
|
33
33
|
* Hiện nút "×" khi hover vào ô đã có giá trị (giống antd).
|
|
34
34
|
*
|
|
35
35
|
* Bấm "×":
|
|
36
|
-
* - Select đơn: gọi `onChange(undefined)
|
|
36
|
+
* - Select đơn: gọi `onChange(clearValue)` (mặc định `undefined`), sau đó gọi `onClear()`.
|
|
37
37
|
* - Multi select: gọi `onChange([])`, sau đó gọi `onClear()`.
|
|
38
38
|
*
|
|
39
39
|
* Thứ tự ưu tiên: prop `allowClear` truyền trực tiếp
|
|
40
|
-
* > `config.components.Select.allowClear`
|
|
41
|
-
* > mặc định `false`.
|
|
40
|
+
* > `config.components.Select.allowClear` > `config.select.allowClear`
|
|
41
|
+
* của `FISThemeProvider` > mặc định `false`.
|
|
42
42
|
*
|
|
43
43
|
* Không hiện nút khi `disabled` hoặc chưa có giá trị.
|
|
44
44
|
*/
|
|
45
45
|
allowClear?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Giá trị select đơn gửi vào `onChange` khi bấm nút "×" (multi select luôn gửi `[]`).
|
|
48
|
+
*
|
|
49
|
+
* Thứ tự ưu tiên: prop `clearValue` truyền trực tiếp
|
|
50
|
+
* > `config.components.Select.clearValue` > `config.select.clearValue`
|
|
51
|
+
* của `FISThemeProvider` > `undefined`.
|
|
52
|
+
*
|
|
53
|
+
* Nên dùng `""` (hoặc để `undefined`): chỉ `undefined`, `null`, `""` được coi là
|
|
54
|
+
* chưa chọn (hiện placeholder, ẩn nút "×").
|
|
55
|
+
* Truyền `clearValue={undefined}` trực tiếp được coi như không truyền.
|
|
56
|
+
*/
|
|
57
|
+
clearValue?: T;
|
|
46
58
|
/**
|
|
47
59
|
* Gọi sau `onChange` khi người dùng bấm nút "×" (chỉ khi `allowClear` bật).
|
|
48
|
-
* Select đơn: sau `onChange(
|
|
60
|
+
* Select đơn: sau `onChange(clearValue)`. Multi select: sau `onChange([])`.
|
|
49
61
|
*/
|
|
50
62
|
onClear?: () => void;
|
|
51
63
|
};
|
|
@@ -59,8 +71,8 @@ export type SingleSelectProps<T extends string | number> = BaseSelectProps<T> &
|
|
|
59
71
|
/**
|
|
60
72
|
* Gọi khi giá trị thay đổi.
|
|
61
73
|
*
|
|
62
|
-
* Nhận `undefined` khi người dùng bấm nút "×"
|
|
63
|
-
* `onClear()` được gọi. Luôn xử lý trường hợp `undefined`, ví dụ:
|
|
74
|
+
* Nhận `clearValue` (mặc định `undefined`) khi người dùng bấm nút "×"
|
|
75
|
+
* (`allowClear`), sau đó `onClear()` được gọi. Luôn xử lý trường hợp `undefined`, ví dụ:
|
|
64
76
|
* `onChange={(value) => field.onChange(value == null ? "" : String(value))}`.
|
|
65
77
|
*/
|
|
66
78
|
onChange: (value: T | undefined) => void;
|
package/dist/esm/index.js
CHANGED
|
@@ -31,10 +31,13 @@ const INHERITS = {
|
|
|
31
31
|
ApiSelect: ["Select"],
|
|
32
32
|
};
|
|
33
33
|
const getDefaults = (config, name) => {
|
|
34
|
-
const legacy =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
const legacy = {};
|
|
35
|
+
if (name === "Select" || name === "ApiSelect") {
|
|
36
|
+
if (config.select?.allowClear !== undefined)
|
|
37
|
+
legacy.allowClear = config.select.allowClear;
|
|
38
|
+
if (config.select?.clearValue !== undefined)
|
|
39
|
+
legacy.clearValue = config.select.clearValue;
|
|
40
|
+
}
|
|
38
41
|
const names = [...(INHERITS[name] ?? []), name];
|
|
39
42
|
return names.reduce((acc, n) => ({ ...acc, ...config.components?.[n] }), legacy);
|
|
40
43
|
};
|
|
@@ -5546,7 +5549,7 @@ const DivWrapperSC$5 = styled.div `
|
|
|
5546
5549
|
`;
|
|
5547
5550
|
|
|
5548
5551
|
const FISInputStepper$1 = forwardRef((props, ref) => {
|
|
5549
|
-
const { min, max, step = 1, defaultValue, sizeInput = "md", StartIcon, EndIcon, negative, positive, message, iconLabel, textLabel = "", onClickIconLabel, disabled, readOnly, onChange, ...rest } = props;
|
|
5552
|
+
const { min, max, step = 1, defaultValue, sizeInput = "md", StartIcon, EndIcon, negative, positive, message, iconLabel, textLabel = "", onClickIconLabel, disabled, readOnly, onChange, className, ...rest } = props;
|
|
5550
5553
|
const [count, setCount] = useState(defaultValue !== undefined ? defaultValue : undefined);
|
|
5551
5554
|
const handleIncrement = () => {
|
|
5552
5555
|
setCount((prev) => {
|
|
@@ -5577,7 +5580,7 @@ const FISInputStepper$1 = forwardRef((props, ref) => {
|
|
|
5577
5580
|
"input-text-lg": sizeInput === "lg",
|
|
5578
5581
|
}), children: [jsx(FISIconButton$1, { icon: StartIcon ? StartIcon : jsx(DecreIcon, {}), size: sizeInput === "lg" ? "md" : "sm", variant: "tertiary-invisible", onClick: handleDecrement, disabled: min !== undefined && count !== undefined && count <= min, className: classNames("decrement", {
|
|
5579
5582
|
"disabled-button": disabled || readOnly,
|
|
5580
|
-
}) }), jsx(InputSC$1, { ...rest, ref: ref, disabled: disabled, readOnly: readOnly, type: "number", value: count !== undefined ? count : "", className: classNames({
|
|
5583
|
+
}) }), jsx(InputSC$1, { ...rest, ref: ref, disabled: disabled, readOnly: readOnly, type: "number", value: count !== undefined ? count : "", className: classNames(className, {
|
|
5581
5584
|
negative: negative,
|
|
5582
5585
|
"input-text-lg": sizeInput === "lg",
|
|
5583
5586
|
}), onChange: handleChange }), jsx(FISIconButton$1, { icon: EndIcon ? EndIcon : jsx(IncreIcon, {}), size: sizeInput === "lg" ? "md" : "sm", variant: "tertiary-invisible", onClick: handleIncrement, disabled: max !== undefined && count !== undefined && count >= max, className: classNames("increment", {
|
|
@@ -75579,7 +75582,7 @@ function isMenuSize(value) {
|
|
|
75579
75582
|
|
|
75580
75583
|
const FISSelect$1 = forwardRef(({ className, style, size = "md", options, value, disabled = false, textLabel = "", iconLabel, required, negative, message, positive, multi, placeholder, placeholderSearch, loading, onChange, renderOption, onClickIconLabel, displayValue, multiDisplayText, searchValue, onSearchChange, portal = true, maxHeight, onPopupScroll, onOpen, hideChip, tooltipTitle, tooltipVariant = "primary", noData, noResult, noDataText, noResultText, footer, searchDebounce, showSearch, onSearchInput, virtualized, virtualItemHeight, removeSelectedText, selectedGroupLabel,
|
|
75581
75584
|
// Default theo dự án được gộp ở withFISDefaults (src/index.ts)
|
|
75582
|
-
allowClear = false, onClear, ...restProps }, ref) => {
|
|
75585
|
+
allowClear = false, clearValue, onClear, ...restProps }, ref) => {
|
|
75583
75586
|
const [isOpen, setIsOpen] = useState(false);
|
|
75584
75587
|
const [isHovered, setIsHovered] = useState(false);
|
|
75585
75588
|
const [referenceElement, setReferenceElement] = useState(null);
|
|
@@ -75683,11 +75686,11 @@ allowClear = false, onClear, ...restProps }, ref) => {
|
|
|
75683
75686
|
onChange([]);
|
|
75684
75687
|
}
|
|
75685
75688
|
else {
|
|
75686
|
-
onChange(
|
|
75689
|
+
onChange(clearValue);
|
|
75687
75690
|
}
|
|
75688
75691
|
setCachedSelectedItem(null);
|
|
75689
75692
|
onClear?.();
|
|
75690
|
-
}, [multi, onChange, onClear]);
|
|
75693
|
+
}, [multi, onChange, onClear, clearValue]);
|
|
75691
75694
|
const handleOptionRemove = useCallback((option) => {
|
|
75692
75695
|
if (multi && Array.isArray(value)) {
|
|
75693
75696
|
const newValues = value.filter((v) => v !== option.value);
|