UNPKG

@native-html/heuristic-table-plugin

Version:

🔠 A 100% native component using heuristics to render tables in react-native-render-html

61 lines (57 loc) • 1.82 kB
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } import React, { memo } from 'react'; import { ScrollView, View } from 'react-native'; import TreeRenderer from './TreeRenderer'; import { getHorizontalSpacing } from './helpers/measure'; function Container({ children, tableWidth, availableWidth }) { const scroll = tableWidth > availableWidth; return /*#__PURE__*/React.createElement(scroll ? ScrollView : View, scroll ? { contentContainerStyle: { width: tableWidth }, style: { width: availableWidth }, horizontal: true } : { style: { width: tableWidth } }, children); } /** * A component to render tables. * * @param props - Props from {@link useHtmlTableProps} hook. * * @public */ const HTMLTable = /*#__PURE__*/memo(function HTMLTable({ layout, TDefaultRenderer, settings, config, ...props }) { const tableWidth = layout.totalWidth; const containerWidth = settings.contentWidth; return /*#__PURE__*/React.createElement(TDefaultRenderer, _extends({}, props, { style: { ...props.style, width: Math.min(tableWidth + getHorizontalSpacing(props.tnode.styles.nativeBlockRet), containerWidth) } }), /*#__PURE__*/React.createElement(Container, { tableWidth: tableWidth, availableWidth: containerWidth }, /*#__PURE__*/React.createElement(TreeRenderer, { node: layout.renderTree, config, renderIndex: props.renderIndex, renderLength: props.renderLength }))); }); export default HTMLTable; //# sourceMappingURL=HTMLTable.js.map