Skip to content

Commit

Permalink
feat: add sortable col monorepo package
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewgallo committed Sep 3, 2024
1 parent cff0aad commit 12020b1
Show file tree
Hide file tree
Showing 21 changed files with 2,677 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/gallery/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"react": "^18.3.1",
"react-dom": "^18.3.1",
"resizing": "*",
"sass": "^1.77.8"
"sass": "^1.77.8",
"sortable": "*"
},
"devDependencies": {
"@eslint/js": "^9.9.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/gallery/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import { QueryClient, QueryClientProvider, } from '@tanstack/react-query'
import { ResizableCols } from 'resizing'
import { PaginationExample } from 'pagination'
import { GlobalFilter } from 'global-filter'
import { SortableColumns } from 'sortable'

import { WithSelectableRows } from './WithSelectableRows'
import { WithBatchActions } from './WithBatchActions'
import { WithExpansion } from './WithExpansion'
import { WithInfiniteScroll } from './WithInfiniteScroll'
import { WithRowClick } from './WithRowClick'
import { WithSortableColumns } from './useSortableColumns'
import { WithStickyColumn } from './WithStickyColumn'
import { WithNestedRows } from './WithNestedRows'
import { WithCustomizeColumns } from './WithCustomizeColumns'
Expand Down Expand Up @@ -72,7 +72,7 @@ createRoot(document.getElementById('root')!).render(
<WithRowClick />
</Column>
<Column sm={4} md={8} lg={16}>
<WithSortableColumns />
<SortableColumns />
</Column>
<Column sm={4} md={8} lg={16}>
<WithStickyColumn />
Expand Down
24 changes: 24 additions & 0 deletions packages/sortable/.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?
50 changes: 50 additions & 0 deletions packages/sortable/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 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 packages/sortable/eslint.config.js
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 packages/sortable/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>
40 changes: 40 additions & 0 deletions packages/sortable/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "sortable",
"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.47.0",
"@carbon/react": "^1.64.1",
"@faker-js/faker": "^8.4.1",
"@tanstack/match-sorter-utils": "^8.19.4",
"@tanstack/react-query": "^5.52.1",
"@tanstack/react-table": "^8.20.1",
"@tanstack/react-virtual": "^3.10.4",
"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 packages/sortable/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 packages/sortable/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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const sortStatusFn: SortingFn<Resource> = (rowA, rowB) => {
return statusOrder.indexOf(statusA) - statusOrder.indexOf(statusB)
}

export const WithSortableColumns = () => {
export const SortableColumns = () => {
const [sorting, setSorting] = React.useState<SortingState>([])

const columns = React.useMemo<ColumnDef<Resource>[]>(
Expand Down
18 changes: 18 additions & 0 deletions packages/sortable/src/customTypings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import "@tanstack/react-table";

declare module "@tanstack/table-core" {
interface TableOptions<TData extends RowData>
extends PartialKeys<TableOptionsResolved<TData>, "state" | "onStateChange" | "renderFallbackValue"> {
filterFns?: FilterFns;
}

interface FilterFns {
fuzzy: FilterFn<unknown>;
}

//allows us to define custom properties for our columns
interface ColumnMeta<TData, TValue> {
filterVariant?: 'text' | 'select' | 'checkbox' | 'number'
}
}
8 changes: 8 additions & 0 deletions packages/sortable/src/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@use '@carbon/react' with ($font-path: '@ibm/plex');
@use '@carbon/ibm-products/css/index';
@use './App.scss';

body {
margin: 0;
padding: 0;
}
3 changes: 3 additions & 0 deletions packages/sortable/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { SortableColumns } from "./SortableColumns";

export { SortableColumns };
37 changes: 37 additions & 0 deletions packages/sortable/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import {
CodeSnippet,
Column,
Grid,
Header,
HeaderContainer,
HeaderName,
} from '@carbon/react'

import { SortableColumns } from './SortableColumns'

import './index.scss'

const renderUIShellHeader = () => (
<HeaderContainer
render={() => (
<Header aria-label="Tanstack Carbon DataTable">
<HeaderName href="/" prefix="Carbon">
DataTable / <CodeSnippet hideCopyButton type='inline'>@tanstack/table</CodeSnippet>explorations
</HeaderName>
</Header>
)}
/>
);

createRoot(document.getElementById('root')!).render(
<StrictMode>
{renderUIShellHeader()}
<Grid className='page-grid'>
<Column sm={4} md={8} lg={16}>
<SortableColumns />
</Column>
</Grid>
</StrictMode>
)
Loading

0 comments on commit 12020b1

Please sign in to comment.