UNPKG

@metamask/design-system-react-native

Version:
68 lines 3.29 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Spinner = void 0; const design_system_twrnc_preset_1 = require("@metamask/design-system-twrnc-preset"); const react_1 = __importStar(require("react")); const react_native_1 = require("react-native/index.js"); const react_native_reanimated_1 = __importStar(require("react-native-reanimated")); const Icon_1 = require("../../Icon/index.cjs"); const Text_1 = require("../../Text/index.cjs"); const Spinner = ({ color = Icon_1.IconColor.IconDefault, spinnerIconProps, loadingText, loadingTextProps, twClassName = '', style, ...props }) => { const tw = (0, design_system_twrnc_preset_1.useTailwind)(); // Create a shared value for rotation const rotation = (0, react_native_reanimated_1.useSharedValue)(0); // Start the animation when the component mounts (0, react_1.useEffect)(() => { rotation.value = (0, react_native_reanimated_1.withRepeat)((0, react_native_reanimated_1.withTiming)(360, { duration: 1000, easing: react_native_reanimated_1.Easing.linear }), // Complete a full spin in 1 second -1, // Infinite repetitions false); }, []); // Define the animated style const animatedStyle = (0, react_native_reanimated_1.useAnimatedStyle)(() => ({ transform: [{ rotate: `${rotation.value % 360}deg` }], })); const finalSpinnerIconProps = { size: Icon_1.IconSize.Md, name: Icon_1.IconName.Loading, testID: 'spinner-icon', color, ...spinnerIconProps, }; const finalLoadingTextProps = { variant: Text_1.TextVariant.BodyMd, color: Text_1.TextColor.TextDefault, testID: 'spinner-text', ...loadingTextProps, }; return (<react_native_1.View style={[tw `flex-row items-center gap-x-2 ${twClassName}`, style]} testID="spinner" {...props}> <react_native_reanimated_1.default.View style={[animatedStyle]} testID="spinner-animated-view"> <Icon_1.Icon {...finalSpinnerIconProps}/> </react_native_reanimated_1.default.View> {loadingText && <Text_1.Text {...finalLoadingTextProps}>{loadingText}</Text_1.Text>} </react_native_1.View>); }; exports.Spinner = Spinner; //# sourceMappingURL=Spinner.cjs.map