From eacd21f1184cf4fef22e809e0c1ffe2098bd0981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B8=B8=E5=90=9B?= Date: Wed, 1 Sep 2021 15:17:13 +0800 Subject: [PATCH] style(table): allow custom tr background-color (#3166) * style(table): allow custom tr background-color * style(table): format table docs & add status tr example by var --- packages/theme-chalk/src/common/var.scss | 1 + packages/theme-chalk/src/table.scss | 4 +- website/demo-styles/table.scss | 4 +- website/docs/en-US/table.md | 2428 ++++++++++------------ website/docs/fr-FR/table.md | 2422 ++++++++++----------- website/docs/jp/table.md | 5 +- website/docs/zh-CN/table.md | 2378 ++++++++++----------- 7 files changed, 3393 insertions(+), 3849 deletions(-) diff --git a/packages/theme-chalk/src/common/var.scss b/packages/theme-chalk/src/common/var.scss index 3496259aeb..0001391c91 100644 --- a/packages/theme-chalk/src/common/var.scss +++ b/packages/theme-chalk/src/common/var.scss @@ -668,6 +668,7 @@ $--table: map.merge( 'header-background-color': var(--el-color-white), 'fixed-box-shadow': 0 0 10px rgba(0, 0, 0, 0.12), 'background-color': var(--el-color-white), + 'tr-background-color': var(--el-color-white), 'expanded-cell-background-color': var(--el-color-white), ), $--table diff --git a/packages/theme-chalk/src/table.scss b/packages/theme-chalk/src/table.scss index d8aeec06f1..4c6051cf02 100644 --- a/packages/theme-chalk/src/table.scss +++ b/packages/theme-chalk/src/table.scss @@ -171,7 +171,7 @@ } tr { - background-color: var(--el-color-white); + background-color: var(--el-table-tr-background-color); input[type='checkbox'] { margin: 0; @@ -328,7 +328,7 @@ position: absolute; top: -1px; right: 0; - background-color: var(--el-color-white); + background-color: var(--el-table-header-background-color); border-bottom: var(--el-table-border); } diff --git a/website/demo-styles/table.scss b/website/demo-styles/table.scss index e3a5775851..0ebb8cebd5 100644 --- a/website/demo-styles/table.scss +++ b/website/demo-styles/table.scss @@ -1,9 +1,9 @@ .#{$namespace}-table .warning-row { - background: var(--el-color-warning-lighter); + --el-table-tr-background-color: var(--el-color-warning-lighter); } .#{$namespace}-table .success-row { - background: var(--el-color-success-lighter); + --el-table-tr-background-color: var(--el-color-success-lighter); } .demo-table .name-wrapper { diff --git a/website/docs/en-US/table.md b/website/docs/en-US/table.md index 4d8ab0f733..09dbd6dd0e 100644 --- a/website/docs/en-US/table.md +++ b/website/docs/en-US/table.md @@ -8,81 +8,12 @@ Basic table is just for data display. :::demo After setting attribute `data` of `el-table` with an object array, you can use `prop` (corresponding to a key of the object in `data` array) in `el-table-column` to insert data to table columns, and set the attribute `label` to define the column name. You can also use the attribute `width` to define the width of columns. -```html - - - -``` -::: - -### Striped Table - -Striped table makes it easier to distinguish different rows. - -:::demo Attribute `stripe` accepts a `Boolean`. If `true`, table will be striped. ```html @@ -90,28 +21,83 @@ Striped table makes it easier to distinguish different rows. export default { data() { return { - tableData: [{ - date: '2016-05-03', - name: 'Tom', - address: 'No. 189, Grove St, Los Angeles' - }, { - date: '2016-05-02', - name: 'Tom', - address: 'No. 189, Grove St, Los Angeles' - }, { - date: '2016-05-04', - name: 'Tom', - address: 'No. 189, Grove St, Los Angeles' - }, { - date: '2016-05-01', - name: 'Tom', - address: 'No. 189, Grove St, Los Angeles' - }] + tableData: [ + { + date: '2016-05-03', + name: 'Tom', + address: 'No. 189, Grove St, Los Angeles', + }, + { + date: '2016-05-02', + name: 'Tom', + address: 'No. 189, Grove St, Los Angeles', + }, + { + date: '2016-05-04', + name: 'Tom', + address: 'No. 189, Grove St, Los Angeles', + }, + { + date: '2016-05-01', + name: 'Tom', + address: 'No. 189, Grove St, Los Angeles', + }, + ], } - } + }, } ``` + +::: + +### Striped Table + +Striped table makes it easier to distinguish different rows. + +:::demo Attribute `stripe` accepts a `Boolean`. If `true`, table will be striped. + +```html + + + +``` + ::: ### Table with border @@ -120,24 +106,10 @@ Striped table makes it easier to distinguish different rows. ```html @@ -145,28 +117,34 @@ Striped table makes it easier to distinguish different rows. export default { data() { return { - tableData: [{ - date: '2016-05-03', - name: 'Tom', - address: 'No. 189, Grove St, Los Angeles' - }, { - date: '2016-05-02', - name: 'Tom', - address: 'No. 189, Grove St, Los Angeles' - }, { - date: '2016-05-04', - name: 'Tom', - address: 'No. 189, Grove St, Los Angeles' - }, { - date: '2016-05-01', - name: 'Tom', - address: 'No. 189, Grove St, Los Angeles' - }] + tableData: [ + { + date: '2016-05-03', + name: 'Tom', + address: 'No. 189, Grove St, Los Angeles', + }, + { + date: '2016-05-02', + name: 'Tom', + address: 'No. 189, Grove St, Los Angeles', + }, + { + date: '2016-05-04', + name: 'Tom', + address: 'No. 189, Grove St, Los Angeles', + }, + { + date: '2016-05-01', + name: 'Tom', + address: 'No. 189, Grove St, Los Angeles', + }, + ], } - } + }, } ``` + ::: ### Table with status @@ -174,75 +152,71 @@ Striped table makes it easier to distinguish different rows. You can highlight your table content to distinguish between "success, information, warning, danger" and other states. :::demo Use `row-class-name` in `el-table` to add custom classes to a certain row. Then you can style it with custom classes. + ```html ``` + ::: ### Table with fixed header @@ -250,26 +224,13 @@ You can highlight your table content to distinguish between "success, informatio When there are too many rows, you can use a fixed header. :::demo By setting the attribute `height` of `el-table`, you can fix the table header without any other codes. + ```html @@ -277,40 +238,49 @@ When there are too many rows, you can use a fixed header. export default { data() { return { - tableData: [{ - date: '2016-05-03', - name: 'Tom', - address: 'No. 189, Grove St, Los Angeles' - }, { - date: '2016-05-02', - name: 'Tom', - address: 'No. 189, Grove St, Los Angeles' - }, { - date: '2016-05-04', - name: 'Tom', - address: 'No. 189, Grove St, Los Angeles' - }, { - date: '2016-05-01', - name: 'Tom', - address: 'No. 189, Grove St, Los Angeles' - }, { - date: '2016-05-08', - name: 'Tom', - address: 'No. 189, Grove St, Los Angeles' - }, { - date: '2016-05-06', - name: 'Tom', - address: 'No. 189, Grove St, Los Angeles' - }, { - date: '2016-05-07', - name: 'Tom', - address: 'No. 189, Grove St, Los Angeles' - }], + tableData: [ + { + date: '2016-05-03', + name: 'Tom', + address: 'No. 189, Grove St, Los Angeles', + }, + { + date: '2016-05-02', + name: 'Tom', + address: 'No. 189, Grove St, Los Angeles', + }, + { + date: '2016-05-04', + name: 'Tom', + address: 'No. 189, Grove St, Los Angeles', + }, + { + date: '2016-05-01', + name: 'Tom', + address: 'No. 189, Grove St, Los Angeles', + }, + { + date: '2016-05-08', + name: 'Tom', + address: 'No. 189, Grove St, Los Angeles', + }, + { + date: '2016-05-06', + name: 'Tom', + address: 'No. 189, Grove St, Los Angeles', + }, + { + date: '2016-05-07', + name: 'Tom', + address: 'No. 189, Grove St, Los Angeles', + }, + ], } - } + }, } ``` + ::: ### Table with fixed column @@ -318,48 +288,23 @@ When there are too many rows, you can use a fixed header. When there are too many columns, you can fix some of them. :::demo Attribute `fixed` is used in `el-table-column`, it accepts a `Boolean`. If `true`, the column will be fixed at left. It also accepts two string literals: 'left' and 'right', both indicating that the column will be fixed at corresponding direction. + ```html