@bytedance/mona-client-web
Version:
web for mona
38 lines • 2.95 kB
JavaScript
import { useEffect, useState } from 'react';
import EventEmitter from '../../EventEmitter';
var eventEmitter = new EventEmitter();
export var useNavBarTitle = function (props) {
var _a = useState(props === null || props === void 0 ? void 0 : props.navigationBarTitleText), title = _a[0], setTitle = _a[1];
var _b = useState((props === null || props === void 0 ? void 0 : props.navigationBarTextStyle) || '#000'), frontColor = _b[0], setFrontColor = _b[1];
var _c = useState((props === null || props === void 0 ? void 0 : props.navigationBarBackgroundColor) || '#fff'), backgroundColor = _c[0], setBackgroundColor = _c[1];
useEffect(function () {
eventEmitter.on('setNavigationBarTitle', function (options) {
var _a, _b, _c, _d;
if (options.title) {
setTitle(options.title);
(_a = options === null || options === void 0 ? void 0 : options.success) === null || _a === void 0 ? void 0 : _a.call(options, { errMsg: 'setNavigationBarTitle:ok' });
(_b = options === null || options === void 0 ? void 0 : options.complete) === null || _b === void 0 ? void 0 : _b.call(options, { errMsg: 'setNavigationBarTitle:ok' });
}
else {
(_c = options === null || options === void 0 ? void 0 : options.success) === null || _c === void 0 ? void 0 : _c.call(options, { errMsg: 'setNavigationBarTitle:fail' });
(_d = options === null || options === void 0 ? void 0 : options.complete) === null || _d === void 0 ? void 0 : _d.call(options, { errMsg: 'setNavigationBarTitle:fail' });
}
});
eventEmitter.on('setNavigationBarColor', function (options) {
var _a, _b, _c, _d;
if (options.frontColor || options.backgroundColor) {
options.frontColor && setFrontColor(options.frontColor);
options.backgroundColor && setBackgroundColor(options.backgroundColor);
(_a = options === null || options === void 0 ? void 0 : options.success) === null || _a === void 0 ? void 0 : _a.call(options, { errMsg: 'setNavigationBarTitle:ok' });
(_b = options === null || options === void 0 ? void 0 : options.complete) === null || _b === void 0 ? void 0 : _b.call(options, { errMsg: 'setNavigationBarTitle:ok' });
}
else {
(_c = options === null || options === void 0 ? void 0 : options.success) === null || _c === void 0 ? void 0 : _c.call(options, { errMsg: 'setNavigationBarTitle:fail' });
(_d = options === null || options === void 0 ? void 0 : options.complete) === null || _d === void 0 ? void 0 : _d.call(options, { errMsg: 'setNavigationBarTitle:fail' });
}
});
}, []);
return { title: title, frontColor: frontColor, backgroundColor: backgroundColor };
};
export var useNavBarColor = function () { };
//# sourceMappingURL=utils.js.map