diff --git a/README.md b/README.md index 9f007f0..18b57d8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Highcharts Grid React -Monorepo containing React wrappers for [Highcharts Grid Lite](https://www.highcharts.com/docs/grid/getting-started/grid-lite) and [Highcharts Grid Pro](https://www.highcharts.com/docs/grid/getting-started/grid-pro). +Monorepo containing React packages for [Highcharts Grid Lite](https://www.highcharts.com/docs/grid/getting-started/grid-lite) and [Highcharts Grid Pro](https://www.highcharts.com/docs/grid/getting-started/grid-pro). ## Packages @@ -8,12 +8,12 @@ This monorepo contains the following packages: ### Published Packages -- **[@highcharts/grid-lite-react](./packages/grid-lite-react/)** - React wrapper for Highcharts Grid Lite -- **[@highcharts/grid-pro-react](./packages/grid-pro-react/)** - React wrapper for Highcharts Grid Pro +- **[@highcharts/grid-lite-react](./packages/grid-lite-react/)** - React package for Highcharts Grid Lite +- **[@highcharts/grid-pro-react](./packages/grid-pro-react/)** - React package for Highcharts Grid Pro ### Internal Packages -- **[@highcharts/grid-shared-react](./packages/grid-shared-react/)** - Shared core functionality used by both Grid Lite and Grid Pro React wrappers +- **[@highcharts/grid-shared-react](./packages/grid-shared-react/)** - Shared core functionality used by both Grid Lite and Grid Pro React packages ## Quick Start @@ -33,7 +33,7 @@ npm install @highcharts/grid-pro-react ```tsx import React, { useState } from 'react'; -import { GridLite, type GridOptions } from '@highcharts/grid-lite-react'; +import { Grid, type GridOptions } from '@highcharts/grid-lite-react'; function App() { const [options] = useState({ @@ -45,7 +45,7 @@ function App() { } }); - return ; + return ; } ``` @@ -53,7 +53,7 @@ function App() { ```tsx import React, { useState } from 'react'; -import { GridPro, type GridOptions } from '@highcharts/grid-pro-react'; +import { Grid, type GridOptions } from '@highcharts/grid-pro-react'; function App() { const [options] = useState({ @@ -65,7 +65,7 @@ function App() { } }); - return ; + return ; } ``` @@ -74,8 +74,8 @@ function App() { ``` highcharts-grid-react/ ├── packages/ # Source packages -│ ├── grid-lite-react/ # Grid Lite React wrapper -│ ├── grid-pro-react/ # Grid Pro React wrapper +│ ├── grid-lite-react/ # Grid Lite React package +│ ├── grid-pro-react/ # Grid Pro React package │ └── grid-shared-react/ # Shared core functionality ├── examples/ # Example applications │ ├── grid-lite/ # Grid Lite examples @@ -89,9 +89,9 @@ highcharts-grid-react/ ### Packages -- **`packages/grid-lite-react/`** - React component wrapper for Highcharts Grid Lite. See [README](./packages/grid-lite-react/README.md) for details. -- **`packages/grid-pro-react/`** - React component wrapper for Highcharts Grid Pro. See [README](./packages/grid-pro-react/README.md) for details. -- **`packages/grid-shared-react/`** - Internal package containing shared React components and hooks used by both wrappers. +- **`packages/grid-lite-react/`** - React component package for Highcharts Grid Lite. See [README](./packages/grid-lite-react/README.md) for details. +- **`packages/grid-pro-react/`** - React component package for Highcharts Grid Pro. See [README](./packages/grid-pro-react/README.md) for details. +- **`packages/grid-shared-react/`** - Internal package containing shared React components and hooks used by both packages. ### Examples @@ -171,8 +171,8 @@ import { type GridOptions } from '@highcharts/grid-lite-react'; import '@highcharts/grid-lite/css/grid-lite.css'; // Disable SSR for the Grid component -const GridLite = dynamic( - () => import('@highcharts/grid-lite-react').then((mod) => mod.GridLite), +const Grid = dynamic( + () => import('@highcharts/grid-lite-react').then((mod) => mod.Grid), { ssr: false } ); @@ -186,7 +186,7 @@ export default function Page() { } }); - return ; + return ; } ``` @@ -210,4 +210,3 @@ See the [Next.js examples](./examples/) for complete working implementations. ## License SEE LICENSE IN [LICENSE](https://github.com/highcharts/grid-react/blob/main/LICENSE). - diff --git a/examples/grid-lite/minimal-nextjs/app/page.tsx b/examples/grid-lite/minimal-nextjs/app/page.tsx index fb41d38..1d82cc4 100644 --- a/examples/grid-lite/minimal-nextjs/app/page.tsx +++ b/examples/grid-lite/minimal-nextjs/app/page.tsx @@ -8,9 +8,10 @@ import { type GridRefHandle } from '@highcharts/grid-lite-react'; -// Dynamically import Grid with SSR disabled to avoid window is not defined error -const GridLite = dynamic( - () => import('@highcharts/grid-lite-react').then((mod) => mod.GridLite), +// Dynamic import with ssr:false is required because @highcharts/grid-lite +// accesses `window` at module load time +const Grid = dynamic( + () => import('@highcharts/grid-lite-react').then((mod) => mod.Grid), { ssr: false } ); @@ -37,20 +38,19 @@ export default function Home() { } }); - const gridLite = useRef | null>(null); + const gridRef = useRef | null>(null); const onButtonClick = () => { - console.info('(ref) gridLite:', gridLite.current?.grid); + console.info('(ref) grid:', gridRef.current?.grid); }; - const onGridLiteCallback = (grid: GridInstance) => { - console.info('(callback) gridLite:', grid); + const onGridCallback = (grid: GridInstance) => { + console.info('(callback) grid:', grid); }; return ( <> - + ); } - diff --git a/examples/grid-lite/minimal-react/src/App.tsx b/examples/grid-lite/minimal-react/src/App.tsx index 064c523..9151ef7 100644 --- a/examples/grid-lite/minimal-react/src/App.tsx +++ b/examples/grid-lite/minimal-react/src/App.tsx @@ -3,7 +3,7 @@ import { type GridInstance, type GridOptions, type GridRefHandle, - GridLite + Grid } from '@highcharts/grid-lite-react'; function App() { @@ -31,19 +31,18 @@ function App() { const grid = useRef | null>(null); const onButtonClick = () => { - console.info('(ref) gridLite:', grid.current?.grid); + console.info('(ref) grid:', grid.current?.grid); }; - const onGridLiteCallback = (grid: GridInstance) => { - console.info('(callback) gridLite:', grid); + const onGridCallback = (grid: GridInstance) => { + console.info('(callback) grid:', grid); }; return ( <> - + ); } export default App; - diff --git a/examples/grid-pro/minimal-nextjs/app/page.tsx b/examples/grid-pro/minimal-nextjs/app/page.tsx index 06a5db4..0397a91 100644 --- a/examples/grid-pro/minimal-nextjs/app/page.tsx +++ b/examples/grid-pro/minimal-nextjs/app/page.tsx @@ -3,14 +3,15 @@ import { useState, useRef } from 'react'; import dynamic from 'next/dynamic'; import { - type GridInstance, - type GridOptions, - type GridRefHandle + type GridInstance, + type GridOptions, + type GridRefHandle } from '@highcharts/grid-pro-react'; -// Dynamically import Grid with SSR disabled to avoid window is not defined error -const GridPro = dynamic( - () => import('@highcharts/grid-pro-react').then((mod) => mod.GridPro), +// Dynamic import with ssr:false is required because @highcharts/grid-pro +// accesses `window` at module load time +const Grid = dynamic( + () => import('@highcharts/grid-pro-react').then((mod) => mod.Grid), { ssr: false } ); @@ -53,20 +54,19 @@ export default function Home() { }] }); - const gridPro = useRef | null>(null); + const gridRef = useRef | null>(null); const onButtonClick = () => { - console.info('(ref) gridPro:', gridPro.current?.grid); + console.info('(ref) grid:', gridRef.current?.grid); }; - const onGridProCallback = (grid: GridInstance) => { - console.info('(callback) gridPro:', grid); + const onGridCallback = (grid: GridInstance) => { + console.info('(callback) grid:', grid); }; return ( <> - + ); } - diff --git a/examples/grid-pro/minimal-react/src/App.tsx b/examples/grid-pro/minimal-react/src/App.tsx index 6f5b219..8abbbe0 100644 --- a/examples/grid-pro/minimal-react/src/App.tsx +++ b/examples/grid-pro/minimal-react/src/App.tsx @@ -3,7 +3,7 @@ import { type GridInstance, type GridOptions, type GridRefHandle, - GridPro, + Grid, } from '@highcharts/grid-pro-react'; function App() { @@ -47,19 +47,18 @@ function App() { const grid = useRef | null>(null); const onButtonClick = () => { - console.info('(ref) gridPro:', grid.current?.grid); + console.info('(ref) grid:', grid.current?.grid); }; - const onGridProCallback = (grid: GridInstance) => { - console.info('(callback) gridPro:', grid); + const onGridCallback = (grid: GridInstance) => { + console.info('(callback) grid:', grid); }; return ( <> - + ); } export default App; - diff --git a/package.json b/package.json index 83476ec..5d1eb21 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "scripts": { "test": "vitest run", "test:watch": "vitest", + "pretest:e2e": "pnpm build", "test:e2e": "vitest run --config vitest.e2e.config.ts", "test:all": "pnpm test && pnpm test:e2e", "check": "pnpm lint && pnpm test", diff --git a/packages/grid-lite-react/README.md b/packages/grid-lite-react/README.md index 977db12..2f8c259 100644 --- a/packages/grid-lite-react/README.md +++ b/packages/grid-lite-react/README.md @@ -16,7 +16,7 @@ npm install @highcharts/grid-lite-react ```tsx import React, { useState } from 'react'; -import { GridLite, type GridOptions } from '@highcharts/grid-lite-react'; +import { Grid, type GridOptions } from '@highcharts/grid-lite-react'; function App() { const [options] = useState({ @@ -32,20 +32,21 @@ function App() { } }); - return ; + return ; } ``` ## API -### `GridLite` +### `Grid` React component that wraps Highcharts Grid Lite. #### Props - `options` (required): Configuration options for the grid. Type: `GridOptions` -- `gridRef` (optional): Ref to access the underlying grid instance. Type: `RefObject>` +- `ref` (optional): React ref to access the underlying grid instance. Type: `RefObject>` +- `gridRef` (optional): Alternative prop-based ref. Type: `RefObject>` - `callback` (optional): Callback function called when the grid is initialized. Receives the grid instance as parameter. Type: `(grid: GridInstance) => void` ### `GridOptions` @@ -82,7 +83,7 @@ You can access the grid instance in two ways: **Using ref:** ```tsx import { useRef } from 'react'; -import { GridLite, type GridRefHandle, type GridOptions } from '@highcharts/grid-lite-react'; +import { Grid, type GridRefHandle, type GridOptions } from '@highcharts/grid-lite-react'; function App() { const gridRef = useRef | null>(null); @@ -97,7 +98,7 @@ function App() { return ( <> - + ); @@ -106,14 +107,14 @@ function App() { **Using callback:** ```tsx -import { GridLite, type GridInstance, type GridOptions } from '@highcharts/grid-lite-react'; +import { Grid, type GridInstance, type GridOptions } from '@highcharts/grid-lite-react'; function App() { const handleGridReady = (grid: GridInstance) => { console.log('Grid initialized:', grid); }; - return ; + return ; } ``` @@ -130,8 +131,8 @@ import { type GridOptions } from '@highcharts/grid-lite-react'; import '@highcharts/grid-lite/css/grid-lite.css'; // Disable SSR for the Grid component -const GridLite = dynamic( - () => import('@highcharts/grid-lite-react').then((mod) => mod.GridLite), +const Grid = dynamic( + () => import('@highcharts/grid-lite-react').then((mod) => mod.Grid), { ssr: false } ); @@ -145,7 +146,7 @@ export default function Page() { } }); - return ; + return ; } ``` @@ -158,4 +159,3 @@ For detailed documentation on available options and features, see the [Highchart ## License SEE LICENSE IN [LICENSE](https://github.com/highcharts/grid-react/blob/main/packages/grid-lite-react/LICENSE). - diff --git a/packages/grid-lite-react/src/__tests__/Grid.test.tsx b/packages/grid-lite-react/src/__tests__/Grid.test.tsx index 0d0caad..770322a 100644 --- a/packages/grid-lite-react/src/__tests__/Grid.test.tsx +++ b/packages/grid-lite-react/src/__tests__/Grid.test.tsx @@ -1,9 +1,9 @@ import { createGridTests } from '@highcharts/grid-shared-react/src/test/createGridTests'; -import { GridLite, GridOptions } from '../index'; +import { Grid, GridOptions } from '../index'; createGridTests( - 'GridLite', - GridLite, + 'Grid Lite', + Grid, { dataTable: { columns: { diff --git a/packages/grid-lite-react/src/index.ts b/packages/grid-lite-react/src/index.ts index a1a1520..93cb0e5 100644 --- a/packages/grid-lite-react/src/index.ts +++ b/packages/grid-lite-react/src/index.ts @@ -9,6 +9,7 @@ import GridLite from '@highcharts/grid-lite'; +export { default as Grid } from './Grid'; export { default as GridLite } from './Grid'; export type { GridInstance } from '@highcharts/grid-shared-react'; export type { GridRefHandle } from '@highcharts/grid-shared-react'; diff --git a/packages/grid-pro-react/README.md b/packages/grid-pro-react/README.md index 2e858de..6afa19d 100644 --- a/packages/grid-pro-react/README.md +++ b/packages/grid-pro-react/README.md @@ -16,7 +16,7 @@ npm install @highcharts/grid-pro-react ```tsx import React, { useState } from 'react'; -import { GridPro, type GridOptions } from '@highcharts/grid-pro-react'; +import { Grid, type GridOptions } from '@highcharts/grid-pro-react'; function App() { const [options] = useState({ @@ -32,20 +32,21 @@ function App() { } }); - return ; + return ; } ``` ## API -### `GridPro` +### `Grid` React component that wraps Highcharts Grid Pro. #### Props - `options` (required): Configuration options for the grid. Type: `GridOptions` -- `gridRef` (optional): Ref to access the underlying grid instance. Type: `RefObject>` +- `ref` (optional): React ref to access the underlying grid instance. Type: `RefObject>` +- `gridRef` (optional): Alternative prop-based ref. Type: `RefObject>` - `callback` (optional): Callback function called when the grid is initialized. Receives the grid instance as parameter. Type: `(grid: GridInstance) => void` ### `GridOptions` @@ -82,7 +83,7 @@ You can access the grid instance in two ways: **Using ref:** ```tsx import { useRef } from 'react'; -import { GridPro, type GridRefHandle, type GridOptions } from '@highcharts/grid-pro-react'; +import { Grid, type GridRefHandle, type GridOptions } from '@highcharts/grid-pro-react'; function App() { const gridRef = useRef | null>(null); @@ -97,7 +98,7 @@ function App() { return ( <> - + ); @@ -106,14 +107,14 @@ function App() { **Using callback:** ```tsx -import { GridPro, type GridInstance, type GridOptions } from '@highcharts/grid-pro-react'; +import { Grid, type GridInstance, type GridOptions } from '@highcharts/grid-pro-react'; function App() { const handleGridReady = (grid: GridInstance) => { console.log('Grid initialized:', grid); }; - return ; + return ; } ``` @@ -130,8 +131,8 @@ import { type GridOptions } from '@highcharts/grid-pro-react'; import '@highcharts/grid-pro/css/grid-pro.css'; // Disable SSR for the Grid component -const GridPro = dynamic( - () => import('@highcharts/grid-pro-react').then((mod) => mod.GridPro), +const Grid = dynamic( + () => import('@highcharts/grid-pro-react').then((mod) => mod.Grid), { ssr: false } ); @@ -145,7 +146,7 @@ export default function Page() { } }); - return ; + return ; } ``` diff --git a/packages/grid-pro-react/src/__tests__/Grid.test.tsx b/packages/grid-pro-react/src/__tests__/Grid.test.tsx index 5d72560..e44d6d9 100644 --- a/packages/grid-pro-react/src/__tests__/Grid.test.tsx +++ b/packages/grid-pro-react/src/__tests__/Grid.test.tsx @@ -1,9 +1,9 @@ import { createGridTests } from '@highcharts/grid-shared-react/src/test/createGridTests'; -import { GridPro, GridOptions } from '../index'; +import { Grid, GridOptions } from '../index'; createGridTests( - 'GridPro', - GridPro, + 'Grid Pro', + Grid, { dataTable: { columns: { diff --git a/packages/grid-pro-react/src/index.ts b/packages/grid-pro-react/src/index.ts index 25207fa..a44be66 100644 --- a/packages/grid-pro-react/src/index.ts +++ b/packages/grid-pro-react/src/index.ts @@ -9,6 +9,7 @@ import GridPro from '@highcharts/grid-pro'; +export { default as Grid } from './Grid'; export { default as GridPro } from './Grid'; export type { GridInstance } from '@highcharts/grid-shared-react'; export type { GridRefHandle } from '@highcharts/grid-shared-react'; diff --git a/packages/grid-shared-react/src/test/createGridTests.tsx b/packages/grid-shared-react/src/test/createGridTests.tsx index 5492516..1faed12 100644 --- a/packages/grid-shared-react/src/test/createGridTests.tsx +++ b/packages/grid-shared-react/src/test/createGridTests.tsx @@ -1,22 +1,18 @@ import { render, waitFor, fireEvent } from '@testing-library/react'; -import { useRef, useState, ComponentType } from 'react'; +import { + useRef, + useState, + type ComponentType +} from 'react'; import { describe, it, expect, vi } from 'vitest'; import { GridProps, GridRefHandle } from '../components/BaseGrid'; import { GridInstance } from '../hooks/useGrid'; -type CellValue = string | number | boolean | null; - -interface TestOptions { - dataTable?: { - columns?: Record; - }; -} - /** * Creates a standard test suite for a Grid component. * Use this to avoid duplicating tests between grid-lite-react and grid-pro-react. */ -export function createGridTests( +export function createGridTests( name: string, GridComponent: ComponentType>, testOptions: TOptions, @@ -42,7 +38,7 @@ export function createGridTests( }); }); - it('provides grid instance via ref', async () => { + it('provides grid instance via gridRef prop', async () => { let gridRef: React.RefObject | null>; let initialized = false;