Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import globals from 'globals';

export default defineConfig(
{
ignores: ['**/dist/**', '**/build/**'],
ignores: [
'**/dist/**',
'**/build/**',
'**/.next/**',
'**/node_modules/**'
],
},
eslint.configs.recommended,
tseslint.configs.recommended,
Expand Down Expand Up @@ -34,7 +39,7 @@ export default defineConfig(
},
},
{
files: ['scripts/**/*.js'],
files: ['scripts/**/*.js', '**/next.config.js'],
languageOptions: {
globals: {
...globals.node,
Expand Down
11 changes: 7 additions & 4 deletions examples/grid-lite/components-react/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { useState, useRef } from 'react';
import {
useState,
// useRef
} from 'react';
import {
type GridInstance,
type GridRefHandle,
// type GridRefHandle,
type GridOptions,
Grid,
Caption,
Data,
DataTable,
// DataTable,
ColumnDefaults,
Column,
Description,
Expand All @@ -15,7 +18,7 @@ import {
} from '@highcharts/grid-lite-react';

function App() {
const grid = useRef<GridRefHandle<GridOptions> | null>(null);
// const grid = useRef<GridRefHandle<GridOptions> | null>(null);

// ==== OPTIONS ====
// const [options] = useState<GridOptions>({
Expand Down
8 changes: 6 additions & 2 deletions examples/grid-lite/minimal-nextjs/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ export default function Home() {
};

return (
<>
<Grid options={liteOptions} gridRef={gridRef} callback={onGridCallback} />
<>
<Grid
options={liteOptions}
gridRef={gridRef}
callback={onGridCallback}
/>
<button onClick={onButtonClick}>Click me</button>
</>
);
Expand Down
12 changes: 12 additions & 0 deletions examples/grid-pro/components-react/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Highcharts Grid Pro - React Example</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
25 changes: 25 additions & 0 deletions examples/grid-pro/components-react/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "grid-pro-components-react",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
"clean": "rimraf dist node_modules"
},
"dependencies": {
"@highcharts/grid-pro": ">=3.0.0",
"@highcharts/grid-pro-react": "workspace:*",
"react": ">=18",
"react-dom": ">=18"
},
"devDependencies": {
"@types/react": ">=18",
"@types/react-dom": ">=18",
"@vitejs/plugin-react": "^4.2.0",
"typescript": "^5.0.0",
"vite": "^5.0.0"
}
}
98 changes: 98 additions & 0 deletions examples/grid-pro/components-react/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { useState } from 'react';
import {
type GridInstance,
type GridOptions,
Grid,
Caption,
Data,
ColumnDefaults,
Column,
Description,
Pagination
} from '@highcharts/grid-pro-react';

const GRID_KEY = 'AAAA-BBBB-CCCC-DDDD-EEEE-FFFF';

function App() {
const [dataSource, setDataSource] = useState({
name: ['Alice', 'Bob', 'Charlie', 'David', 'Eve'],
age: [23, 34, 45, 56, 67],
city: ['New York', 'Oslo', 'Paris', 'Tokyo', 'London'],
salary: [50000, 60000, 70000, 80000, 90000]
});

const onButtonClick = () => {
setDataSource({
name: ['John', 'Jane', 'Jim', 'Jill', 'Jack'],
age: [30, 25, 35, 40, 45],
city: ['New York', 'Los Angeles', 'Chicago', 'Houston', 'Miami'],
salary: [40000, 35000, 45000, 50000, 55000]
});
};

const onGridCallback = (grid: GridInstance<GridOptions>) => {
console.info('(callback) grid:', grid);
};

return (
<>
<Grid
gridKey={GRID_KEY}
callback={onGridCallback}
onAfterLoad={function () {
console.info('Grid loaded');
}}
>
<Data columns={dataSource} />
<ColumnDefaults
dataType="string"
sortingEnabled
filteringEnabled
/>
<Caption>Grid Pro Components</Caption>
<Description>Declarative API with gridKey and event props</Description>
<Column
columnId="name"
headerFormat="Name"
onAfterSort={function () {
console.info('Sorted name column');
}}
onCellClick={function () {
console.info('Clicked name cell', this);
}}
onHeaderClick={function () {
console.info('Clicked name header', this);
}}
/>
<Column
columnId="age"
dataType="number"
headerFormat="Age"
/>
<Column
columnId="city"
headerFormat="City"
/>
<Column
columnId="salary"
dataType="number"
headerFormat="Salary (USD)"
cellFormat="${value}"
/>
<Pagination
page={1}
pageSize={3}
pageSizeOptions={[3, 5, 10]}
onBeforePageChange={function (event) {
console.info('Before page change', event);
}}
/>
</Grid>
<div id="controls">
<button onClick={onButtonClick}>Update data</button>
</div>
</>
);
}

export default App;
26 changes: 26 additions & 0 deletions examples/grid-pro/components-react/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

#root {
width: 100%;
min-height: 100vh;
padding: 20px;
}

#controls {
margin-top: 20px;
display: flex;
gap: 10px;
}

@media (prefers-color-scheme: dark) {
body {
background-color: #121212;
color: #ffffff;
}
}
10 changes: 10 additions & 0 deletions examples/grid-pro/components-react/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import './index.css';

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>
);
27 changes: 27 additions & 0 deletions examples/grid-pro/components-react/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"target": "ES2020",
"lib": [
"DOM",
"ES2016",
"ES2017.Object"
],
"jsx": "react-jsx",
"module": "ES6",
"moduleResolution": "node",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitThis": true,
"noFallthroughCasesInSwitch": true,
"skipDefaultLibCheck": true,
"skipLibCheck": true,
"ignoreDeprecations": "5.0",
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
11 changes: 11 additions & 0 deletions examples/grid-pro/components-react/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true,
"types": ["node"]
},
"include": ["vite.config.ts"]
}
29 changes: 29 additions & 0 deletions examples/grid-pro/components-react/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';

const __dirname = dirname(fileURLToPath(import.meta.url));

export default defineConfig({
plugins: [react()],
resolve: {
alias: [
{
find: '@highcharts/grid-pro-react',
replacement: resolve(__dirname, '../../../packages/grid-pro-react/src/index.ts')
},
{
find: '@highcharts/grid-shared-react',
replacement: resolve(__dirname, '../../../packages/grid-shared-react/src/index.ts')
},
{
find: /^@highcharts\/grid-pro(\/.*)?$/,
replacement: resolve(__dirname, 'node_modules/@highcharts/grid-pro$1')
}
]
},
server: {
port: 3002
}
});
7 changes: 6 additions & 1 deletion examples/grid-pro/minimal-nextjs/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ export default function Home() {

return (
<>
<Grid options={proOptions} gridRef={gridRef} callback={onGridCallback} />
<Grid
gridKey="AAAA-BBBB-CCCC-DDDD-EEEE-FFFF"
options={proOptions}
gridRef={gridRef}
callback={onGridCallback}
/>
<button onClick={onButtonClick}>Click me</button>
</>
);
Expand Down
7 changes: 6 additions & 1 deletion examples/grid-pro/minimal-react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ function App() {

return (
<>
<Grid options={options} gridRef={grid} callback={onGridCallback} />
<Grid
gridKey="AAAA-BBBB-CCCC-DDDD-EEEE-FFFF"
options={options}
gridRef={grid}
callback={onGridCallback}
/>
<button onClick={onButtonClick}>Click me</button>
</>
);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"test:all": "pnpm test && pnpm test:e2e",
"check": "pnpm lint && pnpm test",
"build": "pnpm -r --filter './packages/*' run build",
"lint": "pnpm -r --filter './packages/*' run lint",
"lint": "eslint packages examples scripts --ext .ts,.tsx,.js",
"clean": "pnpm -r --filter './{packages,examples}/*' run clean && rimraf node_modules",
"release:preflight": "pnpm check && pnpm build",
"release:prepare": "node scripts/release.js",
Expand Down
25 changes: 9 additions & 16 deletions packages/grid-lite-react/src/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,30 @@
*
*/

import { useMemo } from 'react';
import {
BaseGrid,
GridProps,
getChildProps
useDeclarativeGridOptions
} from '@highcharts/grid-shared-react';
import { merge } from '@highcharts/grid-lite/es-modules/Shared/Utilities.js';
import Grid from '@highcharts/grid-lite/es-modules/masters/grid-lite.src';
import '@highcharts/grid-lite/css/grid-lite.css';
import type { Options } from '@highcharts/grid-lite/es-modules/Grid/Core/Options';
import type { GridProps } from '@highcharts/grid-shared-react';
import { buildGridOptions } from './utils/buildGridOptions';

export default function GridLite(props: GridProps<Options>) {
const { gridRef, children, options, ...gridProps } = props;
const childOptions = useMemo(() => getChildProps(children), [children]);
const columnKey = useMemo(() => {
const columns = childOptions.columns as
Array<{ id?: string }> | undefined;

return columns?.map((column) => column.id).join('\0') ?? '';
}, [childOptions]);
const gridOptions = useMemo(
() => merge(childOptions, options ?? {}) as Options,
[childOptions, options]
const { gridRef, children, options, callback } = props;
const { gridOptions, columnKey } = useDeclarativeGridOptions(
children,
options,
(childOptions, opts) => buildGridOptions(childOptions, opts)
);

return (
<BaseGrid
key={columnKey}
{...gridProps}
options={gridOptions}
Grid={Grid}
callback={callback}
ref={gridRef}
/>
);
Expand Down
Loading
Loading