@metamask-previews/design-system-react-native 0.18.0-preview.ba86146 → 0.19.0-preview.1679aa9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -16
- package/dist/components/BottomSheetDialog/BottomSheetDialog.cjs +1 -1
- package/dist/components/BottomSheetDialog/BottomSheetDialog.cjs.map +1 -1
- package/dist/components/BottomSheetDialog/BottomSheetDialog.mjs +1 -1
- package/dist/components/BottomSheetDialog/BottomSheetDialog.mjs.map +1 -1
- package/dist/components/Icon/Icon.cjs +1 -2
- package/dist/components/Icon/Icon.cjs.map +1 -1
- package/dist/components/Icon/Icon.d.cts.map +1 -1
- package/dist/components/Icon/Icon.d.mts.map +1 -1
- package/dist/components/Icon/Icon.mjs +1 -2
- package/dist/components/Icon/Icon.mjs.map +1 -1
- package/dist/components/Tag/Tag.cjs +45 -0
- package/dist/components/Tag/Tag.cjs.map +1 -0
- package/dist/components/Tag/Tag.constants.cjs +27 -0
- package/dist/components/Tag/Tag.constants.cjs.map +1 -0
- package/dist/components/Tag/Tag.constants.d.cts +6 -0
- package/dist/components/Tag/Tag.constants.d.cts.map +1 -0
- package/dist/components/Tag/Tag.constants.d.mts +6 -0
- package/dist/components/Tag/Tag.constants.d.mts.map +1 -0
- package/dist/components/Tag/Tag.constants.mjs +24 -0
- package/dist/components/Tag/Tag.constants.mjs.map +1 -0
- package/dist/components/Tag/Tag.d.cts +4 -0
- package/dist/components/Tag/Tag.d.cts.map +1 -0
- package/dist/components/Tag/Tag.d.mts +4 -0
- package/dist/components/Tag/Tag.d.mts.map +1 -0
- package/dist/components/Tag/Tag.mjs +45 -0
- package/dist/components/Tag/Tag.mjs.map +1 -0
- package/dist/components/Tag/Tag.types.cjs +3 -0
- package/dist/components/Tag/Tag.types.cjs.map +1 -0
- package/dist/components/Tag/Tag.types.d.cts +38 -0
- package/dist/components/Tag/Tag.types.d.cts.map +1 -0
- package/dist/components/Tag/Tag.types.d.mts +38 -0
- package/dist/components/Tag/Tag.types.d.mts.map +1 -0
- package/dist/components/Tag/Tag.types.mjs +2 -0
- package/dist/components/Tag/Tag.types.mjs.map +1 -0
- package/dist/components/Tag/index.cjs +8 -0
- package/dist/components/Tag/index.cjs.map +1 -0
- package/dist/components/Tag/index.d.cts +4 -0
- package/dist/components/Tag/index.d.cts.map +1 -0
- package/dist/components/Tag/index.d.mts +4 -0
- package/dist/components/Tag/index.d.mts.map +1 -0
- package/dist/components/Tag/index.mjs +3 -0
- package/dist/components/Tag/index.mjs.map +1 -0
- package/dist/components/TitleHub/TitleHub.cjs +65 -0
- package/dist/components/TitleHub/TitleHub.cjs.map +1 -0
- package/dist/components/TitleHub/TitleHub.d.cts +26 -0
- package/dist/components/TitleHub/TitleHub.d.cts.map +1 -0
- package/dist/components/TitleHub/TitleHub.d.mts +26 -0
- package/dist/components/TitleHub/TitleHub.d.mts.map +1 -0
- package/dist/components/TitleHub/TitleHub.mjs +65 -0
- package/dist/components/TitleHub/TitleHub.mjs.map +1 -0
- package/dist/components/TitleHub/TitleHub.types.cjs +3 -0
- package/dist/components/TitleHub/TitleHub.types.cjs.map +1 -0
- package/dist/components/TitleHub/TitleHub.types.d.cts +39 -0
- package/dist/components/TitleHub/TitleHub.types.d.cts.map +1 -0
- package/dist/components/TitleHub/TitleHub.types.d.mts +39 -0
- package/dist/components/TitleHub/TitleHub.types.d.mts.map +1 -0
- package/dist/components/TitleHub/TitleHub.types.mjs +2 -0
- package/dist/components/TitleHub/TitleHub.types.mjs.map +1 -0
- package/dist/components/TitleHub/index.cjs +6 -0
- package/dist/components/TitleHub/index.cjs.map +1 -0
- package/dist/components/TitleHub/index.d.cts +4 -0
- package/dist/components/TitleHub/index.d.cts.map +1 -0
- package/dist/components/TitleHub/index.d.mts +4 -0
- package/dist/components/TitleHub/index.d.mts.map +1 -0
- package/dist/components/TitleHub/index.mjs +2 -0
- package/dist/components/TitleHub/index.mjs.map +1 -0
- package/dist/components/index.cjs +7 -2
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.d.cts +4 -0
- package/dist/components/index.d.cts.map +1 -1
- package/dist/components/index.d.mts +4 -0
- package/dist/components/index.d.mts.map +1 -1
- package/dist/components/index.mjs +2 -0
- package/dist/components/index.mjs.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.19.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Added `TitleHub` for stacked title, amount, and bottom-label layouts with optional accessory slots. ([#1052](https://github.com/MetaMask/metamask-design-system/pull/1052))
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- **BREAKING:** Raised the minimum supported peer dependency versions to React Native `>=0.76.0`, `react-native-gesture-handler >=2.25.0`, `react-native-reanimated >=3.17.0`, and `react-native-safe-area-context >=5.0.0` to align the package with the React Native 0.76 and Storybook 10 stack. ([#844](https://github.com/MetaMask/metamask-design-system/pull/844))
|
|
19
|
+
- **BREAKING:** `HeaderRoot` now renders `titleAccessory` only when `title` is present; use `children` for fully custom accessory-only title rows. See [Migration Guide](./MIGRATION.md#from-version-0180-to-0190). ([#1076](https://github.com/MetaMask/metamask-design-system/pull/1076))
|
|
20
|
+
- **BREAKING:** `IconProps` now align with the underlying SVG component props instead of `ViewProps`; move `View`-specific props to a wrapper view if TypeScript flags them after upgrading. See [Migration Guide](./MIGRATION.md#from-version-0180-to-0190). ([#1090](https://github.com/MetaMask/metamask-design-system/pull/1090))
|
|
21
|
+
|
|
10
22
|
## [0.18.0]
|
|
11
23
|
|
|
12
24
|
### Added
|
|
@@ -55,35 +67,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
55
67
|
|
|
56
68
|
### Added
|
|
57
69
|
|
|
58
|
-
- Added `HeaderRoot` as a new root primitive for React Native header composition ([#1029](https://github.com/MetaMask/metamask-design-system/pull/1029))
|
|
59
|
-
- Added `HeaderStandard` for standardized title + action header layouts in mobile screens ([#1028](https://github.com/MetaMask/metamask-design-system/pull/1028), [#1030](https://github.com/MetaMask/metamask-design-system/pull/1030))
|
|
60
|
-
- Added `TextFieldSearch` for search-style text input flows on mobile ([#1027](https://github.com/MetaMask/metamask-design-system/pull/1027))
|
|
61
|
-
- Added `BoxHorizontal` and `BoxVertical` utility components for common directional layout composition ([#1003](https://github.com/MetaMask/metamask-design-system/pull/1003))
|
|
70
|
+
- Added `HeaderRoot` as a new root primitive for React Native header composition ([#1029](https://github.com/MetaMask/metamask-design-system/pull/1029))
|
|
71
|
+
- Added `HeaderStandard` for standardized title + action header layouts in mobile screens ([#1028](https://github.com/MetaMask/metamask-design-system/pull/1028), [#1030](https://github.com/MetaMask/metamask-design-system/pull/1030))
|
|
72
|
+
- Added `TextFieldSearch` for search-style text input flows on mobile ([#1027](https://github.com/MetaMask/metamask-design-system/pull/1027))
|
|
73
|
+
- Added `BoxHorizontal` and `BoxVertical` utility components for common directional layout composition ([#1003](https://github.com/MetaMask/metamask-design-system/pull/1003))
|
|
62
74
|
|
|
63
75
|
### Changed
|
|
64
76
|
|
|
65
|
-
- **BREAKING:** Replaced BottomSheet `shouldNavigateBack` with an optional `goBack` callback for explicit navigation handling in host apps ([#1024](https://github.com/MetaMask/metamask-design-system/pull/1024))
|
|
77
|
+
- **BREAKING:** Replaced BottomSheet `shouldNavigateBack` with an optional `goBack` callback for explicit navigation handling in host apps ([#1024](https://github.com/MetaMask/metamask-design-system/pull/1024))
|
|
66
78
|
- Remove `shouldNavigateBack` usage and pass `goBack` when you want the sheet close action to navigate back.
|
|
67
79
|
- See [Migration Guide](./MIGRATION.md#from-version-0130-to-0140).
|
|
68
|
-
- Added `panGestureHandlerProps` support to `BottomSheet` so integrators can customize gesture-handler behavior ([#1016](https://github.com/MetaMask/metamask-design-system/pull/1016))
|
|
69
|
-
- Migrated React Native package exports from default exports to named exports for more consistent import ergonomics across the library ([#1032](https://github.com/MetaMask/metamask-design-system/pull/1032))
|
|
70
|
-
- **BREAKING:** Updated `AvatarBase` exports to use shared const-object + string-union types instead of local enums ([#1005](https://github.com/MetaMask/metamask-design-system/pull/1005))
|
|
80
|
+
- Added `panGestureHandlerProps` support to `BottomSheet` so integrators can customize gesture-handler behavior ([#1016](https://github.com/MetaMask/metamask-design-system/pull/1016))
|
|
81
|
+
- Migrated React Native package exports from default exports to named exports for more consistent import ergonomics across the library ([#1032](https://github.com/MetaMask/metamask-design-system/pull/1032))
|
|
82
|
+
- **BREAKING:** Updated `AvatarBase` exports to use shared const-object + string-union types instead of local enums ([#1005](https://github.com/MetaMask/metamask-design-system/pull/1005))
|
|
71
83
|
- No migration required for typical usage; continue importing from `@metamask/design-system-react-native` as before.
|
|
72
84
|
- Runtime values remain stable while type definitions follow ADR-0003/ADR-0004.
|
|
73
|
-
- Updated `@metamask/utils` peer dependency to `^11.11.0` ([#1033](https://github.com/MetaMask/metamask-design-system/pull/1033))
|
|
74
|
-
- Expanded `BannerBase` migration documentation to improve upgrade guidance for consumers ([#1011](https://github.com/MetaMask/metamask-design-system/pull/1011))
|
|
85
|
+
- Updated `@metamask/utils` peer dependency to `^11.11.0` ([#1033](https://github.com/MetaMask/metamask-design-system/pull/1033))
|
|
86
|
+
- Expanded `BannerBase` migration documentation to improve upgrade guidance for consumers ([#1011](https://github.com/MetaMask/metamask-design-system/pull/1011))
|
|
75
87
|
|
|
76
88
|
### Fixed
|
|
77
89
|
|
|
78
|
-
- Updated `BottomSheetHeader` action button size to `md` for consistent sizing and visual alignment ([#1012](https://github.com/MetaMask/metamask-design-system/pull/1012))
|
|
90
|
+
- Updated `BottomSheetHeader` action button size to `md` for consistent sizing and visual alignment ([#1012](https://github.com/MetaMask/metamask-design-system/pull/1012))
|
|
79
91
|
|
|
80
92
|
## [0.13.0]
|
|
81
93
|
|
|
82
94
|
### Changed
|
|
83
95
|
|
|
84
|
-
- `FontWeight.Bold` and the React Native `Text` component now describe bold as weight 600; the Storybook mobile `FontLoader` and `@metamask/design-system-twrnc-preset` now reference the `Geist-SemiBold`/`Geist-SemiBoldItalic` assets, so update any custom font registrations that previously assumed weight 700 as explained in the [migration guide](./MIGRATION.md#from-version-0120-to-0130) ([#1017](https://github.com/MetaMask/metamask-design-system/pull/1017))
|
|
96
|
+
- `FontWeight.Bold` and the React Native `Text` component now describe bold as weight 600; the Storybook mobile `FontLoader` and `@metamask/design-system-twrnc-preset` now reference the `Geist-SemiBold`/`Geist-SemiBoldItalic` assets, so update any custom font registrations that previously assumed weight 700 as explained in the [migration guide](./MIGRATION.md#from-version-0120-to-0130) ([#1017](https://github.com/MetaMask/metamask-design-system/pull/1017))
|
|
85
97
|
- `BadgeWrapperPosition`, `BadgeWrapperPositionAnchorShape`, `BadgeWrapperCustomPosition`, and `BadgeWrapperPropsShared` now derive from const objects annotated `as const`, producing string-union typings per ADR-0003/ADR-0004; the React Native entry point still exports the same names, so your imports stay on `@metamask/design-system-react-native` while the shared package hosts the canonical definitions ([#1014](https://github.com/MetaMask/metamask-design-system/pull/1014); see https://github.com/MetaMask/decisions/blob/main/decisions/design-system/0003-enum-to-string-union-migration.md and https://github.com/MetaMask/decisions/blob/main/decisions/design-system/0004-centralized-types-architecture.md).
|
|
86
|
-
- Documented the Button migration instructions (prop, variant, and size mappings) in [MIGRATION.md#button-component](./MIGRATION.md#button-component) so both web and native developers follow the same before/after story ([#999](https://github.com/MetaMask/metamask-design-system/pull/999))
|
|
98
|
+
- Documented the Button migration instructions (prop, variant, and size mappings) in [MIGRATION.md#button-component](./MIGRATION.md#button-component) so both web and native developers follow the same before/after story ([#999](https://github.com/MetaMask/metamask-design-system/pull/999))
|
|
87
99
|
|
|
88
100
|
## [0.12.0]
|
|
89
101
|
|
|
@@ -285,8 +297,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
285
297
|
### Added
|
|
286
298
|
|
|
287
299
|
- New icons (AppleLogo, Backspace, Candlestick, Clear, MetamaskFoxOutline) ([#798](https://github.com/MetaMask/metamask-design-system/pull/798))
|
|
288
|
-
|
|
289
|
-
- Figma code connect files for all components ([#766](https://github.com/MetaMask/metamask-design-system/pull/766)), ([#791](https://github.com/MetaMask/metamask-design-system/pull/791)), ([#795](https://github.com/MetaMask/metamask-design-system/pull/795)), ([#796](https://github.com/MetaMask/metamask-design-system/pull/796)), ([#794](https://github.com/MetaMask/metamask-design-system/pull/794)), ([#792](https://github.com/MetaMask/metamask-design-system/pull/792))
|
|
300
|
+
- Figma code connect files for all components ([#766](https://github.com/MetaMask/metamask-design-system/pull/766), [#791](https://github.com/MetaMask/metamask-design-system/pull/791), [#795](https://github.com/MetaMask/metamask-design-system/pull/795), [#796](https://github.com/MetaMask/metamask-design-system/pull/796), [#794](https://github.com/MetaMask/metamask-design-system/pull/794), [#792](https://github.com/MetaMask/metamask-design-system/pull/792))
|
|
290
301
|
|
|
291
302
|
### Changed
|
|
292
303
|
|
|
@@ -332,7 +343,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
332
343
|
- Full TypeScript support with type definitions and enums
|
|
333
344
|
- React Native integration with TWRNC preset support
|
|
334
345
|
|
|
335
|
-
[Unreleased]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/design-system-react-native@0.
|
|
346
|
+
[Unreleased]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/design-system-react-native@0.19.0...HEAD
|
|
347
|
+
[0.19.0]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/design-system-react-native@0.18.0...@metamask/design-system-react-native@0.19.0
|
|
336
348
|
[0.18.0]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/design-system-react-native@0.17.0...@metamask/design-system-react-native@0.18.0
|
|
337
349
|
[0.17.0]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/design-system-react-native@0.16.0...@metamask/design-system-react-native@0.17.0
|
|
338
350
|
[0.16.0]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/design-system-react-native@0.15.0...@metamask/design-system-react-native@0.16.0
|
|
@@ -166,7 +166,7 @@ exports.BottomSheetDialog = (0, react_1.forwardRef)(({ children, isFullscreen =
|
|
|
166
166
|
],
|
|
167
167
|
}));
|
|
168
168
|
const sheetStyle = (0, react_1.useMemo)(() => [
|
|
169
|
-
tw.style('bg-
|
|
169
|
+
tw.style('bg-section rounded-t-3xl overflow-hidden border border-muted', twClassName),
|
|
170
170
|
{
|
|
171
171
|
maxHeight: maxSheetHeight,
|
|
172
172
|
paddingBottom: react_native_1.Platform.select({
|
|
@@ -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,wDAKsB;AACtB,+EAGsC;AACtC,mFAMiC;AACjC,mFAGwC;AAExC,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,sBAAsB,EACtB,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;QAC5B,CAAC,CAAC,yBAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;IA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useTailwind,\n useTheme,\n} from '@metamask-previews/design-system-twrnc-preset';\nimport { lightTheme, darkTheme } 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 {\n PanGestureHandler,\n PanGestureHandlerGestureEvent,\n} from 'react-native-gesture-handler';\nimport Animated, {\n runOnJS,\n useAnimatedGestureHandler,\n useAnimatedStyle,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated';\nimport {\n useSafeAreaFrame,\n useSafeAreaInsets,\n} from 'react-native-safe-area-context';\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 panGestureHandlerProps,\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 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 runOnJS(onCloseCB)();\n if (callback) {\n runOnJS(callback)();\n }\n },\n );\n // Ref values do not affect deps.\n },\n [onCloseCB],\n );\n\n const gestureHandler = useAnimatedGestureHandler<\n PanGestureHandlerGestureEvent,\n { startY: number }\n >({\n onStart: (_, ctx) => {\n // Starts tracking vertical position of gesture\n ctx.startY = currentYOffset.value;\n },\n onActive: (event, ctx) => {\n const { translationY } = event;\n currentYOffset.value = ctx.startY + 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, ctx) => {\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 = ctx.startY + 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 runOnJS(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\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 runOnJS(onOpenCB)();\n if (callback) {\n runOnJS(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 transform: [\n {\n translateY: currentYOffset.value,\n },\n ],\n }));\n\n const sheetStyle = useMemo(\n () => [\n tw.style(\n 'bg-default rounded-t-3xl overflow-hidden border border-muted',\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 <PanGestureHandler\n {...panGestureHandlerProps}\n enabled={isInteractable}\n onGestureEvent={gestureHandler}\n >\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 </PanGestureHandler>\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,wDAKsB;AACtB,+EAGsC;AACtC,mFAMiC;AACjC,mFAGwC;AAExC,yBAAyB;AACzB,mFAIuC;AAM1B,QAAA,iBAAiB,GAAG,IAAA,kBAAU,EA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AC,iBAAiB,CAAC,CAC5B,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,gDAAiB,CACrB;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 { lightTheme, darkTheme } 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 {\n PanGestureHandler,\n PanGestureHandlerGestureEvent,\n} from 'react-native-gesture-handler';\nimport Animated, {\n runOnJS,\n useAnimatedGestureHandler,\n useAnimatedStyle,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated';\nimport {\n useSafeAreaFrame,\n useSafeAreaInsets,\n} from 'react-native-safe-area-context';\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 panGestureHandlerProps,\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 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 runOnJS(onCloseCB)();\n if (callback) {\n runOnJS(callback)();\n }\n },\n );\n // Ref values do not affect deps.\n },\n [onCloseCB],\n );\n\n const gestureHandler = useAnimatedGestureHandler<\n PanGestureHandlerGestureEvent,\n { startY: number }\n >({\n onStart: (_, ctx) => {\n // Starts tracking vertical position of gesture\n ctx.startY = currentYOffset.value;\n },\n onActive: (event, ctx) => {\n const { translationY } = event;\n currentYOffset.value = ctx.startY + 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, ctx) => {\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 = ctx.startY + 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 runOnJS(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\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 runOnJS(onOpenCB)();\n if (callback) {\n runOnJS(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 transform: [\n {\n translateY: currentYOffset.value,\n },\n ],\n }));\n\n const sheetStyle = useMemo(\n () => [\n tw.style(\n 'bg-section rounded-t-3xl overflow-hidden border border-muted',\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 <PanGestureHandler\n {...panGestureHandlerProps}\n enabled={isInteractable}\n onGestureEvent={gestureHandler}\n >\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 </PanGestureHandler>\n </KeyboardAvoidingView>\n );\n },\n);\n"]}
|
|
@@ -148,7 +148,7 @@ export const BottomSheetDialog = forwardRef(({ children, isFullscreen = false, i
|
|
|
148
148
|
],
|
|
149
149
|
}));
|
|
150
150
|
const sheetStyle = useMemo(() => [
|
|
151
|
-
tw.style('bg-
|
|
151
|
+
tw.style('bg-section rounded-t-3xl overflow-hidden border border-muted', twClassName),
|
|
152
152
|
{
|
|
153
153
|
maxHeight: maxSheetHeight,
|
|
154
154
|
paddingBottom: Platform.select({
|
|
@@ -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,UAAU,EAAE,SAAS,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,8BAAqB;AACtB,OAAO,EACL,iBAAiB,EAElB,qCAAqC;AACtC,OAAO,QAAQ,EAAE,EACf,OAAO,EACP,yBAAyB,EACzB,gBAAgB,EAChB,cAAc,EACd,UAAU,EACX,gCAAgC;AACjC,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EAClB,uCAAuC;AAExC,yBAAyB;AACzB,OAAO,EACL,0CAA0C,EAC1C,0CAA0C,EAC1C,iDAAiD,EAClD,0CAAsC;AAMvC,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAIzC,CACE,EACE,QAAQ,EACR,YAAY,GAAG,KAAK,EAC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AK,CAAC,qCAAqC,CAAC,CAAC,EAC/D;cAAA,EAAE,IAAI,CAAC,CACR,CACD;YAAA,CAAC,QAAQ,CACX;UAAA,EAAE,QAAQ,CAAC,IAAI,CACjB;QAAA,EAAE,iBAAiB,CACrB;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 { lightTheme, darkTheme } 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 {\n PanGestureHandler,\n PanGestureHandlerGestureEvent,\n} from 'react-native-gesture-handler';\nimport Animated, {\n runOnJS,\n useAnimatedGestureHandler,\n useAnimatedStyle,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated';\nimport {\n useSafeAreaFrame,\n useSafeAreaInsets,\n} from 'react-native-safe-area-context';\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 panGestureHandlerProps,\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 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 runOnJS(onCloseCB)();\n if (callback) {\n runOnJS(callback)();\n }\n },\n );\n // Ref values do not affect deps.\n },\n [onCloseCB],\n );\n\n const gestureHandler = useAnimatedGestureHandler<\n PanGestureHandlerGestureEvent,\n { startY: number }\n >({\n onStart: (_, ctx) => {\n // Starts tracking vertical position of gesture\n ctx.startY = currentYOffset.value;\n },\n onActive: (event, ctx) => {\n const { translationY } = event;\n currentYOffset.value = ctx.startY + 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, ctx) => {\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 = ctx.startY + 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 runOnJS(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\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 runOnJS(onOpenCB)();\n if (callback) {\n runOnJS(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 transform: [\n {\n translateY: currentYOffset.value,\n },\n ],\n }));\n\n const sheetStyle = useMemo(\n () => [\n tw.style(\n 'bg-default rounded-t-3xl overflow-hidden border border-muted',\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 <PanGestureHandler\n {...panGestureHandlerProps}\n enabled={isInteractable}\n onGestureEvent={gestureHandler}\n >\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 </PanGestureHandler>\n </KeyboardAvoidingView>\n );\n },\n);\n"]}
|
|
1
|
+
{"version":3,"file":"BottomSheetDialog.mjs","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomS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AC,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,iBAAiB,CAChB,IAAI,sBAAsB,CAAC,CAC3B,OAAO,CAAC,CAAC,cAAc,CAAC,CACxB,cAAc,CAAC,CAAC,cAAc,CAAC,CAE/B;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,iBAAiB,CACrB;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 { lightTheme, darkTheme } 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 {\n PanGestureHandler,\n PanGestureHandlerGestureEvent,\n} from 'react-native-gesture-handler';\nimport Animated, {\n runOnJS,\n useAnimatedGestureHandler,\n useAnimatedStyle,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated';\nimport {\n useSafeAreaFrame,\n useSafeAreaInsets,\n} from 'react-native-safe-area-context';\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 panGestureHandlerProps,\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 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 runOnJS(onCloseCB)();\n if (callback) {\n runOnJS(callback)();\n }\n },\n );\n // Ref values do not affect deps.\n },\n [onCloseCB],\n );\n\n const gestureHandler = useAnimatedGestureHandler<\n PanGestureHandlerGestureEvent,\n { startY: number }\n >({\n onStart: (_, ctx) => {\n // Starts tracking vertical position of gesture\n ctx.startY = currentYOffset.value;\n },\n onActive: (event, ctx) => {\n const { translationY } = event;\n currentYOffset.value = ctx.startY + 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, ctx) => {\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 = ctx.startY + 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 runOnJS(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\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 runOnJS(onOpenCB)();\n if (callback) {\n runOnJS(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 transform: [\n {\n translateY: currentYOffset.value,\n },\n ],\n }));\n\n const sheetStyle = useMemo(\n () => [\n tw.style(\n 'bg-section rounded-t-3xl overflow-hidden border border-muted',\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 <PanGestureHandler\n {...panGestureHandlerProps}\n enabled={isInteractable}\n onGestureEvent={gestureHandler}\n >\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 </PanGestureHandler>\n </KeyboardAvoidingView>\n );\n },\n);\n"]}
|
|
@@ -12,9 +12,8 @@ const Icon_constants_1 = require("./Icon.constants.cjs");
|
|
|
12
12
|
const Icon = ({ size = types_1.IconSize.Md, name, color = types_1.IconColor.IconDefault, twClassName, style, ...props }) => {
|
|
13
13
|
const tw = (0, design_system_twrnc_preset_1.useTailwind)();
|
|
14
14
|
const SVG = Icon_assets_1.assetByIconName[name];
|
|
15
|
-
const { hitSlop, ...svgProps } = props;
|
|
16
15
|
const twStyle = tw.style(color, Icon_constants_1.TWCLASSMAP_ICON_SIZE_DIMENSION[size], twClassName);
|
|
17
|
-
return (<SVG name={name} fill="currentColor" style={[twStyle, style]}
|
|
16
|
+
return (<SVG name={name} fill="currentColor" style={[twStyle, style]} {...props}/>);
|
|
18
17
|
};
|
|
19
18
|
exports.Icon = Icon;
|
|
20
19
|
//# sourceMappingURL=Icon.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Icon.cjs","sourceRoot":"","sources":["../../../src/components/Icon/Icon.tsx"],"names":[],"mappings":";;;;;;AAAA,8FAA4E;AAC5E,kDAA0B;AAE1B,iDAAkD;AAElD,mDAAgD;AAChD,yDAAkE;AAG3D,MAAM,IAAI,GAAG,CAAC,EACnB,IAAI,GAAG,gBAAQ,CAAC,EAAE,EAClB,IAAI,EACJ,KAAK,GAAG,iBAAS,CAAC,WAAW,EAC7B,WAAW,EACX,KAAK,EACL,GAAG,KAAK,EACE,EAAE,EAAE;IACd,MAAM,EAAE,GAAG,IAAA,wCAAW,GAAE,CAAC;IACzB,MAAM,GAAG,GAAG,6BAAe,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,
|
|
1
|
+
{"version":3,"file":"Icon.cjs","sourceRoot":"","sources":["../../../src/components/Icon/Icon.tsx"],"names":[],"mappings":";;;;;;AAAA,8FAA4E;AAC5E,kDAA0B;AAE1B,iDAAkD;AAElD,mDAAgD;AAChD,yDAAkE;AAG3D,MAAM,IAAI,GAAG,CAAC,EACnB,IAAI,GAAG,gBAAQ,CAAC,EAAE,EAClB,IAAI,EACJ,KAAK,GAAG,iBAAS,CAAC,WAAW,EAC7B,WAAW,EACX,KAAK,EACL,GAAG,KAAK,EACE,EAAE,EAAE;IACd,MAAM,EAAE,GAAG,IAAA,wCAAW,GAAE,CAAC;IACzB,MAAM,GAAG,GAAG,6BAAe,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,OAAO,GAAG,EAAE,CAAC,KAAK,CACtB,KAAK,EACL,+CAA8B,CAAC,IAAI,CAAC,EACpC,WAAW,CACZ,CAAC;IAEF,OAAO,CACL,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,EAAG,CAC5E,CAAC;AACJ,CAAC,CAAC;AAnBW,QAAA,IAAI,QAmBf","sourcesContent":["import { useTailwind } from '@metamask-previews/design-system-twrnc-preset';\nimport React from 'react';\n\nimport { IconColor, IconSize } from '../../types';\n\nimport { assetByIconName } from './Icon.assets';\nimport { TWCLASSMAP_ICON_SIZE_DIMENSION } from './Icon.constants';\nimport type { IconProps } from './Icon.types';\n\nexport const Icon = ({\n size = IconSize.Md,\n name,\n color = IconColor.IconDefault,\n twClassName,\n style,\n ...props\n}: IconProps) => {\n const tw = useTailwind();\n const SVG = assetByIconName[name];\n const twStyle = tw.style(\n color,\n TWCLASSMAP_ICON_SIZE_DIMENSION[size],\n twClassName,\n );\n\n return (\n <SVG name={name} fill=\"currentColor\" style={[twStyle, style]} {...props} />\n );\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Icon.d.cts","sourceRoot":"","sources":["../../../src/components/Icon/Icon.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,cAAc;AAM1B,OAAO,KAAK,EAAE,SAAS,EAAE,yBAAqB;AAE9C,eAAO,MAAM,IAAI,wDAOd,SAAS,
|
|
1
|
+
{"version":3,"file":"Icon.d.cts","sourceRoot":"","sources":["../../../src/components/Icon/Icon.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,cAAc;AAM1B,OAAO,KAAK,EAAE,SAAS,EAAE,yBAAqB;AAE9C,eAAO,MAAM,IAAI,wDAOd,SAAS,sBAYX,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Icon.d.mts","sourceRoot":"","sources":["../../../src/components/Icon/Icon.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,cAAc;AAM1B,OAAO,KAAK,EAAE,SAAS,EAAE,yBAAqB;AAE9C,eAAO,MAAM,IAAI,wDAOd,SAAS,
|
|
1
|
+
{"version":3,"file":"Icon.d.mts","sourceRoot":"","sources":["../../../src/components/Icon/Icon.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,cAAc;AAM1B,OAAO,KAAK,EAAE,SAAS,EAAE,yBAAqB;AAE9C,eAAO,MAAM,IAAI,wDAOd,SAAS,sBAYX,CAAC"}
|
|
@@ -13,8 +13,7 @@ import { TWCLASSMAP_ICON_SIZE_DIMENSION } from "./Icon.constants.mjs";
|
|
|
13
13
|
export const Icon = ({ size = IconSize.Md, name, color = IconColor.IconDefault, twClassName, style, ...props }) => {
|
|
14
14
|
const tw = useTailwind();
|
|
15
15
|
const SVG = assetByIconName[name];
|
|
16
|
-
const { hitSlop, ...svgProps } = props;
|
|
17
16
|
const twStyle = tw.style(color, TWCLASSMAP_ICON_SIZE_DIMENSION[size], twClassName);
|
|
18
|
-
return (<SVG name={name} fill="currentColor" style={[twStyle, style]}
|
|
17
|
+
return (<SVG name={name} fill="currentColor" style={[twStyle, style]} {...props}/>);
|
|
19
18
|
};
|
|
20
19
|
//# sourceMappingURL=Icon.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Icon.mjs","sourceRoot":"","sources":["../../../src/components/Icon/Icon.tsx"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,sDAAsD;AAC5E,OAAO,MAAK,cAAc;;AAE1B,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,8BAAoB;AAElD,OAAO,EAAE,eAAe,EAAE,0BAAsB;AAChD,OAAO,EAAE,8BAA8B,EAAE,6BAAyB;AAGlE,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,EACnB,IAAI,GAAG,QAAQ,CAAC,EAAE,EAClB,IAAI,EACJ,KAAK,GAAG,SAAS,CAAC,WAAW,EAC7B,WAAW,EACX,KAAK,EACL,GAAG,KAAK,EACE,EAAE,EAAE;IACd,MAAM,EAAE,GAAG,WAAW,EAAE,CAAC;IACzB,MAAM,GAAG,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,
|
|
1
|
+
{"version":3,"file":"Icon.mjs","sourceRoot":"","sources":["../../../src/components/Icon/Icon.tsx"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,sDAAsD;AAC5E,OAAO,MAAK,cAAc;;AAE1B,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,8BAAoB;AAElD,OAAO,EAAE,eAAe,EAAE,0BAAsB;AAChD,OAAO,EAAE,8BAA8B,EAAE,6BAAyB;AAGlE,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,EACnB,IAAI,GAAG,QAAQ,CAAC,EAAE,EAClB,IAAI,EACJ,KAAK,GAAG,SAAS,CAAC,WAAW,EAC7B,WAAW,EACX,KAAK,EACL,GAAG,KAAK,EACE,EAAE,EAAE;IACd,MAAM,EAAE,GAAG,WAAW,EAAE,CAAC;IACzB,MAAM,GAAG,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,OAAO,GAAG,EAAE,CAAC,KAAK,CACtB,KAAK,EACL,8BAA8B,CAAC,IAAI,CAAC,EACpC,WAAW,CACZ,CAAC;IAEF,OAAO,CACL,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,EAAG,CAC5E,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { useTailwind } from '@metamask-previews/design-system-twrnc-preset';\nimport React from 'react';\n\nimport { IconColor, IconSize } from '../../types';\n\nimport { assetByIconName } from './Icon.assets';\nimport { TWCLASSMAP_ICON_SIZE_DIMENSION } from './Icon.constants';\nimport type { IconProps } from './Icon.types';\n\nexport const Icon = ({\n size = IconSize.Md,\n name,\n color = IconColor.IconDefault,\n twClassName,\n style,\n ...props\n}: IconProps) => {\n const tw = useTailwind();\n const SVG = assetByIconName[name];\n const twStyle = tw.style(\n color,\n TWCLASSMAP_ICON_SIZE_DIMENSION[size],\n twClassName,\n );\n\n return (\n <SVG name={name} fill=\"currentColor\" style={[twStyle, style]} {...props} />\n );\n};\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Tag = void 0;
|
|
7
|
+
const design_system_shared_1 = require("@metamask-previews/design-system-shared");
|
|
8
|
+
const design_system_twrnc_preset_1 = require("@metamask-previews/design-system-twrnc-preset");
|
|
9
|
+
const react_1 = __importDefault(require("react"));
|
|
10
|
+
const Box_1 = require("../Box/index.cjs");
|
|
11
|
+
const BoxRow_1 = require("../BoxRow/index.cjs");
|
|
12
|
+
const Icon_1 = require("../Icon/index.cjs");
|
|
13
|
+
const Tag_constants_1 = require("./Tag.constants.cjs");
|
|
14
|
+
const Tag = ({ children, severity = design_system_shared_1.TagSeverity.Neutral, startIconName, startIconProps, startAccessory, endIconName, endIconProps, endAccessory, twClassName, style, ...props }) => {
|
|
15
|
+
const tw = (0, design_system_twrnc_preset_1.useTailwind)();
|
|
16
|
+
const backgroundColor = Tag_constants_1.MAP_TAG_SEVERITY_BACKGROUND[severity];
|
|
17
|
+
const textColor = Tag_constants_1.MAP_TAG_SEVERITY_TEXT_COLOR[severity];
|
|
18
|
+
const iconColor = Tag_constants_1.MAP_TAG_SEVERITY_ICON_COLOR[severity];
|
|
19
|
+
return (<Box_1.Box {...props} backgroundColor={backgroundColor} style={[
|
|
20
|
+
tw.style('rounded-md self-start', (startIconName ?? startIconProps?.name) ? 'pl-1' : 'pl-1.5', (endIconName ?? endIconProps?.name) ? 'pr-1' : 'pr-1.5', twClassName),
|
|
21
|
+
style,
|
|
22
|
+
]}>
|
|
23
|
+
<BoxRow_1.BoxRow textProps={{
|
|
24
|
+
color: textColor,
|
|
25
|
+
variant: design_system_shared_1.TextVariant.BodyXs,
|
|
26
|
+
fontWeight: design_system_shared_1.FontWeight.Medium,
|
|
27
|
+
}} startAccessory={(() => {
|
|
28
|
+
const name = startIconName ?? startIconProps?.name;
|
|
29
|
+
if (!name) {
|
|
30
|
+
return startAccessory ?? null;
|
|
31
|
+
}
|
|
32
|
+
return (<Icon_1.Icon name={name} color={iconColor} size={Icon_1.IconSize.Xs} twClassName="shrink-0" {...startIconProps}/>);
|
|
33
|
+
})()} endAccessory={(() => {
|
|
34
|
+
const name = endIconName ?? endIconProps?.name;
|
|
35
|
+
if (!name) {
|
|
36
|
+
return endAccessory ?? null;
|
|
37
|
+
}
|
|
38
|
+
return (<Icon_1.Icon name={name} color={iconColor} size={Icon_1.IconSize.Xs} twClassName="shrink-0" {...endIconProps}/>);
|
|
39
|
+
})()}>
|
|
40
|
+
{children}
|
|
41
|
+
</BoxRow_1.BoxRow>
|
|
42
|
+
</Box_1.Box>);
|
|
43
|
+
};
|
|
44
|
+
exports.Tag = Tag;
|
|
45
|
+
//# sourceMappingURL=Tag.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tag.cjs","sourceRoot":"","sources":["../../../src/components/Tag/Tag.tsx"],"names":[],"mappings":";;;;;;AAAA,kFAIiD;AACjD,8FAA4E;AAC5E,kDAA0B;AAE1B,0CAA6B;AAC7B,gDAAmC;AACnC,4CAAyC;AAEzC,uDAIyB;AAGlB,MAAM,GAAG,GAAuB,CAAC,EACtC,QAAQ,EACR,QAAQ,GAAG,kCAAW,CAAC,OAAO,EAC9B,aAAa,EACb,cAAc,EACd,cAAc,EACd,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,KAAK,EACL,GAAG,KAAK,EACT,EAAE,EAAE;IACH,MAAM,EAAE,GAAG,IAAA,wCAAW,GAAE,CAAC;IACzB,MAAM,eAAe,GAAG,2CAA2B,CAAC,QAAQ,CAAC,CAAC;IAC9D,MAAM,SAAS,GAAG,2CAA2B,CAAC,QAAQ,CAAC,CAAC;IACxD,MAAM,SAAS,GAAG,2CAA2B,CAAC,QAAQ,CAAC,CAAC;IAExD,OAAO,CACL,CAAC,SAAG,CACF,IAAI,KAAK,CAAC,CACV,eAAe,CA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,UAAU,CACtB,IAAI,YAAY,CAAC,EACjB,CACH,CAAC;QACJ,CAAC,CAAC,EAAE,CAAC,CAEL;QAAA,CAAC,QAAQ,CACX;MAAA,EAAE,eAAM,CACV;IAAA,EAAE,SAAG,CAAC,CACP,CAAC;AACJ,CAAC,CAAC;AAzEW,QAAA,GAAG,OAyEd","sourcesContent":["import {\n FontWeight,\n TagSeverity,\n TextVariant,\n} from '@metamask-previews/design-system-shared';\nimport { useTailwind } from '@metamask-previews/design-system-twrnc-preset';\nimport React from 'react';\n\nimport { Box } from '../Box';\nimport { BoxRow } from '../BoxRow';\nimport { Icon, IconSize } from '../Icon';\n\nimport {\n MAP_TAG_SEVERITY_BACKGROUND,\n MAP_TAG_SEVERITY_ICON_COLOR,\n MAP_TAG_SEVERITY_TEXT_COLOR,\n} from './Tag.constants';\nimport type { TagProps } from './Tag.types';\n\nexport const Tag: React.FC<TagProps> = ({\n children,\n severity = TagSeverity.Neutral,\n startIconName,\n startIconProps,\n startAccessory,\n endIconName,\n endIconProps,\n endAccessory,\n twClassName,\n style,\n ...props\n}) => {\n const tw = useTailwind();\n const backgroundColor = MAP_TAG_SEVERITY_BACKGROUND[severity];\n const textColor = MAP_TAG_SEVERITY_TEXT_COLOR[severity];\n const iconColor = MAP_TAG_SEVERITY_ICON_COLOR[severity];\n\n return (\n <Box\n {...props}\n backgroundColor={backgroundColor}\n style={[\n tw.style(\n 'rounded-md self-start',\n (startIconName ?? startIconProps?.name) ? 'pl-1' : 'pl-1.5',\n (endIconName ?? endIconProps?.name) ? 'pr-1' : 'pr-1.5',\n twClassName,\n ),\n style,\n ]}\n >\n <BoxRow\n textProps={{\n color: textColor,\n variant: TextVariant.BodyXs,\n fontWeight: FontWeight.Medium,\n }}\n startAccessory={(() => {\n const name = startIconName ?? startIconProps?.name;\n if (!name) {\n return startAccessory ?? null;\n }\n return (\n <Icon\n name={name}\n color={iconColor}\n size={IconSize.Xs}\n twClassName=\"shrink-0\"\n {...startIconProps}\n />\n );\n })()}\n endAccessory={(() => {\n const name = endIconName ?? endIconProps?.name;\n if (!name) {\n return endAccessory ?? null;\n }\n return (\n <Icon\n name={name}\n color={iconColor}\n size={IconSize.Xs}\n twClassName=\"shrink-0\"\n {...endIconProps}\n />\n );\n })()}\n >\n {children}\n </BoxRow>\n </Box>\n );\n};\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAP_TAG_SEVERITY_ICON_COLOR = exports.MAP_TAG_SEVERITY_TEXT_COLOR = exports.MAP_TAG_SEVERITY_BACKGROUND = void 0;
|
|
4
|
+
const design_system_shared_1 = require("@metamask-previews/design-system-shared");
|
|
5
|
+
const types_1 = require("../../types/index.cjs");
|
|
6
|
+
exports.MAP_TAG_SEVERITY_BACKGROUND = {
|
|
7
|
+
[design_system_shared_1.TagSeverity.Neutral]: types_1.BoxBackgroundColor.BackgroundMuted,
|
|
8
|
+
[design_system_shared_1.TagSeverity.Success]: types_1.BoxBackgroundColor.SuccessMuted,
|
|
9
|
+
[design_system_shared_1.TagSeverity.Error]: types_1.BoxBackgroundColor.ErrorMuted,
|
|
10
|
+
[design_system_shared_1.TagSeverity.Warning]: types_1.BoxBackgroundColor.WarningMuted,
|
|
11
|
+
[design_system_shared_1.TagSeverity.Info]: types_1.BoxBackgroundColor.InfoMuted,
|
|
12
|
+
};
|
|
13
|
+
exports.MAP_TAG_SEVERITY_TEXT_COLOR = {
|
|
14
|
+
[design_system_shared_1.TagSeverity.Neutral]: design_system_shared_1.TextColor.TextDefault,
|
|
15
|
+
[design_system_shared_1.TagSeverity.Success]: design_system_shared_1.TextColor.SuccessDefault,
|
|
16
|
+
[design_system_shared_1.TagSeverity.Error]: design_system_shared_1.TextColor.ErrorDefault,
|
|
17
|
+
[design_system_shared_1.TagSeverity.Warning]: design_system_shared_1.TextColor.WarningDefault,
|
|
18
|
+
[design_system_shared_1.TagSeverity.Info]: design_system_shared_1.TextColor.InfoDefault,
|
|
19
|
+
};
|
|
20
|
+
exports.MAP_TAG_SEVERITY_ICON_COLOR = {
|
|
21
|
+
[design_system_shared_1.TagSeverity.Neutral]: types_1.IconColor.IconDefault,
|
|
22
|
+
[design_system_shared_1.TagSeverity.Success]: types_1.IconColor.SuccessDefault,
|
|
23
|
+
[design_system_shared_1.TagSeverity.Error]: types_1.IconColor.ErrorDefault,
|
|
24
|
+
[design_system_shared_1.TagSeverity.Warning]: types_1.IconColor.WarningDefault,
|
|
25
|
+
[design_system_shared_1.TagSeverity.Info]: types_1.IconColor.InfoDefault,
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=Tag.constants.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tag.constants.cjs","sourceRoot":"","sources":["../../../src/components/Tag/Tag.constants.ts"],"names":[],"mappings":";;;AAAA,kFAAiF;AAEjF,iDAA4D;AAE/C,QAAA,2BAA2B,GAGpC;IACF,CAAC,kCAAW,CAAC,OAAO,CAAC,EAAE,0BAAkB,CAAC,eAAe;IACzD,CAAC,kCAAW,CAAC,OAAO,CAAC,EAAE,0BAAkB,CAAC,YAAY;IACtD,CAAC,kCAAW,CAAC,KAAK,CAAC,EAAE,0BAAkB,CAAC,UAAU;IAClD,CAAC,kCAAW,CAAC,OAAO,CAAC,EAAE,0BAAkB,CAAC,YAAY;IACtD,CAAC,kCAAW,CAAC,IAAI,CAAC,EAAE,0BAAkB,CAAC,SAAS;CACjD,CAAC;AAEW,QAAA,2BAA2B,GAAmC;IACzE,CAAC,kCAAW,CAAC,OAAO,CAAC,EAAE,gCAAS,CAAC,WAAW;IAC5C,CAAC,kCAAW,CAAC,OAAO,CAAC,EAAE,gCAAS,CAAC,cAAc;IAC/C,CAAC,kCAAW,CAAC,KAAK,CAAC,EAAE,gCAAS,CAAC,YAAY;IAC3C,CAAC,kCAAW,CAAC,OAAO,CAAC,EAAE,gCAAS,CAAC,cAAc;IAC/C,CAAC,kCAAW,CAAC,IAAI,CAAC,EAAE,gCAAS,CAAC,WAAW;CAC1C,CAAC;AAEW,QAAA,2BAA2B,GAAmC;IACzE,CAAC,kCAAW,CAAC,OAAO,CAAC,EAAE,iBAAS,CAAC,WAAW;IAC5C,CAAC,kCAAW,CAAC,OAAO,CAAC,EAAE,iBAAS,CAAC,cAAc;IAC/C,CAAC,kCAAW,CAAC,KAAK,CAAC,EAAE,iBAAS,CAAC,YAAY;IAC3C,CAAC,kCAAW,CAAC,OAAO,CAAC,EAAE,iBAAS,CAAC,cAAc;IAC/C,CAAC,kCAAW,CAAC,IAAI,CAAC,EAAE,iBAAS,CAAC,WAAW;CAC1C,CAAC","sourcesContent":["import { TagSeverity, TextColor } from '@metamask-previews/design-system-shared';\n\nimport { BoxBackgroundColor, IconColor } from '../../types';\n\nexport const MAP_TAG_SEVERITY_BACKGROUND: Record<\n TagSeverity,\n BoxBackgroundColor\n> = {\n [TagSeverity.Neutral]: BoxBackgroundColor.BackgroundMuted,\n [TagSeverity.Success]: BoxBackgroundColor.SuccessMuted,\n [TagSeverity.Error]: BoxBackgroundColor.ErrorMuted,\n [TagSeverity.Warning]: BoxBackgroundColor.WarningMuted,\n [TagSeverity.Info]: BoxBackgroundColor.InfoMuted,\n};\n\nexport const MAP_TAG_SEVERITY_TEXT_COLOR: Record<TagSeverity, TextColor> = {\n [TagSeverity.Neutral]: TextColor.TextDefault,\n [TagSeverity.Success]: TextColor.SuccessDefault,\n [TagSeverity.Error]: TextColor.ErrorDefault,\n [TagSeverity.Warning]: TextColor.WarningDefault,\n [TagSeverity.Info]: TextColor.InfoDefault,\n};\n\nexport const MAP_TAG_SEVERITY_ICON_COLOR: Record<TagSeverity, IconColor> = {\n [TagSeverity.Neutral]: IconColor.IconDefault,\n [TagSeverity.Success]: IconColor.SuccessDefault,\n [TagSeverity.Error]: IconColor.ErrorDefault,\n [TagSeverity.Warning]: IconColor.WarningDefault,\n [TagSeverity.Info]: IconColor.InfoDefault,\n};\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TagSeverity, TextColor } from "@metamask-previews/design-system-shared";
|
|
2
|
+
import { BoxBackgroundColor, IconColor } from "../../types/index.cjs";
|
|
3
|
+
export declare const MAP_TAG_SEVERITY_BACKGROUND: Record<TagSeverity, BoxBackgroundColor>;
|
|
4
|
+
export declare const MAP_TAG_SEVERITY_TEXT_COLOR: Record<TagSeverity, TextColor>;
|
|
5
|
+
export declare const MAP_TAG_SEVERITY_ICON_COLOR: Record<TagSeverity, IconColor>;
|
|
6
|
+
//# sourceMappingURL=Tag.constants.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tag.constants.d.cts","sourceRoot":"","sources":["../../../src/components/Tag/Tag.constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,gDAAgD;AAEjF,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,8BAAoB;AAE5D,eAAO,MAAM,2BAA2B,EAAE,MAAM,CAC9C,WAAW,EACX,kBAAkB,CAOnB,CAAC;AAEF,eAAO,MAAM,2BAA2B,EAAE,MAAM,CAAC,WAAW,EAAE,SAAS,CAMtE,CAAC;AAEF,eAAO,MAAM,2BAA2B,EAAE,MAAM,CAAC,WAAW,EAAE,SAAS,CAMtE,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TagSeverity, TextColor } from "@metamask-previews/design-system-shared";
|
|
2
|
+
import { BoxBackgroundColor, IconColor } from "../../types/index.mjs";
|
|
3
|
+
export declare const MAP_TAG_SEVERITY_BACKGROUND: Record<TagSeverity, BoxBackgroundColor>;
|
|
4
|
+
export declare const MAP_TAG_SEVERITY_TEXT_COLOR: Record<TagSeverity, TextColor>;
|
|
5
|
+
export declare const MAP_TAG_SEVERITY_ICON_COLOR: Record<TagSeverity, IconColor>;
|
|
6
|
+
//# sourceMappingURL=Tag.constants.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tag.constants.d.mts","sourceRoot":"","sources":["../../../src/components/Tag/Tag.constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,gDAAgD;AAEjF,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,8BAAoB;AAE5D,eAAO,MAAM,2BAA2B,EAAE,MAAM,CAC9C,WAAW,EACX,kBAAkB,CAOnB,CAAC;AAEF,eAAO,MAAM,2BAA2B,EAAE,MAAM,CAAC,WAAW,EAAE,SAAS,CAMtE,CAAC;AAEF,eAAO,MAAM,2BAA2B,EAAE,MAAM,CAAC,WAAW,EAAE,SAAS,CAMtE,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TagSeverity, TextColor } from "@metamask-previews/design-system-shared";
|
|
2
|
+
import { BoxBackgroundColor, IconColor } from "../../types/index.mjs";
|
|
3
|
+
export const MAP_TAG_SEVERITY_BACKGROUND = {
|
|
4
|
+
[TagSeverity.Neutral]: BoxBackgroundColor.BackgroundMuted,
|
|
5
|
+
[TagSeverity.Success]: BoxBackgroundColor.SuccessMuted,
|
|
6
|
+
[TagSeverity.Error]: BoxBackgroundColor.ErrorMuted,
|
|
7
|
+
[TagSeverity.Warning]: BoxBackgroundColor.WarningMuted,
|
|
8
|
+
[TagSeverity.Info]: BoxBackgroundColor.InfoMuted,
|
|
9
|
+
};
|
|
10
|
+
export const MAP_TAG_SEVERITY_TEXT_COLOR = {
|
|
11
|
+
[TagSeverity.Neutral]: TextColor.TextDefault,
|
|
12
|
+
[TagSeverity.Success]: TextColor.SuccessDefault,
|
|
13
|
+
[TagSeverity.Error]: TextColor.ErrorDefault,
|
|
14
|
+
[TagSeverity.Warning]: TextColor.WarningDefault,
|
|
15
|
+
[TagSeverity.Info]: TextColor.InfoDefault,
|
|
16
|
+
};
|
|
17
|
+
export const MAP_TAG_SEVERITY_ICON_COLOR = {
|
|
18
|
+
[TagSeverity.Neutral]: IconColor.IconDefault,
|
|
19
|
+
[TagSeverity.Success]: IconColor.SuccessDefault,
|
|
20
|
+
[TagSeverity.Error]: IconColor.ErrorDefault,
|
|
21
|
+
[TagSeverity.Warning]: IconColor.WarningDefault,
|
|
22
|
+
[TagSeverity.Info]: IconColor.InfoDefault,
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=Tag.constants.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tag.constants.mjs","sourceRoot":"","sources":["../../../src/components/Tag/Tag.constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,gDAAgD;AAEjF,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,8BAAoB;AAE5D,MAAM,CAAC,MAAM,2BAA2B,GAGpC;IACF,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,eAAe;IACzD,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,YAAY;IACtD,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,kBAAkB,CAAC,UAAU;IAClD,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,YAAY;IACtD,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,kBAAkB,CAAC,SAAS;CACjD,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAmC;IACzE,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,WAAW;IAC5C,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,cAAc;IAC/C,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,YAAY;IAC3C,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,cAAc;IAC/C,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,WAAW;CAC1C,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAmC;IACzE,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,WAAW;IAC5C,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,cAAc;IAC/C,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,YAAY;IAC3C,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,cAAc;IAC/C,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,WAAW;CAC1C,CAAC","sourcesContent":["import { TagSeverity, TextColor } from '@metamask-previews/design-system-shared';\n\nimport { BoxBackgroundColor, IconColor } from '../../types';\n\nexport const MAP_TAG_SEVERITY_BACKGROUND: Record<\n TagSeverity,\n BoxBackgroundColor\n> = {\n [TagSeverity.Neutral]: BoxBackgroundColor.BackgroundMuted,\n [TagSeverity.Success]: BoxBackgroundColor.SuccessMuted,\n [TagSeverity.Error]: BoxBackgroundColor.ErrorMuted,\n [TagSeverity.Warning]: BoxBackgroundColor.WarningMuted,\n [TagSeverity.Info]: BoxBackgroundColor.InfoMuted,\n};\n\nexport const MAP_TAG_SEVERITY_TEXT_COLOR: Record<TagSeverity, TextColor> = {\n [TagSeverity.Neutral]: TextColor.TextDefault,\n [TagSeverity.Success]: TextColor.SuccessDefault,\n [TagSeverity.Error]: TextColor.ErrorDefault,\n [TagSeverity.Warning]: TextColor.WarningDefault,\n [TagSeverity.Info]: TextColor.InfoDefault,\n};\n\nexport const MAP_TAG_SEVERITY_ICON_COLOR: Record<TagSeverity, IconColor> = {\n [TagSeverity.Neutral]: IconColor.IconDefault,\n [TagSeverity.Success]: IconColor.SuccessDefault,\n [TagSeverity.Error]: IconColor.ErrorDefault,\n [TagSeverity.Warning]: IconColor.WarningDefault,\n [TagSeverity.Info]: IconColor.InfoDefault,\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tag.d.cts","sourceRoot":"","sources":["../../../src/components/Tag/Tag.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,cAAc;AAW1B,OAAO,KAAK,EAAE,QAAQ,EAAE,wBAAoB;AAE5C,eAAO,MAAM,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC,QAAQ,CAyElC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tag.d.mts","sourceRoot":"","sources":["../../../src/components/Tag/Tag.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,cAAc;AAW1B,OAAO,KAAK,EAAE,QAAQ,EAAE,wBAAoB;AAE5C,eAAO,MAAM,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC,QAAQ,CAyElC,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
function $importDefault(module) {
|
|
2
|
+
if (module?.__esModule) {
|
|
3
|
+
return module.default;
|
|
4
|
+
}
|
|
5
|
+
return module;
|
|
6
|
+
}
|
|
7
|
+
import { FontWeight, TagSeverity, TextVariant } from "@metamask-previews/design-system-shared";
|
|
8
|
+
import { useTailwind } from "@metamask-previews/design-system-twrnc-preset";
|
|
9
|
+
import $React from "react";
|
|
10
|
+
const React = $importDefault($React);
|
|
11
|
+
import { Box } from "../Box/index.mjs";
|
|
12
|
+
import { BoxRow } from "../BoxRow/index.mjs";
|
|
13
|
+
import { Icon, IconSize } from "../Icon/index.mjs";
|
|
14
|
+
import { MAP_TAG_SEVERITY_BACKGROUND, MAP_TAG_SEVERITY_ICON_COLOR, MAP_TAG_SEVERITY_TEXT_COLOR } from "./Tag.constants.mjs";
|
|
15
|
+
export const Tag = ({ children, severity = TagSeverity.Neutral, startIconName, startIconProps, startAccessory, endIconName, endIconProps, endAccessory, twClassName, style, ...props }) => {
|
|
16
|
+
const tw = useTailwind();
|
|
17
|
+
const backgroundColor = MAP_TAG_SEVERITY_BACKGROUND[severity];
|
|
18
|
+
const textColor = MAP_TAG_SEVERITY_TEXT_COLOR[severity];
|
|
19
|
+
const iconColor = MAP_TAG_SEVERITY_ICON_COLOR[severity];
|
|
20
|
+
return (<Box {...props} backgroundColor={backgroundColor} style={[
|
|
21
|
+
tw.style('rounded-md self-start', (startIconName ?? startIconProps?.name) ? 'pl-1' : 'pl-1.5', (endIconName ?? endIconProps?.name) ? 'pr-1' : 'pr-1.5', twClassName),
|
|
22
|
+
style,
|
|
23
|
+
]}>
|
|
24
|
+
<BoxRow textProps={{
|
|
25
|
+
color: textColor,
|
|
26
|
+
variant: TextVariant.BodyXs,
|
|
27
|
+
fontWeight: FontWeight.Medium,
|
|
28
|
+
}} startAccessory={(() => {
|
|
29
|
+
const name = startIconName ?? startIconProps?.name;
|
|
30
|
+
if (!name) {
|
|
31
|
+
return startAccessory ?? null;
|
|
32
|
+
}
|
|
33
|
+
return (<Icon name={name} color={iconColor} size={IconSize.Xs} twClassName="shrink-0" {...startIconProps}/>);
|
|
34
|
+
})()} endAccessory={(() => {
|
|
35
|
+
const name = endIconName ?? endIconProps?.name;
|
|
36
|
+
if (!name) {
|
|
37
|
+
return endAccessory ?? null;
|
|
38
|
+
}
|
|
39
|
+
return (<Icon name={name} color={iconColor} size={IconSize.Xs} twClassName="shrink-0" {...endIconProps}/>);
|
|
40
|
+
})()}>
|
|
41
|
+
{children}
|
|
42
|
+
</BoxRow>
|
|
43
|
+
</Box>);
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=Tag.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tag.mjs","sourceRoot":"","sources":["../../../src/components/Tag/Tag.tsx"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,UAAU,EACV,WAAW,EACX,WAAW,EACZ,gDAAgD;AACjD,OAAO,EAAE,WAAW,EAAE,sDAAsD;AAC5E,OAAO,MAAK,cAAc;;AAE1B,OAAO,EAAE,GAAG,EAAE,yBAAe;AAC7B,OAAO,EAAE,MAAM,EAAE,4BAAkB;AACnC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,0BAAgB;AAEzC,OAAO,EACL,2BAA2B,E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CAAC,CAAC,IAAI,CAAC,CACX,KAAK,CAAC,CAAC,SAAS,CAAC,CACjB,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAClB,WAAW,CAAC,UAAU,CACtB,IAAI,cAAc,CAAC,EACnB,CACH,CAAC;QACJ,CAAC,CAAC,EAAE,CAAC,CACL,YAAY,CAAC,CAAC,CAAC,GAAG,EAAE;YAClB,MAAM,IAAI,GAAG,WAAW,IAAI,YAAY,EAAE,IAAI,CAAC;YAC/C,IAAI,CAAC,IAAI,EAAE;gBACT,OAAO,YAAY,IAAI,IAAI,CAAC;aAC7B;YACD,OAAO,CACL,CAAC,IAAI,CACH,IAAI,CAAC,CAAC,IAAI,CAAC,CACX,KAAK,CAAC,CAAC,SAAS,CAAC,CACjB,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAClB,WAAW,CAAC,UAAU,CACtB,IAAI,YAAY,CAAC,EACjB,CACH,CAAC;QACJ,CAAC,CAAC,EAAE,CAAC,CAEL;QAAA,CAAC,QAAQ,CACX;MAAA,EAAE,MAAM,CACV;IAAA,EAAE,GAAG,CAAC,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n FontWeight,\n TagSeverity,\n TextVariant,\n} from '@metamask-previews/design-system-shared';\nimport { useTailwind } from '@metamask-previews/design-system-twrnc-preset';\nimport React from 'react';\n\nimport { Box } from '../Box';\nimport { BoxRow } from '../BoxRow';\nimport { Icon, IconSize } from '../Icon';\n\nimport {\n MAP_TAG_SEVERITY_BACKGROUND,\n MAP_TAG_SEVERITY_ICON_COLOR,\n MAP_TAG_SEVERITY_TEXT_COLOR,\n} from './Tag.constants';\nimport type { TagProps } from './Tag.types';\n\nexport const Tag: React.FC<TagProps> = ({\n children,\n severity = TagSeverity.Neutral,\n startIconName,\n startIconProps,\n startAccessory,\n endIconName,\n endIconProps,\n endAccessory,\n twClassName,\n style,\n ...props\n}) => {\n const tw = useTailwind();\n const backgroundColor = MAP_TAG_SEVERITY_BACKGROUND[severity];\n const textColor = MAP_TAG_SEVERITY_TEXT_COLOR[severity];\n const iconColor = MAP_TAG_SEVERITY_ICON_COLOR[severity];\n\n return (\n <Box\n {...props}\n backgroundColor={backgroundColor}\n style={[\n tw.style(\n 'rounded-md self-start',\n (startIconName ?? startIconProps?.name) ? 'pl-1' : 'pl-1.5',\n (endIconName ?? endIconProps?.name) ? 'pr-1' : 'pr-1.5',\n twClassName,\n ),\n style,\n ]}\n >\n <BoxRow\n textProps={{\n color: textColor,\n variant: TextVariant.BodyXs,\n fontWeight: FontWeight.Medium,\n }}\n startAccessory={(() => {\n const name = startIconName ?? startIconProps?.name;\n if (!name) {\n return startAccessory ?? null;\n }\n return (\n <Icon\n name={name}\n color={iconColor}\n size={IconSize.Xs}\n twClassName=\"shrink-0\"\n {...startIconProps}\n />\n );\n })()}\n endAccessory={(() => {\n const name = endIconName ?? endIconProps?.name;\n if (!name) {\n return endAccessory ?? null;\n }\n return (\n <Icon\n name={name}\n color={iconColor}\n size={IconSize.Xs}\n twClassName=\"shrink-0\"\n {...endIconProps}\n />\n );\n })()}\n >\n {children}\n </BoxRow>\n </Box>\n );\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tag.types.cjs","sourceRoot":"","sources":["../../../src/components/Tag/Tag.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { TagPropsShared } from '@metamask-previews/design-system-shared';\nimport type { ViewProps, StyleProp, ViewStyle } from 'react-native';\n\nimport type { IconName, IconProps } from '../Icon';\n\n/**\n * Tag component props (React Native platform-specific).\n * Extends shared props from @metamask-previews/design-system-shared with React Native specific platform concerns.\n */\nexport type TagProps = TagPropsShared & {\n /**\n * Optional prop to specify an icon to show at the start of the tag (`IconSize.Xs` unless overridden in `startIconProps`).\n */\n startIconName?: IconName;\n /**\n * Optional prop to pass additional properties to the start icon. You may set `name` here instead of `startIconName`.\n */\n startIconProps?: Partial<IconProps>;\n /**\n * Optional prop to specify an icon to show at the end of the tag (`IconSize.Xs` unless overridden in `endIconProps`).\n */\n endIconName?: IconName;\n /**\n * Optional prop to pass additional properties to the end icon. You may set `name` here instead of `endIconName`.\n */\n endIconProps?: Partial<IconProps>;\n /**\n * Additional Tailwind classes to be applied to the Tag container.\n */\n twClassName?: string;\n /**\n * Test identifier for selecting the component in tests.\n */\n testID?: string;\n /**\n * Optional container styles.\n */\n style?: StyleProp<ViewStyle>;\n} & Omit<ViewProps, 'children' | 'style'>;\n"]}
|