feat: export indexValue utils function

This commit is contained in:
Emil Zhai 2021-12-13 14:38:10 +08:00
parent 34600cc194
commit cbecbdb8cf
No known key found for this signature in database
GPG Key ID: 780B385DB72F1EBD
5 changed files with 11 additions and 7 deletions

View File

@ -7,7 +7,8 @@
*/
import React from 'react';
import { get } from '@/drip-table/utils';
import { indexValue } from '@/drip-table/utils';
import { DripTableComponentProps, DripTableComponentSchema } from '../component';
export interface DTCImageSchema extends DripTableComponentSchema {
@ -31,7 +32,7 @@ export default class DTCImage<RecordType> extends React.PureComponent<DTCImagePr
private get value() {
const schema = this.props.schema;
const dataIndex = schema.dataIndex;
return get(this.props.data, dataIndex, '');
return indexValue(this.props.data, dataIndex, '');
}
public render() {

View File

@ -7,7 +7,8 @@
*/
import React from 'react';
import { get } from '@/drip-table/utils';
import { indexValue } from '@/drip-table/utils';
import { DripTableComponentProps, DripTableComponentSchema } from '../component';
export interface DTCTagSchema extends DripTableComponentSchema {
@ -40,7 +41,7 @@ export default class DTCTag<RecordType> extends React.PureComponent<DTCTagProps<
private get value() {
const schema = this.props.schema;
const dataIndex = schema.dataIndex;
return get(this.props.data, dataIndex, '');
return indexValue(this.props.data, dataIndex, '');
}
public render() {

View File

@ -13,7 +13,7 @@
* @param defaultValue
* @returns
*/
export const get = (data: unknown, indexes: string | string[], defaultValue: unknown = void 0) => {
export const indexValue = (data: unknown, indexes: string | string[], defaultValue: unknown = void 0) => {
if (typeof data !== 'object' || !data) {
return void 0;
}

View File

@ -1,10 +1,11 @@
import React, { useState, useEffect, useRef } from 'react';
import { VariableSizeGrid } from 'react-window';
import ResizeObserver from 'rc-resize-observer';
import { indexValue } from '../utils';
import { DripTableDriver, DripTableRecordTypeBase } from '../..';
import styles from './index.module.css';
import { get } from '../utils';
// 根据size来控制行高
const rowHeightMap = {
@ -74,7 +75,7 @@ function VirtualTable<RecordType extends DripTableRecordTypeBase>(props: { drive
const renderCell = ({ columnIndex, rowIndex, style }: { columnIndex: number; rowIndex: number; style: React.CSSProperties }) => {
const columnItem = mergedColumns[columnIndex];
const dataItem = rawData[rowIndex];
const value = columnItem.dataIndex ? get(dataItem, columnItem.dataIndex) : dataItem;
const value = columnItem.dataIndex ? indexValue(dataItem, columnItem.dataIndex) : dataItem;
return (
<div className={styles['virtual-table-cell']} style={style}>
{

View File

@ -1,5 +1,6 @@
export * from './drip-table-provider';
export * from './types';
export { indexValue } from './drip-table/utils';
export { default as builtInComponents } from './drip-table/components';
export type { DripTableComponentProps, DripTableComponentSchema } from './drip-table/components';
export type { DripTableProps } from './drip-table';