@xsolla/xui-button 0.190.0 → 0.192.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.mjs CHANGED
@@ -831,12 +831,30 @@ var IconButton = ({
831
831
  IconButton.displayName = "IconButton";
832
832
 
833
833
  // src/FlexButton.tsx
834
- import {
834
+ import React5, {
835
835
  useRef,
836
836
  useState as useState3
837
837
  } from "react";
838
838
  import { useDesignSystem } from "@xsolla/xui-core";
839
839
  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 || node === true) 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
+ if (React5.isValidElement(node)) {
847
+ const { children: elementChildren } = node.props ?? {};
848
+ return hasVisibleLabel(elementChildren);
849
+ }
850
+ return true;
851
+ };
852
+ var hasRenderableContent = (node) => {
853
+ if (node == null || node === false || node === true) return false;
854
+ if (typeof node === "string") return node.trim().length > 0;
855
+ if (Array.isArray(node)) return node.some(hasRenderableContent);
856
+ return true;
857
+ };
840
858
  var ICON_SIZES = {
841
859
  xs: 12,
842
860
  sm: 14,
@@ -1036,6 +1054,10 @@ var FlexButton = ({
1036
1054
  const fontSize = FONT_SIZES[size];
1037
1055
  const borderRadius = BORDER_RADIUS[size];
1038
1056
  const lineHeight = LINE_HEIGHTS[size];
1057
+ const showTextLabel = hasVisibleLabel(children);
1058
+ const hasIconChildren = !showTextLabel && hasRenderableContent(children);
1059
+ const isIconOnly = !loading && !showTextLabel && Boolean(iconLeft || iconRight || hasIconChildren);
1060
+ const iconOnlyHitArea = theme.sizing.flexButton(size).height;
1039
1061
  const handleMouseEnter = () => {
1040
1062
  if (!isDisabled) {
1041
1063
  isMouseOverRef.current = true;
@@ -1102,8 +1124,9 @@ var FlexButton = ({
1102
1124
  display: "inline-flex",
1103
1125
  alignItems: "center",
1104
1126
  justifyContent: "center",
1105
- gap: "2px",
1106
- padding: noPadding ? "0px" : "4px",
1127
+ gap: isIconOnly ? 0 : "2px",
1128
+ boxSizing: "border-box",
1129
+ padding: noPadding ? "0px" : `${FLEX_BUTTON_PADDING}px`,
1107
1130
  backgroundColor: loading ? "transparent" : colors.bg,
1108
1131
  color: colors.text,
1109
1132
  border: "none",
@@ -1112,18 +1135,30 @@ var FlexButton = ({
1112
1135
  cursor: isDisabled ? "not-allowed" : "pointer",
1113
1136
  fontSize: `${fontSize}px`,
1114
1137
  fontWeight: 500,
1115
- lineHeight,
1138
+ lineHeight: isIconOnly ? 0 : lineHeight,
1116
1139
  fontFamily: "inherit",
1117
1140
  transition: "background-color 100ms ease-in-out, color 100ms ease-in-out, box-shadow 100ms ease-in-out",
1118
1141
  outline: "none",
1119
1142
  boxShadow: combinedBoxShadow,
1120
- opacity: isDisabled && !loading ? 0.6 : 1
1143
+ opacity: isDisabled && !loading ? 0.6 : 1,
1144
+ ...isIconOnly && {
1145
+ width: iconOnlyHitArea,
1146
+ height: iconOnlyHitArea,
1147
+ minWidth: iconOnlyHitArea,
1148
+ minHeight: iconOnlyHitArea,
1149
+ flexShrink: 0
1150
+ }
1121
1151
  };
1122
1152
  const contentStyle = {
1123
1153
  display: "flex",
1124
1154
  alignItems: "center",
1125
1155
  justifyContent: "center",
1126
- gap: "2px"
1156
+ gap: isIconOnly ? 0 : "2px",
1157
+ ...isIconOnly && {
1158
+ width: "100%",
1159
+ height: "100%",
1160
+ lineHeight: 0
1161
+ }
1127
1162
  };
1128
1163
  const spinnerStyle = {
1129
1164
  display: "flex",
@@ -1162,7 +1197,8 @@ var FlexButton = ({
1162
1197
  "data-testid": testID || "flex-button",
1163
1198
  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: [
1164
1199
  iconLeft && /* @__PURE__ */ jsx7(Icon, { size: iconSize, color: colors.text, children: iconLeft }),
1165
- /* @__PURE__ */ jsx7("span", { children }),
1200
+ showTextLabel && /* @__PURE__ */ jsx7("span", { children }),
1201
+ hasIconChildren && /* @__PURE__ */ jsx7(Icon, { size: iconSize, color: colors.text, children }),
1166
1202
  iconRight && /* @__PURE__ */ jsx7(Icon, { size: iconSize, color: colors.text, children: iconRight })
1167
1203
  ] }) })
1168
1204
  }