@xsolla/xui-button 0.192.0 → 0.193.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/README.md +13 -1
- package/native/index.d.mts +8 -3
- package/native/index.d.ts +8 -3
- package/native/index.js +321 -306
- package/native/index.js.map +1 -1
- package/native/index.mjs +325 -310
- package/native/index.mjs.map +1 -1
- package/package.json +4 -4
- package/web/index.d.mts +8 -3
- package/web/index.d.ts +8 -3
- package/web/index.js +321 -306
- package/web/index.js.map +1 -1
- package/web/index.mjs +325 -310
- package/web/index.mjs.map +1 -1
package/native/index.js
CHANGED
|
@@ -34,7 +34,8 @@ __export(index_exports, {
|
|
|
34
34
|
Button: () => Button,
|
|
35
35
|
ButtonGroup: () => ButtonGroup,
|
|
36
36
|
FlexButton: () => FlexButton,
|
|
37
|
-
IconButton: () => IconButton
|
|
37
|
+
IconButton: () => IconButton,
|
|
38
|
+
getFlexButtonBoxSize: () => getFlexButtonBoxSize
|
|
38
39
|
});
|
|
39
40
|
module.exports = __toCommonJS(index_exports);
|
|
40
41
|
|
|
@@ -811,6 +812,20 @@ IconButton.displayName = "IconButton";
|
|
|
811
812
|
var import_react4 = __toESM(require("react"));
|
|
812
813
|
var import_xui_core3 = require("@xsolla/xui-core");
|
|
813
814
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
815
|
+
var ICON_SIZES = {
|
|
816
|
+
xs: 12,
|
|
817
|
+
sm: 14,
|
|
818
|
+
md: 16,
|
|
819
|
+
lg: 18,
|
|
820
|
+
xl: 20
|
|
821
|
+
};
|
|
822
|
+
var SPINNER_SIZES = {
|
|
823
|
+
xs: 12,
|
|
824
|
+
sm: 14,
|
|
825
|
+
md: 16,
|
|
826
|
+
lg: 18,
|
|
827
|
+
xl: 20
|
|
828
|
+
};
|
|
814
829
|
var FLEX_BUTTON_PADDING = 4;
|
|
815
830
|
var hasVisibleLabel = (node) => {
|
|
816
831
|
if (node == null || node === false || node === true) return false;
|
|
@@ -829,20 +844,14 @@ var hasRenderableContent = (node) => {
|
|
|
829
844
|
if (Array.isArray(node)) return node.some(hasRenderableContent);
|
|
830
845
|
return true;
|
|
831
846
|
};
|
|
832
|
-
var
|
|
833
|
-
xs:
|
|
834
|
-
sm:
|
|
835
|
-
md:
|
|
836
|
-
lg:
|
|
837
|
-
xl:
|
|
838
|
-
};
|
|
839
|
-
var SPINNER_SIZES = {
|
|
840
|
-
xs: 12,
|
|
841
|
-
sm: 14,
|
|
842
|
-
md: 16,
|
|
843
|
-
lg: 18,
|
|
844
|
-
xl: 20
|
|
847
|
+
var BOX_SIZES = {
|
|
848
|
+
xs: 20,
|
|
849
|
+
sm: 22,
|
|
850
|
+
md: 28,
|
|
851
|
+
lg: 32,
|
|
852
|
+
xl: 36
|
|
845
853
|
};
|
|
854
|
+
var getFlexButtonBoxSize = (size = "md") => BOX_SIZES[size];
|
|
846
855
|
var LINE_HEIGHTS = {
|
|
847
856
|
xs: "14px",
|
|
848
857
|
sm: "16px",
|
|
@@ -864,320 +873,325 @@ var BORDER_RADIUS = {
|
|
|
864
873
|
sm: 2,
|
|
865
874
|
xs: 2
|
|
866
875
|
};
|
|
867
|
-
var FlexButton = (
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
border: void 0
|
|
903
|
-
};
|
|
904
|
-
}
|
|
905
|
-
const effectiveBackground = loading ? false : background;
|
|
906
|
-
switch (variant) {
|
|
907
|
-
case "brand":
|
|
908
|
-
if (effectiveBackground) {
|
|
909
|
-
return {
|
|
910
|
-
bg: currentState === "press" ? theme.colors.control.brand.primary.bgPress : currentState === "hover" ? theme.colors.control.brand.primary.bgHover : theme.colors.background.brand.primary,
|
|
911
|
-
text: theme.colors.content.on.brand,
|
|
912
|
-
border: void 0
|
|
913
|
-
};
|
|
914
|
-
}
|
|
876
|
+
var FlexButton = (0, import_react4.forwardRef)(
|
|
877
|
+
({
|
|
878
|
+
children,
|
|
879
|
+
variant = "brand",
|
|
880
|
+
size = "md",
|
|
881
|
+
background = false,
|
|
882
|
+
hoverBackground = true,
|
|
883
|
+
noPadding = false,
|
|
884
|
+
disabled = false,
|
|
885
|
+
loading = false,
|
|
886
|
+
iconLeft,
|
|
887
|
+
iconRight,
|
|
888
|
+
onPress,
|
|
889
|
+
onClick,
|
|
890
|
+
className,
|
|
891
|
+
type = "button",
|
|
892
|
+
"aria-label": ariaLabel,
|
|
893
|
+
"aria-describedby": ariaDescribedBy,
|
|
894
|
+
"aria-expanded": ariaExpanded,
|
|
895
|
+
"aria-haspopup": ariaHasPopup,
|
|
896
|
+
"aria-pressed": ariaPressed,
|
|
897
|
+
"aria-controls": ariaControls,
|
|
898
|
+
testID,
|
|
899
|
+
tabIndex = 0,
|
|
900
|
+
themeMode,
|
|
901
|
+
themeProductContext,
|
|
902
|
+
...buttonProps
|
|
903
|
+
}, ref) => {
|
|
904
|
+
const { theme } = (0, import_xui_core3.useResolvedTheme)({ themeMode, themeProductContext });
|
|
905
|
+
const [state, setState] = (0, import_react4.useState)("default");
|
|
906
|
+
const [isFocused, setIsFocused] = (0, import_react4.useState)(false);
|
|
907
|
+
const isMouseOverRef = (0, import_react4.useRef)(false);
|
|
908
|
+
const isDisabled = disabled || loading;
|
|
909
|
+
const getVariantColors = (currentState) => {
|
|
910
|
+
if (isDisabled) {
|
|
915
911
|
return {
|
|
916
|
-
bg:
|
|
917
|
-
text:
|
|
912
|
+
bg: background ? theme.colors.overlay.mono : "transparent",
|
|
913
|
+
text: theme.colors.control.text.disable,
|
|
918
914
|
border: void 0
|
|
919
915
|
};
|
|
920
|
-
|
|
921
|
-
|
|
916
|
+
}
|
|
917
|
+
const effectiveBackground = loading ? false : background;
|
|
918
|
+
switch (variant) {
|
|
919
|
+
case "brand":
|
|
920
|
+
if (effectiveBackground) {
|
|
921
|
+
return {
|
|
922
|
+
bg: currentState === "press" ? theme.colors.control.brand.primary.bgPress : currentState === "hover" ? theme.colors.control.brand.primary.bgHover : theme.colors.background.brand.primary,
|
|
923
|
+
text: theme.colors.content.on.brand,
|
|
924
|
+
border: void 0
|
|
925
|
+
};
|
|
926
|
+
}
|
|
927
|
+
return {
|
|
928
|
+
bg: !hoverBackground ? "transparent" : currentState === "press" ? theme.colors.background.brand.primary : currentState === "hover" ? theme.colors.overlay.brand : "transparent",
|
|
929
|
+
text: currentState === "press" && hoverBackground ? theme.colors.content.on.brand : theme.colors.content.brand.primary,
|
|
930
|
+
border: void 0
|
|
931
|
+
};
|
|
932
|
+
case "primary":
|
|
933
|
+
if (effectiveBackground) {
|
|
934
|
+
return {
|
|
935
|
+
bg: theme.colors.background.primary,
|
|
936
|
+
text: theme.colors.content.primary,
|
|
937
|
+
border: currentState === "press" ? theme.colors.border.primary : void 0
|
|
938
|
+
};
|
|
939
|
+
}
|
|
922
940
|
return {
|
|
923
|
-
bg: theme.colors.
|
|
941
|
+
bg: !hoverBackground ? "transparent" : currentState === "press" || currentState === "hover" ? theme.colors.overlay.mono : "transparent",
|
|
924
942
|
text: theme.colors.content.primary,
|
|
925
943
|
border: currentState === "press" ? theme.colors.border.primary : void 0
|
|
926
944
|
};
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
945
|
+
case "secondary":
|
|
946
|
+
if (effectiveBackground) {
|
|
947
|
+
return {
|
|
948
|
+
bg: currentState === "press" ? theme.colors.control.mono.secondary.bgPress : currentState === "hover" ? theme.colors.control.mono.secondary.bgHover : theme.colors.background.secondary,
|
|
949
|
+
text: theme.colors.content.secondary,
|
|
950
|
+
border: void 0
|
|
951
|
+
};
|
|
952
|
+
}
|
|
935
953
|
return {
|
|
936
|
-
bg: currentState === "press"
|
|
937
|
-
text: theme.colors.content.secondary,
|
|
954
|
+
bg: !hoverBackground ? "transparent" : currentState === "press" || currentState === "hover" ? theme.colors.overlay.mono : "transparent",
|
|
955
|
+
text: currentState === "press" ? theme.colors.content.primary : currentState === "hover" ? theme.colors.content.secondary : theme.colors.content.secondary,
|
|
938
956
|
border: void 0
|
|
939
957
|
};
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
958
|
+
case "tertiary":
|
|
959
|
+
if (effectiveBackground) {
|
|
960
|
+
return {
|
|
961
|
+
bg: currentState === "press" ? theme.colors.control.mono.secondary.bgPress : currentState === "hover" ? theme.colors.control.mono.secondary.bgHover : theme.colors.background.secondary,
|
|
962
|
+
text: theme.colors.content.tertiary,
|
|
963
|
+
border: void 0
|
|
964
|
+
};
|
|
965
|
+
}
|
|
948
966
|
return {
|
|
949
|
-
bg: currentState === "press"
|
|
950
|
-
text: theme.colors.content.tertiary,
|
|
967
|
+
bg: !hoverBackground ? "transparent" : currentState === "press" || currentState === "hover" ? theme.colors.overlay.mono : "transparent",
|
|
968
|
+
text: currentState === "press" ? theme.colors.content.secondary : currentState === "hover" ? theme.colors.content.tertiary : theme.colors.content.tertiary,
|
|
951
969
|
border: void 0
|
|
952
970
|
};
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
971
|
+
case "brandExtra":
|
|
972
|
+
if (effectiveBackground) {
|
|
973
|
+
return {
|
|
974
|
+
bg: currentState === "press" ? theme.colors.control.brandExtra.primary.bgPress : currentState === "hover" ? theme.colors.control.brandExtra.primary.bgHover : theme.colors.background.brandExtra.primary,
|
|
975
|
+
text: theme.colors.content.on.brandExtra,
|
|
976
|
+
border: void 0
|
|
977
|
+
};
|
|
978
|
+
}
|
|
961
979
|
return {
|
|
962
|
-
bg: currentState === "press" ? theme.colors.
|
|
963
|
-
text: theme.colors.content.on.brandExtra,
|
|
980
|
+
bg: !hoverBackground ? "transparent" : currentState === "press" ? theme.colors.background.brandExtra.primary : currentState === "hover" ? theme.colors.overlay.brandExtra : "transparent",
|
|
981
|
+
text: currentState === "press" ? theme.colors.content.on.brandExtra : theme.colors.content.brandExtra.secondary,
|
|
964
982
|
border: void 0
|
|
965
983
|
};
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
984
|
+
case "inverse":
|
|
985
|
+
if (effectiveBackground) {
|
|
986
|
+
return {
|
|
987
|
+
bg: currentState === "press" ? theme.colors.control.mono.primary.bgPress : currentState === "hover" ? theme.colors.control.mono.primary.bgHover : theme.colors.background.inverse,
|
|
988
|
+
text: theme.colors.content.inverse,
|
|
989
|
+
border: void 0
|
|
990
|
+
};
|
|
991
|
+
}
|
|
974
992
|
return {
|
|
975
|
-
bg: currentState === "press"
|
|
993
|
+
bg: !hoverBackground ? "transparent" : currentState === "press" || currentState === "hover" ? theme.colors.overlay.mono : "transparent",
|
|
976
994
|
text: theme.colors.content.inverse,
|
|
977
995
|
border: void 0
|
|
978
996
|
};
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
}
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
}
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
}
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
};
|
|
1062
|
-
const handleBlur = () => {
|
|
1063
|
-
setIsFocused(false);
|
|
1064
|
-
};
|
|
1065
|
-
const handleClick = (event) => {
|
|
1066
|
-
if (isDisabled) return;
|
|
1067
|
-
if (onPress) {
|
|
1068
|
-
onPress();
|
|
1069
|
-
}
|
|
1070
|
-
if (onClick) {
|
|
1071
|
-
onClick(event);
|
|
1072
|
-
}
|
|
1073
|
-
};
|
|
1074
|
-
const handleKeyDown = (event) => {
|
|
1075
|
-
if (isDisabled) return;
|
|
1076
|
-
if (event.key === "Enter" || event.key === " ") {
|
|
1077
|
-
event.preventDefault();
|
|
1078
|
-
setState("press");
|
|
1079
|
-
}
|
|
1080
|
-
};
|
|
1081
|
-
const handleKeyUp = (event) => {
|
|
1082
|
-
if (isDisabled) return;
|
|
1083
|
-
if (event.key === "Enter" || event.key === " ") {
|
|
1084
|
-
event.preventDefault();
|
|
1085
|
-
setState(isMouseOverRef.current ? "hover" : "default");
|
|
997
|
+
default:
|
|
998
|
+
return {
|
|
999
|
+
bg: "transparent",
|
|
1000
|
+
text: theme.colors.content.primary,
|
|
1001
|
+
border: void 0
|
|
1002
|
+
};
|
|
1003
|
+
}
|
|
1004
|
+
};
|
|
1005
|
+
const getFocusRingColor = () => {
|
|
1006
|
+
switch (variant) {
|
|
1007
|
+
case "brand":
|
|
1008
|
+
return theme.colors.overlay.brand;
|
|
1009
|
+
case "brandExtra":
|
|
1010
|
+
return theme.colors.overlay.brandExtra;
|
|
1011
|
+
case "inverse":
|
|
1012
|
+
return "rgba(255, 255, 255, 0.3)";
|
|
1013
|
+
default:
|
|
1014
|
+
return theme.colors.overlay.mono;
|
|
1015
|
+
}
|
|
1016
|
+
};
|
|
1017
|
+
const getSpinnerColor = () => {
|
|
1018
|
+
switch (variant) {
|
|
1019
|
+
case "brand":
|
|
1020
|
+
return theme.colors.content.brand.primary;
|
|
1021
|
+
case "primary":
|
|
1022
|
+
return theme.colors.content.primary;
|
|
1023
|
+
case "secondary":
|
|
1024
|
+
return theme.colors.content.secondary;
|
|
1025
|
+
case "tertiary":
|
|
1026
|
+
return theme.colors.content.tertiary;
|
|
1027
|
+
case "brandExtra":
|
|
1028
|
+
return theme.colors.content.brandExtra.secondary;
|
|
1029
|
+
case "inverse":
|
|
1030
|
+
return theme.colors.content.inverse;
|
|
1031
|
+
default:
|
|
1032
|
+
return theme.colors.content.brand.primary;
|
|
1033
|
+
}
|
|
1034
|
+
};
|
|
1035
|
+
const colors = getVariantColors(state);
|
|
1036
|
+
const focusRingColor = getFocusRingColor();
|
|
1037
|
+
const spinnerColor = getSpinnerColor();
|
|
1038
|
+
const iconSize = ICON_SIZES[size];
|
|
1039
|
+
const spinnerSize = SPINNER_SIZES[size];
|
|
1040
|
+
const fontSize = FONT_SIZES[size];
|
|
1041
|
+
const borderRadius = BORDER_RADIUS[size];
|
|
1042
|
+
const lineHeight = LINE_HEIGHTS[size];
|
|
1043
|
+
const showTextLabel = hasVisibleLabel(children);
|
|
1044
|
+
const hasIconChildren = !showTextLabel && hasRenderableContent(children);
|
|
1045
|
+
const isIconOnly = !loading && !showTextLabel && Boolean(iconLeft || iconRight || hasIconChildren);
|
|
1046
|
+
const iconOnlyHitArea = getFlexButtonBoxSize(size);
|
|
1047
|
+
const handleMouseEnter = () => {
|
|
1048
|
+
if (!isDisabled) {
|
|
1049
|
+
isMouseOverRef.current = true;
|
|
1050
|
+
setState("hover");
|
|
1051
|
+
}
|
|
1052
|
+
};
|
|
1053
|
+
const handleMouseLeave = () => {
|
|
1054
|
+
if (!isDisabled) {
|
|
1055
|
+
isMouseOverRef.current = false;
|
|
1056
|
+
setState("default");
|
|
1057
|
+
}
|
|
1058
|
+
};
|
|
1059
|
+
const handleMouseDown = () => {
|
|
1060
|
+
if (!isDisabled) {
|
|
1061
|
+
setState("press");
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
1064
|
+
const handleMouseUp = () => {
|
|
1065
|
+
if (!isDisabled) {
|
|
1066
|
+
setState(isMouseOverRef.current ? "hover" : "default");
|
|
1067
|
+
}
|
|
1068
|
+
};
|
|
1069
|
+
const handleFocus = () => {
|
|
1070
|
+
if (!isDisabled) {
|
|
1071
|
+
setIsFocused(true);
|
|
1072
|
+
}
|
|
1073
|
+
};
|
|
1074
|
+
const handleBlur = () => {
|
|
1075
|
+
setIsFocused(false);
|
|
1076
|
+
};
|
|
1077
|
+
const handleClick = (event) => {
|
|
1078
|
+
if (isDisabled) return;
|
|
1086
1079
|
if (onPress) {
|
|
1087
1080
|
onPress();
|
|
1088
1081
|
}
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
"
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1082
|
+
if (onClick) {
|
|
1083
|
+
onClick(event);
|
|
1084
|
+
}
|
|
1085
|
+
};
|
|
1086
|
+
const handleKeyDown = (event) => {
|
|
1087
|
+
if (isDisabled) return;
|
|
1088
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
1089
|
+
event.preventDefault();
|
|
1090
|
+
setState("press");
|
|
1091
|
+
}
|
|
1092
|
+
};
|
|
1093
|
+
const handleKeyUp = (event) => {
|
|
1094
|
+
if (isDisabled) return;
|
|
1095
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
1096
|
+
event.preventDefault();
|
|
1097
|
+
setState(isMouseOverRef.current ? "hover" : "default");
|
|
1098
|
+
if (onPress) {
|
|
1099
|
+
onPress();
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
};
|
|
1103
|
+
const borderShadow = colors.border ? `inset 0 0 0 1px ${colors.border}` : void 0;
|
|
1104
|
+
const focusShadow = isFocused && !isDisabled ? `0 0 0 2px ${focusRingColor}` : void 0;
|
|
1105
|
+
const boxShadows = [];
|
|
1106
|
+
if (borderShadow) boxShadows.push(borderShadow);
|
|
1107
|
+
if (focusShadow) boxShadows.push(focusShadow);
|
|
1108
|
+
const combinedBoxShadow = boxShadows.length > 0 ? boxShadows.join(", ") : "none";
|
|
1109
|
+
const buttonStyle = {
|
|
1110
|
+
display: "inline-flex",
|
|
1111
|
+
alignItems: "center",
|
|
1112
|
+
justifyContent: "center",
|
|
1113
|
+
gap: isIconOnly ? 0 : "2px",
|
|
1114
|
+
boxSizing: "border-box",
|
|
1115
|
+
padding: noPadding ? "0px" : `${FLEX_BUTTON_PADDING}px`,
|
|
1116
|
+
backgroundColor: loading ? "transparent" : colors.bg,
|
|
1117
|
+
color: colors.text,
|
|
1118
|
+
border: "none",
|
|
1119
|
+
borderWidth: "0px",
|
|
1120
|
+
borderRadius: `${borderRadius}px`,
|
|
1121
|
+
cursor: isDisabled ? "not-allowed" : "pointer",
|
|
1122
|
+
fontSize: `${fontSize}px`,
|
|
1123
|
+
fontWeight: 500,
|
|
1124
|
+
lineHeight: isIconOnly ? 0 : lineHeight,
|
|
1125
|
+
fontFamily: "inherit",
|
|
1126
|
+
transition: "background-color 100ms ease-in-out, color 100ms ease-in-out, box-shadow 100ms ease-in-out",
|
|
1127
|
+
outline: "none",
|
|
1128
|
+
boxShadow: combinedBoxShadow,
|
|
1129
|
+
opacity: isDisabled && !loading ? 0.6 : 1,
|
|
1130
|
+
...isIconOnly && {
|
|
1131
|
+
width: iconOnlyHitArea,
|
|
1132
|
+
height: iconOnlyHitArea,
|
|
1133
|
+
minWidth: iconOnlyHitArea,
|
|
1134
|
+
minHeight: iconOnlyHitArea,
|
|
1135
|
+
flexShrink: 0
|
|
1136
|
+
}
|
|
1137
|
+
};
|
|
1138
|
+
const contentStyle = {
|
|
1139
|
+
display: "flex",
|
|
1140
|
+
alignItems: "center",
|
|
1141
|
+
justifyContent: "center",
|
|
1142
|
+
gap: isIconOnly ? 0 : "2px",
|
|
1143
|
+
...isIconOnly && {
|
|
1144
|
+
width: "100%",
|
|
1145
|
+
height: "100%",
|
|
1146
|
+
lineHeight: 0
|
|
1147
|
+
}
|
|
1148
|
+
};
|
|
1149
|
+
const spinnerStyle = {
|
|
1150
|
+
display: "flex",
|
|
1151
|
+
alignItems: "center",
|
|
1152
|
+
justifyContent: "center",
|
|
1153
|
+
backgroundColor: "transparent",
|
|
1154
|
+
height: lineHeight
|
|
1155
|
+
};
|
|
1156
|
+
const computedAriaLabel = ariaLabel || (typeof children === "string" ? children : void 0);
|
|
1157
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1158
|
+
"button",
|
|
1159
|
+
{
|
|
1160
|
+
...buttonProps,
|
|
1161
|
+
ref,
|
|
1162
|
+
type,
|
|
1163
|
+
className,
|
|
1164
|
+
disabled: isDisabled,
|
|
1165
|
+
onClick: handleClick,
|
|
1166
|
+
onMouseEnter: handleMouseEnter,
|
|
1167
|
+
onMouseLeave: handleMouseLeave,
|
|
1168
|
+
onMouseDown: handleMouseDown,
|
|
1169
|
+
onMouseUp: handleMouseUp,
|
|
1170
|
+
onKeyDown: handleKeyDown,
|
|
1171
|
+
onKeyUp: handleKeyUp,
|
|
1172
|
+
onFocus: handleFocus,
|
|
1173
|
+
onBlur: handleBlur,
|
|
1174
|
+
"aria-label": computedAriaLabel,
|
|
1175
|
+
"aria-busy": loading || void 0,
|
|
1176
|
+
"aria-disabled": isDisabled || void 0,
|
|
1177
|
+
"aria-describedby": ariaDescribedBy,
|
|
1178
|
+
"aria-expanded": ariaExpanded,
|
|
1179
|
+
"aria-haspopup": ariaHasPopup,
|
|
1180
|
+
"aria-pressed": ariaPressed,
|
|
1181
|
+
"aria-controls": ariaControls,
|
|
1182
|
+
tabIndex,
|
|
1183
|
+
style: buttonStyle,
|
|
1184
|
+
"data-testid": testID || "flex-button",
|
|
1185
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { style: contentStyle, children: loading ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { style: spinnerStyle, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Spinner, { size: spinnerSize, color: spinnerColor }) }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
|
|
1186
|
+
iconLeft && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { size: iconSize, color: colors.text, children: iconLeft }),
|
|
1187
|
+
showTextLabel && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children }),
|
|
1188
|
+
hasIconChildren && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { size: iconSize, color: colors.text, children }),
|
|
1189
|
+
iconRight && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { size: iconSize, color: colors.text, children: iconRight })
|
|
1190
|
+
] }) })
|
|
1191
|
+
}
|
|
1192
|
+
);
|
|
1193
|
+
}
|
|
1194
|
+
);
|
|
1181
1195
|
FlexButton.displayName = "FlexButton";
|
|
1182
1196
|
|
|
1183
1197
|
// src/AppButton.tsx
|
|
@@ -1538,6 +1552,7 @@ ButtonGroup.displayName = "ButtonGroup";
|
|
|
1538
1552
|
Button,
|
|
1539
1553
|
ButtonGroup,
|
|
1540
1554
|
FlexButton,
|
|
1541
|
-
IconButton
|
|
1555
|
+
IconButton,
|
|
1556
|
+
getFlexButtonBoxSize
|
|
1542
1557
|
});
|
|
1543
1558
|
//# sourceMappingURL=index.js.map
|