@extend-ai/react-xlsx 0.10.3 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -407,12 +407,61 @@ Common rendering props:
407
407
  - `loadingState?: React.ReactNode`
408
408
  - `errorState?: React.ReactNode | ((error: Error) => React.ReactNode)`
409
409
  - `fileTooLargeState?: React.ReactNode | ((props: XlsxFileTooLargeRenderProps) => React.ReactNode)`
410
+ - `getCellStyle?: (context: XlsxCellStyleContext) => React.CSSProperties | null | undefined`
410
411
  - `renderImage?: (props: XlsxImageRenderProps) => React.ReactNode`
411
412
  - `renderImageSelection?: (props: XlsxImageSelectionRenderProps) => React.ReactNode`
412
413
  - `renderChartLoading?: (props: XlsxChartLoadingRenderProps) => React.ReactNode`
413
414
  - `renderTableHeaderMenu?: (props: XlsxTableHeaderMenuRenderProps) => React.ReactNode`
414
415
  - `renderScroller?: (props: XlsxScrollerRenderProps) => React.ReactNode`
415
416
 
417
+ ### Custom Cell Styling
418
+
419
+ `getCellStyle` is an escape hatch for styling individual cells without forking the workbook data. It is called for every rendered cell and returns a partial `React.CSSProperties` that merges on top of the viewer's resolved style. Return `undefined` (or `null`) to leave a cell untouched.
420
+
421
+ ```tsx
422
+ import { XlsxViewer, type XlsxViewerProps } from "@extend-ai/react-xlsx";
423
+
424
+ function Workbook({ buffer, highlighted }: { buffer: ArrayBuffer; highlighted: Set<string> }) {
425
+ const getCellStyle = React.useCallback<NonNullable<XlsxViewerProps["getCellStyle"]>>(
426
+ ({ cell, isTableHeader }) => {
427
+ if (isTableHeader) {
428
+ return undefined;
429
+ }
430
+ if (highlighted.has(`${cell.row}:${cell.col}`)) {
431
+ return { backgroundColor: "rgba(37, 99, 235, 0.12)", outline: "1px solid #2563eb" };
432
+ }
433
+ return undefined;
434
+ },
435
+ [highlighted]
436
+ );
437
+
438
+ return <XlsxViewer file={buffer} getCellStyle={getCellStyle} />;
439
+ }
440
+ ```
441
+
442
+ The `context` passed to `getCellStyle` is an `XlsxCellStyleContext`:
443
+
444
+ | Field | Type | Notes |
445
+ | --- | --- | --- |
446
+ | `cell` | `XlsxCellAddress` | Address of the cell being styled. |
447
+ | `workbookSheetIndex` | `number` | Workbook sheet index of the cell's sheet. |
448
+ | `sheetName` | `string` | Display name of the cell's sheet. |
449
+ | `resolvedStyle` | `React.CSSProperties` | The style the viewer computed (workbook formatting + built-ins). Read-only. |
450
+ | `value` | `string` | The cell's resolved display value. |
451
+ | `hasValidation` | `boolean` | Cell has a data validation rule. |
452
+ | `hasHyperlink` | `boolean` | Cell has a hyperlink. |
453
+ | `hasConditionalFormat` | `boolean` | Cell is affected by a color scale, data bar, or icon set. |
454
+ | `hasChartHighlight` | `boolean` | Cell is in a selected chart's highlighted source range. |
455
+ | `isMerged` | `boolean` | Cell is the anchor of a merged range. |
456
+ | `isTableHeader` | `boolean` | Cell is a table header cell. |
457
+
458
+ Notes:
459
+
460
+ - Keep the callback stable (e.g. `useCallback`) so cell styling is not recomputed every render. When the callback identity changes, the viewer re-resolves and repaints cells.
461
+ - The DOM renderer (`experimentalCanvas={false}`) applies every returned CSS property.
462
+ - The canvas renderer (the default) honors the subset it can paint: `backgroundColor`, `backgroundImage` gradients, `color`, the four `border*` sides, `padding`, `textAlign`, `textDecoration`, `textOverflow`, and font properties. CSS-only effects such as `boxShadow`, `outline`, or `animation` apply in the DOM renderer.
463
+ - `getCellStyle` is not applied to worksheet thumbnails painted via `useXlsxViewerThumbnails(...)`.
464
+
416
465
  ### Custom Scroll Area
417
466
 
418
467
  By default, the viewer renders its native scroll viewport with the browser scrollbar. To use a custom scroll area, provide `renderScroller` and spread `viewportProps` onto the actual scrollable viewport element:
@@ -478,6 +527,7 @@ The package exports the main types you are likely to use for custom integrations
478
527
  - `XlsxViewerCharts`
479
528
  - `XlsxViewerThumbnails`
480
529
  - `XlsxScrollerRenderProps`
530
+ - `XlsxCellStyleContext`
481
531
  - `XlsxSheetThumbnail`
482
532
  - `UseXlsxViewerThumbnailsOptions`
483
533
  - `XlsxChart`, `XlsxChartSeries`, `XlsxChartAxis`, `XlsxChartsheet`