@vention/machine-ui 5.22.0 → 5.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.esm.js
CHANGED
|
@@ -8878,7 +8878,7 @@ $$9({ target: 'Map', proto: true, real: true, forced: IS_PURE }, {
|
|
|
8878
8878
|
}
|
|
8879
8879
|
});
|
|
8880
8880
|
|
|
8881
|
-
const
|
|
8881
|
+
const getSelectIconSize = size => {
|
|
8882
8882
|
switch (size) {
|
|
8883
8883
|
case "small":
|
|
8884
8884
|
case "medium":
|
|
@@ -8889,7 +8889,33 @@ const getChevronIconSize = size => {
|
|
|
8889
8889
|
return 32;
|
|
8890
8890
|
}
|
|
8891
8891
|
};
|
|
8892
|
+
const MenuItemContent = ({
|
|
8893
|
+
size,
|
|
8894
|
+
icon,
|
|
8895
|
+
children
|
|
8896
|
+
}) => jsxs(Box$1, {
|
|
8897
|
+
display: "flex",
|
|
8898
|
+
alignItems: "center",
|
|
8899
|
+
gap: 2,
|
|
8900
|
+
minWidth: 0,
|
|
8901
|
+
children: [icon !== undefined && jsx(Box$1, {
|
|
8902
|
+
display: "flex",
|
|
8903
|
+
flexShrink: 0,
|
|
8904
|
+
children: jsx(VentionIcon, {
|
|
8905
|
+
type: icon,
|
|
8906
|
+
size: getSelectIconSize(size),
|
|
8907
|
+
color: "inherit"
|
|
8908
|
+
})
|
|
8909
|
+
}), children]
|
|
8910
|
+
});
|
|
8911
|
+
const MenuItemDivider = ({
|
|
8912
|
+
className
|
|
8913
|
+
}) => jsx("li", {
|
|
8914
|
+
role: "separator",
|
|
8915
|
+
className: className
|
|
8916
|
+
});
|
|
8892
8917
|
const VentionSelect = props => {
|
|
8918
|
+
var _a;
|
|
8893
8919
|
const {
|
|
8894
8920
|
classes
|
|
8895
8921
|
} = useStyles$q(props);
|
|
@@ -8902,13 +8928,16 @@ const VentionSelect = props => {
|
|
|
8902
8928
|
isDisabled,
|
|
8903
8929
|
onChange,
|
|
8904
8930
|
errorText,
|
|
8931
|
+
helperText,
|
|
8905
8932
|
isMultiple,
|
|
8906
8933
|
state = "default"
|
|
8907
8934
|
} = props,
|
|
8908
|
-
other = __rest(props, ["size", "placeholder", "value", "menuItems", "labelText", "isDisabled", "onChange", "errorText", "isMultiple", "state"]);
|
|
8935
|
+
other = __rest(props, ["size", "placeholder", "value", "menuItems", "labelText", "isDisabled", "onChange", "errorText", "helperText", "isMultiple", "state"]);
|
|
8909
8936
|
const theme = useTheme$1();
|
|
8910
8937
|
const typographyVariants = typographyNameFromSizeMap[size];
|
|
8911
|
-
const menuItemsMap = useMemo(() => new Map(menuItems.map(item => [item.value, item])), [menuItems]);
|
|
8938
|
+
const menuItemsMap = useMemo(() => new Map(menuItems.filter(isMenuItem).map(item => [item.value, item])), [menuItems]);
|
|
8939
|
+
const selectedHelperText = Array.isArray(value) ? undefined : (_a = menuItemsMap.get(value)) === null || _a === void 0 ? void 0 : _a.helperText;
|
|
8940
|
+
const helperTextToDisplay = selectedHelperText !== null && selectedHelperText !== void 0 ? selectedHelperText : helperText;
|
|
8912
8941
|
return jsx(FormControl, {
|
|
8913
8942
|
fullWidth: true,
|
|
8914
8943
|
error: Boolean(errorText),
|
|
@@ -8925,7 +8954,7 @@ const VentionSelect = props => {
|
|
|
8925
8954
|
className: classes.chevronIconContainer,
|
|
8926
8955
|
children: jsx(VentionIcon, {
|
|
8927
8956
|
type: "chevron-down",
|
|
8928
|
-
size:
|
|
8957
|
+
size: getSelectIconSize(size),
|
|
8929
8958
|
color: theme.palette.icon.primary
|
|
8930
8959
|
})
|
|
8931
8960
|
}),
|
|
@@ -8952,8 +8981,8 @@ const VentionSelect = props => {
|
|
|
8952
8981
|
if (isMultiple) {
|
|
8953
8982
|
if (!Array.isArray(selected)) throw new Error("Selected value must be an array when isMultiple is true");
|
|
8954
8983
|
const isOnlyText = selected.every(value => {
|
|
8955
|
-
|
|
8956
|
-
return (
|
|
8984
|
+
const menuItem = menuItemsMap.get(value);
|
|
8985
|
+
return (menuItem === null || menuItem === void 0 ? void 0 : menuItem.displayNode) === undefined && (menuItem === null || menuItem === void 0 ? void 0 : menuItem.icon) === undefined;
|
|
8957
8986
|
});
|
|
8958
8987
|
if (isOnlyText) {
|
|
8959
8988
|
const _inputValue = selected.map(value => {
|
|
@@ -8972,9 +9001,12 @@ const VentionSelect = props => {
|
|
|
8972
9001
|
gap: theme.spacing(2),
|
|
8973
9002
|
className: classes.inputValue,
|
|
8974
9003
|
children: selected.map(value => {
|
|
9004
|
+
var _a;
|
|
8975
9005
|
const menuItem = menuItemsMap.get(value);
|
|
8976
|
-
return jsx(
|
|
8977
|
-
|
|
9006
|
+
return jsx(MenuItemContent, {
|
|
9007
|
+
size: size,
|
|
9008
|
+
icon: menuItem === null || menuItem === void 0 ? void 0 : menuItem.icon,
|
|
9009
|
+
children: menuItem && "displayNode" in menuItem ? menuItem.displayNode : (_a = menuItem === null || menuItem === void 0 ? void 0 : menuItem.displayText) !== null && _a !== void 0 ? _a : value
|
|
8978
9010
|
}, toReactKey(value));
|
|
8979
9011
|
})
|
|
8980
9012
|
});
|
|
@@ -8984,19 +9016,30 @@ const VentionSelect = props => {
|
|
|
8984
9016
|
const inputValue = (_b = (_a = menuItemSelected === null || menuItemSelected === void 0 ? void 0 : menuItemSelected.displayText) !== null && _a !== void 0 ? _a : menuItemSelected === null || menuItemSelected === void 0 ? void 0 : menuItemSelected.displayNode) !== null && _b !== void 0 ? _b : selected;
|
|
8985
9017
|
return jsx("div", {
|
|
8986
9018
|
className: classes.inputValue,
|
|
8987
|
-
children:
|
|
9019
|
+
children: jsx(MenuItemContent, {
|
|
9020
|
+
size: size,
|
|
9021
|
+
icon: menuItemSelected === null || menuItemSelected === void 0 ? void 0 : menuItemSelected.icon,
|
|
9022
|
+
children: inputValue
|
|
9023
|
+
})
|
|
8988
9024
|
});
|
|
8989
9025
|
}
|
|
8990
9026
|
}, other, {
|
|
8991
|
-
children: menuItems.map(item =>
|
|
9027
|
+
children: menuItems.map((item, index) => isMenuItem(item) ? jsx(MenuItem, {
|
|
8992
9028
|
value: item.value,
|
|
8993
9029
|
className: classes.menuItem,
|
|
8994
9030
|
disableRipple: true,
|
|
8995
|
-
children:
|
|
8996
|
-
|
|
8997
|
-
|
|
8998
|
-
|
|
8999
|
-
|
|
9031
|
+
children: jsxs(MenuItemContent, {
|
|
9032
|
+
size: size,
|
|
9033
|
+
icon: item.icon,
|
|
9034
|
+
children: ["displayText" in item && jsx(Typography, {
|
|
9035
|
+
variant: typographyVariants.text,
|
|
9036
|
+
children: item.displayText
|
|
9037
|
+
}), "displayNode" in item && item.displayNode]
|
|
9038
|
+
})
|
|
9039
|
+
}, `select-menu-item-${toReactKey(item.value)}`) : jsx(MenuItemDivider, {
|
|
9040
|
+
className: classes.divider,
|
|
9041
|
+
disabled: true
|
|
9042
|
+
}, `divider-${index}`))
|
|
9000
9043
|
})), errorText && jsxs(FormHelperText, {
|
|
9001
9044
|
error: Boolean(errorText),
|
|
9002
9045
|
classes: {
|
|
@@ -9008,6 +9051,14 @@ const VentionSelect = props => {
|
|
|
9008
9051
|
variant: typographyVariants.helperText,
|
|
9009
9052
|
children: errorText
|
|
9010
9053
|
})]
|
|
9054
|
+
}), !errorText && helperTextToDisplay && jsx(FormHelperText, {
|
|
9055
|
+
classes: {
|
|
9056
|
+
root: classes.helperText
|
|
9057
|
+
},
|
|
9058
|
+
children: jsx(Typography, {
|
|
9059
|
+
variant: typographyVariants.helperText,
|
|
9060
|
+
children: helperTextToDisplay
|
|
9061
|
+
})
|
|
9011
9062
|
})]
|
|
9012
9063
|
})
|
|
9013
9064
|
});
|
|
@@ -9110,6 +9161,16 @@ const useStyles$q = tss.withParams().create(({
|
|
|
9110
9161
|
gap: theme.spacing(1),
|
|
9111
9162
|
alignItems: "center"
|
|
9112
9163
|
},
|
|
9164
|
+
helperText: {
|
|
9165
|
+
marginLeft: 0,
|
|
9166
|
+
color: theme.palette.text.secondary
|
|
9167
|
+
},
|
|
9168
|
+
divider: {
|
|
9169
|
+
height: 0,
|
|
9170
|
+
listStyle: "none",
|
|
9171
|
+
margin: `${theme.spacing(2)} ${theme.spacing(3)}`,
|
|
9172
|
+
borderTop: `1px solid ${theme.palette.border.default}`
|
|
9173
|
+
},
|
|
9113
9174
|
placeholder: {
|
|
9114
9175
|
color: theme.palette.text.tertiary,
|
|
9115
9176
|
overflow: "hidden",
|
|
@@ -9164,6 +9225,9 @@ const getIconSize = size => {
|
|
|
9164
9225
|
return 14;
|
|
9165
9226
|
}
|
|
9166
9227
|
};
|
|
9228
|
+
function isMenuItem(item) {
|
|
9229
|
+
return item.type !== "divider";
|
|
9230
|
+
}
|
|
9167
9231
|
/**
|
|
9168
9232
|
* `undefined` is not a valid React key, so we'll format it to the string `"undefined"`
|
|
9169
9233
|
*/
|
package/package.json
CHANGED
|
@@ -2,21 +2,30 @@ import { SelectChangeEvent, SelectProps } from "@mui/material";
|
|
|
2
2
|
import { Sizes, StrictExtract } from "../../theme/machine-ui-theme";
|
|
3
3
|
import { ReactNode } from "react";
|
|
4
4
|
import { InputStates } from "../shared/types/input-types";
|
|
5
|
+
import { DuotoneIconType, IconType } from "../vention-icon/vention-icon";
|
|
5
6
|
export type VentionSelectMenuItem<T> = {
|
|
7
|
+
type?: never;
|
|
6
8
|
value: T;
|
|
7
9
|
displayText?: string;
|
|
8
10
|
displayNode?: ReactNode;
|
|
11
|
+
icon?: IconType | DuotoneIconType;
|
|
12
|
+
helperText?: string;
|
|
9
13
|
};
|
|
14
|
+
export type VentionSelectDivider = {
|
|
15
|
+
type: "divider";
|
|
16
|
+
};
|
|
17
|
+
export type VentionSelectItem<T> = VentionSelectMenuItem<T> | VentionSelectDivider;
|
|
10
18
|
export interface VentionSelectProps extends Omit<SelectProps, "placeholder" | "size" | "defaultValue" | "label"> {
|
|
11
19
|
size: StrictExtract<Sizes, "small" | "medium" | "large" | "x-large" | "xx-large">;
|
|
12
20
|
variant: "outlined";
|
|
13
21
|
value: string | number | string[] | number[] | undefined;
|
|
14
22
|
onChange: (event: SelectChangeEvent<VentionSelectProps["value"]>, child: ReactNode) => void;
|
|
15
|
-
menuItems: ReadonlyArray<
|
|
23
|
+
menuItems: ReadonlyArray<VentionSelectItem<string | number | undefined>>;
|
|
16
24
|
labelText?: string;
|
|
17
25
|
isDisabled?: boolean;
|
|
18
26
|
placeholder?: string;
|
|
19
27
|
errorText?: string;
|
|
28
|
+
helperText?: string;
|
|
20
29
|
isMultiple?: boolean;
|
|
21
30
|
state?: StrictExtract<InputStates, "default" | "warning">;
|
|
22
31
|
}
|