pixelize-design-library 2.2.149 → 2.2.150
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/Components/Input/PhoneNumberInput.js +6 -2
- package/dist/Components/Input/TextInput.js +9 -2
- package/dist/Components/Input/textInputIconSize.d.ts +10 -0
- package/dist/Components/Input/textInputIconSize.js +40 -0
- package/dist/Components/Input/textInputIconSize.test.d.ts +1 -0
- package/dist/Components/Input/textInputIconSize.test.js +27 -0
- package/dist/Components/MultiSelect/MultiSelect.js +12 -10
- package/dist/Components/MultiSelect/MultiSelectProps.d.ts +1 -1
- package/dist/Components/SearchSelect/SearchSelect.js +37 -34
- package/dist/Components/SearchSelect/SelectTruncatedLabel.d.ts +4 -3
- package/dist/Components/SearchSelect/SelectTruncatedLabel.js +3 -3
- package/dist/Components/SearchSelect/searchSelectSize.d.ts +44 -0
- package/dist/Components/SearchSelect/searchSelectSize.js +96 -0
- package/dist/Components/SearchSelect/searchSelectSize.test.d.ts +1 -0
- package/dist/Components/SearchSelect/searchSelectSize.test.js +22 -0
- package/dist/Components/Select/Select.js +17 -3
- package/dist/Components/Tag/Tag.js +1 -1
- package/package.json +1 -1
|
@@ -63,6 +63,7 @@ var react_2 = require("@chakra-ui/react");
|
|
|
63
63
|
var ErrorMessage_1 = __importDefault(require("../Common/ErrorMessage"));
|
|
64
64
|
var HelperText_1 = __importDefault(require("../Common/HelperText"));
|
|
65
65
|
var FormLabel_1 = require("../Common/FormLabel");
|
|
66
|
+
var useCustomTheme_1 = require("../../Theme/useCustomTheme");
|
|
66
67
|
var getFlagEmoji = function (countryCode) {
|
|
67
68
|
if (!countryCode)
|
|
68
69
|
return "";
|
|
@@ -72,8 +73,11 @@ var getFlagEmoji = function (countryCode) {
|
|
|
72
73
|
return String.fromCodePoint(127397 + char.charCodeAt(0));
|
|
73
74
|
});
|
|
74
75
|
};
|
|
76
|
+
var sizeToPt = { xs: 2, sm: -1, md: 2, lg: 4 };
|
|
77
|
+
var sizeToWidth = { xs: "3.5rem", sm: "3.8rem", md: "4rem", lg: "4rem" };
|
|
75
78
|
var PhoneNumberInput = function (_a) {
|
|
76
79
|
var _b = _a.size, size = _b === void 0 ? "md" : _b, value = _a.value, _c = _a.codeValueReturn, codeValueReturn = _c === void 0 ? true : _c, country = _a.country, countries = _a.countries, _d = _a.placeholder, placeholder = _d === void 0 ? "Enter phone number" : _d, onChange = _a.onChange, inputId = _a.inputId, selectId = _a.selectId, error = _a.error, errorMessage = _a.errorMessage, helperText = _a.helperText, label = _a.label, id = _a.id, _e = _a.width, width = _e === void 0 ? "100%" : _e, isInformation = _a.isInformation, informationMessage = _a.informationMessage, isRequired = _a.isRequired, onBlur = _a.onBlur, onFocus = _a.onFocus, isReadOnly = _a.isReadOnly, height = _a.height, autoComplete = _a.autoComplete, _f = _a.showCountrySelect, showCountrySelect = _f === void 0 ? true : _f, ref = _a.ref, name = _a.name, minW = _a.minW, maxW = _a.maxW, rest = __rest(_a, ["size", "value", "codeValueReturn", "country", "countries", "placeholder", "onChange", "inputId", "selectId", "error", "errorMessage", "helperText", "label", "id", "width", "isInformation", "informationMessage", "isRequired", "onBlur", "onFocus", "isReadOnly", "height", "autoComplete", "showCountrySelect", "ref", "name", "minW", "maxW"]);
|
|
80
|
+
var theme = (0, useCustomTheme_1.useCustomTheme)();
|
|
77
81
|
var getCountryTelCode = (0, react_1.useCallback)(function (countryCode) {
|
|
78
82
|
var _a;
|
|
79
83
|
if (!countryCode)
|
|
@@ -121,9 +125,9 @@ var PhoneNumberInput = function (_a) {
|
|
|
121
125
|
return (react_1.default.createElement(react_2.FormControl, { w: width, minW: minW, maxW: maxW },
|
|
122
126
|
label && (react_1.default.createElement(FormLabel_1.TextLabel, { label: label, id: id, isInformation: isInformation, informationMessage: informationMessage, isRequired: isRequired })),
|
|
123
127
|
react_1.default.createElement(react_2.InputGroup, __assign({ size: size }, rest),
|
|
124
|
-
react_1.default.createElement(react_2.InputLeftElement, { width: showCountrySelect ? "
|
|
128
|
+
react_1.default.createElement(react_2.InputLeftElement, { width: showCountrySelect ? "3rem" : "2rem", height: "100%" },
|
|
125
129
|
showCountrySelect && react_1.default.createElement(react_1.default.Fragment, null,
|
|
126
|
-
react_1.default.createElement(react_2.Select, { position: "absolute", top: "0", left: "0", height: "100%", id: selectId, width:
|
|
130
|
+
react_1.default.createElement(react_2.Select, { position: "absolute", top: "0", left: "0", height: "100%", id: selectId, width: sizeToWidth[size], opacity: 0, zIndex: 1, value: selectedCountry, onChange: handleCountryChange, size: size, pt: sizeToPt[size], iconColor: theme.colors.gray[500] },
|
|
127
131
|
react_1.default.createElement("option", { value: "" }, "Select Country"),
|
|
128
132
|
countries.map(function (option) { return (react_1.default.createElement("option", { key: option.code, value: option.code }, option.country)); }))),
|
|
129
133
|
react_1.default.createElement(react_2.Flex, { pl: 2, width: "100%", alignItems: "center", justifyContent: "space-between" }, selectedCountry ? (react_1.default.createElement(react_2.Box, { fontSize: "1.2rem" }, getFlagEmoji(selectedCountry))) : (react_1.default.createElement(react_2.Icon, { viewBox: "0 0 24 24", boxSize: "1rem" },
|
|
@@ -60,17 +60,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
60
60
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
61
61
|
var react_1 = __importStar(require("react"));
|
|
62
62
|
var react_2 = require("@chakra-ui/react");
|
|
63
|
+
var textInputIconSize_1 = require("./textInputIconSize");
|
|
63
64
|
var FormLabel_1 = require("../Common/FormLabel");
|
|
64
65
|
var HelperText_1 = __importDefault(require("../Common/HelperText"));
|
|
65
66
|
var ErrorMessage_1 = __importDefault(require("../Common/ErrorMessage"));
|
|
67
|
+
var useCustomTheme_1 = require("../../Theme/useCustomTheme");
|
|
66
68
|
var TextInput = (0, react_1.forwardRef)(function (_a, ref) {
|
|
67
69
|
var label = _a.label, _b = _a.type, type = _b === void 0 ? "text" : _b, id = _a.id, name = _a.name, onChange = _a.onChange, onBlur = _a.onBlur, onFocus = _a.onFocus, _c = _a.isDisabled, isDisabled = _c === void 0 ? false : _c, _d = _a.isReadOnly, isReadOnly = _d === void 0 ? false : _d, _e = _a.isRequired, isRequired = _e === void 0 ? false : _e, value = _a.value, _f = _a.placeholder, placeholder = _f === void 0 ? "Placeholder" : _f, _g = _a.width, width = _g === void 0 ? "100%" : _g, height = _a.height, error = _a.error, errorMessage = _a.errorMessage, helperText = _a.helperText, onRightIconclick = _a.onRightIconclick, inputRightIcon = _a.inputRightIcon, inputLeftIcon = _a.inputLeftIcon, onLeftIconClick = _a.onLeftIconClick, inputGroupStyle = _a.inputGroupStyle, inputStyle = _a.inputStyle, _h = _a.size, size = _h === void 0 ? "md" : _h, _j = _a.isInformation, isInformation = _j === void 0 ? false : _j, informationMessage = _a.informationMessage, leftElementStyle = _a.leftElementStyle, rightElementStyle = _a.rightElementStyle, autoComplete = _a.autoComplete, minW = _a.minW, maxW = _a.maxW, props = __rest(_a, ["label", "type", "id", "name", "onChange", "onBlur", "onFocus", "isDisabled", "isReadOnly", "isRequired", "value", "placeholder", "width", "height", "error", "errorMessage", "helperText", "onRightIconclick", "inputRightIcon", "inputLeftIcon", "onLeftIconClick", "inputGroupStyle", "inputStyle", "size", "isInformation", "informationMessage", "leftElementStyle", "rightElementStyle", "autoComplete", "minW", "maxW"]);
|
|
70
|
+
var theme = (0, useCustomTheme_1.useCustomTheme)();
|
|
71
|
+
var sizeKey = typeof size === "string" ? size : "md";
|
|
72
|
+
var iconScaleSx = (0, textInputIconSize_1.getTextInputIconWrapperSx)(sizeKey);
|
|
68
73
|
return (react_1.default.createElement(react_2.FormControl, { w: width, minW: minW, maxW: maxW },
|
|
69
74
|
label && (react_1.default.createElement(FormLabel_1.TextLabel, { label: label, id: id, isInformation: isInformation, informationMessage: informationMessage, isRequired: isRequired })),
|
|
70
75
|
react_1.default.createElement(react_2.InputGroup, { style: inputGroupStyle, size: size, height: height },
|
|
71
|
-
inputLeftIcon && (react_1.default.createElement(react_2.InputLeftElement, __assign({ onClick: onLeftIconClick, pointerEvents: onLeftIconClick ? "auto" : "none" }, leftElementStyle, { height: "100%", display: "flex", alignItems: "center" }),
|
|
76
|
+
inputLeftIcon && (react_1.default.createElement(react_2.InputLeftElement, __assign({ onClick: onLeftIconClick, pointerEvents: onLeftIconClick ? "auto" : "none" }, leftElementStyle, { height: "100%", display: "flex", alignItems: "center" }),
|
|
77
|
+
react_1.default.createElement(react_2.Box, { as: "span", sx: iconScaleSx, color: theme.colors.gray[500] }, inputLeftIcon))),
|
|
72
78
|
react_1.default.createElement(react_2.Input, __assign({ type: type, placeholder: placeholder, onChange: onChange, onBlur: onBlur, onFocus: onFocus, value: value, isDisabled: isDisabled, isReadOnly: isReadOnly, id: id, name: name, size: size }, (height != null && { height: height }), { isInvalid: error, ref: ref, autoComplete: autoComplete }, inputStyle, props)),
|
|
73
|
-
inputRightIcon && (react_1.default.createElement(react_2.InputRightElement, __assign({ onClick: onRightIconclick, pointerEvents: onRightIconclick ? "auto" : "none" }, rightElementStyle, { height: "100%", display: "flex", alignItems: "center" }),
|
|
79
|
+
inputRightIcon && (react_1.default.createElement(react_2.InputRightElement, __assign({ onClick: onRightIconclick, pointerEvents: onRightIconclick ? "auto" : "none" }, rightElementStyle, { height: "100%", display: "flex", alignItems: "center" }),
|
|
80
|
+
react_1.default.createElement(react_2.Box, { as: "span", sx: iconScaleSx }, inputRightIcon)))),
|
|
74
81
|
error && react_1.default.createElement(ErrorMessage_1.default, { errorMessage: errorMessage }),
|
|
75
82
|
helperText && !error && react_1.default.createElement(HelperText_1.default, { helperText: helperText })));
|
|
76
83
|
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SystemStyleObject } from "@chakra-ui/styled-system";
|
|
2
|
+
/**
|
|
3
|
+
* Returns icon target width/height in px for a Chakra `Input` / `InputGroup` `size`.
|
|
4
|
+
*/
|
|
5
|
+
export declare function getTextInputIconSizePx(size: string | undefined): number;
|
|
6
|
+
/**
|
|
7
|
+
* Scales any SVG in the icon slot (e.g. Lucide) to match field size; plain `fontSize` does not
|
|
8
|
+
* affect them because they set explicit width/height.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getTextInputIconWrapperSx(size: string | undefined): SystemStyleObject;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTextInputIconSizePx = getTextInputIconSizePx;
|
|
4
|
+
exports.getTextInputIconWrapperSx = getTextInputIconWrapperSx;
|
|
5
|
+
/** Pixels: aligned with `Input` field density (Chakra `sizes.6`–`12` and typical Lucide use). */
|
|
6
|
+
var TEXT_INPUT_ICON_PX = {
|
|
7
|
+
xs: 14,
|
|
8
|
+
sm: 16,
|
|
9
|
+
md: 18,
|
|
10
|
+
lg: 20,
|
|
11
|
+
xl: 24,
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Returns icon target width/height in px for a Chakra `Input` / `InputGroup` `size`.
|
|
15
|
+
*/
|
|
16
|
+
function getTextInputIconSizePx(size) {
|
|
17
|
+
var _a;
|
|
18
|
+
if (!size)
|
|
19
|
+
return TEXT_INPUT_ICON_PX.md;
|
|
20
|
+
return (_a = TEXT_INPUT_ICON_PX[size]) !== null && _a !== void 0 ? _a : TEXT_INPUT_ICON_PX.md;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Scales any SVG in the icon slot (e.g. Lucide) to match field size; plain `fontSize` does not
|
|
24
|
+
* affect them because they set explicit width/height.
|
|
25
|
+
*/
|
|
26
|
+
function getTextInputIconWrapperSx(size) {
|
|
27
|
+
var px = getTextInputIconSizePx(size);
|
|
28
|
+
return {
|
|
29
|
+
display: "inline-flex",
|
|
30
|
+
alignItems: "center",
|
|
31
|
+
justifyContent: "center",
|
|
32
|
+
lineHeight: 0,
|
|
33
|
+
flexShrink: 0,
|
|
34
|
+
// Override Lucide/inline width on SVG; cover direct or nested (e.g. one wrapper) icons
|
|
35
|
+
"& > svg, & > * svg, & svg": {
|
|
36
|
+
width: "".concat(px, "px !important"),
|
|
37
|
+
height: "".concat(px, "px !important"),
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var textInputIconSize_1 = require("./textInputIconSize");
|
|
4
|
+
describe("getTextInputIconSizePx", function () {
|
|
5
|
+
it("maps Chakra input sizes to increasing pixel values", function () {
|
|
6
|
+
var xs = (0, textInputIconSize_1.getTextInputIconSizePx)("xs");
|
|
7
|
+
var sm = (0, textInputIconSize_1.getTextInputIconSizePx)("sm");
|
|
8
|
+
var md = (0, textInputIconSize_1.getTextInputIconSizePx)("md");
|
|
9
|
+
var lg = (0, textInputIconSize_1.getTextInputIconSizePx)("lg");
|
|
10
|
+
expect(xs).toBeLessThan(sm);
|
|
11
|
+
expect(sm).toBeLessThan(md);
|
|
12
|
+
expect(md).toBeLessThan(lg);
|
|
13
|
+
});
|
|
14
|
+
it("defaults to md for missing or unknown size", function () {
|
|
15
|
+
expect((0, textInputIconSize_1.getTextInputIconSizePx)(undefined)).toBe(18);
|
|
16
|
+
expect((0, textInputIconSize_1.getTextInputIconSizePx)("nope")).toBe(18);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
describe("getTextInputIconWrapperSx", function () {
|
|
20
|
+
it("includes the resolved pixel size in svg rules for xs", function () {
|
|
21
|
+
var sx = (0, textInputIconSize_1.getTextInputIconWrapperSx)("xs");
|
|
22
|
+
var svg = sx["& > svg, & > * svg, & svg"];
|
|
23
|
+
expect(svg).toBeDefined();
|
|
24
|
+
expect(svg === null || svg === void 0 ? void 0 : svg.width).toContain("14");
|
|
25
|
+
expect(svg === null || svg === void 0 ? void 0 : svg.height).toContain("14");
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -61,8 +61,11 @@ var react_1 = __importStar(require("react"));
|
|
|
61
61
|
var react_2 = require("@chakra-ui/react");
|
|
62
62
|
var FormLabel_1 = require("../Common/FormLabel");
|
|
63
63
|
var useCustomTheme_1 = require("../../Theme/useCustomTheme");
|
|
64
|
+
var searchSelectSize_1 = require("../SearchSelect/searchSelectSize");
|
|
64
65
|
var ErrorMessage_1 = __importDefault(require("../Common/ErrorMessage"));
|
|
65
66
|
var HelperText_1 = __importDefault(require("../Common/HelperText"));
|
|
67
|
+
var Tag_1 = __importDefault(require("../Tag/Tag"));
|
|
68
|
+
var lucide_react_1 = require("lucide-react");
|
|
66
69
|
var generateUniqueId = (function () {
|
|
67
70
|
var counter = 0;
|
|
68
71
|
return function () {
|
|
@@ -72,11 +75,12 @@ var generateUniqueId = (function () {
|
|
|
72
75
|
})();
|
|
73
76
|
function MultiSelect(_a) {
|
|
74
77
|
var _b, _c;
|
|
75
|
-
var value = _a.value, onValueChange = _a.onValueChange, _d = _a.width, width = _d === void 0 ? "100%" : _d, _e = _a.label, label = _e === void 0 ? "label" : _e, _f = _a.isRequired, isRequired = _f === void 0 ? true : _f, _g = _a.isInformation, isInformation = _g === void 0 ? false : _g, _h = _a.informationMessage, informationMessage = _h === void 0 ? "" : _h, name = _a.name, id = _a.id, _j = _a.placeholderText, placeholderText = _j === void 0 ? "Type valid email and press enter" : _j, isDisabled = _a.isDisabled, isReadOnly = _a.isReadOnly,
|
|
78
|
+
var value = _a.value, onValueChange = _a.onValueChange, _d = _a.width, width = _d === void 0 ? "100%" : _d, _e = _a.label, label = _e === void 0 ? "label" : _e, _f = _a.isRequired, isRequired = _f === void 0 ? true : _f, _g = _a.isInformation, isInformation = _g === void 0 ? false : _g, _h = _a.informationMessage, informationMessage = _h === void 0 ? "" : _h, name = _a.name, id = _a.id, _j = _a.placeholderText, placeholderText = _j === void 0 ? "Type valid email and press enter" : _j, isDisabled = _a.isDisabled, isReadOnly = _a.isReadOnly, _k = _a.size, size = _k === void 0 ? "md" : _k, inputStyle = _a.inputStyle, helperText = _a.helperText, error = _a.error, errorMessage = _a.errorMessage;
|
|
76
79
|
var theme = (0, useCustomTheme_1.useCustomTheme)();
|
|
77
|
-
var
|
|
78
|
-
var _l = (0, react_1.useState)(
|
|
79
|
-
var _m = (0, react_1.useState)(""),
|
|
80
|
+
var s = (0, searchSelectSize_1.getSearchSelectSizeStyles)((size || "md"));
|
|
81
|
+
var _l = (0, react_1.useState)(value), options = _l[0], setOptions = _l[1];
|
|
82
|
+
var _m = (0, react_1.useState)(""), inputValue = _m[0], setInputValue = _m[1];
|
|
83
|
+
var _o = (0, react_1.useState)(""), localError = _o[0], setLocalError = _o[1];
|
|
80
84
|
var inputRef = (0, react_1.useRef)(null);
|
|
81
85
|
(0, react_1.useEffect)(function () {
|
|
82
86
|
setOptions(value);
|
|
@@ -117,9 +121,9 @@ function MultiSelect(_a) {
|
|
|
117
121
|
};
|
|
118
122
|
return (react_1.default.createElement(react_2.Box, { width: width },
|
|
119
123
|
label && (react_1.default.createElement(FormLabel_1.TextLabel, { label: label, isRequired: isRequired, isInformation: isInformation, informationMessage: informationMessage })),
|
|
120
|
-
react_1.default.createElement(react_2.Flex, { wrap: "wrap", gap:
|
|
124
|
+
react_1.default.createElement(react_2.Flex, { wrap: "wrap", gap: s.gap, align: "center", px: s.px, border: "1px solid", borderColor: error || localError
|
|
121
125
|
? theme.colors.red[500]
|
|
122
|
-
: theme.colors.gray[300], borderRadius: "sm", bg: theme.colors.white, minH:
|
|
126
|
+
: theme.colors.gray[300], borderRadius: "sm", bg: theme.colors.white, minH: s.minH, _focusWithin: {
|
|
123
127
|
borderColor: error || localError
|
|
124
128
|
? theme.colors.red[500]
|
|
125
129
|
: theme.colors.primary[500],
|
|
@@ -128,10 +132,8 @@ function MultiSelect(_a) {
|
|
|
128
132
|
? (_b = theme.colors.boxShadow) === null || _b === void 0 ? void 0 : _b.error
|
|
129
133
|
: (_c = theme.colors.boxShadow) === null || _c === void 0 ? void 0 : _c.primary),
|
|
130
134
|
} },
|
|
131
|
-
options.map(function (option) { return (react_1.default.createElement(
|
|
132
|
-
|
|
133
|
-
react_1.default.createElement(react_2.TagCloseButton, { onClick: function () { return handleRemove(option); } }))); }),
|
|
134
|
-
react_1.default.createElement(react_2.Input, { ref: inputRef, type: "text", value: inputValue, isDisabled: isDisabled, isReadOnly: isReadOnly, id: id, name: name, size: size, variant: "unstyled", flex: "1", style: __assign(__assign({}, inputStyle), { backgroundColor: "transparent", fontWeight: 500, color: theme.colors.gray[700], fontSize: 15, letterSpacing: 0.3 }), onChange: handleInputChange, onKeyDown: handleKeyDown, placeholder: options.length === 0 ? placeholderText : "" })),
|
|
135
|
+
options.map(function (option) { return (react_1.default.createElement(Tag_1.default, { key: option.id, size: s.tagSize, colorScheme: "primary", label: option.label, onIconClick: function () { return handleRemove(option); }, icon: lucide_react_1.X })); }),
|
|
136
|
+
react_1.default.createElement(react_2.Input, { ref: inputRef, type: "text", value: inputValue, isDisabled: isDisabled, isReadOnly: isReadOnly, id: id, name: name, size: size, variant: "unstyled", h: s.fieldHeight, minH: s.fieldHeight, fontSize: s.fieldFontSize, fontWeight: "500", color: theme.colors.gray[700], letterSpacing: "0.02em", flex: "1", minW: 0, style: __assign({ backgroundColor: "transparent" }, inputStyle), onChange: handleInputChange, onKeyDown: handleKeyDown, placeholder: options.length === 0 ? placeholderText : "" })),
|
|
135
137
|
(error || localError) && (react_1.default.createElement(ErrorMessage_1.default, { errorMessage: localError || errorMessage })),
|
|
136
138
|
helperText && !error && react_1.default.createElement(HelperText_1.default, { helperText: helperText })));
|
|
137
139
|
}
|
|
@@ -66,6 +66,7 @@ var ErrorMessage_1 = __importDefault(require("../Common/ErrorMessage"));
|
|
|
66
66
|
var HelperText_1 = __importDefault(require("../Common/HelperText"));
|
|
67
67
|
var ToolTip_1 = __importDefault(require("../ToolTip/ToolTip"));
|
|
68
68
|
var SelectTruncatedLabel_1 = __importDefault(require("./SelectTruncatedLabel"));
|
|
69
|
+
var searchSelectSize_1 = require("./searchSelectSize");
|
|
69
70
|
var normalizeSingleValue = function (val) {
|
|
70
71
|
if (typeof val === "object" && val !== null && "id" in val && "label" in val) {
|
|
71
72
|
return val;
|
|
@@ -80,21 +81,23 @@ var normalizeMultiValue = function (val) {
|
|
|
80
81
|
};
|
|
81
82
|
var SearchSelect = function (_a) {
|
|
82
83
|
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
83
|
-
var id = _a.id, label = _a.label, options = _a.options, onSelect = _a.onSelect, onSearch = _a.onSearch, _k = _a.isOptionLoading, isOptionLoading = _k === void 0 ? false : _k, _l = _a.isLoading, isLoading = _l === void 0 ? false : _l, _m = _a.loadingText, loadingText = _m === void 0 ? "Loading..." : _m, _o = _a.placeholder, placeholder = _o === void 0 ? "Select" : _o, value = _a.value, _p = _a.searchQuery, searchQuery = _p === void 0 ? "" : _p, _q = _a.isMultiple, isMultiple = _q === void 0 ? false : _q, _r = _a.isRequired, isRequired = _r === void 0 ? false : _r, _s = _a.error, error = _s === void 0 ? false : _s, errorMessage = _a.errorMessage, helperText = _a.helperText, _t = _a.width, width = _t === void 0 ? "100%" : _t,
|
|
84
|
-
var
|
|
85
|
-
var
|
|
86
|
-
var
|
|
84
|
+
var id = _a.id, label = _a.label, options = _a.options, onSelect = _a.onSelect, onSearch = _a.onSearch, _k = _a.isOptionLoading, isOptionLoading = _k === void 0 ? false : _k, _l = _a.isLoading, isLoading = _l === void 0 ? false : _l, _m = _a.loadingText, loadingText = _m === void 0 ? "Loading..." : _m, _o = _a.placeholder, placeholder = _o === void 0 ? "Select" : _o, value = _a.value, _p = _a.searchQuery, searchQuery = _p === void 0 ? "" : _p, _q = _a.isMultiple, isMultiple = _q === void 0 ? false : _q, _r = _a.isRequired, isRequired = _r === void 0 ? false : _r, _s = _a.error, error = _s === void 0 ? false : _s, errorMessage = _a.errorMessage, helperText = _a.helperText, _t = _a.width, width = _t === void 0 ? "100%" : _t, height = _a.height, _u = _a.size, size = _u === void 0 ? "md" : _u, chip = _a.chip, information = _a.information, rightIcon = _a.rightIcon, addNew = _a.addNew, _v = _a.isSelectAll, isSelectAll = _v === void 0 ? false : _v, pagination = _a.pagination, insideSelect = _a.insideSelect, isRemoveAllIcon = _a.isRemoveAllIcon;
|
|
85
|
+
var s = (0, searchSelectSize_1.getSearchSelectSizeStyles)((size || "md"));
|
|
86
|
+
var insideSelectBoxHeight = height !== null && height !== void 0 ? height : s.insideSelectDefaultHeight;
|
|
87
|
+
var _w = (0, react_1.useState)(searchQuery), inputValue = _w[0], setInputValue = _w[1];
|
|
88
|
+
var _x = (0, react_1.useState)(false), isOpen = _x[0], setIsOpen = _x[1];
|
|
89
|
+
var _y = (0, react_1.useState)(true), hasMore = _y[0], setHasMore = _y[1];
|
|
87
90
|
var inputRef = (0, react_1.useRef)(null);
|
|
88
91
|
var containerRef = (0, react_1.useRef)(null);
|
|
89
92
|
var scrollTimeoutRef = (0, react_1.useRef)(null);
|
|
90
|
-
var
|
|
91
|
-
var
|
|
93
|
+
var _z = (0, react_1.useState)(false), focused = _z[0], setFocused = _z[1];
|
|
94
|
+
var _0 = (0, react_1.useState)(false), customSelectOpen = _0[0], setCustomSelectOpen = _0[1];
|
|
92
95
|
var customSelectRef = (0, react_1.useRef)(null);
|
|
93
|
-
var
|
|
96
|
+
var _1 = (0, react_1.useState)({
|
|
94
97
|
top: 0,
|
|
95
98
|
left: 0,
|
|
96
99
|
width: 0,
|
|
97
|
-
}), customSelectPos =
|
|
100
|
+
}), customSelectPos = _1[0], setCustomSelectPos = _1[1];
|
|
98
101
|
var theme = (0, useCustomTheme_1.useCustomTheme)();
|
|
99
102
|
(0, react_2.useOutsideClick)({
|
|
100
103
|
ref: containerRef,
|
|
@@ -220,7 +223,7 @@ var SearchSelect = function (_a) {
|
|
|
220
223
|
return (react_1.default.createElement(react_2.Box, { ref: containerRef, width: width, position: "relative" },
|
|
221
224
|
label && (react_1.default.createElement(FormLabel_1.TextLabel, { label: label, id: id, isRequired: isRequired, isInformation: information === null || information === void 0 ? void 0 : information.isInformation, informationMessage: information === null || information === void 0 ? void 0 : information.informationMessage })),
|
|
222
225
|
react_1.default.createElement(react_2.InputGroup, { size: size },
|
|
223
|
-
react_1.default.createElement(react_2.Box, { as: "div", w: "100%", minH:
|
|
226
|
+
react_1.default.createElement(react_2.Box, { as: "div", w: "100%", minH: s.minH, px: s.px, pr: s.pr, position: "relative", display: "flex", alignItems: "center", flexWrap: "wrap", gap: s.gap, border: "0.063rem solid", borderColor: error
|
|
224
227
|
? theme.colors.semantic.error[500]
|
|
225
228
|
: focused
|
|
226
229
|
? theme.colors.primary[500]
|
|
@@ -231,12 +234,12 @@ var SearchSelect = function (_a) {
|
|
|
231
234
|
: error
|
|
232
235
|
? "0 0 0 0.125rem ".concat((_f = theme.colors.boxShadow) === null || _f === void 0 ? void 0 : _f.error)
|
|
233
236
|
: "none", transition: "box-shadow 0.2s, border-color 0.2s", onClick: function () { return setIsOpen(true); } },
|
|
234
|
-
insideSelect && (react_1.default.createElement(react_2.Box, { position: "relative", ref: customSelectRef, backgroundColor: theme.colors.gray[200], ml:
|
|
235
|
-
react_1.default.createElement(react_2.Box, { minW: "5rem", cursor: "pointer", display: "flex", justifyContent: "space-between", alignItems: "center", width: insideSelect.width, height:
|
|
236
|
-
react_1.default.createElement(SelectTruncatedLabel_1.default, { label: (_h = (_g = insideSelect === null || insideSelect === void 0 ? void 0 : insideSelect.value) === null || _g === void 0 ? void 0 : _g.label) !== null && _h !== void 0 ? _h : "", maxWidth: (insideSelect === null || insideSelect === void 0 ? void 0 : insideSelect.width) || "6rem" }),
|
|
237
|
-
customSelectOpen ? react_1.default.createElement(lucide_react_1.ChevronUp, { size:
|
|
237
|
+
insideSelect && (react_1.default.createElement(react_2.Box, { position: "relative", ref: customSelectRef, backgroundColor: theme.colors.gray[200], ml: s.insideSelectMarginLeft, h: "-webkit-fill-available", borderRadius: "0.25rem 0 0 0.25rem", onClick: function () { return setCustomSelectOpen(function (prev) { return !prev; }); } },
|
|
238
|
+
react_1.default.createElement(react_2.Box, { minW: "5rem", cursor: "pointer", display: "flex", justifyContent: "space-between", alignItems: "center", width: insideSelect.width, height: insideSelectBoxHeight, pl: "0.5rem", pr: "0.5rem" },
|
|
239
|
+
react_1.default.createElement(SelectTruncatedLabel_1.default, { label: (_h = (_g = insideSelect === null || insideSelect === void 0 ? void 0 : insideSelect.value) === null || _g === void 0 ? void 0 : _g.label) !== null && _h !== void 0 ? _h : "", maxWidth: (insideSelect === null || insideSelect === void 0 ? void 0 : insideSelect.width) || "6rem", fontSize: s.fieldFontSize }),
|
|
240
|
+
customSelectOpen ? (react_1.default.createElement(lucide_react_1.ChevronUp, { size: s.chevronSize })) : (react_1.default.createElement(lucide_react_1.ChevronDown, { size: s.chevronSize }))),
|
|
238
241
|
customSelectOpen && (react_1.default.createElement(react_2.Portal, null,
|
|
239
|
-
react_1.default.createElement(react_2.Box, { id: "custom-select-portal", position: "absolute", top: "".concat(customSelectPos.top, "px"), left: "".concat(customSelectPos.left, "px"), zIndex: 1400, bg: theme.colors.white, border: "0.063rem solid", borderColor: theme.colors.gray[300], borderRadius: "md", boxShadow: "md", minW: "10rem", maxW: "38rem" }, (_j = insideSelect === null || insideSelect === void 0 ? void 0 : insideSelect.option) === null || _j === void 0 ? void 0 : _j.map(function (item) { return (react_1.default.createElement(react_2.Box, { key: item.id, display: "flex", alignItems: "center",
|
|
242
|
+
react_1.default.createElement(react_2.Box, { id: "custom-select-portal", position: "absolute", top: "".concat(customSelectPos.top, "px"), left: "".concat(customSelectPos.left, "px"), zIndex: 1400, bg: theme.colors.white, border: "0.063rem solid", borderColor: theme.colors.gray[300], borderRadius: "md", boxShadow: "md", minW: "10rem", maxW: "38rem" }, (_j = insideSelect === null || insideSelect === void 0 ? void 0 : insideSelect.option) === null || _j === void 0 ? void 0 : _j.map(function (item) { return (react_1.default.createElement(react_2.Box, { key: item.id, display: "flex", alignItems: "center", minH: s.optionRowMinH, px: "0.75rem", fontSize: s.dropdownTextFontSize, _hover: { bg: theme.colors.gray[100] }, cursor: "pointer", onClick: function (e) {
|
|
240
243
|
e.stopPropagation();
|
|
241
244
|
handleCustomSelect(item);
|
|
242
245
|
} }, item.label)); })))))),
|
|
@@ -245,42 +248,42 @@ var SearchSelect = function (_a) {
|
|
|
245
248
|
.slice(0, (chip === null || chip === void 0 ? void 0 : chip.maxChips) || selectedValues.length)
|
|
246
249
|
.map(function (item) { return (react_1.default.createElement(Tag_1.default, { key: item.id, label: (chip === null || chip === void 0 ? void 0 : chip.maxText) && item.label.length > chip.maxText
|
|
247
250
|
? item.label.slice(0, chip.maxText) + "…"
|
|
248
|
-
: item.label, onIconClick: (chip === null || chip === void 0 ? void 0 : chip.onClick) ? function () { return handleRemove(item === null || item === void 0 ? void 0 : item.id); } : undefined, icon: (chip === null || chip === void 0 ? void 0 : chip.onClick) ? lucide_react_1.CircleX : undefined, colorScheme: "gray", size:
|
|
251
|
+
: item.label, onIconClick: (chip === null || chip === void 0 ? void 0 : chip.onClick) ? function () { return handleRemove(item === null || item === void 0 ? void 0 : item.id); } : undefined, icon: (chip === null || chip === void 0 ? void 0 : chip.onClick) ? lucide_react_1.CircleX : undefined, colorScheme: "gray", size: s.tagSize })); })
|
|
249
252
|
: selectedValues.length === 1 &&
|
|
250
|
-
!isOpen && (react_1.default.createElement(react_2.Box, { as: "button", type: "button", onClick: function () { return setIsOpen(true); }, fontSize:
|
|
251
|
-
react_1.default.createElement(SelectTruncatedLabel_1.default, { label: String(selectedValues[0].label), maxWidth: "calc(100% - 2rem)" }))),
|
|
252
|
-
(chip === null || chip === void 0 ? void 0 : chip.maxChips) && isMultiple && selectedValues.length > chip.maxChips && (react_1.default.createElement(Tag_1.default, { key: "extra-count", label: "+ ".concat(selectedValues.length - chip.maxChips), colorScheme: "gray", size:
|
|
253
|
-
(isOpen || inputValue || !selectedValues.length) && (react_1.default.createElement(react_2.Input, { ref: inputRef, variant: "unstyled", flex: "1",
|
|
253
|
+
!isOpen && (react_1.default.createElement(react_2.Box, { as: "button", type: "button", onClick: function () { return setIsOpen(true); }, fontSize: s.fieldFontSize, color: theme.colors.gray[800], background: "transparent", border: "none", cursor: "pointer", p: 0, display: "flex", alignItems: "center", flex: "1", minW: 0 },
|
|
254
|
+
react_1.default.createElement(SelectTruncatedLabel_1.default, { label: String(selectedValues[0].label), maxWidth: "calc(100% - 2rem)", fontSize: s.fieldFontSize }))),
|
|
255
|
+
(chip === null || chip === void 0 ? void 0 : chip.maxChips) && isMultiple && selectedValues.length > chip.maxChips && (react_1.default.createElement(Tag_1.default, { key: "extra-count", label: "+ ".concat(selectedValues.length - chip.maxChips), colorScheme: "gray", size: s.tagSize })),
|
|
256
|
+
(isOpen || inputValue || !selectedValues.length) && (react_1.default.createElement(react_2.Input, { ref: inputRef, variant: "unstyled", size: size, h: s.fieldHeight, minH: s.fieldHeight, fontSize: s.fieldFontSize, flex: "1",
|
|
254
257
|
// minW="5rem"
|
|
255
258
|
minW: "0", value: inputValue, onChange: function (e) { return setInputValue(e.target.value); }, onFocus: function () {
|
|
256
259
|
setFocused(true);
|
|
257
260
|
setIsOpen(true);
|
|
258
261
|
}, onBlur: function () { return setFocused(false); }, placeholder: selectedValues.length && !isOpen ? "" : placeholder })),
|
|
259
|
-
react_1.default.createElement(react_2.Box, { position: "absolute", right:
|
|
262
|
+
react_1.default.createElement(react_2.Box, { position: "absolute", right: s.rightOffset, top: "50%", transform: "translateY(-50%)", display: "flex", alignItems: "center", gap: 1 },
|
|
260
263
|
isRemoveAllIcon && selectedValues.length > 0 && (react_1.default.createElement(ToolTip_1.default, { placement: "top", label: "Remove All", hasArrow: true, bg: theme.colors.gray[600], color: theme.colors.white, fontSize: "0.75rem" },
|
|
261
|
-
react_1.default.createElement(react_2.IconButton, { icon: react_1.default.createElement(lucide_react_1.X, { size:
|
|
264
|
+
react_1.default.createElement(react_2.IconButton, { icon: react_1.default.createElement(lucide_react_1.X, { size: s.clearIconSize, color: theme.colors.black }), "aria-label": "Clear all", variant: "ghost", size: s.iconButtonSize, onClick: handleClearAll, sx: {
|
|
262
265
|
bg: "transparent",
|
|
263
266
|
_hover: { bg: "transparent" },
|
|
264
267
|
_active: { bg: "transparent" },
|
|
265
268
|
_focus: { boxShadow: "none", bg: "transparent" },
|
|
266
269
|
} }))),
|
|
267
|
-
isLoading ? (react_1.default.createElement(react_2.Spinner, { size:
|
|
270
|
+
isLoading ? (react_1.default.createElement(react_2.Spinner, { size: s.spinnerSize })) : isValidIcon(rightIcon === null || rightIcon === void 0 ? void 0 : rightIcon.icon) ? (react_1.default.createElement(react_2.IconButton, { icon: rightIcon === null || rightIcon === void 0 ? void 0 : rightIcon.icon, "aria-label": "right-icon", variant: "ghost", size: s.iconButtonSize, onClick: rightIcon === null || rightIcon === void 0 ? void 0 : rightIcon.onClick })) : (react_1.default.createElement(react_2.Box, { as: "button", onClick: function (e) {
|
|
268
271
|
e.preventDefault();
|
|
269
272
|
e.stopPropagation();
|
|
270
273
|
setIsOpen(function (prev) { return !prev; });
|
|
271
|
-
}, "aria-label": "toggle-dropdown", display: "flex", alignItems: "center" }, isOpen ? react_1.default.createElement(lucide_react_1.ChevronUp, { size:
|
|
274
|
+
}, "aria-label": "toggle-dropdown", display: "flex", alignItems: "center" }, isOpen ? (react_1.default.createElement(lucide_react_1.ChevronUp, { size: s.chevronSize })) : (react_1.default.createElement(lucide_react_1.ChevronDown, { size: s.chevronSize }))))))),
|
|
272
275
|
isOpen && (react_1.default.createElement(react_2.Box, { position: "absolute", zIndex: 10, width: "100%", maxH: "20rem", borderWidth: 1, borderRadius: "sm", bg: theme.colors.white, boxShadow: "md", display: "flex", flexDirection: "column" },
|
|
273
|
-
isMultiple && isSelectAll && (react_1.default.createElement(react_2.Box, {
|
|
274
|
-
react_1.default.createElement(react_2.Checkbox, { isChecked: allFilteredSelected, pointerEvents: "none" }),
|
|
275
|
-
react_1.default.createElement(react_2.Text, { fontSize:
|
|
276
|
-
react_1.default.createElement(react_2.Box, { flex: "1", overflowY: "auto", onScroll: handleScroll, maxH: "15rem", borderBottom: "0.063rem solid", borderColor: theme.colors.gray[200] }, isOptionLoading ? (react_1.default.createElement(react_2.Box, {
|
|
277
|
-
react_1.default.createElement(react_2.Spinner, { size:
|
|
278
|
-
react_1.default.createElement(react_2.Text, { fontSize:
|
|
279
|
-
isMultiple && (react_1.default.createElement(react_2.Checkbox, { isChecked: isSelected(option.id), pointerEvents: "none", colorScheme: "blue" })),
|
|
280
|
-
option.view ? (react_1.default.createElement(react_1.default.Fragment, null, option.view)) : (react_1.default.createElement(react_2.Text, { fontSize:
|
|
281
|
-
(addNew === null || addNew === void 0 ? void 0 : addNew.enabled) && (react_1.default.createElement(react_2.Box, {
|
|
282
|
-
addNew.icon || react_1.default.createElement(lucide_react_1.Plus, { size:
|
|
283
|
-
react_1.default.createElement(react_2.Text, { fontSize:
|
|
276
|
+
isMultiple && isSelectAll && (react_1.default.createElement(react_2.Box, { py: s.optionRowPy, px: 3, cursor: "pointer", onClick: handleSelectAll, display: "flex", alignItems: "center", gap: 2, borderBottom: "0.063rem solid ".concat(theme.colors.gray[100]) },
|
|
277
|
+
react_1.default.createElement(react_2.Checkbox, { isChecked: allFilteredSelected, pointerEvents: "none", size: s.checkboxSize }),
|
|
278
|
+
react_1.default.createElement(react_2.Text, { fontSize: s.dropdownTextFontSize }, allFilteredSelected ? "Unselect All" : "Select All"))),
|
|
279
|
+
react_1.default.createElement(react_2.Box, { flex: "1", overflowY: "auto", onScroll: handleScroll, maxH: "15rem", borderBottom: "0.063rem solid", borderColor: theme.colors.gray[200] }, isOptionLoading ? (react_1.default.createElement(react_2.Box, { py: s.optionRowPy, px: 3, display: "flex", alignItems: "center", gap: 2, minH: s.optionRowMinH },
|
|
280
|
+
react_1.default.createElement(react_2.Spinner, { size: s.spinnerSize }),
|
|
281
|
+
react_1.default.createElement(react_2.Text, { fontSize: s.dropdownTextFontSize }, loadingText))) : filteredOptions.length === 0 ? (react_1.default.createElement(react_2.Text, { p: 3, fontSize: s.dropdownTextFontSize, color: theme.colors.gray[500] }, "No results found")) : (filteredOptions.map(function (option) { return (react_1.default.createElement(react_2.Box, { key: option.id, py: s.optionRowPy, px: 3, minH: s.optionRowMinH, cursor: "pointer", bg: isSelected(option.id) ? theme.colors.gray[100] : "transparent", _hover: { bg: theme.colors.gray[50] }, onClick: function () { return handleSelect(option); }, display: "flex", alignItems: "center", gap: 2, borderBottom: "0.063rem solid ".concat(theme.colors.gray[100]) },
|
|
282
|
+
isMultiple && (react_1.default.createElement(react_2.Checkbox, { isChecked: isSelected(option.id), pointerEvents: "none", colorScheme: "blue", size: s.checkboxSize })),
|
|
283
|
+
option.view ? (react_1.default.createElement(react_1.default.Fragment, null, option.view)) : (react_1.default.createElement(react_2.Text, { fontSize: s.dropdownTextFontSize }, option.label)))); }))),
|
|
284
|
+
(addNew === null || addNew === void 0 ? void 0 : addNew.enabled) && (react_1.default.createElement(react_2.Box, { py: s.optionRowPy, px: 3, borderTop: "0.063rem solid", borderColor: theme.colors.gray[200], bg: theme.colors.white, display: "flex", alignItems: "center", gap: 2, minH: s.optionRowMinH, cursor: "pointer", onClick: addNew.onClick, _hover: { bg: theme.colors.gray[50] } },
|
|
285
|
+
addNew.icon || react_1.default.createElement(lucide_react_1.Plus, { size: s.addNewIconSize }),
|
|
286
|
+
react_1.default.createElement(react_2.Text, { fontSize: s.dropdownTextFontSize }, addNew.text || "Add New"))))),
|
|
284
287
|
helperText && !error && react_1.default.createElement(HelperText_1.default, { helperText: helperText }),
|
|
285
288
|
error && react_1.default.createElement(ErrorMessage_1.default, { errorMessage: errorMessage })));
|
|
286
289
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { TextProps } from "@chakra-ui/react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
declare const SelectTruncatedLabel: ({ label, maxWidth, fontSize, }: {
|
|
3
4
|
label: string;
|
|
4
5
|
maxWidth?: string;
|
|
5
|
-
}) => React.JSX.Element;
|
|
6
|
+
} & Pick<TextProps, "fontSize">) => React.JSX.Element;
|
|
6
7
|
export default SelectTruncatedLabel;
|
|
@@ -40,16 +40,16 @@ var react_1 = require("@chakra-ui/react");
|
|
|
40
40
|
var react_2 = __importStar(require("react"));
|
|
41
41
|
var ToolTip_1 = __importDefault(require("../ToolTip/ToolTip"));
|
|
42
42
|
var SelectTruncatedLabel = function (_a) {
|
|
43
|
-
var label = _a.label, _b = _a.maxWidth, maxWidth = _b === void 0 ? "6rem" : _b;
|
|
43
|
+
var label = _a.label, _b = _a.maxWidth, maxWidth = _b === void 0 ? "6rem" : _b, _c = _a.fontSize, fontSize = _c === void 0 ? "sm" : _c;
|
|
44
44
|
var textRef = (0, react_2.useRef)(null);
|
|
45
|
-
var
|
|
45
|
+
var _d = (0, react_2.useState)(false), isOverflowing = _d[0], setIsOverflowing = _d[1];
|
|
46
46
|
(0, react_2.useEffect)(function () {
|
|
47
47
|
var el = textRef.current;
|
|
48
48
|
if (el) {
|
|
49
49
|
setIsOverflowing(el.scrollWidth > el.clientWidth);
|
|
50
50
|
}
|
|
51
51
|
}, [label, maxWidth]);
|
|
52
|
-
var textElement = (react_2.default.createElement(react_1.Text, { ref: textRef, maxW: maxWidth, isTruncated: true, whiteSpace: "nowrap", fontWeight: 500, fontSize:
|
|
52
|
+
var textElement = (react_2.default.createElement(react_1.Text, { ref: textRef, maxW: maxWidth, isTruncated: true, whiteSpace: "nowrap", fontWeight: 500, fontSize: fontSize, letterSpacing: "0.044rem" }, label));
|
|
53
53
|
return isOverflowing ? react_2.default.createElement(ToolTip_1.default, { label: label, placement: "top" }, textElement) : textElement;
|
|
54
54
|
};
|
|
55
55
|
exports.default = SelectTruncatedLabel;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Layout tokens for SearchSelect so `size` matches Chakra input density (xs–lg).
|
|
3
|
+
*/
|
|
4
|
+
export type SearchSelectControlSize = "xs" | "sm" | "md" | "lg";
|
|
5
|
+
export type SearchSelectSizeStyles = {
|
|
6
|
+
minH: string;
|
|
7
|
+
/** Horizontal padding of the main field (Chakra spacing scale or rem). */
|
|
8
|
+
px: number;
|
|
9
|
+
/** Right padding to clear the absolute-positioned action icons. */
|
|
10
|
+
pr: string;
|
|
11
|
+
/** Vertical gap for wrapped chips. */
|
|
12
|
+
gap: string;
|
|
13
|
+
chevronSize: number;
|
|
14
|
+
iconButtonSize: "xs" | "sm" | "md" | "lg";
|
|
15
|
+
tagSize: "sm" | "md" | "lg";
|
|
16
|
+
spinnerSize: "sm" | "md" | "lg" | "xl" | "xs";
|
|
17
|
+
/** Default height for the `insideSelect` trigger when `height` prop is omitted. */
|
|
18
|
+
insideSelectDefaultHeight: string;
|
|
19
|
+
rightOffset: string;
|
|
20
|
+
clearIconSize: number;
|
|
21
|
+
addNewIconSize: number;
|
|
22
|
+
/** Offset for the nested select segment (aligns with field padding). */
|
|
23
|
+
insideSelectMarginLeft: string;
|
|
24
|
+
/** “Select all” / option row text in the dropdown. */
|
|
25
|
+
dropdownTextFontSize: "xs" | "sm" | "md";
|
|
26
|
+
/** Min row height for main option list items. */
|
|
27
|
+
optionRowMinH: string;
|
|
28
|
+
optionRowPy: number;
|
|
29
|
+
/** Chakra `Checkbox` only supports sm | md | lg. */
|
|
30
|
+
checkboxSize: "sm" | "md" | "lg";
|
|
31
|
+
/**
|
|
32
|
+
* Chakra `Input` uses these font tokens per `size` (unstyled still needs explicit fontSize).
|
|
33
|
+
*/
|
|
34
|
+
fieldFontSize: "xs" | "sm" | "md" | "lg";
|
|
35
|
+
/**
|
|
36
|
+
* Matches Chakra `Input` field height (`sizes.6`..`12`) so `unstyled` + `height: auto` does
|
|
37
|
+
* not prevent `size` from affecting the control.
|
|
38
|
+
*/
|
|
39
|
+
fieldHeight: string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Returns layout and child control tokens for a SearchSelect `size`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function getSearchSelectSizeStyles(size: SearchSelectControlSize): SearchSelectSizeStyles;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSearchSelectSizeStyles = getSearchSelectSizeStyles;
|
|
4
|
+
var SIZE_STYLES = {
|
|
5
|
+
xs: {
|
|
6
|
+
minH: "1.5rem",
|
|
7
|
+
px: 2,
|
|
8
|
+
pr: "1.75rem",
|
|
9
|
+
gap: "0.25rem",
|
|
10
|
+
fieldFontSize: "xs",
|
|
11
|
+
fieldHeight: "1.5rem",
|
|
12
|
+
chevronSize: 14,
|
|
13
|
+
iconButtonSize: "xs",
|
|
14
|
+
tagSize: "sm",
|
|
15
|
+
spinnerSize: "sm",
|
|
16
|
+
insideSelectDefaultHeight: "1.5rem",
|
|
17
|
+
rightOffset: "0.5rem",
|
|
18
|
+
clearIconSize: 10,
|
|
19
|
+
addNewIconSize: 14,
|
|
20
|
+
insideSelectMarginLeft: "-0.5rem",
|
|
21
|
+
dropdownTextFontSize: "xs",
|
|
22
|
+
optionRowMinH: "1.5rem",
|
|
23
|
+
optionRowPy: 1.5,
|
|
24
|
+
checkboxSize: "sm",
|
|
25
|
+
},
|
|
26
|
+
sm: {
|
|
27
|
+
minH: "2rem",
|
|
28
|
+
px: 2.5,
|
|
29
|
+
pr: "1.85rem",
|
|
30
|
+
gap: "0.3rem",
|
|
31
|
+
fieldFontSize: "sm",
|
|
32
|
+
fieldHeight: "2rem",
|
|
33
|
+
chevronSize: 16,
|
|
34
|
+
iconButtonSize: "sm",
|
|
35
|
+
tagSize: "sm",
|
|
36
|
+
spinnerSize: "sm",
|
|
37
|
+
insideSelectDefaultHeight: "2rem",
|
|
38
|
+
rightOffset: "0.5rem",
|
|
39
|
+
clearIconSize: 12,
|
|
40
|
+
addNewIconSize: 16,
|
|
41
|
+
insideSelectMarginLeft: "-0.625rem",
|
|
42
|
+
dropdownTextFontSize: "sm",
|
|
43
|
+
optionRowMinH: "2rem",
|
|
44
|
+
optionRowPy: 2,
|
|
45
|
+
checkboxSize: "sm",
|
|
46
|
+
},
|
|
47
|
+
md: {
|
|
48
|
+
minH: "2.5rem",
|
|
49
|
+
px: 3,
|
|
50
|
+
pr: "2rem",
|
|
51
|
+
gap: "0.375rem",
|
|
52
|
+
fieldFontSize: "sm",
|
|
53
|
+
fieldHeight: "2.5rem",
|
|
54
|
+
chevronSize: 16,
|
|
55
|
+
iconButtonSize: "sm",
|
|
56
|
+
tagSize: "sm",
|
|
57
|
+
spinnerSize: "sm",
|
|
58
|
+
insideSelectDefaultHeight: "2.5rem",
|
|
59
|
+
rightOffset: "0.75rem",
|
|
60
|
+
clearIconSize: 12,
|
|
61
|
+
addNewIconSize: 16,
|
|
62
|
+
insideSelectMarginLeft: "-0.75rem",
|
|
63
|
+
dropdownTextFontSize: "sm",
|
|
64
|
+
optionRowMinH: "2.5rem",
|
|
65
|
+
optionRowPy: 2,
|
|
66
|
+
checkboxSize: "md",
|
|
67
|
+
},
|
|
68
|
+
lg: {
|
|
69
|
+
minH: "3rem",
|
|
70
|
+
px: 4,
|
|
71
|
+
pr: "2.25rem",
|
|
72
|
+
gap: "0.5rem",
|
|
73
|
+
fieldFontSize: "sm",
|
|
74
|
+
fieldHeight: "3rem",
|
|
75
|
+
chevronSize: 18,
|
|
76
|
+
iconButtonSize: "md",
|
|
77
|
+
tagSize: "md",
|
|
78
|
+
spinnerSize: "md",
|
|
79
|
+
insideSelectDefaultHeight: "3rem",
|
|
80
|
+
rightOffset: "0.75rem",
|
|
81
|
+
clearIconSize: 14,
|
|
82
|
+
addNewIconSize: 18,
|
|
83
|
+
insideSelectMarginLeft: "-0.875rem",
|
|
84
|
+
dropdownTextFontSize: "md",
|
|
85
|
+
optionRowMinH: "2.75rem",
|
|
86
|
+
optionRowPy: 2.5,
|
|
87
|
+
checkboxSize: "lg",
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Returns layout and child control tokens for a SearchSelect `size`.
|
|
92
|
+
*/
|
|
93
|
+
function getSearchSelectSizeStyles(size) {
|
|
94
|
+
var _a;
|
|
95
|
+
return (_a = SIZE_STYLES[size]) !== null && _a !== void 0 ? _a : SIZE_STYLES.md;
|
|
96
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var searchSelectSize_1 = require("./searchSelectSize");
|
|
4
|
+
describe("getSearchSelectSizeStyles", function () {
|
|
5
|
+
it.each(["xs", "sm", "md", "lg"])("returns minH for %s", function (sz) {
|
|
6
|
+
var t = (0, searchSelectSize_1.getSearchSelectSizeStyles)(sz);
|
|
7
|
+
expect(t.minH).toMatch(/rem$/);
|
|
8
|
+
expect(t.insideSelectDefaultHeight).toMatch(/rem$/);
|
|
9
|
+
});
|
|
10
|
+
it("xs is more compact than lg", function () {
|
|
11
|
+
var xs = (0, searchSelectSize_1.getSearchSelectSizeStyles)("xs");
|
|
12
|
+
var lg = (0, searchSelectSize_1.getSearchSelectSizeStyles)("lg");
|
|
13
|
+
var parse = function (h) { return parseFloat(h); };
|
|
14
|
+
expect(parse(xs.minH)).toBeLessThan(parse(lg.minH));
|
|
15
|
+
expect(parse(xs.insideSelectDefaultHeight)).toBeLessThan(parse(lg.insideSelectDefaultHeight));
|
|
16
|
+
});
|
|
17
|
+
it("uses md as fallback for unknown size keys (runtime map lookup)", function () {
|
|
18
|
+
var t = (0, searchSelectSize_1.getSearchSelectSizeStyles)("unknown");
|
|
19
|
+
var md = (0, searchSelectSize_1.getSearchSelectSizeStyles)("md");
|
|
20
|
+
expect(t).toEqual(md);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
14
|
if (k2 === undefined) k2 = k;
|
|
4
15
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -39,11 +50,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
50
|
exports.default = Select;
|
|
40
51
|
var react_1 = __importStar(require("react"));
|
|
41
52
|
var react_2 = require("@chakra-ui/react");
|
|
53
|
+
var textInputIconSize_1 = require("../Input/textInputIconSize");
|
|
42
54
|
var FormLabel_1 = require("../Common/FormLabel");
|
|
43
55
|
var ErrorMessage_1 = __importDefault(require("../Common/ErrorMessage"));
|
|
44
56
|
var HelperText_1 = __importDefault(require("../Common/HelperText"));
|
|
45
57
|
function Select(_a) {
|
|
46
|
-
var _b = _a.placeholder, placeholder = _b === void 0 ? "Select Option" : _b, _c = _a.size, size = _c === void 0 ? "md" : _c, _d = _a.variant, variant = _d === void 0 ? "outline" : _d, icon = _a.icon, onChange = _a.onChange, onBlur = _a.onBlur, onFocus = _a.onFocus, errorBorderColor = _a.errorBorderColor, isDisabled = _a.isDisabled, isReadOnly = _a.isReadOnly, _e = _a.isRequired, isRequired = _e === void 0 ? false : _e, _f = _a.value, value = _f === void 0 ? "" : _f, colorScheme = _a.colorScheme, label = _a.label, error = _a.error, errorMessage = _a.errorMessage, helperText = _a.helperText, _g = _a.options, options = _g === void 0 ? [] : _g,
|
|
58
|
+
var _b = _a.placeholder, placeholder = _b === void 0 ? "Select Option" : _b, _c = _a.size, size = _c === void 0 ? "md" : _c, _d = _a.variant, variant = _d === void 0 ? "outline" : _d, icon = _a.icon, onChange = _a.onChange, onBlur = _a.onBlur, onFocus = _a.onFocus, errorBorderColor = _a.errorBorderColor, isDisabled = _a.isDisabled, isReadOnly = _a.isReadOnly, _e = _a.isRequired, isRequired = _e === void 0 ? false : _e, _f = _a.value, value = _f === void 0 ? "" : _f, colorScheme = _a.colorScheme, label = _a.label, error = _a.error, errorMessage = _a.errorMessage, helperText = _a.helperText, _g = _a.options, options = _g === void 0 ? [] : _g, height = _a.height, formControlStyle = _a.formControlStyle, _h = _a.isInformation, isInformation = _h === void 0 ? false : _h, informationMessage = _a.informationMessage, selectStyle = _a.selectStyle;
|
|
59
|
+
var sizeKey = typeof size === "string" ? size : "md";
|
|
60
|
+
var iconSizePx = (0, textInputIconSize_1.getTextInputIconSizePx)(sizeKey);
|
|
47
61
|
var getOptionsList = (0, react_1.useCallback)(function () {
|
|
48
62
|
if (!options.length)
|
|
49
63
|
return react_1.default.createElement("option", { value: "" }, "No Options");
|
|
@@ -56,9 +70,9 @@ function Select(_a) {
|
|
|
56
70
|
onChange(selectedOption);
|
|
57
71
|
}
|
|
58
72
|
};
|
|
59
|
-
return (react_1.default.createElement(react_2.FormControl, { isInvalid: error, style: formControlStyle },
|
|
73
|
+
return (react_1.default.createElement(react_2.FormControl, { isInvalid: error, style: formControlStyle, size: size },
|
|
60
74
|
label && (react_1.default.createElement(FormLabel_1.TextLabel, { label: label, isRequired: isRequired, isInformation: isInformation, informationMessage: informationMessage })),
|
|
61
|
-
react_1.default.createElement(react_2.Select, { placeholder: placeholder, size: size, variant: variant, icon: icon, isInvalid: error, value: value, onChange: handleOnChange, onBlur: onBlur, onFocus: onFocus, isDisabled: isDisabled, isReadOnly: isReadOnly, colorScheme: colorScheme, errorBorderColor: errorBorderColor, style: selectStyle, minH: height }, getOptionsList()),
|
|
75
|
+
react_1.default.createElement(react_2.Select, __assign({ placeholder: placeholder, size: size, variant: variant, icon: icon, iconSize: "".concat(iconSizePx, "px"), isInvalid: error, value: value, onChange: handleOnChange, onBlur: onBlur, onFocus: onFocus, isDisabled: isDisabled, isReadOnly: isReadOnly, colorScheme: colorScheme, errorBorderColor: errorBorderColor, style: selectStyle }, (height != null && height !== "" ? { minH: height, h: height } : {})), getOptionsList()),
|
|
62
76
|
error && react_1.default.createElement(ErrorMessage_1.default, { errorMessage: errorMessage }),
|
|
63
77
|
helperText && !error && react_1.default.createElement(HelperText_1.default, { helperText: helperText })));
|
|
64
78
|
}
|
|
@@ -9,7 +9,7 @@ var Tag = function (_a) {
|
|
|
9
9
|
var label = _a.label, _b = _a.colorScheme, colorScheme = _b === void 0 ? "primary" : _b, _c = _a.variant, variant = _c === void 0 ? "solid" : _c, _d = _a.size, size = _d === void 0 ? "md" : _d, icon = _a.icon, onTagClick = _a.onTagClick, onIconClick = _a.onIconClick;
|
|
10
10
|
return (react_1.default.createElement(react_2.Tag, { size: size, variant: variant, colorScheme: colorScheme, borderRadius: "full", cursor: "pointer", onClick: function () { return onTagClick === null || onTagClick === void 0 ? void 0 : onTagClick(); } },
|
|
11
11
|
react_1.default.createElement(react_2.TagLabel, null, label),
|
|
12
|
-
icon && (react_1.default.createElement(react_2.TagRightIcon, { as: icon, boxSize: "1em",
|
|
12
|
+
icon && (react_1.default.createElement(react_2.TagRightIcon, { as: icon, boxSize: "1em", cursor: onIconClick ? "pointer" : "default", onClick: function (e) {
|
|
13
13
|
e.stopPropagation();
|
|
14
14
|
onIconClick === null || onIconClick === void 0 ? void 0 : onIconClick();
|
|
15
15
|
}, transition: "all 0.2s ease", _hover: {
|