docs: fix DataTable repro links
This commit is contained in:
parent
b2caaca1e2
commit
9527b1656f
|
|
@ -10,12 +10,20 @@ const props = defineProps<{
|
||||||
name: string
|
name: string
|
||||||
code: string
|
code: string
|
||||||
style: Style
|
style: Style
|
||||||
|
extraFiles?: string[]
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const sources = ref<Record<string, string>>({})
|
const sources = ref<Record<string, string>>({})
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
sources.value['App.vue'] = props.code
|
sources.value['App.vue'] = props.code
|
||||||
|
if (props.extraFiles) {
|
||||||
|
props.extraFiles.forEach((file) => {
|
||||||
|
import(`../../../src/lib/registry/${props.style}/example/${file}.vue?raw`).then((module) => {
|
||||||
|
sources.value[`${file}.vue`] = module.default
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ const props = withDefaults(defineProps<{
|
||||||
align?: 'center' | 'start' | 'end'
|
align?: 'center' | 'start' | 'end'
|
||||||
sfcTsCode?: string
|
sfcTsCode?: string
|
||||||
sfcTsHtml?: string
|
sfcTsHtml?: string
|
||||||
|
extraFiles?: string[]
|
||||||
}>(), { align: 'center' })
|
}>(), { align: 'center' })
|
||||||
|
|
||||||
const { style } = useConfigStore()
|
const { style } = useConfigStore()
|
||||||
|
|
@ -43,8 +44,8 @@ const { style } = useConfigStore()
|
||||||
<StyleSwitcher />
|
<StyleSwitcher />
|
||||||
|
|
||||||
<div class="flex items-center gap-x-1">
|
<div class="flex items-center gap-x-1">
|
||||||
<Stackblitz :key="style" :style="style" :name="name" :code="decodeURIComponent(sfcTsCode ?? '')" />
|
<Stackblitz :key="style" :extra-files="extraFiles" :style="style" :name="name" :code="decodeURIComponent(sfcTsCode ?? '')" />
|
||||||
<CodeSandbox :key="style" :style="style" :name="name" :code="decodeURIComponent(sfcTsCode ?? '')" />
|
<CodeSandbox :key="style" :extra-files="extraFiles" :style="style" :name="name" :code="decodeURIComponent(sfcTsCode ?? '')" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,20 @@ const props = defineProps<{
|
||||||
name: string
|
name: string
|
||||||
code: string
|
code: string
|
||||||
style: Style
|
style: Style
|
||||||
|
extraFiles?: string[]
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const sources = ref<Record<string, string>>({})
|
const sources = ref<Record<string, string>>({})
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
sources.value['App.vue'] = props.code
|
sources.value['App.vue'] = props.code
|
||||||
|
if (props.extraFiles) {
|
||||||
|
props.extraFiles.forEach((file) => {
|
||||||
|
import(`../../../src/lib/registry/${props.style}/example/${file}.vue?raw`).then((module) => {
|
||||||
|
sources.value[`${file}.vue`] = module.default
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
function handleClick() {
|
function handleClick() {
|
||||||
|
|
|
||||||
|
|
@ -75,8 +75,10 @@ function constructFiles(componentName: string, style: Style, sources: Record<str
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isDataTableDemo = componentName.includes('DataTable')
|
||||||
const iconPackage = style === 'default' ? 'lucide-vue-next' : '@radix-icons/vue'
|
const iconPackage = style === 'default' ? 'lucide-vue-next' : '@radix-icons/vue'
|
||||||
const dependencies = {
|
const dependencies = {
|
||||||
|
'@vueuse/core': 'latest',
|
||||||
'vue': 'latest',
|
'vue': 'latest',
|
||||||
'radix-vue': deps['radix-vue'],
|
'radix-vue': deps['radix-vue'],
|
||||||
'@radix-ui/colors': 'latest',
|
'@radix-ui/colors': 'latest',
|
||||||
|
|
@ -88,6 +90,8 @@ function constructFiles(componentName: string, style: Style, sources: Record<str
|
||||||
'shadcn-vue': 'latest',
|
'shadcn-vue': 'latest',
|
||||||
'typescript': 'latest',
|
'typescript': 'latest',
|
||||||
}
|
}
|
||||||
|
if (isDataTableDemo)
|
||||||
|
dependencies['@tanstack/vue-table'] = 'latest'
|
||||||
|
|
||||||
const devDependencies = {
|
const devDependencies = {
|
||||||
'vite': 'latest',
|
'vite': 'latest',
|
||||||
|
|
@ -98,6 +102,29 @@ function constructFiles(componentName: string, style: Style, sources: Record<str
|
||||||
'autoprefixer': 'latest',
|
'autoprefixer': 'latest',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const baseUtilsString = `import { type ClassValue, clsx } from 'clsx'
|
||||||
|
import { twMerge } from 'tailwind-merge'
|
||||||
|
import { camelize, getCurrentInstance, toHandlerKey } from 'vue'
|
||||||
|
|
||||||
|
export function cn(...inputs: ClassValue[]) {
|
||||||
|
return twMerge(clsx(inputs))`
|
||||||
|
|
||||||
|
const baseUtilsStringWithUpdater = `import type { Updater } from '@tanstack/vue-table'
|
||||||
|
import { type ClassValue, clsx } from 'clsx'
|
||||||
|
import { twMerge } from 'tailwind-merge'
|
||||||
|
import { type Ref, camelize, getCurrentInstance, toHandlerKey } from 'vue'
|
||||||
|
|
||||||
|
export function cn(...inputs: ClassValue[]) {
|
||||||
|
return twMerge(clsx(inputs))
|
||||||
|
}
|
||||||
|
|
||||||
|
export function valueUpdater<T extends Updater<any>>(updaterOrValue: T, ref: Ref) {
|
||||||
|
ref.value
|
||||||
|
= typeof updaterOrValue === 'function'
|
||||||
|
? updaterOrValue(ref.value)
|
||||||
|
: updaterOrValue
|
||||||
|
}`
|
||||||
|
|
||||||
const transformImportPath = (code: string) => {
|
const transformImportPath = (code: string) => {
|
||||||
let parsed = code
|
let parsed = code
|
||||||
parsed = parsed.replaceAll(`@/lib/registry/${style}`, '@/components')
|
parsed = parsed.replaceAll(`@/lib/registry/${style}`, '@/components')
|
||||||
|
|
@ -159,13 +186,7 @@ function constructFiles(componentName: string, style: Style, sources: Record<str
|
||||||
},
|
},
|
||||||
'src/utils.ts': {
|
'src/utils.ts': {
|
||||||
isBinary: false,
|
isBinary: false,
|
||||||
content: `import { type ClassValue, clsx } from 'clsx'
|
content: isDataTableDemo ? baseUtilsStringWithUpdater : baseUtilsString,
|
||||||
import { twMerge } from 'tailwind-merge'
|
|
||||||
import { camelize, getCurrentInstance, toHandlerKey } from 'vue'
|
|
||||||
|
|
||||||
export function cn(...inputs: ClassValue[]) {
|
|
||||||
return twMerge(clsx(inputs))
|
|
||||||
}`,
|
|
||||||
},
|
},
|
||||||
'src/assets/index.css': {
|
'src/assets/index.css': {
|
||||||
content: cssRaw,
|
content: cssRaw,
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ description: Powerful table and datagrids built using TanStack Table.
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
<ComponentPreview name="DataTableDemo" />
|
<ComponentPreview name="DataTableDemo" :extra-files='["DataTableDemoColumn"]' />
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
|
|
@ -20,4 +20,4 @@ We'll start with the basic `<Table />` component and build a complex data table
|
||||||
|
|
||||||
**Tip:** If you find yourself using the same table in multiple places in your app, you can always extract it into a reusable component.
|
**Tip:** If you find yourself using the same table in multiple places in your app, you can always extract it into a reusable component.
|
||||||
|
|
||||||
</Callout>
|
</Callout>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user