Skip to content

Commit d58c16d

Browse files
committed
fix: exposed table config as a type (TableColConfig)
BREAKING CHANGE: colInfo prop is now colConfig
1 parent 5de8e4d commit d58c16d

File tree

3 files changed

+31
-33
lines changed

3 files changed

+31
-33
lines changed

src/components/LibTable/LibTable.stories.ts

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import * as components from "../index.js"
77

88

99
const meta: Meta<typeof LibTable> = {
10-
// @ts-expect-error ???
1110
component: LibTable,
1211
}
1312

@@ -18,14 +17,12 @@ export const Primary: Story = {
1817
components,
1918
setup: () => ({ args }),
2019
template: `
21-
<test-wrapper :outline="args.outline">
2220
<div class="overflow-x-scroll scrollbar-hidden">
2321
<lib-table
2422
v-bind="args"
2523
>
2624
</lib-table>
2725
</div>
28-
</test-wrapper>
2926
`,
3027
}),
3128
args: {
@@ -35,7 +32,8 @@ export const Primary: Story = {
3532
{ prop1: "Item2 Prop 1", prop2: "Item2 Prop 2", prop3: "Item2 Prop 3" },
3633
{ prop1: "Item3 Prop 1", prop2: "Item3 Prop 2", prop3: "Item3 Prop 3" },
3734
],
38-
colInfo: { prop1: { name: "Header 1" }, prop2: { name: "Header 2" } },
35+
colConfig: { prop1: { name: "Header 1" }, prop2: { name: "Header 2" } },
36+
itemKey: "prop1",
3937
},
4038
}
4139

@@ -107,65 +105,63 @@ export const ThreeColSomeColsNotResizable: Story = {
107105
components,
108106
setup: () => ({ args }),
109107
template: `
110-
<test-wrapper :outline="args.outline">
111-
<lib-table
112-
v-bind="args"
113-
>
114-
</lib-table>
115-
<br>
116-
<lib-table
117-
v-bind="{...args, colInfo:args.colInfo2}"
118-
>
108+
<lib-table
109+
v-bind="args"
110+
>
119111
</lib-table>
120112
<br>
121-
<lib-table
122-
v-bind="{...args, colInfo:args.colInfo3}"
123-
>
124-
</lib-table>
125-
</test-wrapper>
113+
<lib-table
114+
v-bind="{...args, colConfig:args.colConfig2}"
115+
>
116+
</lib-table>
117+
<br>
118+
<lib-table
119+
v-bind="{...args, colConfig:args.colConfig3}"
120+
>
121+
</lib-table>
126122
`,
127123
}),
128124
args: {
129125
cols: ["prop1", "prop2", "prop3"],
126+
itemKey: "prop1",
130127
values: [
131128
{ prop1: "Prop 1", prop2: "Prop 2", prop3: "Prop 3" },
132129
],
133-
colInfo: { prop1: { name: "No Resize", resizable: false } },
134-
colInfo2: { prop2: { name: "No Resize", resizable: false } },
135-
colInfo3: { prop3: { name: "No Resize", resizable: false } },
130+
colConfig: { prop1: { name: "No Resize", resizable: false } },
131+
colConfig2: { prop2: { name: "No Resize", resizable: false } },
132+
colConfig3: { prop3: { name: "No Resize", resizable: false } },
136133
} as any,
137134
}
138135
export const FourColSomeColsNotResizable: Story = {
139136
render: args => ({
140137
components,
141138
setup: () => ({ args }),
142139
template: `
143-
<test-wrapper :outline="args.outline">
144140
<lib-table
145141
v-bind="args"
146142
>
147143
</lib-table>
148144
<br>
149145
<lib-table
150-
v-bind="{...args, colInfo:args.colInfo2}"
146+
v-bind="{...args, colConfig:args.colConfig2}"
151147
>
152148
</lib-table>
153149
<br>
154150
<lib-table
155-
v-bind="{...args, colInfo:args.colInfo3}"
151+
v-bind="{...args, colConfig:args.colConfig3}"
156152
>
157153
</lib-table>
158-
</test-wrapper>
159154
`,
160155
}),
161156
args: {
162157
cols: ["prop1", "prop2", "prop3", "prop4"],
163158
values: [
164159
{ prop1: "Prop 1", prop2: "Prop 2", prop3: "Prop 3", prop4: "Prop 4" },
165160
],
166-
colInfo: { prop1: { name: "No Resize", resizable: false }, prop3: { name: "No Resize", resizable: false } },
167-
colInfo2: { prop2: { name: "No Resize", resizable: false }, prop3: { name: "No Resize", resizable: false } },
168-
colInfo3: { prop1: { name: "No Resize", resizable: false }, prop4: { name: "No Resize", resizable: false } },
161+
itemKey: "prop1",
162+
colConfig: { prop1: { name: "No Resize", resizable: false }, prop3: { name: "No Resize", resizable: false } },
163+
colConfig2: { prop2: { name: "No Resize", resizable: false }, prop3: { name: "No Resize", resizable: false } },
164+
colConfig3: { prop1: { name: "No Resize", resizable: false }, prop4: { name: "No Resize", resizable: false } },
169165
} as any,
170166
}
171167

src/components/LibTable/LibTable.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,21 @@
4747
:class="[
4848
extraClasses[`-1-${i}`],
4949
'cell',
50-
(colInfo as any)[col]?.resizable === false
50+
(colConfig as any)[col]?.resizable === false
5151
? 'no-resize'
5252
: ''
5353
].join(' ')"
5454
>
5555
<td :class="[
5656
extraClasses[`-1-${i}`] ,
5757
'cell',
58-
(colInfo as any)[col]?.resizable === false
58+
(colConfig as any)[col]?.resizable === false
5959
? 'no-resize'
6060
: ''
6161
].join(' ')"
6262
:style="` width:${widths.length > 0 ? widths[i] : ``}; `"
6363
>
64-
{{ (colInfo as any)[col]?.name ?? col }}
64+
{{ (colConfig as any)[col]?.name ?? col }}
6565
</td>
6666
</slot>
6767
</template>
@@ -92,7 +92,7 @@ import { computed, type PropType, ref } from "vue"
9292
9393
import { resizableCols as vResizableCols } from "../../directives/resizableCols.js"
9494
import { twMerge } from "../../helpers/twMerge.js"
95-
import type { ResizableOptions } from "../../types.js"
95+
import type { ResizableOptions, TableColConfig } from "../../types.js"
9696
9797
9898
defineOptions({
@@ -110,7 +110,7 @@ const props = defineProps({
110110
border: { type: Boolean, required: false, default: true },
111111
cellBorder: { type: Boolean, required: false, default: true },
112112
header: { type: Boolean, required: false, default: true },
113-
colInfo: { type: Object as PropType<Record<keyof T, { name?: string, resizable?: boolean }>>, required: false, default: () => ({}) },
113+
colConfig: { type: Object as PropType<TableColConfig<T>>, required: false, default: () => ({}) },
114114
})
115115
const widths = ref([])
116116
const resizableOptions = computed<MakeRequired<Partial<ResizableOptions>, "colCount" | "widths">>(() => ({

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export type ResizableOptions = {
4545
/** The selector to use for the cells. "tr > td" by default. */
4646
selector: string
4747
}
48+
export type TableColConfig<T = {}> = Record<keyof T, { name?: string, resizable?: boolean }>
49+
4850
export type ResizeCallback = (rect: DOMRectReadOnly, el: Element) => void
4951

5052
export type FileInputError = ErrorW<{ file: File, isValidMimeType: boolean, isValidExtension: boolean }>

0 commit comments

Comments
 (0)