通过 CSS variables 来定义的 table的样式
BaseTableCSSVariables 参考
https://ali-react-table.js.org/docs/table/api/#css-%E5%8F%98%E9%87%8F%E5%88%97%E8%A1%A8
style样式变量参考
https://github.com/alibaba/ali-react-table/blob/master/packages/website/src/assets/AntdBaseTable.tsx
const style = {'--line-height': 1.5715,'--font-size': '12px','--row-height': '32px','--header-row-height': '36px','--cell-padding': '8px','--lock-shadow': '10px 0 8px -8px rgba(0, 0, 0, 0.2)','--border-color': '#f0f0f0',// '--bgcolor': '#fff','--bgcolor': 'inherit', // transparent 用 tr的颜色,选中当前行'--header-bgcolor': '#dceefe', // 'rgba(205,229,253, 0.45)','--color': 'rgba(0, 0, 0, 0.65)', // td文字颜色'--header-color': 'rgba(0, 0, 0, 0.85)', // th 文字颜色// '--hover-bgcolor': '#fafafa','--hover-bgcolor': '#fafcff', // 'rgba(205,229,253, 0.1)', // hover时 tr的颜色// '--header-hover-bgcolor': 'rgba(205,229,253, 0.3)' = #f5fafe'--header-hover-bgcolor': '#f5fafe','--header-highlight-bgcolor': '#f5fafe','--highlight-bgcolor': '#f5fafe',};import styles from './style.module.less';function App() {// 选中高亮的当前行const [currentIndex, setCurrentIndex] = useState(null);function getRowProps(record, rowIndex) {return {style:rowIndex === currentIndex? { '--bgcolor': '#eff5fe', '--hover-bgcolor': '#eff5fe' }: { '--bgcolor': '#fff' },onClick() {setCurrentIndex(rowIndex);},};}return (<BaseTable{...pipeline.getProps()}getRowProps={getRowProps}style={style}// style={{ '--color': '#333', '--cell-border': 'none' }}className={`${styles.table} bordered`}/>)}

css variables
BaseTable主题参考 https://ali-react-table.js.org/docs/table/theming/
支持的自定义 CSS 变量如下
export type BaseTableCSSVariables = Partial<{/** 表格一行的高度,注意该属性将被作为 CSS variable,不能使用数字作为简写 */'--row-height': string/** 表格的字体颜色 */'--color': string/** 表格背景颜色 */'--bgcolor': string/** 鼠标悬停时的背景色 */'--hover-bgcolor': string/** 单元格高亮时的背景色 */'--highlight-bgcolor': string/** 表头中一行的高度,注意该属性将被作为 CSS variable,不能使用数字作为简写 */'--header-row-height': string/** 表头中的字体颜色 */'--header-color': string/** 表头的背景色 */'--header-bgcolor': string/** 表头上鼠标悬停时的背景色 */'--header-hover-bgcolor': string/** 表头上单元格高亮时的背景色 */'--header-highlight-bgcolor': string/** 单元格 padding */'--cell-padding': string/** 字体大小 */'--font-size': string/** 表格内字体的行高 */'--line-height': string/** 锁列阴影,默认为 rgba(152, 152, 152, 0.5) 0 0 6px 2px */'--lock-shadow': string/** 单元格的边框颜色 */'--border-color': string/** 单元格边框,默认为 1px solid var(--border-color) */'--cell-border': string/** 单元格上下边框,默认为 var(--cell-border) */'--cell-border-horizontal': string/** 单元格左右边框,默认为 var(--cell-border) */'--cell-border-vertical': string/** 表头单元格边框,默认为 1px solid var(--border-color) */'--header-cell-border': string/** 表头单元格上下边框,默认为 var(--header-cell-border) */'--header-cell-border-horizontal': string/** 表头单元格左右边框,默认为 var(--header-cell-border) */'--header-cell-border-vertical': string}>
getCell设置单元格样式
精细的场景下,可以使用 getCellProps 来定制每个单元格的样式
getRowProps 当前行高亮
通过 getRowProps(…) 设置 tr 元素上的 props,例如 className, style, onClick
https://ali-react-table.js.org/docs/table/examples/#%E8%87%AA%E5%AE%9A%E4%B9%89%E8%A1%A8%E6%A0%BC%E8%A1%8C%E6%A0%B7%E5%BC%8F
functionApp() {function getRowProps(record, rowIndex) {console.log('record', currentIndex, rowIndex);return {style:rowIndex === currentIndex? { '--bgcolor': '#eff5fe', '--hover-bgcolor': '#eff5fe' }: { '--bgcolor': '#fff' },onClick() {setCurrentIndex(rowIndex);},};}return (<BaseTablegetRowProps={getRowProps}className={`${styles.table} bordered`}/>)}
