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