UNPKG

rn-inkpad

Version:

<img src="https://res.cloudinary.com/fercloudinary/image/upload/v1715452841/packages/inkpad-banner_acl0xl.png" />

81 lines (79 loc) 3.22 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.Switch = void 0; const react_1 = __importStar(require("react")); const react_native_1 = require("react-native"); const Switch = ({ backgrounColor = '#1DFF56', border, borderColor, borderWidth = 2, isOn, fullWidth, justifyContent, onChange, textStyle, text, }) => { const [isEnabled, setIsEnabled] = (0, react_1.useState)(isOn); const isWeb = react_native_1.Platform.OS === 'web'; const toggleSwitch = () => { setIsEnabled(!isEnabled); if (!!onChange) { onChange(!isEnabled); } }; return (<react_native_1.View style={{ width: fullWidth ? '100%' : 'auto', flexDirection: 'row', alignItems: 'center', gap: 5, justifyContent, }}> {text && <react_native_1.Text style={textStyle}>{text}</react_native_1.Text>} {isWeb ? (<react_native_1.TouchableOpacity onPress={toggleSwitch} style={[ styles.switchContainer, { borderWidth: border ? borderWidth : 0, borderColor }, { backgroundColor: isOn ? backgrounColor : '#D9D9DB' }, ]}> <react_native_1.View style={[ styles.thumb, { alignSelf: isOn ? 'flex-end' : 'flex-start' }, ]}/> </react_native_1.TouchableOpacity>) : (<react_native_1.View style={{ borderWidth: border ? borderWidth : 0, borderColor, borderRadius: 16, }}> <react_native_1.Switch trackColor={{ false: '#D9D9DB', true: backgrounColor }} thumbColor={react_native_1.Platform.OS === 'android' ? backgrounColor : ''} onValueChange={toggleSwitch} value={isEnabled}/> </react_native_1.View>)} </react_native_1.View>); }; exports.Switch = Switch; const styles = react_native_1.StyleSheet.create({ switchContainer: { width: 50, height: 30, borderRadius: 15, justifyContent: 'center', padding: 5, }, thumb: { width: 20, height: 20, borderRadius: 10, backgroundColor: '#FFF', }, });