UNPKG

@nayan-ui/react-native

Version:

React Native Component Library for smooth and faster mobile application development.

206 lines (205 loc) 4.99 kB
"use strict"; import React, { useMemo } from 'react'; import Toast, { BaseToast, ErrorToast } from 'react-native-toast-message'; import { useNTheme } from "../hooks/useNTheme.js"; import { jsx as _jsx } from "react-native-css-interop/jsx-runtime"; const createToastConfig = (colors, icons = {}) => ({ success: props => { const IconComponent = icons.successIcon; const iconElement = IconComponent ? /*#__PURE__*/React.isValidElement(IconComponent) ? IconComponent : _jsx(IconComponent, { size: 20, color: colors.primary }) : null; return _jsx(BaseToast, { ...props, style: { borderLeftColor: colors.primary }, contentContainerStyle: { paddingHorizontal: 10, backgroundColor: colors.card, borderWidth: 1, borderColor: colors.border }, text2NumberOfLines: 2, text1Style: { height: 0 }, text2Style: { marginTop: -3, fontSize: 16, lineHeight: 25, color: colors.text }, renderLeadingIcon: () => iconElement }); }, error: props => { const IconComponent = icons.errorIcon; const iconElement = IconComponent ? /*#__PURE__*/React.isValidElement(IconComponent) ? IconComponent : _jsx(IconComponent, { size: 20, color: "red" }) : null; return _jsx(ErrorToast, { ...props, style: { borderLeftColor: 'red' }, contentContainerStyle: { paddingHorizontal: 10, backgroundColor: colors.card, borderWidth: 1, borderColor: colors.border }, text2NumberOfLines: 2, text1Style: { height: 0 }, text2Style: { marginTop: -3, fontSize: 16, lineHeight: 25, color: colors.text }, renderLeadingIcon: () => iconElement }); }, info: props => { const IconComponent = icons.infoIcon; const iconElement = IconComponent ? /*#__PURE__*/React.isValidElement(IconComponent) ? IconComponent : _jsx(IconComponent, { size: 20, color: colors.primary }) : null; return _jsx(BaseToast, { ...props, style: { borderLeftColor: colors.primary }, contentContainerStyle: { paddingHorizontal: 10, backgroundColor: colors.card, borderWidth: 1, borderColor: colors.border }, text2NumberOfLines: 2, text1Style: { height: 0 }, text2Style: { marginTop: -3, fontSize: 16, lineHeight: 25, color: colors.text }, renderLeadingIcon: () => iconElement }); }, warning: props => { const IconComponent = icons.warningIcon; const iconElement = IconComponent ? /*#__PURE__*/React.isValidElement(IconComponent) ? IconComponent : _jsx(IconComponent, { size: 20, color: "orange" }) : null; return _jsx(BaseToast, { ...props, style: { borderLeftColor: 'orange' }, contentContainerStyle: { paddingHorizontal: 10, backgroundColor: colors.card, borderWidth: 1, borderColor: colors.border }, text2NumberOfLines: 2, text1Style: { height: 0 }, text2Style: { marginTop: -3, fontSize: 16, lineHeight: 25, color: colors.text }, renderLeadingIcon: () => iconElement }); } }); const NToastComponent = /*#__PURE__*/React.memo(({ config, successIcon, errorIcon, infoIcon, warningIcon }) => { const { colors } = useNTheme(); const toastConfig = useMemo(() => config || createToastConfig(colors, { successIcon, errorIcon, infoIcon, warningIcon }), [colors, config, successIcon, errorIcon, infoIcon, warningIcon]); return _jsx(Toast, { config: toastConfig }); }); NToastComponent.displayName = 'NToast'; const toastMethods = { show: ({ message, title, type = 'success', icon, ...options }) => { Toast.show({ type, text1: title, text2: message, position: 'bottom', bottomOffset: 50, ...options }); }, hide: () => Toast.hide(), success: (message, title) => { Toast.show({ type: 'success', text1: title, text2: message, position: 'bottom', bottomOffset: 50 }); }, error: (message, title) => { Toast.show({ type: 'error', text1: title, text2: message, position: 'bottom', bottomOffset: 50 }); }, info: (message, title) => { Toast.show({ type: 'info', text1: title, text2: message, position: 'bottom', bottomOffset: 50 }); }, warning: (message, title) => { Toast.show({ type: 'warning', text1: title, text2: message, position: 'bottom', bottomOffset: 50 }); } }; export const NToast = Object.assign(NToastComponent, toastMethods); //# sourceMappingURL=NToast.js.map