panelui-native 0.6.0 → 0.7.0
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 +1 -1
- package/lib/module/components/accordion/index.js +7 -5
- package/lib/module/components/accordion/index.js.map +1 -1
- package/lib/module/components/alert/index.js +3 -6
- package/lib/module/components/alert/index.js.map +1 -1
- package/lib/module/components/bottom-sheet/index.js +67 -3
- package/lib/module/components/bottom-sheet/index.js.map +1 -1
- package/lib/module/components/button/index.js +36 -1
- package/lib/module/components/button/index.js.map +1 -1
- package/lib/module/components/empty-state/index.js +4 -5
- package/lib/module/components/empty-state/index.js.map +1 -1
- package/lib/module/components/inline-select/index.js +171 -46
- package/lib/module/components/inline-select/index.js.map +1 -1
- package/lib/module/components/input/index.js +28 -5
- package/lib/module/components/input/index.js.map +1 -1
- package/lib/module/components/input-group/index.js +0 -1
- package/lib/module/components/input-group/index.js.map +1 -1
- package/lib/module/components/item/index.js +359 -0
- package/lib/module/components/item/index.js.map +1 -0
- package/lib/module/components/label/index.js +5 -3
- package/lib/module/components/label/index.js.map +1 -1
- package/lib/module/components/message/index.js +318 -0
- package/lib/module/components/message/index.js.map +1 -0
- package/lib/module/components/scroll-fade/index.js +119 -71
- package/lib/module/components/scroll-fade/index.js.map +1 -1
- package/lib/module/components/select/index.js +35 -6
- package/lib/module/components/select/index.js.map +1 -1
- package/lib/module/components/shimmer/index.js +111 -64
- package/lib/module/components/shimmer/index.js.map +1 -1
- package/lib/module/components/surface/index.js +3 -2
- package/lib/module/components/surface/index.js.map +1 -1
- package/lib/module/components/switch/index.js +20 -1
- package/lib/module/components/switch/index.js.map +1 -1
- package/lib/module/components/toast/index.js +7 -8
- package/lib/module/components/toast/index.js.map +1 -1
- package/lib/module/components/typography/index.js +3 -3
- package/lib/module/hooks/index.js +1 -0
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/hooks/use-breakpoint.js +2 -2
- package/lib/module/hooks/use-copy-to-clipboard.js +0 -2
- package/lib/module/hooks/use-copy-to-clipboard.js.map +1 -1
- package/lib/module/hooks/use-keyboard-avoidance.js +120 -0
- package/lib/module/hooks/use-keyboard-avoidance.js.map +1 -0
- package/lib/module/icons/index.js +4 -4
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/native/index.js +53 -0
- package/lib/module/native/index.js.map +1 -0
- package/lib/module/primitives/keyboard-avoider.js +40 -0
- package/lib/module/primitives/keyboard-avoider.js.map +1 -0
- package/lib/module/providers/panel-ui-provider.js +24 -4
- package/lib/module/providers/panel-ui-provider.js.map +1 -1
- package/lib/module/theme/use-theme.js +1 -1
- package/lib/typescript/src/components/accordion/index.d.ts +7 -5
- package/lib/typescript/src/components/accordion/index.d.ts.map +1 -1
- package/lib/typescript/src/components/alert/index.d.ts +3 -6
- package/lib/typescript/src/components/alert/index.d.ts.map +1 -1
- package/lib/typescript/src/components/bottom-sheet/index.d.ts +21 -1
- package/lib/typescript/src/components/bottom-sheet/index.d.ts.map +1 -1
- package/lib/typescript/src/components/button/index.d.ts +11 -0
- package/lib/typescript/src/components/button/index.d.ts.map +1 -1
- package/lib/typescript/src/components/empty-state/index.d.ts +4 -5
- package/lib/typescript/src/components/empty-state/index.d.ts.map +1 -1
- package/lib/typescript/src/components/inline-select/index.d.ts +29 -6
- package/lib/typescript/src/components/inline-select/index.d.ts.map +1 -1
- package/lib/typescript/src/components/input/index.d.ts +13 -0
- package/lib/typescript/src/components/input/index.d.ts.map +1 -1
- package/lib/typescript/src/components/input-group/index.d.ts +0 -1
- package/lib/typescript/src/components/input-group/index.d.ts.map +1 -1
- package/lib/typescript/src/components/item/index.d.ts +286 -0
- package/lib/typescript/src/components/item/index.d.ts.map +1 -0
- package/lib/typescript/src/components/label/index.d.ts +5 -3
- package/lib/typescript/src/components/label/index.d.ts.map +1 -1
- package/lib/typescript/src/components/message/index.d.ts +170 -0
- package/lib/typescript/src/components/message/index.d.ts.map +1 -0
- package/lib/typescript/src/components/scroll-fade/index.d.ts +18 -9
- package/lib/typescript/src/components/scroll-fade/index.d.ts.map +1 -1
- package/lib/typescript/src/components/select/index.d.ts +16 -1
- package/lib/typescript/src/components/select/index.d.ts.map +1 -1
- package/lib/typescript/src/components/shimmer/index.d.ts +38 -20
- package/lib/typescript/src/components/shimmer/index.d.ts.map +1 -1
- package/lib/typescript/src/components/surface/index.d.ts.map +1 -1
- package/lib/typescript/src/components/switch/index.d.ts +10 -0
- package/lib/typescript/src/components/switch/index.d.ts.map +1 -1
- package/lib/typescript/src/components/toast/index.d.ts +4 -4
- package/lib/typescript/src/components/toast/index.d.ts.map +1 -1
- package/lib/typescript/src/hooks/index.d.ts +1 -0
- package/lib/typescript/src/hooks/index.d.ts.map +1 -1
- package/lib/typescript/src/hooks/use-breakpoint.d.ts +2 -2
- package/lib/typescript/src/hooks/use-copy-to-clipboard.d.ts +0 -2
- package/lib/typescript/src/hooks/use-copy-to-clipboard.d.ts.map +1 -1
- package/lib/typescript/src/hooks/use-keyboard-avoidance.d.ts +20 -0
- package/lib/typescript/src/hooks/use-keyboard-avoidance.d.ts.map +1 -0
- package/lib/typescript/src/icons/index.d.ts +4 -4
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/native/index.d.ts +35 -0
- package/lib/typescript/src/native/index.d.ts.map +1 -0
- package/lib/typescript/src/primitives/keyboard-avoider.d.ts +22 -0
- package/lib/typescript/src/primitives/keyboard-avoider.d.ts.map +1 -0
- package/lib/typescript/src/providers/panel-ui-provider.d.ts +1 -1
- package/lib/typescript/src/providers/panel-ui-provider.d.ts.map +1 -1
- package/lib/typescript/src/theme/use-theme.d.ts +1 -1
- package/package.json +12 -3
- package/src/components/accordion/index.tsx +7 -5
- package/src/components/alert/index.tsx +3 -6
- package/src/components/bottom-sheet/index.tsx +82 -2
- package/src/components/button/index.tsx +52 -0
- package/src/components/empty-state/index.tsx +4 -5
- package/src/components/inline-select/index.tsx +191 -44
- package/src/components/input/index.tsx +39 -3
- package/src/components/input-group/index.tsx +0 -1
- package/src/components/item/index.tsx +387 -0
- package/src/components/label/index.tsx +5 -3
- package/src/components/message/index.tsx +312 -0
- package/src/components/scroll-fade/index.tsx +163 -51
- package/src/components/select/index.tsx +54 -9
- package/src/components/shimmer/index.tsx +151 -58
- package/src/components/surface/index.tsx +3 -2
- package/src/components/switch/index.tsx +27 -1
- package/src/components/toast/index.tsx +7 -8
- package/src/components/typography/index.tsx +3 -3
- package/src/hooks/index.ts +5 -0
- package/src/hooks/use-breakpoint.ts +2 -2
- package/src/hooks/use-copy-to-clipboard.ts +0 -2
- package/src/hooks/use-keyboard-avoidance.ts +140 -0
- package/src/icons/index.tsx +4 -4
- package/src/index.ts +32 -0
- package/src/native/index.ts +79 -0
- package/src/primitives/keyboard-avoider.tsx +49 -0
- package/src/providers/panel-ui-provider.tsx +30 -9
- package/src/theme/use-theme.ts +1 -1
- package/theme.css +5 -3
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Message — a chat turn: avatar, bubble, and the metadata around it.
|
|
5
|
+
*
|
|
6
|
+
* The pieces are separate because conversations differ in which ones they
|
|
7
|
+
* need. A support thread wants a sender name and a read receipt; an assistant
|
|
8
|
+
* transcript wants neither, but does want the bubble to carry tool output and
|
|
9
|
+
* actions. Composing them beats a component with a dozen optional props.
|
|
10
|
+
*
|
|
11
|
+
* `align` is the only thing the root decides, and everything downstream reads
|
|
12
|
+
* it from context: which side the row sits on, which way the avatar goes,
|
|
13
|
+
* which corner of the bubble is squared off, and which colour it takes.
|
|
14
|
+
*
|
|
15
|
+
* ```tsx
|
|
16
|
+
* <Message align="end">
|
|
17
|
+
* <Message.Content>
|
|
18
|
+
* <Message.Bubble>
|
|
19
|
+
* <Message.BubbleContent>How can I help?</Message.BubbleContent>
|
|
20
|
+
* </Message.Bubble>
|
|
21
|
+
* </Message.Content>
|
|
22
|
+
* </Message>
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
import { Children, cloneElement, createContext, forwardRef, isValidElement, useContext } from 'react';
|
|
26
|
+
import { View } from 'react-native';
|
|
27
|
+
import { tv } from 'tailwind-variants';
|
|
28
|
+
import { Text } from "../../primitives/text.js";
|
|
29
|
+
import { cn } from "../../utils/cn.js";
|
|
30
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
31
|
+
const messageVariants = tv({
|
|
32
|
+
slots: {
|
|
33
|
+
root: 'w-full flex-row items-end gap-2',
|
|
34
|
+
avatar: 'shrink-0',
|
|
35
|
+
content: 'max-w-[85%] gap-1',
|
|
36
|
+
header: 'text-xs font-medium text-muted-foreground',
|
|
37
|
+
bubble: 'rounded-2xl px-3.5 py-2.5',
|
|
38
|
+
bubbleContent: 'text-base',
|
|
39
|
+
footer: 'text-xs text-muted-foreground',
|
|
40
|
+
group: 'w-full gap-1'
|
|
41
|
+
},
|
|
42
|
+
variants: {
|
|
43
|
+
align: {
|
|
44
|
+
start: {
|
|
45
|
+
root: 'flex-row justify-start',
|
|
46
|
+
content: 'items-start',
|
|
47
|
+
// A squared corner on the side the message comes from points the
|
|
48
|
+
// bubble back at its sender.
|
|
49
|
+
bubble: 'rounded-bl-md bg-muted',
|
|
50
|
+
bubbleContent: 'text-foreground',
|
|
51
|
+
header: 'text-left',
|
|
52
|
+
footer: 'text-left'
|
|
53
|
+
},
|
|
54
|
+
end: {
|
|
55
|
+
root: 'flex-row-reverse justify-start',
|
|
56
|
+
content: 'items-end',
|
|
57
|
+
bubble: 'rounded-br-md bg-primary',
|
|
58
|
+
bubbleContent: 'text-primary-foreground',
|
|
59
|
+
header: 'text-right',
|
|
60
|
+
footer: 'text-right'
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
defaultVariants: {
|
|
65
|
+
align: 'start'
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
const MessageContext = /*#__PURE__*/createContext({
|
|
69
|
+
align: 'start',
|
|
70
|
+
stacked: false
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
/** Reads the alignment set by the nearest Message. */
|
|
74
|
+
function useMessageContext() {
|
|
75
|
+
return useContext(MessageContext);
|
|
76
|
+
}
|
|
77
|
+
const GroupContext = /*#__PURE__*/createContext(null);
|
|
78
|
+
const MessageRoot = /*#__PURE__*/forwardRef(({
|
|
79
|
+
className,
|
|
80
|
+
align,
|
|
81
|
+
stacked = false,
|
|
82
|
+
children,
|
|
83
|
+
...props
|
|
84
|
+
}, ref) => {
|
|
85
|
+
const group = useContext(GroupContext);
|
|
86
|
+
const resolvedAlign = align ?? group?.align ?? 'start';
|
|
87
|
+
const {
|
|
88
|
+
root
|
|
89
|
+
} = messageVariants({
|
|
90
|
+
align: resolvedAlign
|
|
91
|
+
});
|
|
92
|
+
return /*#__PURE__*/_jsx(MessageContext.Provider, {
|
|
93
|
+
value: {
|
|
94
|
+
align: resolvedAlign,
|
|
95
|
+
stacked
|
|
96
|
+
},
|
|
97
|
+
children: /*#__PURE__*/_jsx(View, {
|
|
98
|
+
ref: ref,
|
|
99
|
+
className: root({
|
|
100
|
+
className
|
|
101
|
+
}),
|
|
102
|
+
...props,
|
|
103
|
+
children: children
|
|
104
|
+
})
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
MessageRoot.displayName = 'Message';
|
|
108
|
+
/**
|
|
109
|
+
* Consecutive turns from one sender. Tightens the spacing between them and
|
|
110
|
+
* marks every message after the first as `stacked`, so only the first shows an
|
|
111
|
+
* avatar and the rest stay aligned with it.
|
|
112
|
+
*/
|
|
113
|
+
const MessageGroup = /*#__PURE__*/forwardRef(({
|
|
114
|
+
className,
|
|
115
|
+
align = 'start',
|
|
116
|
+
children,
|
|
117
|
+
...props
|
|
118
|
+
}, ref) => {
|
|
119
|
+
const {
|
|
120
|
+
group
|
|
121
|
+
} = messageVariants({
|
|
122
|
+
align
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// Every turn after the first is a continuation, so it drops its avatar and
|
|
126
|
+
// sits tight against the one above. A child that sets `stacked` itself
|
|
127
|
+
// wins — grouping is a default, not a rule.
|
|
128
|
+
const stackedChildren = Children.map(children, (child, index) => /*#__PURE__*/isValidElement(child) && child.props.stacked === undefined ? /*#__PURE__*/cloneElement(child, {
|
|
129
|
+
stacked: index > 0
|
|
130
|
+
}) : child);
|
|
131
|
+
return /*#__PURE__*/_jsx(GroupContext.Provider, {
|
|
132
|
+
value: {
|
|
133
|
+
align
|
|
134
|
+
},
|
|
135
|
+
children: /*#__PURE__*/_jsx(View, {
|
|
136
|
+
ref: ref,
|
|
137
|
+
className: group({
|
|
138
|
+
className
|
|
139
|
+
}),
|
|
140
|
+
...props,
|
|
141
|
+
children: stackedChildren
|
|
142
|
+
})
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
MessageGroup.displayName = 'Message.Group';
|
|
146
|
+
/**
|
|
147
|
+
* Slot for the sender's avatar. On a stacked message the slot is rendered but
|
|
148
|
+
* left empty, which keeps the bubbles in a column instead of letting the
|
|
149
|
+
* second one slide under the first one's avatar.
|
|
150
|
+
*/
|
|
151
|
+
const MessageAvatar = /*#__PURE__*/forwardRef(({
|
|
152
|
+
className,
|
|
153
|
+
children,
|
|
154
|
+
...props
|
|
155
|
+
}, ref) => {
|
|
156
|
+
const {
|
|
157
|
+
stacked
|
|
158
|
+
} = useMessageContext();
|
|
159
|
+
const {
|
|
160
|
+
avatar
|
|
161
|
+
} = messageVariants();
|
|
162
|
+
return /*#__PURE__*/_jsx(View, {
|
|
163
|
+
ref: ref,
|
|
164
|
+
className: avatar({
|
|
165
|
+
className
|
|
166
|
+
}),
|
|
167
|
+
...props,
|
|
168
|
+
children: stacked ? /*#__PURE__*/_jsx(View, {
|
|
169
|
+
className: "opacity-0",
|
|
170
|
+
children: children
|
|
171
|
+
}) : children
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
MessageAvatar.displayName = 'Message.Avatar';
|
|
175
|
+
/** Column holding the header, bubble and footer. */
|
|
176
|
+
const MessageContent = /*#__PURE__*/forwardRef(({
|
|
177
|
+
className,
|
|
178
|
+
children,
|
|
179
|
+
...props
|
|
180
|
+
}, ref) => {
|
|
181
|
+
const {
|
|
182
|
+
align
|
|
183
|
+
} = useMessageContext();
|
|
184
|
+
const {
|
|
185
|
+
content
|
|
186
|
+
} = messageVariants({
|
|
187
|
+
align
|
|
188
|
+
});
|
|
189
|
+
return /*#__PURE__*/_jsx(View, {
|
|
190
|
+
ref: ref,
|
|
191
|
+
className: content({
|
|
192
|
+
className
|
|
193
|
+
}),
|
|
194
|
+
...props,
|
|
195
|
+
children: children
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
MessageContent.displayName = 'Message.Content';
|
|
199
|
+
/** Sender name or timestamp above the bubble. */
|
|
200
|
+
const MessageHeader = /*#__PURE__*/forwardRef(({
|
|
201
|
+
className,
|
|
202
|
+
...props
|
|
203
|
+
}, ref) => {
|
|
204
|
+
const {
|
|
205
|
+
align
|
|
206
|
+
} = useMessageContext();
|
|
207
|
+
const {
|
|
208
|
+
header
|
|
209
|
+
} = messageVariants({
|
|
210
|
+
align
|
|
211
|
+
});
|
|
212
|
+
return /*#__PURE__*/_jsx(Text, {
|
|
213
|
+
ref: ref,
|
|
214
|
+
size: "xs",
|
|
215
|
+
className: header({
|
|
216
|
+
className
|
|
217
|
+
}),
|
|
218
|
+
...props
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
MessageHeader.displayName = 'Message.Header';
|
|
222
|
+
/** The speech bubble. Takes its colour and squared corner from `align`. */
|
|
223
|
+
const MessageBubble = /*#__PURE__*/forwardRef(({
|
|
224
|
+
className,
|
|
225
|
+
children,
|
|
226
|
+
...props
|
|
227
|
+
}, ref) => {
|
|
228
|
+
const {
|
|
229
|
+
align
|
|
230
|
+
} = useMessageContext();
|
|
231
|
+
const {
|
|
232
|
+
bubble
|
|
233
|
+
} = messageVariants({
|
|
234
|
+
align
|
|
235
|
+
});
|
|
236
|
+
return /*#__PURE__*/_jsx(View, {
|
|
237
|
+
ref: ref,
|
|
238
|
+
className: bubble({
|
|
239
|
+
className
|
|
240
|
+
}),
|
|
241
|
+
...props,
|
|
242
|
+
children: children
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
MessageBubble.displayName = 'Message.Bubble';
|
|
246
|
+
/** Text inside the bubble, in whichever colour reads against it. */
|
|
247
|
+
const MessageBubbleContent = /*#__PURE__*/forwardRef(({
|
|
248
|
+
className,
|
|
249
|
+
...props
|
|
250
|
+
}, ref) => {
|
|
251
|
+
const {
|
|
252
|
+
align
|
|
253
|
+
} = useMessageContext();
|
|
254
|
+
const {
|
|
255
|
+
bubbleContent
|
|
256
|
+
} = messageVariants({
|
|
257
|
+
align
|
|
258
|
+
});
|
|
259
|
+
return /*#__PURE__*/_jsx(Text, {
|
|
260
|
+
ref: ref,
|
|
261
|
+
className: bubbleContent({
|
|
262
|
+
className
|
|
263
|
+
}),
|
|
264
|
+
...props
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
MessageBubbleContent.displayName = 'Message.BubbleContent';
|
|
268
|
+
/** Delivery state, timestamp or actions below the bubble. */
|
|
269
|
+
const MessageFooter = /*#__PURE__*/forwardRef(({
|
|
270
|
+
className,
|
|
271
|
+
...props
|
|
272
|
+
}, ref) => {
|
|
273
|
+
const {
|
|
274
|
+
align
|
|
275
|
+
} = useMessageContext();
|
|
276
|
+
const {
|
|
277
|
+
footer
|
|
278
|
+
} = messageVariants({
|
|
279
|
+
align
|
|
280
|
+
});
|
|
281
|
+
return /*#__PURE__*/_jsx(Text, {
|
|
282
|
+
ref: ref,
|
|
283
|
+
size: "xs",
|
|
284
|
+
className: footer({
|
|
285
|
+
className
|
|
286
|
+
}),
|
|
287
|
+
...props
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
MessageFooter.displayName = 'Message.Footer';
|
|
291
|
+
/** Row of controls under the bubble — copy, retry, feedback. */
|
|
292
|
+
const MessageActions = /*#__PURE__*/forwardRef(({
|
|
293
|
+
className,
|
|
294
|
+
children,
|
|
295
|
+
...props
|
|
296
|
+
}, ref) => {
|
|
297
|
+
const {
|
|
298
|
+
align
|
|
299
|
+
} = useMessageContext();
|
|
300
|
+
return /*#__PURE__*/_jsx(View, {
|
|
301
|
+
ref: ref,
|
|
302
|
+
className: cn('flex-row items-center gap-1', align === 'end' && 'flex-row-reverse', className),
|
|
303
|
+
...props,
|
|
304
|
+
children: children
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
MessageActions.displayName = 'Message.Actions';
|
|
308
|
+
export const Message = Object.assign(MessageRoot, {
|
|
309
|
+
Group: MessageGroup,
|
|
310
|
+
Avatar: MessageAvatar,
|
|
311
|
+
Content: MessageContent,
|
|
312
|
+
Header: MessageHeader,
|
|
313
|
+
Bubble: MessageBubble,
|
|
314
|
+
BubbleContent: MessageBubbleContent,
|
|
315
|
+
Footer: MessageFooter,
|
|
316
|
+
Actions: MessageActions
|
|
317
|
+
});
|
|
318
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Children","cloneElement","createContext","forwardRef","isValidElement","useContext","View","tv","Text","cn","jsx","_jsx","messageVariants","slots","root","avatar","content","header","bubble","bubbleContent","footer","group","variants","align","start","end","defaultVariants","MessageContext","stacked","useMessageContext","GroupContext","MessageRoot","className","children","props","ref","resolvedAlign","Provider","value","displayName","MessageGroup","stackedChildren","map","child","index","undefined","MessageAvatar","MessageContent","MessageHeader","size","MessageBubble","MessageBubbleContent","MessageFooter","MessageActions","Message","Object","assign","Group","Avatar","Content","Header","Bubble","BubbleContent","Footer","Actions"],"sourceRoot":"../../../../src","sources":["components/message/index.tsx"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SACEA,QAAQ,EACRC,YAA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X,6BAA6B,EAC7Bc,KAAK,KAAK,KAAK,IAAI,kBAAkB,EACrCS,SACF,CAAE;IAAA,GACEE,KAAK;IAAAD,QAAA,EAERA;EAAQ,CACL,CAAC;AAEX,CACF,CAAC;AACDoB,cAAc,CAACd,WAAW,GAAG,iBAAiB;AAE9C,OAAO,MAAMe,OAAO,GAAGC,MAAM,CAACC,MAAM,CAACzB,WAAW,EAAE;EAChD0B,KAAK,EAAEjB,YAAY;EACnBkB,MAAM,EAAEZ,aAAa;EACrBa,OAAO,EAAEZ,cAAc;EACvBa,MAAM,EAAEZ,aAAa;EACrBa,MAAM,EAAEX,aAAa;EACrBY,aAAa,EAAEX,oBAAoB;EACnCY,MAAM,EAAEX,aAAa;EACrBY,OAAO,EAAEX;AACX,CAAC,CAAC","ignoreList":[]}
|
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* ScrollFade — fades the edges of a scroll container.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* timelines, so the fades are SVG gradients overlaid on each edge, with their
|
|
10
|
-
* opacity following the scroll position.
|
|
6
|
+
* Content that runs past a boundary reads better fading out than being cut
|
|
7
|
+
* off, and the fade doubles as an affordance: an edge that is fading is an
|
|
8
|
+
* edge with more content behind it.
|
|
11
9
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* Scroll position, content size and viewport size are all held in shared
|
|
11
|
+
* values and consumed by `useAnimatedStyle`, so the fades track the scroll on
|
|
12
|
+
* the UI thread without re-rendering React.
|
|
14
13
|
*
|
|
15
14
|
* ```tsx
|
|
16
15
|
* <ScrollFade>
|
|
@@ -18,61 +17,101 @@
|
|
|
18
17
|
* </ScrollFade>
|
|
19
18
|
* ```
|
|
20
19
|
*/
|
|
21
|
-
import { Children,
|
|
22
|
-
import { View } from 'react-native';
|
|
23
|
-
import
|
|
20
|
+
import { Children, isValidElement, useMemo } from 'react';
|
|
21
|
+
import { StyleSheet, View } from 'react-native';
|
|
22
|
+
import { LinearGradient } from 'expo-linear-gradient';
|
|
23
|
+
import Animated, { useAnimatedScrollHandler, useAnimatedStyle, useComposedEventHandler, useDerivedValue, useSharedValue } from 'react-native-reanimated';
|
|
24
24
|
import { useCSSVariable } from 'uniwind';
|
|
25
25
|
|
|
26
26
|
/** Past this many pixels from an edge, that edge's fade is fully shown. */
|
|
27
27
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
28
|
-
const
|
|
28
|
+
const DEFAULT_FADE_IN_DISTANCE = 24;
|
|
29
29
|
export function ScrollFade({
|
|
30
30
|
className,
|
|
31
31
|
size = 48,
|
|
32
32
|
edges = 'both',
|
|
33
|
+
orientation,
|
|
33
34
|
color,
|
|
35
|
+
fadeInDistance = DEFAULT_FADE_IN_DISTANCE,
|
|
36
|
+
enabled = true,
|
|
34
37
|
children,
|
|
35
38
|
...props
|
|
36
39
|
}) {
|
|
37
|
-
const
|
|
38
|
-
const
|
|
40
|
+
const offset = useSharedValue(0);
|
|
41
|
+
const contentLength = useSharedValue(0);
|
|
42
|
+
const viewportLength = useSharedValue(0);
|
|
39
43
|
const themeBackground = useCSSVariable('--color-background');
|
|
40
44
|
const fadeColor = color ?? (typeof themeBackground === 'string' ? themeBackground : '#000000');
|
|
41
45
|
const child = Children.only(children);
|
|
42
|
-
const horizontal = /*#__PURE__*/isValidElement(child)
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
const horizontal = orientation !== undefined ? orientation === 'horizontal' : /*#__PURE__*/isValidElement(child) && !!child.props.horizontal;
|
|
47
|
+
|
|
48
|
+
// Reanimated can only drive a scroll handler on an animated component, and
|
|
49
|
+
// `Animated.ScrollView` is not necessarily what was passed in — the child may
|
|
50
|
+
// be a FlatList, a SectionList or a custom scrollable. Keyed on the element
|
|
51
|
+
// *type*, not the element: rebuilding the wrapper would remount the list.
|
|
52
|
+
const childType = /*#__PURE__*/isValidElement(child) ? child.type : null;
|
|
53
|
+
const AnimatedScrollable = useMemo(() => childType ? Animated.createAnimatedComponent(childType) : null, [childType]);
|
|
54
|
+
const scrollHandler = useAnimatedScrollHandler({
|
|
55
|
+
onScroll: event => {
|
|
56
|
+
const {
|
|
57
|
+
contentOffset,
|
|
58
|
+
contentSize,
|
|
59
|
+
layoutMeasurement
|
|
60
|
+
} = event;
|
|
61
|
+
offset.value = horizontal ? contentOffset.x : contentOffset.y;
|
|
62
|
+
contentLength.value = horizontal ? contentSize.width : contentSize.height;
|
|
63
|
+
viewportLength.value = horizontal ? layoutMeasurement.width : layoutMeasurement.height;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
53
66
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
67
|
+
// A consumer `onScroll` is composed rather than dropped — but because the
|
|
68
|
+
// child is now an animated component it has to be an animated handler too.
|
|
69
|
+
const onScroll = useComposedEventHandler([scrollHandler, child.props.onScroll ?? null]);
|
|
70
|
+
|
|
71
|
+
// Measured up front as well as on scroll, so an end edge with content behind
|
|
72
|
+
// it fades from the first frame rather than waiting for a scroll event.
|
|
73
|
+
const onLayout = event => {
|
|
74
|
+
const {
|
|
75
|
+
width,
|
|
76
|
+
height
|
|
77
|
+
} = event.nativeEvent.layout;
|
|
78
|
+
viewportLength.value = horizontal ? width : height;
|
|
79
|
+
child.props.onLayout?.(event);
|
|
80
|
+
};
|
|
81
|
+
const onContentSizeChange = (width, height) => {
|
|
82
|
+
contentLength.value = horizontal ? width : height;
|
|
83
|
+
child.props.onContentSizeChange?.(width, height);
|
|
59
84
|
};
|
|
60
|
-
const
|
|
61
|
-
|
|
85
|
+
const startOpacity = useDerivedValue(() => Math.min(offset.value / fadeInDistance, 1));
|
|
86
|
+
const endOpacity = useDerivedValue(() => {
|
|
87
|
+
// Nothing to fade towards when the content fits inside the viewport.
|
|
88
|
+
const remaining = contentLength.value - viewportLength.value - offset.value;
|
|
89
|
+
return Math.min(Math.max(remaining, 0) / fadeInDistance, 1);
|
|
90
|
+
});
|
|
91
|
+
const scrollable = AnimatedScrollable && /*#__PURE__*/isValidElement(child) ? /*#__PURE__*/_jsx(AnimatedScrollable, {
|
|
92
|
+
...child.props,
|
|
93
|
+
onScroll: onScroll,
|
|
94
|
+
onLayout: onLayout,
|
|
95
|
+
onContentSizeChange: onContentSizeChange,
|
|
62
96
|
scrollEventThrottle: child.props.scrollEventThrottle ?? 16
|
|
63
97
|
}) : child;
|
|
64
|
-
|
|
65
|
-
|
|
98
|
+
if (!enabled || edges === 'none') {
|
|
99
|
+
return /*#__PURE__*/_jsx(View, {
|
|
100
|
+
...props,
|
|
101
|
+
className: className,
|
|
102
|
+
children: scrollable
|
|
103
|
+
});
|
|
104
|
+
}
|
|
66
105
|
return /*#__PURE__*/_jsxs(View, {
|
|
67
106
|
...props,
|
|
68
107
|
className: className,
|
|
69
|
-
children: [scrollable,
|
|
108
|
+
children: [scrollable, edges !== 'end' ? /*#__PURE__*/_jsx(Fade, {
|
|
70
109
|
color: fadeColor,
|
|
71
110
|
size: size,
|
|
72
111
|
horizontal: horizontal,
|
|
73
112
|
opacity: startOpacity,
|
|
74
113
|
edge: "start"
|
|
75
|
-
}) : null,
|
|
114
|
+
}) : null, edges !== 'start' ? /*#__PURE__*/_jsx(Fade, {
|
|
76
115
|
color: fadeColor,
|
|
77
116
|
size: size,
|
|
78
117
|
horizontal: horizontal,
|
|
@@ -92,7 +131,6 @@ function Fade({
|
|
|
92
131
|
edge
|
|
93
132
|
}) {
|
|
94
133
|
const isStart = edge === 'start';
|
|
95
|
-
const id = `scroll-fade-${edge}-${horizontal ? 'x' : 'y'}`;
|
|
96
134
|
const position = horizontal ? {
|
|
97
135
|
top: 0,
|
|
98
136
|
bottom: 0,
|
|
@@ -112,45 +150,55 @@ function Fade({
|
|
|
112
150
|
bottom: 0
|
|
113
151
|
})
|
|
114
152
|
};
|
|
153
|
+
const style = useAnimatedStyle(() => ({
|
|
154
|
+
opacity: opacity.value
|
|
155
|
+
}));
|
|
115
156
|
|
|
116
|
-
// The gradient runs from the
|
|
157
|
+
// The gradient runs from the edge inwards, so its stops are reversed on the
|
|
117
158
|
// end edge.
|
|
118
|
-
const
|
|
119
|
-
return /*#__PURE__*/_jsx(View, {
|
|
159
|
+
const colors = isStart ? [withAlpha(color, 1), withAlpha(color, 0)] : [withAlpha(color, 0), withAlpha(color, 1)];
|
|
160
|
+
return /*#__PURE__*/_jsx(Animated.View, {
|
|
120
161
|
pointerEvents: "none",
|
|
121
|
-
style: {
|
|
122
|
-
position: 'absolute'
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
stopColor: color,
|
|
139
|
-
stopOpacity: isStart ? 1 : 0
|
|
140
|
-
}), /*#__PURE__*/_jsx(Stop, {
|
|
141
|
-
offset: "1",
|
|
142
|
-
stopColor: color,
|
|
143
|
-
stopOpacity: isStart ? 0 : 1
|
|
144
|
-
})]
|
|
145
|
-
})
|
|
146
|
-
}), /*#__PURE__*/_jsx(Rect, {
|
|
147
|
-
x: "0",
|
|
148
|
-
y: "0",
|
|
149
|
-
width: "100%",
|
|
150
|
-
height: "100%",
|
|
151
|
-
fill: `url(#${id})`
|
|
152
|
-
})]
|
|
162
|
+
style: [{
|
|
163
|
+
position: 'absolute'
|
|
164
|
+
}, position, style],
|
|
165
|
+
children: /*#__PURE__*/_jsx(LinearGradient, {
|
|
166
|
+
colors: colors,
|
|
167
|
+
start: {
|
|
168
|
+
x: 0,
|
|
169
|
+
y: 0
|
|
170
|
+
},
|
|
171
|
+
end: horizontal ? {
|
|
172
|
+
x: 1,
|
|
173
|
+
y: 0
|
|
174
|
+
} : {
|
|
175
|
+
x: 0,
|
|
176
|
+
y: 1
|
|
177
|
+
},
|
|
178
|
+
style: StyleSheet.absoluteFill
|
|
153
179
|
})
|
|
154
180
|
});
|
|
155
181
|
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Gradients need a transparent stop of the *same* colour — `transparent` is
|
|
185
|
+
* black at zero alpha on Android, which shows as a grey smear.
|
|
186
|
+
*/
|
|
187
|
+
function withAlpha(color, alpha) {
|
|
188
|
+
if (color.startsWith('#')) {
|
|
189
|
+
const hex = color.slice(1);
|
|
190
|
+
const full = hex.length === 3 ? hex.split('').map(c => c + c).join('') : hex.slice(0, 6);
|
|
191
|
+
const r = parseInt(full.slice(0, 2), 16);
|
|
192
|
+
const g = parseInt(full.slice(2, 4), 16);
|
|
193
|
+
const b = parseInt(full.slice(4, 6), 16);
|
|
194
|
+
if (Number.isNaN(r + g + b)) return color;
|
|
195
|
+
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
196
|
+
}
|
|
197
|
+
const channels = color.match(/rgba?\(([^)]+)\)/)?.[1];
|
|
198
|
+
if (channels) {
|
|
199
|
+
const [r, g, b] = channels.split(',').map(part => part.trim());
|
|
200
|
+
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
201
|
+
}
|
|
202
|
+
return color;
|
|
203
|
+
}
|
|
156
204
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Children","
|
|
1
|
+
{"version":3,"names":["Children","isValidElement","useMemo","StyleSheet","View","LinearGradient","Animated","useAnimatedScrollHandler","useAnimatedStyle","useComposedEventHandler","useDerivedValue","useSharedValue","useCSSVariable","jsx","_jsx","jsxs","_jsxs","DEFAULT_FADE_IN_DISTANCE","ScrollFade","className","size","edges","orientation","color","fadeInDistance","enabled","children","props","offset","contentLength","viewportLength","themeBackground","fadeColor","child","only","horizontal","undefined","childType","type","AnimatedScrollable","createAnimatedComponent","scrollHandler","onScroll","event","contentOffset","contentSize","layoutMeasurement","value","x","y","width","height","onLayout","nativeEvent","layout","onContentSizeChange","startOpacity","Math","min","endOpacity","remaining","max","scrollable","scrollEventThrottle","Fade","opacity","edge","displayName","isStart","position","top","bottom","left","right","style","colors","withAlpha","pointerEvents","start","end","absoluteFill","alpha","startsWith","hex","slice","full","length","split","map","c","join","r","parseInt","g","b","Number","isNaN","channels","match","part","trim"],"sourceRoot":"../../../../src","sources":["components/scroll-fade/index.tsx"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SACEA,QAAQ,EAERC,cAAc,EACdC,OAAO,QAIF,OAAO;AACd,SACEC,UAAU,EACVC,IAAI,QAKC,cAAc;AACrB,SAASC,cAAc,QAAQ,sBAAsB;AACrD,OAAOC,QAAQ,IACbC,wBAAwB,EACxBC,gBAAgB,EAChBC,uBAAuB,EACvBC,eAAe,EACfC,cAAc,QAGT,yBAAyB;AAChC,SAASC,cAAc,QAAQ,SAAS;;AAExC;AAAA,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AACA,MAAMC,wBAAwB,GAAG,EAAE;AAkCnC,OAAO,SAASC,UAAUA,CAAC;EACzBC,SAAS;EACTC,IAAI,GAAG,EAAE;EACTC,KAAK,GAAG,MAAM;EACdC,WAAW;EACXC,KAAK;EACLC,cAAc,GAAGP,wBAAwB;EACzCQ,OAAO,GAAG,IAAI;EACdC,QAAQ;EACR,GAAGC;AACY,CAAC,EAAE;EAClB,MAAMC,MAAM,GAAGjB,cAAc,CAAC,CAAC,CAAC;EAChC,MAAMkB,aAAa,GAAGlB,cAAc,CAAC,CAAC,CAAC;EACvC,MAAMmB,cAAc,GAAGnB,cAAc,CAAC,CAAC,CAAC;EAExC,MAAMoB,eAAe,GAAGnB,cAAc,CAAC,oBAAoB,CAAC;EAC5D,MAAMoB,SAAS,GACbT,KAAK,KAAK,O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