Skip to content

Commit

Permalink
feat: add mix and match example
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewgallo committed Oct 3, 2024
1 parent 3a9420e commit 85eb9d9
Show file tree
Hide file tree
Showing 24 changed files with 2,955 additions and 0 deletions.
1 change: 1 addition & 0 deletions react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
| Row expansion | [View example](https://codesandbox.io/s/github/matthewgallo/tanstack-carbon/tree/main/react/rowExpansion) | [View example](https://stackblitz.com/github/matthewgallo/tanstack-carbon/tree/main/react/rowExpansion) |
| Sortable columns | [View example](https://codesandbox.io/s/github/matthewgallo/tanstack-carbon/tree/main/react/sortable) | [View example](https://stackblitz.com/github/matthewgallo/tanstack-carbon/tree/main/react/sortable) |
| Sticky columns | [View example](https://codesandbox.io/s/github/matthewgallo/tanstack-carbon/tree/main/react/sticky-columns) | [View example](https://stackblitz.com/github/matthewgallo/tanstack-carbon/tree/main/react/sticky-columns) |
| Mix and match | [View example](https://codesandbox.io/s/github/matthewgallo/tanstack-carbon/tree/main/react/mix-and-match) | [View example](https://stackblitz.com/github/matthewgallo/tanstack-carbon/tree/main/react/mix-and-match) |
2 changes: 2 additions & 0 deletions react/mix-and-match/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VITE_CODE_SANDBOX_URL_ROOT=https://codesandbox.io/s/github/matthewgallo/tanstack-carbon/tree/main/react
VITE_STACK_BLITZ_URL_ROOT=https://stackblitz.com/github/matthewgallo/tanstack-carbon/tree/main/react
24 changes: 24 additions & 0 deletions react/mix-and-match/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
58 changes: 58 additions & 0 deletions react/mix-and-match/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and
some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md)
uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc)
uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the
configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default tseslint.config({
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
});
```

- Replace `tseslint.configs.recommended` to
`tseslint.configs.recommendedTypeChecked` or
`tseslint.configs.strictTypeChecked`
- Optionally add `...tseslint.configs.stylisticTypeChecked`
- Install
[eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and
update the config:

```js
// eslint.config.js
import react from 'eslint-plugin-react';

export default tseslint.config({
// Set the react version
settings: { react: { version: '18.3' } },
plugins: {
// Add the react plugin
react,
},
rules: {
// other rules...
// Enable its recommended rules
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
},
});
```
29 changes: 29 additions & 0 deletions react/mix-and-match/eslint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import js from '@eslint/js';
import globals from 'globals';
import reactHooks from 'eslint-plugin-react-hooks';
import reactRefresh from 'eslint-plugin-react-refresh';
import tseslint from 'typescript-eslint';

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
'@typescript-eslint/no-explicit-any': 'off',
},
}
);
13 changes: 13 additions & 0 deletions react/mix-and-match/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
37 changes: 37 additions & 0 deletions react/mix-and-match/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "mix-and-match",
"private": true,
"version": "0.0.0",
"type": "module",
"main": "src/index.ts",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@carbon/ibm-products": "^2.50.0",
"@carbon/react": "^1.64.1",
"@faker-js/faker": "^8.4.1",
"@tanstack/react-table": "^8.20.1",
"classnames": "^2.5.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"sass": "^1.77.8"
},
"devDependencies": {
"@eslint/js": "^9.9.0",
"@types/node": "^22.5.0",
"@types/react": "^18.3.4",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1",
"eslint": "^9.9.0",
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
"eslint-plugin-react-refresh": "^0.4.9",
"globals": "^15.9.0",
"typescript": "^5.5.3",
"typescript-eslint": "^8.0.1",
"vite": "^5.4.1"
}
}
1 change: 1 addition & 0 deletions react/mix-and-match/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions react/mix-and-match/src/App.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
@use '@carbon/styles/scss/theme' as *;
@use '@carbon/styles/scss/spacing' as *;
@use '@carbon/styles/scss/utilities';
@use '@carbon/styles/scss/colors';
@use '@carbon/styles/scss/type';
@use '@carbon/type/scss/font-family';

.page-grid {
margin-top: 4rem;
}

.flex {
display: flex;
align-items: center;
}

.basic-table th,
.cds--data-table th:last-of-type {
position: relative;
}

.resizer {
position: absolute;
top: 0;
height: 100%;
width: 5px;
background: rgba(0, 0, 0, 0.5);
cursor: col-resize;
user-select: none;
touch-action: none;
}

.resizer.ltr {
right: 0;
}

.resizer.rtl {
left: 0;
}

.resizer.isResizing {
background: blue;
opacity: 1;
}

@media (hover: hover) {
.resizer {
opacity: 0;
}

*:hover > .resizer {
opacity: 1;
}
}

.tanstack-example {
padding-bottom: 2rem;
}
11 changes: 11 additions & 0 deletions react/mix-and-match/src/ExampleLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';

export const ExampleLink = ({ icon, label, url }) => {
const Icon = icon;
return (
<a className="example--link" href={url} target="_blank">
{icon && <Icon className="example--link__icon" />}
{label}
</a>
);
};
47 changes: 47 additions & 0 deletions react/mix-and-match/src/LegacyGrid.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React, { useState } from 'react';
import { useDatagrid, Datagrid } from '@carbon/ibm-products';
import { makeData } from './makeData';

export const LegacyGrid = () => {
const columns = React.useMemo(
() => [
{
Header: 'Name',
accessor: 'name',
},
{
Header: 'Rule',
accessor: 'rule',
},
{
Header: 'Status',
accessor: 'status',
},
{
Header: 'Other',
accessor: 'other',
},
{
Header: 'Example',
accessor: 'example',
},
],
[]
);
const [data] = useState(makeData(7));
const rows = React.useMemo(() => data, [data]);

const datagridState = useDatagrid({
columns,
data: rows,
gridTitle: 'Legacy Datagrid',
gridDescription: (
<>
This example demonstrates how to mix and match Datagrid and
@tanstack/react-table@v8
</>
),
});

return <Datagrid datagridState={datagridState} />;
};
Loading

0 comments on commit 85eb9d9

Please sign in to comment.