@kosdev-code/kos-ddk-components 0.1.0-dev.76 → 0.1.0-dev.87
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/components/dashboard-card/dashboard-card.d.ts.map +1 -1
- package/index.cjs +31 -3
- package/index.cjs.map +1 -1
- package/index.js +31 -3
- package/index.js.map +1 -1
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -5137,9 +5137,36 @@ const CardTitle$1 = styled.div`
|
|
|
5137
5137
|
gap: 12px;
|
|
5138
5138
|
|
|
5139
5139
|
letter-spacing: 0.56px;
|
|
5140
|
-
|
|
5141
|
-
max-height: 36px;
|
|
5142
5140
|
`;
|
|
5141
|
+
const TITLE_TWO_LINES = 2.6;
|
|
5142
|
+
const TITLE_MIN_SCALE = 0.75;
|
|
5143
|
+
const useFitTitle = () => {
|
|
5144
|
+
const ref = useRef(null);
|
|
5145
|
+
const fitted = useRef("");
|
|
5146
|
+
const fit = useCallback(() => {
|
|
5147
|
+
const el = ref.current;
|
|
5148
|
+
if (!el) return;
|
|
5149
|
+
const key = `${el.clientWidth}|${el.textContent}`;
|
|
5150
|
+
if (key === fitted.current) return;
|
|
5151
|
+
fitted.current = key;
|
|
5152
|
+
el.style.fontSize = "";
|
|
5153
|
+
let size = parseFloat(getComputedStyle(el).fontSize);
|
|
5154
|
+
const min = size * TITLE_MIN_SCALE;
|
|
5155
|
+
while (el.scrollHeight > size * TITLE_TWO_LINES && size - 1 >= min) {
|
|
5156
|
+
size -= 1;
|
|
5157
|
+
el.style.fontSize = `${size}px`;
|
|
5158
|
+
}
|
|
5159
|
+
}, []);
|
|
5160
|
+
useLayoutEffect(fit);
|
|
5161
|
+
useLayoutEffect(() => {
|
|
5162
|
+
const el = ref.current;
|
|
5163
|
+
if (!el || typeof ResizeObserver === "undefined") return;
|
|
5164
|
+
const observer = new ResizeObserver(() => fit());
|
|
5165
|
+
observer.observe(el);
|
|
5166
|
+
return () => observer.disconnect();
|
|
5167
|
+
}, [fit]);
|
|
5168
|
+
return ref;
|
|
5169
|
+
};
|
|
5143
5170
|
const CardBody = styled.div`
|
|
5144
5171
|
align-items: center;
|
|
5145
5172
|
grid-area: body;
|
|
@@ -5206,6 +5233,7 @@ const DashboardCard = ({
|
|
|
5206
5233
|
};
|
|
5207
5234
|
const { componentModeOverride } = useComponentConfigurationContext();
|
|
5208
5235
|
const isCompact = componentModeOverride === "compact";
|
|
5236
|
+
const titleRef = useFitTitle();
|
|
5209
5237
|
return /* @__PURE__ */ jsxs(
|
|
5210
5238
|
DashboardCardContainer,
|
|
5211
5239
|
{
|
|
@@ -5224,7 +5252,7 @@ const DashboardCard = ({
|
|
|
5224
5252
|
}
|
|
5225
5253
|
),
|
|
5226
5254
|
!!avatar && /* @__PURE__ */ jsx(CardAvatar, { backgroundColor, children: avatar }),
|
|
5227
|
-
title && /* @__PURE__ */ jsx(CardTitle$1, { backgroundColor, children: title }),
|
|
5255
|
+
title && /* @__PURE__ */ jsx(CardTitle$1, { ref: titleRef, backgroundColor, children: title }),
|
|
5228
5256
|
/* @__PURE__ */ jsx(CardBody, { children: body }),
|
|
5229
5257
|
componentModeOverride === "compact" && !!showNavIcon && /* @__PURE__ */ jsx(CardNav, {}),
|
|
5230
5258
|
!!footer && /* @__PURE__ */ jsx(CardFooter, { children: footer })
|