Skip to content

Commit

Permalink
fix(ui): type fixes and change slot implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mesqueeb committed Jul 20, 2023
1 parent 5048393 commit 88b8c72
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
6 changes: 3 additions & 3 deletions packages/ui/src/components/MagnetarTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ async function setOrderBy(
<tr v-for="row in rows" :key="row.id">
<template
v-for="(column, columnIndex) in columns"
:key="column.fieldPath + 'td' + row.id"
:key="(column.fieldPath || column.slot) + 'td' + row.id"
>
<slot :name="`cell-${column.fieldPath || `${columnIndex}`}`">
<TableTd :row="row" :column="column" :parseLabel="parseLabel" />
<slot :name="column.slot || columnIndex" v-bind="{ data: row }">
<TableTd :row="row" :column="column" :parseLabel="parseLabel"> </TableTd>
</slot>
</template>
</tr>
Expand Down
26 changes: 12 additions & 14 deletions packages/ui/src/components/TableTd.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,18 @@ async function handleClick(index: number): Promise<void> {

<template>
<td class="magnetar-table-td">
<slot :name="`column-${column.fieldPath || ''}`" v-bind="{ data: row, value: cellValueRaw }">
<div :class="cellAttrs.class" :style="cellAttrs.style">
<div v-if="column.parseMarkdown" v-html="cellValueParsed" />
<div v-if="!column.parseMarkdown">{{ cellValueParsed }}</div>
<button
v-for="(button, i) in buttonAttrArr"
:key="button?.label"
:disabled="button.disabled || undefined"
@click.stop="() => handleClick(i)"
>
{{ button.label }}
</button>
</div>
</slot>
<div :class="cellAttrs.class" :style="cellAttrs.style">
<div v-if="column.parseMarkdown" v-html="cellValueParsed" />
<div v-if="!column.parseMarkdown">{{ cellValueParsed }}</div>
<button
v-for="(button, i) in buttonAttrArr"
:key="button?.label"
:disabled="button.disabled || undefined"
@click.stop="() => handleClick(i)"
>
{{ button.label }}
</button>
</div>
</td>
</template>
Expand Down
7 changes: 6 additions & 1 deletion packages/ui/src/components/TestTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const columns: MUIColumn<Item>[] = [
buttons: [{ label: 'Copy', handler: ({ value }) => alert(`copied to clipboard ${value}`) }],
},
{ label: 'Title', fieldPath: 'title', sortable: true },
{ label: 'Custom Slot', slot: 'somecolumn' },
{
label: 'Is it done?',
fieldPath: 'isDone',
Expand Down Expand Up @@ -76,7 +77,11 @@ const filters: MUIFilter<Item>[] = [
:columns="columns"
:filters="filters"
:pagination="{ limit: 10 }"
/>
>
<template #somecolumn="{ data }">
<pre>{{ data }}</pre>
</template>
</MagnetarTable>
</div>
</template>

Expand Down
4 changes: 4 additions & 0 deletions packages/ui/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export type MUIColumn<T extends Record<string, any>, Label extends string = stri
* ```
*/
parseMarkdown?: (text: string) => string
/**
* When set this will be the name of the slot you can use to edit the column cells via Vue slots.
*/
slot?: string
}

export type MUIPagination = {
Expand Down

0 comments on commit 88b8c72

Please sign in to comment.