@@ -12,7 +22,7 @@
diff --git a/packages/varlet-ui/src/table/__tests__/index.spec.js b/packages/varlet-ui/src/table/__tests__/index.spec.js
index 58b40a9524e..7a6b647eebb 100644
--- a/packages/varlet-ui/src/table/__tests__/index.spec.js
+++ b/packages/varlet-ui/src/table/__tests__/index.spec.js
@@ -10,6 +10,16 @@ test('table use', () => {
})
describe('test table component props', () => {
+ test('table default elevation', () => {
+ const wrapper = mount(VarTable)
+
+ expect(wrapper.classes()).toContain('var-elevation--1')
+ expect(wrapper.classes()).not.toContain('var-table--plain')
+ expect(wrapper.classes()).not.toContain('var-table--surface-low')
+
+ wrapper.unmount()
+ })
+
test('table full-Width', async () => {
const wrapper = mount(VarTable)
@@ -40,6 +50,31 @@ describe('test table component props', () => {
wrapper.unmount()
})
+ test('table plain', () => {
+ const wrapper = mount(VarTable, {
+ props: {
+ plain: true,
+ },
+ })
+
+ expect(wrapper.classes()).toContain('var-table--plain')
+ expect(wrapper.classes()).not.toContain('var-elevation--1')
+
+ wrapper.unmount()
+ })
+
+ test('table surface low', () => {
+ const wrapper = mount(VarTable, {
+ props: {
+ surface: 'low',
+ },
+ })
+
+ expect(wrapper.classes()).toContain('var-table--surface-low')
+
+ wrapper.unmount()
+ })
+
test('table scroller height', () => {
const wrapper = mount(VarTable, {
props: {
@@ -51,6 +86,18 @@ describe('test table component props', () => {
wrapper.unmount()
})
+
+ test('table numeric scroller height', () => {
+ const wrapper = mount(VarTable, {
+ props: {
+ scrollerHeight: 300,
+ },
+ })
+
+ expect(wrapper.find('.var-table__main').attributes('style')).toContain('max-height: 300px;')
+
+ wrapper.unmount()
+ })
})
describe('test table component slots', () => {
@@ -66,6 +113,18 @@ describe('test table component slots', () => {
wrapper.unmount()
})
+ test('table should not render footer without footer slot', () => {
+ const wrapper = mount(VarTable, {
+ slots: {
+ default: () => '
| Body |
',
+ },
+ })
+
+ expect(wrapper.find('.var-table__footer').exists()).toBe(false)
+
+ wrapper.unmount()
+ })
+
test('table footer slot', () => {
const wrapper = mount(VarTable, {
slots: {
@@ -77,4 +136,18 @@ describe('test table component slots', () => {
wrapper.unmount()
})
+
+ test('table default and footer slots', () => {
+ const wrapper = mount(VarTable, {
+ slots: {
+ default: () => '
| table body slot |
',
+ footer: () => 'table footer slot',
+ },
+ })
+
+ expect(wrapper.find('.var-table__table').text()).toContain('table body slot')
+ expect(wrapper.find('.var-table__footer').text()).toBe('table footer slot')
+
+ wrapper.unmount()
+ })
})
diff --git a/packages/varlet-ui/src/table/docs/en-US.md b/packages/varlet-ui/src/table/docs/en-US.md
index 409ae1151c1..4cd910fb21b 100644
--- a/packages/varlet-ui/src/table/docs/en-US.md
+++ b/packages/varlet-ui/src/table/docs/en-US.md
@@ -32,6 +32,66 @@ A minimal table, when you need to display some data in the form of a table, you
```
+### Plain Table
+
+Set `plain` to remove the card-like shadow, background, and radius, and present the table as a pure table surface.
+
+```html
+
+
+
+
+ | Name |
+ Math |
+ English |
+
+
+
+
+ | Jerry |
+ 124 |
+ 38 |
+
+
+ | Tom |
+ 100 |
+ 135 |
+
+
+
+
+```
+
+### Subtle Background
+
+Use `surface="low"` for a subtler MD3-style surface layer.
+
+```html
+
+
+
+
+ | Name |
+ Math |
+ English |
+
+
+
+
+ | Jerry |
+ 124 |
+ 38 |
+
+
+ | Tom |
+ 100 |
+ 135 |
+
+
+
+
+```
+
### Footer Slots
You can insert something in the tail slot, the most common is to insert a `Pagination`.
@@ -176,6 +236,8 @@ function get(current, size) {
|--------------| -------------- | -------- | ---------- |
| `full-width` | The width of the `table` (including the scrollable part) | _string \| number_ | `100%` |
| `elevation` | Elevation level, options `true` `false` and level of `0-24` | _string \| number \| boolean_| `true` |
+| `plain` | Whether to render as a plain table without card shadow, background, or radius | _boolean_ | `false` |
+| `surface` | Subtle background style | _'low'_ | `-` |
| `scroller-height` ***3.2.0*** | The height of the scroll container, which can be used to implement functions such as longitudinal partial scrolling and fixed table headers. | _string \| number_ | `-` |
### Slots
@@ -192,13 +254,16 @@ Here are the CSS variables used by the component. Styles can be customized using
| Variable | Default |
| --- | --- |
| `--table-background` | `#fff` |
+| `--table-surface-low-background` | `var(--color-surface-container-highest)` |
+| `--table-surface-low-row-hover-background` | `var(--color-surface-container-highest)` |
+| `--table-plain-row-hover-background` | `hsla(var(--hsl-on-surface), 0.04)` |
| `--table-border-radius` | `2px` |
| `--table-thead-border-bottom` | `thin solid var(--color-outline)` |
| `--table-thead-th-text-color` | `rgba(0, 0, 0, 0.6)` |
| `--table-thead-th-text-align` | `left` |
| `--table-thead-th-font-size` | `14px` |
| `--table-thead-tr-border-bottom` | `thin solid var(--color-outline)` |
-| `--table-tbody-tr-hover-background` | `#eee` |
+| `--table-tbody-tr-hover-background` | `#f5f5f5` |
| `--table-tbody-tr-border-bottom` | `thin solid var(--color-outline)` |
| `--table-tbody-td-text-color` | `#555` |
| `--table-tbody-td-font-size` | `16px` |
diff --git a/packages/varlet-ui/src/table/docs/zh-CN.md b/packages/varlet-ui/src/table/docs/zh-CN.md
index 0f20bb73f6e..ac9a77507ad 100644
--- a/packages/varlet-ui/src/table/docs/zh-CN.md
+++ b/packages/varlet-ui/src/table/docs/zh-CN.md
@@ -32,6 +32,66 @@
```
+### 纯表格
+
+设置 `plain` 可以一并去掉卡片阴影、背景色和圆角,展示更纯粹的表格形态。
+
+```html
+
+
+
+
+ | 姓名 |
+ 数学 |
+ 英语 |
+
+
+
+
+ | 耗子君 |
+ 124 |
+ 38 |
+
+
+ | 火猫桑 |
+ 100 |
+ 135 |
+
+
+
+
+```
+
+### 弱背景色
+
+通过 `surface="low"` 使用更接近 MD3 的弱背景层级。
+
+```html
+
+
+
+
+ | 姓名 |
+ 数学 |
+ 英语 |
+
+
+
+
+ | 耗子君 |
+ 124 |
+ 38 |
+
+
+ | 火猫桑 |
+ 100 |
+ 135 |
+
+
+
+
+```
+
### 尾部插槽
可以在尾部插槽中插入一些东西,最常见的是插入分页组件。
@@ -176,6 +236,8 @@ function get(current, size) {
|--------------| -------------- | -------- | ---------- |
| `full-width` | `table` 的宽度(包含可滚动部分) | _string \| number_ | `100%` |
| `elevation` | 海拔高度,可选值为 `true` `false` 和 `0-24` 的等级 | _string \| number \| boolean_| `true` |
+| `plain` | 是否以纯表格形态渲染,不带卡片阴影、背景色和圆角 | _boolean_ | `false` |
+| `surface` | 弱背景色风格 | _'low'_ | `-` |
| `scroller-height` ***3.2.0*** | 滚动容器高度,可用于实现纵向局部滚动,固定表头等功能 | _string \| number_ | `-` |
### 插槽
@@ -192,13 +254,16 @@ function get(current, size) {
| 变量名 | 默认值 |
| --- | --- |
| `--table-background` | `#fff` |
+| `--table-surface-low-background` | `var(--color-surface-container-highest)` |
+| `--table-surface-low-row-hover-background` | `var(--color-surface-container-highest)` |
+| `--table-plain-row-hover-background` | `hsla(var(--hsl-on-surface), 0.04)` |
| `--table-border-radius` | `2px` |
| `--table-thead-border-bottom` | `thin solid var(--color-outline)` |
| `--table-thead-th-text-color` | `rgba(0, 0, 0, 0.6)` |
| `--table-thead-th-text-align` | `left` |
| `--table-thead-th-font-size` | `14px` |
| `--table-thead-tr-border-bottom` | `thin solid var(--color-outline)` |
-| `--table-tbody-tr-hover-background` | `#eee` |
+| `--table-tbody-tr-hover-background` | `#f5f5f5` |
| `--table-tbody-tr-border-bottom` | `thin solid var(--color-outline)` |
| `--table-tbody-td-text-color` | `#555` |
| `--table-tbody-td-font-size` | `16px` |
diff --git a/packages/varlet-ui/src/table/example/index.vue b/packages/varlet-ui/src/table/example/index.vue
index 62fd2163789..4397b8fd99e 100644
--- a/packages/varlet-ui/src/table/example/index.vue
+++ b/packages/varlet-ui/src/table/example/index.vue
@@ -55,6 +55,54 @@ onThemeChange()
+
{{ t('plainTable') }}
+
+
+
+ | {{ t('name') }} |
+ {{ t('math') }} |
+ {{ t('english') }} |
+
+
+
+
+
+ | {{ t('jerry') }} |
+ 124 |
+ 38 |
+
+
+ | {{ t('tom') }} |
+ 100 |
+ 135 |
+
+
+
+
+
{{ t('surfaceLow') }}
+
+
+
+ | {{ t('name') }} |
+ {{ t('math') }} |
+ {{ t('english') }} |
+
+
+
+
+
+ | {{ t('jerry') }} |
+ 124 |
+ 38 |
+
+
+ | {{ t('tom') }} |
+ 100 |
+ 135 |
+
+
+
+
{{ t('slot') }}
diff --git a/packages/varlet-ui/src/table/example/locale/en-US.ts b/packages/varlet-ui/src/table/example/locale/en-US.ts
index fa3cc403825..418e949f06d 100644
--- a/packages/varlet-ui/src/table/example/locale/en-US.ts
+++ b/packages/varlet-ui/src/table/example/locale/en-US.ts
@@ -1,5 +1,7 @@
export default {
basicUsage: 'Basic Usage',
+ plainTable: 'Plain Table',
+ surfaceLow: 'Subtle Background',
slot: 'Footer Slots',
fixedHeader: 'Fixed Table Header',
math: 'Math',
diff --git a/packages/varlet-ui/src/table/example/locale/zh-CN.ts b/packages/varlet-ui/src/table/example/locale/zh-CN.ts
index ce8c7096cd3..7e5879b96f9 100644
--- a/packages/varlet-ui/src/table/example/locale/zh-CN.ts
+++ b/packages/varlet-ui/src/table/example/locale/zh-CN.ts
@@ -1,5 +1,7 @@
export default {
basicUsage: '基本使用',
+ plainTable: '纯表格',
+ surfaceLow: '弱背景色',
slot: '尾部插槽',
fixedHeader: '固定表头',
math: '数学',
diff --git a/packages/varlet-ui/src/table/props.ts b/packages/varlet-ui/src/table/props.ts
index 324692950d6..037a33eb25e 100644
--- a/packages/varlet-ui/src/table/props.ts
+++ b/packages/varlet-ui/src/table/props.ts
@@ -1,3 +1,7 @@
+import type { PropType } from 'vue'
+
+export type TableSurface = 'low'
+
export const props = {
fullWidth: {
type: [Number, String],
@@ -10,4 +14,6 @@ export const props = {
type: [Boolean, Number, String],
default: true,
},
+ surface: String as PropType,
+ plain: Boolean,
}
diff --git a/packages/varlet-ui/src/table/table.less b/packages/varlet-ui/src/table/table.less
index a8ba067940e..9dcddc66f1c 100644
--- a/packages/varlet-ui/src/table/table.less
+++ b/packages/varlet-ui/src/table/table.less
@@ -1,12 +1,15 @@
:root {
--table-background: #fff;
+ --table-surface-low-background: var(--color-surface-container-highest);
+ --table-surface-low-row-hover-background: var(--color-surface-container-highest);
+ --table-plain-row-hover-background: hsla(var(--hsl-on-surface), 0.04);
--table-border-radius: 2px;
--table-thead-border-bottom: thin solid var(--color-outline);
--table-thead-th-text-color: rgba(0, 0, 0, 0.6);
--table-thead-th-text-align: left;
--table-thead-th-font-size: 14px;
--table-thead-tr-border-bottom: thin solid var(--color-outline);
- --table-tbody-tr-hover-background: #eee;
+ --table-tbody-tr-hover-background: #f5f5f5;
--table-tbody-tr-border-bottom: thin solid var(--color-outline);
--table-tbody-td-text-color: #555;
--table-tbody-td-font-size: 16px;
@@ -17,6 +20,7 @@
}
.var-table {
+ --scrollbar-track-background: var(--table-background);
width: 100%;
border-radius: var(--table-border-radius);
@@ -75,6 +79,8 @@
td {
color: var(--table-tbody-td-text-color);
font-size: var(--table-tbody-td-font-size);
+ background: inherit;
+ background-clip: padding-box;
}
}
@@ -95,6 +101,17 @@
}
}
+ &--surface-low {
+ --table-background: var(--table-surface-low-background);
+ --table-tbody-tr-hover-background: var(--table-surface-low-row-hover-background);
+ }
+
+ &--plain {
+ --table-background: transparent;
+ --table-tbody-tr-hover-background: var(--table-plain-row-hover-background);
+ border-radius: 0;
+ }
+
&__footer {
width: 100%;
min-height: var(--table-row-height);
diff --git a/packages/varlet-ui/src/themes/__tests__/__snapshots__/index.spec.js.snap b/packages/varlet-ui/src/themes/__tests__/__snapshots__/index.spec.js.snap
index 22c85b91463..be0526d49d8 100644
--- a/packages/varlet-ui/src/themes/__tests__/__snapshots__/index.spec.js.snap
+++ b/packages/varlet-ui/src/themes/__tests__/__snapshots__/index.spec.js.snap
@@ -302,6 +302,32 @@ exports[`dark theme 1`] = `
"--counter-input-width": "28px",
"--counter-padding": "0 4px",
"--cubic-bezier": "cubic-bezier(0.25, 0.8, 0.5, 1)",
+ "--data-table-background": "#303030",
+ "--data-table-body-cell-text-color": "#fff",
+ "--data-table-border-color": "var(--color-outline)",
+ "--data-table-border-radius": "2px",
+ "--data-table-cell-font-size": "16px",
+ "--data-table-cell-padding": "0 16px",
+ "--data-table-empty-padding": "48px 16px",
+ "--data-table-empty-text-color": "var(--color-text-disabled)",
+ "--data-table-expand-cell-padding": "0 8px",
+ "--data-table-fixed-shadow-color": "rgba(0, 0, 0, 0.04)",
+ "--data-table-footer-padding": "12px 16px",
+ "--data-table-header-cell-background": "#303030",
+ "--data-table-header-cell-text-color": "rgba(255, 255, 255, 0.6)",
+ "--data-table-header-font-size": "14px",
+ "--data-table-plain-row-hover-background": "hsla(var(--hsl-on-surface), 0.08)",
+ "--data-table-resize-trigger-color": "hsla(var(--hsl-on-surface-variant), 0.36)",
+ "--data-table-row-height": "46px",
+ "--data-table-row-hover-background": "#3a3a3a",
+ "--data-table-row-large-height": "52px",
+ "--data-table-row-small-height": "40px",
+ "--data-table-selection-cell-padding": "0 8px",
+ "--data-table-sort-trigger-active-color": "var(--color-primary)",
+ "--data-table-sort-trigger-color": "hsla(var(--hsl-on-surface), 0.5)",
+ "--data-table-sort-trigger-hover-background": "hsla(var(--hsl-primary), 0.12)",
+ "--data-table-surface-low-background": "#2a2a2a",
+ "--data-table-surface-low-row-hover-background": "#2a2a2a",
"--date-picker-actions-padding": "0 8px 12px 8px",
"--date-picker-body-background-color": "#303030",
"--date-picker-body-height": "280px",
@@ -825,13 +851,16 @@ exports[`dark theme 1`] = `
"--table-background": "#303030",
"--table-border-radius": "2px",
"--table-footer-border-top": "thin solid var(--color-outline)",
+ "--table-plain-row-hover-background": "hsla(var(--hsl-on-surface), 0.08)",
"--table-row-height": "46px",
"--table-row-padding": "0 16px",
+ "--table-surface-low-background": "#2a2a2a",
+ "--table-surface-low-row-hover-background": "#2a2a2a",
"--table-tbody-td-font-size": "16px",
"--table-tbody-td-text-align": "left",
"--table-tbody-td-text-color": "#fff",
"--table-tbody-tr-border-bottom": "thin solid var(--color-outline)",
- "--table-tbody-tr-hover-background": "#4c4b4b",
+ "--table-tbody-tr-hover-background": "#3a3a3a",
"--table-thead-border-bottom": "thin solid var(--color-outline)",
"--table-thead-th-font-size": "14px",
"--table-thead-th-text-align": "left",
@@ -1258,6 +1287,32 @@ exports[`md3Dark theme 1`] = `
"--counter-input-width": "28px",
"--counter-padding": "0 4px",
"--cubic-bezier": "cubic-bezier(0.25, 0.8, 0.5, 1)",
+ "--data-table-background": "var(--color-surface-container-highest)",
+ "--data-table-body-cell-text-color": "#fff",
+ "--data-table-border-color": "var(--color-outline)",
+ "--data-table-border-radius": "2px",
+ "--data-table-cell-font-size": "16px",
+ "--data-table-cell-padding": "0 16px",
+ "--data-table-empty-padding": "48px 16px",
+ "--data-table-empty-text-color": "var(--color-text-disabled)",
+ "--data-table-expand-cell-padding": "0 8px",
+ "--data-table-fixed-shadow-color": "rgba(0, 0, 0, 0.04)",
+ "--data-table-footer-padding": "12px 16px",
+ "--data-table-header-cell-background": "var(--color-surface-container-highest)",
+ "--data-table-header-cell-text-color": "rgba(255, 255, 255, 0.6)",
+ "--data-table-header-font-size": "14px",
+ "--data-table-plain-row-hover-background": "hsla(var(--hsl-on-surface), 0.08)",
+ "--data-table-resize-trigger-color": "hsla(var(--hsl-on-surface-variant), 0.36)",
+ "--data-table-row-height": "46px",
+ "--data-table-row-hover-background": "var(--color-surface-container-high)",
+ "--data-table-row-large-height": "52px",
+ "--data-table-row-small-height": "40px",
+ "--data-table-selection-cell-padding": "0 8px",
+ "--data-table-sort-trigger-active-color": "var(--color-primary)",
+ "--data-table-sort-trigger-color": "hsla(var(--hsl-on-surface), 0.5)",
+ "--data-table-sort-trigger-hover-background": "hsla(var(--hsl-primary), 0.12)",
+ "--data-table-surface-low-background": "#1c1b1d",
+ "--data-table-surface-low-row-hover-background": "var(--color-surface-container-highest)",
"--date-picker-actions-padding": "20px",
"--date-picker-body-background-color": "var(--color-surface-container-high)",
"--date-picker-body-height": "300px",
@@ -1782,13 +1837,16 @@ exports[`md3Dark theme 1`] = `
"--table-background": "var(--color-surface-container-highest)",
"--table-border-radius": "2px",
"--table-footer-border-top": "thin solid var(--color-outline)",
+ "--table-plain-row-hover-background": "hsla(var(--hsl-on-surface), 0.08)",
"--table-row-height": "46px",
"--table-row-padding": "0 16px",
+ "--table-surface-low-background": "#1c1b1d",
+ "--table-surface-low-row-hover-background": "#1c1b1d",
"--table-tbody-td-font-size": "16px",
"--table-tbody-td-text-align": "left",
"--table-tbody-td-text-color": "#fff",
"--table-tbody-tr-border-bottom": "thin solid var(--color-outline)",
- "--table-tbody-tr-hover-background": "var(--color-surface-container-highest)",
+ "--table-tbody-tr-hover-background": "var(--color-surface-container-high)",
"--table-thead-border-bottom": "thin solid var(--color-outline)",
"--table-thead-th-font-size": "14px",
"--table-thead-th-text-align": "left",
@@ -2199,6 +2257,32 @@ exports[`md3Light theme 1`] = `
"--counter-input-width": "28px",
"--counter-padding": "0 4px",
"--cubic-bezier": "cubic-bezier(0.25, 0.8, 0.5, 1)",
+ "--data-table-background": "var(--color-surface-container-low)",
+ "--data-table-body-cell-text-color": "#555",
+ "--data-table-border-color": "var(--color-outline)",
+ "--data-table-border-radius": "2px",
+ "--data-table-cell-font-size": "16px",
+ "--data-table-cell-padding": "0 16px",
+ "--data-table-empty-padding": "48px 16px",
+ "--data-table-empty-text-color": "var(--color-text-disabled)",
+ "--data-table-expand-cell-padding": "0 8px",
+ "--data-table-fixed-shadow-color": "rgba(0, 0, 0, 0.04)",
+ "--data-table-footer-padding": "12px 16px",
+ "--data-table-header-cell-background": "var(--color-surface-container-low)",
+ "--data-table-header-cell-text-color": "rgba(0, 0, 0, 0.6)",
+ "--data-table-header-font-size": "14px",
+ "--data-table-plain-row-hover-background": "hsla(var(--hsl-on-surface), 0.04)",
+ "--data-table-resize-trigger-color": "hsla(var(--hsl-on-surface-variant), 0.36)",
+ "--data-table-row-height": "46px",
+ "--data-table-row-hover-background": "var(--color-surface-container-high)",
+ "--data-table-row-large-height": "52px",
+ "--data-table-row-small-height": "40px",
+ "--data-table-selection-cell-padding": "0 8px",
+ "--data-table-sort-trigger-active-color": "var(--color-primary)",
+ "--data-table-sort-trigger-color": "hsla(var(--hsl-on-surface), 0.42)",
+ "--data-table-sort-trigger-hover-background": "hsla(var(--hsl-primary), 0.08)",
+ "--data-table-surface-low-background": "var(--color-surface-container-low)",
+ "--data-table-surface-low-row-hover-background": "var(--color-surface-container-highest)",
"--date-picker-actions-padding": "20px",
"--date-picker-body-background-color": "var(--color-surface-container-high)",
"--date-picker-body-height": "300px",
@@ -2472,7 +2556,7 @@ exports[`md3Light theme 1`] = `
"--pagination-font-size": "var(--font-size-md)",
"--pagination-hover-bg-color": "rgba(85, 85, 85, 0.15)",
"--pagination-input-width": "32px",
- "--pagination-item-background": "#fff",
+ "--pagination-item-background": "var(--color-surface-container)",
"--pagination-item-border-radius": "4px",
"--pagination-item-height": "32px",
"--pagination-item-margin": "0 6px",
@@ -2721,13 +2805,16 @@ exports[`md3Light theme 1`] = `
"--table-background": "var(--color-surface-container-low)",
"--table-border-radius": "2px",
"--table-footer-border-top": "thin solid var(--color-outline)",
+ "--table-plain-row-hover-background": "hsla(var(--hsl-on-surface), 0.04)",
"--table-row-height": "46px",
"--table-row-padding": "0 16px",
+ "--table-surface-low-background": "var(--color-surface-container-low)",
+ "--table-surface-low-row-hover-background": "var(--color-surface-container-highest)",
"--table-tbody-td-font-size": "16px",
"--table-tbody-td-text-align": "left",
"--table-tbody-td-text-color": "#555",
"--table-tbody-tr-border-bottom": "thin solid var(--color-outline)",
- "--table-tbody-tr-hover-background": "var(--color-surface-container-low)",
+ "--table-tbody-tr-hover-background": "var(--color-surface-container-high)",
"--table-thead-border-bottom": "thin solid var(--color-outline)",
"--table-thead-th-font-size": "14px",
"--table-thead-th-text-align": "left",
diff --git a/packages/varlet-ui/src/themes/dark/dataTable.ts b/packages/varlet-ui/src/themes/dark/dataTable.ts
new file mode 100644
index 00000000000..cd41c717a53
--- /dev/null
+++ b/packages/varlet-ui/src/themes/dark/dataTable.ts
@@ -0,0 +1,28 @@
+export default {
+ '--data-table-background': '#303030',
+ '--data-table-surface-low-background': '#2a2a2a',
+ '--data-table-header-cell-background': '#303030',
+ '--data-table-header-cell-text-color': 'rgba(255, 255, 255, 0.6)',
+ '--data-table-body-cell-text-color': '#fff',
+ '--data-table-border-color': 'var(--color-outline)',
+ '--data-table-row-hover-background': '#3a3a3a',
+ '--data-table-surface-low-row-hover-background': '#2a2a2a',
+ '--data-table-plain-row-hover-background': 'hsla(var(--hsl-on-surface), 0.08)',
+ '--data-table-sort-trigger-color': 'hsla(var(--hsl-on-surface), 0.5)',
+ '--data-table-sort-trigger-active-color': 'var(--color-primary)',
+ '--data-table-sort-trigger-hover-background': 'hsla(var(--hsl-primary), 0.12)',
+ '--data-table-empty-text-color': 'var(--color-text-disabled)',
+ '--data-table-resize-trigger-color': 'hsla(var(--hsl-on-surface-variant), 0.36)',
+ '--data-table-fixed-shadow-color': 'rgba(0, 0, 0, 0.04)',
+ '--data-table-border-radius': '2px',
+ '--data-table-cell-padding': '0 16px',
+ '--data-table-selection-cell-padding': '0 8px',
+ '--data-table-expand-cell-padding': '0 8px',
+ '--data-table-cell-font-size': '16px',
+ '--data-table-header-font-size': '14px',
+ '--data-table-row-height': '46px',
+ '--data-table-row-small-height': '40px',
+ '--data-table-row-large-height': '52px',
+ '--data-table-footer-padding': '12px 16px',
+ '--data-table-empty-padding': '48px 16px',
+}
diff --git a/packages/varlet-ui/src/themes/dark/index.ts b/packages/varlet-ui/src/themes/dark/index.ts
index 80945b38a4d..c6f0a53ce3a 100644
--- a/packages/varlet-ui/src/themes/dark/index.ts
+++ b/packages/varlet-ui/src/themes/dark/index.ts
@@ -18,6 +18,7 @@ import code from './code'
import collapse from './collapse'
import countdown from './countdown'
import counter from './counter'
+import dataTable from './dataTable'
import datePicker from './datePicker'
import dialog from './dialog'
import divider from './divider'
@@ -193,6 +194,7 @@ export default {
...bottomNavigation,
...countdown,
...counter,
+ ...dataTable,
...fab,
...floatingPanel,
...formDetails,
diff --git a/packages/varlet-ui/src/themes/dark/table.ts b/packages/varlet-ui/src/themes/dark/table.ts
index efaa1db8f6c..21adb1c0e84 100644
--- a/packages/varlet-ui/src/themes/dark/table.ts
+++ b/packages/varlet-ui/src/themes/dark/table.ts
@@ -1,9 +1,12 @@
export default {
'--table-background': '#303030',
+ '--table-surface-low-background': '#2a2a2a',
+ '--table-plain-row-hover-background': 'hsla(var(--hsl-on-surface), 0.08)',
+ '--table-surface-low-row-hover-background': '#2a2a2a',
'--table-thead-th-text-color': 'rgba(255, 255, 255, 0.6)',
'--table-thead-th-text-align': 'left',
'--table-tbody-td-text-color': '#fff',
- '--table-tbody-tr-hover-background': '#4c4b4b',
+ '--table-tbody-tr-hover-background': '#3a3a3a',
'--table-border-radius': '2px',
'--table-thead-border-bottom': 'thin solid var(--color-outline)',
'--table-thead-th-font-size': '14px',
diff --git a/packages/varlet-ui/src/themes/md3-dark/dataTable.ts b/packages/varlet-ui/src/themes/md3-dark/dataTable.ts
new file mode 100644
index 00000000000..e2a5c63a9f6
--- /dev/null
+++ b/packages/varlet-ui/src/themes/md3-dark/dataTable.ts
@@ -0,0 +1,28 @@
+export default {
+ '--data-table-background': 'var(--color-surface-container-highest)',
+ '--data-table-surface-low-background': '#1c1b1d',
+ '--data-table-header-cell-background': 'var(--color-surface-container-highest)',
+ '--data-table-header-cell-text-color': 'rgba(255, 255, 255, 0.6)',
+ '--data-table-body-cell-text-color': '#fff',
+ '--data-table-border-color': 'var(--color-outline)',
+ '--data-table-row-hover-background': 'var(--color-surface-container-high)',
+ '--data-table-surface-low-row-hover-background': 'var(--color-surface-container-highest)',
+ '--data-table-plain-row-hover-background': 'hsla(var(--hsl-on-surface), 0.08)',
+ '--data-table-sort-trigger-color': 'hsla(var(--hsl-on-surface), 0.5)',
+ '--data-table-sort-trigger-active-color': 'var(--color-primary)',
+ '--data-table-sort-trigger-hover-background': 'hsla(var(--hsl-primary), 0.12)',
+ '--data-table-empty-text-color': 'var(--color-text-disabled)',
+ '--data-table-resize-trigger-color': 'hsla(var(--hsl-on-surface-variant), 0.36)',
+ '--data-table-fixed-shadow-color': 'rgba(0, 0, 0, 0.04)',
+ '--data-table-border-radius': '2px',
+ '--data-table-cell-padding': '0 16px',
+ '--data-table-selection-cell-padding': '0 8px',
+ '--data-table-expand-cell-padding': '0 8px',
+ '--data-table-cell-font-size': '16px',
+ '--data-table-header-font-size': '14px',
+ '--data-table-row-height': '46px',
+ '--data-table-row-small-height': '40px',
+ '--data-table-row-large-height': '52px',
+ '--data-table-footer-padding': '12px 16px',
+ '--data-table-empty-padding': '48px 16px',
+}
diff --git a/packages/varlet-ui/src/themes/md3-dark/index.ts b/packages/varlet-ui/src/themes/md3-dark/index.ts
index ac1b561cecf..cec6d033c2e 100644
--- a/packages/varlet-ui/src/themes/md3-dark/index.ts
+++ b/packages/varlet-ui/src/themes/md3-dark/index.ts
@@ -18,6 +18,7 @@ import code from './code'
import collapse from './collapse'
import countdown from './countdown'
import counter from './counter'
+import dataTable from './dataTable'
import datePicker from './datePicker'
import dialog from './dialog'
import divider from './divider'
@@ -193,6 +194,7 @@ export default {
...select,
...option,
...counter,
+ ...dataTable,
...switchThemes,
...slider,
...uploader,
diff --git a/packages/varlet-ui/src/themes/md3-dark/table.ts b/packages/varlet-ui/src/themes/md3-dark/table.ts
index 40d01b53303..a5ed7b55f17 100644
--- a/packages/varlet-ui/src/themes/md3-dark/table.ts
+++ b/packages/varlet-ui/src/themes/md3-dark/table.ts
@@ -1,9 +1,12 @@
export default {
'--table-background': 'var(--color-surface-container-highest)',
+ '--table-surface-low-background': '#1c1b1d',
+ '--table-plain-row-hover-background': 'hsla(var(--hsl-on-surface), 0.08)',
+ '--table-surface-low-row-hover-background': '#1c1b1d',
'--table-thead-th-text-color': 'rgba(255, 255, 255, 0.6)',
'--table-thead-th-text-align': 'left',
'--table-tbody-td-text-color': '#fff',
- '--table-tbody-tr-hover-background': 'var(--color-surface-container-highest)',
+ '--table-tbody-tr-hover-background': 'var(--color-surface-container-high)',
'--table-border-radius': '2px',
'--table-thead-border-bottom': 'thin solid var(--color-outline)',
'--table-thead-th-font-size': '14px',
diff --git a/packages/varlet-ui/src/themes/md3-light/dataTable.ts b/packages/varlet-ui/src/themes/md3-light/dataTable.ts
new file mode 100644
index 00000000000..9f7561fd997
--- /dev/null
+++ b/packages/varlet-ui/src/themes/md3-light/dataTable.ts
@@ -0,0 +1,28 @@
+export default {
+ '--data-table-background': 'var(--color-surface-container-low)',
+ '--data-table-surface-low-background': 'var(--color-surface-container-low)',
+ '--data-table-header-cell-background': 'var(--color-surface-container-low)',
+ '--data-table-header-cell-text-color': 'rgba(0, 0, 0, 0.6)',
+ '--data-table-body-cell-text-color': '#555',
+ '--data-table-border-color': 'var(--color-outline)',
+ '--data-table-row-hover-background': 'var(--color-surface-container-high)',
+ '--data-table-surface-low-row-hover-background': 'var(--color-surface-container-highest)',
+ '--data-table-plain-row-hover-background': 'hsla(var(--hsl-on-surface), 0.04)',
+ '--data-table-sort-trigger-color': 'hsla(var(--hsl-on-surface), 0.42)',
+ '--data-table-sort-trigger-active-color': 'var(--color-primary)',
+ '--data-table-sort-trigger-hover-background': 'hsla(var(--hsl-primary), 0.08)',
+ '--data-table-empty-text-color': 'var(--color-text-disabled)',
+ '--data-table-resize-trigger-color': 'hsla(var(--hsl-on-surface-variant), 0.36)',
+ '--data-table-fixed-shadow-color': 'rgba(0, 0, 0, 0.04)',
+ '--data-table-border-radius': '2px',
+ '--data-table-cell-padding': '0 16px',
+ '--data-table-selection-cell-padding': '0 8px',
+ '--data-table-expand-cell-padding': '0 8px',
+ '--data-table-cell-font-size': '16px',
+ '--data-table-header-font-size': '14px',
+ '--data-table-row-height': '46px',
+ '--data-table-row-small-height': '40px',
+ '--data-table-row-large-height': '52px',
+ '--data-table-footer-padding': '12px 16px',
+ '--data-table-empty-padding': '48px 16px',
+}
diff --git a/packages/varlet-ui/src/themes/md3-light/index.ts b/packages/varlet-ui/src/themes/md3-light/index.ts
index a3842212abf..1a6489d3930 100644
--- a/packages/varlet-ui/src/themes/md3-light/index.ts
+++ b/packages/varlet-ui/src/themes/md3-light/index.ts
@@ -18,6 +18,7 @@ import code from './code'
import collapse from './collapse'
import countdown from './countdown'
import counter from './counter'
+import dataTable from './dataTable'
import datePicker from './datePicker'
import dialog from './dialog'
import divider from './divider'
@@ -195,6 +196,7 @@ export default {
...badge,
...countdown,
...counter,
+ ...dataTable,
...divider,
...formDetails,
...icon,
diff --git a/packages/varlet-ui/src/themes/md3-light/pagination.ts b/packages/varlet-ui/src/themes/md3-light/pagination.ts
index 65651624d04..c2d875fc2aa 100644
--- a/packages/varlet-ui/src/themes/md3-light/pagination.ts
+++ b/packages/varlet-ui/src/themes/md3-light/pagination.ts
@@ -9,7 +9,7 @@ export default {
'--pagination-item-width': '32px',
'--pagination-item-height': '32px',
'--pagination-item-margin': '0 6px',
- '--pagination-item-background': '#fff',
+ '--pagination-item-background': 'var(--color-surface-container)',
'--pagination-item-border-radius': '4px',
'--pagination-item-simple-border-radius': '50%',
'--pagination-input-width': '32px',
diff --git a/packages/varlet-ui/src/themes/md3-light/table.ts b/packages/varlet-ui/src/themes/md3-light/table.ts
index 701ddaeba74..ad2e8ae3b76 100644
--- a/packages/varlet-ui/src/themes/md3-light/table.ts
+++ b/packages/varlet-ui/src/themes/md3-light/table.ts
@@ -1,6 +1,9 @@
export default {
'--table-background': 'var(--color-surface-container-low)',
- '--table-tbody-tr-hover-background': 'var(--color-surface-container-low)',
+ '--table-surface-low-background': 'var(--color-surface-container-low)',
+ '--table-plain-row-hover-background': 'hsla(var(--hsl-on-surface), 0.04)',
+ '--table-surface-low-row-hover-background': 'var(--color-surface-container-highest)',
+ '--table-tbody-tr-hover-background': 'var(--color-surface-container-high)',
'--table-border-radius': '2px',
'--table-thead-border-bottom': 'thin solid var(--color-outline)',
'--table-thead-th-text-color': 'rgba(0, 0, 0, 0.6)',
diff --git a/packages/varlet-ui/types/dataTable.d.ts b/packages/varlet-ui/types/dataTable.d.ts
new file mode 100644
index 00000000000..74ea1be29f1
--- /dev/null
+++ b/packages/varlet-ui/types/dataTable.d.ts
@@ -0,0 +1,173 @@
+import { HTMLAttributes, VNode, VNodeChild } from 'vue'
+import { BasicAttributes, ListenerProp, SetPropsDefaults, VarComponent } from './varComponent'
+
+export declare const dataTableProps: Record
+
+export type DataTableColumnAlign = 'left' | 'center' | 'right'
+
+export type DataTableColumnFixed = 'left' | 'right'
+
+export type DataTableSurface = 'low'
+
+export type DataTableTableLayout = 'auto' | 'fixed'
+
+export type DataTableSortMode = 'single' | 'multiple'
+
+export type DataTableSorterOrder = 'asc' | 'desc'
+
+export type DataTableRowKey = string | number | ((context: DataTableRowBaseContext) => string | number)
+
+export interface DataTableRowBaseContext {
+ row: Row
+ rowIndex: number
+}
+
+export interface DataTableColumnRenderContext extends DataTableRowBaseContext {}
+
+export interface DataTableRowPropsContext extends DataTableRowBaseContext {}
+
+export interface DataTableColumnCellPropsContext extends DataTableRowBaseContext {}
+
+export interface DataTableSummaryContext {
+ data: Row[]
+}
+
+export type DataTableColumnCellSpan = number | ((context: DataTableRowBaseContext) => number)
+
+export type DataTableColumnSelectable = boolean | ((context: DataTableRowBaseContext) => boolean)
+
+export type DataTableColumnTitle = VNodeChild | (() => VNodeChild)
+
+export type DataTableRowProps =
+ | HTMLAttributes
+ | ((context: DataTableRowPropsContext) => HTMLAttributes | undefined)
+
+export type DataTableRowClass =
+ | HTMLAttributes['class']
+ | ((context: DataTableRowPropsContext) => HTMLAttributes['class'])
+
+export type DataTableColumnCellProps =
+ | HTMLAttributes
+ | ((context: DataTableColumnCellPropsContext) => HTMLAttributes | undefined)
+
+export interface DataTableSummaryCell {
+ value?: VNodeChild
+ colSpan?: number
+ rowSpan?: number
+}
+
+export type DataTableSummary = (
+ context: DataTableSummaryContext,
+) => Record | Array>
+
+export interface DataTableBaseColumn {
+ fixed?: DataTableColumnFixed
+ resizable?: boolean
+ width?: string | number
+ minWidth?: string | number
+ maxWidth?: string | number
+ align?: DataTableColumnAlign
+ titleAlign?: DataTableColumnAlign
+ titleColSpan?: number
+ colSpan?: DataTableColumnCellSpan
+ rowSpan?: DataTableColumnCellSpan
+ cellProps?: DataTableColumnCellProps
+}
+
+export interface DataTableSorter {
+ key: string
+ order: DataTableSorterOrder
+}
+
+export interface DataTableFieldColumn extends DataTableBaseColumn {
+ type?: undefined
+ key: string
+ title: DataTableColumnTitle
+ children?: DataTableColumn[]
+ sorter?: boolean
+ render?: (context: DataTableColumnRenderContext) => VNodeChild
+}
+
+export interface DataTableSelectionColumn extends DataTableBaseColumn {
+ type: 'selection'
+ key?: string
+ title?: DataTableColumnTitle
+ multiple?: boolean
+ selectable?: DataTableColumnSelectable
+ render?: never
+}
+
+export interface DataTableExpandColumn extends DataTableBaseColumn {
+ type: 'expand'
+ key?: string
+ title?: DataTableColumnTitle
+ render?: never
+ expandable?: (context: DataTableRowPropsContext) => boolean
+ renderExpand: (context: DataTableRowBaseContext) => VNodeChild
+}
+
+export type DataTableColumn =
+ | DataTableFieldColumn
+ | DataTableSelectionColumn
+ | DataTableExpandColumn
+
+export interface DataTablePagination {
+ simple?: boolean
+ disabled?: boolean
+ showSizeChanger?: boolean
+ showQuickJumper?: boolean
+ maxPagerCount?: number
+ sizeOption?: number[]
+ showTotal?: (total: number, range: [number, number]) => string
+}
+
+export interface DataTableProps extends BasicAttributes {
+ data?: any[]
+ columns?: DataTableColumn[]
+ rowKey?: DataTableRowKey
+ rowProps?: DataTableRowProps
+ rowClass?: DataTableRowClass
+ summary?: DataTableSummary
+ loading?: boolean
+ pagination?: boolean | DataTablePagination
+ remote?: boolean
+ page?: number
+ pageSize?: number
+ total?: number
+ maxHeight?: number | string
+ scrollX?: number | string
+ sorters?: DataTableSorter[]
+ sortMode?: DataTableSortMode
+ tree?: boolean
+ surface?: DataTableSurface
+ cascade?: boolean
+ childrenKey?: string
+ plain?: boolean
+ elevation?: boolean | string | number
+ cellBordered?: boolean
+ tableLayout?: DataTableTableLayout
+ size?: 'small' | 'normal' | 'large'
+ checkedRowKeys?: Array
+ expandedRowKeys?: Array
+ expandedTreeRowKeys?: Array
+ 'onUpdate:checkedRowKeys'?: ListenerProp<(checkedRowKeys: Array) => void>
+ 'onUpdate:expandedRowKeys'?: ListenerProp<(expandedRowKeys: Array) => void>
+ 'onUpdate:expandedTreeRowKeys'?: ListenerProp<(expandedTreeRowKeys: Array) => void>
+ 'onUpdate:page'?: ListenerProp<(page: number) => void>
+ 'onUpdate:pageSize'?: ListenerProp<(pageSize: number) => void>
+ 'onUpdate:sorters'?: ListenerProp<(sorters: DataTableSorter[]) => void>
+}
+
+export class DataTable extends VarComponent {
+ static setPropsDefaults: SetPropsDefaults
+
+ $props: DataTableProps
+
+ $slots: {
+ empty(): VNode[]
+ loadingDescription(): VNode[]
+ footerPrefix(): VNode[]
+ }
+}
+
+export class _DataTableComponent extends DataTable {}
diff --git a/packages/varlet-ui/types/index.d.ts b/packages/varlet-ui/types/index.d.ts
index f69e458d926..360be390c5e 100644
--- a/packages/varlet-ui/types/index.d.ts
+++ b/packages/varlet-ui/types/index.d.ts
@@ -31,6 +31,7 @@ export * from './context'
export * from './countTo'
export * from './countdown'
export * from './counter'
+export * from './dataTable'
export * from './datePicker'
export * from './dialog'
export * from './divider'
@@ -133,6 +134,7 @@ declare module 'vue' {
VarCountTo: typeof import('@varlet/ui')['_CountToComponent']
VarCountdown: typeof import('@varlet/ui')['_CountdownComponent']
VarCounter: typeof import('@varlet/ui')['_CounterComponent']
+ VarDataTable: typeof import('@varlet/ui')['_DataTableComponent']
VarDatePicker: typeof import('@varlet/ui')['_DatePickerComponent']
VarDialog: typeof import('@varlet/ui')['_DialogComponent']
VarDivider: typeof import('@varlet/ui')['_DividerComponent']
diff --git a/packages/varlet-ui/types/styleVars.d.ts b/packages/varlet-ui/types/styleVars.d.ts
index 20416091fb6..52756375fe5 100644
--- a/packages/varlet-ui/types/styleVars.d.ts
+++ b/packages/varlet-ui/types/styleVars.d.ts
@@ -280,6 +280,32 @@ interface BaseStyleVars {
'--counter-disabled-color'?: string
'--counter-disabled-opacity'?: string
'--counter-error-color'?: string
+ '--data-table-background'?: string
+ '--data-table-header-cell-background'?: string
+ '--data-table-surface-low-background'?: string
+ '--data-table-header-cell-text-color'?: string
+ '--data-table-body-cell-text-color'?: string
+ '--data-table-border-color'?: string
+ '--data-table-row-hover-background'?: string
+ '--data-table-surface-low-row-hover-background'?: string
+ '--data-table-plain-row-hover-background'?: string
+ '--data-table-sort-trigger-color'?: string
+ '--data-table-sort-trigger-active-color'?: string
+ '--data-table-sort-trigger-hover-background'?: string
+ '--data-table-empty-text-color'?: string
+ '--data-table-resize-trigger-color'?: string
+ '--data-table-fixed-shadow-color'?: string
+ '--data-table-border-radius'?: string
+ '--data-table-cell-padding'?: string
+ '--data-table-selection-cell-padding'?: string
+ '--data-table-expand-cell-padding'?: string
+ '--data-table-cell-font-size'?: string
+ '--data-table-header-font-size'?: string
+ '--data-table-row-height'?: string
+ '--data-table-row-small-height'?: string
+ '--data-table-row-large-height'?: string
+ '--data-table-footer-padding'?: string
+ '--data-table-empty-padding'?: string
'--date-picker-border-radius'?: string
'--date-picker-font-size'?: string
'--date-picker-min-width'?: string
@@ -749,6 +775,9 @@ interface BaseStyleVars {
'--switch-variant-ripple-left'?: string
'--switch-variant-ripple-active-left'?: string
'--table-background'?: string
+ '--table-surface-low-background'?: string
+ '--table-surface-low-row-hover-background'?: string
+ '--table-plain-row-hover-background'?: string
'--table-border-radius'?: string
'--table-thead-border-bottom'?: string
'--table-thead-th-text-color'?: string
diff --git a/packages/varlet-ui/types/table.d.ts b/packages/varlet-ui/types/table.d.ts
index e0ef0e27d38..4ec17529283 100644
--- a/packages/varlet-ui/types/table.d.ts
+++ b/packages/varlet-ui/types/table.d.ts
@@ -7,6 +7,8 @@ export interface TableProps extends BasicAttributes {
fullWidth?: string | number
scrollerHeight?: string | number
elevation?: boolean | string | number
+ surface?: 'low'
+ plain?: boolean
}
export class Table extends VarComponent {
diff --git a/packages/varlet-ui/varlet.config.mjs b/packages/varlet-ui/varlet.config.mjs
index 4598d059b93..5b049470242 100644
--- a/packages/varlet-ui/varlet.config.mjs
+++ b/packages/varlet-ui/varlet.config.mjs
@@ -384,6 +384,22 @@ export default defineConfig({
doc: 'table',
type: 2,
},
+ {
+ text: {
+ 'zh-CN': 'DataTable 数据表格',
+ 'en-US': 'DataTable',
+ },
+ doc: 'data-table',
+ type: 2,
+ },
+ {
+ text: {
+ 'zh-CN': 'Pagination 分页',
+ 'en-US': 'Pagination',
+ },
+ doc: 'pagination',
+ type: 2,
+ },
{
text: {
'zh-CN': 'Watermark 水印',
@@ -549,14 +565,6 @@ export default defineConfig({
doc: 'popup',
type: 2,
},
- {
- text: {
- 'zh-CN': 'Pagination 分页',
- 'en-US': 'Pagination',
- },
- doc: 'pagination',
- type: 2,
- },
{
text: {
'zh-CN': 'Menu 菜单',