@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/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 ICON_SIZES = {
833
- xs: 12,
834
- sm: 14,
835
- md: 16,
836
- lg: 18,
837
- xl: 20
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
- children,
869
- variant = "brand",
870
- size = "md",
871
- background = false,
872
- hoverBackground = true,
873
- noPadding = false,
874
- disabled = false,
875
- loading = false,
876
- iconLeft,
877
- iconRight,
878
- onPress,
879
- onClick,
880
- className,
881
- type = "button",
882
- "aria-label": ariaLabel,
883
- "aria-describedby": ariaDescribedBy,
884
- "aria-expanded": ariaExpanded,
885
- "aria-haspopup": ariaHasPopup,
886
- "aria-pressed": ariaPressed,
887
- "aria-controls": ariaControls,
888
- testID,
889
- tabIndex = 0,
890
- ...buttonProps
891
- }) => {
892
- const { theme } = (0, import_xui_core3.useDesignSystem)();
893
- const [state, setState] = (0, import_react4.useState)("default");
894
- const [isFocused, setIsFocused] = (0, import_react4.useState)(false);
895
- const isMouseOverRef = (0, import_react4.useRef)(false);
896
- const isDisabled = disabled || loading;
897
- const getVariantColors = (currentState) => {
898
- if (isDisabled) {
899
- return {
900
- bg: background ? theme.colors.overlay.mono : "transparent",
901
- text: theme.colors.control.text.disable,
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: !hoverBackground ? "transparent" : currentState === "press" ? theme.colors.background.brand.primary : currentState === "hover" ? theme.colors.overlay.brand : "transparent",
917
- 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,
918
914
  border: void 0
919
915
  };
920
- case "primary":
921
- 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
+ }
922
940
  return {
923
- bg: theme.colors.background.primary,
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
- return {
929
- bg: !hoverBackground ? "transparent" : currentState === "press" || currentState === "hover" ? theme.colors.overlay.mono : "transparent",
930
- text: theme.colors.content.primary,
931
- border: currentState === "press" ? theme.colors.border.primary : void 0
932
- };
933
- case "secondary":
934
- 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
+ }
935
953
  return {
936
- bg: currentState === "press" ? theme.colors.control.mono.secondary.bgPress : currentState === "hover" ? theme.colors.control.mono.secondary.bgHover : theme.colors.background.secondary,
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
- return {
942
- bg: !hoverBackground ? "transparent" : currentState === "press" || currentState === "hover" ? theme.colors.overlay.mono : "transparent",
943
- text: currentState === "press" ? theme.colors.content.primary : currentState === "hover" ? theme.colors.content.secondary : theme.colors.content.secondary,
944
- border: void 0
945
- };
946
- case "tertiary":
947
- 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
+ }
948
966
  return {
949
- bg: currentState === "press" ? theme.colors.control.mono.secondary.bgPress : currentState === "hover" ? theme.colors.control.mono.secondary.bgHover : theme.colors.background.secondary,
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
- return {
955
- bg: !hoverBackground ? "transparent" : currentState === "press" || currentState === "hover" ? theme.colors.overlay.mono : "transparent",
956
- text: currentState === "press" ? theme.colors.content.secondary : currentState === "hover" ? theme.colors.content.tertiary : theme.colors.content.tertiary,
957
- border: void 0
958
- };
959
- case "brandExtra":
960
- 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
+ }
961
979
  return {
962
- bg: currentState === "press" ? theme.colors.control.brandExtra.primary.bgPress : currentState === "hover" ? theme.colors.control.brandExtra.primary.bgHover : theme.colors.background.brandExtra.primary,
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
- return {
968
- bg: !hoverBackground ? "transparent" : currentState === "press" ? theme.colors.background.brandExtra.primary : currentState === "hover" ? theme.colors.overlay.brandExtra : "transparent",
969
- text: currentState === "press" ? theme.colors.content.on.brandExtra : theme.colors.content.brandExtra.secondary,
970
- border: void 0
971
- };
972
- case "inverse":
973
- 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
+ }
974
992
  return {
975
- 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",
976
994
  text: theme.colors.content.inverse,
977
995
  border: void 0
978
996
  };
979
- }
980
- return {
981
- bg: !hoverBackground ? "transparent" : currentState === "press" || currentState === "hover" ? theme.colors.overlay.mono : "transparent",
982
- text: theme.colors.content.inverse,
983
- border: void 0
984
- };
985
- default:
986
- return {
987
- bg: "transparent",
988
- text: theme.colors.content.primary,
989
- border: void 0
990
- };
991
- }
992
- };
993
- const getFocusRingColor = () => {
994
- switch (variant) {
995
- case "brand":
996
- return theme.colors.overlay.brand;
997
- case "brandExtra":
998
- return theme.colors.overlay.brandExtra;
999
- case "inverse":
1000
- return "rgba(255, 255, 255, 0.3)";
1001
- default:
1002
- return theme.colors.overlay.mono;
1003
- }
1004
- };
1005
- const getSpinnerColor = () => {
1006
- switch (variant) {
1007
- case "brand":
1008
- return theme.colors.content.brand.primary;
1009
- case "primary":
1010
- return theme.colors.content.primary;
1011
- case "secondary":
1012
- return theme.colors.content.secondary;
1013
- case "tertiary":
1014
- return theme.colors.content.tertiary;
1015
- case "brandExtra":
1016
- return theme.colors.content.brandExtra.secondary;
1017
- case "inverse":
1018
- return theme.colors.content.inverse;
1019
- default:
1020
- return theme.colors.content.brand.primary;
1021
- }
1022
- };
1023
- const colors = getVariantColors(state);
1024
- const focusRingColor = getFocusRingColor();
1025
- const spinnerColor = getSpinnerColor();
1026
- const iconSize = ICON_SIZES[size];
1027
- const spinnerSize = SPINNER_SIZES[size];
1028
- const fontSize = FONT_SIZES[size];
1029
- const borderRadius = BORDER_RADIUS[size];
1030
- const lineHeight = LINE_HEIGHTS[size];
1031
- const showTextLabel = hasVisibleLabel(children);
1032
- const hasIconChildren = !showTextLabel && hasRenderableContent(children);
1033
- const isIconOnly = !loading && !showTextLabel && Boolean(iconLeft || iconRight || hasIconChildren);
1034
- const iconOnlyHitArea = theme.sizing.flexButton(size).height;
1035
- const handleMouseEnter = () => {
1036
- if (!isDisabled) {
1037
- isMouseOverRef.current = true;
1038
- setState("hover");
1039
- }
1040
- };
1041
- const handleMouseLeave = () => {
1042
- if (!isDisabled) {
1043
- isMouseOverRef.current = false;
1044
- setState("default");
1045
- }
1046
- };
1047
- const handleMouseDown = () => {
1048
- if (!isDisabled) {
1049
- setState("press");
1050
- }
1051
- };
1052
- const handleMouseUp = () => {
1053
- if (!isDisabled) {
1054
- setState(isMouseOverRef.current ? "hover" : "default");
1055
- }
1056
- };
1057
- const handleFocus = () => {
1058
- if (!isDisabled) {
1059
- setIsFocused(true);
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
- const borderShadow = colors.border ? `inset 0 0 0 1px ${colors.border}` : void 0;
1092
- const focusShadow = isFocused && !isDisabled ? `0 0 0 2px ${focusRingColor}` : void 0;
1093
- const boxShadows = [];
1094
- if (borderShadow) boxShadows.push(borderShadow);
1095
- if (focusShadow) boxShadows.push(focusShadow);
1096
- const combinedBoxShadow = boxShadows.length > 0 ? boxShadows.join(", ") : "none";
1097
- const buttonStyle = {
1098
- display: "inline-flex",
1099
- alignItems: "center",
1100
- justifyContent: "center",
1101
- gap: isIconOnly ? 0 : "2px",
1102
- boxSizing: "border-box",
1103
- padding: noPadding ? "0px" : `${FLEX_BUTTON_PADDING}px`,
1104
- backgroundColor: loading ? "transparent" : colors.bg,
1105
- color: colors.text,
1106
- border: "none",
1107
- borderWidth: "0px",
1108
- borderRadius: `${borderRadius}px`,
1109
- cursor: isDisabled ? "not-allowed" : "pointer",
1110
- fontSize: `${fontSize}px`,
1111
- fontWeight: 500,
1112
- lineHeight: isIconOnly ? 0 : lineHeight,
1113
- fontFamily: "inherit",
1114
- transition: "background-color 100ms ease-in-out, color 100ms ease-in-out, box-shadow 100ms ease-in-out",
1115
- outline: "none",
1116
- boxShadow: combinedBoxShadow,
1117
- opacity: isDisabled && !loading ? 0.6 : 1,
1118
- ...isIconOnly && {
1119
- width: iconOnlyHitArea,
1120
- height: iconOnlyHitArea,
1121
- minWidth: iconOnlyHitArea,
1122
- minHeight: iconOnlyHitArea,
1123
- flexShrink: 0
1124
- }
1125
- };
1126
- const contentStyle = {
1127
- display: "flex",
1128
- alignItems: "center",
1129
- justifyContent: "center",
1130
- gap: isIconOnly ? 0 : "2px",
1131
- ...isIconOnly && {
1132
- width: "100%",
1133
- height: "100%",
1134
- lineHeight: 0
1135
- }
1136
- };
1137
- const spinnerStyle = {
1138
- display: "flex",
1139
- alignItems: "center",
1140
- justifyContent: "center",
1141
- backgroundColor: "transparent",
1142
- height: lineHeight
1143
- };
1144
- const computedAriaLabel = ariaLabel || (typeof children === "string" ? children : void 0);
1145
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1146
- "button",
1147
- {
1148
- ...buttonProps,
1149
- type,
1150
- className,
1151
- disabled: isDisabled,
1152
- onClick: handleClick,
1153
- onMouseEnter: handleMouseEnter,
1154
- onMouseLeave: handleMouseLeave,
1155
- onMouseDown: handleMouseDown,
1156
- onMouseUp: handleMouseUp,
1157
- onKeyDown: handleKeyDown,
1158
- onKeyUp: handleKeyUp,
1159
- onFocus: handleFocus,
1160
- onBlur: handleBlur,
1161
- "aria-label": computedAriaLabel,
1162
- "aria-busy": loading || void 0,
1163
- "aria-disabled": isDisabled || void 0,
1164
- "aria-describedby": ariaDescribedBy,
1165
- "aria-expanded": ariaExpanded,
1166
- "aria-haspopup": ariaHasPopup,
1167
- "aria-pressed": ariaPressed,
1168
- "aria-controls": ariaControls,
1169
- tabIndex,
1170
- style: buttonStyle,
1171
- "data-testid": testID || "flex-button",
1172
- 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: [
1173
- iconLeft && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { size: iconSize, color: colors.text, children: iconLeft }),
1174
- showTextLabel && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children }),
1175
- hasIconChildren && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { size: iconSize, color: colors.text, children }),
1176
- iconRight && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { size: iconSize, color: colors.text, children: iconRight })
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