-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(Table): Convert Table to TypeScript
- Loading branch information
Showing
26 changed files
with
207 additions
and
291 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
32 changes: 0 additions & 32 deletions
32
packages/forma-36-react-components/src/components/Table/Table/Table.js
This file was deleted.
Oops, something went wrong.
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
27 changes: 27 additions & 0 deletions
27
packages/forma-36-react-components/src/components/Table/Table/Table.tsx
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React, { Component } from 'react'; | ||
import cn from 'classnames'; | ||
import styles from './Table.css'; | ||
|
||
export interface TableProps { | ||
extraClassNames?: string; | ||
children: React.ReactNode; | ||
} | ||
|
||
export class Table extends Component<TableProps> { | ||
render() { | ||
const { extraClassNames, children, ...otherProps } = this.props; | ||
|
||
return ( | ||
<table | ||
className={cn(extraClassNames, styles['Table'])} | ||
cellPadding="0" | ||
cellSpacing="0" | ||
{...otherProps} | ||
> | ||
{children} | ||
</table> | ||
); | ||
} | ||
} | ||
|
||
export default Table; |
File renamed without changes.
21 changes: 0 additions & 21 deletions
21
packages/forma-36-react-components/src/components/Table/TableBody/TableBody.js
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
packages/forma-36-react-components/src/components/Table/TableBody/TableBody.tsx
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React, { Component } from 'react'; | ||
|
||
export interface TableBodyProps { | ||
extraClassNames?: string; | ||
children: React.ReactNode; | ||
} | ||
|
||
export class TableBody extends Component<TableBodyProps> { | ||
render() { | ||
const { extraClassNames, children } = this.props; | ||
|
||
return <tbody className={extraClassNames}>{children}</tbody>; | ||
} | ||
} | ||
|
||
export default TableBody; |
File renamed without changes.
60 changes: 0 additions & 60 deletions
60
packages/forma-36-react-components/src/components/Table/TableCell/TableCell/TableCell.js
This file was deleted.
Oops, something went wrong.
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
60 changes: 60 additions & 0 deletions
60
packages/forma-36-react-components/src/components/Table/TableCell/TableCell/TableCell.tsx
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React, { Component } from 'react'; | ||
import cn from 'classnames'; | ||
|
||
import { TableCellContext } from './TableCellContext'; | ||
|
||
import styles from './TableCell.css'; | ||
|
||
export const sortingDirections = { | ||
asc: 'asc', | ||
desc: 'desc', | ||
}; | ||
|
||
export interface TableCellProps { | ||
extraClassNames?: string; | ||
children?: React.ReactNode; | ||
align?: 'center' | 'left' | 'right'; | ||
sorting?: keyof typeof sortingDirections | boolean; | ||
} | ||
|
||
export class TableCell extends Component<TableCellProps> { | ||
static defaultProps: Partial<TableCellProps> = { | ||
align: 'left', | ||
sorting: false, | ||
}; | ||
|
||
render() { | ||
const { | ||
extraClassNames, | ||
children, | ||
sorting, | ||
align, | ||
...otherProps | ||
} = this.props; | ||
|
||
return ( | ||
<TableCellContext.Consumer> | ||
{({ name: context, element, offsetTop }) => { | ||
const Element = element as any; | ||
return ( | ||
<Element | ||
className={cn(styles['TableCell'], extraClassNames, { | ||
[styles['TableCell--head']]: context === 'head', | ||
[styles['TableCell--head__sorting']]: sorting, | ||
})} | ||
style={{ | ||
top: offsetTop, | ||
}} | ||
align={align} | ||
{...otherProps} | ||
> | ||
{children} | ||
</Element> | ||
); | ||
}} | ||
</TableCellContext.Consumer> | ||
); | ||
} | ||
} | ||
|
||
export default TableCell; |
4 changes: 2 additions & 2 deletions
4
...e/TableCell/TableCell/TableCellContext.js → ...e/TableCell/TableCell/TableCellContext.ts
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,8 +1,8 @@ | ||
import React from 'react'; | ||
|
||
export const contextOptions = { | ||
body: { name: 'body', element: 'td' }, | ||
head: { name: 'head', element: 'th' }, | ||
body: { name: 'body', element: 'td', offsetTop: 0 }, | ||
head: { name: 'head', element: 'th', offsetTop: 0 }, | ||
}; | ||
|
||
export const TableCellContext = React.createContext(contextOptions.body); |
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
File renamed without changes.
Oops, something went wrong.