mirror of
https://github.com/zhigang1992/react.git
synced 2026-01-27 22:27:09 +08:00
37 lines
725 B
TypeScript
37 lines
725 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
|