Skip to content

Commit 1526efe

Browse files
committed
feat(table-plugin): support react-native-render-html 6.x
BREAKING CHANGE: - `extractHtmlTableProps` has been dropped in favor of `useHtmlTableProps` hook for reusability. - `IGNORED_TAGS` is not exported anymore, and not necessary. - requires `react-native` 0.63.x and above - new `tableModel` export for the new custom renderers API
1 parent 2ef3c3d commit 1526efe

19 files changed

+178
-251
lines changed

packages/table-plugin/README.md

Lines changed: 33 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
> **:warning: as of version 1.0.0, this package name has been changed from
2-
> `react-native-render-html-table-bridge` to `@native-html/table-plugin`**. To
3-
> migrate, you must add the new package in your project and change imports.
4-
> Also, [check all breaking changes here](https://github.com/native-html/table-plugin/blob/master/packages/table-plugin/CHANGELOG.md#100-2020-08-19).
1+
> :warning: This documentation is for **react-native-render-html v6**. For v5 and below, [go here](https://github.com/native-html/plugins/tree/rnrh/5.x/packages/table-plugin#readme).
52
63
<h1 align="center">@native-html/table-plugin</h1>
74

@@ -89,26 +86,22 @@ yarn add @native-html/table-plugin
8986
| ------------------------ | -------------------------------------------------------------------------------------------------------- |
9087
| ≥ 4.2.1 &lt; 5.0.0 | 2.x ([documentation](https://github.com/native-html/plugins/tree/rnrh/4.x#readme)) |
9188
| ≥ 5.0.0 &lt; 6.0.0 | 3.x ([documentation](https://github.com/native-html/plugins/tree/rnrh/5.x/packages/table-plugin#readme)) |
92-
| ≥ 6.0.0 | 4.x (_in development_) |
89+
| ≥ 6.0.0 | 4.x ([documentation](https://github.com/native-html/plugins/tree/rnrh/6.x/packages/table-plugin#readme)) |
9390

9491
## Minimal working example
9592

9693
_[Full example](https://github.com/native-html/plugins/blob/master/example/SimpleExample.js)_
9794

98-
> :warning: The API has changed as of table-plugin@3 /
99-
> react-native-render-html@5. If you need to pass config options to the
100-
> `HTMLTable` component, assign this config to `renderersProps.table` prop.
101-
10295
You need 2 steps to get to a working example:
10396

10497
1. Import the `WebView` component. [Instructions will differ depending on your setup](#errors-when-importing-webview-component);
105-
2. Inject `ignoredTags`, `renderers` and `WebView` props to the `HTML` component;
98+
2. Inject `renderers` and `WebView` props to the `HTML` component;
10699

107100
```javascript
108101
import React from 'react';
109102
import { ScrollView } from 'react-native';
110103
import HTML from 'react-native-render-html';
111-
import table, { IGNORED_TAGS } from '@native-html/table-plugin';
104+
import TableRenderer from '@native-html/table-plugin';
112105
import WebView from 'react-native-webview';
113106

114107
const html = `
@@ -127,13 +120,11 @@ const html = `
127120
const htmlProps = {
128121
WebView,
129122
renderers: {
130-
table
123+
table: TableRenderer
131124
},
132-
ignoredTags: IGNORED_TAGS,
133125
renderersProps: {
134126
table: {
135-
// Put the table config here (previously,
136-
// the first argument of makeTableRenderer)
127+
// Put the table config here
137128
}
138129
}
139130
};
@@ -152,16 +143,14 @@ Most notably, check [`TableConfig`](https://github.com/native-html/plugins/blob/
152143

153144
**Landmark exports**:
154145

155-
- [`table`](https://github.com/native-html/plugins/blob/master/packages/table-plugin/docs/table-plugin.table.md)
156-
- [`extractHtmlTableProps`](https://github.com/native-html/plugins/blob/master/packages/table-plugin/docs/table-plugin.extracthtmltableprops.md)
157-
- [`IGNORED_TAGS`](https://github.com/native-html/plugins/blob/master/packages/table-plugin/docs/table-plugin.ignored_tags.md)
146+
- [`TableRenderer(default)`](https://github.com/native-html/plugins/blob/master/packages/table-plugin/docs/table-plugin.tablerenderer.md)
147+
- [`useHtmlTableProps`](https://github.com/native-html/plugins/blob/master/packages/table-plugin/docs/table-plugin.usehtmltableprops.md)
158148

159149
Other exports:
160150

161151
- [`HTMLTable`](https://github.com/native-html/plugins/blob/master/packages/table-plugin/docs/table-plugin.htmltable.md)
162152
- [`defaultTableStylesSpecs`](https://github.com/native-html/plugins/blob/master/packages/table-plugin/docs/table-plugin.defaulttablestylesspecs.md)
163153
- [`cssRulesFromSpecs`](https://github.com/native-html/plugins/blob/master/packages/table-plugin/docs/table-plugin.cssrulesfromspecs.md)
164-
- [`TABLE_TAGS`](https://github.com/native-html/plugins/blob/master/packages/table-plugin/docs/table-plugin.table_tags.md)
165154

166155
## Troubleshooting
167156

@@ -188,21 +177,19 @@ so you are not required to pass every field. See
188177
[documentation](https://github.com/native-html/plugins/blob/master/packages/table-plugin/docs/table-plugin.tablestylespecs.md).
189178

190179
```javascript
191-
import table {
180+
import TableRenderer {
192181
defaultTableStylesSpecs,
193182
cssRulesFromSpecs
194183
} from '@native-html/table-plugin';
195184

196-
const tableConfig = {
197-
tableStyleSpecs: {
198-
// my style specs
199-
}
200-
}
201-
202185
const htmlProps = {
203-
renderers: { table },
186+
renderers: { table: TableRenderer },
204187
renderersProps: {
205-
table: tableConfig
188+
table: {
189+
tableStyleSpecs: {
190+
// my style specs
191+
}
192+
}
206193
}
207194
};
208195
```
@@ -212,21 +199,19 @@ const htmlProps = {
212199
Pass `computeContainerHeight` option with a function returning `null`:
213200

214201
```javascript
215-
import table {
202+
import TableRenderer {
216203
defaultTableStylesSpecs,
217204
cssRulesFromSpecs
218205
} from '@native-html/table-plugin';
219206

220-
const tableConfig = {
221-
computeContainerHeight() {
222-
return null;
223-
}
224-
}
225-
226207
const htmlProps = {
227-
renderers: { table },
208+
renderers: { table: TableRenderer },
228209
renderersProps: {
229-
table: tableConfig
210+
table: {
211+
computeContainerHeight() {
212+
return null;
213+
}
214+
}
230215
}
231216
};
232217

@@ -239,7 +224,7 @@ const htmlProps = {
239224
**A**: Use `cssRulesFromSpecs` function and override `cssRules` config.
240225

241226
```javascript
242-
import table {
227+
import TableRenderer {
243228
defaultTableStylesSpecs,
244229
cssRulesFromSpecs
245230
} from '@native-html/table-plugin';
@@ -257,17 +242,19 @@ const tableConfig = {
257242
}
258243

259244
const htmlProps = {
260-
renderers: { table },
245+
renderers: { table: TableRenderer },
261246
renderersProps: {
262-
table: tableConfig
247+
table: {
248+
cssRules
249+
}
263250
}
264251
};
265252

266253
```
267254

268255
### How to customize the Table component?
269256

270-
**A**: Use `extractHtmlTableProps` function. [See custom example](https://github.com/native-html/plugins/blob/master/example/CustomExample.js).
257+
**A**: See `useHtmlTableProps` hook. [See custom example](https://github.com/native-html/plugins/blob/master/example/CustomExample.js).
271258

272259
<img src="https://github.com/native-html/table-plugin/raw/master/images/adaptative.jpeg" width="300">
273260

@@ -276,7 +263,7 @@ const htmlProps = {
276263
**A**: Extend styles and add `@font-face` rules.
277264

278265
```javascript
279-
import {
266+
import TableRenderer, {
280267
defaultTableStylesSpecs,
281268
cssRulesFromSpecs
282269
} from '@native-html/table-plugin';
@@ -309,14 +296,12 @@ const cssRules =
309296
}
310297
`;
311298

312-
const tableConfig = {
313-
cssRules
314-
};
315-
316299
const htmlProps = {
317-
renderers: { table },
300+
renderers: { table: TableRenderer },
318301
renderersProps: {
319-
table: tableConfig
302+
table: {
303+
cssRules
304+
}
320305
}
321306
};
322307
```

packages/table-plugin/docs/table-plugin.extracthtmltableprops.md

Lines changed: 0 additions & 29 deletions
This file was deleted.

packages/table-plugin/docs/table-plugin.htmltablebaseprops.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ export interface HTMLTableBaseProps extends HTMLTableStats
1919
| --- | --- | --- |
2020
| [html](./table-plugin.htmltablebaseprops.html.md) | string | The outerHtml of <table> tag. |
2121
| [htmlAttribs?](./table-plugin.htmltablebaseprops.htmlattribs.md) | HtmlAttributesDictionary | <i>(Optional)</i> Html attributes for this table node. |
22-
| [onLinkPress?](./table-plugin.htmltablebaseprops.onlinkpress.md) | ContainerProps\['onLinkPress'\] | <i>(Optional)</i> Intercept links press. |
22+
| [onLinkPress?](./table-plugin.htmltablebaseprops.onlinkpress.md) | RenderHTMLPassedProps\['onLinkPress'\] | <i>(Optional)</i> Intercept links press. |
2323
| [WebView](./table-plugin.htmltablebaseprops.webview.md) | ComponentType&lt;any&gt; | The <code>WebView</code> Component you wish to use. |
2424

packages/table-plugin/docs/table-plugin.htmltablebaseprops.onlinkpress.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ Intercept links press.
99
<b>Signature:</b>
1010

1111
```typescript
12-
onLinkPress?: ContainerProps['onLinkPress'];
12+
onLinkPress?: RenderHTMLPassedProps['onLinkPress'];
1313
```

packages/table-plugin/docs/table-plugin.ignored_tags.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

packages/table-plugin/docs/table-plugin.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
| Function | Description |
1010
| --- | --- |
1111
| [cssRulesFromSpecs(specs)](./table-plugin.cssrulesfromspecs.md) | Create css rules from a specification object. |
12-
| [extractHtmlTableProps(htmlAttribs, convertedCSSStyles, passProps, tableConfig)](./table-plugin.extracthtmltableprops.md) | Extract props for the HTMLTable component from renderer function arguments. This function is especially usefull for custom table renderers. |
12+
| [useHtmlTableProps({ key, style, tnode }, tableConfig)](./table-plugin.usehtmltableprops.md) | Extract props for the HTMLTable component from renderer function arguments. This function is especially usefull for custom table renderers. |
1313

1414
## Interfaces
1515

@@ -29,9 +29,7 @@
2929
| --- | --- |
3030
| [defaultTableStylesSpecs](./table-plugin.defaulttablestylesspecs.md) | Default styles attributes.<img src="https://raw.githubusercontent.com/native-html/table-plugin/master/images/TableStyleSpecs.png" /> |
3131
| [HTMLTable](./table-plugin.htmltable.md) | A component capable of rendering a html string which root tag is a table tag. This component should not be used directly, except with custom renderers. |
32-
| [IGNORED\_TAGS](./table-plugin.ignored_tags.md) | A new list of tags to ignore, which exclude [TABLE\_TAGS](./table-plugin.table_tags.md)<!-- -->. |
33-
| [TABLE\_TAGS](./table-plugin.table_tags.md) | All HTML tags associated with a table element. |
34-
| [table](./table-plugin.table.md) | The renderer function for the iframe element. This renderer is fully scalable, and will adjust to <code>contentWidth</code> and <code>computeEmbeddedMaxWidth</code>. It also features <code>onLinkPress</code>. |
32+
| [TableRenderer](./table-plugin.tablerenderer.md) | The renderer component for the table element. This renderer is fully scalable, and will adjust to <code>contentWidth</code> and <code>computeEmbeddedMaxWidth</code>. It also features <code>onLinkPress</code>. |
3533

3634
## Type Aliases
3735

packages/table-plugin/docs/table-plugin.table_tags.md

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
22

3-
[Home](./index.md) &gt; [@native-html/table-plugin](./table-plugin.md) &gt; [table](./table-plugin.table.md)
3+
[Home](./index.md) &gt; [@native-html/table-plugin](./table-plugin.md) &gt; [TableRenderer](./table-plugin.tablerenderer.md)
44

5-
## table variable
5+
## TableRenderer variable
66

7-
The renderer function for the iframe element. This renderer is fully scalable, and will adjust to `contentWidth` and `computeEmbeddedMaxWidth`<!-- -->. It also features `onLinkPress`<!-- -->.
7+
The renderer component for the table element. This renderer is fully scalable, and will adjust to `contentWidth` and `computeEmbeddedMaxWidth`<!-- -->. It also features `onLinkPress`<!-- -->.
88

99
<b>Signature:</b>
1010

1111
```typescript
12-
table: RendererFunction<any>
12+
TableRenderer: CustomBlockRenderer
1313
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@native-html/table-plugin](./table-plugin.md) &gt; [useHtmlTableProps](./table-plugin.usehtmltableprops.md)
4+
5+
## useHtmlTableProps() function
6+
7+
Extract props for the HTMLTable component from renderer function arguments. This function is especially usefull for custom table renderers.
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
export default function useHtmlTableProps({ key, style, tnode }: CustomTagRendererProps<TBlock>, tableConfig?: TableConfig): HTMLTableProps & {
13+
key?: string | number;
14+
};
15+
```
16+
17+
## Parameters
18+
19+
| Parameter | Type | Description |
20+
| --- | --- | --- |
21+
| { key, style, tnode } | CustomTagRendererProps&lt;TBlock&gt; | |
22+
| tableConfig | [TableConfig](./table-plugin.tableconfig.md) | Override config options. |
23+
24+
<b>Returns:</b>
25+
26+
[HTMLTableProps](./table-plugin.htmltableprops.md) &amp; { key?: string \| number; }
27+

0 commit comments

Comments
 (0)