@knitui/components 1.2.2 → 1.3.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/lib/commonjs/Avatar/Avatar.js +22 -10
- package/lib/commonjs/Avatar/Avatar.js.map +1 -1
- package/lib/commonjs/Modal/index.js +18 -0
- package/lib/commonjs/Modal/index.js.map +1 -1
- package/lib/commonjs/Modal/modal-base.js +20 -15
- package/lib/commonjs/Modal/modal-base.js.map +1 -1
- package/lib/commonjs/Modal/modal-stack.js +87 -0
- package/lib/commonjs/Modal/modal-stack.js.map +1 -0
- package/lib/commonjs/Portal/OverlayPortal.js +7 -1
- package/lib/commonjs/Portal/OverlayPortal.js.map +1 -1
- package/lib/commonjs/Portal/index.js +19 -0
- package/lib/commonjs/Portal/index.js.map +1 -1
- package/lib/commonjs/Portal/teleported-layer-scope.js +72 -0
- package/lib/commonjs/Portal/teleported-layer-scope.js.map +1 -0
- package/lib/commonjs/ScrollArea/ScrollArea.js +23 -1
- package/lib/commonjs/ScrollArea/ScrollArea.js.map +1 -1
- package/lib/commonjs/ScrollArea/ScrollArea.native.js +70 -61
- package/lib/commonjs/ScrollArea/ScrollArea.native.js.map +1 -1
- package/lib/commonjs/index.js +30 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/Avatar/Avatar.js +22 -10
- package/lib/module/Avatar/Avatar.js.map +1 -1
- package/lib/module/Modal/index.js +1 -0
- package/lib/module/Modal/index.js.map +1 -1
- package/lib/module/Modal/modal-base.js +20 -15
- package/lib/module/Modal/modal-base.js.map +1 -1
- package/lib/module/Modal/modal-stack.js +80 -0
- package/lib/module/Modal/modal-stack.js.map +1 -0
- package/lib/module/Portal/OverlayPortal.js +8 -2
- package/lib/module/Portal/OverlayPortal.js.map +1 -1
- package/lib/module/Portal/index.js +1 -0
- package/lib/module/Portal/index.js.map +1 -1
- package/lib/module/Portal/teleported-layer-scope.js +66 -0
- package/lib/module/Portal/teleported-layer-scope.js.map +1 -0
- package/lib/module/ScrollArea/ScrollArea.js +23 -1
- package/lib/module/ScrollArea/ScrollArea.js.map +1 -1
- package/lib/module/ScrollArea/ScrollArea.native.js +70 -61
- package/lib/module/ScrollArea/ScrollArea.native.js.map +1 -1
- package/lib/module/index.js +2 -2
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/Avatar/Avatar.d.ts +5 -0
- package/lib/typescript/Avatar/Avatar.d.ts.map +1 -1
- package/lib/typescript/Modal/index.d.ts +1 -0
- package/lib/typescript/Modal/index.d.ts.map +1 -1
- package/lib/typescript/Modal/modal-base.d.ts +2 -2
- package/lib/typescript/Modal/modal-base.d.ts.map +1 -1
- package/lib/typescript/Modal/modal-stack.d.ts +45 -0
- package/lib/typescript/Modal/modal-stack.d.ts.map +1 -0
- package/lib/typescript/Portal/OverlayPortal.d.ts.map +1 -1
- package/lib/typescript/Portal/index.d.ts +1 -0
- package/lib/typescript/Portal/index.d.ts.map +1 -1
- package/lib/typescript/Portal/teleported-layer-scope.d.ts +41 -0
- package/lib/typescript/Portal/teleported-layer-scope.d.ts.map +1 -0
- package/lib/typescript/ScrollArea/ScrollArea.d.ts.map +1 -1
- package/lib/typescript/ScrollArea/ScrollArea.native.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +3 -3
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/Avatar/Avatar.tsx +24 -8
- package/src/Modal/index.ts +1 -0
- package/src/Modal/modal-base.tsx +17 -18
- package/src/Modal/modal-stack.ts +100 -0
- package/src/Portal/OverlayPortal.tsx +9 -2
- package/src/Portal/index.ts +6 -0
- package/src/Portal/teleported-layer-scope.tsx +73 -0
- package/src/ScrollArea/ScrollArea.native.tsx +85 -74
- package/src/ScrollArea/ScrollArea.tsx +47 -1
- package/src/index.ts +8 -1
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Lets a scroller know that an overlay rendered INSIDE it in React (a `Sheet`,
|
|
5
|
+
* `Modal`, `Drawer` or dropdown teleported on screen through `OverlayPortal`)
|
|
6
|
+
* is currently open.
|
|
7
|
+
*
|
|
8
|
+
* Why (native): teleporting moves the native view, but in React the layer stays
|
|
9
|
+
* where it was rendered, e.g. a comment sheet opened from a row of a feed list.
|
|
10
|
+
* React Native's responder system walks the React tree, so that list's
|
|
11
|
+
* `ScrollView` is an ancestor of every button in the sheet. With the default
|
|
12
|
+
* `keyboardShouldPersistTaps="never"` the ScrollView CAPTURES a touch that starts
|
|
13
|
+
* while the keyboard is up, only to dismiss the keyboard, and the sheet's button
|
|
14
|
+
* never gets the first tap. A descendant cannot outbid an ancestor's capture, so
|
|
15
|
+
* the scroller has to step back: while a layer is registered here it uses
|
|
16
|
+
* `"handled"`, which leaves the tap to the control it lands on and still
|
|
17
|
+
* dismisses the keyboard on a tap nothing handles.
|
|
18
|
+
*
|
|
19
|
+
* Scopes nest: a layer registers with the nearest scroller, which forwards the
|
|
20
|
+
* registration to every scroller above it. Web has no such capture, so
|
|
21
|
+
* `OverlayPortal` only registers on native.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
type RegisterLayer = () => () => void;
|
|
25
|
+
|
|
26
|
+
const TeleportedLayerContext = React.createContext<RegisterLayer | null>(null);
|
|
27
|
+
|
|
28
|
+
export interface TeleportedLayerScope {
|
|
29
|
+
/** At least one teleported layer rendered inside this scope is open. */
|
|
30
|
+
hasOpenLayer: boolean;
|
|
31
|
+
/** Wrap the scroller's children so layers inside it can register. */
|
|
32
|
+
Provider: typeof TeleportedLayerContext.Provider;
|
|
33
|
+
register: RegisterLayer;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Scroller side: open a scope and learn whether a layer inside it is open. */
|
|
37
|
+
export function useTeleportedLayerScope(): TeleportedLayerScope {
|
|
38
|
+
const parent = React.useContext(TeleportedLayerContext);
|
|
39
|
+
const [count, setCount] = React.useState(0);
|
|
40
|
+
const register = React.useCallback<RegisterLayer>(() => {
|
|
41
|
+
setCount((c) => c + 1);
|
|
42
|
+
const releaseParent = parent?.();
|
|
43
|
+
let released = false;
|
|
44
|
+
return () => {
|
|
45
|
+
if (released) return;
|
|
46
|
+
released = true;
|
|
47
|
+
setCount((c) => c - 1);
|
|
48
|
+
releaseParent?.();
|
|
49
|
+
};
|
|
50
|
+
}, [parent]);
|
|
51
|
+
return { hasOpenLayer: count > 0, Provider: TeleportedLayerContext.Provider, register };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Layer side: register with the enclosing scroller(s) while `active`. */
|
|
55
|
+
export function useRegisterTeleportedLayer(active: boolean): void {
|
|
56
|
+
const register = React.useContext(TeleportedLayerContext);
|
|
57
|
+
React.useEffect(() => {
|
|
58
|
+
if (!active || !register) return;
|
|
59
|
+
return register();
|
|
60
|
+
}, [active, register]);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The `keyboardShouldPersistTaps` a native scroller should use: the consumer's
|
|
65
|
+
* explicit value wins; otherwise `"handled"` while a layer inside it is open.
|
|
66
|
+
*/
|
|
67
|
+
export function resolvePersistTaps<T>(
|
|
68
|
+
explicit: T | undefined,
|
|
69
|
+
hasOpenLayer: boolean,
|
|
70
|
+
): T | "handled" | undefined {
|
|
71
|
+
if (explicit !== undefined) return explicit;
|
|
72
|
+
return hasOpenLayer ? "handled" : undefined;
|
|
73
|
+
}
|
|
@@ -30,6 +30,7 @@ import { useReducedTransition } from "../internal/motion";
|
|
|
30
30
|
import { resolveThemeColor } from "../internal/resolve-theme-color";
|
|
31
31
|
import { scopeTransition } from "../internal/style-props";
|
|
32
32
|
import { slotStyles } from "../internal/styles";
|
|
33
|
+
import { resolvePersistTaps, useTeleportedLayerScope } from "../Portal/teleported-layer-scope";
|
|
33
34
|
import {
|
|
34
35
|
DEFAULT_HIDE_DELAY,
|
|
35
36
|
DEFAULT_IDLE_SCROLLBAR_SIZE,
|
|
@@ -894,6 +895,11 @@ const ScrollAreaComponent = React.forwardRef<ScrollAreaHandle, ScrollAreaProps>(
|
|
|
894
895
|
const padRight = shouldOffsetAxis(offsetScrollbars, "y") ? scrollbarSize : 0;
|
|
895
896
|
const padBottom = shouldOffsetAxis(offsetScrollbars, "x") ? scrollbarSize : 0;
|
|
896
897
|
|
|
898
|
+
// A sheet/modal teleported from inside this area still has the ScrollView as
|
|
899
|
+
// its React ancestor; while one is open, step back to `"handled"` so its
|
|
900
|
+
// controls get the first tap with the keyboard up (`teleported-layer-scope`).
|
|
901
|
+
const layerScope = useTeleportedLayerScope();
|
|
902
|
+
|
|
897
903
|
// Shared native-ScrollView props (single-axis + Autosize). `viewportRef` lands on
|
|
898
904
|
// the scroller. `nestedScrollEnabled` is what makes a vertical area scroll when it
|
|
899
905
|
// sits inside another vertical ScrollView on Android (inner consumes first, then
|
|
@@ -909,7 +915,10 @@ const ScrollAreaComponent = React.forwardRef<ScrollAreaHandle, ScrollAreaProps>(
|
|
|
909
915
|
showsHorizontalScrollIndicator: false,
|
|
910
916
|
scrollEventThrottle: 16,
|
|
911
917
|
nestedScrollEnabled: true,
|
|
912
|
-
keyboardShouldPersistTaps:
|
|
918
|
+
keyboardShouldPersistTaps: resolvePersistTaps(
|
|
919
|
+
keyboardShouldPersistTaps,
|
|
920
|
+
layerScope.hasOpenLayer,
|
|
921
|
+
) as never,
|
|
913
922
|
...(onRefresh
|
|
914
923
|
? {
|
|
915
924
|
refreshControl: (
|
|
@@ -1004,81 +1013,83 @@ const ScrollAreaComponent = React.forwardRef<ScrollAreaHandle, ScrollAreaProps>(
|
|
|
1004
1013
|
};
|
|
1005
1014
|
|
|
1006
1015
|
return (
|
|
1007
|
-
<
|
|
1008
|
-
{
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
{/* Plain Animated.View carries the per-frame geometry (height/offset/
|
|
1033
|
-
inset); the inner Tamagui Thumb fills it and supplies colour/radius/
|
|
1034
|
-
`thumbProps`. Keeps reanimated off the styled component. */}
|
|
1035
|
-
<Animated.View
|
|
1036
|
-
style={[
|
|
1037
|
-
{ position: "absolute", top: 0, height: yBar.size },
|
|
1038
|
-
yThumbInsetStyle,
|
|
1039
|
-
yThumbStyle,
|
|
1040
|
-
]}
|
|
1016
|
+
<layerScope.Provider value={layerScope.register}>
|
|
1017
|
+
<ScrollAreaFrame onLayout={handleFrameLayout} {...rest}>
|
|
1018
|
+
{content}
|
|
1019
|
+
|
|
1020
|
+
{anyShadow && (
|
|
1021
|
+
<>
|
|
1022
|
+
{renderEdgeShadow("top")}
|
|
1023
|
+
{renderEdgeShadow("bottom")}
|
|
1024
|
+
{renderEdgeShadow("left")}
|
|
1025
|
+
{renderEdgeShadow("right")}
|
|
1026
|
+
</>
|
|
1027
|
+
)}
|
|
1028
|
+
|
|
1029
|
+
{axes.y && (
|
|
1030
|
+
<ScrollAreaScrollbar
|
|
1031
|
+
ref={yMove.ref}
|
|
1032
|
+
{...yMove.rootProps}
|
|
1033
|
+
top={0}
|
|
1034
|
+
right={0}
|
|
1035
|
+
bottom={hasCorner ? scrollbarSize : 0}
|
|
1036
|
+
width={scrollbarSize}
|
|
1037
|
+
opacity={showY ? 1 : 0}
|
|
1038
|
+
pointerEvents={showY ? "auto" : "none"}
|
|
1039
|
+
{...scopeTransition(fade, ANIMATE_OPACITY)}
|
|
1040
|
+
{...mergedScrollbarProps}
|
|
1041
1041
|
>
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1042
|
+
{/* Plain Animated.View carries the per-frame geometry (height/offset/
|
|
1043
|
+
inset); the inner Tamagui Thumb fills it and supplies colour/radius/
|
|
1044
|
+
`thumbProps`. Keeps reanimated off the styled component. */}
|
|
1045
|
+
<Animated.View
|
|
1046
|
+
style={[
|
|
1047
|
+
{ position: "absolute", top: 0, height: yBar.size },
|
|
1048
|
+
yThumbInsetStyle,
|
|
1049
|
+
yThumbStyle,
|
|
1050
|
+
]}
|
|
1051
|
+
>
|
|
1052
|
+
<ScrollAreaThumb top={0} left={0} right={0} bottom={0} {...mergedThumbProps} />
|
|
1053
|
+
</Animated.View>
|
|
1054
|
+
</ScrollAreaScrollbar>
|
|
1055
|
+
)}
|
|
1056
|
+
|
|
1057
|
+
{axes.x && (
|
|
1058
|
+
<ScrollAreaScrollbar
|
|
1059
|
+
ref={xMove.ref}
|
|
1060
|
+
{...xMove.rootProps}
|
|
1061
|
+
left={0}
|
|
1062
|
+
right={hasCorner ? scrollbarSize : 0}
|
|
1063
|
+
bottom={0}
|
|
1064
|
+
height={scrollbarSize}
|
|
1065
|
+
opacity={showX ? 1 : 0}
|
|
1066
|
+
pointerEvents={showX ? "auto" : "none"}
|
|
1067
|
+
{...scopeTransition(fade, ANIMATE_OPACITY)}
|
|
1068
|
+
{...mergedScrollbarProps}
|
|
1066
1069
|
>
|
|
1067
|
-
<
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1070
|
+
<Animated.View
|
|
1071
|
+
style={[
|
|
1072
|
+
{ position: "absolute", left: 0, width: xBar.size },
|
|
1073
|
+
xThumbInsetStyle,
|
|
1074
|
+
xThumbStyle,
|
|
1075
|
+
]}
|
|
1076
|
+
>
|
|
1077
|
+
<ScrollAreaThumb top={0} left={0} right={0} bottom={0} {...mergedThumbProps} />
|
|
1078
|
+
</Animated.View>
|
|
1079
|
+
</ScrollAreaScrollbar>
|
|
1080
|
+
)}
|
|
1081
|
+
|
|
1082
|
+
{hasCorner && (
|
|
1083
|
+
<ScrollAreaCorner
|
|
1084
|
+
width={scrollbarSize}
|
|
1085
|
+
height={scrollbarSize}
|
|
1086
|
+
opacity={showX && showY ? 1 : 0}
|
|
1087
|
+
{...scopeTransition(fade, ANIMATE_OPACITY)}
|
|
1088
|
+
{...mergedCornerProps}
|
|
1089
|
+
/>
|
|
1090
|
+
)}
|
|
1091
|
+
</ScrollAreaFrame>
|
|
1092
|
+
</layerScope.Provider>
|
|
1082
1093
|
);
|
|
1083
1094
|
},
|
|
1084
1095
|
);
|
|
@@ -175,6 +175,48 @@ type ScrollAreaFrameProps = Omit<GetProps<typeof ScrollAreaFrame>, "type" | "sha
|
|
|
175
175
|
|
|
176
176
|
export interface ScrollAreaProps extends ScrollAreaFrameProps, ScrollAreaOwnProps {}
|
|
177
177
|
|
|
178
|
+
/** ARIA roles whose widgets consume Space, Home/End or the arrow keys themselves. */
|
|
179
|
+
const KEY_OWNING_ROLES = new Set([
|
|
180
|
+
"button",
|
|
181
|
+
"checkbox",
|
|
182
|
+
"combobox",
|
|
183
|
+
"grid",
|
|
184
|
+
"listbox",
|
|
185
|
+
"menu",
|
|
186
|
+
"menubar",
|
|
187
|
+
"menuitem",
|
|
188
|
+
"menuitemcheckbox",
|
|
189
|
+
"menuitemradio",
|
|
190
|
+
"option",
|
|
191
|
+
"radio",
|
|
192
|
+
"radiogroup",
|
|
193
|
+
"scrollbar",
|
|
194
|
+
"searchbox",
|
|
195
|
+
"slider",
|
|
196
|
+
"spinbutton",
|
|
197
|
+
"switch",
|
|
198
|
+
"tab",
|
|
199
|
+
"tablist",
|
|
200
|
+
"textbox",
|
|
201
|
+
"tree",
|
|
202
|
+
"treegrid",
|
|
203
|
+
]);
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Whether a keydown target handles the scroll keys itself, so the viewport must
|
|
207
|
+
* not turn them into a scroll: native form controls, editable content, and ARIA
|
|
208
|
+
* widgets. The browser still applies its own default for these keys.
|
|
209
|
+
*/
|
|
210
|
+
function ownsScrollKeys(target: EventTarget | null): boolean {
|
|
211
|
+
if (!target || typeof (target as Element).closest !== "function") return false;
|
|
212
|
+
const el = target as HTMLElement;
|
|
213
|
+
if (el.isContentEditable) return true;
|
|
214
|
+
const tag = el.tagName;
|
|
215
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT" || tag === "BUTTON") return true;
|
|
216
|
+
const role = el.getAttribute("role");
|
|
217
|
+
return role !== null && KEY_OWNING_ROLES.has(role);
|
|
218
|
+
}
|
|
219
|
+
|
|
178
220
|
/* Local style narrowing for the web-only CSS props on the viewport element. */
|
|
179
221
|
type ViewportStyle = NonNullable<BoxProps["style"]> & {
|
|
180
222
|
overflowX?: "auto" | "hidden" | "scroll" | "visible";
|
|
@@ -771,7 +813,11 @@ const ScrollAreaComponent = React.forwardRef<ScrollAreaHandle, ScrollAreaProps>(
|
|
|
771
813
|
const handleKeyDown = React.useCallback(
|
|
772
814
|
(event: React.KeyboardEvent<HTMLElement>) => {
|
|
773
815
|
const node = viewportNodeRef.current as HTMLElement | null;
|
|
774
|
-
if (!node) return;
|
|
816
|
+
if (!node || event.defaultPrevented) return;
|
|
817
|
+
// Keys bubbling up from a field or widget inside the viewport belong to
|
|
818
|
+
// it (Space types a space, Home/End/arrows move the caret or the widget's
|
|
819
|
+
// selection). Leave them alone; a non-interactive descendant still scrolls.
|
|
820
|
+
if (event.target !== event.currentTarget && ownsScrollKeys(event.target)) return;
|
|
775
821
|
const delta = keyToScrollDelta(
|
|
776
822
|
event.key,
|
|
777
823
|
keyStep,
|
package/src/index.ts
CHANGED
|
@@ -37,10 +37,10 @@ export { Autocomplete, type AutocompleteProps, type AutocompleteRef } from "./Au
|
|
|
37
37
|
export {
|
|
38
38
|
Avatar,
|
|
39
39
|
type AvatarGroupProps,
|
|
40
|
-
getAvatarSize,
|
|
41
40
|
type AvatarProps,
|
|
42
41
|
type AvatarSize,
|
|
43
42
|
type AvatarVariant,
|
|
43
|
+
getAvatarSize,
|
|
44
44
|
} from "./Avatar";
|
|
45
45
|
// Media
|
|
46
46
|
export {
|
|
@@ -325,6 +325,8 @@ export {
|
|
|
325
325
|
type MenuTrigger,
|
|
326
326
|
} from "./Menu";
|
|
327
327
|
export {
|
|
328
|
+
type EscapeLayerOptions,
|
|
329
|
+
hasOpenEscapeLayer,
|
|
328
330
|
Modal,
|
|
329
331
|
type ModalBodyProps,
|
|
330
332
|
type ModalContentProps,
|
|
@@ -332,6 +334,7 @@ export {
|
|
|
332
334
|
type ModalProps,
|
|
333
335
|
type ModalSize,
|
|
334
336
|
type ModalTitleProps,
|
|
337
|
+
useEscapeLayer,
|
|
335
338
|
} from "./Modal";
|
|
336
339
|
|
|
337
340
|
export {
|
|
@@ -431,9 +434,13 @@ export {
|
|
|
431
434
|
type PortalProps,
|
|
432
435
|
PortalProvider,
|
|
433
436
|
type PortalProviderProps,
|
|
437
|
+
resolvePersistTaps,
|
|
434
438
|
ROOT_OVERLAY_HOST,
|
|
439
|
+
type TeleportedLayerScope,
|
|
435
440
|
useOverlayHost,
|
|
436
441
|
usePortal,
|
|
442
|
+
useRegisterTeleportedLayer,
|
|
443
|
+
useTeleportedLayerScope,
|
|
437
444
|
useTopmostOverlayHost,
|
|
438
445
|
} from "./Portal";
|
|
439
446
|
export {
|