From b54950e3ed77a466eb048788757a76018638eafa Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Wed, 23 Oct 2024 17:32:30 +0200 Subject: [PATCH] feat(Table): implement component (#2364) --- docs/app/components/content/ComponentCode.vue | 9 +- .../components/content/ComponentExample.vue | 15 +- .../app/components/content/ComponentProps.vue | 1 + .../content/ComponentPropsLinks.vue | 17 + .../app/components/content/ComponentTheme.vue | 8 + .../table/TableColumnFiltersExample.vue | 119 +++ .../table/TableColumnPinningExample.vue | 114 ++ .../table/TableColumnSortingExample.vue | 118 +++ .../TableColumnSortingReusableExample.vue | 150 +++ .../table/TableColumnVisibilityExample.vue | 134 +++ .../examples/table/TableColumnsExample.vue | 96 ++ .../content/examples/table/TableExample.vue | 319 ++++++ .../examples/table/TableFetchExample.vue | 55 + .../table/TableGlobalFilterExample.vue | 115 ++ .../examples/table/TableRowActionsExample.vue | 140 +++ .../table/TableRowExpandableExample.vue | 121 +++ .../table/TableRowSelectionExample.vue | 122 +++ docs/app/pages/[...slug].vue | 16 +- docs/content/3.components/carousel.md | 4 - docs/content/3.components/table.md | 419 +++++++- docs/nuxt.config.ts | 1 + docs/package.json | 2 +- package.json | 1 + playground/app/app.vue | 1 + playground/app/pages/components/table.vue | 354 +++++++ pnpm-lock.yaml | 32 +- src/module.ts | 12 +- src/runtime/components/Carousel.vue | 12 +- src/runtime/components/Table.vue | 232 +++++ src/runtime/composables/useModal.ts | 2 +- src/runtime/composables/useSlideover.ts | 2 +- src/runtime/types/component.ts | 14 - src/runtime/types/index.ts | 1 + src/theme/command-palette.ts | 2 +- src/theme/index.ts | 1 + src/theme/table.ts | 83 ++ test/components/CommandPalette.spec.ts | 3 +- test/components/Table.spec.ts | 164 +++ .../__snapshots__/CommandPalette.spec.ts.snap | 65 +- .../__snapshots__/Table.spec.ts.snap | 986 ++++++++++++++++++ 40 files changed, 4000 insertions(+), 62 deletions(-) create mode 100644 docs/app/components/content/ComponentPropsLinks.vue create mode 100644 docs/app/components/content/examples/table/TableColumnFiltersExample.vue create mode 100644 docs/app/components/content/examples/table/TableColumnPinningExample.vue create mode 100644 docs/app/components/content/examples/table/TableColumnSortingExample.vue create mode 100644 docs/app/components/content/examples/table/TableColumnSortingReusableExample.vue create mode 100644 docs/app/components/content/examples/table/TableColumnVisibilityExample.vue create mode 100644 docs/app/components/content/examples/table/TableColumnsExample.vue create mode 100644 docs/app/components/content/examples/table/TableExample.vue create mode 100644 docs/app/components/content/examples/table/TableFetchExample.vue create mode 100644 docs/app/components/content/examples/table/TableGlobalFilterExample.vue create mode 100644 docs/app/components/content/examples/table/TableRowActionsExample.vue create mode 100644 docs/app/components/content/examples/table/TableRowExpandableExample.vue create mode 100644 docs/app/components/content/examples/table/TableRowSelectionExample.vue create mode 100644 playground/app/pages/components/table.vue create mode 100644 src/runtime/components/Table.vue delete mode 100644 src/runtime/types/component.ts create mode 100644 src/theme/table.ts create mode 100644 test/components/Table.spec.ts create mode 100644 test/components/__snapshots__/Table.spec.ts.snap diff --git a/docs/app/components/content/ComponentCode.vue b/docs/app/components/content/ComponentCode.vue index 6ac96cae63..e565f32af8 100644 --- a/docs/app/components/content/ComponentCode.vue +++ b/docs/app/components/content/ComponentCode.vue @@ -32,6 +32,10 @@ const props = defineProps<{ * @defaultValue false */ collapse?: boolean + /** + * A list of line numbers to highlight in the code block + */ + highlights?: number[] }>() const route = useRoute() @@ -105,7 +109,7 @@ const code = computed(() => { ` } - code += `\`\`\`vue` + code += `\`\`\`vue${props.highlights?.length ? ` {${props.highlights.join('-')}}` : ''}` if (props.external?.length) { code += ` @@ -201,7 +205,8 @@ const { data: ast } = await useAsyncData(`component-code-${name}-${hash({ props: formatted = await $prettier.format(code.value, { trailingComma: 'none', semi: false, - singleQuote: true + singleQuote: true, + printWidth: 100 }) } catch { formatted = code.value diff --git a/docs/app/components/content/ComponentExample.vue b/docs/app/components/content/ComponentExample.vue index 8e7a62a7dc..c19206d352 100644 --- a/docs/app/components/content/ComponentExample.vue +++ b/docs/app/components/content/ComponentExample.vue @@ -22,13 +22,11 @@ const props = withDefaults(defineProps<{ * @defaultValue true */ preview?: boolean - /** * Whether to show the source code * @defaultValue true */ source?: boolean - /** * A list of variable props to link to the component. */ @@ -40,6 +38,10 @@ const props = withDefaults(defineProps<{ default: any multiple?: boolean }> + /** + * A list of line numbers to highlight in the code block + */ + highlights?: number[] }>(), { preview: true, source: true @@ -65,7 +67,7 @@ const code = computed(() => { ` } - code += `\`\`\`vue${props.preview ? '' : ` [${data.pascalName}.vue]`} + code += `\`\`\`vue ${props.preview ? '' : ` [${data.pascalName}.vue]`}${props.highlights?.length ? `{${props.highlights.join('-')}}` : ''} ${data?.code ?? ''} \`\`\`` @@ -87,7 +89,8 @@ const { data: ast } = await useAsyncData(`component-example-${camelName}`, async formatted = await $prettier.format(code.value, { trailingComma: 'none', semi: false, - singleQuote: true + singleQuote: true, + printWidth: 100 }) } catch { formatted = code.value @@ -113,7 +116,7 @@ const optionsValues = ref(props.options?.reduce((acc, option) => {