@native-html/table-plugin
Version:
🔠A WebView-based plugin to render tables in react-native-render-html
57 lines (56 loc) • 2.08 kB
JavaScript
import { Dimensions } from 'react-native';
import { useSharedProps, useDocumentMetadata, useRendererProps, useContentWidth } from 'react-native-render-html';
import extractHtmlAndStatsFromTableDomNode from './extractHtmlAndStatsFromTableDomNode';
/**
* Extract props for the HTMLTable component from renderer function arguments.
* This function is especially usefull for custom table renderers.
*
* @param props - The props of a custom block renderer.
* @param tableConfig - Override config options.
*
* @public
*/
export default function useHtmlTableProps({
style,
tnode
}, tableConfig) {
const {
WebView,
defaultWebViewProps,
computeEmbeddedMaxWidth
} = useSharedProps();
const contentWidth = useContentWidth();
const globalTableConfig = useRendererProps('table');
const {
onPress: onLinkPress
} = useRendererProps('a');
const resolvedConfig = { ...globalTableConfig,
...tableConfig,
webViewProps: { ...defaultWebViewProps,
...(globalTableConfig === null || globalTableConfig === void 0 ? void 0 : globalTableConfig.webViewProps),
...(tableConfig === null || tableConfig === void 0 ? void 0 : tableConfig.webViewProps)
}
};
const resolvedContentWidth = typeof contentWidth === 'number' ? contentWidth : Dimensions.get('window').width;
const documentBaseUrl = useDocumentMetadata().baseUrl;
const availableWidth = (computeEmbeddedMaxWidth === null || computeEmbeddedMaxWidth === void 0 ? void 0 : computeEmbeddedMaxWidth.call(null, resolvedContentWidth, 'table')) || resolvedContentWidth;
const {
html,
stats
} = extractHtmlAndStatsFromTableDomNode(tnode.domNode);
const displayMode = resolvedConfig.displayMode || 'normal';
const composedStyles = [style, displayMode === 'expand' ? {
width: availableWidth
} : displayMode === 'embedded' ? {
maxWidth: availableWidth
} : null];
return { ...resolvedConfig,
...stats,
html,
sourceBaseUrl: documentBaseUrl,
style: composedStyles,
onLinkPress,
WebView
};
}
//# sourceMappingURL=useHtmlTableProps.js.map