@xsolla/xui-button 0.191.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 +32 -4
- package/native/index.d.ts +32 -4
- package/native/index.js +327 -299
- package/native/index.js.map +1 -1
- package/native/index.mjs +331 -303
- package/native/index.mjs.map +1 -1
- package/package.json +4 -4
- package/web/index.d.mts +32 -4
- package/web/index.d.ts +32 -4
- package/web/index.js +327 -299
- package/web/index.js.map +1 -1
- package/web/index.mjs +331 -303
- package/web/index.mjs.map +1 -1
package/web/index.mjs
CHANGED
|
@@ -831,20 +831,13 @@ var IconButton = ({
|
|
|
831
831
|
IconButton.displayName = "IconButton";
|
|
832
832
|
|
|
833
833
|
// src/FlexButton.tsx
|
|
834
|
-
import {
|
|
834
|
+
import React5, {
|
|
835
|
+
forwardRef,
|
|
835
836
|
useRef,
|
|
836
837
|
useState as useState3
|
|
837
838
|
} from "react";
|
|
838
|
-
import {
|
|
839
|
+
import { useResolvedTheme as useResolvedTheme3 } from "@xsolla/xui-core";
|
|
839
840
|
import { Fragment, jsx as jsx7, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
840
|
-
var FLEX_BUTTON_PADDING = 4;
|
|
841
|
-
var hasVisibleLabel = (node) => {
|
|
842
|
-
if (node == null || node === false) return false;
|
|
843
|
-
if (typeof node === "string") return node.trim().length > 0;
|
|
844
|
-
if (typeof node === "number") return true;
|
|
845
|
-
if (Array.isArray(node)) return node.some(hasVisibleLabel);
|
|
846
|
-
return true;
|
|
847
|
-
};
|
|
848
841
|
var ICON_SIZES = {
|
|
849
842
|
xs: 12,
|
|
850
843
|
sm: 14,
|
|
@@ -859,6 +852,32 @@ var SPINNER_SIZES = {
|
|
|
859
852
|
lg: 18,
|
|
860
853
|
xl: 20
|
|
861
854
|
};
|
|
855
|
+
var FLEX_BUTTON_PADDING = 4;
|
|
856
|
+
var hasVisibleLabel = (node) => {
|
|
857
|
+
if (node == null || node === false || node === true) return false;
|
|
858
|
+
if (typeof node === "string") return node.trim().length > 0;
|
|
859
|
+
if (typeof node === "number") return true;
|
|
860
|
+
if (Array.isArray(node)) return node.some(hasVisibleLabel);
|
|
861
|
+
if (React5.isValidElement(node)) {
|
|
862
|
+
const { children: elementChildren } = node.props ?? {};
|
|
863
|
+
return hasVisibleLabel(elementChildren);
|
|
864
|
+
}
|
|
865
|
+
return true;
|
|
866
|
+
};
|
|
867
|
+
var hasRenderableContent = (node) => {
|
|
868
|
+
if (node == null || node === false || node === true) return false;
|
|
869
|
+
if (typeof node === "string") return node.trim().length > 0;
|
|
870
|
+
if (Array.isArray(node)) return node.some(hasRenderableContent);
|
|
871
|
+
return true;
|
|
872
|
+
};
|
|
873
|
+
var BOX_SIZES = {
|
|
874
|
+
xs: 20,
|
|
875
|
+
sm: 22,
|
|
876
|
+
md: 28,
|
|
877
|
+
lg: 32,
|
|
878
|
+
xl: 36
|
|
879
|
+
};
|
|
880
|
+
var getFlexButtonBoxSize = (size = "md") => BOX_SIZES[size];
|
|
862
881
|
var LINE_HEIGHTS = {
|
|
863
882
|
xs: "14px",
|
|
864
883
|
sm: "16px",
|
|
@@ -880,322 +899,330 @@ var BORDER_RADIUS = {
|
|
|
880
899
|
sm: 2,
|
|
881
900
|
xs: 2
|
|
882
901
|
};
|
|
883
|
-
var FlexButton = (
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
border: void 0
|
|
919
|
-
};
|
|
920
|
-
}
|
|
921
|
-
const effectiveBackground = loading ? false : background;
|
|
922
|
-
switch (variant) {
|
|
923
|
-
case "brand":
|
|
924
|
-
if (effectiveBackground) {
|
|
925
|
-
return {
|
|
926
|
-
bg: currentState === "press" ? theme.colors.control.brand.primary.bgPress : currentState === "hover" ? theme.colors.control.brand.primary.bgHover : theme.colors.background.brand.primary,
|
|
927
|
-
text: theme.colors.content.on.brand,
|
|
928
|
-
border: void 0
|
|
929
|
-
};
|
|
930
|
-
}
|
|
902
|
+
var FlexButton = forwardRef(
|
|
903
|
+
({
|
|
904
|
+
children,
|
|
905
|
+
variant = "brand",
|
|
906
|
+
size = "md",
|
|
907
|
+
background = false,
|
|
908
|
+
hoverBackground = true,
|
|
909
|
+
noPadding = false,
|
|
910
|
+
disabled = false,
|
|
911
|
+
loading = false,
|
|
912
|
+
iconLeft,
|
|
913
|
+
iconRight,
|
|
914
|
+
onPress,
|
|
915
|
+
onClick,
|
|
916
|
+
className,
|
|
917
|
+
type = "button",
|
|
918
|
+
"aria-label": ariaLabel,
|
|
919
|
+
"aria-describedby": ariaDescribedBy,
|
|
920
|
+
"aria-expanded": ariaExpanded,
|
|
921
|
+
"aria-haspopup": ariaHasPopup,
|
|
922
|
+
"aria-pressed": ariaPressed,
|
|
923
|
+
"aria-controls": ariaControls,
|
|
924
|
+
testID,
|
|
925
|
+
tabIndex = 0,
|
|
926
|
+
themeMode,
|
|
927
|
+
themeProductContext,
|
|
928
|
+
...buttonProps
|
|
929
|
+
}, ref) => {
|
|
930
|
+
const { theme } = useResolvedTheme3({ themeMode, themeProductContext });
|
|
931
|
+
const [state, setState] = useState3("default");
|
|
932
|
+
const [isFocused, setIsFocused] = useState3(false);
|
|
933
|
+
const isMouseOverRef = useRef(false);
|
|
934
|
+
const isDisabled = disabled || loading;
|
|
935
|
+
const getVariantColors = (currentState) => {
|
|
936
|
+
if (isDisabled) {
|
|
931
937
|
return {
|
|
932
|
-
bg:
|
|
933
|
-
text:
|
|
938
|
+
bg: background ? theme.colors.overlay.mono : "transparent",
|
|
939
|
+
text: theme.colors.control.text.disable,
|
|
934
940
|
border: void 0
|
|
935
941
|
};
|
|
936
|
-
|
|
937
|
-
|
|
942
|
+
}
|
|
943
|
+
const effectiveBackground = loading ? false : background;
|
|
944
|
+
switch (variant) {
|
|
945
|
+
case "brand":
|
|
946
|
+
if (effectiveBackground) {
|
|
947
|
+
return {
|
|
948
|
+
bg: currentState === "press" ? theme.colors.control.brand.primary.bgPress : currentState === "hover" ? theme.colors.control.brand.primary.bgHover : theme.colors.background.brand.primary,
|
|
949
|
+
text: theme.colors.content.on.brand,
|
|
950
|
+
border: void 0
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
return {
|
|
954
|
+
bg: !hoverBackground ? "transparent" : currentState === "press" ? theme.colors.background.brand.primary : currentState === "hover" ? theme.colors.overlay.brand : "transparent",
|
|
955
|
+
text: currentState === "press" && hoverBackground ? theme.colors.content.on.brand : theme.colors.content.brand.primary,
|
|
956
|
+
border: void 0
|
|
957
|
+
};
|
|
958
|
+
case "primary":
|
|
959
|
+
if (effectiveBackground) {
|
|
960
|
+
return {
|
|
961
|
+
bg: theme.colors.background.primary,
|
|
962
|
+
text: theme.colors.content.primary,
|
|
963
|
+
border: currentState === "press" ? theme.colors.border.primary : void 0
|
|
964
|
+
};
|
|
965
|
+
}
|
|
938
966
|
return {
|
|
939
|
-
bg: theme.colors.
|
|
967
|
+
bg: !hoverBackground ? "transparent" : currentState === "press" || currentState === "hover" ? theme.colors.overlay.mono : "transparent",
|
|
940
968
|
text: theme.colors.content.primary,
|
|
941
969
|
border: currentState === "press" ? theme.colors.border.primary : void 0
|
|
942
970
|
};
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
971
|
+
case "secondary":
|
|
972
|
+
if (effectiveBackground) {
|
|
973
|
+
return {
|
|
974
|
+
bg: currentState === "press" ? theme.colors.control.mono.secondary.bgPress : currentState === "hover" ? theme.colors.control.mono.secondary.bgHover : theme.colors.background.secondary,
|
|
975
|
+
text: theme.colors.content.secondary,
|
|
976
|
+
border: void 0
|
|
977
|
+
};
|
|
978
|
+
}
|
|
951
979
|
return {
|
|
952
|
-
bg: currentState === "press"
|
|
953
|
-
text: theme.colors.content.secondary,
|
|
980
|
+
bg: !hoverBackground ? "transparent" : currentState === "press" || currentState === "hover" ? theme.colors.overlay.mono : "transparent",
|
|
981
|
+
text: currentState === "press" ? theme.colors.content.primary : currentState === "hover" ? theme.colors.content.secondary : theme.colors.content.secondary,
|
|
954
982
|
border: void 0
|
|
955
983
|
};
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
984
|
+
case "tertiary":
|
|
985
|
+
if (effectiveBackground) {
|
|
986
|
+
return {
|
|
987
|
+
bg: currentState === "press" ? theme.colors.control.mono.secondary.bgPress : currentState === "hover" ? theme.colors.control.mono.secondary.bgHover : theme.colors.background.secondary,
|
|
988
|
+
text: theme.colors.content.tertiary,
|
|
989
|
+
border: void 0
|
|
990
|
+
};
|
|
991
|
+
}
|
|
964
992
|
return {
|
|
965
|
-
bg: currentState === "press"
|
|
966
|
-
text: theme.colors.content.tertiary,
|
|
993
|
+
bg: !hoverBackground ? "transparent" : currentState === "press" || currentState === "hover" ? theme.colors.overlay.mono : "transparent",
|
|
994
|
+
text: currentState === "press" ? theme.colors.content.secondary : currentState === "hover" ? theme.colors.content.tertiary : theme.colors.content.tertiary,
|
|
967
995
|
border: void 0
|
|
968
996
|
};
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
997
|
+
case "brandExtra":
|
|
998
|
+
if (effectiveBackground) {
|
|
999
|
+
return {
|
|
1000
|
+
bg: currentState === "press" ? theme.colors.control.brandExtra.primary.bgPress : currentState === "hover" ? theme.colors.control.brandExtra.primary.bgHover : theme.colors.background.brandExtra.primary,
|
|
1001
|
+
text: theme.colors.content.on.brandExtra,
|
|
1002
|
+
border: void 0
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
977
1005
|
return {
|
|
978
|
-
bg: currentState === "press" ? theme.colors.
|
|
979
|
-
text: theme.colors.content.on.brandExtra,
|
|
1006
|
+
bg: !hoverBackground ? "transparent" : currentState === "press" ? theme.colors.background.brandExtra.primary : currentState === "hover" ? theme.colors.overlay.brandExtra : "transparent",
|
|
1007
|
+
text: currentState === "press" ? theme.colors.content.on.brandExtra : theme.colors.content.brandExtra.secondary,
|
|
980
1008
|
border: void 0
|
|
981
1009
|
};
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
1010
|
+
case "inverse":
|
|
1011
|
+
if (effectiveBackground) {
|
|
1012
|
+
return {
|
|
1013
|
+
bg: currentState === "press" ? theme.colors.control.mono.primary.bgPress : currentState === "hover" ? theme.colors.control.mono.primary.bgHover : theme.colors.background.inverse,
|
|
1014
|
+
text: theme.colors.content.inverse,
|
|
1015
|
+
border: void 0
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
990
1018
|
return {
|
|
991
|
-
bg: currentState === "press"
|
|
1019
|
+
bg: !hoverBackground ? "transparent" : currentState === "press" || currentState === "hover" ? theme.colors.overlay.mono : "transparent",
|
|
992
1020
|
text: theme.colors.content.inverse,
|
|
993
1021
|
border: void 0
|
|
994
1022
|
};
|
|
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
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
setIsFocused(
|
|
1074
|
-
}
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
setIsFocused(false);
|
|
1078
|
-
};
|
|
1079
|
-
const handleClick = (event) => {
|
|
1080
|
-
if (isDisabled) return;
|
|
1081
|
-
if (onPress) {
|
|
1082
|
-
onPress();
|
|
1083
|
-
}
|
|
1084
|
-
if (onClick) {
|
|
1085
|
-
onClick(event);
|
|
1086
|
-
}
|
|
1087
|
-
};
|
|
1088
|
-
const handleKeyDown = (event) => {
|
|
1089
|
-
if (isDisabled) return;
|
|
1090
|
-
if (event.key === "Enter" || event.key === " ") {
|
|
1091
|
-
event.preventDefault();
|
|
1092
|
-
setState("press");
|
|
1093
|
-
}
|
|
1094
|
-
};
|
|
1095
|
-
const handleKeyUp = (event) => {
|
|
1096
|
-
if (isDisabled) return;
|
|
1097
|
-
if (event.key === "Enter" || event.key === " ") {
|
|
1098
|
-
event.preventDefault();
|
|
1099
|
-
setState(isMouseOverRef.current ? "hover" : "default");
|
|
1023
|
+
default:
|
|
1024
|
+
return {
|
|
1025
|
+
bg: "transparent",
|
|
1026
|
+
text: theme.colors.content.primary,
|
|
1027
|
+
border: void 0
|
|
1028
|
+
};
|
|
1029
|
+
}
|
|
1030
|
+
};
|
|
1031
|
+
const getFocusRingColor = () => {
|
|
1032
|
+
switch (variant) {
|
|
1033
|
+
case "brand":
|
|
1034
|
+
return theme.colors.overlay.brand;
|
|
1035
|
+
case "brandExtra":
|
|
1036
|
+
return theme.colors.overlay.brandExtra;
|
|
1037
|
+
case "inverse":
|
|
1038
|
+
return "rgba(255, 255, 255, 0.3)";
|
|
1039
|
+
default:
|
|
1040
|
+
return theme.colors.overlay.mono;
|
|
1041
|
+
}
|
|
1042
|
+
};
|
|
1043
|
+
const getSpinnerColor = () => {
|
|
1044
|
+
switch (variant) {
|
|
1045
|
+
case "brand":
|
|
1046
|
+
return theme.colors.content.brand.primary;
|
|
1047
|
+
case "primary":
|
|
1048
|
+
return theme.colors.content.primary;
|
|
1049
|
+
case "secondary":
|
|
1050
|
+
return theme.colors.content.secondary;
|
|
1051
|
+
case "tertiary":
|
|
1052
|
+
return theme.colors.content.tertiary;
|
|
1053
|
+
case "brandExtra":
|
|
1054
|
+
return theme.colors.content.brandExtra.secondary;
|
|
1055
|
+
case "inverse":
|
|
1056
|
+
return theme.colors.content.inverse;
|
|
1057
|
+
default:
|
|
1058
|
+
return theme.colors.content.brand.primary;
|
|
1059
|
+
}
|
|
1060
|
+
};
|
|
1061
|
+
const colors = getVariantColors(state);
|
|
1062
|
+
const focusRingColor = getFocusRingColor();
|
|
1063
|
+
const spinnerColor = getSpinnerColor();
|
|
1064
|
+
const iconSize = ICON_SIZES[size];
|
|
1065
|
+
const spinnerSize = SPINNER_SIZES[size];
|
|
1066
|
+
const fontSize = FONT_SIZES[size];
|
|
1067
|
+
const borderRadius = BORDER_RADIUS[size];
|
|
1068
|
+
const lineHeight = LINE_HEIGHTS[size];
|
|
1069
|
+
const showTextLabel = hasVisibleLabel(children);
|
|
1070
|
+
const hasIconChildren = !showTextLabel && hasRenderableContent(children);
|
|
1071
|
+
const isIconOnly = !loading && !showTextLabel && Boolean(iconLeft || iconRight || hasIconChildren);
|
|
1072
|
+
const iconOnlyHitArea = getFlexButtonBoxSize(size);
|
|
1073
|
+
const handleMouseEnter = () => {
|
|
1074
|
+
if (!isDisabled) {
|
|
1075
|
+
isMouseOverRef.current = true;
|
|
1076
|
+
setState("hover");
|
|
1077
|
+
}
|
|
1078
|
+
};
|
|
1079
|
+
const handleMouseLeave = () => {
|
|
1080
|
+
if (!isDisabled) {
|
|
1081
|
+
isMouseOverRef.current = false;
|
|
1082
|
+
setState("default");
|
|
1083
|
+
}
|
|
1084
|
+
};
|
|
1085
|
+
const handleMouseDown = () => {
|
|
1086
|
+
if (!isDisabled) {
|
|
1087
|
+
setState("press");
|
|
1088
|
+
}
|
|
1089
|
+
};
|
|
1090
|
+
const handleMouseUp = () => {
|
|
1091
|
+
if (!isDisabled) {
|
|
1092
|
+
setState(isMouseOverRef.current ? "hover" : "default");
|
|
1093
|
+
}
|
|
1094
|
+
};
|
|
1095
|
+
const handleFocus = () => {
|
|
1096
|
+
if (!isDisabled) {
|
|
1097
|
+
setIsFocused(true);
|
|
1098
|
+
}
|
|
1099
|
+
};
|
|
1100
|
+
const handleBlur = () => {
|
|
1101
|
+
setIsFocused(false);
|
|
1102
|
+
};
|
|
1103
|
+
const handleClick = (event) => {
|
|
1104
|
+
if (isDisabled) return;
|
|
1100
1105
|
if (onPress) {
|
|
1101
1106
|
onPress();
|
|
1102
1107
|
}
|
|
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
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1108
|
+
if (onClick) {
|
|
1109
|
+
onClick(event);
|
|
1110
|
+
}
|
|
1111
|
+
};
|
|
1112
|
+
const handleKeyDown = (event) => {
|
|
1113
|
+
if (isDisabled) return;
|
|
1114
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
1115
|
+
event.preventDefault();
|
|
1116
|
+
setState("press");
|
|
1117
|
+
}
|
|
1118
|
+
};
|
|
1119
|
+
const handleKeyUp = (event) => {
|
|
1120
|
+
if (isDisabled) return;
|
|
1121
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
1122
|
+
event.preventDefault();
|
|
1123
|
+
setState(isMouseOverRef.current ? "hover" : "default");
|
|
1124
|
+
if (onPress) {
|
|
1125
|
+
onPress();
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
};
|
|
1129
|
+
const borderShadow = colors.border ? `inset 0 0 0 1px ${colors.border}` : void 0;
|
|
1130
|
+
const focusShadow = isFocused && !isDisabled ? `0 0 0 2px ${focusRingColor}` : void 0;
|
|
1131
|
+
const boxShadows = [];
|
|
1132
|
+
if (borderShadow) boxShadows.push(borderShadow);
|
|
1133
|
+
if (focusShadow) boxShadows.push(focusShadow);
|
|
1134
|
+
const combinedBoxShadow = boxShadows.length > 0 ? boxShadows.join(", ") : "none";
|
|
1135
|
+
const buttonStyle = {
|
|
1136
|
+
display: "inline-flex",
|
|
1137
|
+
alignItems: "center",
|
|
1138
|
+
justifyContent: "center",
|
|
1139
|
+
gap: isIconOnly ? 0 : "2px",
|
|
1140
|
+
boxSizing: "border-box",
|
|
1141
|
+
padding: noPadding ? "0px" : `${FLEX_BUTTON_PADDING}px`,
|
|
1142
|
+
backgroundColor: loading ? "transparent" : colors.bg,
|
|
1143
|
+
color: colors.text,
|
|
1144
|
+
border: "none",
|
|
1145
|
+
borderWidth: "0px",
|
|
1146
|
+
borderRadius: `${borderRadius}px`,
|
|
1147
|
+
cursor: isDisabled ? "not-allowed" : "pointer",
|
|
1148
|
+
fontSize: `${fontSize}px`,
|
|
1149
|
+
fontWeight: 500,
|
|
1150
|
+
lineHeight: isIconOnly ? 0 : lineHeight,
|
|
1151
|
+
fontFamily: "inherit",
|
|
1152
|
+
transition: "background-color 100ms ease-in-out, color 100ms ease-in-out, box-shadow 100ms ease-in-out",
|
|
1153
|
+
outline: "none",
|
|
1154
|
+
boxShadow: combinedBoxShadow,
|
|
1155
|
+
opacity: isDisabled && !loading ? 0.6 : 1,
|
|
1156
|
+
...isIconOnly && {
|
|
1157
|
+
width: iconOnlyHitArea,
|
|
1158
|
+
height: iconOnlyHitArea,
|
|
1159
|
+
minWidth: iconOnlyHitArea,
|
|
1160
|
+
minHeight: iconOnlyHitArea,
|
|
1161
|
+
flexShrink: 0
|
|
1162
|
+
}
|
|
1163
|
+
};
|
|
1164
|
+
const contentStyle = {
|
|
1165
|
+
display: "flex",
|
|
1166
|
+
alignItems: "center",
|
|
1167
|
+
justifyContent: "center",
|
|
1168
|
+
gap: isIconOnly ? 0 : "2px",
|
|
1169
|
+
...isIconOnly && {
|
|
1170
|
+
width: "100%",
|
|
1171
|
+
height: "100%",
|
|
1172
|
+
lineHeight: 0
|
|
1173
|
+
}
|
|
1174
|
+
};
|
|
1175
|
+
const spinnerStyle = {
|
|
1176
|
+
display: "flex",
|
|
1177
|
+
alignItems: "center",
|
|
1178
|
+
justifyContent: "center",
|
|
1179
|
+
backgroundColor: "transparent",
|
|
1180
|
+
height: lineHeight
|
|
1181
|
+
};
|
|
1182
|
+
const computedAriaLabel = ariaLabel || (typeof children === "string" ? children : void 0);
|
|
1183
|
+
return /* @__PURE__ */ jsx7(
|
|
1184
|
+
"button",
|
|
1185
|
+
{
|
|
1186
|
+
...buttonProps,
|
|
1187
|
+
ref,
|
|
1188
|
+
type,
|
|
1189
|
+
className,
|
|
1190
|
+
disabled: isDisabled,
|
|
1191
|
+
onClick: handleClick,
|
|
1192
|
+
onMouseEnter: handleMouseEnter,
|
|
1193
|
+
onMouseLeave: handleMouseLeave,
|
|
1194
|
+
onMouseDown: handleMouseDown,
|
|
1195
|
+
onMouseUp: handleMouseUp,
|
|
1196
|
+
onKeyDown: handleKeyDown,
|
|
1197
|
+
onKeyUp: handleKeyUp,
|
|
1198
|
+
onFocus: handleFocus,
|
|
1199
|
+
onBlur: handleBlur,
|
|
1200
|
+
"aria-label": computedAriaLabel,
|
|
1201
|
+
"aria-busy": loading || void 0,
|
|
1202
|
+
"aria-disabled": isDisabled || void 0,
|
|
1203
|
+
"aria-describedby": ariaDescribedBy,
|
|
1204
|
+
"aria-expanded": ariaExpanded,
|
|
1205
|
+
"aria-haspopup": ariaHasPopup,
|
|
1206
|
+
"aria-pressed": ariaPressed,
|
|
1207
|
+
"aria-controls": ariaControls,
|
|
1208
|
+
tabIndex,
|
|
1209
|
+
style: buttonStyle,
|
|
1210
|
+
"data-testid": testID || "flex-button",
|
|
1211
|
+
children: /* @__PURE__ */ jsx7("span", { style: contentStyle, children: loading ? /* @__PURE__ */ jsx7("span", { style: spinnerStyle, children: /* @__PURE__ */ jsx7(Spinner, { size: spinnerSize, color: spinnerColor }) }) : /* @__PURE__ */ jsxs3(Fragment, { children: [
|
|
1212
|
+
iconLeft && /* @__PURE__ */ jsx7(Icon, { size: iconSize, color: colors.text, children: iconLeft }),
|
|
1213
|
+
showTextLabel && /* @__PURE__ */ jsx7("span", { children }),
|
|
1214
|
+
hasIconChildren && /* @__PURE__ */ jsx7(Icon, { size: iconSize, color: colors.text, children }),
|
|
1215
|
+
iconRight && /* @__PURE__ */ jsx7(Icon, { size: iconSize, color: colors.text, children: iconRight })
|
|
1216
|
+
] }) })
|
|
1217
|
+
}
|
|
1218
|
+
);
|
|
1219
|
+
}
|
|
1220
|
+
);
|
|
1194
1221
|
FlexButton.displayName = "FlexButton";
|
|
1195
1222
|
|
|
1196
1223
|
// src/AppButton.tsx
|
|
1197
1224
|
import React6, { useState as useState4 } from "react";
|
|
1198
|
-
import { useResolvedTheme as
|
|
1225
|
+
import { useResolvedTheme as useResolvedTheme4 } from "@xsolla/xui-core";
|
|
1199
1226
|
import { jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1200
1227
|
var cloneIconWithDefaults3 = (icon, defaultSize, defaultColor) => {
|
|
1201
1228
|
if (!React6.isValidElement(icon)) return icon;
|
|
@@ -1232,7 +1259,7 @@ var AppButton = ({
|
|
|
1232
1259
|
themeMode,
|
|
1233
1260
|
themeProductContext
|
|
1234
1261
|
}) => {
|
|
1235
|
-
const { theme } =
|
|
1262
|
+
const { theme } = useResolvedTheme4({ themeMode, themeProductContext });
|
|
1236
1263
|
const [isKeyboardPressed, setIsKeyboardPressed] = useState4(false);
|
|
1237
1264
|
const isDisabled = disabled || loading;
|
|
1238
1265
|
const sizeStyles = theme.sizing.button(size);
|
|
@@ -1418,7 +1445,7 @@ AppButton.displayName = "AppButton";
|
|
|
1418
1445
|
|
|
1419
1446
|
// src/ButtonGroup.tsx
|
|
1420
1447
|
import React7 from "react";
|
|
1421
|
-
import { useResolvedTheme as
|
|
1448
|
+
import { useResolvedTheme as useResolvedTheme5 } from "@xsolla/xui-core";
|
|
1422
1449
|
import { Fragment as Fragment2, jsx as jsx9, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
1423
1450
|
var ButtonGroup = ({
|
|
1424
1451
|
orientation = "horizontal",
|
|
@@ -1435,7 +1462,7 @@ var ButtonGroup = ({
|
|
|
1435
1462
|
themeMode,
|
|
1436
1463
|
themeProductContext
|
|
1437
1464
|
}) => {
|
|
1438
|
-
const { theme } =
|
|
1465
|
+
const { theme } = useResolvedTheme5({ themeMode, themeProductContext });
|
|
1439
1466
|
const flattenChildren = (children2) => {
|
|
1440
1467
|
const result = [];
|
|
1441
1468
|
React7.Children.forEach(children2, (child) => {
|
|
@@ -1550,6 +1577,7 @@ export {
|
|
|
1550
1577
|
Button,
|
|
1551
1578
|
ButtonGroup,
|
|
1552
1579
|
FlexButton,
|
|
1553
|
-
IconButton
|
|
1580
|
+
IconButton,
|
|
1581
|
+
getFlexButtonBoxSize
|
|
1554
1582
|
};
|
|
1555
1583
|
//# sourceMappingURL=index.mjs.map
|