Files
react/components/table/table-column.tsx
2020-04-01 06:45:01 +08:00

33 lines
707 B
TypeScript

import React, { useEffect } from 'react'
import { useTableContext } from './table-context'
import useWarning from '../utils/use-warning'
interface Props {
prop: string
label?: string
width?: number
}
export type TableColumnProps = Props
const TableColumn: React.FC<React.PropsWithChildren<TableColumnProps>> = ({
children, prop, label, width,
}) => {
const { appendColumn } = useTableContext()
if (!prop || prop.trim() === '') {
useWarning('The props "prop" is required.', 'Table.Column')
}
useEffect(() => {
appendColumn && appendColumn({
label: children || label,
value: `${prop}`.trim(),
width,
})
}, [])
return null
}
export default TableColumn