@octanejs/stick-to-bottom 0.0.16 → 0.0.18
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/package.json +4 -4
- package/src/StickToBottom.tsrx +57 -49
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octanejs/stick-to-bottom",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "Octane binding for use-stick-to-bottom 1.1.6.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
"./package.json": "./package.json"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"octane": "^0.
|
|
43
|
+
"octane": "^0.11.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@octanejs/testing-library": "0.1.
|
|
47
|
-
"octane": "0.
|
|
46
|
+
"@octanejs/testing-library": "0.1.61",
|
|
47
|
+
"octane": "0.11.0",
|
|
48
48
|
"vitest": "^4.1.10"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
package/src/StickToBottom.tsrx
CHANGED
|
@@ -50,8 +50,7 @@ export interface StickToBottomProps extends Omit<DivProps, 'children'>, StickToB
|
|
|
50
50
|
children: ((context: StickToBottomContext) => OctaneNode) | OctaneNode;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
const useIsomorphicLayoutEffect =
|
|
54
|
-
typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
53
|
+
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
55
54
|
|
|
56
55
|
export function StickToBottom({
|
|
57
56
|
instance,
|
|
@@ -87,35 +86,34 @@ export function StickToBottom({
|
|
|
87
86
|
const { scrollRef, contentRef, scrollToBottom, stopScroll, isAtBottom, escapedFromLock, state } =
|
|
88
87
|
instance ?? defaultInstance;
|
|
89
88
|
|
|
90
|
-
const context = useMemo(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
isAtBottom,
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}, [context]);
|
|
89
|
+
const context = useMemo(
|
|
90
|
+
function createContextValue(): StickToBottomContext {
|
|
91
|
+
return {
|
|
92
|
+
scrollToBottom,
|
|
93
|
+
stopScroll,
|
|
94
|
+
scrollRef,
|
|
95
|
+
isAtBottom,
|
|
96
|
+
escapedFromLock,
|
|
97
|
+
contentRef,
|
|
98
|
+
state,
|
|
99
|
+
get targetScrollTop() {
|
|
100
|
+
return customTargetScrollTop.current;
|
|
101
|
+
},
|
|
102
|
+
set targetScrollTop(next: GetTargetScrollTop | null) {
|
|
103
|
+
customTargetScrollTop.current = next;
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
[scrollToBottom, isAtBottom, contentRef, scrollRef, stopScroll, escapedFromLock, state],
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
useImperativeHandle(
|
|
111
|
+
contextRef,
|
|
112
|
+
function getContext() {
|
|
113
|
+
return context;
|
|
114
|
+
},
|
|
115
|
+
[context],
|
|
116
|
+
);
|
|
119
117
|
|
|
120
118
|
useIsomorphicLayoutEffect(function ensureOverflow() {
|
|
121
119
|
if (!scrollRef.current) {
|
|
@@ -127,11 +125,15 @@ export function StickToBottom({
|
|
|
127
125
|
}
|
|
128
126
|
}, []);
|
|
129
127
|
|
|
130
|
-
return
|
|
131
|
-
<
|
|
132
|
-
{
|
|
133
|
-
|
|
134
|
-
|
|
128
|
+
return (
|
|
129
|
+
<StickToBottomContext value={context}>
|
|
130
|
+
<div {...props}>
|
|
131
|
+
{typeof children === 'function' && !isChildrenBlock(children)
|
|
132
|
+
? children(context)
|
|
133
|
+
: children}
|
|
134
|
+
</div>
|
|
135
|
+
</StickToBottomContext>
|
|
136
|
+
);
|
|
135
137
|
}
|
|
136
138
|
|
|
137
139
|
export interface StickToBottomContentProps extends Omit<DivProps, 'children'> {
|
|
@@ -146,19 +148,23 @@ export function StickToBottomContent({
|
|
|
146
148
|
}: StickToBottomContentProps) {
|
|
147
149
|
const context = useStickToBottomContext();
|
|
148
150
|
|
|
149
|
-
return
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
{
|
|
151
|
+
return (
|
|
152
|
+
<div
|
|
153
|
+
ref={context.scrollRef}
|
|
154
|
+
style={{
|
|
155
|
+
height: '100%',
|
|
156
|
+
width: '100%',
|
|
157
|
+
scrollbarGutter: 'stable both-edges',
|
|
158
|
+
}}
|
|
159
|
+
className={scrollClassName}
|
|
160
|
+
>
|
|
161
|
+
<div {...props} ref={context.contentRef}>
|
|
162
|
+
{typeof children === 'function' && !isChildrenBlock(children)
|
|
163
|
+
? children(context)
|
|
164
|
+
: children}
|
|
165
|
+
</div>
|
|
160
166
|
</div>
|
|
161
|
-
|
|
167
|
+
);
|
|
162
168
|
}
|
|
163
169
|
|
|
164
170
|
StickToBottom.Content = StickToBottomContent;
|
|
@@ -166,7 +172,9 @@ StickToBottom.Content = StickToBottomContent;
|
|
|
166
172
|
export function useStickToBottomContext(): StickToBottomContext {
|
|
167
173
|
const context = useContext(StickToBottomContext);
|
|
168
174
|
if (!context) {
|
|
169
|
-
throw new Error(
|
|
175
|
+
throw new Error(
|
|
176
|
+
'use-stick-to-bottom component context must be used within a StickToBottom component',
|
|
177
|
+
);
|
|
170
178
|
}
|
|
171
179
|
|
|
172
180
|
return context;
|