@xsolla/xui-button 0.190.0 → 0.191.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.d.mts +2 -2
- package/native/index.d.ts +2 -2
- package/native/index.js +29 -6
- package/native/index.js.map +1 -1
- package/native/index.mjs +29 -6
- package/native/index.mjs.map +1 -1
- package/package.json +4 -4
- package/web/index.d.mts +2 -2
- package/web/index.d.ts +2 -2
- package/web/index.js +29 -6
- package/web/index.js.map +1 -1
- package/web/index.mjs +29 -6
- package/web/index.mjs.map +1 -1
package/web/index.mjs
CHANGED
|
@@ -837,6 +837,14 @@ import {
|
|
|
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) 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
|
+
};
|
|
840
848
|
var ICON_SIZES = {
|
|
841
849
|
xs: 12,
|
|
842
850
|
sm: 14,
|
|
@@ -1036,6 +1044,8 @@ var FlexButton = ({
|
|
|
1036
1044
|
const fontSize = FONT_SIZES[size];
|
|
1037
1045
|
const borderRadius = BORDER_RADIUS[size];
|
|
1038
1046
|
const lineHeight = LINE_HEIGHTS[size];
|
|
1047
|
+
const isIconOnly = !loading && !hasVisibleLabel(children) && Boolean(iconLeft || iconRight);
|
|
1048
|
+
const iconOnlyHitArea = iconSize + FLEX_BUTTON_PADDING * 2;
|
|
1039
1049
|
const handleMouseEnter = () => {
|
|
1040
1050
|
if (!isDisabled) {
|
|
1041
1051
|
isMouseOverRef.current = true;
|
|
@@ -1102,8 +1112,9 @@ var FlexButton = ({
|
|
|
1102
1112
|
display: "inline-flex",
|
|
1103
1113
|
alignItems: "center",
|
|
1104
1114
|
justifyContent: "center",
|
|
1105
|
-
gap: "2px",
|
|
1106
|
-
|
|
1115
|
+
gap: isIconOnly ? 0 : "2px",
|
|
1116
|
+
boxSizing: "border-box",
|
|
1117
|
+
padding: noPadding ? "0px" : `${FLEX_BUTTON_PADDING}px`,
|
|
1107
1118
|
backgroundColor: loading ? "transparent" : colors.bg,
|
|
1108
1119
|
color: colors.text,
|
|
1109
1120
|
border: "none",
|
|
@@ -1112,18 +1123,30 @@ var FlexButton = ({
|
|
|
1112
1123
|
cursor: isDisabled ? "not-allowed" : "pointer",
|
|
1113
1124
|
fontSize: `${fontSize}px`,
|
|
1114
1125
|
fontWeight: 500,
|
|
1115
|
-
lineHeight,
|
|
1126
|
+
lineHeight: isIconOnly ? 0 : lineHeight,
|
|
1116
1127
|
fontFamily: "inherit",
|
|
1117
1128
|
transition: "background-color 100ms ease-in-out, color 100ms ease-in-out, box-shadow 100ms ease-in-out",
|
|
1118
1129
|
outline: "none",
|
|
1119
1130
|
boxShadow: combinedBoxShadow,
|
|
1120
|
-
opacity: isDisabled && !loading ? 0.6 : 1
|
|
1131
|
+
opacity: isDisabled && !loading ? 0.6 : 1,
|
|
1132
|
+
...isIconOnly && {
|
|
1133
|
+
width: iconOnlyHitArea,
|
|
1134
|
+
height: iconOnlyHitArea,
|
|
1135
|
+
minWidth: iconOnlyHitArea,
|
|
1136
|
+
minHeight: iconOnlyHitArea,
|
|
1137
|
+
flexShrink: 0
|
|
1138
|
+
}
|
|
1121
1139
|
};
|
|
1122
1140
|
const contentStyle = {
|
|
1123
1141
|
display: "flex",
|
|
1124
1142
|
alignItems: "center",
|
|
1125
1143
|
justifyContent: "center",
|
|
1126
|
-
gap: "2px"
|
|
1144
|
+
gap: isIconOnly ? 0 : "2px",
|
|
1145
|
+
...isIconOnly && {
|
|
1146
|
+
width: "100%",
|
|
1147
|
+
height: "100%",
|
|
1148
|
+
lineHeight: 0
|
|
1149
|
+
}
|
|
1127
1150
|
};
|
|
1128
1151
|
const spinnerStyle = {
|
|
1129
1152
|
display: "flex",
|
|
@@ -1162,7 +1185,7 @@ var FlexButton = ({
|
|
|
1162
1185
|
"data-testid": testID || "flex-button",
|
|
1163
1186
|
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
1187
|
iconLeft && /* @__PURE__ */ jsx7(Icon, { size: iconSize, color: colors.text, children: iconLeft }),
|
|
1165
|
-
/* @__PURE__ */ jsx7("span", { children }),
|
|
1188
|
+
hasVisibleLabel(children) && /* @__PURE__ */ jsx7("span", { children }),
|
|
1166
1189
|
iconRight && /* @__PURE__ */ jsx7(Icon, { size: iconSize, color: colors.text, children: iconRight })
|
|
1167
1190
|
] }) })
|
|
1168
1191
|
}
|