Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Table components now forward ref
- Loading branch information
Showing
2 changed files
with
50 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,69 @@ | ||
import React from 'react' | ||
import styles from './styles.styl' | ||
import cx from 'classnames' | ||
import PropTypes from 'prop-types' | ||
|
||
import styles from './styles.styl' | ||
|
||
export const Table = props => { | ||
export const Table = React.forwardRef((props, ref) => { | ||
const { className, ...rest } = props | ||
|
||
return <div className={cx(styles.Table, className)} {...rest} /> | ||
} | ||
return <div className={cx(styles.Table, className)} {...rest} ref={ref} /> | ||
}) | ||
|
||
export const TableHead = props => { | ||
export const TableHead = React.forwardRef((props, ref) => { | ||
const { className, ...rest } = props | ||
|
||
return <div className={cx(styles.TableHead, className)} {...rest} /> | ||
} | ||
return <div className={cx(styles.TableHead, className)} {...rest} ref={ref} /> | ||
}) | ||
|
||
export const TableBody = props => { | ||
export const TableBody = React.forwardRef((props, ref) => { | ||
const { className, ...rest } = props | ||
|
||
return <div className={cx(styles.TableBody, className)} {...rest} /> | ||
} | ||
return <div className={cx(styles.TableBody, className)} {...rest} ref={ref} /> | ||
}) | ||
|
||
export const TableRow = props => { | ||
export const TableRow = React.forwardRef((props, ref) => { | ||
const { className, ...rest } = props | ||
|
||
return <div className={cx(styles.TableRow, className)} {...rest} /> | ||
} | ||
return <div className={cx(styles.TableRow, className)} {...rest} ref={ref} /> | ||
}) | ||
|
||
export const TableCell = props => { | ||
export const TableCell = React.forwardRef((props, ref) => { | ||
const { className, ...rest } = props | ||
|
||
return <div className={cx(styles.TableCell, className)} {...rest} /> | ||
} | ||
return <div className={cx(styles.TableCell, className)} {...rest} ref={ref} /> | ||
}) | ||
|
||
export const TableHeader = props => { | ||
export const TableHeader = React.forwardRef((props, ref) => { | ||
const { className, ...rest } = props | ||
|
||
return <div className={cx(styles.TableHeader, className)} {...rest} /> | ||
return ( | ||
<div className={cx(styles.TableHeader, className)} {...rest} ref={ref} /> | ||
) | ||
}) | ||
|
||
Table.propTypes = { | ||
className: PropTypes.string, | ||
ref: PropTypes.oneOfType([PropTypes.func, PropTypes.object]) | ||
} | ||
TableHead.propTypes = { | ||
className: PropTypes.string, | ||
ref: PropTypes.oneOfType([PropTypes.func, PropTypes.object]) | ||
} | ||
TableBody.propTypes = { | ||
className: PropTypes.string, | ||
ref: PropTypes.oneOfType([PropTypes.func, PropTypes.object]) | ||
} | ||
|
||
TableRow.propTypes = { | ||
className: PropTypes.string, | ||
ref: PropTypes.oneOfType([PropTypes.func, PropTypes.object]) | ||
} | ||
TableCell.propTypes = { | ||
className: PropTypes.string, | ||
ref: PropTypes.oneOfType([PropTypes.func, PropTypes.object]) | ||
} | ||
TableHeader.propTypes = { | ||
className: PropTypes.string, | ||
ref: PropTypes.oneOfType([PropTypes.func, PropTypes.object]) | ||
} |