@cdx-ui/components 0.0.1-beta.137 → 0.0.1-beta.139

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.
Files changed (49) hide show
  1. package/lib/commonjs/components/Carousel/context.js +13 -0
  2. package/lib/commonjs/components/Carousel/context.js.map +1 -0
  3. package/lib/commonjs/components/Carousel/index.js +12 -7
  4. package/lib/commonjs/components/Carousel/index.js.map +1 -1
  5. package/lib/commonjs/components/Carousel/navButton.js +119 -0
  6. package/lib/commonjs/components/Carousel/navButton.js.map +1 -0
  7. package/lib/commonjs/components/Carousel/styles.js +24 -1
  8. package/lib/commonjs/components/Carousel/styles.js.map +1 -1
  9. package/lib/commonjs/components/Carousel/useCarouselActiveIndex.js +52 -0
  10. package/lib/commonjs/components/Carousel/useCarouselActiveIndex.js.map +1 -0
  11. package/lib/commonjs/components/Icon/index.js +1 -1
  12. package/lib/commonjs/components/Icon/index.js.map +1 -1
  13. package/lib/commonjs/components/IconButton/index.js +4 -2
  14. package/lib/commonjs/components/IconButton/index.js.map +1 -1
  15. package/lib/module/components/Carousel/context.js +7 -0
  16. package/lib/module/components/Carousel/context.js.map +1 -0
  17. package/lib/module/components/Carousel/index.js +11 -6
  18. package/lib/module/components/Carousel/index.js.map +1 -1
  19. package/lib/module/components/Carousel/navButton.js +114 -0
  20. package/lib/module/components/Carousel/navButton.js.map +1 -0
  21. package/lib/module/components/Carousel/styles.js +23 -0
  22. package/lib/module/components/Carousel/styles.js.map +1 -1
  23. package/lib/module/components/Carousel/useCarouselActiveIndex.js +48 -0
  24. package/lib/module/components/Carousel/useCarouselActiveIndex.js.map +1 -0
  25. package/lib/module/components/Icon/index.js +1 -1
  26. package/lib/module/components/Icon/index.js.map +1 -1
  27. package/lib/module/components/IconButton/index.js +4 -2
  28. package/lib/module/components/IconButton/index.js.map +1 -1
  29. package/lib/typescript/components/Carousel/context.d.ts +15 -0
  30. package/lib/typescript/components/Carousel/context.d.ts.map +1 -0
  31. package/lib/typescript/components/Carousel/index.d.ts +5 -2
  32. package/lib/typescript/components/Carousel/index.d.ts.map +1 -1
  33. package/lib/typescript/components/Carousel/navButton.d.ts +40 -0
  34. package/lib/typescript/components/Carousel/navButton.d.ts.map +1 -0
  35. package/lib/typescript/components/Carousel/styles.d.ts +8 -0
  36. package/lib/typescript/components/Carousel/styles.d.ts.map +1 -1
  37. package/lib/typescript/components/Carousel/useCarouselActiveIndex.d.ts +12 -0
  38. package/lib/typescript/components/Carousel/useCarouselActiveIndex.d.ts.map +1 -0
  39. package/lib/typescript/components/Icon/index.d.ts +3 -10
  40. package/lib/typescript/components/Icon/index.d.ts.map +1 -1
  41. package/lib/typescript/components/IconButton/index.d.ts.map +1 -1
  42. package/package.json +4 -4
  43. package/src/components/Carousel/context.ts +15 -0
  44. package/src/components/Carousel/index.tsx +18 -13
  45. package/src/components/Carousel/navButton.tsx +160 -0
  46. package/src/components/Carousel/styles.ts +27 -0
  47. package/src/components/Carousel/useCarouselActiveIndex.ts +54 -0
  48. package/src/components/Icon/index.tsx +3 -10
  49. package/src/components/IconButton/index.tsx +5 -1
@@ -0,0 +1,54 @@
1
+ import { useEffect, useRef, useState } from 'react';
2
+ import { useAnimatedReaction, type SharedValue } from 'react-native-reanimated';
3
+ import { scheduleOnRN } from 'react-native-worklets';
4
+
5
+ let nextListenerId = 1;
6
+
7
+ /**
8
+ * Syncs `Math.round(progress)` into React state for bounds-aware disabled state.
9
+ * Do not call `getCurrentIndex()` during render — the adopted library warns against it.
10
+ *
11
+ * Uses both:
12
+ * - `useAnimatedReaction` + `scheduleOnRN` (native / Babel-transformed web worklets)
13
+ * - SharedValue `addListener` (JS-thread fallback for web hosts that serve bob-built
14
+ * `lib/` without the Reanimated Babel plugin — e.g. the docs Vite SPA)
15
+ */
16
+ export function useCarouselActiveIndex(progress: SharedValue<number>): number {
17
+ const [activeIndex, setActiveIndex] = useState(() => Math.round(progress.get()));
18
+ const setActiveIndexRef = useRef(setActiveIndex);
19
+ setActiveIndexRef.current = setActiveIndex;
20
+
21
+ useAnimatedReaction(
22
+ () => Math.round(progress.get()),
23
+ (current, previous) => {
24
+ if (current !== previous) {
25
+ scheduleOnRN(setActiveIndexRef.current, current);
26
+ }
27
+ },
28
+ );
29
+
30
+ useEffect(() => {
31
+ const listenerId = nextListenerId++;
32
+ const onChange = (value: number) => {
33
+ const next = Math.round(value);
34
+ setActiveIndexRef.current((prev) => (prev === next ? prev : next));
35
+ };
36
+
37
+ try {
38
+ progress.addListener(listenerId, onChange);
39
+ } catch {
40
+ // Native JS runtime rejects addListener — the worklet path above handles it.
41
+ return;
42
+ }
43
+
44
+ return () => {
45
+ try {
46
+ progress.removeListener(listenerId);
47
+ } catch {
48
+ // ignore
49
+ }
50
+ };
51
+ }, [progress]);
52
+
53
+ return activeIndex;
54
+ }
@@ -1,17 +1,10 @@
1
1
  import { withUniwind } from 'uniwind';
2
2
  import { cn } from '@cdx-ui/utils';
3
- import type { ForgeIcon, ForgeIconProps, BrandIcon } from '@cdx-ui/icons';
3
+ import type { ForgeIcon, ForgeIconProps } from '@cdx-ui/icons';
4
4
 
5
5
  export type IconProps = ForgeIconProps & {
6
6
  className?: string; // TODO: Why does this need to specified manually?
7
- /**
8
- * The icon component to render. Accepts `BrandIcon` components (e.g. `WhatsApp`
9
- * from `@cdx-ui/icons`) in addition to themeable `ForgeIcon`s — the `size`
10
- * portion of `className` still applies, but brand icons ignore `color`/`filled`
11
- * (they are permanently fixed-color and non-themeable; see
12
- * docs/internal/research/brand-icons-direction-summary.md).
13
- */
14
- as: ForgeIcon | BrandIcon;
7
+ as: ForgeIcon;
15
8
  };
16
9
 
17
10
  function IconImpl({ as: IconComponent, ...props }: IconProps) {
@@ -51,7 +44,7 @@ const StyledIcon = withUniwind(withUniwind(IconImpl), {
51
44
  * <Icon as={ArrowRight} className="text-red-500 size-4" />
52
45
  * ```
53
46
  *
54
- * @param {ForgeIcon | BrandIcon} as - The Forge (or brand) icon component to render.
47
+ * @param {ForgeIcon} as - The Forge icon component to render.
55
48
  * @param {string} className - Utility classes to style the icon using Uniwind.
56
49
  * @param {number} size - Icon size (overrides the size class).
57
50
  * @param {...ForgeIconProps} ...props - Additional icon props passed to the "as" icon.
@@ -81,7 +81,11 @@ const IconButtonRoot = forwardRef<View, IconButtonProps>(
81
81
  className={rootClassName}
82
82
  style={style}
83
83
  {...props}
84
- {...mergeDataAttributes(props, dataAttributes({ slot: 'icon-button' }))}
84
+ {...mergeDataAttributes(
85
+ dataAttributes({ slot: 'icon-button' }),
86
+ // Consumer/parent compound slots (e.g. carousel-prev-button) win over the default.
87
+ props,
88
+ )}
85
89
  >
86
90
  <Icon as={IconComponent} className={glyphClassName} />
87
91
  </ButtonRoot>