UNPKG

rmux

Version:
80 lines (67 loc) 1.97 kB
/*! * rmux.js v0.0.1-alpha.16 * (c) 2018-2019 空鱼 * Released under the MIT License. */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) : typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) : (global = global || self, factory(global.rmux = global.rmux || {}, global.React)); }(this, (function (exports, React) { 'use strict'; React = React && React.hasOwnProperty('default') ? React['default'] : React; const getStyle = (font, base) => ({ fontSize: `${font}px`, "-webkit-transform": `scale(${font / base})`, "-webkit-transform-origin-x": "left", "-o-transform": "scale(1)", display: "inline-block", "white-space": "nowrap" // 默认强制不换行 }); const ChromeSizeAdjust = props => { const { font = 10, base = 12, children, style } = props; const defaultStyle = getStyle(font, base); return React.createElement("span", { style: { ...defaultStyle, ...style } }, children); }; class ErrorBoundary extends React.Component { constructor(props) { super(props); this.state = { hasError: false }; } componentDidCatch(error, errorInfo) { // tslint:disable console.error("loading error: ", error, errorInfo); // tslint:enable this.setState({ hasError: true }); } render() { const { errorFallback = null, children } = this.props; const { hasError } = this.state; return hasError ? errorFallback : children; } } const If = props => { return props.data ? props.children : null; }; exports.ChromeSizeAdjust = ChromeSizeAdjust; exports.ErrorBoundary = ErrorBoundary; exports.If = If; exports.getStyle = getStyle; Object.defineProperty(exports, '__esModule', { value: true }); })));