@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/web/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
 
@@ -871,17 +872,9 @@ var IconButton = ({
871
872
  IconButton.displayName = "IconButton";
872
873
 
873
874
  // src/FlexButton.tsx
874
- var import_react5 = require("react");
875
+ var import_react5 = __toESM(require("react"));
875
876
  var import_xui_core3 = require("@xsolla/xui-core");
876
877
  var import_jsx_runtime7 = require("react/jsx-runtime");
877
- var FLEX_BUTTON_PADDING = 4;
878
- var hasVisibleLabel = (node) => {
879
- if (node == null || node === false) return false;
880
- if (typeof node === "string") return node.trim().length > 0;
881
- if (typeof node === "number") return true;
882
- if (Array.isArray(node)) return node.some(hasVisibleLabel);
883
- return true;
884
- };
885
878
  var ICON_SIZES = {
886
879
  xs: 12,
887
880
  sm: 14,
@@ -896,6 +889,32 @@ var SPINNER_SIZES = {
896
889
  lg: 18,
897
890
  xl: 20
898
891
  };
892
+ var FLEX_BUTTON_PADDING = 4;
893
+ var hasVisibleLabel = (node) => {
894
+ if (node == null || node === false || node === true) return false;
895
+ if (typeof node === "string") return node.trim().length > 0;
896
+ if (typeof node === "number") return true;
897
+ if (Array.isArray(node)) return node.some(hasVisibleLabel);
898
+ if (import_react5.default.isValidElement(node)) {
899
+ const { children: elementChildren } = node.props ?? {};
900
+ return hasVisibleLabel(elementChildren);
901
+ }
902
+ return true;
903
+ };
904
+ var hasRenderableContent = (node) => {
905
+ if (node == null || node === false || node === true) return false;
906
+ if (typeof node === "string") return node.trim().length > 0;
907
+ if (Array.isArray(node)) return node.some(hasRenderableContent);
908
+ return true;
909
+ };
910
+ var BOX_SIZES = {
911
+ xs: 20,
912
+ sm: 22,
913
+ md: 28,
914
+ lg: 32,
915
+ xl: 36
916
+ };
917
+ var getFlexButtonBoxSize = (size = "md") => BOX_SIZES[size];
899
918
  var LINE_HEIGHTS = {
900
919
  xs: "14px",
901
920
  sm: "16px",
@@ -917,317 +936,325 @@ var BORDER_RADIUS = {
917
936
  sm: 2,
918
937
  xs: 2
919
938
  };
920
- var FlexButton = ({
921
- children,
922
- variant = "brand",
923
- size = "md",
924
- background = false,
925
- hoverBackground = true,
926
- noPadding = false,
927
- disabled = false,
928
- loading = false,
929
- iconLeft,
930
- iconRight,
931
- onPress,
932
- onClick,
933
- className,
934
- type = "button",
935
- "aria-label": ariaLabel,
936
- "aria-describedby": ariaDescribedBy,
937
- "aria-expanded": ariaExpanded,
938
- "aria-haspopup": ariaHasPopup,
939
- "aria-pressed": ariaPressed,
940
- "aria-controls": ariaControls,
941
- testID,
942
- tabIndex = 0,
943
- ...buttonProps
944
- }) => {
945
- const { theme } = (0, import_xui_core3.useDesignSystem)();
946
- const [state, setState] = (0, import_react5.useState)("default");
947
- const [isFocused, setIsFocused] = (0, import_react5.useState)(false);
948
- const isMouseOverRef = (0, import_react5.useRef)(false);
949
- const isDisabled = disabled || loading;
950
- const getVariantColors = (currentState) => {
951
- if (isDisabled) {
952
- return {
953
- bg: background ? theme.colors.overlay.mono : "transparent",
954
- text: theme.colors.control.text.disable,
955
- border: void 0
956
- };
957
- }
958
- const effectiveBackground = loading ? false : background;
959
- switch (variant) {
960
- case "brand":
961
- if (effectiveBackground) {
962
- return {
963
- bg: currentState === "press" ? theme.colors.control.brand.primary.bgPress : currentState === "hover" ? theme.colors.control.brand.primary.bgHover : theme.colors.background.brand.primary,
964
- text: theme.colors.content.on.brand,
965
- border: void 0
966
- };
967
- }
939
+ var FlexButton = (0, import_react5.forwardRef)(
940
+ ({
941
+ children,
942
+ variant = "brand",
943
+ size = "md",
944
+ background = false,
945
+ hoverBackground = true,
946
+ noPadding = false,
947
+ disabled = false,
948
+ loading = false,
949
+ iconLeft,
950
+ iconRight,
951
+ onPress,
952
+ onClick,
953
+ className,
954
+ type = "button",
955
+ "aria-label": ariaLabel,
956
+ "aria-describedby": ariaDescribedBy,
957
+ "aria-expanded": ariaExpanded,
958
+ "aria-haspopup": ariaHasPopup,
959
+ "aria-pressed": ariaPressed,
960
+ "aria-controls": ariaControls,
961
+ testID,
962
+ tabIndex = 0,
963
+ themeMode,
964
+ themeProductContext,
965
+ ...buttonProps
966
+ }, ref) => {
967
+ const { theme } = (0, import_xui_core3.useResolvedTheme)({ themeMode, themeProductContext });
968
+ const [state, setState] = (0, import_react5.useState)("default");
969
+ const [isFocused, setIsFocused] = (0, import_react5.useState)(false);
970
+ const isMouseOverRef = (0, import_react5.useRef)(false);
971
+ const isDisabled = disabled || loading;
972
+ const getVariantColors = (currentState) => {
973
+ if (isDisabled) {
968
974
  return {
969
- bg: !hoverBackground ? "transparent" : currentState === "press" ? theme.colors.background.brand.primary : currentState === "hover" ? theme.colors.overlay.brand : "transparent",
970
- text: currentState === "press" && hoverBackground ? theme.colors.content.on.brand : theme.colors.content.brand.primary,
975
+ bg: background ? theme.colors.overlay.mono : "transparent",
976
+ text: theme.colors.control.text.disable,
971
977
  border: void 0
972
978
  };
973
- case "primary":
974
- if (effectiveBackground) {
979
+ }
980
+ const effectiveBackground = loading ? false : background;
981
+ switch (variant) {
982
+ case "brand":
983
+ if (effectiveBackground) {
984
+ return {
985
+ bg: currentState === "press" ? theme.colors.control.brand.primary.bgPress : currentState === "hover" ? theme.colors.control.brand.primary.bgHover : theme.colors.background.brand.primary,
986
+ text: theme.colors.content.on.brand,
987
+ border: void 0
988
+ };
989
+ }
990
+ return {
991
+ bg: !hoverBackground ? "transparent" : currentState === "press" ? theme.colors.background.brand.primary : currentState === "hover" ? theme.colors.overlay.brand : "transparent",
992
+ text: currentState === "press" && hoverBackground ? theme.colors.content.on.brand : theme.colors.content.brand.primary,
993
+ border: void 0
994
+ };
995
+ case "primary":
996
+ if (effectiveBackground) {
997
+ return {
998
+ bg: theme.colors.background.primary,
999
+ text: theme.colors.content.primary,
1000
+ border: currentState === "press" ? theme.colors.border.primary : void 0
1001
+ };
1002
+ }
975
1003
  return {
976
- bg: theme.colors.background.primary,
1004
+ bg: !hoverBackground ? "transparent" : currentState === "press" || currentState === "hover" ? theme.colors.overlay.mono : "transparent",
977
1005
  text: theme.colors.content.primary,
978
1006
  border: currentState === "press" ? theme.colors.border.primary : void 0
979
1007
  };
980
- }
981
- return {
982
- bg: !hoverBackground ? "transparent" : currentState === "press" || currentState === "hover" ? theme.colors.overlay.mono : "transparent",
983
- text: theme.colors.content.primary,
984
- border: currentState === "press" ? theme.colors.border.primary : void 0
985
- };
986
- case "secondary":
987
- if (effectiveBackground) {
1008
+ case "secondary":
1009
+ if (effectiveBackground) {
1010
+ return {
1011
+ bg: currentState === "press" ? theme.colors.control.mono.secondary.bgPress : currentState === "hover" ? theme.colors.control.mono.secondary.bgHover : theme.colors.background.secondary,
1012
+ text: theme.colors.content.secondary,
1013
+ border: void 0
1014
+ };
1015
+ }
988
1016
  return {
989
- bg: currentState === "press" ? theme.colors.control.mono.secondary.bgPress : currentState === "hover" ? theme.colors.control.mono.secondary.bgHover : theme.colors.background.secondary,
990
- text: theme.colors.content.secondary,
1017
+ bg: !hoverBackground ? "transparent" : currentState === "press" || currentState === "hover" ? theme.colors.overlay.mono : "transparent",
1018
+ text: currentState === "press" ? theme.colors.content.primary : currentState === "hover" ? theme.colors.content.secondary : theme.colors.content.secondary,
991
1019
  border: void 0
992
1020
  };
993
- }
994
- return {
995
- bg: !hoverBackground ? "transparent" : currentState === "press" || currentState === "hover" ? theme.colors.overlay.mono : "transparent",
996
- text: currentState === "press" ? theme.colors.content.primary : currentState === "hover" ? theme.colors.content.secondary : theme.colors.content.secondary,
997
- border: void 0
998
- };
999
- case "tertiary":
1000
- if (effectiveBackground) {
1021
+ case "tertiary":
1022
+ if (effectiveBackground) {
1023
+ return {
1024
+ bg: currentState === "press" ? theme.colors.control.mono.secondary.bgPress : currentState === "hover" ? theme.colors.control.mono.secondary.bgHover : theme.colors.background.secondary,
1025
+ text: theme.colors.content.tertiary,
1026
+ border: void 0
1027
+ };
1028
+ }
1001
1029
  return {
1002
- bg: currentState === "press" ? theme.colors.control.mono.secondary.bgPress : currentState === "hover" ? theme.colors.control.mono.secondary.bgHover : theme.colors.background.secondary,
1003
- text: theme.colors.content.tertiary,
1030
+ bg: !hoverBackground ? "transparent" : currentState === "press" || currentState === "hover" ? theme.colors.overlay.mono : "transparent",
1031
+ text: currentState === "press" ? theme.colors.content.secondary : currentState === "hover" ? theme.colors.content.tertiary : theme.colors.content.tertiary,
1004
1032
  border: void 0
1005
1033
  };
1006
- }
1007
- return {
1008
- bg: !hoverBackground ? "transparent" : currentState === "press" || currentState === "hover" ? theme.colors.overlay.mono : "transparent",
1009
- text: currentState === "press" ? theme.colors.content.secondary : currentState === "hover" ? theme.colors.content.tertiary : theme.colors.content.tertiary,
1010
- border: void 0
1011
- };
1012
- case "brandExtra":
1013
- if (effectiveBackground) {
1034
+ case "brandExtra":
1035
+ if (effectiveBackground) {
1036
+ return {
1037
+ bg: currentState === "press" ? theme.colors.control.brandExtra.primary.bgPress : currentState === "hover" ? theme.colors.control.brandExtra.primary.bgHover : theme.colors.background.brandExtra.primary,
1038
+ text: theme.colors.content.on.brandExtra,
1039
+ border: void 0
1040
+ };
1041
+ }
1014
1042
  return {
1015
- bg: currentState === "press" ? theme.colors.control.brandExtra.primary.bgPress : currentState === "hover" ? theme.colors.control.brandExtra.primary.bgHover : theme.colors.background.brandExtra.primary,
1016
- text: theme.colors.content.on.brandExtra,
1043
+ bg: !hoverBackground ? "transparent" : currentState === "press" ? theme.colors.background.brandExtra.primary : currentState === "hover" ? theme.colors.overlay.brandExtra : "transparent",
1044
+ text: currentState === "press" ? theme.colors.content.on.brandExtra : theme.colors.content.brandExtra.secondary,
1017
1045
  border: void 0
1018
1046
  };
1019
- }
1020
- return {
1021
- bg: !hoverBackground ? "transparent" : currentState === "press" ? theme.colors.background.brandExtra.primary : currentState === "hover" ? theme.colors.overlay.brandExtra : "transparent",
1022
- text: currentState === "press" ? theme.colors.content.on.brandExtra : theme.colors.content.brandExtra.secondary,
1023
- border: void 0
1024
- };
1025
- case "inverse":
1026
- if (effectiveBackground) {
1047
+ case "inverse":
1048
+ if (effectiveBackground) {
1049
+ return {
1050
+ bg: currentState === "press" ? theme.colors.control.mono.primary.bgPress : currentState === "hover" ? theme.colors.control.mono.primary.bgHover : theme.colors.background.inverse,
1051
+ text: theme.colors.content.inverse,
1052
+ border: void 0
1053
+ };
1054
+ }
1027
1055
  return {
1028
- bg: currentState === "press" ? theme.colors.control.mono.primary.bgPress : currentState === "hover" ? theme.colors.control.mono.primary.bgHover : theme.colors.background.inverse,
1056
+ bg: !hoverBackground ? "transparent" : currentState === "press" || currentState === "hover" ? theme.colors.overlay.mono : "transparent",
1029
1057
  text: theme.colors.content.inverse,
1030
1058
  border: void 0
1031
1059
  };
1032
- }
1033
- return {
1034
- bg: !hoverBackground ? "transparent" : currentState === "press" || currentState === "hover" ? theme.colors.overlay.mono : "transparent",
1035
- text: theme.colors.content.inverse,
1036
- border: void 0
1037
- };
1038
- default:
1039
- return {
1040
- bg: "transparent",
1041
- text: theme.colors.content.primary,
1042
- border: void 0
1043
- };
1044
- }
1045
- };
1046
- const getFocusRingColor = () => {
1047
- switch (variant) {
1048
- case "brand":
1049
- return theme.colors.overlay.brand;
1050
- case "brandExtra":
1051
- return theme.colors.overlay.brandExtra;
1052
- case "inverse":
1053
- return "rgba(255, 255, 255, 0.3)";
1054
- default:
1055
- return theme.colors.overlay.mono;
1056
- }
1057
- };
1058
- const getSpinnerColor = () => {
1059
- switch (variant) {
1060
- case "brand":
1061
- return theme.colors.content.brand.primary;
1062
- case "primary":
1063
- return theme.colors.content.primary;
1064
- case "secondary":
1065
- return theme.colors.content.secondary;
1066
- case "tertiary":
1067
- return theme.colors.content.tertiary;
1068
- case "brandExtra":
1069
- return theme.colors.content.brandExtra.secondary;
1070
- case "inverse":
1071
- return theme.colors.content.inverse;
1072
- default:
1073
- return theme.colors.content.brand.primary;
1074
- }
1075
- };
1076
- const colors = getVariantColors(state);
1077
- const focusRingColor = getFocusRingColor();
1078
- const spinnerColor = getSpinnerColor();
1079
- const iconSize = ICON_SIZES[size];
1080
- const spinnerSize = SPINNER_SIZES[size];
1081
- const fontSize = FONT_SIZES[size];
1082
- const borderRadius = BORDER_RADIUS[size];
1083
- const lineHeight = LINE_HEIGHTS[size];
1084
- const isIconOnly = !loading && !hasVisibleLabel(children) && Boolean(iconLeft || iconRight);
1085
- const iconOnlyHitArea = iconSize + FLEX_BUTTON_PADDING * 2;
1086
- const handleMouseEnter = () => {
1087
- if (!isDisabled) {
1088
- isMouseOverRef.current = true;
1089
- setState("hover");
1090
- }
1091
- };
1092
- const handleMouseLeave = () => {
1093
- if (!isDisabled) {
1094
- isMouseOverRef.current = false;
1095
- setState("default");
1096
- }
1097
- };
1098
- const handleMouseDown = () => {
1099
- if (!isDisabled) {
1100
- setState("press");
1101
- }
1102
- };
1103
- const handleMouseUp = () => {
1104
- if (!isDisabled) {
1105
- setState(isMouseOverRef.current ? "hover" : "default");
1106
- }
1107
- };
1108
- const handleFocus = () => {
1109
- if (!isDisabled) {
1110
- setIsFocused(true);
1111
- }
1112
- };
1113
- const handleBlur = () => {
1114
- setIsFocused(false);
1115
- };
1116
- const handleClick = (event) => {
1117
- if (isDisabled) return;
1118
- if (onPress) {
1119
- onPress();
1120
- }
1121
- if (onClick) {
1122
- onClick(event);
1123
- }
1124
- };
1125
- const handleKeyDown = (event) => {
1126
- if (isDisabled) return;
1127
- if (event.key === "Enter" || event.key === " ") {
1128
- event.preventDefault();
1129
- setState("press");
1130
- }
1131
- };
1132
- const handleKeyUp = (event) => {
1133
- if (isDisabled) return;
1134
- if (event.key === "Enter" || event.key === " ") {
1135
- event.preventDefault();
1136
- setState(isMouseOverRef.current ? "hover" : "default");
1060
+ default:
1061
+ return {
1062
+ bg: "transparent",
1063
+ text: theme.colors.content.primary,
1064
+ border: void 0
1065
+ };
1066
+ }
1067
+ };
1068
+ const getFocusRingColor = () => {
1069
+ switch (variant) {
1070
+ case "brand":
1071
+ return theme.colors.overlay.brand;
1072
+ case "brandExtra":
1073
+ return theme.colors.overlay.brandExtra;
1074
+ case "inverse":
1075
+ return "rgba(255, 255, 255, 0.3)";
1076
+ default:
1077
+ return theme.colors.overlay.mono;
1078
+ }
1079
+ };
1080
+ const getSpinnerColor = () => {
1081
+ switch (variant) {
1082
+ case "brand":
1083
+ return theme.colors.content.brand.primary;
1084
+ case "primary":
1085
+ return theme.colors.content.primary;
1086
+ case "secondary":
1087
+ return theme.colors.content.secondary;
1088
+ case "tertiary":
1089
+ return theme.colors.content.tertiary;
1090
+ case "brandExtra":
1091
+ return theme.colors.content.brandExtra.secondary;
1092
+ case "inverse":
1093
+ return theme.colors.content.inverse;
1094
+ default:
1095
+ return theme.colors.content.brand.primary;
1096
+ }
1097
+ };
1098
+ const colors = getVariantColors(state);
1099
+ const focusRingColor = getFocusRingColor();
1100
+ const spinnerColor = getSpinnerColor();
1101
+ const iconSize = ICON_SIZES[size];
1102
+ const spinnerSize = SPINNER_SIZES[size];
1103
+ const fontSize = FONT_SIZES[size];
1104
+ const borderRadius = BORDER_RADIUS[size];
1105
+ const lineHeight = LINE_HEIGHTS[size];
1106
+ const showTextLabel = hasVisibleLabel(children);
1107
+ const hasIconChildren = !showTextLabel && hasRenderableContent(children);
1108
+ const isIconOnly = !loading && !showTextLabel && Boolean(iconLeft || iconRight || hasIconChildren);
1109
+ const iconOnlyHitArea = getFlexButtonBoxSize(size);
1110
+ const handleMouseEnter = () => {
1111
+ if (!isDisabled) {
1112
+ isMouseOverRef.current = true;
1113
+ setState("hover");
1114
+ }
1115
+ };
1116
+ const handleMouseLeave = () => {
1117
+ if (!isDisabled) {
1118
+ isMouseOverRef.current = false;
1119
+ setState("default");
1120
+ }
1121
+ };
1122
+ const handleMouseDown = () => {
1123
+ if (!isDisabled) {
1124
+ setState("press");
1125
+ }
1126
+ };
1127
+ const handleMouseUp = () => {
1128
+ if (!isDisabled) {
1129
+ setState(isMouseOverRef.current ? "hover" : "default");
1130
+ }
1131
+ };
1132
+ const handleFocus = () => {
1133
+ if (!isDisabled) {
1134
+ setIsFocused(true);
1135
+ }
1136
+ };
1137
+ const handleBlur = () => {
1138
+ setIsFocused(false);
1139
+ };
1140
+ const handleClick = (event) => {
1141
+ if (isDisabled) return;
1137
1142
  if (onPress) {
1138
1143
  onPress();
1139
1144
  }
1140
- }
1141
- };
1142
- const borderShadow = colors.border ? `inset 0 0 0 1px ${colors.border}` : void 0;
1143
- const focusShadow = isFocused && !isDisabled ? `0 0 0 2px ${focusRingColor}` : void 0;
1144
- const boxShadows = [];
1145
- if (borderShadow) boxShadows.push(borderShadow);
1146
- if (focusShadow) boxShadows.push(focusShadow);
1147
- const combinedBoxShadow = boxShadows.length > 0 ? boxShadows.join(", ") : "none";
1148
- const buttonStyle = {
1149
- display: "inline-flex",
1150
- alignItems: "center",
1151
- justifyContent: "center",
1152
- gap: isIconOnly ? 0 : "2px",
1153
- boxSizing: "border-box",
1154
- padding: noPadding ? "0px" : `${FLEX_BUTTON_PADDING}px`,
1155
- backgroundColor: loading ? "transparent" : colors.bg,
1156
- color: colors.text,
1157
- border: "none",
1158
- borderWidth: "0px",
1159
- borderRadius: `${borderRadius}px`,
1160
- cursor: isDisabled ? "not-allowed" : "pointer",
1161
- fontSize: `${fontSize}px`,
1162
- fontWeight: 500,
1163
- lineHeight: isIconOnly ? 0 : lineHeight,
1164
- fontFamily: "inherit",
1165
- transition: "background-color 100ms ease-in-out, color 100ms ease-in-out, box-shadow 100ms ease-in-out",
1166
- outline: "none",
1167
- boxShadow: combinedBoxShadow,
1168
- opacity: isDisabled && !loading ? 0.6 : 1,
1169
- ...isIconOnly && {
1170
- width: iconOnlyHitArea,
1171
- height: iconOnlyHitArea,
1172
- minWidth: iconOnlyHitArea,
1173
- minHeight: iconOnlyHitArea,
1174
- flexShrink: 0
1175
- }
1176
- };
1177
- const contentStyle = {
1178
- display: "flex",
1179
- alignItems: "center",
1180
- justifyContent: "center",
1181
- gap: isIconOnly ? 0 : "2px",
1182
- ...isIconOnly && {
1183
- width: "100%",
1184
- height: "100%",
1185
- lineHeight: 0
1186
- }
1187
- };
1188
- const spinnerStyle = {
1189
- display: "flex",
1190
- alignItems: "center",
1191
- justifyContent: "center",
1192
- backgroundColor: "transparent",
1193
- height: lineHeight
1194
- };
1195
- const computedAriaLabel = ariaLabel || (typeof children === "string" ? children : void 0);
1196
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1197
- "button",
1198
- {
1199
- ...buttonProps,
1200
- type,
1201
- className,
1202
- disabled: isDisabled,
1203
- onClick: handleClick,
1204
- onMouseEnter: handleMouseEnter,
1205
- onMouseLeave: handleMouseLeave,
1206
- onMouseDown: handleMouseDown,
1207
- onMouseUp: handleMouseUp,
1208
- onKeyDown: handleKeyDown,
1209
- onKeyUp: handleKeyUp,
1210
- onFocus: handleFocus,
1211
- onBlur: handleBlur,
1212
- "aria-label": computedAriaLabel,
1213
- "aria-busy": loading || void 0,
1214
- "aria-disabled": isDisabled || void 0,
1215
- "aria-describedby": ariaDescribedBy,
1216
- "aria-expanded": ariaExpanded,
1217
- "aria-haspopup": ariaHasPopup,
1218
- "aria-pressed": ariaPressed,
1219
- "aria-controls": ariaControls,
1220
- tabIndex,
1221
- style: buttonStyle,
1222
- "data-testid": testID || "flex-button",
1223
- 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: [
1224
- iconLeft && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { size: iconSize, color: colors.text, children: iconLeft }),
1225
- hasVisibleLabel(children) && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children }),
1226
- iconRight && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { size: iconSize, color: colors.text, children: iconRight })
1227
- ] }) })
1228
- }
1229
- );
1230
- };
1145
+ if (onClick) {
1146
+ onClick(event);
1147
+ }
1148
+ };
1149
+ const handleKeyDown = (event) => {
1150
+ if (isDisabled) return;
1151
+ if (event.key === "Enter" || event.key === " ") {
1152
+ event.preventDefault();
1153
+ setState("press");
1154
+ }
1155
+ };
1156
+ const handleKeyUp = (event) => {
1157
+ if (isDisabled) return;
1158
+ if (event.key === "Enter" || event.key === " ") {
1159
+ event.preventDefault();
1160
+ setState(isMouseOverRef.current ? "hover" : "default");
1161
+ if (onPress) {
1162
+ onPress();
1163
+ }
1164
+ }
1165
+ };
1166
+ const borderShadow = colors.border ? `inset 0 0 0 1px ${colors.border}` : void 0;
1167
+ const focusShadow = isFocused && !isDisabled ? `0 0 0 2px ${focusRingColor}` : void 0;
1168
+ const boxShadows = [];
1169
+ if (borderShadow) boxShadows.push(borderShadow);
1170
+ if (focusShadow) boxShadows.push(focusShadow);
1171
+ const combinedBoxShadow = boxShadows.length > 0 ? boxShadows.join(", ") : "none";
1172
+ const buttonStyle = {
1173
+ display: "inline-flex",
1174
+ alignItems: "center",
1175
+ justifyContent: "center",
1176
+ gap: isIconOnly ? 0 : "2px",
1177
+ boxSizing: "border-box",
1178
+ padding: noPadding ? "0px" : `${FLEX_BUTTON_PADDING}px`,
1179
+ backgroundColor: loading ? "transparent" : colors.bg,
1180
+ color: colors.text,
1181
+ border: "none",
1182
+ borderWidth: "0px",
1183
+ borderRadius: `${borderRadius}px`,
1184
+ cursor: isDisabled ? "not-allowed" : "pointer",
1185
+ fontSize: `${fontSize}px`,
1186
+ fontWeight: 500,
1187
+ lineHeight: isIconOnly ? 0 : lineHeight,
1188
+ fontFamily: "inherit",
1189
+ transition: "background-color 100ms ease-in-out, color 100ms ease-in-out, box-shadow 100ms ease-in-out",
1190
+ outline: "none",
1191
+ boxShadow: combinedBoxShadow,
1192
+ opacity: isDisabled && !loading ? 0.6 : 1,
1193
+ ...isIconOnly && {
1194
+ width: iconOnlyHitArea,
1195
+ height: iconOnlyHitArea,
1196
+ minWidth: iconOnlyHitArea,
1197
+ minHeight: iconOnlyHitArea,
1198
+ flexShrink: 0
1199
+ }
1200
+ };
1201
+ const contentStyle = {
1202
+ display: "flex",
1203
+ alignItems: "center",
1204
+ justifyContent: "center",
1205
+ gap: isIconOnly ? 0 : "2px",
1206
+ ...isIconOnly && {
1207
+ width: "100%",
1208
+ height: "100%",
1209
+ lineHeight: 0
1210
+ }
1211
+ };
1212
+ const spinnerStyle = {
1213
+ display: "flex",
1214
+ alignItems: "center",
1215
+ justifyContent: "center",
1216
+ backgroundColor: "transparent",
1217
+ height: lineHeight
1218
+ };
1219
+ const computedAriaLabel = ariaLabel || (typeof children === "string" ? children : void 0);
1220
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1221
+ "button",
1222
+ {
1223
+ ...buttonProps,
1224
+ ref,
1225
+ type,
1226
+ className,
1227
+ disabled: isDisabled,
1228
+ onClick: handleClick,
1229
+ onMouseEnter: handleMouseEnter,
1230
+ onMouseLeave: handleMouseLeave,
1231
+ onMouseDown: handleMouseDown,
1232
+ onMouseUp: handleMouseUp,
1233
+ onKeyDown: handleKeyDown,
1234
+ onKeyUp: handleKeyUp,
1235
+ onFocus: handleFocus,
1236
+ onBlur: handleBlur,
1237
+ "aria-label": computedAriaLabel,
1238
+ "aria-busy": loading || void 0,
1239
+ "aria-disabled": isDisabled || void 0,
1240
+ "aria-describedby": ariaDescribedBy,
1241
+ "aria-expanded": ariaExpanded,
1242
+ "aria-haspopup": ariaHasPopup,
1243
+ "aria-pressed": ariaPressed,
1244
+ "aria-controls": ariaControls,
1245
+ tabIndex,
1246
+ style: buttonStyle,
1247
+ "data-testid": testID || "flex-button",
1248
+ 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: [
1249
+ iconLeft && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { size: iconSize, color: colors.text, children: iconLeft }),
1250
+ showTextLabel && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children }),
1251
+ hasIconChildren && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { size: iconSize, color: colors.text, children }),
1252
+ iconRight && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { size: iconSize, color: colors.text, children: iconRight })
1253
+ ] }) })
1254
+ }
1255
+ );
1256
+ }
1257
+ );
1231
1258
  FlexButton.displayName = "FlexButton";
1232
1259
 
1233
1260
  // src/AppButton.tsx
@@ -1588,6 +1615,7 @@ ButtonGroup.displayName = "ButtonGroup";
1588
1615
  Button,
1589
1616
  ButtonGroup,
1590
1617
  FlexButton,
1591
- IconButton
1618
+ IconButton,
1619
+ getFlexButtonBoxSize
1592
1620
  });
1593
1621
  //# sourceMappingURL=index.js.map