@khipu/design-system 0.3.5-alpha.7 → 0.3.5-alpha.9
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/dist/beercss/khipu-beercss.css +1 -1
- package/dist/beercss/khipu-beercss.js +5 -61
- package/dist/beercss/khipu-beercss.min.js +1 -1
- package/dist/beercss/khipu-beercss.scoped.css +1 -1
- package/dist/beercss/metadata.json +5 -5
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +162 -242
- package/dist/index.mjs +31 -112
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
// src/theme/KdsThemeProvider.tsx
|
|
2
|
-
import { useEffect } from "react";
|
|
3
|
-
|
|
4
1
|
// src/components/core/utils.ts
|
|
5
2
|
import { clsx } from "clsx";
|
|
6
3
|
function hexToRgb(hex) {
|
|
@@ -72,107 +69,28 @@ function formatTime(iso) {
|
|
|
72
69
|
return `${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
73
70
|
}
|
|
74
71
|
|
|
72
|
+
// src/version.ts
|
|
73
|
+
var KDS_VERSION = "0.3.5-alpha.9";
|
|
74
|
+
|
|
75
75
|
// src/theme/KdsThemeProvider.tsx
|
|
76
76
|
import { jsx } from "react/jsx-runtime";
|
|
77
|
-
var CARD_MIN_DELTA_PX = 8;
|
|
78
|
-
var CARD_TRANSITION_MS = 280;
|
|
79
|
-
var BODY_CARD_SELECTOR = ".kds-screen > .kds-card-elevated";
|
|
80
|
-
var CARD_MARK_ATTRIBUTE = "data-kds-height-transition";
|
|
81
|
-
var SCREEN_LAST_HEIGHT_ATTRIBUTE = "data-kds-last-card-height";
|
|
82
|
-
function useCardHeightTransition() {
|
|
83
|
-
useEffect(() => {
|
|
84
|
-
if (typeof window === "undefined" || typeof ResizeObserver === "undefined") {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
if (typeof Element.prototype.animate !== "function") {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
if (window.matchMedia?.("(prefers-reduced-motion: reduce)").matches) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
const observers = [];
|
|
94
|
-
const animate = (card, from, to) => {
|
|
95
|
-
card.style.height = `${from}px`;
|
|
96
|
-
const animation = card.animate(
|
|
97
|
-
[{ height: `${from}px` }, { height: `${to}px` }],
|
|
98
|
-
{ duration: CARD_TRANSITION_MS, easing: "ease-out" }
|
|
99
|
-
);
|
|
100
|
-
return animation.finished.catch(() => void 0).then(() => {
|
|
101
|
-
const current = parseFloat(card.style.height) || card.offsetHeight;
|
|
102
|
-
const natural = card.scrollHeight;
|
|
103
|
-
if (Math.abs(natural - current) >= CARD_MIN_DELTA_PX) {
|
|
104
|
-
return animate(card, current, natural);
|
|
105
|
-
}
|
|
106
|
-
card.style.height = "";
|
|
107
|
-
return void 0;
|
|
108
|
-
});
|
|
109
|
-
};
|
|
110
|
-
const observe = (card) => {
|
|
111
|
-
if (card.getAttribute(CARD_MARK_ATTRIBUTE) === "on") {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
card.setAttribute(CARD_MARK_ATTRIBUTE, "on");
|
|
115
|
-
const screen = card.parentElement;
|
|
116
|
-
let previous = card.offsetHeight;
|
|
117
|
-
let animating = false;
|
|
118
|
-
const remembered = screen?.getAttribute(SCREEN_LAST_HEIGHT_ATTRIBUTE);
|
|
119
|
-
if (remembered) {
|
|
120
|
-
const from = Number(remembered);
|
|
121
|
-
if (Number.isFinite(from) && from > 0 && Math.abs(from - previous) >= CARD_MIN_DELTA_PX) {
|
|
122
|
-
animating = true;
|
|
123
|
-
animate(card, from, previous).then(() => {
|
|
124
|
-
animating = false;
|
|
125
|
-
previous = card.offsetHeight;
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
screen?.setAttribute(SCREEN_LAST_HEIGHT_ATTRIBUTE, String(previous));
|
|
130
|
-
const observer = new ResizeObserver(() => {
|
|
131
|
-
if (animating) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
const next = card.offsetHeight;
|
|
135
|
-
if (Math.abs(next - previous) < CARD_MIN_DELTA_PX) {
|
|
136
|
-
previous = next;
|
|
137
|
-
screen?.setAttribute(SCREEN_LAST_HEIGHT_ATTRIBUTE, String(next));
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
animating = true;
|
|
141
|
-
const from = previous;
|
|
142
|
-
previous = next;
|
|
143
|
-
screen?.setAttribute(SCREEN_LAST_HEIGHT_ATTRIBUTE, String(next));
|
|
144
|
-
animate(card, from, next).then(() => {
|
|
145
|
-
animating = false;
|
|
146
|
-
previous = card.offsetHeight;
|
|
147
|
-
screen?.setAttribute(SCREEN_LAST_HEIGHT_ATTRIBUTE, String(previous));
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
observer.observe(card);
|
|
151
|
-
observers.push(observer);
|
|
152
|
-
};
|
|
153
|
-
document.querySelectorAll(BODY_CARD_SELECTOR).forEach(observe);
|
|
154
|
-
const tree = new MutationObserver(() => {
|
|
155
|
-
document.querySelectorAll(BODY_CARD_SELECTOR).forEach(observe);
|
|
156
|
-
});
|
|
157
|
-
tree.observe(document.body, { childList: true, subtree: true });
|
|
158
|
-
return () => {
|
|
159
|
-
tree.disconnect();
|
|
160
|
-
observers.forEach((observer) => observer.disconnect());
|
|
161
|
-
document.querySelectorAll(BODY_CARD_SELECTOR).forEach((card) => {
|
|
162
|
-
card.removeAttribute(CARD_MARK_ATTRIBUTE);
|
|
163
|
-
});
|
|
164
|
-
};
|
|
165
|
-
}, []);
|
|
166
|
-
}
|
|
167
77
|
function KdsThemeProvider({ primaryColor, mode = "light", children }) {
|
|
168
|
-
useCardHeightTransition();
|
|
169
78
|
const style = primaryColor ? {
|
|
170
79
|
"--primary": primaryColor,
|
|
171
80
|
"--on-primary": getContrastColor(primaryColor),
|
|
172
81
|
"--primary-container": lighten(primaryColor, 0.85),
|
|
173
82
|
"--on-primary-container": primaryColor
|
|
174
83
|
} : void 0;
|
|
175
|
-
return /* @__PURE__ */ jsx(
|
|
84
|
+
return /* @__PURE__ */ jsx(
|
|
85
|
+
"div",
|
|
86
|
+
{
|
|
87
|
+
className: `kds-theme-root ${mode}`,
|
|
88
|
+
"data-theme": mode,
|
|
89
|
+
"data-kds-version": KDS_VERSION,
|
|
90
|
+
style,
|
|
91
|
+
children
|
|
92
|
+
}
|
|
93
|
+
);
|
|
176
94
|
}
|
|
177
95
|
|
|
178
96
|
// src/tokens/index.ts
|
|
@@ -1548,7 +1466,7 @@ var KdsTypography = forwardRef11(
|
|
|
1548
1466
|
KdsTypography.displayName = "KdsTypography";
|
|
1549
1467
|
|
|
1550
1468
|
// src/components/core/KdsTabs/KdsTabs.tsx
|
|
1551
|
-
import
|
|
1469
|
+
import React12, { forwardRef as forwardRef12, Children, useMemo } from "react";
|
|
1552
1470
|
|
|
1553
1471
|
// src/components/core/hooks/useTabsKeyboard.ts
|
|
1554
1472
|
import { useCallback as useCallback2 } from "react";
|
|
@@ -1596,8 +1514,8 @@ var KdsTabs = forwardRef12(
|
|
|
1596
1514
|
onKeyDown,
|
|
1597
1515
|
...props,
|
|
1598
1516
|
children: Children.map(children, (child, i) => {
|
|
1599
|
-
if (!
|
|
1600
|
-
return
|
|
1517
|
+
if (!React12.isValidElement(child)) return child;
|
|
1518
|
+
return React12.cloneElement(child, {
|
|
1601
1519
|
_active: i === activeIndex,
|
|
1602
1520
|
_onClick: () => onChange(i)
|
|
1603
1521
|
});
|
|
@@ -1758,12 +1676,12 @@ KdsChip.displayName = "KdsChip";
|
|
|
1758
1676
|
import { forwardRef as forwardRef16 } from "react";
|
|
1759
1677
|
|
|
1760
1678
|
// src/components/core/hooks/useAutoHide.ts
|
|
1761
|
-
import { useState as useState3, useEffect
|
|
1679
|
+
import { useState as useState3, useEffect, useRef } from "react";
|
|
1762
1680
|
function useAutoHide(durationMs, onHide) {
|
|
1763
1681
|
const [visible, setVisible] = useState3(true);
|
|
1764
1682
|
const onHideRef = useRef(onHide);
|
|
1765
1683
|
onHideRef.current = onHide;
|
|
1766
|
-
|
|
1684
|
+
useEffect(() => {
|
|
1767
1685
|
if (durationMs <= 0) return;
|
|
1768
1686
|
const timer = setTimeout(() => {
|
|
1769
1687
|
setVisible(false);
|
|
@@ -2207,10 +2125,10 @@ var KdsExpandPanel = forwardRef24(
|
|
|
2207
2125
|
KdsExpandPanel.displayName = "KdsExpandPanel";
|
|
2208
2126
|
|
|
2209
2127
|
// src/components/core/KdsCountdown/KdsCountdown.tsx
|
|
2210
|
-
import { forwardRef as forwardRef25, useEffect as
|
|
2128
|
+
import { forwardRef as forwardRef25, useEffect as useEffect3, useRef as useRef3 } from "react";
|
|
2211
2129
|
|
|
2212
2130
|
// src/components/core/hooks/useCountdown.ts
|
|
2213
|
-
import { useState as useState6, useEffect as
|
|
2131
|
+
import { useState as useState6, useEffect as useEffect2 } from "react";
|
|
2214
2132
|
function calcRemaining(deadline) {
|
|
2215
2133
|
const diff = Math.max(0, new Date(deadline).getTime() - Date.now());
|
|
2216
2134
|
const totalSeconds = Math.floor(diff / 1e3);
|
|
@@ -2224,7 +2142,7 @@ function calcRemaining(deadline) {
|
|
|
2224
2142
|
}
|
|
2225
2143
|
function useCountdown(deadline) {
|
|
2226
2144
|
const [state, setState] = useState6(() => calcRemaining(deadline));
|
|
2227
|
-
|
|
2145
|
+
useEffect2(() => {
|
|
2228
2146
|
const tick = () => setState(calcRemaining(deadline));
|
|
2229
2147
|
const id = setInterval(tick, 1e3);
|
|
2230
2148
|
return () => clearInterval(id);
|
|
@@ -2239,7 +2157,7 @@ var KdsCountdown = forwardRef25(
|
|
|
2239
2157
|
const { hours, minutes, seconds, expired, urgent } = useCountdown(deadline);
|
|
2240
2158
|
const onExpireRef = useRef3(onExpire);
|
|
2241
2159
|
onExpireRef.current = onExpire;
|
|
2242
|
-
|
|
2160
|
+
useEffect3(() => {
|
|
2243
2161
|
if (expired) {
|
|
2244
2162
|
onExpireRef.current?.();
|
|
2245
2163
|
}
|
|
@@ -2618,7 +2536,7 @@ KdsMerchantTile.displayName = "KdsMerchantTile";
|
|
|
2618
2536
|
import { forwardRef as forwardRef42, useState as useState9 } from "react";
|
|
2619
2537
|
|
|
2620
2538
|
// src/components/domain/KdsInvoiceMerchant/useLogoBackdrop.ts
|
|
2621
|
-
import { useEffect as
|
|
2539
|
+
import { useEffect as useEffect4, useState as useState8 } from "react";
|
|
2622
2540
|
|
|
2623
2541
|
// src/components/domain/KdsInvoiceMerchant/logoLuminance.ts
|
|
2624
2542
|
var LIGHT_LOGO_LUMINANCE_THRESHOLD = 0.72;
|
|
@@ -2668,7 +2586,7 @@ function pickLogoBackdrop(luminance) {
|
|
|
2668
2586
|
// src/components/domain/KdsInvoiceMerchant/useLogoBackdrop.ts
|
|
2669
2587
|
function useLogoBackdrop(logoUrl) {
|
|
2670
2588
|
const [backdrop, setBackdrop] = useState8("light");
|
|
2671
|
-
|
|
2589
|
+
useEffect4(() => {
|
|
2672
2590
|
let cancelled = false;
|
|
2673
2591
|
setBackdrop("light");
|
|
2674
2592
|
if (!logoUrl) {
|
|
@@ -2910,12 +2828,12 @@ var guideToFirstInvalidFieldOnBlur = (form) => {
|
|
|
2910
2828
|
};
|
|
2911
2829
|
|
|
2912
2830
|
// src/components/core/hooks/useStickyInvoiceCollapse.ts
|
|
2913
|
-
import { useEffect as
|
|
2831
|
+
import { useEffect as useEffect5, useRef as useRef4 } from "react";
|
|
2914
2832
|
function useStickyInvoiceCollapse(options = {}) {
|
|
2915
2833
|
const { onCollapseStart, collapseEnd = 20, mobileBreakpoint = 768 } = options;
|
|
2916
2834
|
const onCollapseStartRef = useRef4(onCollapseStart);
|
|
2917
2835
|
onCollapseStartRef.current = onCollapseStart;
|
|
2918
|
-
|
|
2836
|
+
useEffect5(() => {
|
|
2919
2837
|
let viewportOffset = 0;
|
|
2920
2838
|
let ticking = false;
|
|
2921
2839
|
let wasCollapsing = false;
|
|
@@ -3037,11 +2955,11 @@ function useExpandToggle(options = {}) {
|
|
|
3037
2955
|
}
|
|
3038
2956
|
|
|
3039
2957
|
// src/components/core/hooks/useHideOnScroll.ts
|
|
3040
|
-
import { useEffect as
|
|
2958
|
+
import { useEffect as useEffect6, useState as useState11 } from "react";
|
|
3041
2959
|
function useHideOnScroll(options = {}) {
|
|
3042
2960
|
const { threshold = 8, topOffset = 0 } = options;
|
|
3043
2961
|
const [hidden, setHidden] = useState11(false);
|
|
3044
|
-
|
|
2962
|
+
useEffect6(() => {
|
|
3045
2963
|
let viewportOffset = 0;
|
|
3046
2964
|
let lastY = 0;
|
|
3047
2965
|
let ticking = false;
|
|
@@ -3084,12 +3002,12 @@ function useHideOnScroll(options = {}) {
|
|
|
3084
3002
|
}
|
|
3085
3003
|
|
|
3086
3004
|
// src/components/core/hooks/useMediaQuery.ts
|
|
3087
|
-
import { useEffect as
|
|
3005
|
+
import { useEffect as useEffect7, useState as useState12 } from "react";
|
|
3088
3006
|
function useMediaQuery(query) {
|
|
3089
3007
|
const [matches, setMatches] = useState12(
|
|
3090
3008
|
() => typeof window !== "undefined" ? window.matchMedia(query).matches : false
|
|
3091
3009
|
);
|
|
3092
|
-
|
|
3010
|
+
useEffect7(() => {
|
|
3093
3011
|
if (typeof window === "undefined") return;
|
|
3094
3012
|
const mql = window.matchMedia(query);
|
|
3095
3013
|
setMatches(mql.matches);
|
|
@@ -3100,6 +3018,7 @@ function useMediaQuery(query) {
|
|
|
3100
3018
|
return matches;
|
|
3101
3019
|
}
|
|
3102
3020
|
export {
|
|
3021
|
+
KDS_VERSION,
|
|
3103
3022
|
KdsAccordion,
|
|
3104
3023
|
KdsAccordionDetails,
|
|
3105
3024
|
KdsAccordionSummary,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khipu/design-system",
|
|
3
|
-
"version": "0.3.5-alpha.
|
|
3
|
+
"version": "0.3.5-alpha.9",
|
|
4
4
|
"description": "Khipu Design System - UI components and design tokens for the Khipu payment platform",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "npm run build:web && npm run tokens:export && node scripts/generate-css-variables.js && npm run beercss:build",
|
|
52
|
-
"build:web": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
52
|
+
"build:web": "node scripts/generate-version.js && tsup src/index.ts --format cjs,esm --dts --clean",
|
|
53
53
|
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
54
54
|
"demo": "vite --config demo/vite.config.ts",
|
|
55
55
|
"typecheck": "tsc --noEmit",
|