Skip to content

Commit f6c2e44

Browse files
authored
feat(Table): 使用Rem规范修改Table组件样式命名 (DevCloudFE#341)
1 parent 7c0c759 commit f6c2e44

File tree

9 files changed

+117
-104
lines changed

9 files changed

+117
-104
lines changed
Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
11
@import '../../../../styles-var/devui-var.scss';
22

3-
.devui-tbody {
4-
tr {
5-
font-size: $devui-font-size-card-title;
6-
color: $devui-text;
7-
border: none;
8-
border-bottom: 1px solid $devui-dividing-line;
9-
background-color: $devui-base-bg;
3+
.devui-table {
4+
&__tbody {
5+
tr {
6+
font-size: $devui-font-size-card-title;
7+
color: $devui-text;
8+
border: none;
9+
border-bottom: 1px solid $devui-dividing-line;
10+
background-color: $devui-base-bg;
1011

11-
&.hover-enabled:hover {
12-
background-color: $devui-list-item-hover-bg;
13-
}
12+
&.hover-enabled:hover {
13+
background-color: $devui-list-item-hover-bg;
14+
}
1415

15-
td {
16-
padding: 10px;
17-
border: none;
16+
td {
17+
padding: 10px;
18+
border: none;
19+
}
1820
}
1921
}
2022
}
2123

22-
.devui-sticky-cell {
23-
position: sticky;
24-
z-index: 5;
25-
background-color: inherit;
24+
.devui-table {
25+
&--sticky-cell {
26+
position: sticky;
27+
z-index: 5;
28+
background-color: inherit;
2629

27-
&.left {
28-
box-shadow: rgba(0, 0, 0, 0.05) $devui-shadow-length-slide-right;
29-
}
30+
&.left {
31+
box-shadow: rgba(0, 0, 0, 0.05) $devui-shadow-length-slide-right;
32+
}
3033

31-
&.right {
32-
box-shadow: rgba(0, 0, 0, 0.05) $devui-shadow-length-slide-left;
34+
&.right {
35+
box-shadow: rgba(0, 0, 0, 0.05) $devui-shadow-length-slide-left;
36+
}
3337
}
3438
}

packages/devui-vue/devui/table/src/components/body/body.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { defineComponent, inject, computed, PropType, toRef } from 'vue';
22
import { TABLE_TOKEN } from '../../table-types';
3-
import { Checkbox } from '../../../../checkbox';
4-
5-
import './body.scss';
63
import { Column } from '../column/column-types';
4+
import { Checkbox } from '../../../../checkbox';
75
import { useFixedColumn } from '../../composable/use-table';
6+
import { useNamespace } from '../../../../shared/hooks/use-namespace';
7+
import './body.scss';
88

99
export default defineComponent({
1010
name: 'DTableBody',
1111
setup() {
1212
const table = inject(TABLE_TOKEN);
1313
const { _data: data, _columns: columns, _checkList: checkList, isFixedLeft } = table.store.states;
14+
const ns = useNamespace('table');
1415

1516
// 移动到行上是否高亮
1617
const hoverEnabled = computed(() => table.props.rowHoveredHighlight);
@@ -19,7 +20,7 @@ export default defineComponent({
1920
const tdAttrs = computed(() =>
2021
isFixedLeft.value
2122
? {
22-
class: 'devui-sticky-cell left',
23+
class: `${ns.m('sticky-cell')} left`,
2324
style: 'left:0;',
2425
}
2526
: null
@@ -32,7 +33,7 @@ export default defineComponent({
3233
) : null;
3334

3435
return () => (
35-
<tbody class='devui-tbody'>
36+
<tbody class={ns.e('tbody')}>
3637
{data.value.map((row, rowIndex) => {
3738
return (
3839
<tr key={rowIndex} class={{ 'hover-enabled': hoverEnabled.value }}>

packages/devui-vue/devui/table/src/components/fix-header.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { defineComponent } from 'vue';
22
import ColGroup from './colgroup/colgroup';
33
import TableHeader from './header/header';
44
import TableBody from './body/body';
5+
import { useNamespace } from '../../../shared/hooks/use-namespace';
56

67
export default defineComponent({
78
props: {
@@ -14,19 +15,21 @@ export default defineComponent({
1415
},
1516
},
1617
setup(props: { classes: Record<string, unknown>; isEmpty: boolean }) {
18+
const ns = useNamespace('table');
19+
1720
return () => {
1821
return (
19-
<div class='devui-table-view'>
20-
<div style='overflow:hidden scroll;'>
21-
<table class={props.classes} cellpadding='0' cellspacing='0'>
22+
<div class={ns.e('fix-header')}>
23+
<div style="overflow:hidden scroll;">
24+
<table class={props.classes} cellpadding="0" cellspacing="0">
2225
<ColGroup />
2326
<TableHeader />
2427
</table>
2528
</div>
26-
<div class='scroll-view'>
27-
<table class={props.classes} cellpadding='0' cellspacing='0'>
29+
<div class={ns.e('scroll-view')}>
30+
<table class={props.classes} cellpadding="0" cellspacing="0">
2831
<ColGroup />
29-
{!props.isEmpty && <TableBody style='flex: 1' />}
32+
{!props.isEmpty && <TableBody style="flex: 1" />}
3033
</table>
3134
</div>
3235
</div>
Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,48 @@
11
@import '../../../../styles-var/devui-var.scss';
22

3-
.devui-thead {
4-
tr {
5-
font-size: $devui-font-size-card-title;
6-
color: $devui-text;
7-
font-weight: 700;
8-
border: none;
9-
border-bottom: 1px solid $devui-line;
10-
background-color: $devui-base-bg;
11-
12-
th {
13-
text-align: left;
14-
padding: 0;
3+
.devui-table {
4+
&__thead {
5+
tr {
6+
font-size: $devui-font-size-card-title;
7+
color: $devui-text;
8+
font-weight: 700;
159
border: none;
10+
border-bottom: 1px solid $devui-line;
11+
background-color: $devui-base-bg;
12+
13+
th {
14+
text-align: left;
15+
padding: 0;
16+
border: none;
17+
}
1618
}
17-
}
1819

19-
.header-container {
20-
position: relative;
21-
display: flex;
22-
align-items: center;
23-
padding-left: 2px;
24-
padding-right: 8px;
20+
.header-container {
21+
position: relative;
22+
display: flex;
23+
align-items: center;
24+
padding-left: 2px;
25+
padding-right: 8px;
2526

26-
.title {
27-
display: inline-block;
28-
line-height: 36px;
29-
vertical-align: middle;
30-
white-space: nowrap;
31-
text-overflow: ellipsis;
32-
overflow: hidden;
33-
cursor: default;
27+
.title {
28+
display: inline-block;
29+
line-height: 36px;
30+
vertical-align: middle;
31+
white-space: nowrap;
32+
text-overflow: ellipsis;
33+
overflow: hidden;
34+
cursor: default;
35+
}
3436
}
3537
}
3638
}
3739

38-
.header-bg {
39-
thead.devui-thead {
40-
tr {
41-
background: var(--devui-list-item-hover-bg, #f2f5fc);
40+
.devui-table {
41+
&--header-bg {
42+
thead.devui-thead {
43+
tr {
44+
background: var(--devui-list-item-hover-bg, #f2f5fc);
45+
}
4246
}
4347
}
4448
}

packages/devui-vue/devui/table/src/components/header/header.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
import { defineComponent, inject, computed, PropType, toRefs } from 'vue';
22
import { TABLE_TOKEN } from '../../table-types';
33
import { Column } from '../column/column-types';
4-
54
import { Checkbox } from '../../../../checkbox';
65
import { Sort } from '../sort';
76
import { Filter } from '../filter';
8-
9-
import './header.scss';
10-
import '../body/body.scss';
117
import { useFliter, useSort } from './use-header';
128
import { useFixedColumn } from '../../composable/use-table';
9+
import { useNamespace } from '../../../../shared/hooks/use-namespace';
10+
import './header.scss';
11+
import '../body/body.scss';
1312

1413
export default defineComponent({
1514
name: 'DTableHeader',
1615
setup() {
1716
const table = inject(TABLE_TOKEN);
1817
const { _checkAll: checkAll, _halfChecked: halfChecked, _columns: columns, isFixedLeft } = table.store.states;
18+
const ns = useNamespace('table');
1919

2020
const thAttrs = computed(() =>
2121
isFixedLeft.value
2222
? {
23-
class: 'devui-sticky-cell left',
23+
class: `${ns.m('sticky-cell')} left`,
2424
style: 'left:0;',
2525
}
2626
: null
2727
);
2828
const checkbox = computed(() =>
2929
table.props.checkable ? (
3030
<th {...thAttrs.value}>
31-
<Checkbox style='padding:10px;' v-model={checkAll.value} halfchecked={halfChecked.value} />
31+
<Checkbox style="padding:10px;" v-model={checkAll.value} halfchecked={halfChecked.value} />
3232
</th>
3333
) : null
3434
);
3535

3636
return () => {
3737
return (
38-
<thead class='devui-thead'>
38+
<thead class={ns.e('thead')}>
3939
<tr>
4040
{checkbox.value}
4141
{columns.value.map((column, index) => (
@@ -70,7 +70,7 @@ const Th = defineComponent({
7070

7171
return () => (
7272
<th class={stickyCell.value} style={offsetStyle.value}>
73-
<div class='header-container'>
73+
<div class="header-container">
7474
{props.column.renderHeader()}
7575
{props.column.filterable && (
7676
<Filter v-model={filteredRef.value} filterList={props.column.filterList} customTemplate={props.column.customFilterTemplate} />

packages/devui-vue/devui/table/src/composable/use-table.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import { computed, ComputedRef, CSSProperties, Ref, ToRefs } from 'vue';
22
import { Column } from '../components/column/column-types';
33
import { TablePropsTypes } from '../table-types';
4+
import { useNamespace } from '../../../shared/hooks/use-namespace';
45

56
interface TableConfig {
67
classes: ComputedRef<Record<string, boolean>>;
78
style: ComputedRef<CSSProperties>;
89
}
910

1011
export function useTable(props: TablePropsTypes): TableConfig {
12+
const ns = useNamespace('table');
1113
const classes = computed(() => ({
12-
'devui-table': true,
13-
'devui-table-striped': props.striped,
14-
'header-bg': props.headerBg,
15-
'table-layout-auto': props.tableLayout === 'auto',
14+
[ns.e('view')]: true,
15+
[ns.m('striped')]: props.striped,
16+
[ns.m('header-bg')]: props.headerBg,
17+
[ns.m('layout-auto')]: props.tableLayout === 'auto',
1618
}));
1719
const style: ComputedRef<CSSProperties> = computed(() => ({
1820
maxHeight: props.maxHeight,
@@ -24,14 +26,15 @@ export function useTable(props: TablePropsTypes): TableConfig {
2426
}
2527

2628
export const useFixedColumn = (column: Ref<Column>): ToRefs<{ stickyCell: string; offsetStyle: string }> => {
29+
const ns = useNamespace('table');
2730
const stickyCell = computed(() => {
2831
const col = column.value;
2932
if (col.fixedLeft) {
30-
return `devui-sticky-cell left`;
33+
return `${ns.m('sticky-cell')} left`;
3134
}
3235

3336
if (col.fixedRight) {
34-
return `devui-sticky-cell right`;
37+
return `${ns.m('sticky-cell')} right`;
3538
}
3639
return undefined;
3740
});
Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,45 @@
11
@import '../../styles-var/devui-var.scss';
22

33
.devui-table {
4-
display: table;
5-
table-layout: fixed;
64
width: 100%;
7-
border-spacing: 0;
8-
border: none;
9-
margin: 0;
10-
padding: 0;
5+
overflow-x: auto;
6+
padding-top: 8px;
117

12-
&-wrapper {
8+
&__view {
9+
display: table;
10+
table-layout: fixed;
1311
width: 100%;
14-
overflow-x: auto;
15-
padding-top: 8px;
12+
border-spacing: 0;
13+
border: none;
14+
margin: 0;
15+
padding: 0;
1616
}
1717

18-
&-striped {
18+
&--striped {
1919
tbody tr:nth-child(even) {
2020
background-color: $devui-list-item-strip-bg;
2121
}
2222
}
2323

24-
&-empty {
24+
&__empty {
2525
width: 100%;
2626
font-size: $devui-font-size;
2727
text-align: center;
2828
}
2929

30-
&-view {
30+
&__fix-header {
3131
display: flex;
3232
flex-direction: column;
3333
position: relative;
3434
height: 100%;
35-
36-
& .scroll-view {
37-
flex: 1;
38-
overflow: scroll;
39-
}
4035
}
41-
}
4236

43-
.table-layout-auto {
44-
table-layout: auto;
45-
}
37+
&__scroll-view {
38+
flex: 1;
39+
overflow: scroll;
40+
}
4641

47-
.table-layout-auto {
48-
table-layout: auto;
42+
&--layout-auto {
43+
table-layout: auto;
44+
}
4945
}

0 commit comments

Comments
 (0)