@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.
@@ -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 raw = align === 'center' ? item.x - (trackWidth - item.width) / 2 : item.x - inset;
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
- scrollRef.current?.scrollTo({ x: stop.offset, animated: !reducedMotion });
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
- scroll.current = { x: contentOffset.x, contentWidth: contentSize.width };
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 || (showArrows && count > 0) ? (
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
- {showArrows && count > 0 ? (
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
- <CarouselContext.Provider value={contextValue}>
486
- <ScrollView
487
- ref={scrollRef}
488
- {...webDataSet({ bloomCarouselTrack: align })}
489
- // Focusable so the arrow keys scroll it once it has focus, the
490
- // browser's own behaviour (`tabIndex={0}`).
491
- {...(IS_WEB ? { tabIndex: 0 } : {})}
492
- horizontal
493
- showsHorizontalScrollIndicator={false}
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 }}>
@@ -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), so a titled carousel costs one row, not two.
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 above the track. Defaults to `true`. */
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'`. */