@kbach/react 0.4.3 → 0.5.1
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/README.md +106 -28
- package/dist/{chunk-RJHOB4EU.mjs → chunk-EBISJEHP.mjs} +74 -19
- package/dist/{chunk-HY6PU2XS.mjs → chunk-M3LZVDYD.mjs} +983 -40
- package/dist/index.d.mts +2 -9
- package/dist/index.d.ts +2 -9
- package/dist/index.js +1074 -115
- package/dist/index.mjs +21 -3
- package/dist/jsx-dev-runtime.js +1051 -58
- package/dist/jsx-dev-runtime.mjs +2 -2
- package/dist/jsx-runtime.js +1051 -58
- package/dist/jsx-runtime.mjs +2 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
EMPTY_BREAKPOINTS,
|
|
2
3
|
InteractiveWrapper,
|
|
3
4
|
__require,
|
|
4
5
|
buildConfig,
|
|
@@ -19,9 +20,10 @@ import {
|
|
|
19
20
|
syncGlobalScreens,
|
|
20
21
|
syncGlobalWidth,
|
|
21
22
|
updateConfig,
|
|
23
|
+
useConditionalWidth,
|
|
22
24
|
useGlobalDarkMode,
|
|
23
25
|
useGlobalWidth
|
|
24
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-M3LZVDYD.mjs";
|
|
25
27
|
|
|
26
28
|
// src/context.tsx
|
|
27
29
|
import { createContext, useContext } from "react";
|
|
@@ -370,6 +372,16 @@ import React3, {
|
|
|
370
372
|
useCallback as useCallback3,
|
|
371
373
|
useMemo as useMemo3
|
|
372
374
|
} from "react";
|
|
375
|
+
var RESPONSIVE_MODS = /* @__PURE__ */ new Set(["sm", "md", "lg", "xl", "2xl"]);
|
|
376
|
+
function hasResponsiveBuckets(resolved) {
|
|
377
|
+
for (const key of Object.keys(resolved)) {
|
|
378
|
+
if (key === "base") continue;
|
|
379
|
+
for (const mod of key.split(":")) {
|
|
380
|
+
if (RESPONSIVE_MODS.has(mod)) return true;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
return false;
|
|
384
|
+
}
|
|
373
385
|
function styled(Component, baseClasses = "") {
|
|
374
386
|
const Styled = forwardRef(
|
|
375
387
|
(props, ref) => {
|
|
@@ -414,9 +426,13 @@ function styled(Component, baseClasses = "") {
|
|
|
414
426
|
}, [onBlur]);
|
|
415
427
|
const combined = extraClasses ? `${baseClasses} ${extraClasses}` : baseClasses;
|
|
416
428
|
const resolved = useMemo3(() => resolve(combined, config.theme, config.darkMode), [combined, config.theme, config.darkMode]);
|
|
429
|
+
const needsWidth = hasResponsiveBuckets(resolved);
|
|
430
|
+
const width = useConditionalWidth(needsWidth);
|
|
431
|
+
const breakpoints = needsWidth ? getActiveBreakpoints(width) : EMPTY_BREAKPOINTS;
|
|
417
432
|
const computedStyle = useMemo3(
|
|
418
|
-
() => flatten(resolved, isDark, { pressed, hover: hovered, focus: focused }),
|
|
419
|
-
[resolved, isDark, pressed, hovered, focused]
|
|
433
|
+
() => flatten(resolved, isDark, { pressed, hover: hovered, focus: focused }, breakpoints),
|
|
434
|
+
[resolved, isDark, pressed, hovered, focused, width]
|
|
435
|
+
// eslint-disable-line react-hooks/exhaustive-deps
|
|
420
436
|
);
|
|
421
437
|
const extraStyle = Array.isArray(styleProp) ? Object.assign({}, ...styleProp) : styleProp;
|
|
422
438
|
const finalStyle = extraStyle ? { ...computedStyle, ...extraStyle } : computedStyle;
|
|
@@ -424,6 +440,8 @@ function styled(Component, baseClasses = "") {
|
|
|
424
440
|
ref,
|
|
425
441
|
...rest,
|
|
426
442
|
style: finalStyle,
|
|
443
|
+
// className lets injected CSS rules (group-hover:, before:, print:, etc.) match the element.
|
|
444
|
+
...isWeb && combined ? { className: combined } : {},
|
|
427
445
|
// onPressIn / onPressOut are React Native-only events; forwarding them to
|
|
428
446
|
// a DOM element on web triggers React's unknown-prop warning.
|
|
429
447
|
...isWeb ? {} : { onPressIn: handlePressIn, onPressOut: handlePressOut },
|