@oxy.so/bloom 7.9.1 → 7.10.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/docs/adoption-matrix.mdx +1 -1
- package/docs/carousel.mdx +21 -1
- package/lib/commonjs/avatar/Avatar.js +18 -11
- package/lib/commonjs/avatar/Avatar.js.map +1 -1
- package/lib/commonjs/carousel/Carousel.js +93 -53
- package/lib/commonjs/carousel/Carousel.js.map +1 -1
- package/lib/commonjs/hooks/use-textarea-autosize.js +2 -2
- package/lib/module/avatar/Avatar.js +18 -11
- package/lib/module/avatar/Avatar.js.map +1 -1
- package/lib/module/carousel/Carousel.js +93 -53
- package/lib/module/carousel/Carousel.js.map +1 -1
- package/lib/module/hooks/use-textarea-autosize.js +2 -2
- package/lib/typescript/commonjs/avatar/Avatar.d.ts.map +1 -1
- package/lib/typescript/commonjs/carousel/Carousel.d.ts +1 -1
- package/lib/typescript/commonjs/carousel/Carousel.d.ts.map +1 -1
- package/lib/typescript/commonjs/carousel/types.d.ts +4 -2
- package/lib/typescript/commonjs/carousel/types.d.ts.map +1 -1
- package/lib/typescript/commonjs/hooks/use-textarea-autosize.d.ts +2 -2
- package/lib/typescript/module/avatar/Avatar.d.ts.map +1 -1
- package/lib/typescript/module/carousel/Carousel.d.ts +1 -1
- package/lib/typescript/module/carousel/Carousel.d.ts.map +1 -1
- package/lib/typescript/module/carousel/types.d.ts +4 -2
- package/lib/typescript/module/carousel/types.d.ts.map +1 -1
- package/lib/typescript/module/hooks/use-textarea-autosize.d.ts +2 -2
- package/package.json +1 -1
- package/src/avatar/Avatar.tsx +17 -13
- package/src/carousel/Carousel.tsx +74 -37
- package/src/carousel/types.ts +4 -2
|
@@ -25,6 +25,7 @@ import { Button } from '../button';
|
|
|
25
25
|
import { resolveButtonRamps } from '../button/shared';
|
|
26
26
|
import { RiArrowLeftSLine } from '../icons/remix/RiArrowLeftSLine';
|
|
27
27
|
import { RiArrowRightSLine } from '../icons/remix/RiArrowRightSLine';
|
|
28
|
+
import { useDirectionProps, useIsRtl } from '../hooks/use-is-rtl';
|
|
28
29
|
import { useInteractionState } from '../hooks/use-interaction-state';
|
|
29
30
|
import { useMessages } from '../locale/messages';
|
|
30
31
|
import { useInteractiveWebCss } from '../styles/interactive-web-css';
|
|
@@ -302,6 +303,7 @@ const CarouselComponent = function Carousel({
|
|
|
302
303
|
accessibilityLabel,
|
|
303
304
|
header,
|
|
304
305
|
showArrows = true,
|
|
306
|
+
arrowsPlacement = 'header',
|
|
305
307
|
showDots = true,
|
|
306
308
|
align = 'start',
|
|
307
309
|
gap = 16,
|
|
@@ -317,6 +319,8 @@ const CarouselComponent = function Carousel({
|
|
|
317
319
|
const previousLabel = previousLabelProp ?? messages.previousSlide;
|
|
318
320
|
const nextLabel = nextLabelProp ?? messages.nextSlide;
|
|
319
321
|
const theme = useTheme();
|
|
322
|
+
const rtl = useIsRtl();
|
|
323
|
+
const directionProps = useDirectionProps();
|
|
320
324
|
useInteractiveWebCss(STYLE_ID, BLOOM_CAROUSEL_CSS);
|
|
321
325
|
const reducedMotion = useReducedMotion();
|
|
322
326
|
const paint = useMemo(() => resolveCarouselPaint(theme), [theme]);
|
|
@@ -339,11 +343,12 @@ const CarouselComponent = function Carousel({
|
|
|
339
343
|
|
|
340
344
|
const targetFor = useCallback(
|
|
341
345
|
(item: SlideOffset) => {
|
|
342
|
-
const
|
|
346
|
+
const start = rtl ? scroll.current.contentWidth - item.x - item.width : item.x;
|
|
347
|
+
const raw = align === 'center' ? start - (trackWidth - item.width) / 2 : start - inset;
|
|
343
348
|
const max = Math.max(0, scroll.current.contentWidth - trackWidth);
|
|
344
349
|
return Math.min(Math.max(0, raw), max);
|
|
345
350
|
},
|
|
346
|
-
[align, inset, trackWidth],
|
|
351
|
+
[align, inset, trackWidth, rtl],
|
|
347
352
|
);
|
|
348
353
|
|
|
349
354
|
/**
|
|
@@ -416,7 +421,12 @@ const CarouselComponent = function Carousel({
|
|
|
416
421
|
|
|
417
422
|
const scrollToStop = (stop: Stop | undefined) => {
|
|
418
423
|
if (!stop) return;
|
|
419
|
-
|
|
424
|
+
// Web exposes negative scrollLeft in RTL; Android uses physical x, while
|
|
425
|
+
// iOS's ScrollView command already converts a logical offset internally.
|
|
426
|
+
const max = Math.max(0, scroll.current.contentWidth - trackWidth);
|
|
427
|
+
const x = !rtl ? stop.offset : IS_WEB ? -stop.offset
|
|
428
|
+
: Platform.OS === 'android' ? max - stop.offset : stop.offset;
|
|
429
|
+
scrollRef.current?.scrollTo({ x, animated: !reducedMotion });
|
|
420
430
|
};
|
|
421
431
|
|
|
422
432
|
/**
|
|
@@ -437,7 +447,10 @@ const CarouselComponent = function Carousel({
|
|
|
437
447
|
|
|
438
448
|
const onScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
439
449
|
const { contentOffset, contentSize } = event.nativeEvent;
|
|
440
|
-
|
|
450
|
+
const max = Math.max(0, contentSize.width - trackWidth);
|
|
451
|
+
const x = !rtl ? contentOffset.x : IS_WEB ? -contentOffset.x
|
|
452
|
+
: Platform.OS === 'android' ? max - contentOffset.x : contentOffset.x;
|
|
453
|
+
scroll.current = { x, contentWidth: contentSize.width };
|
|
441
454
|
measure();
|
|
442
455
|
};
|
|
443
456
|
|
|
@@ -462,52 +475,76 @@ const CarouselComponent = function Carousel({
|
|
|
462
475
|
'--bloom-carousel-inset': `${inset}px`,
|
|
463
476
|
};
|
|
464
477
|
|
|
478
|
+
const overlay = arrowsPlacement === 'overlay';
|
|
479
|
+
const arrowsVisible = showArrows && count > 0;
|
|
480
|
+
const arrowButtons = <>
|
|
481
|
+
<Button size={overlay ? 'lg' : 'sm'} icon={rtl ? RiArrowRightSLine : RiArrowLeftSLine}
|
|
482
|
+
accessibilityLabel={previousLabel} disabled={atStart} onPress={() => step(-1)}
|
|
483
|
+
appearance="subtle" tone="neutral" />
|
|
484
|
+
<Button size={overlay ? 'lg' : 'sm'} icon={rtl ? RiArrowLeftSLine : RiArrowRightSLine}
|
|
485
|
+
accessibilityLabel={nextLabel} disabled={atEnd} onPress={() => step(1)}
|
|
486
|
+
appearance="subtle" tone="neutral" />
|
|
487
|
+
</>;
|
|
488
|
+
// iOS snapping reads physical offsets even though its imperative command and
|
|
489
|
+
// scroll events use logical offsets. Android converts snap offsets internally.
|
|
490
|
+
const snapOffsets = rtl && Platform.OS === 'ios'
|
|
491
|
+
? stops.map(stop => Math.max(0, scroll.current.contentWidth - trackWidth) - stop.offset).reverse()
|
|
492
|
+
: stops.map(stop => stop.offset);
|
|
493
|
+
|
|
494
|
+
const track = (
|
|
495
|
+
<CarouselContext.Provider value={contextValue}>
|
|
496
|
+
<ScrollView
|
|
497
|
+
ref={scrollRef}
|
|
498
|
+
{...webDataSet({ bloomCarouselTrack: align })}
|
|
499
|
+
// Focusable so the arrow keys scroll it once it has focus, the
|
|
500
|
+
// browser's own behaviour (`tabIndex={0}`).
|
|
501
|
+
{...(IS_WEB ? { tabIndex: 0 } : {})}
|
|
502
|
+
horizontal
|
|
503
|
+
showsHorizontalScrollIndicator={false}
|
|
504
|
+
scrollEventThrottle={16}
|
|
505
|
+
onScroll={onScroll}
|
|
506
|
+
onContentSizeChange={onContentSizeChange}
|
|
507
|
+
onLayout={(event) => setTrackWidth(event.nativeEvent.layout.width)}
|
|
508
|
+
snapToOffsets={IS_WEB ? undefined : snapOffsets}
|
|
509
|
+
decelerationRate={IS_WEB ? undefined : 'fast'}
|
|
510
|
+
disableIntervalMomentum
|
|
511
|
+
style={trackStyle}
|
|
512
|
+
contentContainerStyle={{ gap, paddingHorizontal: inset }}
|
|
513
|
+
>
|
|
514
|
+
{slides.map((child, index) => (
|
|
515
|
+
<CarouselItemIndexContext.Provider key={child.key ?? index} value={index}>
|
|
516
|
+
{child}
|
|
517
|
+
</CarouselItemIndexContext.Provider>
|
|
518
|
+
))}
|
|
519
|
+
</ScrollView>
|
|
520
|
+
</CarouselContext.Provider>
|
|
521
|
+
);
|
|
522
|
+
|
|
465
523
|
return (
|
|
466
524
|
<View
|
|
467
525
|
role="group"
|
|
526
|
+
{...directionProps}
|
|
468
527
|
{...(IS_WEB ? { 'aria-roledescription': messages.carouselRole } : {})}
|
|
469
528
|
accessibilityLabel={accessibilityLabel}
|
|
470
529
|
style={[{ width: '100%', flexDirection: 'column', gap: 16 }, style]}
|
|
471
530
|
testID={testID}
|
|
472
531
|
>
|
|
473
|
-
{header != null || (
|
|
532
|
+
{header != null || (arrowsVisible && !overlay) ? (
|
|
474
533
|
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 8, paddingHorizontal: inset }}>
|
|
475
534
|
<View style={{ flex: 1, minWidth: 0 }}>{header}</View>
|
|
476
|
-
{
|
|
477
|
-
<>
|
|
478
|
-
<Button size="sm" icon={RiArrowLeftSLine} accessibilityLabel={previousLabel} disabled={atStart} onPress={() => step(-1)} appearance="subtle" tone="neutral" />
|
|
479
|
-
<Button size="sm" icon={RiArrowRightSLine} accessibilityLabel={nextLabel} disabled={atEnd} onPress={() => step(1)} appearance="subtle" tone="neutral" />
|
|
480
|
-
</>
|
|
481
|
-
) : null}
|
|
535
|
+
{arrowsVisible && !overlay ? arrowButtons : null}
|
|
482
536
|
</View>
|
|
483
537
|
) : null}
|
|
484
538
|
|
|
485
|
-
<
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
{
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
{
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
scrollEventThrottle={16}
|
|
495
|
-
onScroll={onScroll}
|
|
496
|
-
onContentSizeChange={onContentSizeChange}
|
|
497
|
-
onLayout={(event) => setTrackWidth(event.nativeEvent.layout.width)}
|
|
498
|
-
snapToOffsets={IS_WEB ? undefined : stops.map((stop) => stop.offset)}
|
|
499
|
-
decelerationRate={IS_WEB ? undefined : 'fast'}
|
|
500
|
-
disableIntervalMomentum
|
|
501
|
-
style={trackStyle}
|
|
502
|
-
contentContainerStyle={{ gap, paddingHorizontal: inset }}
|
|
503
|
-
>
|
|
504
|
-
{slides.map((child, index) => (
|
|
505
|
-
<CarouselItemIndexContext.Provider key={child.key ?? index} value={index}>
|
|
506
|
-
{child}
|
|
507
|
-
</CarouselItemIndexContext.Provider>
|
|
508
|
-
))}
|
|
509
|
-
</ScrollView>
|
|
510
|
-
</CarouselContext.Provider>
|
|
539
|
+
{overlay ? <View style={{ position: 'relative', width: '100%' }} testID={testID ? `${testID}-track-frame` : undefined}>
|
|
540
|
+
{track}
|
|
541
|
+
{arrowsVisible && overlay ? <View pointerEvents="box-none"
|
|
542
|
+
testID={testID ? `${testID}-overlay-arrows` : undefined}
|
|
543
|
+
style={{ position: 'absolute', top: 0, bottom: 0, insetInlineStart: 8, insetInlineEnd: 8,
|
|
544
|
+
flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' }}>
|
|
545
|
+
{arrowButtons}
|
|
546
|
+
</View> : null}
|
|
547
|
+
</View> : track}
|
|
511
548
|
|
|
512
549
|
{showDots && dotCount > 1 ? (
|
|
513
550
|
<View style={{ flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 6, paddingHorizontal: inset }}>
|
package/src/carousel/types.ts
CHANGED
|
@@ -12,11 +12,13 @@ export interface CarouselProps {
|
|
|
12
12
|
/**
|
|
13
13
|
* Leading content of the row above the track — typically the section title
|
|
14
14
|
* and a "See all" link. It shares the row with the arrows (header at the
|
|
15
|
-
* start, arrows at the end)
|
|
15
|
+
* start, arrows at the end). With overlay arrows this row contains only the header.
|
|
16
16
|
*/
|
|
17
17
|
header?: ReactNode;
|
|
18
|
-
/** Previous / next buttons
|
|
18
|
+
/** Previous / next buttons. Defaults to `true`; callers may hide them at their mobile breakpoint. */
|
|
19
19
|
showArrows?: boolean;
|
|
20
|
+
/** Arrows share the header row or overlay the track's edges. Defaults to `'header'`. */
|
|
21
|
+
arrowsPlacement?: 'header' | 'overlay';
|
|
20
22
|
/** Position indicator below the track. Defaults to `true`. */
|
|
21
23
|
showDots?: boolean;
|
|
22
24
|
/** Where a slide comes to rest when it snaps. Defaults to `'start'`. */
|