diff --git a/apps/www/.vitepress/theme/styles/vp-doc.css b/apps/www/.vitepress/theme/styles/vp-doc.css index fe2a272a..874867ff 100644 --- a/apps/www/.vitepress/theme/styles/vp-doc.css +++ b/apps/www/.vitepress/theme/styles/vp-doc.css @@ -30,8 +30,9 @@ .vp-doc h2:not(:where(.not-docs *)) { /* margin: 48px 0 16px; */ margin: 16px 0 16px; - border-top: 1px solid var(--vp-c-divider); + border-bottom: 1px solid var(--vp-c-divider); padding-top: 24px; + padding-bottom: 10px; letter-spacing: -0.02em; line-height: 32px; font-size: 24px; diff --git a/apps/www/package.json b/apps/www/package.json index 9b8f66da..bcb520ac 100644 --- a/apps/www/package.json +++ b/apps/www/package.json @@ -12,6 +12,7 @@ }, "dependencies": { "@morev/vue-transitions": "^2.3.6", + "@tanstack/vue-table": "^8.9.3", "@vitejs/plugin-vue-jsx": "^3.0.2", "@vueuse/core": "^10.2.1", "class-variance-authority": "^0.6.1", diff --git a/apps/www/src/content/docs/components/data-table.md b/apps/www/src/content/docs/components/data-table.md new file mode 100644 index 00000000..9e50d6fa --- /dev/null +++ b/apps/www/src/content/docs/components/data-table.md @@ -0,0 +1,23 @@ +--- +title: Data Table +description: Powerful table and datagrids built using TanStack Table. +--- + + + + +## Introduction + +Every data table or datagrid I've created has been unique. They all behave differently, have specific sorting and filtering requirements, and work with different data sources. + +It doesn't make sense to combine all of these variations into a single component. If we do that, we'll lose the flexibility that [headless UI](https://tanstack.com/table/v8/docs/guide/introduction#what-is-headless-ui) provides. + +So instead of a data-table component, I thought it would be more helpful to provide a guide on how to build your own. + +We'll start with the basic `` component and build a complex data table from scratch. + + + +**Tip:** If you find yourself using the same table in multiple places in your app, you can always extract it into a reusable component. + + \ No newline at end of file diff --git a/apps/www/src/lib/registry/default/examples/DataTableDemo.vue b/apps/www/src/lib/registry/default/examples/DataTableDemo.vue new file mode 100644 index 00000000..edb18c80 --- /dev/null +++ b/apps/www/src/lib/registry/default/examples/DataTableDemo.vue @@ -0,0 +1,253 @@ + + + diff --git a/apps/www/src/lib/registry/default/examples/DataTableDemoColumn.vue b/apps/www/src/lib/registry/default/examples/DataTableDemoColumn.vue new file mode 100644 index 00000000..1292cba3 --- /dev/null +++ b/apps/www/src/lib/registry/default/examples/DataTableDemoColumn.vue @@ -0,0 +1,35 @@ + + + diff --git a/apps/www/src/lib/registry/default/ui/input/Input.vue b/apps/www/src/lib/registry/default/ui/input/Input.vue index 3efd0c67..b1aff848 100644 --- a/apps/www/src/lib/registry/default/ui/input/Input.vue +++ b/apps/www/src/lib/registry/default/ui/input/Input.vue @@ -1,11 +1,22 @@ diff --git a/apps/www/src/lib/utils.ts b/apps/www/src/lib/utils.ts index b9c1660e..726b53a0 100644 --- a/apps/www/src/lib/utils.ts +++ b/apps/www/src/lib/utils.ts @@ -1,7 +1,8 @@ +import type { Updater } from '@tanstack/vue-table' import type { ClassValue } from 'clsx' import { clsx } from 'clsx' import { twMerge } from 'tailwind-merge' -import type { FunctionalComponent } from 'vue' +import type { FunctionalComponent, Ref } from 'vue' import { camelize, defineComponent, getCurrentInstance, h, toHandlerKey } from 'vue' export type ParseEmits> = { @@ -38,3 +39,10 @@ export function convertToComponent(component: FunctionalComponent) { setup() { return () => h(component) }, }) } + +export function valueUpdater>(updaterOrValue: T, ref: Ref) { + ref.value + = typeof updaterOrValue === 'function' + ? updaterOrValue(ref.value) + : updaterOrValue +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 09b5b2fa..89d46cb6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -44,6 +44,9 @@ importers: '@morev/vue-transitions': specifier: ^2.3.6 version: 2.3.6(vue@3.3.4) + '@tanstack/vue-table': + specifier: ^8.9.3 + version: 8.9.3(vue@3.3.4) '@vitejs/plugin-vue-jsx': specifier: ^3.0.2 version: 3.0.2(vite@4.3.9)(vue@3.3.4) @@ -1767,6 +1770,21 @@ packages: resolution: {integrity: sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==} dev: true + /@tanstack/table-core@8.9.3: + resolution: {integrity: sha512-NpHZBoHTfqyJk0m/s/+CSuAiwtebhYK90mDuf5eylTvgViNOujiaOaxNDxJkQQAsVvHWZftUGAx1EfO1rkKtLg==} + engines: {node: '>=12'} + dev: false + + /@tanstack/vue-table@8.9.3(vue@3.3.4): + resolution: {integrity: sha512-Ca9+XZogYOi99rBqIoEJKKIfS0hNWcHnIh8pDUy2xbBk396AtJaO/tvP6B9qsxZF6j4szHzx8TeRveHPpZ+bBw==} + engines: {node: '>=12'} + peerDependencies: + vue: ^3.2.33 + dependencies: + '@tanstack/table-core': 8.9.3 + vue: 3.3.4 + dev: false + /@ts-morph/common@0.20.0: resolution: {integrity: sha512-7uKjByfbPpwuzkstL3L5MQyuXPSKdoNG93Fmi2JoDcTf3pEP731JdRFAduRVkOs8oqxPsXKA+ScrWkdQ8t/I+Q==} dependencies: