mh-rn-component
Version:
116 lines (103 loc) • 4.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _index = require("../utils/index");
var _types = require("../types");
var _reactNative = require("react-native");
var _Icon = _interopRequireDefault(require("../Icon"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const Button = props => {
/**
* type 样式的处理
*/
const [buttonStyle, setButtonStyle] = (0, _react.useState)({});
const [plainStyle, setPlainStyle] = (0, _react.useState)({});
const [fontColor, setFontColor] = (0, _react.useState)('#333');
const type = (props === null || props === void 0 ? void 0 : props.type) || 'default';
(0, _react.useEffect)(() => {
if (type !== 'default') {
setFontColor('#fff');
} else {
setFontColor('#333');
}
}, [props === null || props === void 0 ? void 0 : props.type]);
/**
* todo 是否还需要? 处理边框圆角
*/
(0, _react.useEffect)(() => {
if (props.borderRadius) {
if (typeof props.borderRadius == 'string') {
setButtonStyle(oldStyles => ({ ...oldStyles,
borderRadius: styles.button.height / 2
}));
} else {
setButtonStyle(oldStyles => ({ ...oldStyles,
borderRadius: Number(props.borderRadius)
}));
}
}
}, []);
(0, _react.useEffect)(() => {
if (props.plain) {
setPlainStyle({
backgroundColor: "#fff",
color: _types.ButtonType[type],
borderWidth: 1,
borderColor: props.color ? props.color : _types.ButtonType[type]
});
props.color && setFontColor(props.color);
}
}, [props.plain, props.color]);
return /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, null, /*#__PURE__*/_react.default.createElement(_reactNative.TouchableWithoutFeedback, {
disabled: props === null || props === void 0 ? void 0 : props.disabled
}, /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
onPress: props.onPress,
activeOpacity: 0.8
}, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
style: _reactNative.StyleSheet.flatten([styles.button, styles.content, styles.plr10, {
backgroundColor: props.color ? props.color : _types.ButtonType[type]
}, type === 'default' && !props.color && styles.border, plainStyle, props.style, {
opacity: props !== null && props !== void 0 && props.disabled ? 0.5 : 1,
borderRadius: props.borderRadius && Number(props.borderRadius) || 0
}])
}, props.icon && /*#__PURE__*/_react.default.createElement(_Icon.default, {
color: fontColor,
name: props.icon
}), /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
style: [styles.content, {
color: props.color ? fontColor : props.plain ? _types.ButtonType[type] : fontColor
}, props.textStyle]
}, props === null || props === void 0 ? void 0 : props.children)))));
};
const styles = _reactNative.StyleSheet.create({
button: {
minWidth: (0, _index.dp)(88),
height: (0, _index.dp)(44),
borderStyle: 'solid',
backgroundColor: '#fff',
...(_reactNative.Platform.OS === 'web' && {
cursor: 'pointer'
})
},
content: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center'
},
border: {
borderWidth: 1,
borderColor: '#333'
},
plr10: {
paddingLeft: 10,
paddingRight: 10
}
});
var _default = Button;
exports.default = _default;
//# sourceMappingURL=index.js.map