Skip to content

Commit 29e8ed0

Browse files
authored
Merge pull request #98 from HC200ok/new-props/text-direction
New props/text direction
2 parents 252a33b + 56eeb18 commit 29e8ed0

File tree

8 files changed

+56
-26
lines changed

8 files changed

+56
-26
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"author": "HC200ok",
44
"description": "A customizable and easy-to-use data table component made with Vue.js 3.x.",
55
"private": false,
6-
"version": "1.4.14",
6+
"version": "1.4.15",
77
"types": "./types/main.d.ts",
88
"license": "MIT",
99
"files": [

src/components/DataTable.vue

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<span
5454
v-else
5555
class="header"
56+
:class="`direction-${headerTextDirection}`"
5657
>
5758
<slot
5859
v-if="slots[`header-${header.value}`]"
@@ -80,8 +81,8 @@
8081
class="vue3-easy-data-table__body"
8182
:class="{'row-alternation': alternating}"
8283
>
83-
<slot
84-
name="body.prepend"
84+
<slot
85+
name="body-prepend"
8586
v-bind="{
8687
items: pageItems,
8788
pagination: {
@@ -111,7 +112,8 @@
111112
:class="[{
112113
'shadow': column === lastFixedColumn,
113114
'can-expand': column === 'expand',
114-
}, typeof bodyItemClassName === 'string' ? bodyItemClassName : bodyItemClassName(column, i)]"
115+
// eslint-disable-next-line max-len
116+
}, typeof bodyItemClassName === 'string' ? bodyItemClassName : bodyItemClassName(column, i), `direction-${bodyTextDirection}`]"
115117
@click="column === 'expand' ? updateExpandingItemIndexList(index, item, $event) : null"
116118
>
117119
<slot
@@ -155,8 +157,8 @@
155157
</td>
156158
</tr>
157159
</template>
158-
<slot
159-
name="body.append"
160+
<slot
161+
name="body-append"
160162
v-bind="{
161163
items: pageItems,
162164
pagination: {
@@ -290,6 +292,7 @@ const props = defineProps({
290292
});
291293
292294
const {
295+
bodyTextDirection,
293296
checkboxColumnWidth,
294297
expandColumnWidth,
295298
filterOptions,
@@ -298,6 +301,7 @@ const {
298301
fixedHeader,
299302
fixedIndex,
300303
headers,
304+
headerTextDirection,
301305
indexColumnWidth,
302306
items,
303307
itemsSelected,

src/modes/Client.vue

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,9 @@
3434
@click-row="showItem"
3535
@update-sort="updateSort"
3636
hide-footer
37+
body-text-direction="left"
38+
header-text-direction="left"
3739
>
38-
<template #body.prepend="body">
39-
<tr>
40-
<td
41-
v-for="(header, index) in body.headers"
42-
:key="index"
43-
>
44-
<span v-if="isDataHeader(header)">Coloumn {{ header.text }}</span>
45-
</td>
46-
</tr>
47-
</template>
48-
4940
<template #expand="item">
5041
<div style="padding: 15px">
5142
{{ item.name }} won championships
@@ -132,11 +123,11 @@ import {
132123
// import type { UseRowsPerPageReturn } from 'use-vue3-easy-data-table';
133124
import type {
134125
Header, Item, FilterOption, ClickRowArgument, UpdateSortArgument, HeaderItemClassNameFunction, BodyItemClassNameFunction, BodyRowClassNameFunction,
126+
TextDirection,
135127
} from '../types/main';
136128
import DataTable from '../components/DataTable.vue';
137129
import { mockClientNestedItems, mockClientItems, mockDuplicateClientNestedItems } from '../mock';
138130
139-
140131
const searchField = ref('name');
141132
const searchValue = ref('');
142133
@@ -153,15 +144,15 @@ const switchToNested = () => {
153144
const headers: Header[] = [
154145
{ text: 'Name', value: 'name' },
155146
{
156-
text: 'Address', value: 'address', width: 200, fixed: true,
147+
text: 'Address', value: 'address', fixed: true,
157148
},
158149
{ text: 'Height', value: 'info.out.height', sortable: true },
159150
{ text: 'Weight', value: 'info.out.weight', sortable: true },
160151
{
161-
text: 'Age', value: 'age', sortable: true, width: 200,
152+
text: 'Age', value: 'age', sortable: true
162153
},
163-
{ text: 'Favourite sport', value: 'favouriteSport', width: 200 },
164-
{ text: 'Favourite fruits', value: 'favouriteFruits', width: 200 },
154+
{ text: 'Favourite sport', value: 'favouriteSport' },
155+
{ text: 'Favourite fruits', value: 'favouriteFruits' },
165156
];
166157
167158
// const headers: Header[] = [
@@ -313,7 +304,7 @@ const updateRowsPerPageSelect = (e: Event) => {
313304
--easy-table-header-font-color: #c1cad4;
314305
--easy-table-header-background-color: #2d3a4f;
315306
316-
--easy-table-header-item-padding: 10px 15px;
307+
/* --easy-table-header-item-padding: 10px 15px; */
317308
318309
--easy-table-body-even-row-font-color: #fff;
319310
--easy-table-body-even-row-background-color: #4c5d7a;
@@ -326,7 +317,7 @@ const updateRowsPerPageSelect = (e: Event) => {
326317
--easy-table-body-row-hover-font-color: #2d3a4f;
327318
--easy-table-body-row-hover-background-color: #eee;
328319
329-
--easy-table-body-item-padding: 10px 15px;
320+
/* --easy-table-body-item-padding: 10px 15px; */
330321
331322
--easy-table-footer-background-color: #2d3a4f;
332323
--easy-table-footer-font-color: #c0c7d2;

src/propsWithDefault.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { PropType } from 'vue';
22
import type {
33
SortType, Item, ServerOptions, FilterOption,
44
HeaderItemClassNameFunction, BodyItemClassNameFunction, BodyRowClassNameFunction,
5+
TextDirection,
56
} from './types/main';
67

78
export default {
@@ -45,6 +46,14 @@ export default {
4546
type: Boolean,
4647
default: false,
4748
},
49+
headerTextDirection: {
50+
type: String as PropType<TextDirection>,
51+
default: 'left',
52+
},
53+
bodyTextDirection: {
54+
type: String as PropType<TextDirection>,
55+
default: 'left',
56+
},
4857
hideFooter: {
4958
type: Boolean,
5059
default: false,
@@ -149,4 +158,4 @@ export default {
149158
type: Boolean,
150159
default: false,
151160
},
152-
}
161+
};

src/scss/checbox.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ $line-color: #fff;
1717
position: relative;
1818
width: $checkbox-size;
1919
height: $checkbox-size;
20-
20+
font-size: var(--easy-table-body-row-font-size);
21+
margin: 0 auto;
2122
label {
2223
cursor: pointer;
2324
display: inline;

src/scss/vue3-easy-data-table.scss

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ table {
118118
.header {
119119
display: flex;
120120
align-items: center;
121+
&.direction-left {
122+
justify-content: flex-start;
123+
}
124+
&.direction-center {
125+
justify-content: center;
126+
}
127+
&.direction-right {
128+
justify-content: flex-end;
129+
}
121130
}
122131

123132
&.sortable {
@@ -198,6 +207,18 @@ table {
198207
border: none;
199208
border-bottom: var(--easy-table-row-border);
200209

210+
&.direction-left {
211+
text-align: left;
212+
}
213+
214+
&.direction-center {
215+
text-align: center;
216+
}
217+
218+
&.direction-right {
219+
text-align: right;
220+
}
221+
201222
position: relative;
202223
.expand-icon {
203224
border: solid;

src/types/main.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,5 @@ export type UpdateSortArgument = {
5050
export type HeaderItemClassNameFunction = (header: Header, index: number) => string
5151
export type BodyRowClassNameFunction = (item: Item, index: number) => string
5252
export type BodyItemClassNameFunction = (column: string, index: number) => string
53+
54+
export type TextDirection = 'center' | 'left' | 'right'

types/main.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,5 @@ export type UpdateSortArgument = {
5050
export type HeaderItemClassNameFunction = (header: Header, index: number) => string
5151
export type BodyRowClassNameFunction = (item: Item, index: number) => string
5252
export type BodyItemClassNameFunction = (column: string, index: number) => string
53+
54+
export type TextDirection = 'center' | 'left' | 'right'

0 commit comments

Comments
 (0)