@teammodlr/ui-kit 2.1.1 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/checkbox/Checkbox.vue.d.ts +13 -2
- package/lib/components/checkbox/style/Checkbox.css.d.ts +0 -3
- package/lib/components/table/Table.vue.d.ts +15 -3
- package/lib/index.cjs.js +2 -2
- package/lib/index.es.js +1809 -1774
- package/lib/style.css +1 -1
- package/package.json +3 -3
- package/src/components/checkbox/Checkbox.vue +39 -36
- package/src/components/checkbox/style/Checkbox.css.ts +38 -42
- package/src/components/input/style/Input.css.ts +9 -1
- package/src/components/table/Table.vue +87 -8
- package/src/components/table/examples/basic.vue +9 -4
- package/src/components/table/examples/index.stories.ts +4 -1
- package/src/components/table/examples/index.ts +1 -0
- package/src/components/table/examples/selected.vue +68 -0
- package/src/composables/useInput.ts +1 -1
|
@@ -6,13 +6,27 @@
|
|
|
6
6
|
:class="tableComputedClasses"
|
|
7
7
|
>
|
|
8
8
|
<TableHeadRow>
|
|
9
|
+
<TableHead
|
|
10
|
+
v-if="modelValue"
|
|
11
|
+
scope="col"
|
|
12
|
+
:width="20"
|
|
13
|
+
>
|
|
14
|
+
<MCheckbox
|
|
15
|
+
:checked="indeterminate || selected.length === items.length"
|
|
16
|
+
:indeterminate="indeterminate"
|
|
17
|
+
@change="onChange"
|
|
18
|
+
/>
|
|
19
|
+
</TableHead>
|
|
9
20
|
<TableHead
|
|
10
21
|
v-for="(header, index) in headers"
|
|
11
22
|
:key="index"
|
|
12
23
|
:width="header.width"
|
|
13
24
|
:style="{textAlign: header.align}"
|
|
14
25
|
>
|
|
15
|
-
{
|
|
26
|
+
<slot :name="`${header.key}-header`" :item="// @ts-ignore
|
|
27
|
+
item">
|
|
28
|
+
{{ header.name }}
|
|
29
|
+
</slot>
|
|
16
30
|
</TableHead>
|
|
17
31
|
</TableHeadRow>
|
|
18
32
|
<TableBody>
|
|
@@ -22,11 +36,19 @@
|
|
|
22
36
|
:key="index"
|
|
23
37
|
#default="{ onHover }"
|
|
24
38
|
>
|
|
39
|
+
<TableCell
|
|
40
|
+
v-if="modelValue"
|
|
41
|
+
>
|
|
42
|
+
<MCheckbox
|
|
43
|
+
v-model="selected"
|
|
44
|
+
:value="item"
|
|
45
|
+
@click.stop
|
|
46
|
+
/>
|
|
47
|
+
</TableCell>
|
|
25
48
|
<TableCell
|
|
26
49
|
v-for="(header, index) in headers"
|
|
27
50
|
:key="index"
|
|
28
51
|
:style="{ textAlign: header.align}"
|
|
29
|
-
@click.self="$emit('onClick', item)"
|
|
30
52
|
>
|
|
31
53
|
<slot :name="header.key" :item="item" :onHover="onHover">
|
|
32
54
|
{{//@ts-ignore
|
|
@@ -45,14 +67,17 @@
|
|
|
45
67
|
</template>
|
|
46
68
|
|
|
47
69
|
<script lang="ts">
|
|
48
|
-
import { computed, defineComponent, type PropType } from 'vue';
|
|
70
|
+
import { computed, defineComponent, useAttrs, type PropType, toRaw } from 'vue';
|
|
49
71
|
import type { TableHeadItem } from './types';
|
|
50
72
|
import TableHeadRow from './TableHeadRow.vue';
|
|
51
73
|
import TableHead from './TableHead.vue';
|
|
52
74
|
import TableBody from './TableBody.vue';
|
|
53
75
|
import TableRow from './TableRow.vue';
|
|
54
76
|
import TableCell from './TableCell.vue';
|
|
77
|
+
import MCheckbox from '../checkbox/Checkbox.vue';
|
|
78
|
+
|
|
55
79
|
import * as style from "./style";
|
|
80
|
+
import { indeterminate } from '../checkbox/style';
|
|
56
81
|
|
|
57
82
|
export default defineComponent({
|
|
58
83
|
name: "Table",
|
|
@@ -61,13 +86,17 @@ export default defineComponent({
|
|
|
61
86
|
TableHead,
|
|
62
87
|
TableBody,
|
|
63
88
|
TableRow,
|
|
64
|
-
TableCell
|
|
89
|
+
TableCell,
|
|
90
|
+
MCheckbox
|
|
65
91
|
},
|
|
66
92
|
emits: [
|
|
67
|
-
'update:
|
|
68
|
-
'onClick'
|
|
93
|
+
'update:modelValue',
|
|
69
94
|
],
|
|
70
95
|
props: {
|
|
96
|
+
modelValue: {
|
|
97
|
+
type: Array,
|
|
98
|
+
default: null
|
|
99
|
+
},
|
|
71
100
|
headers: {
|
|
72
101
|
type: Array as PropType<Array<TableHeadItem>>,
|
|
73
102
|
default: () => [],
|
|
@@ -89,7 +118,7 @@ export default defineComponent({
|
|
|
89
118
|
default: false
|
|
90
119
|
},
|
|
91
120
|
},
|
|
92
|
-
setup(props) {
|
|
121
|
+
setup(props, { emit, attrs }) {
|
|
93
122
|
|
|
94
123
|
const wrapperComputedClasses = computed(() => {
|
|
95
124
|
return [
|
|
@@ -111,9 +140,59 @@ export default defineComponent({
|
|
|
111
140
|
]
|
|
112
141
|
});
|
|
113
142
|
|
|
143
|
+
const selected = computed({
|
|
144
|
+
get() {
|
|
145
|
+
return props.modelValue;
|
|
146
|
+
},
|
|
147
|
+
set(value) {
|
|
148
|
+
emit('update:modelValue', value);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const indeterminate = computed(() => {
|
|
153
|
+
return selected.value && selected.value.length > 0 && selected.value.length < props.items.length;
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
function compare (a: any, z: any) {
|
|
157
|
+
return a === z;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function onSelect (row: any) {
|
|
161
|
+
|
|
162
|
+
if (!attrs.onSelect) {
|
|
163
|
+
selected.value.push(row);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// @ts-ignore
|
|
168
|
+
attrs.onSelect(row);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function selectAllRows() {
|
|
172
|
+
props.items.forEach((row: any) => {
|
|
173
|
+
if (selected.value.some((item) => compare(toRaw(item), toRaw(row)))) {
|
|
174
|
+
return
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
onSelect(row);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function onChange (event: any) {
|
|
182
|
+
if (event.target.checked) {
|
|
183
|
+
selectAllRows();
|
|
184
|
+
} else {
|
|
185
|
+
selected.value = [];
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
114
189
|
return {
|
|
115
190
|
wrapperComputedClasses,
|
|
116
|
-
tableComputedClasses
|
|
191
|
+
tableComputedClasses,
|
|
192
|
+
selected,
|
|
193
|
+
indeterminate,
|
|
194
|
+
onChange,
|
|
195
|
+
onSelect
|
|
117
196
|
}
|
|
118
197
|
}
|
|
119
198
|
})
|
|
@@ -26,6 +26,11 @@ import { ref } from "vue";
|
|
|
26
26
|
import type { TableHeadItem } from "../types";
|
|
27
27
|
|
|
28
28
|
let headers = ref<TableHeadItem[]>([
|
|
29
|
+
{
|
|
30
|
+
name: "ID",
|
|
31
|
+
key: "id",
|
|
32
|
+
width: 50
|
|
33
|
+
},
|
|
29
34
|
{
|
|
30
35
|
name: "Name",
|
|
31
36
|
key: "name",
|
|
@@ -42,13 +47,13 @@ let headers = ref<TableHeadItem[]>([
|
|
|
42
47
|
}
|
|
43
48
|
]);
|
|
44
49
|
|
|
45
|
-
let items =
|
|
46
|
-
...Array.from({ length: 30 }, () => ({
|
|
50
|
+
let items = [
|
|
51
|
+
...Array.from({ length: 30 }, (v, i) => ({
|
|
52
|
+
id: i,
|
|
47
53
|
name: "John Doe",
|
|
48
54
|
age: 4
|
|
49
55
|
}))
|
|
50
|
-
|
|
51
|
-
]);
|
|
56
|
+
];
|
|
52
57
|
|
|
53
58
|
const handleClick = (item: any) => {
|
|
54
59
|
console.log(item);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import MTable from "../Table.vue";
|
|
2
2
|
import MButton from "../../button/Button.vue";
|
|
3
3
|
import {
|
|
4
|
-
MTableBasic,
|
|
4
|
+
MTableBasic,
|
|
5
|
+
MTableEmpty,
|
|
6
|
+
MTableSelected
|
|
5
7
|
} from "./index";
|
|
6
8
|
|
|
7
9
|
import {
|
|
@@ -18,3 +20,4 @@ export default {
|
|
|
18
20
|
|
|
19
21
|
export const Basic = createStory(MTableBasic);
|
|
20
22
|
export const Empty = createStory(MTableEmpty);
|
|
23
|
+
export const Selected = createStory(MTableSelected);
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<MTable
|
|
3
|
+
:headers="headers"
|
|
4
|
+
:items="items"
|
|
5
|
+
@onClick="handleClick"
|
|
6
|
+
v-model="selected"
|
|
7
|
+
>
|
|
8
|
+
<template #name-header="{ item }">
|
|
9
|
+
Custom header slot if need be
|
|
10
|
+
</template>
|
|
11
|
+
<template #actions="{ item, onHover }">
|
|
12
|
+
{{ onHover }}
|
|
13
|
+
<MButton
|
|
14
|
+
color="blue"
|
|
15
|
+
secondary
|
|
16
|
+
size="sm"
|
|
17
|
+
>
|
|
18
|
+
Edit - {{ item.name }}
|
|
19
|
+
</MButton>
|
|
20
|
+
</template>
|
|
21
|
+
|
|
22
|
+
<template #empty>
|
|
23
|
+
Nothing here
|
|
24
|
+
</template>
|
|
25
|
+
</MTable>
|
|
26
|
+
</template>
|
|
27
|
+
|
|
28
|
+
<script setup lang="ts">
|
|
29
|
+
import { ref } from "vue";
|
|
30
|
+
import type { TableHeadItem } from "../types";
|
|
31
|
+
|
|
32
|
+
let headers = ref<TableHeadItem[]>([
|
|
33
|
+
{
|
|
34
|
+
name: "ID",
|
|
35
|
+
key: "id",
|
|
36
|
+
width: 50
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "Name",
|
|
40
|
+
key: "name",
|
|
41
|
+
width: 200
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "Age",
|
|
45
|
+
key: "age",
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "Actions",
|
|
49
|
+
key: "actions",
|
|
50
|
+
align: "right"
|
|
51
|
+
}
|
|
52
|
+
]);
|
|
53
|
+
|
|
54
|
+
let items = [
|
|
55
|
+
...Array.from({ length: 30 }, (v, i) => ({
|
|
56
|
+
id: i,
|
|
57
|
+
name: "John Doe",
|
|
58
|
+
age: 4
|
|
59
|
+
}))
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
let selected = ref([items[0]]);
|
|
63
|
+
|
|
64
|
+
const handleClick = (item: any) => {
|
|
65
|
+
console.log(item);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
</script>
|
|
@@ -117,7 +117,7 @@ useInput.emits = (withListeners: boolean = true): string[] => {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
useInput.props = () => ({
|
|
120
|
-
modelValue: [String, Number, Boolean, Object, Array] as PropType<string | number | boolean | object | any[] | undefined>,
|
|
120
|
+
modelValue: [String, Number, Boolean, Object, Array] as PropType<string | number | boolean | object | Array<any> | any[] | undefined>,
|
|
121
121
|
name: String,
|
|
122
122
|
readonly: Boolean,
|
|
123
123
|
required: Boolean,
|