UNPKG

rn-inkpad

Version:

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

64 lines (63 loc) 3.05 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.FloatingActionButton = void 0; const react_1 = __importStar(require("react")); const react_native_1 = require("react-native"); const ActionButton_1 = require("./ActionButton"); const FloatingActionButton = ({ actions, backgroundColor, marginHorizontal = 20, marginVertical = 30, icon, iconColor, iconSize, onPress, align = 'bottom-right', size = 50, }) => { const [showActions, setShowActions] = (0, react_1.useState)(false); const position = { bottom: align.includes('bottom') ? marginVertical : undefined, top: align.includes('top') ? marginVertical : undefined, right: align.includes('right') ? marginHorizontal : undefined, left: align.includes('left') ? marginHorizontal : undefined, }; const handlePress = () => { if (!!actions && !onPress) { setShowActions(!showActions); } else { if (!!onPress) { onPress(); } } }; return (<react_native_1.View style={[ { position: 'absolute', alignItems: align.includes('left') ? 'flex-start' : 'flex-end', flexDirection: align.includes('top') ? 'column-reverse' : 'column', }, position, ]}> {showActions && actions && !onPress && actions.map((action, index) => (<ActionButton_1.ActionButton align={align.includes('left') ? 'left' : 'right'} backgroundColor={backgroundColor} icon={action.icon} iconColor={iconColor} iconSize={(iconSize ?? 22) - 4} margin={5} onPress={action.onPress} size={size - 10} text={action.text} key={index}/>))} <ActionButton_1.ActionButton onPress={handlePress} backgroundColor={backgroundColor} icon={icon ? icon : showActions ? 'close' : 'add'} iconColor={iconColor} size={size} iconSize={iconSize}/> </react_native_1.View>); }; exports.FloatingActionButton = FloatingActionButton;