@antv/s2-react
Version:
use S2 with react
55 lines • 3.02 kB
JavaScript
import { getTooltipDefaultOptions } from '@antv/s2';
import { isEmpty } from 'lodash';
import React from 'react';
import { TooltipDescription } from './components/description';
import { TooltipDetail } from './components/detail';
import { TooltipHead } from './components/head-info';
import { TooltipInfos } from './components/infos';
import { TooltipInterpretation } from './components/interpretation';
import { TooltipOperator } from './components/operator';
import { TooltipSimpleTips } from './components/simple-tips';
import { TooltipSummary } from './components/summary';
import './index.less';
export const TooltipComponent = React.memo((props) => {
const { data, options, content, cell, onMounted } = props;
const renderOperation = (operator, onlyShowOperator) => {
if (!operator) {
return null;
}
return (React.createElement(TooltipOperator, Object.assign({}, operator, { menu: operator.menu, onlyShowOperator: onlyShowOperator, cell: cell })));
};
const renderNameTips = (nameTip) => {
const { name, tips } = nameTip || {};
return React.createElement(TooltipSimpleTips, { name: name, tips: tips });
};
const renderSummary = (summaries) => !isEmpty(summaries) && React.createElement(TooltipSummary, { summaries: summaries });
const renderHeadInfo = (headInfo) => {
const { cols = [], rows = [] } = headInfo || {};
return ((!isEmpty(cols) || !isEmpty(rows)) && (React.createElement(TooltipHead, { cols: cols, rows: rows })));
};
const renderDetail = (details) => !isEmpty(details) && React.createElement(TooltipDetail, { list: details });
const renderInfos = (infos) => infos && React.createElement(TooltipInfos, { infos: infos });
const renderInterpretation = (interpretation) => interpretation && React.createElement(TooltipInterpretation, Object.assign({}, interpretation));
const renderDescription = (description) => (React.createElement(TooltipDescription, { description: description }));
const renderContent = () => {
const { operator, onlyShowOperator } = getTooltipDefaultOptions(options);
const { summaries, headInfo, details, interpretation, infos, tips, name, description, } = data || {};
const nameTip = { name, tips };
if (onlyShowOperator) {
return renderOperation(operator, true);
}
const DefaultContent = (React.createElement(React.Fragment, null,
renderNameTips(nameTip),
renderSummary(summaries),
renderInterpretation(interpretation),
renderHeadInfo(headInfo),
renderDetail(details),
renderInfos(infos),
renderDescription(description)));
return (React.createElement("span", { ref: onMounted },
renderOperation(operator), content !== null && content !== void 0 ? content : DefaultContent));
};
return renderContent();
});
TooltipComponent.displayName = 'TooltipComponent';
//# sourceMappingURL=index.js.map