@metamask-previews/design-system-react-native 0.51.0-preview.b15bc07 → 0.52.0-preview.3026400c

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 (36) hide show
  1. package/CHANGELOG.md +30 -1
  2. package/dist/components/BottomSheetDialog/BottomSheetDialog.cjs +3 -3
  3. package/dist/components/BottomSheetDialog/BottomSheetDialog.cjs.map +1 -1
  4. package/dist/components/BottomSheetDialog/BottomSheetDialog.d.cts.map +1 -1
  5. package/dist/components/BottomSheetDialog/BottomSheetDialog.d.mts.map +1 -1
  6. package/dist/components/BottomSheetDialog/BottomSheetDialog.mjs +3 -3
  7. package/dist/components/BottomSheetDialog/BottomSheetDialog.mjs.map +1 -1
  8. package/dist/components/BottomSheetDialog/BottomSheetDialog.types.cjs.map +1 -1
  9. package/dist/components/BottomSheetDialog/BottomSheetDialog.types.d.cts +2 -1
  10. package/dist/components/BottomSheetDialog/BottomSheetDialog.types.d.cts.map +1 -1
  11. package/dist/components/BottomSheetDialog/BottomSheetDialog.types.d.mts +2 -1
  12. package/dist/components/BottomSheetDialog/BottomSheetDialog.types.d.mts.map +1 -1
  13. package/dist/components/BottomSheetDialog/BottomSheetDialog.types.mjs.map +1 -1
  14. package/dist/components/Slider/Slider.constants.cjs +5 -6
  15. package/dist/components/Slider/Slider.constants.cjs.map +1 -1
  16. package/dist/components/Slider/Slider.constants.d.cts +5 -6
  17. package/dist/components/Slider/Slider.constants.d.cts.map +1 -1
  18. package/dist/components/Slider/Slider.constants.d.mts +5 -6
  19. package/dist/components/Slider/Slider.constants.d.mts.map +1 -1
  20. package/dist/components/Slider/Slider.constants.mjs +5 -6
  21. package/dist/components/Slider/Slider.constants.mjs.map +1 -1
  22. package/dist/components/Slider/Slider.types.cjs.map +1 -1
  23. package/dist/components/Slider/Slider.types.d.cts +4 -5
  24. package/dist/components/Slider/Slider.types.d.cts.map +1 -1
  25. package/dist/components/Slider/Slider.types.d.mts +4 -5
  26. package/dist/components/Slider/Slider.types.d.mts.map +1 -1
  27. package/dist/components/Slider/Slider.types.mjs.map +1 -1
  28. package/dist/components/Slider/Slider.utilities.cjs +37 -7
  29. package/dist/components/Slider/Slider.utilities.cjs.map +1 -1
  30. package/dist/components/Slider/Slider.utilities.d.cts +24 -3
  31. package/dist/components/Slider/Slider.utilities.d.cts.map +1 -1
  32. package/dist/components/Slider/Slider.utilities.d.mts +24 -3
  33. package/dist/components/Slider/Slider.utilities.d.mts.map +1 -1
  34. package/dist/components/Slider/Slider.utilities.mjs +38 -8
  35. package/dist/components/Slider/Slider.utilities.mjs.map +1 -1
  36. package/package.json +6 -6
package/CHANGELOG.md CHANGED
@@ -7,6 +7,34 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.52.0]
11
+
12
+ ### Added
13
+
14
+ - Added `TextVariant.DisplayXl` ([#1587](https://github.com/MetaMask/metamask-design-system/pull/1587))
15
+ - Uses the 60px / 75px bold display style
16
+
17
+ ### Changed
18
+
19
+ - **BREAKING:** `FontFamily.Hero` now renders Grotzec Cond Bold instead of MM Poly ([#1586](https://github.com/MetaMask/metamask-design-system/pull/1586))
20
+ - `Text` applies `font-hero-bold` for `FontFamily.Hero`, including when `fontWeight` is regular or medium
21
+ - The twrnc class `font-hero-regular` is removed; use `font-hero-bold`, which resolves to the PostScript name `GrotzecCond-Bold`
22
+ - See [Migration Guide](./MIGRATION.md#from-version-0510-to-0520)
23
+ - **BREAKING:** Updated peer dependencies to `@metamask/design-tokens@^12.0.0` and `@metamask/design-system-twrnc-preset@^0.13.0` ([#1586](https://github.com/MetaMask/metamask-design-system/pull/1586))
24
+ - Required coordination bump with the hero typeface change in `@metamask/design-tokens@12.0.0`
25
+ - Updated small-screen `TextVariant.AmountDisplayLg` from 40px / 50px to 48px / 56px ([#1587](https://github.com/MetaMask/metamask-design-system/pull/1587))
26
+ - The large-screen size stays 60px / 75px
27
+ - Updated the `Share` icon artwork to a box-and-arrow glyph ([#1588](https://github.com/MetaMask/metamask-design-system/pull/1588))
28
+ - Deprecated `ButtonHero` in favor of `Button` ([#1570](https://github.com/MetaMask/metamask-design-system/pull/1570))
29
+ - Primary is the default `Button` variant; pass `variant={ButtonVariant.Primary}` to set it explicitly
30
+ - `ButtonHero` remains available until a future major version
31
+
32
+ ### Fixed
33
+
34
+ - Fixed `BottomSheetDialog` so a non-interactable sheet keeps the drag handle's space ([#1589](https://github.com/MetaMask/metamask-design-system/pull/1589))
35
+ - When `isInteractable` is `false`, the handle stays in the layout and is only hidden visually (`opacity-0`)
36
+ - Sheet height no longer shifts when the sheet is not swippable
37
+
10
38
  ## [0.51.0]
11
39
 
12
40
  ### Added
@@ -838,7 +866,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
838
866
  - Full TypeScript support with type definitions and enums
839
867
  - React Native integration with TWRNC preset support
840
868
 
841
- [Unreleased]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/design-system-react-native@0.51.0...HEAD
869
+ [Unreleased]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/design-system-react-native@0.52.0...HEAD
870
+ [0.52.0]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/design-system-react-native@0.51.0...@metamask/design-system-react-native@0.52.0
842
871
  [0.51.0]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/design-system-react-native@0.50.0...@metamask/design-system-react-native@0.51.0
843
872
  [0.50.0]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/design-system-react-native@0.49.2...@metamask/design-system-react-native@0.50.0
844
873
  [0.49.2]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/design-system-react-native@0.49.1...@metamask/design-system-react-native@0.49.2
@@ -217,9 +217,9 @@ exports.BottomSheetDialog = (0, react_1.forwardRef)(({ children, isFullscreen =
217
217
  return (<react_native_1.KeyboardAvoidingView style={tw.style('absolute bottom-0 inset-x-0')} behavior={react_native_1.Platform.OS === 'ios' ? 'padding' : undefined} keyboardVerticalOffset={react_native_1.Platform.OS === 'ios' ? -screenBottomPadding : frameY} enabled={keyboardAvoidingViewEnabled} {...props}>
218
218
  <react_native_gesture_handler_1.GestureDetector gesture={gestureHandler}>
219
219
  <react_native_reanimated_1.default.View onLayout={updateSheetHeight} style={combinedSheetStyle}>
220
- {isInteractable && (<react_native_1.View style={tw.style('self-stretch items-center p-1')}>
221
- <react_native_1.View style={tw.style('h-1 w-10 rounded-sm bg-border-muted')}/>
222
- </react_native_1.View>)}
220
+ <react_native_1.View style={tw.style('self-stretch items-center p-1', !isInteractable && 'opacity-0')} testID="bottom-sheet-dialog-drag-handle">
221
+ <react_native_1.View style={tw.style('h-1 w-10 rounded-sm bg-border-muted')}/>
222
+ </react_native_1.View>
223
223
  {children}
224
224
  </react_native_reanimated_1.default.View>
225
225
  </react_native_gesture_handler_1.GestureDetector>
@@ -1 +1 @@
1
- {"version":3,"file":"BottomSheetDialog.cjs","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8FAIuD;AACvD,oEAAyE;AACzE,mCAAkC;AAClC,+CAOe;AACf,+CAKsB;AACtB,+EAAwE;AACxE,mFAIiC;AACjC,mFAGwC;AACxC,iEAAqD;AAErD,yBAAyB;AACzB,mFAIuC;AAM1B,QAAA,iBAAiB,GAAG,IAAA,kBAAU,EAIzC,CACE,EACE,QAAQ,EACR,YAAY,GAAG,KAAK,EACpB,cAAc,GAAG,IAAI,EACrB,2BAA2B,GAAG,IAAI,EAClC,OAAO,EACP,MAAM,EACN,KAAK,EACL,WAAW,EACX,GAAG,KAAK,EACT,EACD,GAAG,EACH,EAAE;IACF,MAAM,EAAE,GAAG,IAAA,wCAAW,GAAE,CAAC;IACzB,MAAM,YAAY,GAAG,IAAA,qCAAQ,GAAE,CAAC;IAChC,MAAM,QAAQ,GACZ,YAAY,KAAK,kCAAK,CAAC,KAAK;QAC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AC5B,KAAK,CAAC,CAAC,kBAAkB,CAAC,CAE1B;YAAA,CAAC,cAAc,IAAI,CACjB,CAAC,mBAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC,CACrD;gBAAA,CAAC,mBAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC,EAC/D;cAAA,EAAE,mBAAI,CAAC,CACR,CACD;YAAA,CAAC,QAAQ,CACX;UAAA,EAAE,iCAAQ,CAAC,IAAI,CACjB;QAAA,EAAE,8CAAe,CACnB;MAAA,EAAE,mCAAoB,CAAC,CACxB,CAAC;AACJ,CAAC,CACF,CAAC","sourcesContent":["import {\n Theme,\n useTailwind,\n useTheme,\n} from '@metamask-previews/design-system-twrnc-preset';\nimport { darkTheme, lightTheme } from '@metamask-previews/design-tokens';\nimport { debounce } from 'lodash';\nimport React, {\n forwardRef,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useImperativeHandle,\n} from 'react';\nimport {\n LayoutChangeEvent,\n View,\n Platform,\n KeyboardAvoidingView,\n} from 'react-native';\nimport { Gesture, GestureDetector } from 'react-native-gesture-handler';\nimport Animated, {\n useAnimatedStyle,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated';\nimport {\n useSafeAreaFrame,\n useSafeAreaInsets,\n} from 'react-native-safe-area-context';\nimport { scheduleOnRN } from 'react-native-worklets';\n\n// Internal dependencies.\nimport {\n DEFAULT_BOTTOMSHEETDIALOG_DISPLAY_DURATION,\n DEFAULT_BOTTOMSHEETDIALOG_DISMISSTHRESHOLD,\n DEFAULT_BOTTOMSHEETDIALOG_SWIPETHRESHOLD_DURATION,\n} from './BottomSheetDialog.constants';\nimport type {\n BottomSheetDialogRef,\n BottomSheetDialogProps,\n} from './BottomSheetDialog.types';\n\nexport const BottomSheetDialog = forwardRef<\n BottomSheetDialogRef,\n BottomSheetDialogProps\n>(\n (\n {\n children,\n isFullscreen = false,\n isInteractable = true,\n keyboardAvoidingViewEnabled = true,\n onClose,\n onOpen,\n style,\n twClassName,\n ...props\n },\n ref,\n ) => {\n const tw = useTailwind();\n const currentTheme = useTheme();\n const shadowLg =\n currentTheme === Theme.Light\n ? lightTheme.shadows.size.lg\n : darkTheme.shadows.size.lg;\n\n const { top: screenTopPadding, bottom: screenBottomPadding } =\n useSafeAreaInsets();\n const { y: frameY, height: screenHeight } = useSafeAreaFrame();\n\n const maxSheetHeight = screenHeight - screenTopPadding;\n // X and Y values start on top left of the DIALOG\n // currentYOffset will be used to animate the Y position of the Dialog\n const currentYOffset = useSharedValue(screenHeight);\n const topOfDialogYValue = useSharedValue(0);\n const bottomOfDialogYValue = useSharedValue(screenHeight);\n const gestureStartYOffset = useSharedValue(0);\n const isMounted = useRef(false);\n\n const onOpenCB = useCallback(() => {\n onOpen?.();\n }, [onOpen]);\n const onCloseCB = useCallback(() => {\n onClose?.();\n }, [onClose]);\n\n const onCloseDialog = useCallback(\n (callback?: () => void) => {\n currentYOffset.value = withTiming(\n bottomOfDialogYValue.value,\n { duration: DEFAULT_BOTTOMSHEETDIALOG_DISPLAY_DURATION },\n () => {\n scheduleOnRN(onCloseCB);\n if (callback) {\n scheduleOnRN(callback);\n }\n },\n );\n // Ref values do not affect deps.\n },\n [onCloseCB],\n );\n\n const gestureHandler = useMemo(() => {\n // These gesture callbacks need explicit 'worklet' directives because this\n // package ships a pre-built dist compiled by ts-bridge (tsc), which emits the\n // gesture chain as a namespaced call (react_native_gesture_handler_1.Gesture).\n // The consumer's Reanimated/Worklets Babel plugin does run over dist (that's\n // why useAnimatedStyle below works), but its gesture auto-detection doesn't\n // recognize that compiled namespaced form, so without these directives the\n // callbacks run on the JS thread and slow drags lag behind the finger.\n const gesture = Gesture.Pan()\n .enabled(isInteractable)\n .onStart(() => {\n 'worklet';\n\n // Starts tracking vertical position of gesture.\n gestureStartYOffset.value = currentYOffset.value;\n })\n .onUpdate((event) => {\n 'worklet';\n\n const { translationY } = event;\n currentYOffset.value = gestureStartYOffset.value + translationY;\n // If gesture Y value goes above the bottom of Dialog Y value(bottom of dialog),\n // which means the gesture is currently below the bottom of the dialog,\n // sets it to bottom of Dialog Y value\n if (currentYOffset.value >= bottomOfDialogYValue.value) {\n currentYOffset.value = bottomOfDialogYValue.value;\n }\n // If gesture Y value goes below the top of Dialog Y value(top of dialog),\n // which means the gesture is currently above the top of the dialog,\n // sets it to top of Dialog Y value\n if (currentYOffset.value <= topOfDialogYValue.value) {\n currentYOffset.value = topOfDialogYValue.value;\n }\n })\n .onEnd((event) => {\n 'worklet';\n\n const { translationY, velocityY } = event;\n // finalYOffset is used to animate the Y position of the Dialog after the gesture event\n let finalYOffset: number;\n // Measuring dismissing swipe action\n const latestOffset = gestureStartYOffset.value + translationY;\n // Check if the swipe distance reach the dismiss offset threshold,\n // which is currently 60% of sheet height\n const hasReachedDismissOffset =\n latestOffset >\n bottomOfDialogYValue.value *\n DEFAULT_BOTTOMSHEETDIALOG_DISMISSTHRESHOLD;\n // Check if the gesture's vertical speed has reached the threshold to determine a swipe action\n const hasReachedSwipeThreshold =\n Math.abs(velocityY) >\n DEFAULT_BOTTOMSHEETDIALOG_SWIPETHRESHOLD_DURATION;\n const isQuickDismissing = velocityY > 0;\n\n // If user is swiping\n if (hasReachedSwipeThreshold) {\n // Quick swipe takes priority\n if (isQuickDismissing) {\n finalYOffset = bottomOfDialogYValue.value;\n } else {\n finalYOffset = topOfDialogYValue.value;\n }\n } else if (hasReachedDismissOffset) {\n finalYOffset = bottomOfDialogYValue.value;\n } else {\n finalYOffset = topOfDialogYValue.value;\n }\n\n const isDismissed = finalYOffset === bottomOfDialogYValue.value;\n\n if (isDismissed) {\n scheduleOnRN(onCloseDialog);\n } else {\n // Only animate dialog to a certain Y position instead\n currentYOffset.value = withTiming(finalYOffset, {\n duration: DEFAULT_BOTTOMSHEETDIALOG_DISPLAY_DURATION,\n });\n }\n });\n\n return gesture;\n }, [\n isInteractable,\n currentYOffset,\n gestureStartYOffset,\n bottomOfDialogYValue,\n topOfDialogYValue,\n onCloseDialog,\n ]);\n\n // Animate in sheet on initial render.\n const onOpenDialog = (callback?: () => void) => {\n // Starts setting the Y position of the dialog to the bottom of the dialog\n currentYOffset.value = bottomOfDialogYValue.value;\n // Animate the Y position to the top of the dialog, then call onOpenCB\n currentYOffset.value = withTiming(\n topOfDialogYValue.value,\n {\n duration: DEFAULT_BOTTOMSHEETDIALOG_DISPLAY_DURATION,\n },\n () => {\n scheduleOnRN(onOpenCB);\n if (callback) {\n scheduleOnRN(callback);\n }\n },\n );\n };\n\n const onDebouncedCloseDialog = useMemo(\n // Prevent hide from being called multiple times. Potentially caused by taps in quick succession.\n () => debounce(onCloseDialog, 2000, { leading: true }),\n [onCloseDialog],\n );\n\n useEffect(\n () =>\n // Automatically handles animation when content changes\n // Disable for now since network switches causes the screen to hang with this on.\n // LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);\n onDebouncedCloseDialog.cancel(),\n [children, onDebouncedCloseDialog],\n );\n\n const updateSheetHeight = (e: LayoutChangeEvent) => {\n const { height } = e.nativeEvent.layout;\n bottomOfDialogYValue.value = height;\n\n if (!isMounted.current) {\n isMounted.current = true;\n onOpenDialog();\n }\n };\n\n const animatedSheetStyle = useAnimatedStyle(\n () => ({\n transform: [\n {\n translateY: currentYOffset.value,\n },\n ],\n }),\n [],\n );\n\n const sheetStyle = useMemo(\n () => [\n tw.style(\n 'bg-elevated1',\n 'rounded-t-[32px] overflow-hidden border border-muted border-b-0',\n twClassName,\n ),\n {\n maxHeight: maxSheetHeight,\n paddingBottom: Platform.select({\n ios: screenBottomPadding,\n macos: screenBottomPadding,\n default: screenBottomPadding + 16,\n }),\n ...(isFullscreen && { height: maxSheetHeight }),\n ...shadowLg,\n },\n style,\n ],\n\n [\n tw,\n maxSheetHeight,\n screenBottomPadding,\n isFullscreen,\n shadowLg,\n style,\n twClassName,\n ],\n );\n\n const combinedSheetStyle = useMemo(\n () => [...sheetStyle, animatedSheetStyle],\n\n [sheetStyle],\n );\n\n useImperativeHandle(ref, () => ({\n onOpenDialog,\n onCloseDialog,\n }));\n\n return (\n <KeyboardAvoidingView\n style={tw.style('absolute bottom-0 inset-x-0')}\n behavior={Platform.OS === 'ios' ? 'padding' : undefined}\n keyboardVerticalOffset={\n Platform.OS === 'ios' ? -screenBottomPadding : frameY\n }\n enabled={keyboardAvoidingViewEnabled}\n {...props}\n >\n <GestureDetector gesture={gestureHandler}>\n <Animated.View\n onLayout={updateSheetHeight}\n style={combinedSheetStyle}\n >\n {isInteractable && (\n <View style={tw.style('self-stretch items-center p-1')}>\n <View style={tw.style('h-1 w-10 rounded-sm bg-border-muted')} />\n </View>\n )}\n {children}\n </Animated.View>\n </GestureDetector>\n </KeyboardAvoidingView>\n );\n },\n);\n"]}
1
+ {"version":3,"file":"BottomSheetDialog.cjs","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8FAIuD;AACvD,oEAAyE;AACzE,mCAAkC;AAClC,+CAOe;AACf,+CAKsB;AACtB,+EAAwE;AACxE,mFAIiC;AACjC,mFAGwC;AACxC,iEAAqD;AAErD,yBAAyB;AACzB,mFAIuC;AAM1B,QAAA,iBAAiB,GAAG,IAAA,kBAAU,EAIzC,CACE,EACE,QAAQ,EACR,YAAY,GAAG,KAAK,EACpB,cAAc,GAAG,IAAI,EACrB,2BAA2B,GAAG,IAAI,EAClC,OAAO,EACP,MAAM,EACN,KAAK,EACL,WAAW,EACX,GAAG,KAAK,EACT,EACD,GAAG,EACH,EAAE;IACF,MAAM,EAAE,GAAG,IAAA,wCAAW,GAAE,CAAC;IACzB,MAAM,YAAY,GAAG,IAAA,qCAAQ,GAAE,CAAC;IAChC,MAAM,QAAQ,GACZ,YAAY,KAAK,kCAAK,CAAC,KAAK;QAC1B,CAAC,CAAC,0BAAU,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;Q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AAI,CACH,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CACb,+BAA+B,EAC/B,CAAC,cAAc,IAAI,WAAW,CAC/B,CAAC,CACF,MAAM,CAAC,iCAAiC,CAExC;cAAA,CAAC,mBAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC,EAC/D;YAAA,EAAE,mBAAI,CACN;YAAA,CAAC,QAAQ,CACX;UAAA,EAAE,iCAAQ,CAAC,IAAI,CACjB;QAAA,EAAE,8CAAe,CACnB;MAAA,EAAE,mCAAoB,CAAC,CACxB,CAAC;AACJ,CAAC,CACF,CAAC","sourcesContent":["import {\n Theme,\n useTailwind,\n useTheme,\n} from '@metamask-previews/design-system-twrnc-preset';\nimport { darkTheme, lightTheme } from '@metamask-previews/design-tokens';\nimport { debounce } from 'lodash';\nimport React, {\n forwardRef,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useImperativeHandle,\n} from 'react';\nimport {\n LayoutChangeEvent,\n View,\n Platform,\n KeyboardAvoidingView,\n} from 'react-native';\nimport { Gesture, GestureDetector } from 'react-native-gesture-handler';\nimport Animated, {\n useAnimatedStyle,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated';\nimport {\n useSafeAreaFrame,\n useSafeAreaInsets,\n} from 'react-native-safe-area-context';\nimport { scheduleOnRN } from 'react-native-worklets';\n\n// Internal dependencies.\nimport {\n DEFAULT_BOTTOMSHEETDIALOG_DISPLAY_DURATION,\n DEFAULT_BOTTOMSHEETDIALOG_DISMISSTHRESHOLD,\n DEFAULT_BOTTOMSHEETDIALOG_SWIPETHRESHOLD_DURATION,\n} from './BottomSheetDialog.constants';\nimport type {\n BottomSheetDialogRef,\n BottomSheetDialogProps,\n} from './BottomSheetDialog.types';\n\nexport const BottomSheetDialog = forwardRef<\n BottomSheetDialogRef,\n BottomSheetDialogProps\n>(\n (\n {\n children,\n isFullscreen = false,\n isInteractable = true,\n keyboardAvoidingViewEnabled = true,\n onClose,\n onOpen,\n style,\n twClassName,\n ...props\n },\n ref,\n ) => {\n const tw = useTailwind();\n const currentTheme = useTheme();\n const shadowLg =\n currentTheme === Theme.Light\n ? lightTheme.shadows.size.lg\n : darkTheme.shadows.size.lg;\n\n const { top: screenTopPadding, bottom: screenBottomPadding } =\n useSafeAreaInsets();\n const { y: frameY, height: screenHeight } = useSafeAreaFrame();\n\n const maxSheetHeight = screenHeight - screenTopPadding;\n // X and Y values start on top left of the DIALOG\n // currentYOffset will be used to animate the Y position of the Dialog\n const currentYOffset = useSharedValue(screenHeight);\n const topOfDialogYValue = useSharedValue(0);\n const bottomOfDialogYValue = useSharedValue(screenHeight);\n const gestureStartYOffset = useSharedValue(0);\n const isMounted = useRef(false);\n\n const onOpenCB = useCallback(() => {\n onOpen?.();\n }, [onOpen]);\n const onCloseCB = useCallback(() => {\n onClose?.();\n }, [onClose]);\n\n const onCloseDialog = useCallback(\n (callback?: () => void) => {\n currentYOffset.value = withTiming(\n bottomOfDialogYValue.value,\n { duration: DEFAULT_BOTTOMSHEETDIALOG_DISPLAY_DURATION },\n () => {\n scheduleOnRN(onCloseCB);\n if (callback) {\n scheduleOnRN(callback);\n }\n },\n );\n // Ref values do not affect deps.\n },\n [onCloseCB],\n );\n\n const gestureHandler = useMemo(() => {\n // These gesture callbacks need explicit 'worklet' directives because this\n // package ships a pre-built dist compiled by ts-bridge (tsc), which emits the\n // gesture chain as a namespaced call (react_native_gesture_handler_1.Gesture).\n // The consumer's Reanimated/Worklets Babel plugin does run over dist (that's\n // why useAnimatedStyle below works), but its gesture auto-detection doesn't\n // recognize that compiled namespaced form, so without these directives the\n // callbacks run on the JS thread and slow drags lag behind the finger.\n const gesture = Gesture.Pan()\n .enabled(isInteractable)\n .onStart(() => {\n 'worklet';\n\n // Starts tracking vertical position of gesture.\n gestureStartYOffset.value = currentYOffset.value;\n })\n .onUpdate((event) => {\n 'worklet';\n\n const { translationY } = event;\n currentYOffset.value = gestureStartYOffset.value + translationY;\n // If gesture Y value goes above the bottom of Dialog Y value(bottom of dialog),\n // which means the gesture is currently below the bottom of the dialog,\n // sets it to bottom of Dialog Y value\n if (currentYOffset.value >= bottomOfDialogYValue.value) {\n currentYOffset.value = bottomOfDialogYValue.value;\n }\n // If gesture Y value goes below the top of Dialog Y value(top of dialog),\n // which means the gesture is currently above the top of the dialog,\n // sets it to top of Dialog Y value\n if (currentYOffset.value <= topOfDialogYValue.value) {\n currentYOffset.value = topOfDialogYValue.value;\n }\n })\n .onEnd((event) => {\n 'worklet';\n\n const { translationY, velocityY } = event;\n // finalYOffset is used to animate the Y position of the Dialog after the gesture event\n let finalYOffset: number;\n // Measuring dismissing swipe action\n const latestOffset = gestureStartYOffset.value + translationY;\n // Check if the swipe distance reach the dismiss offset threshold,\n // which is currently 60% of sheet height\n const hasReachedDismissOffset =\n latestOffset >\n bottomOfDialogYValue.value *\n DEFAULT_BOTTOMSHEETDIALOG_DISMISSTHRESHOLD;\n // Check if the gesture's vertical speed has reached the threshold to determine a swipe action\n const hasReachedSwipeThreshold =\n Math.abs(velocityY) >\n DEFAULT_BOTTOMSHEETDIALOG_SWIPETHRESHOLD_DURATION;\n const isQuickDismissing = velocityY > 0;\n\n // If user is swiping\n if (hasReachedSwipeThreshold) {\n // Quick swipe takes priority\n if (isQuickDismissing) {\n finalYOffset = bottomOfDialogYValue.value;\n } else {\n finalYOffset = topOfDialogYValue.value;\n }\n } else if (hasReachedDismissOffset) {\n finalYOffset = bottomOfDialogYValue.value;\n } else {\n finalYOffset = topOfDialogYValue.value;\n }\n\n const isDismissed = finalYOffset === bottomOfDialogYValue.value;\n\n if (isDismissed) {\n scheduleOnRN(onCloseDialog);\n } else {\n // Only animate dialog to a certain Y position instead\n currentYOffset.value = withTiming(finalYOffset, {\n duration: DEFAULT_BOTTOMSHEETDIALOG_DISPLAY_DURATION,\n });\n }\n });\n\n return gesture;\n }, [\n isInteractable,\n currentYOffset,\n gestureStartYOffset,\n bottomOfDialogYValue,\n topOfDialogYValue,\n onCloseDialog,\n ]);\n\n // Animate in sheet on initial render.\n const onOpenDialog = (callback?: () => void) => {\n // Starts setting the Y position of the dialog to the bottom of the dialog\n currentYOffset.value = bottomOfDialogYValue.value;\n // Animate the Y position to the top of the dialog, then call onOpenCB\n currentYOffset.value = withTiming(\n topOfDialogYValue.value,\n {\n duration: DEFAULT_BOTTOMSHEETDIALOG_DISPLAY_DURATION,\n },\n () => {\n scheduleOnRN(onOpenCB);\n if (callback) {\n scheduleOnRN(callback);\n }\n },\n );\n };\n\n const onDebouncedCloseDialog = useMemo(\n // Prevent hide from being called multiple times. Potentially caused by taps in quick succession.\n () => debounce(onCloseDialog, 2000, { leading: true }),\n [onCloseDialog],\n );\n\n useEffect(\n () =>\n // Automatically handles animation when content changes\n // Disable for now since network switches causes the screen to hang with this on.\n // LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);\n onDebouncedCloseDialog.cancel(),\n [children, onDebouncedCloseDialog],\n );\n\n const updateSheetHeight = (e: LayoutChangeEvent) => {\n const { height } = e.nativeEvent.layout;\n bottomOfDialogYValue.value = height;\n\n if (!isMounted.current) {\n isMounted.current = true;\n onOpenDialog();\n }\n };\n\n const animatedSheetStyle = useAnimatedStyle(\n () => ({\n transform: [\n {\n translateY: currentYOffset.value,\n },\n ],\n }),\n [],\n );\n\n const sheetStyle = useMemo(\n () => [\n tw.style(\n 'bg-elevated1',\n 'rounded-t-[32px] overflow-hidden border border-muted border-b-0',\n twClassName,\n ),\n {\n maxHeight: maxSheetHeight,\n paddingBottom: Platform.select({\n ios: screenBottomPadding,\n macos: screenBottomPadding,\n default: screenBottomPadding + 16,\n }),\n ...(isFullscreen && { height: maxSheetHeight }),\n ...shadowLg,\n },\n style,\n ],\n\n [\n tw,\n maxSheetHeight,\n screenBottomPadding,\n isFullscreen,\n shadowLg,\n style,\n twClassName,\n ],\n );\n\n const combinedSheetStyle = useMemo(\n () => [...sheetStyle, animatedSheetStyle],\n\n [sheetStyle],\n );\n\n useImperativeHandle(ref, () => ({\n onOpenDialog,\n onCloseDialog,\n }));\n\n return (\n <KeyboardAvoidingView\n style={tw.style('absolute bottom-0 inset-x-0')}\n behavior={Platform.OS === 'ios' ? 'padding' : undefined}\n keyboardVerticalOffset={\n Platform.OS === 'ios' ? -screenBottomPadding : frameY\n }\n enabled={keyboardAvoidingViewEnabled}\n {...props}\n >\n <GestureDetector gesture={gestureHandler}>\n <Animated.View\n onLayout={updateSheetHeight}\n style={combinedSheetStyle}\n >\n <View\n style={tw.style(\n 'self-stretch items-center p-1',\n !isInteractable && 'opacity-0',\n )}\n testID=\"bottom-sheet-dialog-drag-handle\"\n >\n <View style={tw.style('h-1 w-10 rounded-sm bg-border-muted')} />\n </View>\n {children}\n </Animated.View>\n </GestureDetector>\n </KeyboardAvoidingView>\n );\n },\n);\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"BottomSheetDialog.d.cts","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.tsx"],"names":[],"mappings":"AAOA,OAAO,KAON,cAAc;AAyBf,OAAO,KAAK,EACV,oBAAoB,EAErB,sCAAkC;AAEnC,eAAO,MAAM,iBAAiB;;;;;;;;iFAmR7B,CAAC"}
1
+ {"version":3,"file":"BottomSheetDialog.d.cts","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.tsx"],"names":[],"mappings":"AAOA,OAAO,KAON,cAAc;AAyBf,OAAO,KAAK,EACV,oBAAoB,EAErB,sCAAkC;AAEnC,eAAO,MAAM,iBAAiB;;;;;;;;iFAuR7B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"BottomSheetDialog.d.mts","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.tsx"],"names":[],"mappings":"AAOA,OAAO,KAON,cAAc;AAyBf,OAAO,KAAK,EACV,oBAAoB,EAErB,sCAAkC;AAEnC,eAAO,MAAM,iBAAiB;;;;;;;;iFAmR7B,CAAC"}
1
+ {"version":3,"file":"BottomSheetDialog.d.mts","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.tsx"],"names":[],"mappings":"AAOA,OAAO,KAON,cAAc;AAyBf,OAAO,KAAK,EACV,oBAAoB,EAErB,sCAAkC;AAEnC,eAAO,MAAM,iBAAiB;;;;;;;;iFAuR7B,CAAC"}
@@ -199,9 +199,9 @@ export const BottomSheetDialog = forwardRef(({ children, isFullscreen = false, i
199
199
  return (<KeyboardAvoidingView style={tw.style('absolute bottom-0 inset-x-0')} behavior={Platform.OS === 'ios' ? 'padding' : undefined} keyboardVerticalOffset={Platform.OS === 'ios' ? -screenBottomPadding : frameY} enabled={keyboardAvoidingViewEnabled} {...props}>
200
200
  <GestureDetector gesture={gestureHandler}>
201
201
  <Animated.View onLayout={updateSheetHeight} style={combinedSheetStyle}>
202
- {isInteractable && (<View style={tw.style('self-stretch items-center p-1')}>
203
- <View style={tw.style('h-1 w-10 rounded-sm bg-border-muted')}/>
204
- </View>)}
202
+ <View style={tw.style('self-stretch items-center p-1', !isInteractable && 'opacity-0')} testID="bottom-sheet-dialog-drag-handle">
203
+ <View style={tw.style('h-1 w-10 rounded-sm bg-border-muted')}/>
204
+ </View>
205
205
  {children}
206
206
  </Animated.View>
207
207
  </GestureDetector>
@@ -1 +1 @@
1
- {"version":3,"file":"BottomSheetDialog.mjs","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.tsx"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,KAAK,EACL,WAAW,EACX,QAAQ,EACT,sDAAsD;AACvD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,yCAAyC;;;AAEzE,OAAO,QAAO,EACZ,UAAU,EACV,WAAW,EACX,SAAS,EACT,OAAO,EACP,MAAM,EACN,mBAAmB,EACpB,cAAc;;AACf,OAAO,EAEL,IAAI,EACJ,QAAQ,EACR,oBAAoB,EACrB,qBAAqB;AACtB,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,qCAAqC;AACx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AAC,CAC/C,QAAQ,CAAC,CAAC,QAAQ,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CACxD,sBAAsB,CAAC,CACrB,QAAQ,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,MAAM,CACtD,CACD,OAAO,CAAC,CAAC,2BAA2B,CAAC,CACrC,IAAI,KAAK,CAAC,CAEV;QAAA,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,CACvC;UAAA,CAAC,QAAQ,CAAC,IAAI,CACZ,QAAQ,CAAC,CAAC,iBAAiB,CAAC,CAC5B,KAAK,CAAC,CAAC,kBAAkB,CAAC,CAE1B;YAAA,CAAC,cAAc,IAAI,CACjB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC,CACrD;gBAAA,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC,EAC/D;cAAA,EAAE,IAAI,CAAC,CACR,CACD;YAAA,CAAC,QAAQ,CACX;UAAA,EAAE,QAAQ,CAAC,IAAI,CACjB;QAAA,EAAE,eAAe,CACnB;MAAA,EAAE,oBAAoB,CAAC,CACxB,CAAC;AACJ,CAAC,CACF,CAAC","sourcesContent":["import {\n Theme,\n useTailwind,\n useTheme,\n} from '@metamask-previews/design-system-twrnc-preset';\nimport { darkTheme, lightTheme } from '@metamask-previews/design-tokens';\nimport { debounce } from 'lodash';\nimport React, {\n forwardRef,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useImperativeHandle,\n} from 'react';\nimport {\n LayoutChangeEvent,\n View,\n Platform,\n KeyboardAvoidingView,\n} from 'react-native';\nimport { Gesture, GestureDetector } from 'react-native-gesture-handler';\nimport Animated, {\n useAnimatedStyle,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated';\nimport {\n useSafeAreaFrame,\n useSafeAreaInsets,\n} from 'react-native-safe-area-context';\nimport { scheduleOnRN } from 'react-native-worklets';\n\n// Internal dependencies.\nimport {\n DEFAULT_BOTTOMSHEETDIALOG_DISPLAY_DURATION,\n DEFAULT_BOTTOMSHEETDIALOG_DISMISSTHRESHOLD,\n DEFAULT_BOTTOMSHEETDIALOG_SWIPETHRESHOLD_DURATION,\n} from './BottomSheetDialog.constants';\nimport type {\n BottomSheetDialogRef,\n BottomSheetDialogProps,\n} from './BottomSheetDialog.types';\n\nexport const BottomSheetDialog = forwardRef<\n BottomSheetDialogRef,\n BottomSheetDialogProps\n>(\n (\n {\n children,\n isFullscreen = false,\n isInteractable = true,\n keyboardAvoidingViewEnabled = true,\n onClose,\n onOpen,\n style,\n twClassName,\n ...props\n },\n ref,\n ) => {\n const tw = useTailwind();\n const currentTheme = useTheme();\n const shadowLg =\n currentTheme === Theme.Light\n ? lightTheme.shadows.size.lg\n : darkTheme.shadows.size.lg;\n\n const { top: screenTopPadding, bottom: screenBottomPadding } =\n useSafeAreaInsets();\n const { y: frameY, height: screenHeight } = useSafeAreaFrame();\n\n const maxSheetHeight = screenHeight - screenTopPadding;\n // X and Y values start on top left of the DIALOG\n // currentYOffset will be used to animate the Y position of the Dialog\n const currentYOffset = useSharedValue(screenHeight);\n const topOfDialogYValue = useSharedValue(0);\n const bottomOfDialogYValue = useSharedValue(screenHeight);\n const gestureStartYOffset = useSharedValue(0);\n const isMounted = useRef(false);\n\n const onOpenCB = useCallback(() => {\n onOpen?.();\n }, [onOpen]);\n const onCloseCB = useCallback(() => {\n onClose?.();\n }, [onClose]);\n\n const onCloseDialog = useCallback(\n (callback?: () => void) => {\n currentYOffset.value = withTiming(\n bottomOfDialogYValue.value,\n { duration: DEFAULT_BOTTOMSHEETDIALOG_DISPLAY_DURATION },\n () => {\n scheduleOnRN(onCloseCB);\n if (callback) {\n scheduleOnRN(callback);\n }\n },\n );\n // Ref values do not affect deps.\n },\n [onCloseCB],\n );\n\n const gestureHandler = useMemo(() => {\n // These gesture callbacks need explicit 'worklet' directives because this\n // package ships a pre-built dist compiled by ts-bridge (tsc), which emits the\n // gesture chain as a namespaced call (react_native_gesture_handler_1.Gesture).\n // The consumer's Reanimated/Worklets Babel plugin does run over dist (that's\n // why useAnimatedStyle below works), but its gesture auto-detection doesn't\n // recognize that compiled namespaced form, so without these directives the\n // callbacks run on the JS thread and slow drags lag behind the finger.\n const gesture = Gesture.Pan()\n .enabled(isInteractable)\n .onStart(() => {\n 'worklet';\n\n // Starts tracking vertical position of gesture.\n gestureStartYOffset.value = currentYOffset.value;\n })\n .onUpdate((event) => {\n 'worklet';\n\n const { translationY } = event;\n currentYOffset.value = gestureStartYOffset.value + translationY;\n // If gesture Y value goes above the bottom of Dialog Y value(bottom of dialog),\n // which means the gesture is currently below the bottom of the dialog,\n // sets it to bottom of Dialog Y value\n if (currentYOffset.value >= bottomOfDialogYValue.value) {\n currentYOffset.value = bottomOfDialogYValue.value;\n }\n // If gesture Y value goes below the top of Dialog Y value(top of dialog),\n // which means the gesture is currently above the top of the dialog,\n // sets it to top of Dialog Y value\n if (currentYOffset.value <= topOfDialogYValue.value) {\n currentYOffset.value = topOfDialogYValue.value;\n }\n })\n .onEnd((event) => {\n 'worklet';\n\n const { translationY, velocityY } = event;\n // finalYOffset is used to animate the Y position of the Dialog after the gesture event\n let finalYOffset: number;\n // Measuring dismissing swipe action\n const latestOffset = gestureStartYOffset.value + translationY;\n // Check if the swipe distance reach the dismiss offset threshold,\n // which is currently 60% of sheet height\n const hasReachedDismissOffset =\n latestOffset >\n bottomOfDialogYValue.value *\n DEFAULT_BOTTOMSHEETDIALOG_DISMISSTHRESHOLD;\n // Check if the gesture's vertical speed has reached the threshold to determine a swipe action\n const hasReachedSwipeThreshold =\n Math.abs(velocityY) >\n DEFAULT_BOTTOMSHEETDIALOG_SWIPETHRESHOLD_DURATION;\n const isQuickDismissing = velocityY > 0;\n\n // If user is swiping\n if (hasReachedSwipeThreshold) {\n // Quick swipe takes priority\n if (isQuickDismissing) {\n finalYOffset = bottomOfDialogYValue.value;\n } else {\n finalYOffset = topOfDialogYValue.value;\n }\n } else if (hasReachedDismissOffset) {\n finalYOffset = bottomOfDialogYValue.value;\n } else {\n finalYOffset = topOfDialogYValue.value;\n }\n\n const isDismissed = finalYOffset === bottomOfDialogYValue.value;\n\n if (isDismissed) {\n scheduleOnRN(onCloseDialog);\n } else {\n // Only animate dialog to a certain Y position instead\n currentYOffset.value = withTiming(finalYOffset, {\n duration: DEFAULT_BOTTOMSHEETDIALOG_DISPLAY_DURATION,\n });\n }\n });\n\n return gesture;\n }, [\n isInteractable,\n currentYOffset,\n gestureStartYOffset,\n bottomOfDialogYValue,\n topOfDialogYValue,\n onCloseDialog,\n ]);\n\n // Animate in sheet on initial render.\n const onOpenDialog = (callback?: () => void) => {\n // Starts setting the Y position of the dialog to the bottom of the dialog\n currentYOffset.value = bottomOfDialogYValue.value;\n // Animate the Y position to the top of the dialog, then call onOpenCB\n currentYOffset.value = withTiming(\n topOfDialogYValue.value,\n {\n duration: DEFAULT_BOTTOMSHEETDIALOG_DISPLAY_DURATION,\n },\n () => {\n scheduleOnRN(onOpenCB);\n if (callback) {\n scheduleOnRN(callback);\n }\n },\n );\n };\n\n const onDebouncedCloseDialog = useMemo(\n // Prevent hide from being called multiple times. Potentially caused by taps in quick succession.\n () => debounce(onCloseDialog, 2000, { leading: true }),\n [onCloseDialog],\n );\n\n useEffect(\n () =>\n // Automatically handles animation when content changes\n // Disable for now since network switches causes the screen to hang with this on.\n // LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);\n onDebouncedCloseDialog.cancel(),\n [children, onDebouncedCloseDialog],\n );\n\n const updateSheetHeight = (e: LayoutChangeEvent) => {\n const { height } = e.nativeEvent.layout;\n bottomOfDialogYValue.value = height;\n\n if (!isMounted.current) {\n isMounted.current = true;\n onOpenDialog();\n }\n };\n\n const animatedSheetStyle = useAnimatedStyle(\n () => ({\n transform: [\n {\n translateY: currentYOffset.value,\n },\n ],\n }),\n [],\n );\n\n const sheetStyle = useMemo(\n () => [\n tw.style(\n 'bg-elevated1',\n 'rounded-t-[32px] overflow-hidden border border-muted border-b-0',\n twClassName,\n ),\n {\n maxHeight: maxSheetHeight,\n paddingBottom: Platform.select({\n ios: screenBottomPadding,\n macos: screenBottomPadding,\n default: screenBottomPadding + 16,\n }),\n ...(isFullscreen && { height: maxSheetHeight }),\n ...shadowLg,\n },\n style,\n ],\n\n [\n tw,\n maxSheetHeight,\n screenBottomPadding,\n isFullscreen,\n shadowLg,\n style,\n twClassName,\n ],\n );\n\n const combinedSheetStyle = useMemo(\n () => [...sheetStyle, animatedSheetStyle],\n\n [sheetStyle],\n );\n\n useImperativeHandle(ref, () => ({\n onOpenDialog,\n onCloseDialog,\n }));\n\n return (\n <KeyboardAvoidingView\n style={tw.style('absolute bottom-0 inset-x-0')}\n behavior={Platform.OS === 'ios' ? 'padding' : undefined}\n keyboardVerticalOffset={\n Platform.OS === 'ios' ? -screenBottomPadding : frameY\n }\n enabled={keyboardAvoidingViewEnabled}\n {...props}\n >\n <GestureDetector gesture={gestureHandler}>\n <Animated.View\n onLayout={updateSheetHeight}\n style={combinedSheetStyle}\n >\n {isInteractable && (\n <View style={tw.style('self-stretch items-center p-1')}>\n <View style={tw.style('h-1 w-10 rounded-sm bg-border-muted')} />\n </View>\n )}\n {children}\n </Animated.View>\n </GestureDetector>\n </KeyboardAvoidingView>\n );\n },\n);\n"]}
1
+ {"version":3,"file":"BottomSheetDialog.mjs","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.tsx"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,KAAK,EACL,WAAW,EACX,QAAQ,EACT,sDAAsD;AACvD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,yCAAyC;;;AAEzE,OAAO,QAAO,EACZ,UAAU,EACV,WAAW,EACX,SAAS,EACT,OAAO,EACP,MAAM,EACN,mBA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AAY;QACZ,aAAa;KACd,CAAC,CAAC,CAAC;IAEJ,OAAO,CACL,CAAC,oBAAoB,CACnB,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC,CAC/C,QAAQ,CAAC,CAAC,QAAQ,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CACxD,sBAAsB,CAAC,CACrB,QAAQ,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,MAAM,CACtD,CACD,OAAO,CAAC,CAAC,2BAA2B,CAAC,CACrC,IAAI,KAAK,CAAC,CAEV;QAAA,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,CACvC;UAAA,CAAC,QAAQ,CAAC,IAAI,CACZ,QAAQ,CAAC,CAAC,iBAAiB,CAAC,CAC5B,KAAK,CAAC,CAAC,kBAAkB,CAAC,CAE1B;YAAA,CAAC,IAAI,CACH,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CACb,+BAA+B,EAC/B,CAAC,cAAc,IAAI,WAAW,CAC/B,CAAC,CACF,MAAM,CAAC,iCAAiC,CAExC;cAAA,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC,EAC/D;YAAA,EAAE,IAAI,CACN;YAAA,CAAC,QAAQ,CACX;UAAA,EAAE,QAAQ,CAAC,IAAI,CACjB;QAAA,EAAE,eAAe,CACnB;MAAA,EAAE,oBAAoB,CAAC,CACxB,CAAC;AACJ,CAAC,CACF,CAAC","sourcesContent":["import {\n Theme,\n useTailwind,\n useTheme,\n} from '@metamask-previews/design-system-twrnc-preset';\nimport { darkTheme, lightTheme } from '@metamask-previews/design-tokens';\nimport { debounce } from 'lodash';\nimport React, {\n forwardRef,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useImperativeHandle,\n} from 'react';\nimport {\n LayoutChangeEvent,\n View,\n Platform,\n KeyboardAvoidingView,\n} from 'react-native';\nimport { Gesture, GestureDetector } from 'react-native-gesture-handler';\nimport Animated, {\n useAnimatedStyle,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated';\nimport {\n useSafeAreaFrame,\n useSafeAreaInsets,\n} from 'react-native-safe-area-context';\nimport { scheduleOnRN } from 'react-native-worklets';\n\n// Internal dependencies.\nimport {\n DEFAULT_BOTTOMSHEETDIALOG_DISPLAY_DURATION,\n DEFAULT_BOTTOMSHEETDIALOG_DISMISSTHRESHOLD,\n DEFAULT_BOTTOMSHEETDIALOG_SWIPETHRESHOLD_DURATION,\n} from './BottomSheetDialog.constants';\nimport type {\n BottomSheetDialogRef,\n BottomSheetDialogProps,\n} from './BottomSheetDialog.types';\n\nexport const BottomSheetDialog = forwardRef<\n BottomSheetDialogRef,\n BottomSheetDialogProps\n>(\n (\n {\n children,\n isFullscreen = false,\n isInteractable = true,\n keyboardAvoidingViewEnabled = true,\n onClose,\n onOpen,\n style,\n twClassName,\n ...props\n },\n ref,\n ) => {\n const tw = useTailwind();\n const currentTheme = useTheme();\n const shadowLg =\n currentTheme === Theme.Light\n ? lightTheme.shadows.size.lg\n : darkTheme.shadows.size.lg;\n\n const { top: screenTopPadding, bottom: screenBottomPadding } =\n useSafeAreaInsets();\n const { y: frameY, height: screenHeight } = useSafeAreaFrame();\n\n const maxSheetHeight = screenHeight - screenTopPadding;\n // X and Y values start on top left of the DIALOG\n // currentYOffset will be used to animate the Y position of the Dialog\n const currentYOffset = useSharedValue(screenHeight);\n const topOfDialogYValue = useSharedValue(0);\n const bottomOfDialogYValue = useSharedValue(screenHeight);\n const gestureStartYOffset = useSharedValue(0);\n const isMounted = useRef(false);\n\n const onOpenCB = useCallback(() => {\n onOpen?.();\n }, [onOpen]);\n const onCloseCB = useCallback(() => {\n onClose?.();\n }, [onClose]);\n\n const onCloseDialog = useCallback(\n (callback?: () => void) => {\n currentYOffset.value = withTiming(\n bottomOfDialogYValue.value,\n { duration: DEFAULT_BOTTOMSHEETDIALOG_DISPLAY_DURATION },\n () => {\n scheduleOnRN(onCloseCB);\n if (callback) {\n scheduleOnRN(callback);\n }\n },\n );\n // Ref values do not affect deps.\n },\n [onCloseCB],\n );\n\n const gestureHandler = useMemo(() => {\n // These gesture callbacks need explicit 'worklet' directives because this\n // package ships a pre-built dist compiled by ts-bridge (tsc), which emits the\n // gesture chain as a namespaced call (react_native_gesture_handler_1.Gesture).\n // The consumer's Reanimated/Worklets Babel plugin does run over dist (that's\n // why useAnimatedStyle below works), but its gesture auto-detection doesn't\n // recognize that compiled namespaced form, so without these directives the\n // callbacks run on the JS thread and slow drags lag behind the finger.\n const gesture = Gesture.Pan()\n .enabled(isInteractable)\n .onStart(() => {\n 'worklet';\n\n // Starts tracking vertical position of gesture.\n gestureStartYOffset.value = currentYOffset.value;\n })\n .onUpdate((event) => {\n 'worklet';\n\n const { translationY } = event;\n currentYOffset.value = gestureStartYOffset.value + translationY;\n // If gesture Y value goes above the bottom of Dialog Y value(bottom of dialog),\n // which means the gesture is currently below the bottom of the dialog,\n // sets it to bottom of Dialog Y value\n if (currentYOffset.value >= bottomOfDialogYValue.value) {\n currentYOffset.value = bottomOfDialogYValue.value;\n }\n // If gesture Y value goes below the top of Dialog Y value(top of dialog),\n // which means the gesture is currently above the top of the dialog,\n // sets it to top of Dialog Y value\n if (currentYOffset.value <= topOfDialogYValue.value) {\n currentYOffset.value = topOfDialogYValue.value;\n }\n })\n .onEnd((event) => {\n 'worklet';\n\n const { translationY, velocityY } = event;\n // finalYOffset is used to animate the Y position of the Dialog after the gesture event\n let finalYOffset: number;\n // Measuring dismissing swipe action\n const latestOffset = gestureStartYOffset.value + translationY;\n // Check if the swipe distance reach the dismiss offset threshold,\n // which is currently 60% of sheet height\n const hasReachedDismissOffset =\n latestOffset >\n bottomOfDialogYValue.value *\n DEFAULT_BOTTOMSHEETDIALOG_DISMISSTHRESHOLD;\n // Check if the gesture's vertical speed has reached the threshold to determine a swipe action\n const hasReachedSwipeThreshold =\n Math.abs(velocityY) >\n DEFAULT_BOTTOMSHEETDIALOG_SWIPETHRESHOLD_DURATION;\n const isQuickDismissing = velocityY > 0;\n\n // If user is swiping\n if (hasReachedSwipeThreshold) {\n // Quick swipe takes priority\n if (isQuickDismissing) {\n finalYOffset = bottomOfDialogYValue.value;\n } else {\n finalYOffset = topOfDialogYValue.value;\n }\n } else if (hasReachedDismissOffset) {\n finalYOffset = bottomOfDialogYValue.value;\n } else {\n finalYOffset = topOfDialogYValue.value;\n }\n\n const isDismissed = finalYOffset === bottomOfDialogYValue.value;\n\n if (isDismissed) {\n scheduleOnRN(onCloseDialog);\n } else {\n // Only animate dialog to a certain Y position instead\n currentYOffset.value = withTiming(finalYOffset, {\n duration: DEFAULT_BOTTOMSHEETDIALOG_DISPLAY_DURATION,\n });\n }\n });\n\n return gesture;\n }, [\n isInteractable,\n currentYOffset,\n gestureStartYOffset,\n bottomOfDialogYValue,\n topOfDialogYValue,\n onCloseDialog,\n ]);\n\n // Animate in sheet on initial render.\n const onOpenDialog = (callback?: () => void) => {\n // Starts setting the Y position of the dialog to the bottom of the dialog\n currentYOffset.value = bottomOfDialogYValue.value;\n // Animate the Y position to the top of the dialog, then call onOpenCB\n currentYOffset.value = withTiming(\n topOfDialogYValue.value,\n {\n duration: DEFAULT_BOTTOMSHEETDIALOG_DISPLAY_DURATION,\n },\n () => {\n scheduleOnRN(onOpenCB);\n if (callback) {\n scheduleOnRN(callback);\n }\n },\n );\n };\n\n const onDebouncedCloseDialog = useMemo(\n // Prevent hide from being called multiple times. Potentially caused by taps in quick succession.\n () => debounce(onCloseDialog, 2000, { leading: true }),\n [onCloseDialog],\n );\n\n useEffect(\n () =>\n // Automatically handles animation when content changes\n // Disable for now since network switches causes the screen to hang with this on.\n // LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);\n onDebouncedCloseDialog.cancel(),\n [children, onDebouncedCloseDialog],\n );\n\n const updateSheetHeight = (e: LayoutChangeEvent) => {\n const { height } = e.nativeEvent.layout;\n bottomOfDialogYValue.value = height;\n\n if (!isMounted.current) {\n isMounted.current = true;\n onOpenDialog();\n }\n };\n\n const animatedSheetStyle = useAnimatedStyle(\n () => ({\n transform: [\n {\n translateY: currentYOffset.value,\n },\n ],\n }),\n [],\n );\n\n const sheetStyle = useMemo(\n () => [\n tw.style(\n 'bg-elevated1',\n 'rounded-t-[32px] overflow-hidden border border-muted border-b-0',\n twClassName,\n ),\n {\n maxHeight: maxSheetHeight,\n paddingBottom: Platform.select({\n ios: screenBottomPadding,\n macos: screenBottomPadding,\n default: screenBottomPadding + 16,\n }),\n ...(isFullscreen && { height: maxSheetHeight }),\n ...shadowLg,\n },\n style,\n ],\n\n [\n tw,\n maxSheetHeight,\n screenBottomPadding,\n isFullscreen,\n shadowLg,\n style,\n twClassName,\n ],\n );\n\n const combinedSheetStyle = useMemo(\n () => [...sheetStyle, animatedSheetStyle],\n\n [sheetStyle],\n );\n\n useImperativeHandle(ref, () => ({\n onOpenDialog,\n onCloseDialog,\n }));\n\n return (\n <KeyboardAvoidingView\n style={tw.style('absolute bottom-0 inset-x-0')}\n behavior={Platform.OS === 'ios' ? 'padding' : undefined}\n keyboardVerticalOffset={\n Platform.OS === 'ios' ? -screenBottomPadding : frameY\n }\n enabled={keyboardAvoidingViewEnabled}\n {...props}\n >\n <GestureDetector gesture={gestureHandler}>\n <Animated.View\n onLayout={updateSheetHeight}\n style={combinedSheetStyle}\n >\n <View\n style={tw.style(\n 'self-stretch items-center p-1',\n !isInteractable && 'opacity-0',\n )}\n testID=\"bottom-sheet-dialog-drag-handle\"\n >\n <View style={tw.style('h-1 w-10 rounded-sm bg-border-muted')} />\n </View>\n {children}\n </Animated.View>\n </GestureDetector>\n </KeyboardAvoidingView>\n );\n },\n);\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"BottomSheetDialog.types.cjs","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.types.ts"],"names":[],"mappings":"","sourcesContent":["// Third party dependencies.\nimport type { ViewProps } from 'react-native';\n\n/**\n * BottomSheetDialog component props.\n */\nexport type BottomSheetDialogProps = {\n /**\n * Optional content to display inside the dialog.\n */\n children?: React.ReactNode;\n /**\n * Optional prop to toggle full screen state of BottomSheetDialog.\n *\n * @default false\n */\n isFullscreen?: boolean;\n /**\n * Optional boolean that indicates if the sheet is swippable.\n * This affects whether or not tapping on the overlay will dismiss\n * the sheet as well, and whether the drag handle indicator is shown.\n *\n * @default true\n */\n isInteractable?: boolean;\n /**\n * Optional boolean that indicates if the KeyboardAvoidingView is enabled.\n *\n * @default true\n */\n keyboardAvoidingViewEnabled?: boolean;\n /**\n * Optional callback that gets triggered when the sheet is closed.\n */\n onClose?: (hasPendingAction?: boolean) => void;\n /**\n * Optional callback that gets triggered when the sheet is opened.\n */\n onOpen?: (hasPendingAction?: boolean) => void;\n /**\n * Tailwind CSS classes for the dialog container.\n */\n twClassName?: string;\n} & ViewProps;\n\n/**\n * Ref handle for imperative control of the BottomSheetDialog.\n */\nexport type BottomSheetDialogRef = {\n /**\n * Imperatively close the dialog with an optional callback after animation completes.\n */\n onCloseDialog: (callback?: () => void) => void;\n /**\n * Imperatively open the dialog with an optional callback after animation completes.\n */\n onOpenDialog: (callback?: () => void) => void;\n};\n"]}
1
+ {"version":3,"file":"BottomSheetDialog.types.cjs","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.types.ts"],"names":[],"mappings":"","sourcesContent":["// Third party dependencies.\nimport type { ViewProps } from 'react-native';\n\n/**\n * BottomSheetDialog component props.\n */\nexport type BottomSheetDialogProps = {\n /**\n * Optional content to display inside the dialog.\n */\n children?: React.ReactNode;\n /**\n * Optional prop to toggle full screen state of BottomSheetDialog.\n *\n * @default false\n */\n isFullscreen?: boolean;\n /**\n * Optional boolean that indicates if the sheet is swippable.\n * This affects whether or not tapping on the overlay will dismiss\n * the sheet as well, and whether the drag handle indicator is visible.\n * When false, the drag handle is not visible.\n *\n * @default true\n */\n isInteractable?: boolean;\n /**\n * Optional boolean that indicates if the KeyboardAvoidingView is enabled.\n *\n * @default true\n */\n keyboardAvoidingViewEnabled?: boolean;\n /**\n * Optional callback that gets triggered when the sheet is closed.\n */\n onClose?: (hasPendingAction?: boolean) => void;\n /**\n * Optional callback that gets triggered when the sheet is opened.\n */\n onOpen?: (hasPendingAction?: boolean) => void;\n /**\n * Tailwind CSS classes for the dialog container.\n */\n twClassName?: string;\n} & ViewProps;\n\n/**\n * Ref handle for imperative control of the BottomSheetDialog.\n */\nexport type BottomSheetDialogRef = {\n /**\n * Imperatively close the dialog with an optional callback after animation completes.\n */\n onCloseDialog: (callback?: () => void) => void;\n /**\n * Imperatively open the dialog with an optional callback after animation completes.\n */\n onOpenDialog: (callback?: () => void) => void;\n};\n"]}
@@ -16,7 +16,8 @@ export type BottomSheetDialogProps = {
16
16
  /**
17
17
  * Optional boolean that indicates if the sheet is swippable.
18
18
  * This affects whether or not tapping on the overlay will dismiss
19
- * the sheet as well, and whether the drag handle indicator is shown.
19
+ * the sheet as well, and whether the drag handle indicator is visible.
20
+ * When false, the drag handle is not visible.
20
21
  *
21
22
  * @default true
22
23
  */
@@ -1 +1 @@
1
- {"version":3,"file":"BottomSheetDialog.types.d.cts","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,qBAAqB;AAE9C;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC;;OAEG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B;;;;OAIG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;OAIG;IACH,2BAA2B,CAAC,EAAE,OAAO,CAAC;IACtC;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,gBAAgB,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAC/C;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,gBAAgB,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAC9C;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,GAAG,SAAS,CAAC;AAEd;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC;;OAEG;IACH,aAAa,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;IAC/C;;OAEG;IACH,YAAY,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;CAC/C,CAAC"}
1
+ {"version":3,"file":"BottomSheetDialog.types.d.cts","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,qBAAqB;AAE9C;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC;;OAEG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B;;;;OAIG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;OAIG;IACH,2BAA2B,CAAC,EAAE,OAAO,CAAC;IACtC;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,gBAAgB,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAC/C;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,gBAAgB,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAC9C;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,GAAG,SAAS,CAAC;AAEd;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC;;OAEG;IACH,aAAa,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;IAC/C;;OAEG;IACH,YAAY,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;CAC/C,CAAC"}
@@ -16,7 +16,8 @@ export type BottomSheetDialogProps = {
16
16
  /**
17
17
  * Optional boolean that indicates if the sheet is swippable.
18
18
  * This affects whether or not tapping on the overlay will dismiss
19
- * the sheet as well, and whether the drag handle indicator is shown.
19
+ * the sheet as well, and whether the drag handle indicator is visible.
20
+ * When false, the drag handle is not visible.
20
21
  *
21
22
  * @default true
22
23
  */
@@ -1 +1 @@
1
- {"version":3,"file":"BottomSheetDialog.types.d.mts","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,qBAAqB;AAE9C;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC;;OAEG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B;;;;OAIG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;OAIG;IACH,2BAA2B,CAAC,EAAE,OAAO,CAAC;IACtC;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,gBAAgB,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAC/C;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,gBAAgB,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAC9C;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,GAAG,SAAS,CAAC;AAEd;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC;;OAEG;IACH,aAAa,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;IAC/C;;OAEG;IACH,YAAY,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;CAC/C,CAAC"}
1
+ {"version":3,"file":"BottomSheetDialog.types.d.mts","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,qBAAqB;AAE9C;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC;;OAEG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B;;;;OAIG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;OAIG;IACH,2BAA2B,CAAC,EAAE,OAAO,CAAC;IACtC;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,gBAAgB,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAC/C;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,gBAAgB,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAC9C;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,GAAG,SAAS,CAAC;AAEd;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC;;OAEG;IACH,aAAa,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;IAC/C;;OAEG;IACH,YAAY,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;CAC/C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"BottomSheetDialog.types.mjs","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.types.ts"],"names":[],"mappings":"","sourcesContent":["// Third party dependencies.\nimport type { ViewProps } from 'react-native';\n\n/**\n * BottomSheetDialog component props.\n */\nexport type BottomSheetDialogProps = {\n /**\n * Optional content to display inside the dialog.\n */\n children?: React.ReactNode;\n /**\n * Optional prop to toggle full screen state of BottomSheetDialog.\n *\n * @default false\n */\n isFullscreen?: boolean;\n /**\n * Optional boolean that indicates if the sheet is swippable.\n * This affects whether or not tapping on the overlay will dismiss\n * the sheet as well, and whether the drag handle indicator is shown.\n *\n * @default true\n */\n isInteractable?: boolean;\n /**\n * Optional boolean that indicates if the KeyboardAvoidingView is enabled.\n *\n * @default true\n */\n keyboardAvoidingViewEnabled?: boolean;\n /**\n * Optional callback that gets triggered when the sheet is closed.\n */\n onClose?: (hasPendingAction?: boolean) => void;\n /**\n * Optional callback that gets triggered when the sheet is opened.\n */\n onOpen?: (hasPendingAction?: boolean) => void;\n /**\n * Tailwind CSS classes for the dialog container.\n */\n twClassName?: string;\n} & ViewProps;\n\n/**\n * Ref handle for imperative control of the BottomSheetDialog.\n */\nexport type BottomSheetDialogRef = {\n /**\n * Imperatively close the dialog with an optional callback after animation completes.\n */\n onCloseDialog: (callback?: () => void) => void;\n /**\n * Imperatively open the dialog with an optional callback after animation completes.\n */\n onOpenDialog: (callback?: () => void) => void;\n};\n"]}
1
+ {"version":3,"file":"BottomSheetDialog.types.mjs","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.types.ts"],"names":[],"mappings":"","sourcesContent":["// Third party dependencies.\nimport type { ViewProps } from 'react-native';\n\n/**\n * BottomSheetDialog component props.\n */\nexport type BottomSheetDialogProps = {\n /**\n * Optional content to display inside the dialog.\n */\n children?: React.ReactNode;\n /**\n * Optional prop to toggle full screen state of BottomSheetDialog.\n *\n * @default false\n */\n isFullscreen?: boolean;\n /**\n * Optional boolean that indicates if the sheet is swippable.\n * This affects whether or not tapping on the overlay will dismiss\n * the sheet as well, and whether the drag handle indicator is visible.\n * When false, the drag handle is not visible.\n *\n * @default true\n */\n isInteractable?: boolean;\n /**\n * Optional boolean that indicates if the KeyboardAvoidingView is enabled.\n *\n * @default true\n */\n keyboardAvoidingViewEnabled?: boolean;\n /**\n * Optional callback that gets triggered when the sheet is closed.\n */\n onClose?: (hasPendingAction?: boolean) => void;\n /**\n * Optional callback that gets triggered when the sheet is opened.\n */\n onOpen?: (hasPendingAction?: boolean) => void;\n /**\n * Tailwind CSS classes for the dialog container.\n */\n twClassName?: string;\n} & ViewProps;\n\n/**\n * Ref handle for imperative control of the BottomSheetDialog.\n */\nexport type BottomSheetDialogRef = {\n /**\n * Imperatively close the dialog with an optional callback after animation completes.\n */\n onCloseDialog: (callback?: () => void) => void;\n /**\n * Imperatively open the dialog with an optional callback after animation completes.\n */\n onOpenDialog: (callback?: () => void) => void;\n};\n"]}
@@ -20,14 +20,13 @@ exports.SLIDER_LABEL_LINE_HEIGHT = 20;
20
20
  /** Bottom padding when range labels may render (RANGE_LABEL_TOP + label height). */
21
21
  exports.SLIDER_BOTTOM_PADDING = exports.RANGE_LABEL_TOP + exports.SLIDER_LABEL_LINE_HEIGHT;
22
22
  /**
23
- * Default horizontal inset on the root container; equals |THUMB_LEFT_OFFSET| so
24
- * the thumb can overhang at min/max without clipping.
23
+ * Default horizontal inset on the root container. The thumb stays on the track
24
+ * at both ends, so no overhang margin is required.
25
25
  */
26
- exports.SLIDER_TRACK_INSET = Math.abs(exports.THUMB_LEFT_OFFSET);
26
+ exports.SLIDER_TRACK_INSET = 0;
27
27
  /**
28
- * Edge marker inset (percent) so dots/labels at 0/100 stay on the visible track.
29
- * The thumb at 0% sits half its width (THUMB_SIZE / 2) left of the track start;
30
- * a small inset keeps edge markers from sitting under the thumb center.
28
+ * Edge marker inset (percent) so dots/labels at 0/100 stay on the visible track
29
+ * instead of sitting under the thumb when it rests at either end.
31
30
  */
32
31
  exports.DOT_EDGE_INSET_PERCENT = '2%';
33
32
  exports.DOT_EDGE_MAX_PERCENT = '98%';
@@ -1 +1 @@
1
- {"version":3,"file":"Slider.constants.cjs","sourceRoot":"","sources":["../../../src/components/Slider/Slider.constants.ts"],"names":[],"mappings":";;;AAEA,gFAAgF;AACnE,QAAA,UAAU,GAAG,EAAE,CAAC;AAChB,QAAA,gBAAgB,GAAG,CAAC,EAAE,CAAC;AACpC,6EAA6E;AAChE,QAAA,iBAAiB,GAAG,CAAC,EAAE,CAAC;AACxB,QAAA,mBAAmB,GAAG,wBAAgB,GAAG,kBAAU,CAAC;AACpD,QAAA,kBAAkB,GAAG,CAAC,CAAC;AACpC,6DAA6D;AAChD,QAAA,gBAAgB,GAAG,IAAI,CAAC;AACrC,iDAAiD;AACpC,QAAA,6BAA6B,GAAG,GAAG,CAAC;AACjD,oEAAoE;AACvD,QAAA,uBAAuB,GAAG,CAAC,CAAC;AAC5B,QAAA,eAAe,GAC1B,+BAAuB,GAAG,2BAAmB,GAAG,0BAAkB,CAAC;AACrE,uEAAuE;AAC1D,QAAA,wBAAwB,GAAG,EAAE,CAAC;AAC3C,oFAAoF;AACvE,QAAA,qBAAqB,GAAG,uBAAe,GAAG,gCAAwB,CAAC;AAChF;;;GAGG;AACU,QAAA,kBAAkB,GAAG,IAAI,CAAC,GAAG,CAAC,yBAAiB,CAAC,CAAC;AAC9D;;;;GAIG;AACU,QAAA,sBAAsB,GAAG,IAAI,CAAC;AAC9B,QAAA,oBAAoB,GAAG,KAAK,CAAC;AAE7B,QAAA,aAAa,GAA0B;IAClD,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE;IACvC,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE;IACxC,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE;IACxC,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE;IACxC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE;CAC5C,CAAC","sourcesContent":["import type { SliderMark } from '@metamask-previews/design-system-shared';\n\n/** Slider geometry and behavior defaults — not typography or spacing tokens. */\nexport const THUMB_SIZE = 32;\nexport const THUMB_TOP_OFFSET = -13;\n/** Negative offset so the thumb center aligns with the track start at 0%. */\nexport const THUMB_LEFT_OFFSET = -16;\nexport const THUMB_BOTTOM_OFFSET = THUMB_TOP_OFFSET + THUMB_SIZE;\nexport const THUMB_TO_LABEL_GAP = 8;\n/** Scale applied to the thumb while the user is dragging. */\nexport const THUMB_GRIP_SCALE = 1.12;\n/** Duration (ms) for thumb grip scale in/out. */\nexport const THUMB_GRIP_ANIMATION_DURATION = 100;\n/** Matches root `py-2` vertical padding on the slider container. */\nexport const SLIDER_VERTICAL_PADDING = 8;\nexport const RANGE_LABEL_TOP =\n SLIDER_VERTICAL_PADDING + THUMB_BOTTOM_OFFSET + THUMB_TO_LABEL_GAP;\n/** Approximate line height for BodyMd range labels below the track. */\nexport const SLIDER_LABEL_LINE_HEIGHT = 20;\n/** Bottom padding when range labels may render (RANGE_LABEL_TOP + label height). */\nexport const SLIDER_BOTTOM_PADDING = RANGE_LABEL_TOP + SLIDER_LABEL_LINE_HEIGHT;\n/**\n * Default horizontal inset on the root container; equals |THUMB_LEFT_OFFSET| so\n * the thumb can overhang at min/max without clipping.\n */\nexport const SLIDER_TRACK_INSET = Math.abs(THUMB_LEFT_OFFSET);\n/**\n * Edge marker inset (percent) so dots/labels at 0/100 stay on the visible track.\n * The thumb at 0% sits half its width (THUMB_SIZE / 2) left of the track start;\n * a small inset keeps edge markers from sitting under the thumb center.\n */\nexport const DOT_EDGE_INSET_PERCENT = '2%';\nexport const DOT_EDGE_MAX_PERCENT = '98%';\n\nexport const DEFAULT_MARKS: readonly SliderMark[] = [\n { step: 0, label: '0%', haptic: false },\n { step: 25, label: '25%', haptic: true },\n { step: 50, label: '50%', haptic: true },\n { step: 75, label: '75%', haptic: true },\n { step: 100, label: '100%', haptic: false },\n];\n"]}
1
+ {"version":3,"file":"Slider.constants.cjs","sourceRoot":"","sources":["../../../src/components/Slider/Slider.constants.ts"],"names":[],"mappings":";;;AAEA,gFAAgF;AACnE,QAAA,UAAU,GAAG,EAAE,CAAC;AAChB,QAAA,gBAAgB,GAAG,CAAC,EAAE,CAAC;AACpC,6EAA6E;AAChE,QAAA,iBAAiB,GAAG,CAAC,EAAE,CAAC;AACxB,QAAA,mBAAmB,GAAG,wBAAgB,GAAG,kBAAU,CAAC;AACpD,QAAA,kBAAkB,GAAG,CAAC,CAAC;AACpC,6DAA6D;AAChD,QAAA,gBAAgB,GAAG,IAAI,CAAC;AACrC,iDAAiD;AACpC,QAAA,6BAA6B,GAAG,GAAG,CAAC;AACjD,oEAAoE;AACvD,QAAA,uBAAuB,GAAG,CAAC,CAAC;AAC5B,QAAA,eAAe,GAC1B,+BAAuB,GAAG,2BAAmB,GAAG,0BAAkB,CAAC;AACrE,uEAAuE;AAC1D,QAAA,wBAAwB,GAAG,EAAE,CAAC;AAC3C,oFAAoF;AACvE,QAAA,qBAAqB,GAAG,uBAAe,GAAG,gCAAwB,CAAC;AAChF;;;GAGG;AACU,QAAA,kBAAkB,GAAG,CAAC,CAAC;AACpC;;;GAGG;AACU,QAAA,sBAAsB,GAAG,IAAI,CAAC;AAC9B,QAAA,oBAAoB,GAAG,KAAK,CAAC;AAE7B,QAAA,aAAa,GAA0B;IAClD,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE;IACvC,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE;IACxC,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE;IACxC,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE;IACxC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE;CAC5C,CAAC","sourcesContent":["import type { SliderMark } from '@metamask-previews/design-system-shared';\n\n/** Slider geometry and behavior defaults — not typography or spacing tokens. */\nexport const THUMB_SIZE = 32;\nexport const THUMB_TOP_OFFSET = -13;\n/** Negative offset so the thumb center aligns with the track start at 0%. */\nexport const THUMB_LEFT_OFFSET = -16;\nexport const THUMB_BOTTOM_OFFSET = THUMB_TOP_OFFSET + THUMB_SIZE;\nexport const THUMB_TO_LABEL_GAP = 8;\n/** Scale applied to the thumb while the user is dragging. */\nexport const THUMB_GRIP_SCALE = 1.12;\n/** Duration (ms) for thumb grip scale in/out. */\nexport const THUMB_GRIP_ANIMATION_DURATION = 100;\n/** Matches root `py-2` vertical padding on the slider container. */\nexport const SLIDER_VERTICAL_PADDING = 8;\nexport const RANGE_LABEL_TOP =\n SLIDER_VERTICAL_PADDING + THUMB_BOTTOM_OFFSET + THUMB_TO_LABEL_GAP;\n/** Approximate line height for BodyMd range labels below the track. */\nexport const SLIDER_LABEL_LINE_HEIGHT = 20;\n/** Bottom padding when range labels may render (RANGE_LABEL_TOP + label height). */\nexport const SLIDER_BOTTOM_PADDING = RANGE_LABEL_TOP + SLIDER_LABEL_LINE_HEIGHT;\n/**\n * Default horizontal inset on the root container. The thumb stays on the track\n * at both ends, so no overhang margin is required.\n */\nexport const SLIDER_TRACK_INSET = 0;\n/**\n * Edge marker inset (percent) so dots/labels at 0/100 stay on the visible track\n * instead of sitting under the thumb when it rests at either end.\n */\nexport const DOT_EDGE_INSET_PERCENT = '2%';\nexport const DOT_EDGE_MAX_PERCENT = '98%';\n\nexport const DEFAULT_MARKS: readonly SliderMark[] = [\n { step: 0, label: '0%', haptic: false },\n { step: 25, label: '25%', haptic: true },\n { step: 50, label: '50%', haptic: true },\n { step: 75, label: '75%', haptic: true },\n { step: 100, label: '100%', haptic: false },\n];\n"]}
@@ -18,14 +18,13 @@ export declare const SLIDER_LABEL_LINE_HEIGHT = 20;
18
18
  /** Bottom padding when range labels may render (RANGE_LABEL_TOP + label height). */
19
19
  export declare const SLIDER_BOTTOM_PADDING: number;
20
20
  /**
21
- * Default horizontal inset on the root container; equals |THUMB_LEFT_OFFSET| so
22
- * the thumb can overhang at min/max without clipping.
21
+ * Default horizontal inset on the root container. The thumb stays on the track
22
+ * at both ends, so no overhang margin is required.
23
23
  */
24
- export declare const SLIDER_TRACK_INSET: number;
24
+ export declare const SLIDER_TRACK_INSET = 0;
25
25
  /**
26
- * Edge marker inset (percent) so dots/labels at 0/100 stay on the visible track.
27
- * The thumb at 0% sits half its width (THUMB_SIZE / 2) left of the track start;
28
- * a small inset keeps edge markers from sitting under the thumb center.
26
+ * Edge marker inset (percent) so dots/labels at 0/100 stay on the visible track
27
+ * instead of sitting under the thumb when it rests at either end.
29
28
  */
30
29
  export declare const DOT_EDGE_INSET_PERCENT = "2%";
31
30
  export declare const DOT_EDGE_MAX_PERCENT = "98%";
@@ -1 +1 @@
1
- {"version":3,"file":"Slider.constants.d.cts","sourceRoot":"","sources":["../../../src/components/Slider/Slider.constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,gDAAgD;AAE1E,gFAAgF;AAChF,eAAO,MAAM,UAAU,KAAK,CAAC;AAC7B,eAAO,MAAM,gBAAgB,MAAM,CAAC;AACpC,6EAA6E;AAC7E,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,eAAO,MAAM,mBAAmB,QAAgC,CAAC;AACjE,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC,6DAA6D;AAC7D,eAAO,MAAM,gBAAgB,OAAO,CAAC;AACrC,iDAAiD;AACjD,eAAO,MAAM,6BAA6B,MAAM,CAAC;AACjD,oEAAoE;AACpE,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,eAAO,MAAM,eAAe,QACwC,CAAC;AACrE,uEAAuE;AACvE,eAAO,MAAM,wBAAwB,KAAK,CAAC;AAC3C,oFAAoF;AACpF,eAAO,MAAM,qBAAqB,QAA6C,CAAC;AAChF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,QAA8B,CAAC;AAC9D;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAC3C,eAAO,MAAM,oBAAoB,QAAQ,CAAC;AAE1C,eAAO,MAAM,aAAa,EAAE,SAAS,UAAU,EAM9C,CAAC"}
1
+ {"version":3,"file":"Slider.constants.d.cts","sourceRoot":"","sources":["../../../src/components/Slider/Slider.constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,gDAAgD;AAE1E,gFAAgF;AAChF,eAAO,MAAM,UAAU,KAAK,CAAC;AAC7B,eAAO,MAAM,gBAAgB,MAAM,CAAC;AACpC,6EAA6E;AAC7E,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,eAAO,MAAM,mBAAmB,QAAgC,CAAC;AACjE,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC,6DAA6D;AAC7D,eAAO,MAAM,gBAAgB,OAAO,CAAC;AACrC,iDAAiD;AACjD,eAAO,MAAM,6BAA6B,MAAM,CAAC;AACjD,oEAAoE;AACpE,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,eAAO,MAAM,eAAe,QACwC,CAAC;AACrE,uEAAuE;AACvE,eAAO,MAAM,wBAAwB,KAAK,CAAC;AAC3C,oFAAoF;AACpF,eAAO,MAAM,qBAAqB,QAA6C,CAAC;AAChF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC;;;GAGG;AACH,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAC3C,eAAO,MAAM,oBAAoB,QAAQ,CAAC;AAE1C,eAAO,MAAM,aAAa,EAAE,SAAS,UAAU,EAM9C,CAAC"}
@@ -18,14 +18,13 @@ export declare const SLIDER_LABEL_LINE_HEIGHT = 20;
18
18
  /** Bottom padding when range labels may render (RANGE_LABEL_TOP + label height). */
19
19
  export declare const SLIDER_BOTTOM_PADDING: number;
20
20
  /**
21
- * Default horizontal inset on the root container; equals |THUMB_LEFT_OFFSET| so
22
- * the thumb can overhang at min/max without clipping.
21
+ * Default horizontal inset on the root container. The thumb stays on the track
22
+ * at both ends, so no overhang margin is required.
23
23
  */
24
- export declare const SLIDER_TRACK_INSET: number;
24
+ export declare const SLIDER_TRACK_INSET = 0;
25
25
  /**
26
- * Edge marker inset (percent) so dots/labels at 0/100 stay on the visible track.
27
- * The thumb at 0% sits half its width (THUMB_SIZE / 2) left of the track start;
28
- * a small inset keeps edge markers from sitting under the thumb center.
26
+ * Edge marker inset (percent) so dots/labels at 0/100 stay on the visible track
27
+ * instead of sitting under the thumb when it rests at either end.
29
28
  */
30
29
  export declare const DOT_EDGE_INSET_PERCENT = "2%";
31
30
  export declare const DOT_EDGE_MAX_PERCENT = "98%";
@@ -1 +1 @@
1
- {"version":3,"file":"Slider.constants.d.mts","sourceRoot":"","sources":["../../../src/components/Slider/Slider.constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,gDAAgD;AAE1E,gFAAgF;AAChF,eAAO,MAAM,UAAU,KAAK,CAAC;AAC7B,eAAO,MAAM,gBAAgB,MAAM,CAAC;AACpC,6EAA6E;AAC7E,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,eAAO,MAAM,mBAAmB,QAAgC,CAAC;AACjE,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC,6DAA6D;AAC7D,eAAO,MAAM,gBAAgB,OAAO,CAAC;AACrC,iDAAiD;AACjD,eAAO,MAAM,6BAA6B,MAAM,CAAC;AACjD,oEAAoE;AACpE,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,eAAO,MAAM,eAAe,QACwC,CAAC;AACrE,uEAAuE;AACvE,eAAO,MAAM,wBAAwB,KAAK,CAAC;AAC3C,oFAAoF;AACpF,eAAO,MAAM,qBAAqB,QAA6C,CAAC;AAChF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,QAA8B,CAAC;AAC9D;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAC3C,eAAO,MAAM,oBAAoB,QAAQ,CAAC;AAE1C,eAAO,MAAM,aAAa,EAAE,SAAS,UAAU,EAM9C,CAAC"}
1
+ {"version":3,"file":"Slider.constants.d.mts","sourceRoot":"","sources":["../../../src/components/Slider/Slider.constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,gDAAgD;AAE1E,gFAAgF;AAChF,eAAO,MAAM,UAAU,KAAK,CAAC;AAC7B,eAAO,MAAM,gBAAgB,MAAM,CAAC;AACpC,6EAA6E;AAC7E,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,eAAO,MAAM,mBAAmB,QAAgC,CAAC;AACjE,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC,6DAA6D;AAC7D,eAAO,MAAM,gBAAgB,OAAO,CAAC;AACrC,iDAAiD;AACjD,eAAO,MAAM,6BAA6B,MAAM,CAAC;AACjD,oEAAoE;AACpE,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,eAAO,MAAM,eAAe,QACwC,CAAC;AACrE,uEAAuE;AACvE,eAAO,MAAM,wBAAwB,KAAK,CAAC;AAC3C,oFAAoF;AACpF,eAAO,MAAM,qBAAqB,QAA6C,CAAC;AAChF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC;;;GAGG;AACH,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAC3C,eAAO,MAAM,oBAAoB,QAAQ,CAAC;AAE1C,eAAO,MAAM,aAAa,EAAE,SAAS,UAAU,EAM9C,CAAC"}
@@ -17,14 +17,13 @@ export const SLIDER_LABEL_LINE_HEIGHT = 20;
17
17
  /** Bottom padding when range labels may render (RANGE_LABEL_TOP + label height). */
18
18
  export const SLIDER_BOTTOM_PADDING = RANGE_LABEL_TOP + SLIDER_LABEL_LINE_HEIGHT;
19
19
  /**
20
- * Default horizontal inset on the root container; equals |THUMB_LEFT_OFFSET| so
21
- * the thumb can overhang at min/max without clipping.
20
+ * Default horizontal inset on the root container. The thumb stays on the track
21
+ * at both ends, so no overhang margin is required.
22
22
  */
23
- export const SLIDER_TRACK_INSET = Math.abs(THUMB_LEFT_OFFSET);
23
+ export const SLIDER_TRACK_INSET = 0;
24
24
  /**
25
- * Edge marker inset (percent) so dots/labels at 0/100 stay on the visible track.
26
- * The thumb at 0% sits half its width (THUMB_SIZE / 2) left of the track start;
27
- * a small inset keeps edge markers from sitting under the thumb center.
25
+ * Edge marker inset (percent) so dots/labels at 0/100 stay on the visible track
26
+ * instead of sitting under the thumb when it rests at either end.
28
27
  */
29
28
  export const DOT_EDGE_INSET_PERCENT = '2%';
30
29
  export const DOT_EDGE_MAX_PERCENT = '98%';
@@ -1 +1 @@
1
- {"version":3,"file":"Slider.constants.mjs","sourceRoot":"","sources":["../../../src/components/Slider/Slider.constants.ts"],"names":[],"mappings":"AAEA,gFAAgF;AAChF,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,CAAC;AAC7B,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,EAAE,CAAC;AACpC,6EAA6E;AAC7E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAAE,CAAC;AACrC,MAAM,CAAC,MAAM,mBAAmB,GAAG,gBAAgB,GAAG,UAAU,CAAC;AACjE,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AACpC,6DAA6D;AAC7D,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AACrC,iDAAiD;AACjD,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAG,CAAC;AACjD,oEAAoE;AACpE,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC;AACzC,MAAM,CAAC,MAAM,eAAe,GAC1B,uBAAuB,GAAG,mBAAmB,GAAG,kBAAkB,CAAC;AACrE,uEAAuE;AACvE,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAC3C,oFAAoF;AACpF,MAAM,CAAC,MAAM,qBAAqB,GAAG,eAAe,GAAG,wBAAwB,CAAC;AAChF;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;AAC9D;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAC3C,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,CAAC;AAE1C,MAAM,CAAC,MAAM,aAAa,GAA0B;IAClD,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE;IACvC,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE;IACxC,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE;IACxC,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE;IACxC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE;CAC5C,CAAC","sourcesContent":["import type { SliderMark } from '@metamask-previews/design-system-shared';\n\n/** Slider geometry and behavior defaults — not typography or spacing tokens. */\nexport const THUMB_SIZE = 32;\nexport const THUMB_TOP_OFFSET = -13;\n/** Negative offset so the thumb center aligns with the track start at 0%. */\nexport const THUMB_LEFT_OFFSET = -16;\nexport const THUMB_BOTTOM_OFFSET = THUMB_TOP_OFFSET + THUMB_SIZE;\nexport const THUMB_TO_LABEL_GAP = 8;\n/** Scale applied to the thumb while the user is dragging. */\nexport const THUMB_GRIP_SCALE = 1.12;\n/** Duration (ms) for thumb grip scale in/out. */\nexport const THUMB_GRIP_ANIMATION_DURATION = 100;\n/** Matches root `py-2` vertical padding on the slider container. */\nexport const SLIDER_VERTICAL_PADDING = 8;\nexport const RANGE_LABEL_TOP =\n SLIDER_VERTICAL_PADDING + THUMB_BOTTOM_OFFSET + THUMB_TO_LABEL_GAP;\n/** Approximate line height for BodyMd range labels below the track. */\nexport const SLIDER_LABEL_LINE_HEIGHT = 20;\n/** Bottom padding when range labels may render (RANGE_LABEL_TOP + label height). */\nexport const SLIDER_BOTTOM_PADDING = RANGE_LABEL_TOP + SLIDER_LABEL_LINE_HEIGHT;\n/**\n * Default horizontal inset on the root container; equals |THUMB_LEFT_OFFSET| so\n * the thumb can overhang at min/max without clipping.\n */\nexport const SLIDER_TRACK_INSET = Math.abs(THUMB_LEFT_OFFSET);\n/**\n * Edge marker inset (percent) so dots/labels at 0/100 stay on the visible track.\n * The thumb at 0% sits half its width (THUMB_SIZE / 2) left of the track start;\n * a small inset keeps edge markers from sitting under the thumb center.\n */\nexport const DOT_EDGE_INSET_PERCENT = '2%';\nexport const DOT_EDGE_MAX_PERCENT = '98%';\n\nexport const DEFAULT_MARKS: readonly SliderMark[] = [\n { step: 0, label: '0%', haptic: false },\n { step: 25, label: '25%', haptic: true },\n { step: 50, label: '50%', haptic: true },\n { step: 75, label: '75%', haptic: true },\n { step: 100, label: '100%', haptic: false },\n];\n"]}
1
+ {"version":3,"file":"Slider.constants.mjs","sourceRoot":"","sources":["../../../src/components/Slider/Slider.constants.ts"],"names":[],"mappings":"AAEA,gFAAgF;AAChF,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,CAAC;AAC7B,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,EAAE,CAAC;AACpC,6EAA6E;AAC7E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAAE,CAAC;AACrC,MAAM,CAAC,MAAM,mBAAmB,GAAG,gBAAgB,GAAG,UAAU,CAAC;AACjE,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AACpC,6DAA6D;AAC7D,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AACrC,iDAAiD;AACjD,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAG,CAAC;AACjD,oEAAoE;AACpE,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC;AACzC,MAAM,CAAC,MAAM,eAAe,GAC1B,uBAAuB,GAAG,mBAAmB,GAAG,kBAAkB,CAAC;AACrE,uEAAuE;AACvE,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAC3C,oFAAoF;AACpF,MAAM,CAAC,MAAM,qBAAqB,GAAG,eAAe,GAAG,wBAAwB,CAAC;AAChF;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AACpC;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAC3C,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,CAAC;AAE1C,MAAM,CAAC,MAAM,aAAa,GAA0B;IAClD,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE;IACvC,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE;IACxC,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE;IACxC,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE;IACxC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE;CAC5C,CAAC","sourcesContent":["import type { SliderMark } from '@metamask-previews/design-system-shared';\n\n/** Slider geometry and behavior defaults — not typography or spacing tokens. */\nexport const THUMB_SIZE = 32;\nexport const THUMB_TOP_OFFSET = -13;\n/** Negative offset so the thumb center aligns with the track start at 0%. */\nexport const THUMB_LEFT_OFFSET = -16;\nexport const THUMB_BOTTOM_OFFSET = THUMB_TOP_OFFSET + THUMB_SIZE;\nexport const THUMB_TO_LABEL_GAP = 8;\n/** Scale applied to the thumb while the user is dragging. */\nexport const THUMB_GRIP_SCALE = 1.12;\n/** Duration (ms) for thumb grip scale in/out. */\nexport const THUMB_GRIP_ANIMATION_DURATION = 100;\n/** Matches root `py-2` vertical padding on the slider container. */\nexport const SLIDER_VERTICAL_PADDING = 8;\nexport const RANGE_LABEL_TOP =\n SLIDER_VERTICAL_PADDING + THUMB_BOTTOM_OFFSET + THUMB_TO_LABEL_GAP;\n/** Approximate line height for BodyMd range labels below the track. */\nexport const SLIDER_LABEL_LINE_HEIGHT = 20;\n/** Bottom padding when range labels may render (RANGE_LABEL_TOP + label height). */\nexport const SLIDER_BOTTOM_PADDING = RANGE_LABEL_TOP + SLIDER_LABEL_LINE_HEIGHT;\n/**\n * Default horizontal inset on the root container. The thumb stays on the track\n * at both ends, so no overhang margin is required.\n */\nexport const SLIDER_TRACK_INSET = 0;\n/**\n * Edge marker inset (percent) so dots/labels at 0/100 stay on the visible track\n * instead of sitting under the thumb when it rests at either end.\n */\nexport const DOT_EDGE_INSET_PERCENT = '2%';\nexport const DOT_EDGE_MAX_PERCENT = '98%';\n\nexport const DEFAULT_MARKS: readonly SliderMark[] = [\n { step: 0, label: '0%', haptic: false },\n { step: 25, label: '25%', haptic: true },\n { step: 50, label: '50%', haptic: true },\n { step: 75, label: '75%', haptic: true },\n { step: 100, label: '100%', haptic: false },\n];\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Slider.types.cjs","sourceRoot":"","sources":["../../../src/components/Slider/Slider.types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n SliderPropsShared,\n SliderMark,\n SliderMarkColor,\n} from '@metamask-previews/design-system-shared';\nimport type { ViewProps } from 'react-native';\nimport type { Gesture } from 'react-native-gesture-handler';\nimport type { useAnimatedStyle } from 'react-native-reanimated';\n\nimport type { SliderColorStop } from './Slider.utilities';\n\nexport type { SliderMark, SliderMarkColor };\n\n/**\n * React Native Slider props.\n *\n * Extends {@link SliderPropsShared} for cross-platform API (value, range, labels,\n * custom scale hooks) and `ViewProps` for root container passthrough (e.g.\n * `testID`, `accessibilityLabel`). See README for consumer-facing prop docs.\n */\nexport type SliderProps = SliderPropsShared &\n ViewProps & {\n /**\n * Horizontal inset on the root container so the thumb can overhang the track\n * at min/max without clipping. Defaults to {@link SLIDER_TRACK_INSET} (16);\n * override when the parent already provides edge padding.\n *\n * @default 16\n */\n trackInset?: number;\n\n /**\n * Optional twrnc classes merged into the root container after component defaults.\n * Use for layout spacing the Box API does not cover (e.g. `mt-4`).\n */\n twClassName?: string;\n };\n\n/**\n * Inputs for `useSliderGesture` — gesture handling and animated thumb/fill sync.\n *\n * Only `value` and `onValueChange` are required. Remaining fields default to the\n * same values as {@link SliderPropsShared} when omitted.\n */\nexport type UseSliderGestureParams = {\n /** Controlled domain value (`minimumValue`…`maximumValue`). */\n value: number;\n\n /**\n * Lower bound of the domain range.\n *\n * @default 0\n */\n minimumValue?: number;\n\n /**\n * Upper bound of the domain range.\n *\n * @default 100\n */\n maximumValue?: number;\n\n /**\n * Step increment applied by the default `mapTrackPercentToValue` mapper.\n * Custom mappers handle stepping inside `mapTrackPercentToValue`.\n *\n * @default 1\n */\n step?: number;\n\n /**\n * When true, pan/tap gestures and range-label presses are disabled.\n *\n * @default false\n */\n isDisabled?: boolean;\n\n /**\n * Called on every value change during pan drag, track tap, or range-label press.\n * Bridged from UI-thread worklets via `runOnJS`.\n */\n onValueChange: (value: number) => void;\n\n /**\n * Called when a gesture completes (finger lift, tap, or label press).\n * Omitted when the parent does not pass `onDragEnd`.\n */\n onDragEnd?: (value: number) => void;\n\n /**\n * Fires once when pan begins and once when pan ends; not fired on tap or\n * range-label press. Use for haptic feedback (e.g. ImpactMoment.SliderGrip).\n */\n onGrip?: () => void;\n\n /**\n * Called when track percent crosses a haptic mark threshold while dragging.\n * Evaluated on each pan `onUpdate` and on range-label press.\n */\n onMark?: () => void;\n\n /** Mark entries for label press value resolution and haptic thresholds. */\n marks: readonly SliderMark[];\n\n /** Resolved fill color stops for themed interpolation. */\n fillColorStops: readonly SliderColorStop[];\n\n /** Resolved thumb color stops for themed interpolation. */\n thumbColorStops: readonly SliderColorStop[];\n\n /** When true, thumb and fill use interpolated theme colors. */\n hasThemedColors: boolean;\n\n /**\n * Maps domain value → 0–100 track position for thumb/fill sync.\n * Must be a Reanimated worklet when provided (`'worklet';` in the function body).\n */\n mapValueToTrackPercent?: (value: number) => number;\n\n /**\n * Maps 0–100 track position → domain value during gestures.\n * Apply step rounding and snapping here for non-linear scales.\n * Must be a Reanimated worklet when provided (`'worklet';` in the function body).\n */\n mapTrackPercentToValue?: (trackPercent: number) => number;\n};\n\n/**\n * Return value of `useSliderGesture`.\n *\n * Wire `handleLayout`, animated styles, and `gesture` into `Slider.tsx`;\n * `handlePressStep` is bound to range-label `Pressable` targets.\n */\nexport type UseSliderGestureResult = {\n /**\n * Root `onLayout` handler. Stores track width and re-syncs thumb position\n * from the current `value` prop.\n */\n handleLayout: (event: { nativeEvent: { layout: { width: number } } }) => void;\n\n /** Animated width for the filled portion of the track (follows thumb). */\n progressStyle: ReturnType<typeof useAnimatedStyle>;\n\n /** Animated `translateX` for the thumb relative to the track start. */\n thumbStyle: ReturnType<typeof useAnimatedStyle>;\n\n /** Combined pan + tap gesture for the track/thumb hit area. */\n gesture: ReturnType<typeof Gesture.Simultaneous>;\n\n /**\n * Sets value from a tapped mark label: mark value → callbacks → thumb sync.\n * No-op when `isDisabled` is true.\n */\n handlePressStep: (rangeStep: number) => void;\n};\n"]}
1
+ {"version":3,"file":"Slider.types.cjs","sourceRoot":"","sources":["../../../src/components/Slider/Slider.types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n SliderPropsShared,\n SliderMark,\n SliderMarkColor,\n} from '@metamask-previews/design-system-shared';\nimport type { ViewProps } from 'react-native';\nimport type { Gesture } from 'react-native-gesture-handler';\nimport type { useAnimatedStyle } from 'react-native-reanimated';\n\nimport type { SliderColorStop } from './Slider.utilities';\n\nexport type { SliderMark, SliderMarkColor };\n\n/**\n * React Native Slider props.\n *\n * Extends {@link SliderPropsShared} for cross-platform API (value, range, labels,\n * custom scale hooks) and `ViewProps` for root container passthrough (e.g.\n * `testID`, `accessibilityLabel`). See README for consumer-facing prop docs.\n */\nexport type SliderProps = SliderPropsShared &\n ViewProps & {\n /**\n * Extra horizontal inset on the root container. Defaults to\n * {@link SLIDER_TRACK_INSET} (0) because the thumb stays on the track.\n *\n * @default 0\n */\n trackInset?: number;\n\n /**\n * Optional twrnc classes merged into the root container after component defaults.\n * Use for layout spacing the Box API does not cover (e.g. `mt-4`).\n */\n twClassName?: string;\n };\n\n/**\n * Inputs for `useSliderGesture` — gesture handling and animated thumb/fill sync.\n *\n * Only `value` and `onValueChange` are required. Remaining fields default to the\n * same values as {@link SliderPropsShared} when omitted.\n */\nexport type UseSliderGestureParams = {\n /** Controlled domain value (`minimumValue`…`maximumValue`). */\n value: number;\n\n /**\n * Lower bound of the domain range.\n *\n * @default 0\n */\n minimumValue?: number;\n\n /**\n * Upper bound of the domain range.\n *\n * @default 100\n */\n maximumValue?: number;\n\n /**\n * Step increment applied by the default `mapTrackPercentToValue` mapper.\n * Custom mappers handle stepping inside `mapTrackPercentToValue`.\n *\n * @default 1\n */\n step?: number;\n\n /**\n * When true, pan/tap gestures and range-label presses are disabled.\n *\n * @default false\n */\n isDisabled?: boolean;\n\n /**\n * Called on every value change during pan drag, track tap, or range-label press.\n * Bridged from UI-thread worklets via `runOnJS`.\n */\n onValueChange: (value: number) => void;\n\n /**\n * Called when a gesture completes (finger lift, tap, or label press).\n * Omitted when the parent does not pass `onDragEnd`.\n */\n onDragEnd?: (value: number) => void;\n\n /**\n * Fires once when pan begins and once when pan ends; not fired on tap or\n * range-label press. Use for haptic feedback (e.g. ImpactMoment.SliderGrip).\n */\n onGrip?: () => void;\n\n /**\n * Called when track percent crosses a haptic mark threshold while dragging.\n * Evaluated on each pan `onUpdate` and on range-label press.\n */\n onMark?: () => void;\n\n /** Mark entries for label press value resolution and haptic thresholds. */\n marks: readonly SliderMark[];\n\n /** Resolved fill color stops for themed interpolation. */\n fillColorStops: readonly SliderColorStop[];\n\n /** Resolved thumb color stops for themed interpolation. */\n thumbColorStops: readonly SliderColorStop[];\n\n /** When true, thumb and fill use interpolated theme colors. */\n hasThemedColors: boolean;\n\n /**\n * Maps domain value → 0–100 track position for thumb/fill sync.\n * Must be a Reanimated worklet when provided (`'worklet';` in the function body).\n */\n mapValueToTrackPercent?: (value: number) => number;\n\n /**\n * Maps 0–100 track position → domain value during gestures.\n * Apply step rounding and snapping here for non-linear scales.\n * Must be a Reanimated worklet when provided (`'worklet';` in the function body).\n */\n mapTrackPercentToValue?: (trackPercent: number) => number;\n};\n\n/**\n * Return value of `useSliderGesture`.\n *\n * Wire `handleLayout`, animated styles, and `gesture` into `Slider.tsx`;\n * `handlePressStep` is bound to range-label `Pressable` targets.\n */\nexport type UseSliderGestureResult = {\n /**\n * Root `onLayout` handler. Stores track width and re-syncs thumb position\n * from the current `value` prop.\n */\n handleLayout: (event: { nativeEvent: { layout: { width: number } } }) => void;\n\n /** Animated width for the filled portion of the track (follows thumb). */\n progressStyle: ReturnType<typeof useAnimatedStyle>;\n\n /** Animated thumb-center `translateX`, inset so the thumb stays on the track. */\n thumbStyle: ReturnType<typeof useAnimatedStyle>;\n\n /** Combined pan + tap gesture for the track/thumb hit area. */\n gesture: ReturnType<typeof Gesture.Simultaneous>;\n\n /**\n * Sets value from a tapped mark label: mark value → callbacks → thumb sync.\n * No-op when `isDisabled` is true.\n */\n handlePressStep: (rangeStep: number) => void;\n};\n"]}
@@ -13,11 +13,10 @@ export type { SliderMark, SliderMarkColor };
13
13
  */
14
14
  export type SliderProps = SliderPropsShared & ViewProps & {
15
15
  /**
16
- * Horizontal inset on the root container so the thumb can overhang the track
17
- * at min/max without clipping. Defaults to {@link SLIDER_TRACK_INSET} (16);
18
- * override when the parent already provides edge padding.
16
+ * Extra horizontal inset on the root container. Defaults to
17
+ * {@link SLIDER_TRACK_INSET} (0) because the thumb stays on the track.
19
18
  *
20
- * @default 16
19
+ * @default 0
21
20
  */
22
21
  trackInset?: number;
23
22
  /**
@@ -120,7 +119,7 @@ export type UseSliderGestureResult = {
120
119
  }) => void;
121
120
  /** Animated width for the filled portion of the track (follows thumb). */
122
121
  progressStyle: ReturnType<typeof useAnimatedStyle>;
123
- /** Animated `translateX` for the thumb relative to the track start. */
122
+ /** Animated thumb-center `translateX`, inset so the thumb stays on the track. */
124
123
  thumbStyle: ReturnType<typeof useAnimatedStyle>;
125
124
  /** Combined pan + tap gesture for the track/thumb hit area. */
126
125
  gesture: ReturnType<typeof Gesture.Simultaneous>;
@@ -1 +1 @@
1
- {"version":3,"file":"Slider.types.d.cts","sourceRoot":"","sources":["../../../src/components/Slider/Slider.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,UAAU,EACV,eAAe,EAChB,gDAAgD;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,qBAAqB;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,qCAAqC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,gCAAgC;AAEhE,OAAO,KAAK,EAAE,eAAe,EAAE,+BAA2B;AAE1D,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG,iBAAiB,GACzC,SAAS,GAAG;IACV;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEJ;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,+DAA+D;IAC/D,KAAK,EAAE,MAAM,CAAC;IAEd;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;;OAGG;IACH,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAEvC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,eAAe,EAAE,OAAO,CAAC;IAEzB;;;OAGG;IACH,sBAAsB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAEnD;;;;OAIG;IACH,sBAAsB,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3D,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC;;;OAGG;IACH,YAAY,EAAE,CAAC,KAAK,EAAE;QAAE,WAAW,EAAE;YAAE,MAAM,EAAE;gBAAE,KAAK,EAAE,MAAM,CAAA;aAAE,CAAA;SAAE,CAAA;KAAE,KAAK,IAAI,CAAC;IAE9E,0EAA0E;IAC1E,aAAa,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC;IAEnD,iFAAiF;IACjF,UAAU,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC;IAEhD,+DAA+D;IAC/D,OAAO,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,YAAY,CAAC,CAAC;IAEjD;;;OAGG;IACH,eAAe,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9C,CAAC"}
@@ -13,11 +13,10 @@ export type { SliderMark, SliderMarkColor };
13
13
  */
14
14
  export type SliderProps = SliderPropsShared & ViewProps & {
15
15
  /**
16
- * Horizontal inset on the root container so the thumb can overhang the track
17
- * at min/max without clipping. Defaults to {@link SLIDER_TRACK_INSET} (16);
18
- * override when the parent already provides edge padding.
16
+ * Extra horizontal inset on the root container. Defaults to
17
+ * {@link SLIDER_TRACK_INSET} (0) because the thumb stays on the track.
19
18
  *
20
- * @default 16
19
+ * @default 0
21
20
  */
22
21
  trackInset?: number;
23
22
  /**
@@ -120,7 +119,7 @@ export type UseSliderGestureResult = {
120
119
  }) => void;
121
120
  /** Animated width for the filled portion of the track (follows thumb). */
122
121
  progressStyle: ReturnType<typeof useAnimatedStyle>;
123
- /** Animated `translateX` for the thumb relative to the track start. */
122
+ /** Animated thumb-center `translateX`, inset so the thumb stays on the track. */
124
123
  thumbStyle: ReturnType<typeof useAnimatedStyle>;
125
124
  /** Combined pan + tap gesture for the track/thumb hit area. */
126
125
  gesture: ReturnType<typeof Gesture.Simultaneous>;
@@ -1 +1 @@
1
- {"version":3,"file":"Slider.types.d.mts","sourceRoot":"","sources":["../../../src/components/Slider/Slider.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,UAAU,EACV,eAAe,EAChB,gDAAgD;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,qBAAqB;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,qCAAqC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,gCAAgC;AAEhE,OAAO,KAAK,EAAE,eAAe,EAAE,+BAA2B;AAE1D,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG,iBAAiB,GACzC,SAAS,GAAG;IACV;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEJ;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,+DAA+D;IAC/D,KAAK,EAAE,MAAM,CAAC;IAEd;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;;OAGG;IACH,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAEvC;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAEpC;;;OAGG;IACH,MAAM,CA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AAC;IAEnD;;;;OAIG;IACH,sBAAsB,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3D,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC;;;OAGG;IACH,YAAY,EAAE,CAAC,KAAK,EAAE;QAAE,WAAW,EAAE;YAAE,MAAM,EAAE;gBAAE,KAAK,EAAE,MAAM,CAAA;aAAE,CAAA;SAAE,CAAA;KAAE,KAAK,IAAI,CAAC;IAE9E,0EAA0E;IAC1E,aAAa,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC;IAEnD,iFAAiF;IACjF,UAAU,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC;IAEhD,+DAA+D;IAC/D,OAAO,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,YAAY,CAAC,CAAC;IAEjD;;;OAGG;IACH,eAAe,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"Slider.types.mjs","sourceRoot":"","sources":["../../../src/components/Slider/Slider.types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n SliderPropsShared,\n SliderMark,\n SliderMarkColor,\n} from '@metamask-previews/design-system-shared';\nimport type { ViewProps } from 'react-native';\nimport type { Gesture } from 'react-native-gesture-handler';\nimport type { useAnimatedStyle } from 'react-native-reanimated';\n\nimport type { SliderColorStop } from './Slider.utilities';\n\nexport type { SliderMark, SliderMarkColor };\n\n/**\n * React Native Slider props.\n *\n * Extends {@link SliderPropsShared} for cross-platform API (value, range, labels,\n * custom scale hooks) and `ViewProps` for root container passthrough (e.g.\n * `testID`, `accessibilityLabel`). See README for consumer-facing prop docs.\n */\nexport type SliderProps = SliderPropsShared &\n ViewProps & {\n /**\n * Horizontal inset on the root container so the thumb can overhang the track\n * at min/max without clipping. Defaults to {@link SLIDER_TRACK_INSET} (16);\n * override when the parent already provides edge padding.\n *\n * @default 16\n */\n trackInset?: number;\n\n /**\n * Optional twrnc classes merged into the root container after component defaults.\n * Use for layout spacing the Box API does not cover (e.g. `mt-4`).\n */\n twClassName?: string;\n };\n\n/**\n * Inputs for `useSliderGesture` — gesture handling and animated thumb/fill sync.\n *\n * Only `value` and `onValueChange` are required. Remaining fields default to the\n * same values as {@link SliderPropsShared} when omitted.\n */\nexport type UseSliderGestureParams = {\n /** Controlled domain value (`minimumValue`…`maximumValue`). */\n value: number;\n\n /**\n * Lower bound of the domain range.\n *\n * @default 0\n */\n minimumValue?: number;\n\n /**\n * Upper bound of the domain range.\n *\n * @default 100\n */\n maximumValue?: number;\n\n /**\n * Step increment applied by the default `mapTrackPercentToValue` mapper.\n * Custom mappers handle stepping inside `mapTrackPercentToValue`.\n *\n * @default 1\n */\n step?: number;\n\n /**\n * When true, pan/tap gestures and range-label presses are disabled.\n *\n * @default false\n */\n isDisabled?: boolean;\n\n /**\n * Called on every value change during pan drag, track tap, or range-label press.\n * Bridged from UI-thread worklets via `runOnJS`.\n */\n onValueChange: (value: number) => void;\n\n /**\n * Called when a gesture completes (finger lift, tap, or label press).\n * Omitted when the parent does not pass `onDragEnd`.\n */\n onDragEnd?: (value: number) => void;\n\n /**\n * Fires once when pan begins and once when pan ends; not fired on tap or\n * range-label press. Use for haptic feedback (e.g. ImpactMoment.SliderGrip).\n */\n onGrip?: () => void;\n\n /**\n * Called when track percent crosses a haptic mark threshold while dragging.\n * Evaluated on each pan `onUpdate` and on range-label press.\n */\n onMark?: () => void;\n\n /** Mark entries for label press value resolution and haptic thresholds. */\n marks: readonly SliderMark[];\n\n /** Resolved fill color stops for themed interpolation. */\n fillColorStops: readonly SliderColorStop[];\n\n /** Resolved thumb color stops for themed interpolation. */\n thumbColorStops: readonly SliderColorStop[];\n\n /** When true, thumb and fill use interpolated theme colors. */\n hasThemedColors: boolean;\n\n /**\n * Maps domain value → 0–100 track position for thumb/fill sync.\n * Must be a Reanimated worklet when provided (`'worklet';` in the function body).\n */\n mapValueToTrackPercent?: (value: number) => number;\n\n /**\n * Maps 0–100 track position → domain value during gestures.\n * Apply step rounding and snapping here for non-linear scales.\n * Must be a Reanimated worklet when provided (`'worklet';` in the function body).\n */\n mapTrackPercentToValue?: (trackPercent: number) => number;\n};\n\n/**\n * Return value of `useSliderGesture`.\n *\n * Wire `handleLayout`, animated styles, and `gesture` into `Slider.tsx`;\n * `handlePressStep` is bound to range-label `Pressable` targets.\n */\nexport type UseSliderGestureResult = {\n /**\n * Root `onLayout` handler. Stores track width and re-syncs thumb position\n * from the current `value` prop.\n */\n handleLayout: (event: { nativeEvent: { layout: { width: number } } }) => void;\n\n /** Animated width for the filled portion of the track (follows thumb). */\n progressStyle: ReturnType<typeof useAnimatedStyle>;\n\n /** Animated `translateX` for the thumb relative to the track start. */\n thumbStyle: ReturnType<typeof useAnimatedStyle>;\n\n /** Combined pan + tap gesture for the track/thumb hit area. */\n gesture: ReturnType<typeof Gesture.Simultaneous>;\n\n /**\n * Sets value from a tapped mark label: mark value → callbacks → thumb sync.\n * No-op when `isDisabled` is true.\n */\n handlePressStep: (rangeStep: number) => void;\n};\n"]}
1
+ {"version":3,"file":"Slider.types.mjs","sourceRoot":"","sources":["../../../src/components/Slider/Slider.types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n SliderPropsShared,\n SliderMark,\n SliderMarkColor,\n} from '@metamask-previews/design-system-shared';\nimport type { ViewProps } from 'react-native';\nimport type { Gesture } from 'react-native-gesture-handler';\nimport type { useAnimatedStyle } from 'react-native-reanimated';\n\nimport type { SliderColorStop } from './Slider.utilities';\n\nexport type { SliderMark, SliderMarkColor };\n\n/**\n * React Native Slider props.\n *\n * Extends {@link SliderPropsShared} for cross-platform API (value, range, labels,\n * custom scale hooks) and `ViewProps` for root container passthrough (e.g.\n * `testID`, `accessibilityLabel`). See README for consumer-facing prop docs.\n */\nexport type SliderProps = SliderPropsShared &\n ViewProps & {\n /**\n * Extra horizontal inset on the root container. Defaults to\n * {@link SLIDER_TRACK_INSET} (0) because the thumb stays on the track.\n *\n * @default 0\n */\n trackInset?: number;\n\n /**\n * Optional twrnc classes merged into the root container after component defaults.\n * Use for layout spacing the Box API does not cover (e.g. `mt-4`).\n */\n twClassName?: string;\n };\n\n/**\n * Inputs for `useSliderGesture` — gesture handling and animated thumb/fill sync.\n *\n * Only `value` and `onValueChange` are required. Remaining fields default to the\n * same values as {@link SliderPropsShared} when omitted.\n */\nexport type UseSliderGestureParams = {\n /** Controlled domain value (`minimumValue`…`maximumValue`). */\n value: number;\n\n /**\n * Lower bound of the domain range.\n *\n * @default 0\n */\n minimumValue?: number;\n\n /**\n * Upper bound of the domain range.\n *\n * @default 100\n */\n maximumValue?: number;\n\n /**\n * Step increment applied by the default `mapTrackPercentToValue` mapper.\n * Custom mappers handle stepping inside `mapTrackPercentToValue`.\n *\n * @default 1\n */\n step?: number;\n\n /**\n * When true, pan/tap gestures and range-label presses are disabled.\n *\n * @default false\n */\n isDisabled?: boolean;\n\n /**\n * Called on every value change during pan drag, track tap, or range-label press.\n * Bridged from UI-thread worklets via `runOnJS`.\n */\n onValueChange: (value: number) => void;\n\n /**\n * Called when a gesture completes (finger lift, tap, or label press).\n * Omitted when the parent does not pass `onDragEnd`.\n */\n onDragEnd?: (value: number) => void;\n\n /**\n * Fires once when pan begins and once when pan ends; not fired on tap or\n * range-label press. Use for haptic feedback (e.g. ImpactMoment.SliderGrip).\n */\n onGrip?: () => void;\n\n /**\n * Called when track percent crosses a haptic mark threshold while dragging.\n * Evaluated on each pan `onUpdate` and on range-label press.\n */\n onMark?: () => void;\n\n /** Mark entries for label press value resolution and haptic thresholds. */\n marks: readonly SliderMark[];\n\n /** Resolved fill color stops for themed interpolation. */\n fillColorStops: readonly SliderColorStop[];\n\n /** Resolved thumb color stops for themed interpolation. */\n thumbColorStops: readonly SliderColorStop[];\n\n /** When true, thumb and fill use interpolated theme colors. */\n hasThemedColors: boolean;\n\n /**\n * Maps domain value → 0–100 track position for thumb/fill sync.\n * Must be a Reanimated worklet when provided (`'worklet';` in the function body).\n */\n mapValueToTrackPercent?: (value: number) => number;\n\n /**\n * Maps 0–100 track position → domain value during gestures.\n * Apply step rounding and snapping here for non-linear scales.\n * Must be a Reanimated worklet when provided (`'worklet';` in the function body).\n */\n mapTrackPercentToValue?: (trackPercent: number) => number;\n};\n\n/**\n * Return value of `useSliderGesture`.\n *\n * Wire `handleLayout`, animated styles, and `gesture` into `Slider.tsx`;\n * `handlePressStep` is bound to range-label `Pressable` targets.\n */\nexport type UseSliderGestureResult = {\n /**\n * Root `onLayout` handler. Stores track width and re-syncs thumb position\n * from the current `value` prop.\n */\n handleLayout: (event: { nativeEvent: { layout: { width: number } } }) => void;\n\n /** Animated width for the filled portion of the track (follows thumb). */\n progressStyle: ReturnType<typeof useAnimatedStyle>;\n\n /** Animated thumb-center `translateX`, inset so the thumb stays on the track. */\n thumbStyle: ReturnType<typeof useAnimatedStyle>;\n\n /** Combined pan + tap gesture for the track/thumb hit area. */\n gesture: ReturnType<typeof Gesture.Simultaneous>;\n\n /**\n * Sets value from a tapped mark label: mark value → callbacks → thumb sync.\n * No-op when `isDisabled` is true.\n */\n handlePressStep: (rangeStep: number) => void;\n};\n"]}
@@ -6,7 +6,8 @@
6
6
  * - **Domain value** — the controlled `value` prop (`minimumValue`…`maximumValue`).
7
7
  * - **Track percent** — normalized 0–100 position along the track (used for dots,
8
8
  * labels, and haptic thresholds; may be non-linear via `map*` hooks).
9
- * - **Pixel position** — thumb/fill offset in layout pixels (`translateX`).
9
+ * - **Pixel position** — thumb-center offset in layout pixels (`translateX`).
10
+ * Travel is inset by half the thumb so the circle stays on the track.
10
11
  *
11
12
  * Functions marked with `'worklet'` run on the UI thread inside gesture handlers.
12
13
  * JS-thread callers use the non-worklet wrappers (`getTrackPercentFromValue`, etc.).
@@ -96,32 +97,61 @@ function resolveValueToTrackPercent(value, minimumValue, maximumValue, mapValueT
96
97
  }
97
98
  exports.resolveValueToTrackPercent = resolveValueToTrackPercent;
98
99
  // --- Track-percent ↔ pixel position (worklet) ---
100
+ /**
101
+ * Thumb-center pixel for a track percent.
102
+ *
103
+ * Travel is one thumb-width shorter than the track, so the whole thumb stays
104
+ * on the bar: at 0% its left edge is the track start, and at 100% its right
105
+ * edge is the track end. Matches the batch-sell slider in metamask-mobile#37525.
106
+ *
107
+ * @param trackPercent - Track position from 0–100.
108
+ * @param width - Track width in pixels.
109
+ * @returns Thumb-center offset from the track start.
110
+ */
99
111
  function trackPercentToPosition(trackPercent, width) {
100
112
  'worklet';
101
113
  if (width === 0) {
102
114
  return 0;
103
115
  }
104
- return (clampTrackPercent(trackPercent) / 100) * width;
116
+ const travel = Math.max(width - Slider_constants_1.THUMB_SIZE, 0);
117
+ return Slider_constants_1.THUMB_SIZE / 2 + (clampTrackPercent(trackPercent) / 100) * travel;
105
118
  }
106
119
  exports.trackPercentToPosition = trackPercentToPosition;
120
+ /**
121
+ * Track percent for a thumb-center pixel. Touches outside the thumb's travel
122
+ * clamp to 0% or 100%.
123
+ *
124
+ * @param position - Thumb center, or a touch X treated as that center.
125
+ * @param width - Track width in pixels.
126
+ * @returns Track percent clamped to 0–100.
127
+ */
107
128
  function positionToTrackPercent(position, width) {
108
129
  'worklet';
109
- if (width === 0) {
130
+ const travel = width - Slider_constants_1.THUMB_SIZE;
131
+ if (width === 0 || travel <= 0) {
110
132
  return 0;
111
133
  }
112
- return clampTrackPercent((position / width) * 100);
134
+ const minCenter = Slider_constants_1.THUMB_SIZE / 2;
135
+ const center = Math.max(minCenter, Math.min(width - minCenter, position));
136
+ return clampTrackPercent(((center - minCenter) / travel) * 100);
113
137
  }
114
138
  exports.positionToTrackPercent = positionToTrackPercent;
115
139
  /**
116
- * Clamps a touch X coordinate to the track bounds.
140
+ * Clamps a touch X to the thumb-center travel, so a drag cannot pull the thumb
141
+ * off either end of the track.
117
142
  *
118
143
  * @param position - Touch X in track coordinates.
119
144
  * @param width - Track width in pixels.
120
- * @returns Clamped pixel position.
145
+ * @returns Clamped thumb-center position.
121
146
  */
122
147
  function clampGesturePosition(position, width) {
123
148
  'worklet';
124
- return Math.max(0, Math.min(position, width));
149
+ if (width === 0) {
150
+ return 0;
151
+ }
152
+ const minCenter = Slider_constants_1.THUMB_SIZE / 2;
153
+ const maxCenter = Math.max(minCenter, width - minCenter);
154
+ return Math.max(minCenter, Math.min(position, maxCenter));
125
155
  }
126
156
  exports.clampGesturePosition = clampGesturePosition;
127
157
  // --- JS-thread domain ↔ track-percent ---
@@ -1 +1 @@
1
- {"version":3,"file":"Slider.utilities.cjs","sourceRoot":"","sources":["../../../src/components/Slider/Slider.utilities.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAMH,qEAA2D;AAE3D,6DAG4B;AAO5B,6CAA6C;AAE7C,SAAgB,iBAAiB,CAAC,YAAoB;IACpD,SAAS,CAAC;IAEV,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC;AAClD,CAAC;AAJD,8CAIC;AAED,mDAAmD;AAEnD;;;;;;;GAOG;AACH,SAAgB,6BAA6B,CAC3C,KAAa,EACb,YAAoB,EACpB,YAAoB;IAEpB,SAAS,CAAC;IAEV,MAAM,KAAK,GAAG,YAAY,GAAG,YAAY,CAAC;IAC1C,IAAI,KAAK,KAAK,CAAC,EAAE;QACf,OAAO,CAAC,CAAC;KACV;IAED,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,GAAG,YAAY,CAAC,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC;IACvD,OAAO,iBAAiB,CAAC,OAAO,CAAC,CAAC;AACpC,CAAC;AAdD,sEAcC;AAED;;;;;;;;GAQG;AACH,SAAgB,6BAA6B,CAC3C,YAAoB,EACpB,YAAoB,EACpB,YAAoB,EACpB,IAAY;IAEZ,SAAS,CAAC;IAEV,MAAM,KAAK,GAAG,YAAY,GAAG,YAAY,CAAC;IAC1C,IAAI,KAAK,KAAK,CA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EAAE,KAAK,CAAC,CAAC,CAAC;IACtE,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;AAC3C,CAAC;AAbD,8CAaC","sourcesContent":["/**\n * Pure helpers for Slider coordinate conversion and UI defaults.\n *\n * Three coordinate systems:\n * - **Domain value** — the controlled `value` prop (`minimumValue`…`maximumValue`).\n * - **Track percent** — normalized 0–100 position along the track (used for dots,\n * labels, and haptic thresholds; may be non-linear via `map*` hooks).\n * - **Pixel position** — thumb/fill offset in layout pixels (`translateX`).\n *\n * Functions marked with `'worklet'` run on the UI thread inside gesture handlers.\n * JS-thread callers use the non-worklet wrappers (`getTrackPercentFromValue`, etc.).\n */\n\nimport type {\n SliderMark,\n SliderMarkColor,\n} from '@metamask-previews/design-system-shared';\nimport { interpolateColor } from 'react-native-reanimated';\n\nimport {\n DOT_EDGE_INSET_PERCENT,\n DOT_EDGE_MAX_PERCENT,\n} from './Slider.constants';\n\nexport type SliderColorStop = {\n step: number;\n color: string;\n};\n\n// --- Track-percent primitives (worklet) ---\n\nexport function clampTrackPercent(trackPercent: number): number {\n 'worklet';\n\n return Math.max(0, Math.min(100, trackPercent));\n}\n\n// --- Domain ↔ track-percent mappers (worklet) ---\n\n/**\n * Linear default: domain value → 0–100 track position.\n *\n * @param value - Domain value to map.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @returns Track percent clamped to 0–100.\n */\nexport function defaultMapValueToTrackPercent(\n value: number,\n minimumValue: number,\n maximumValue: number,\n): number {\n 'worklet';\n\n const range = maximumValue - minimumValue;\n if (range === 0) {\n return 0;\n }\n\n const percent = ((value - minimumValue) / range) * 100;\n return clampTrackPercent(percent);\n}\n\n/**\n * Linear default: track position → stepped domain value.\n *\n * @param trackPercent - Track position from 0–100.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @param step - Step increment for rounding.\n * @returns Stepped domain value clamped to the range.\n */\nexport function defaultMapTrackPercentToValue(\n trackPercent: number,\n minimumValue: number,\n maximumValue: number,\n step: number,\n): number {\n 'worklet';\n\n const range = maximumValue - minimumValue;\n if (range === 0) {\n return minimumValue;\n }\n\n const rawValue =\n (clampTrackPercent(trackPercent) / 100) * range + minimumValue;\n const stepped = Math.round(rawValue / step) * step;\n return Math.max(minimumValue, Math.min(maximumValue, stepped));\n}\n\n/**\n * UI-thread entry: custom `mapTrackPercentToValue` or linear default.\n *\n * @param trackPercent - Track position from 0–100.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @param step - Step increment for the default mapper.\n * @param mapTrackPercentToValue - Optional custom mapper.\n * @returns Domain value for the track position.\n */\nexport function resolveTrackPercentToValue(\n trackPercent: number,\n minimumValue: number,\n maximumValue: number,\n step: number,\n mapTrackPercentToValue?: (trackPercent: number) => number,\n): number {\n 'worklet';\n\n if (mapTrackPercentToValue) {\n return mapTrackPercentToValue(trackPercent);\n }\n\n return defaultMapTrackPercentToValue(\n trackPercent,\n minimumValue,\n maximumValue,\n step,\n );\n}\n\n/**\n * UI-thread entry: custom `mapValueToTrackPercent` or linear default.\n *\n * @param value - Domain value to map.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @param mapValueToTrackPercent - Optional custom mapper.\n * @returns Track percent for the domain value.\n */\nexport function resolveValueToTrackPercent(\n value: number,\n minimumValue: number,\n maximumValue: number,\n mapValueToTrackPercent?: (value: number) => number,\n): number {\n 'worklet';\n\n if (mapValueToTrackPercent) {\n return mapValueToTrackPercent(value);\n }\n\n return defaultMapValueToTrackPercent(value, minimumValue, maximumValue);\n}\n\n// --- Track-percent ↔ pixel position (worklet) ---\n\nexport function trackPercentToPosition(\n trackPercent: number,\n width: number,\n): number {\n 'worklet';\n\n if (width === 0) {\n return 0;\n }\n\n return (clampTrackPercent(trackPercent) / 100) * width;\n}\n\nexport function positionToTrackPercent(\n position: number,\n width: number,\n): number {\n 'worklet';\n\n if (width === 0) {\n return 0;\n }\n\n return clampTrackPercent((position / width) * 100);\n}\n\n/**\n * Clamps a touch X coordinate to the track bounds.\n *\n * @param position - Touch X in track coordinates.\n * @param width - Track width in pixels.\n * @returns Clamped pixel position.\n */\nexport function clampGesturePosition(position: number, width: number): number {\n 'worklet';\n\n return Math.max(0, Math.min(position, width));\n}\n\n// --- JS-thread domain ↔ track-percent ---\n\n/**\n * JS-thread entry for mapping domain value → track percent.\n * Used by Slider (labels, a11y) and useSliderGesture (prop/layout sync).\n *\n * @param value - Domain value to map.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @param mapValueToTrackPercent - Optional custom mapper.\n * @returns Track percent for the domain value.\n */\nexport function getTrackPercentFromValue(\n value: number,\n minimumValue: number,\n maximumValue: number,\n mapValueToTrackPercent?: (value: number) => number,\n): number {\n if (mapValueToTrackPercent) {\n return mapValueToTrackPercent(value);\n }\n\n return defaultMapValueToTrackPercent(value, minimumValue, maximumValue);\n}\n\n// --- Range label / dot defaults (Slider.tsx) ---\n\n/**\n * Default linear track-percent → domain value for a mark.\n *\n * @param step - Track-percent step from a mark entry.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @returns Domain value for the step.\n */\nexport function defaultStepToValue(\n step: number,\n minimumValue: number,\n maximumValue: number,\n): number {\n return (step / 100) * (maximumValue - minimumValue) + minimumValue;\n}\n\n/**\n * Domain value for a mark: explicit `value` or linear default from step.\n *\n * @param mark - Mark entry.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @returns Domain value for the mark.\n */\nexport function getMarkValue(\n mark: SliderMark,\n minimumValue: number,\n maximumValue: number,\n): number {\n if (mark.value !== undefined) {\n return mark.value;\n }\n\n return defaultStepToValue(mark.step, minimumValue, maximumValue);\n}\n\n/**\n * Track-percent thresholds that trigger onMark while dragging.\n *\n * @param marks - Mark entries.\n * @returns Haptic threshold positions.\n */\nexport function getMarkHapticThresholds(\n marks: readonly SliderMark[],\n): number[] {\n return marks\n .filter((mark) => mark.haptic ?? Boolean(mark.label))\n .map((mark) => mark.step);\n}\n\n/**\n * Resolves a mark color to a concrete color string for Reanimated.\n * Design tokens are looked up on the palette; raw hex/rgb pass through\n * (temporary migration bridge — prefer `SliderMarkColor` tokens in app code).\n *\n * @param color - Theme token key (or legacy hex/rgb string).\n * @param palette - Flattened theme color palette.\n * @param fallback - Fallback color when token is not found.\n * @returns Resolved color string.\n */\nexport function resolveMarkColor(\n color: SliderMarkColor | string,\n palette: Record<string, string>,\n fallback: string,\n): string {\n if (color.startsWith('#') || color.startsWith('rgb')) {\n return color;\n }\n\n return palette[color] ?? fallback;\n}\n\n/**\n * Builds color interpolation stops from marks, applying fallback for missing colors.\n *\n * @param marks - Mark entries.\n * @param palette - Flattened theme color palette.\n * @param fallbackToken - Default token key when mark.color is omitted.\n * @returns Sorted color stops for interpolation.\n */\nexport function buildColorStops(\n marks: readonly SliderMark[],\n palette: Record<string, string>,\n fallbackToken: string,\n): SliderColorStop[] {\n const fallback = palette[fallbackToken] ?? '#000000';\n\n return [...marks]\n .sort((a, b) => a.step - b.step)\n .map((mark) => ({\n step: mark.step,\n color: mark.color\n ? resolveMarkColor(mark.color, palette, fallback)\n : fallback,\n }));\n}\n\n/**\n * Interpolates a color along the track based on mark color stops.\n *\n * @param trackPercent - Current track position from 0–100.\n * @param stops - Sorted color stops.\n * @returns Interpolated color string.\n */\nexport function interpolateMarkColor(\n trackPercent: number,\n stops: readonly SliderColorStop[],\n): string {\n 'worklet';\n\n if (stops.length === 0) {\n return '#000000';\n }\n\n if (stops.length === 1) {\n return stops[0].color;\n }\n\n const inputRange = stops.map((stop) => stop.step);\n const outputRange = stops.map((stop) => stop.color);\n\n return interpolateColor(\n clampTrackPercent(trackPercent),\n inputRange,\n outputRange,\n 'RGB',\n );\n}\n\n/**\n * Whether any mark defines a theme color.\n *\n * @param marks - Mark entries.\n * @returns True when at least one mark has a color.\n */\nexport function hasThemedMarkColors(marks: readonly SliderMark[]): boolean {\n return marks.some((mark) => Boolean(mark.color));\n}\n\n/**\n * Marker `left` percent for range dots and labels; edge steps inset to stay on track.\n *\n * @param step - Track-percent step from a mark entry.\n * @returns CSS `left` percentage string.\n */\nexport function getDotLeftPercent(step: number): string {\n if (step === 0) {\n return DOT_EDGE_INSET_PERCENT;\n }\n if (step === 100) {\n return DOT_EDGE_MAX_PERCENT;\n }\n\n return `${step}%`;\n}\n\n// --- Accessibility (Slider.tsx) ---\n\n/**\n * Clamps and steps a domain value for increment/decrement actions.\n *\n * @param value - Domain value to clamp.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @param step - Step increment for rounding.\n * @returns Clamped and stepped domain value.\n */\nexport function clampValueToRange(\n value: number,\n minimumValue: number,\n maximumValue: number,\n step: number,\n): number {\n const range = maximumValue - minimumValue;\n if (range === 0) {\n return minimumValue;\n }\n\n const clamped = Math.max(minimumValue, Math.min(maximumValue, value));\n return Math.round(clamped / step) * step;\n}\n"]}
1
+ {"version":3,"file":"Slider.utilities.cjs","sourceRoot":"","sources":["../../../src/components/Slider/Slider.utilities.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAMH,qEAA2D;AAE3D,6DAI4B;AAO5B,6CAA6C;AAE7C,SAAgB,iBAAiB,CAAC,YAAoB;IACpD,SAAS,CAAC;IAEV,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC;AAClD,CAAC;AAJD,8CAIC;AAED,mDAAmD;AAEnD;;;;;;;GAOG;AACH,SAAgB,6BAA6B,CAC3C,KAAa,EACb,YAAoB,EACpB,YAAoB;IAEpB,SAAS,CAAC;IAEV,MAAM,KAAK,GAAG,YAAY,GAAG,YAAY,CAAC;IAC1C,IAAI,KAAK,KAAK,CAAC,EAAE;QACf,OAAO,CAAC,CA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AC,IAAI,CAAC,CAAC;IAClD,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAEpD,OAAO,IAAA,0CAAgB,EACrB,iBAAiB,CAAC,YAAY,CAAC,EAC/B,UAAU,EACV,WAAW,EACX,KAAK,CACN,CAAC;AACJ,CAAC;AAvBD,oDAuBC;AAED;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,KAA4B;IAC9D,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AACnD,CAAC;AAFD,kDAEC;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,IAAY;IAC5C,IAAI,IAAI,KAAK,CAAC,EAAE;QACd,OAAO,yCAAsB,CAAC;KAC/B;IACD,IAAI,IAAI,KAAK,GAAG,EAAE;QAChB,OAAO,uCAAoB,CAAC;KAC7B;IAED,OAAO,GAAG,IAAI,GAAG,CAAC;AACpB,CAAC;AATD,8CASC;AAED,qCAAqC;AAErC;;;;;;;;GAQG;AACH,SAAgB,iBAAiB,CAC/B,KAAa,EACb,YAAoB,EACpB,YAAoB,EACpB,IAAY;IAEZ,MAAM,KAAK,GAAG,YAAY,GAAG,YAAY,CAAC;IAC1C,IAAI,KAAK,KAAK,CAAC,EAAE;QACf,OAAO,YAAY,CAAC;KACrB;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,CAAC;IACtE,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;AAC3C,CAAC;AAbD,8CAaC","sourcesContent":["/**\n * Pure helpers for Slider coordinate conversion and UI defaults.\n *\n * Three coordinate systems:\n * - **Domain value** — the controlled `value` prop (`minimumValue`…`maximumValue`).\n * - **Track percent** — normalized 0–100 position along the track (used for dots,\n * labels, and haptic thresholds; may be non-linear via `map*` hooks).\n * - **Pixel position** — thumb-center offset in layout pixels (`translateX`).\n * Travel is inset by half the thumb so the circle stays on the track.\n *\n * Functions marked with `'worklet'` run on the UI thread inside gesture handlers.\n * JS-thread callers use the non-worklet wrappers (`getTrackPercentFromValue`, etc.).\n */\n\nimport type {\n SliderMark,\n SliderMarkColor,\n} from '@metamask-previews/design-system-shared';\nimport { interpolateColor } from 'react-native-reanimated';\n\nimport {\n DOT_EDGE_INSET_PERCENT,\n DOT_EDGE_MAX_PERCENT,\n THUMB_SIZE,\n} from './Slider.constants';\n\nexport type SliderColorStop = {\n step: number;\n color: string;\n};\n\n// --- Track-percent primitives (worklet) ---\n\nexport function clampTrackPercent(trackPercent: number): number {\n 'worklet';\n\n return Math.max(0, Math.min(100, trackPercent));\n}\n\n// --- Domain ↔ track-percent mappers (worklet) ---\n\n/**\n * Linear default: domain value → 0–100 track position.\n *\n * @param value - Domain value to map.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @returns Track percent clamped to 0–100.\n */\nexport function defaultMapValueToTrackPercent(\n value: number,\n minimumValue: number,\n maximumValue: number,\n): number {\n 'worklet';\n\n const range = maximumValue - minimumValue;\n if (range === 0) {\n return 0;\n }\n\n const percent = ((value - minimumValue) / range) * 100;\n return clampTrackPercent(percent);\n}\n\n/**\n * Linear default: track position → stepped domain value.\n *\n * @param trackPercent - Track position from 0–100.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @param step - Step increment for rounding.\n * @returns Stepped domain value clamped to the range.\n */\nexport function defaultMapTrackPercentToValue(\n trackPercent: number,\n minimumValue: number,\n maximumValue: number,\n step: number,\n): number {\n 'worklet';\n\n const range = maximumValue - minimumValue;\n if (range === 0) {\n return minimumValue;\n }\n\n const rawValue =\n (clampTrackPercent(trackPercent) / 100) * range + minimumValue;\n const stepped = Math.round(rawValue / step) * step;\n return Math.max(minimumValue, Math.min(maximumValue, stepped));\n}\n\n/**\n * UI-thread entry: custom `mapTrackPercentToValue` or linear default.\n *\n * @param trackPercent - Track position from 0–100.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @param step - Step increment for the default mapper.\n * @param mapTrackPercentToValue - Optional custom mapper.\n * @returns Domain value for the track position.\n */\nexport function resolveTrackPercentToValue(\n trackPercent: number,\n minimumValue: number,\n maximumValue: number,\n step: number,\n mapTrackPercentToValue?: (trackPercent: number) => number,\n): number {\n 'worklet';\n\n if (mapTrackPercentToValue) {\n return mapTrackPercentToValue(trackPercent);\n }\n\n return defaultMapTrackPercentToValue(\n trackPercent,\n minimumValue,\n maximumValue,\n step,\n );\n}\n\n/**\n * UI-thread entry: custom `mapValueToTrackPercent` or linear default.\n *\n * @param value - Domain value to map.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @param mapValueToTrackPercent - Optional custom mapper.\n * @returns Track percent for the domain value.\n */\nexport function resolveValueToTrackPercent(\n value: number,\n minimumValue: number,\n maximumValue: number,\n mapValueToTrackPercent?: (value: number) => number,\n): number {\n 'worklet';\n\n if (mapValueToTrackPercent) {\n return mapValueToTrackPercent(value);\n }\n\n return defaultMapValueToTrackPercent(value, minimumValue, maximumValue);\n}\n\n// --- Track-percent ↔ pixel position (worklet) ---\n\n/**\n * Thumb-center pixel for a track percent.\n *\n * Travel is one thumb-width shorter than the track, so the whole thumb stays\n * on the bar: at 0% its left edge is the track start, and at 100% its right\n * edge is the track end. Matches the batch-sell slider in metamask-mobile#37525.\n *\n * @param trackPercent - Track position from 0–100.\n * @param width - Track width in pixels.\n * @returns Thumb-center offset from the track start.\n */\nexport function trackPercentToPosition(\n trackPercent: number,\n width: number,\n): number {\n 'worklet';\n\n if (width === 0) {\n return 0;\n }\n\n const travel = Math.max(width - THUMB_SIZE, 0);\n return THUMB_SIZE / 2 + (clampTrackPercent(trackPercent) / 100) * travel;\n}\n\n/**\n * Track percent for a thumb-center pixel. Touches outside the thumb's travel\n * clamp to 0% or 100%.\n *\n * @param position - Thumb center, or a touch X treated as that center.\n * @param width - Track width in pixels.\n * @returns Track percent clamped to 0–100.\n */\nexport function positionToTrackPercent(\n position: number,\n width: number,\n): number {\n 'worklet';\n\n const travel = width - THUMB_SIZE;\n if (width === 0 || travel <= 0) {\n return 0;\n }\n\n const minCenter = THUMB_SIZE / 2;\n const center = Math.max(minCenter, Math.min(width - minCenter, position));\n return clampTrackPercent(((center - minCenter) / travel) * 100);\n}\n\n/**\n * Clamps a touch X to the thumb-center travel, so a drag cannot pull the thumb\n * off either end of the track.\n *\n * @param position - Touch X in track coordinates.\n * @param width - Track width in pixels.\n * @returns Clamped thumb-center position.\n */\nexport function clampGesturePosition(position: number, width: number): number {\n 'worklet';\n\n if (width === 0) {\n return 0;\n }\n\n const minCenter = THUMB_SIZE / 2;\n const maxCenter = Math.max(minCenter, width - minCenter);\n return Math.max(minCenter, Math.min(position, maxCenter));\n}\n\n// --- JS-thread domain ↔ track-percent ---\n\n/**\n * JS-thread entry for mapping domain value → track percent.\n * Used by Slider (labels, a11y) and useSliderGesture (prop/layout sync).\n *\n * @param value - Domain value to map.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @param mapValueToTrackPercent - Optional custom mapper.\n * @returns Track percent for the domain value.\n */\nexport function getTrackPercentFromValue(\n value: number,\n minimumValue: number,\n maximumValue: number,\n mapValueToTrackPercent?: (value: number) => number,\n): number {\n if (mapValueToTrackPercent) {\n return mapValueToTrackPercent(value);\n }\n\n return defaultMapValueToTrackPercent(value, minimumValue, maximumValue);\n}\n\n// --- Range label / dot defaults (Slider.tsx) ---\n\n/**\n * Default linear track-percent → domain value for a mark.\n *\n * @param step - Track-percent step from a mark entry.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @returns Domain value for the step.\n */\nexport function defaultStepToValue(\n step: number,\n minimumValue: number,\n maximumValue: number,\n): number {\n return (step / 100) * (maximumValue - minimumValue) + minimumValue;\n}\n\n/**\n * Domain value for a mark: explicit `value` or linear default from step.\n *\n * @param mark - Mark entry.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @returns Domain value for the mark.\n */\nexport function getMarkValue(\n mark: SliderMark,\n minimumValue: number,\n maximumValue: number,\n): number {\n if (mark.value !== undefined) {\n return mark.value;\n }\n\n return defaultStepToValue(mark.step, minimumValue, maximumValue);\n}\n\n/**\n * Track-percent thresholds that trigger onMark while dragging.\n *\n * @param marks - Mark entries.\n * @returns Haptic threshold positions.\n */\nexport function getMarkHapticThresholds(\n marks: readonly SliderMark[],\n): number[] {\n return marks\n .filter((mark) => mark.haptic ?? Boolean(mark.label))\n .map((mark) => mark.step);\n}\n\n/**\n * Resolves a mark color to a concrete color string for Reanimated.\n * Design tokens are looked up on the palette; raw hex/rgb pass through\n * (temporary migration bridge — prefer `SliderMarkColor` tokens in app code).\n *\n * @param color - Theme token key (or legacy hex/rgb string).\n * @param palette - Flattened theme color palette.\n * @param fallback - Fallback color when token is not found.\n * @returns Resolved color string.\n */\nexport function resolveMarkColor(\n color: SliderMarkColor | string,\n palette: Record<string, string>,\n fallback: string,\n): string {\n if (color.startsWith('#') || color.startsWith('rgb')) {\n return color;\n }\n\n return palette[color] ?? fallback;\n}\n\n/**\n * Builds color interpolation stops from marks, applying fallback for missing colors.\n *\n * @param marks - Mark entries.\n * @param palette - Flattened theme color palette.\n * @param fallbackToken - Default token key when mark.color is omitted.\n * @returns Sorted color stops for interpolation.\n */\nexport function buildColorStops(\n marks: readonly SliderMark[],\n palette: Record<string, string>,\n fallbackToken: string,\n): SliderColorStop[] {\n const fallback = palette[fallbackToken] ?? '#000000';\n\n return [...marks]\n .sort((a, b) => a.step - b.step)\n .map((mark) => ({\n step: mark.step,\n color: mark.color\n ? resolveMarkColor(mark.color, palette, fallback)\n : fallback,\n }));\n}\n\n/**\n * Interpolates a color along the track based on mark color stops.\n *\n * @param trackPercent - Current track position from 0–100.\n * @param stops - Sorted color stops.\n * @returns Interpolated color string.\n */\nexport function interpolateMarkColor(\n trackPercent: number,\n stops: readonly SliderColorStop[],\n): string {\n 'worklet';\n\n if (stops.length === 0) {\n return '#000000';\n }\n\n if (stops.length === 1) {\n return stops[0].color;\n }\n\n const inputRange = stops.map((stop) => stop.step);\n const outputRange = stops.map((stop) => stop.color);\n\n return interpolateColor(\n clampTrackPercent(trackPercent),\n inputRange,\n outputRange,\n 'RGB',\n );\n}\n\n/**\n * Whether any mark defines a theme color.\n *\n * @param marks - Mark entries.\n * @returns True when at least one mark has a color.\n */\nexport function hasThemedMarkColors(marks: readonly SliderMark[]): boolean {\n return marks.some((mark) => Boolean(mark.color));\n}\n\n/**\n * Marker `left` percent for range dots and labels; edge steps inset to stay on track.\n *\n * @param step - Track-percent step from a mark entry.\n * @returns CSS `left` percentage string.\n */\nexport function getDotLeftPercent(step: number): string {\n if (step === 0) {\n return DOT_EDGE_INSET_PERCENT;\n }\n if (step === 100) {\n return DOT_EDGE_MAX_PERCENT;\n }\n\n return `${step}%`;\n}\n\n// --- Accessibility (Slider.tsx) ---\n\n/**\n * Clamps and steps a domain value for increment/decrement actions.\n *\n * @param value - Domain value to clamp.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @param step - Step increment for rounding.\n * @returns Clamped and stepped domain value.\n */\nexport function clampValueToRange(\n value: number,\n minimumValue: number,\n maximumValue: number,\n step: number,\n): number {\n const range = maximumValue - minimumValue;\n if (range === 0) {\n return minimumValue;\n }\n\n const clamped = Math.max(minimumValue, Math.min(maximumValue, value));\n return Math.round(clamped / step) * step;\n}\n"]}
@@ -5,7 +5,8 @@
5
5
  * - **Domain value** — the controlled `value` prop (`minimumValue`…`maximumValue`).
6
6
  * - **Track percent** — normalized 0–100 position along the track (used for dots,
7
7
  * labels, and haptic thresholds; may be non-linear via `map*` hooks).
8
- * - **Pixel position** — thumb/fill offset in layout pixels (`translateX`).
8
+ * - **Pixel position** — thumb-center offset in layout pixels (`translateX`).
9
+ * Travel is inset by half the thumb so the circle stays on the track.
9
10
  *
10
11
  * Functions marked with `'worklet'` run on the UI thread inside gesture handlers.
11
12
  * JS-thread callers use the non-worklet wrappers (`getTrackPercentFromValue`, etc.).
@@ -56,14 +57,34 @@ export declare function resolveTrackPercentToValue(trackPercent: number, minimum
56
57
  * @returns Track percent for the domain value.
57
58
  */
58
59
  export declare function resolveValueToTrackPercent(value: number, minimumValue: number, maximumValue: number, mapValueToTrackPercent?: (value: number) => number): number;
60
+ /**
61
+ * Thumb-center pixel for a track percent.
62
+ *
63
+ * Travel is one thumb-width shorter than the track, so the whole thumb stays
64
+ * on the bar: at 0% its left edge is the track start, and at 100% its right
65
+ * edge is the track end. Matches the batch-sell slider in metamask-mobile#37525.
66
+ *
67
+ * @param trackPercent - Track position from 0–100.
68
+ * @param width - Track width in pixels.
69
+ * @returns Thumb-center offset from the track start.
70
+ */
59
71
  export declare function trackPercentToPosition(trackPercent: number, width: number): number;
72
+ /**
73
+ * Track percent for a thumb-center pixel. Touches outside the thumb's travel
74
+ * clamp to 0% or 100%.
75
+ *
76
+ * @param position - Thumb center, or a touch X treated as that center.
77
+ * @param width - Track width in pixels.
78
+ * @returns Track percent clamped to 0–100.
79
+ */
60
80
  export declare function positionToTrackPercent(position: number, width: number): number;
61
81
  /**
62
- * Clamps a touch X coordinate to the track bounds.
82
+ * Clamps a touch X to the thumb-center travel, so a drag cannot pull the thumb
83
+ * off either end of the track.
63
84
  *
64
85
  * @param position - Touch X in track coordinates.
65
86
  * @param width - Track width in pixels.
66
- * @returns Clamped pixel position.
87
+ * @returns Clamped thumb-center position.
67
88
  */
68
89
  export declare function clampGesturePosition(position: number, width: number): number;
69
90
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Slider.utilities.d.cts","sourceRoot":"","sources":["../../../src/components/Slider/Slider.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AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,GACX,MAAM,CAQR"}
1
+ {"version":3,"file":"Slider.utilities.d.cts","sourceRoot":"","sources":["../../../src/components/Slider/Slider.utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,eAAe,EAChB,gDAAgD;AASjD,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAIF,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAI9D;AAID;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,GACnB,MAAM,CAUR;AAED;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAC3C,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,GACX,MAAM,CAYR;AAED;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CACxC,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,EACZ,sBAAsB,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,GACxD,MAAM,CAaR;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,sBAAsB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GACjD,MAAM,CAQR;AAID;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,MA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B,KAAK,EAAE,SAAS,eAAe,EAAE,GAChC,MAAM,CAoBR;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,GAAG,OAAO,CAEzE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAStD;AAID;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,GACX,MAAM,CAQR"}
@@ -5,7 +5,8 @@
5
5
  * - **Domain value** — the controlled `value` prop (`minimumValue`…`maximumValue`).
6
6
  * - **Track percent** — normalized 0–100 position along the track (used for dots,
7
7
  * labels, and haptic thresholds; may be non-linear via `map*` hooks).
8
- * - **Pixel position** — thumb/fill offset in layout pixels (`translateX`).
8
+ * - **Pixel position** — thumb-center offset in layout pixels (`translateX`).
9
+ * Travel is inset by half the thumb so the circle stays on the track.
9
10
  *
10
11
  * Functions marked with `'worklet'` run on the UI thread inside gesture handlers.
11
12
  * JS-thread callers use the non-worklet wrappers (`getTrackPercentFromValue`, etc.).
@@ -56,14 +57,34 @@ export declare function resolveTrackPercentToValue(trackPercent: number, minimum
56
57
  * @returns Track percent for the domain value.
57
58
  */
58
59
  export declare function resolveValueToTrackPercent(value: number, minimumValue: number, maximumValue: number, mapValueToTrackPercent?: (value: number) => number): number;
60
+ /**
61
+ * Thumb-center pixel for a track percent.
62
+ *
63
+ * Travel is one thumb-width shorter than the track, so the whole thumb stays
64
+ * on the bar: at 0% its left edge is the track start, and at 100% its right
65
+ * edge is the track end. Matches the batch-sell slider in metamask-mobile#37525.
66
+ *
67
+ * @param trackPercent - Track position from 0–100.
68
+ * @param width - Track width in pixels.
69
+ * @returns Thumb-center offset from the track start.
70
+ */
59
71
  export declare function trackPercentToPosition(trackPercent: number, width: number): number;
72
+ /**
73
+ * Track percent for a thumb-center pixel. Touches outside the thumb's travel
74
+ * clamp to 0% or 100%.
75
+ *
76
+ * @param position - Thumb center, or a touch X treated as that center.
77
+ * @param width - Track width in pixels.
78
+ * @returns Track percent clamped to 0–100.
79
+ */
60
80
  export declare function positionToTrackPercent(position: number, width: number): number;
61
81
  /**
62
- * Clamps a touch X coordinate to the track bounds.
82
+ * Clamps a touch X to the thumb-center travel, so a drag cannot pull the thumb
83
+ * off either end of the track.
63
84
  *
64
85
  * @param position - Touch X in track coordinates.
65
86
  * @param width - Track width in pixels.
66
- * @returns Clamped pixel position.
87
+ * @returns Clamped thumb-center position.
67
88
  */
68
89
  export declare function clampGesturePosition(position: number, width: number): number;
69
90
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Slider.utilities.d.mts","sourceRoot":"","sources":["../../../src/components/Slider/Slider.utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,eAAe,EAChB,gDAAgD;AAQjD,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAIF,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAI9D;AAID;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,GACnB,MAAM,CAUR;AAED;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAC3C,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,GACX,MAAM,CAYR;AAED;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CACxC,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,EACZ,sBAAsB,CAAC,EAAE,CA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AAM,GACf,MAAM,CAMR;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,SAAS,UAAU,EAAE,EAC5B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,aAAa,EAAE,MAAM,GACpB,eAAe,EAAE,CAWnB;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,SAAS,eAAe,EAAE,GAChC,MAAM,CAoBR;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,GAAG,OAAO,CAEzE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAStD;AAID;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,GACX,MAAM,CAQR"}
1
+ {"version":3,"file":"Slider.utilities.d.mts","sourceRoot":"","sources":["../../../src/components/Slider/Slider.utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,eAAe,EAChB,gDAAgD;AASjD,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAIF,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAI9D;AAID;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,GACnB,MAAM,CAUR;AAED;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAC3C,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACp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AKG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,SAAS,UAAU,EAAE,GAC3B,MAAM,EAAE,CAIV;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,eAAe,GAAG,MAAM,EAC/B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,QAAQ,EAAE,MAAM,GACf,MAAM,CAMR;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,SAAS,UAAU,EAAE,EAC5B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,aAAa,EAAE,MAAM,GACpB,eAAe,EAAE,CAWnB;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,SAAS,eAAe,EAAE,GAChC,MAAM,CAoBR;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,GAAG,OAAO,CAEzE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAStD;AAID;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,GACX,MAAM,CAQR"}
@@ -5,13 +5,14 @@
5
5
  * - **Domain value** — the controlled `value` prop (`minimumValue`…`maximumValue`).
6
6
  * - **Track percent** — normalized 0–100 position along the track (used for dots,
7
7
  * labels, and haptic thresholds; may be non-linear via `map*` hooks).
8
- * - **Pixel position** — thumb/fill offset in layout pixels (`translateX`).
8
+ * - **Pixel position** — thumb-center offset in layout pixels (`translateX`).
9
+ * Travel is inset by half the thumb so the circle stays on the track.
9
10
  *
10
11
  * Functions marked with `'worklet'` run on the UI thread inside gesture handlers.
11
12
  * JS-thread callers use the non-worklet wrappers (`getTrackPercentFromValue`, etc.).
12
13
  */
13
14
  import { interpolateColor } from "react-native-reanimated";
14
- import { DOT_EDGE_INSET_PERCENT, DOT_EDGE_MAX_PERCENT } from "./Slider.constants.mjs";
15
+ import { DOT_EDGE_INSET_PERCENT, DOT_EDGE_MAX_PERCENT, THUMB_SIZE } from "./Slider.constants.mjs";
15
16
  // --- Track-percent primitives (worklet) ---
16
17
  export function clampTrackPercent(trackPercent) {
17
18
  'worklet';
@@ -88,30 +89,59 @@ export function resolveValueToTrackPercent(value, minimumValue, maximumValue, ma
88
89
  return defaultMapValueToTrackPercent(value, minimumValue, maximumValue);
89
90
  }
90
91
  // --- Track-percent ↔ pixel position (worklet) ---
92
+ /**
93
+ * Thumb-center pixel for a track percent.
94
+ *
95
+ * Travel is one thumb-width shorter than the track, so the whole thumb stays
96
+ * on the bar: at 0% its left edge is the track start, and at 100% its right
97
+ * edge is the track end. Matches the batch-sell slider in metamask-mobile#37525.
98
+ *
99
+ * @param trackPercent - Track position from 0–100.
100
+ * @param width - Track width in pixels.
101
+ * @returns Thumb-center offset from the track start.
102
+ */
91
103
  export function trackPercentToPosition(trackPercent, width) {
92
104
  'worklet';
93
105
  if (width === 0) {
94
106
  return 0;
95
107
  }
96
- return (clampTrackPercent(trackPercent) / 100) * width;
108
+ const travel = Math.max(width - THUMB_SIZE, 0);
109
+ return THUMB_SIZE / 2 + (clampTrackPercent(trackPercent) / 100) * travel;
97
110
  }
111
+ /**
112
+ * Track percent for a thumb-center pixel. Touches outside the thumb's travel
113
+ * clamp to 0% or 100%.
114
+ *
115
+ * @param position - Thumb center, or a touch X treated as that center.
116
+ * @param width - Track width in pixels.
117
+ * @returns Track percent clamped to 0–100.
118
+ */
98
119
  export function positionToTrackPercent(position, width) {
99
120
  'worklet';
100
- if (width === 0) {
121
+ const travel = width - THUMB_SIZE;
122
+ if (width === 0 || travel <= 0) {
101
123
  return 0;
102
124
  }
103
- return clampTrackPercent((position / width) * 100);
125
+ const minCenter = THUMB_SIZE / 2;
126
+ const center = Math.max(minCenter, Math.min(width - minCenter, position));
127
+ return clampTrackPercent(((center - minCenter) / travel) * 100);
104
128
  }
105
129
  /**
106
- * Clamps a touch X coordinate to the track bounds.
130
+ * Clamps a touch X to the thumb-center travel, so a drag cannot pull the thumb
131
+ * off either end of the track.
107
132
  *
108
133
  * @param position - Touch X in track coordinates.
109
134
  * @param width - Track width in pixels.
110
- * @returns Clamped pixel position.
135
+ * @returns Clamped thumb-center position.
111
136
  */
112
137
  export function clampGesturePosition(position, width) {
113
138
  'worklet';
114
- return Math.max(0, Math.min(position, width));
139
+ if (width === 0) {
140
+ return 0;
141
+ }
142
+ const minCenter = THUMB_SIZE / 2;
143
+ const maxCenter = Math.max(minCenter, width - minCenter);
144
+ return Math.max(minCenter, Math.min(position, maxCenter));
115
145
  }
116
146
  // --- JS-thread domain ↔ track-percent ---
117
147
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Slider.utilities.mjs","sourceRoot":"","sources":["../../../src/components/Slider/Slider.utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH,OAAO,EAAE,gBAAgB,EAAE,gCAAgC;AAE3D,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACrB,+BAA2B;AAO5B,6CAA6C;AAE7C,MAAM,UAAU,iBAAiB,CAAC,YAAoB;IACpD,SAAS,CAAC;IAEV,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC;AAClD,CAAC;AAED,mDAAmD;AAEnD;;;;;;;GAOG;AACH,MAAM,UAAU,6BAA6B,CAC3C,KAAa,EACb,YAAoB,EACpB,YAAoB;IAEpB,SAAS,CAAC;IAEV,MAAM,KAAK,GAAG,YAAY,GAAG,YAAY,CAAC;IAC1C,IAAI,KAAK,KAAK,CAAC,EAAE;QACf,OAAO,CAAC,CAAC;KACV;IAED,MAAM,OAAO,GAAG,CAAC,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,YAAY,GAAG,YAAY,CAAC;IAC1C,IAAI,KAAK,KAAK,CAAC,EAAE;QACf,OAAO,YAAY,CAAC;KACrB;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,CAAC;IACtE,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;AAC3C,CAAC","sourcesContent":["/**\n * Pure helpers for Slider coordinate conversion and UI defaults.\n *\n * Three coordinate systems:\n * - **Domain value** — the controlled `value` prop (`minimumValue`…`maximumValue`).\n * - **Track percent** — normalized 0–100 position along the track (used for dots,\n * labels, and haptic thresholds; may be non-linear via `map*` hooks).\n * - **Pixel position** — thumb/fill offset in layout pixels (`translateX`).\n *\n * Functions marked with `'worklet'` run on the UI thread inside gesture handlers.\n * JS-thread callers use the non-worklet wrappers (`getTrackPercentFromValue`, etc.).\n */\n\nimport type {\n SliderMark,\n SliderMarkColor,\n} from '@metamask-previews/design-system-shared';\nimport { interpolateColor } from 'react-native-reanimated';\n\nimport {\n DOT_EDGE_INSET_PERCENT,\n DOT_EDGE_MAX_PERCENT,\n} from './Slider.constants';\n\nexport type SliderColorStop = {\n step: number;\n color: string;\n};\n\n// --- Track-percent primitives (worklet) ---\n\nexport function clampTrackPercent(trackPercent: number): number {\n 'worklet';\n\n return Math.max(0, Math.min(100, trackPercent));\n}\n\n// --- Domain ↔ track-percent mappers (worklet) ---\n\n/**\n * Linear default: domain value → 0–100 track position.\n *\n * @param value - Domain value to map.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @returns Track percent clamped to 0–100.\n */\nexport function defaultMapValueToTrackPercent(\n value: number,\n minimumValue: number,\n maximumValue: number,\n): number {\n 'worklet';\n\n const range = maximumValue - minimumValue;\n if (range === 0) {\n return 0;\n }\n\n const percent = ((value - minimumValue) / range) * 100;\n return clampTrackPercent(percent);\n}\n\n/**\n * Linear default: track position → stepped domain value.\n *\n * @param trackPercent - Track position from 0–100.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @param step - Step increment for rounding.\n * @returns Stepped domain value clamped to the range.\n */\nexport function defaultMapTrackPercentToValue(\n trackPercent: number,\n minimumValue: number,\n maximumValue: number,\n step: number,\n): number {\n 'worklet';\n\n const range = maximumValue - minimumValue;\n if (range === 0) {\n return minimumValue;\n }\n\n const rawValue =\n (clampTrackPercent(trackPercent) / 100) * range + minimumValue;\n const stepped = Math.round(rawValue / step) * step;\n return Math.max(minimumValue, Math.min(maximumValue, stepped));\n}\n\n/**\n * UI-thread entry: custom `mapTrackPercentToValue` or linear default.\n *\n * @param trackPercent - Track position from 0–100.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @param step - Step increment for the default mapper.\n * @param mapTrackPercentToValue - Optional custom mapper.\n * @returns Domain value for the track position.\n */\nexport function resolveTrackPercentToValue(\n trackPercent: number,\n minimumValue: number,\n maximumValue: number,\n step: number,\n mapTrackPercentToValue?: (trackPercent: number) => number,\n): number {\n 'worklet';\n\n if (mapTrackPercentToValue) {\n return mapTrackPercentToValue(trackPercent);\n }\n\n return defaultMapTrackPercentToValue(\n trackPercent,\n minimumValue,\n maximumValue,\n step,\n );\n}\n\n/**\n * UI-thread entry: custom `mapValueToTrackPercent` or linear default.\n *\n * @param value - Domain value to map.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @param mapValueToTrackPercent - Optional custom mapper.\n * @returns Track percent for the domain value.\n */\nexport function resolveValueToTrackPercent(\n value: number,\n minimumValue: number,\n maximumValue: number,\n mapValueToTrackPercent?: (value: number) => number,\n): number {\n 'worklet';\n\n if (mapValueToTrackPercent) {\n return mapValueToTrackPercent(value);\n }\n\n return defaultMapValueToTrackPercent(value, minimumValue, maximumValue);\n}\n\n// --- Track-percent ↔ pixel position (worklet) ---\n\nexport function trackPercentToPosition(\n trackPercent: number,\n width: number,\n): number {\n 'worklet';\n\n if (width === 0) {\n return 0;\n }\n\n return (clampTrackPercent(trackPercent) / 100) * width;\n}\n\nexport function positionToTrackPercent(\n position: number,\n width: number,\n): number {\n 'worklet';\n\n if (width === 0) {\n return 0;\n }\n\n return clampTrackPercent((position / width) * 100);\n}\n\n/**\n * Clamps a touch X coordinate to the track bounds.\n *\n * @param position - Touch X in track coordinates.\n * @param width - Track width in pixels.\n * @returns Clamped pixel position.\n */\nexport function clampGesturePosition(position: number, width: number): number {\n 'worklet';\n\n return Math.max(0, Math.min(position, width));\n}\n\n// --- JS-thread domain ↔ track-percent ---\n\n/**\n * JS-thread entry for mapping domain value → track percent.\n * Used by Slider (labels, a11y) and useSliderGesture (prop/layout sync).\n *\n * @param value - Domain value to map.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @param mapValueToTrackPercent - Optional custom mapper.\n * @returns Track percent for the domain value.\n */\nexport function getTrackPercentFromValue(\n value: number,\n minimumValue: number,\n maximumValue: number,\n mapValueToTrackPercent?: (value: number) => number,\n): number {\n if (mapValueToTrackPercent) {\n return mapValueToTrackPercent(value);\n }\n\n return defaultMapValueToTrackPercent(value, minimumValue, maximumValue);\n}\n\n// --- Range label / dot defaults (Slider.tsx) ---\n\n/**\n * Default linear track-percent → domain value for a mark.\n *\n * @param step - Track-percent step from a mark entry.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @returns Domain value for the step.\n */\nexport function defaultStepToValue(\n step: number,\n minimumValue: number,\n maximumValue: number,\n): number {\n return (step / 100) * (maximumValue - minimumValue) + minimumValue;\n}\n\n/**\n * Domain value for a mark: explicit `value` or linear default from step.\n *\n * @param mark - Mark entry.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @returns Domain value for the mark.\n */\nexport function getMarkValue(\n mark: SliderMark,\n minimumValue: number,\n maximumValue: number,\n): number {\n if (mark.value !== undefined) {\n return mark.value;\n }\n\n return defaultStepToValue(mark.step, minimumValue, maximumValue);\n}\n\n/**\n * Track-percent thresholds that trigger onMark while dragging.\n *\n * @param marks - Mark entries.\n * @returns Haptic threshold positions.\n */\nexport function getMarkHapticThresholds(\n marks: readonly SliderMark[],\n): number[] {\n return marks\n .filter((mark) => mark.haptic ?? Boolean(mark.label))\n .map((mark) => mark.step);\n}\n\n/**\n * Resolves a mark color to a concrete color string for Reanimated.\n * Design tokens are looked up on the palette; raw hex/rgb pass through\n * (temporary migration bridge — prefer `SliderMarkColor` tokens in app code).\n *\n * @param color - Theme token key (or legacy hex/rgb string).\n * @param palette - Flattened theme color palette.\n * @param fallback - Fallback color when token is not found.\n * @returns Resolved color string.\n */\nexport function resolveMarkColor(\n color: SliderMarkColor | string,\n palette: Record<string, string>,\n fallback: string,\n): string {\n if (color.startsWith('#') || color.startsWith('rgb')) {\n return color;\n }\n\n return palette[color] ?? fallback;\n}\n\n/**\n * Builds color interpolation stops from marks, applying fallback for missing colors.\n *\n * @param marks - Mark entries.\n * @param palette - Flattened theme color palette.\n * @param fallbackToken - Default token key when mark.color is omitted.\n * @returns Sorted color stops for interpolation.\n */\nexport function buildColorStops(\n marks: readonly SliderMark[],\n palette: Record<string, string>,\n fallbackToken: string,\n): SliderColorStop[] {\n const fallback = palette[fallbackToken] ?? '#000000';\n\n return [...marks]\n .sort((a, b) => a.step - b.step)\n .map((mark) => ({\n step: mark.step,\n color: mark.color\n ? resolveMarkColor(mark.color, palette, fallback)\n : fallback,\n }));\n}\n\n/**\n * Interpolates a color along the track based on mark color stops.\n *\n * @param trackPercent - Current track position from 0–100.\n * @param stops - Sorted color stops.\n * @returns Interpolated color string.\n */\nexport function interpolateMarkColor(\n trackPercent: number,\n stops: readonly SliderColorStop[],\n): string {\n 'worklet';\n\n if (stops.length === 0) {\n return '#000000';\n }\n\n if (stops.length === 1) {\n return stops[0].color;\n }\n\n const inputRange = stops.map((stop) => stop.step);\n const outputRange = stops.map((stop) => stop.color);\n\n return interpolateColor(\n clampTrackPercent(trackPercent),\n inputRange,\n outputRange,\n 'RGB',\n );\n}\n\n/**\n * Whether any mark defines a theme color.\n *\n * @param marks - Mark entries.\n * @returns True when at least one mark has a color.\n */\nexport function hasThemedMarkColors(marks: readonly SliderMark[]): boolean {\n return marks.some((mark) => Boolean(mark.color));\n}\n\n/**\n * Marker `left` percent for range dots and labels; edge steps inset to stay on track.\n *\n * @param step - Track-percent step from a mark entry.\n * @returns CSS `left` percentage string.\n */\nexport function getDotLeftPercent(step: number): string {\n if (step === 0) {\n return DOT_EDGE_INSET_PERCENT;\n }\n if (step === 100) {\n return DOT_EDGE_MAX_PERCENT;\n }\n\n return `${step}%`;\n}\n\n// --- Accessibility (Slider.tsx) ---\n\n/**\n * Clamps and steps a domain value for increment/decrement actions.\n *\n * @param value - Domain value to clamp.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @param step - Step increment for rounding.\n * @returns Clamped and stepped domain value.\n */\nexport function clampValueToRange(\n value: number,\n minimumValue: number,\n maximumValue: number,\n step: number,\n): number {\n const range = maximumValue - minimumValue;\n if (range === 0) {\n return minimumValue;\n }\n\n const clamped = Math.max(minimumValue, Math.min(maximumValue, value));\n return Math.round(clamped / step) * step;\n}\n"]}
1
+ {"version":3,"file":"Slider.utilities.mjs","sourceRoot":"","sources":["../../../src/components/Slider/Slider.utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAMH,OAAO,EAAE,gBAAgB,EAAE,gCAAgC;AAE3D,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,UAAU,EACX,+BAA2B;AAO5B,6CAA6C;AAE7C,MAAM,UAAU,iBAAiB,CAAC,YAAoB;IACpD,SAAS,CAAC;IAEV,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC,C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* Pure helpers for Slider coordinate conversion and UI defaults.\n *\n * Three coordinate systems:\n * - **Domain value** — the controlled `value` prop (`minimumValue`…`maximumValue`).\n * - **Track percent** — normalized 0–100 position along the track (used for dots,\n * labels, and haptic thresholds; may be non-linear via `map*` hooks).\n * - **Pixel position** — thumb-center offset in layout pixels (`translateX`).\n * Travel is inset by half the thumb so the circle stays on the track.\n *\n * Functions marked with `'worklet'` run on the UI thread inside gesture handlers.\n * JS-thread callers use the non-worklet wrappers (`getTrackPercentFromValue`, etc.).\n */\n\nimport type {\n SliderMark,\n SliderMarkColor,\n} from '@metamask-previews/design-system-shared';\nimport { interpolateColor } from 'react-native-reanimated';\n\nimport {\n DOT_EDGE_INSET_PERCENT,\n DOT_EDGE_MAX_PERCENT,\n THUMB_SIZE,\n} from './Slider.constants';\n\nexport type SliderColorStop = {\n step: number;\n color: string;\n};\n\n// --- Track-percent primitives (worklet) ---\n\nexport function clampTrackPercent(trackPercent: number): number {\n 'worklet';\n\n return Math.max(0, Math.min(100, trackPercent));\n}\n\n// --- Domain ↔ track-percent mappers (worklet) ---\n\n/**\n * Linear default: domain value → 0–100 track position.\n *\n * @param value - Domain value to map.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @returns Track percent clamped to 0–100.\n */\nexport function defaultMapValueToTrackPercent(\n value: number,\n minimumValue: number,\n maximumValue: number,\n): number {\n 'worklet';\n\n const range = maximumValue - minimumValue;\n if (range === 0) {\n return 0;\n }\n\n const percent = ((value - minimumValue) / range) * 100;\n return clampTrackPercent(percent);\n}\n\n/**\n * Linear default: track position → stepped domain value.\n *\n * @param trackPercent - Track position from 0–100.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @param step - Step increment for rounding.\n * @returns Stepped domain value clamped to the range.\n */\nexport function defaultMapTrackPercentToValue(\n trackPercent: number,\n minimumValue: number,\n maximumValue: number,\n step: number,\n): number {\n 'worklet';\n\n const range = maximumValue - minimumValue;\n if (range === 0) {\n return minimumValue;\n }\n\n const rawValue =\n (clampTrackPercent(trackPercent) / 100) * range + minimumValue;\n const stepped = Math.round(rawValue / step) * step;\n return Math.max(minimumValue, Math.min(maximumValue, stepped));\n}\n\n/**\n * UI-thread entry: custom `mapTrackPercentToValue` or linear default.\n *\n * @param trackPercent - Track position from 0–100.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @param step - Step increment for the default mapper.\n * @param mapTrackPercentToValue - Optional custom mapper.\n * @returns Domain value for the track position.\n */\nexport function resolveTrackPercentToValue(\n trackPercent: number,\n minimumValue: number,\n maximumValue: number,\n step: number,\n mapTrackPercentToValue?: (trackPercent: number) => number,\n): number {\n 'worklet';\n\n if (mapTrackPercentToValue) {\n return mapTrackPercentToValue(trackPercent);\n }\n\n return defaultMapTrackPercentToValue(\n trackPercent,\n minimumValue,\n maximumValue,\n step,\n );\n}\n\n/**\n * UI-thread entry: custom `mapValueToTrackPercent` or linear default.\n *\n * @param value - Domain value to map.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @param mapValueToTrackPercent - Optional custom mapper.\n * @returns Track percent for the domain value.\n */\nexport function resolveValueToTrackPercent(\n value: number,\n minimumValue: number,\n maximumValue: number,\n mapValueToTrackPercent?: (value: number) => number,\n): number {\n 'worklet';\n\n if (mapValueToTrackPercent) {\n return mapValueToTrackPercent(value);\n }\n\n return defaultMapValueToTrackPercent(value, minimumValue, maximumValue);\n}\n\n// --- Track-percent ↔ pixel position (worklet) ---\n\n/**\n * Thumb-center pixel for a track percent.\n *\n * Travel is one thumb-width shorter than the track, so the whole thumb stays\n * on the bar: at 0% its left edge is the track start, and at 100% its right\n * edge is the track end. Matches the batch-sell slider in metamask-mobile#37525.\n *\n * @param trackPercent - Track position from 0–100.\n * @param width - Track width in pixels.\n * @returns Thumb-center offset from the track start.\n */\nexport function trackPercentToPosition(\n trackPercent: number,\n width: number,\n): number {\n 'worklet';\n\n if (width === 0) {\n return 0;\n }\n\n const travel = Math.max(width - THUMB_SIZE, 0);\n return THUMB_SIZE / 2 + (clampTrackPercent(trackPercent) / 100) * travel;\n}\n\n/**\n * Track percent for a thumb-center pixel. Touches outside the thumb's travel\n * clamp to 0% or 100%.\n *\n * @param position - Thumb center, or a touch X treated as that center.\n * @param width - Track width in pixels.\n * @returns Track percent clamped to 0–100.\n */\nexport function positionToTrackPercent(\n position: number,\n width: number,\n): number {\n 'worklet';\n\n const travel = width - THUMB_SIZE;\n if (width === 0 || travel <= 0) {\n return 0;\n }\n\n const minCenter = THUMB_SIZE / 2;\n const center = Math.max(minCenter, Math.min(width - minCenter, position));\n return clampTrackPercent(((center - minCenter) / travel) * 100);\n}\n\n/**\n * Clamps a touch X to the thumb-center travel, so a drag cannot pull the thumb\n * off either end of the track.\n *\n * @param position - Touch X in track coordinates.\n * @param width - Track width in pixels.\n * @returns Clamped thumb-center position.\n */\nexport function clampGesturePosition(position: number, width: number): number {\n 'worklet';\n\n if (width === 0) {\n return 0;\n }\n\n const minCenter = THUMB_SIZE / 2;\n const maxCenter = Math.max(minCenter, width - minCenter);\n return Math.max(minCenter, Math.min(position, maxCenter));\n}\n\n// --- JS-thread domain ↔ track-percent ---\n\n/**\n * JS-thread entry for mapping domain value → track percent.\n * Used by Slider (labels, a11y) and useSliderGesture (prop/layout sync).\n *\n * @param value - Domain value to map.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @param mapValueToTrackPercent - Optional custom mapper.\n * @returns Track percent for the domain value.\n */\nexport function getTrackPercentFromValue(\n value: number,\n minimumValue: number,\n maximumValue: number,\n mapValueToTrackPercent?: (value: number) => number,\n): number {\n if (mapValueToTrackPercent) {\n return mapValueToTrackPercent(value);\n }\n\n return defaultMapValueToTrackPercent(value, minimumValue, maximumValue);\n}\n\n// --- Range label / dot defaults (Slider.tsx) ---\n\n/**\n * Default linear track-percent → domain value for a mark.\n *\n * @param step - Track-percent step from a mark entry.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @returns Domain value for the step.\n */\nexport function defaultStepToValue(\n step: number,\n minimumValue: number,\n maximumValue: number,\n): number {\n return (step / 100) * (maximumValue - minimumValue) + minimumValue;\n}\n\n/**\n * Domain value for a mark: explicit `value` or linear default from step.\n *\n * @param mark - Mark entry.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @returns Domain value for the mark.\n */\nexport function getMarkValue(\n mark: SliderMark,\n minimumValue: number,\n maximumValue: number,\n): number {\n if (mark.value !== undefined) {\n return mark.value;\n }\n\n return defaultStepToValue(mark.step, minimumValue, maximumValue);\n}\n\n/**\n * Track-percent thresholds that trigger onMark while dragging.\n *\n * @param marks - Mark entries.\n * @returns Haptic threshold positions.\n */\nexport function getMarkHapticThresholds(\n marks: readonly SliderMark[],\n): number[] {\n return marks\n .filter((mark) => mark.haptic ?? Boolean(mark.label))\n .map((mark) => mark.step);\n}\n\n/**\n * Resolves a mark color to a concrete color string for Reanimated.\n * Design tokens are looked up on the palette; raw hex/rgb pass through\n * (temporary migration bridge — prefer `SliderMarkColor` tokens in app code).\n *\n * @param color - Theme token key (or legacy hex/rgb string).\n * @param palette - Flattened theme color palette.\n * @param fallback - Fallback color when token is not found.\n * @returns Resolved color string.\n */\nexport function resolveMarkColor(\n color: SliderMarkColor | string,\n palette: Record<string, string>,\n fallback: string,\n): string {\n if (color.startsWith('#') || color.startsWith('rgb')) {\n return color;\n }\n\n return palette[color] ?? fallback;\n}\n\n/**\n * Builds color interpolation stops from marks, applying fallback for missing colors.\n *\n * @param marks - Mark entries.\n * @param palette - Flattened theme color palette.\n * @param fallbackToken - Default token key when mark.color is omitted.\n * @returns Sorted color stops for interpolation.\n */\nexport function buildColorStops(\n marks: readonly SliderMark[],\n palette: Record<string, string>,\n fallbackToken: string,\n): SliderColorStop[] {\n const fallback = palette[fallbackToken] ?? '#000000';\n\n return [...marks]\n .sort((a, b) => a.step - b.step)\n .map((mark) => ({\n step: mark.step,\n color: mark.color\n ? resolveMarkColor(mark.color, palette, fallback)\n : fallback,\n }));\n}\n\n/**\n * Interpolates a color along the track based on mark color stops.\n *\n * @param trackPercent - Current track position from 0–100.\n * @param stops - Sorted color stops.\n * @returns Interpolated color string.\n */\nexport function interpolateMarkColor(\n trackPercent: number,\n stops: readonly SliderColorStop[],\n): string {\n 'worklet';\n\n if (stops.length === 0) {\n return '#000000';\n }\n\n if (stops.length === 1) {\n return stops[0].color;\n }\n\n const inputRange = stops.map((stop) => stop.step);\n const outputRange = stops.map((stop) => stop.color);\n\n return interpolateColor(\n clampTrackPercent(trackPercent),\n inputRange,\n outputRange,\n 'RGB',\n );\n}\n\n/**\n * Whether any mark defines a theme color.\n *\n * @param marks - Mark entries.\n * @returns True when at least one mark has a color.\n */\nexport function hasThemedMarkColors(marks: readonly SliderMark[]): boolean {\n return marks.some((mark) => Boolean(mark.color));\n}\n\n/**\n * Marker `left` percent for range dots and labels; edge steps inset to stay on track.\n *\n * @param step - Track-percent step from a mark entry.\n * @returns CSS `left` percentage string.\n */\nexport function getDotLeftPercent(step: number): string {\n if (step === 0) {\n return DOT_EDGE_INSET_PERCENT;\n }\n if (step === 100) {\n return DOT_EDGE_MAX_PERCENT;\n }\n\n return `${step}%`;\n}\n\n// --- Accessibility (Slider.tsx) ---\n\n/**\n * Clamps and steps a domain value for increment/decrement actions.\n *\n * @param value - Domain value to clamp.\n * @param minimumValue - Lower bound of the domain range.\n * @param maximumValue - Upper bound of the domain range.\n * @param step - Step increment for rounding.\n * @returns Clamped and stepped domain value.\n */\nexport function clampValueToRange(\n value: number,\n minimumValue: number,\n maximumValue: number,\n step: number,\n): number {\n const range = maximumValue - minimumValue;\n if (range === 0) {\n return minimumValue;\n }\n\n const clamped = Math.max(minimumValue, Math.min(maximumValue, value));\n return Math.round(clamped / step) * step;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/design-system-react-native",
3
- "version": "0.51.0-preview.b15bc07",
3
+ "version": "0.52.0-preview.3026400c",
4
4
  "description": "Design System React Native",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -47,7 +47,7 @@
47
47
  "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
48
48
  },
49
49
  "dependencies": {
50
- "@metamask-previews/design-system-shared": "0.40.0-preview.b15bc07",
50
+ "@metamask-previews/design-system-shared": "0.41.0-preview.3026400c",
51
51
  "react-native-jazzicon": "^0.1.2"
52
52
  },
53
53
  "devDependencies": {
@@ -57,8 +57,8 @@
57
57
  "@babel/preset-typescript": "^7.23.3",
58
58
  "@figma/code-connect": "^1.4.9",
59
59
  "@gorhom/bottom-sheet": "^5.1.3",
60
- "@metamask-previews/design-system-twrnc-preset": "0.12.0-preview.b15bc07",
61
- "@metamask-previews/design-tokens": "11.1.0-preview.b15bc07",
60
+ "@metamask-previews/design-system-twrnc-preset": "0.13.0-preview.3026400c",
61
+ "@metamask-previews/design-tokens": "12.0.0-preview.3026400c",
62
62
  "@metamask/auto-changelog": "^6.2.1",
63
63
  "@metamask/utils": "^11.12.1",
64
64
  "@react-native/babel-preset": "0.86.3",
@@ -91,8 +91,8 @@
91
91
  "typescript": "~5.2.2"
92
92
  },
93
93
  "peerDependencies": {
94
- "@metamask/design-system-twrnc-preset": "^0.12.0",
95
- "@metamask/design-tokens": "^11.0.0",
94
+ "@metamask/design-system-twrnc-preset": "^0.13.0",
95
+ "@metamask/design-tokens": "^12.0.0",
96
96
  "@metamask/utils": "^11.12.1",
97
97
  "expo-image": ">=3.0.0",
98
98
  "lodash": "^4.17.21",