UNPKG

@antmjs/vantui

Version:

一套适用于Taro3及React的vantui组件库

125 lines 5.45 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; var _excluded = ["style", "className", "zIndex", "message", "background", "type", "color", "safeAreaInsetTop", "top", "duration"]; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } import { useState, useEffect, useCallback } from 'react'; import { View, Text } from '@tarojs/components'; import { nextTick } from '@tarojs/taro'; import * as utils from '../wxs/utils'; import VanTransition from '../transition/index'; import { getWindowInfo } from '../common/utils'; import { get } from '../default-props'; import * as computed from './wxs'; import { jsx as _jsx } from "react/jsx-runtime"; import { jsxs as _jsxs } from "react/jsx-runtime"; var defaultId = 'van-notify'; var defaultOptions = { selector: '#van-notify', message: '', background: '', type: 'danger', color: '#fff', duration: 3000, safeAreaInsetTop: false, top: 0, id: defaultId }; export function Notify(props) { var _useState = useState(get().Notify), _useState2 = _slicedToArray(_useState, 1), d = _useState2[0]; var _useState3 = useState({ selector: '#van-notify', show: false, statusBarHeight: undefined, message: '', background: '', type: 'danger', color: '#fff', safeAreaInsetTop: false, top: 0, id: defaultId, onClick: function onClick(_data) {}, onOpened: function onOpened() {}, onClose: function onClose() {} }), _useState4 = _slicedToArray(_useState3, 2), state = _useState4[0], setState = _useState4[1]; var _defaultOptions$d$pro = _objectSpread(_objectSpread(_objectSpread({}, defaultOptions), d), props), style = _defaultOptions$d$pro.style, className = _defaultOptions$d$pro.className, zIndex = _defaultOptions$d$pro.zIndex, _defaultOptions$d$pro2 = _defaultOptions$d$pro.message, message = _defaultOptions$d$pro2 === void 0 ? '' : _defaultOptions$d$pro2, _defaultOptions$d$pro3 = _defaultOptions$d$pro.background, background = _defaultOptions$d$pro3 === void 0 ? '' : _defaultOptions$d$pro3, _defaultOptions$d$pro4 = _defaultOptions$d$pro.type, type = _defaultOptions$d$pro4 === void 0 ? 'danger' : _defaultOptions$d$pro4, _defaultOptions$d$pro5 = _defaultOptions$d$pro.color, color = _defaultOptions$d$pro5 === void 0 ? '#fff' : _defaultOptions$d$pro5, _defaultOptions$d$pro6 = _defaultOptions$d$pro.safeAreaInsetTop, safeAreaInsetTop = _defaultOptions$d$pro6 === void 0 ? false : _defaultOptions$d$pro6, _defaultOptions$d$pro7 = _defaultOptions$d$pro.top, top = _defaultOptions$d$pro7 === void 0 ? 0 : _defaultOptions$d$pro7, duration = _defaultOptions$d$pro.duration, others = _objectWithoutProperties(_defaultOptions$d$pro, _excluded); useEffect(function () { setState(function (state) { return _objectSpread(_objectSpread({}, state), {}, { id: props.id || defaultId }); }); }, [props]); useEffect(function () { nextTick(function () { var _getWindowInfo = getWindowInfo(), statusBarHeight = _getWindowInfo.statusBarHeight; setState(function (state) { return _objectSpread(_objectSpread({}, state), {}, { statusBarHeight: statusBarHeight }); }); }); }, []); var onTap = useCallback(function (event) { var _state$onClick; (_state$onClick = state.onClick) === null || _state$onClick === void 0 ? void 0 : _state$onClick.call(state, event); }, [state]); useEffect(function () { setTimeout(function () { setState(_objectSpread(_objectSpread({}, state), {}, { show: true })); }); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return /*#__PURE__*/_jsx(VanTransition, _objectSpread(_objectSpread({ name: "slide-down", show: state.show, className: "van-notify__container ".concat(className), style: utils.style([computed.rootStyle(zIndex ? { zIndex: zIndex, top: top } : { top: top }), style]), onClick: onTap }, others), {}, { children: /*#__PURE__*/_jsxs(View, { className: 'van-notify van-notify--' + type, style: computed.notifyStyle({ background: background, color: color }), children: [safeAreaInsetTop && /*#__PURE__*/_jsx(View, { style: 'height: ' + state.statusBarHeight + 'px' }), /*#__PURE__*/_jsx(Text, { children: message })] }) })); } export default Notify;