-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from stoplightio/SL-650/table-component
SL-650/table component
- Loading branch information
Showing
15 changed files
with
310 additions
and
117 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ TODO | |
- List | ||
- Button | ||
- Portal | ||
- Table | ||
|
||
## Helpful Links | ||
|
||
|
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,5 +1,5 @@ | ||
module.exports = { | ||
preset: '@stoplight/scripts', | ||
setupTestFrameworkScriptFile: './setupTests.js', | ||
snapshotSerializers: ['enzyme-to-json/serializer'], | ||
snapshotSerializers: ['enzyme-to-json/serializer'] | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import * as React from 'react'; | ||
import { themeGet } from 'styled-system'; | ||
import { Box, IBoxProps } from './Box'; | ||
import { styled } from './utils'; | ||
|
||
interface ITableProps extends IBoxProps { | ||
children: any; | ||
isSelection?: boolean; | ||
} | ||
|
||
interface ITableCellProps extends ITableProps { | ||
minWidth?: string; | ||
} | ||
|
||
interface ITableViewProps { | ||
className: string; | ||
children: any; | ||
} | ||
|
||
const TableView = ({ className, children }: ITableViewProps) => ( | ||
<table className={className}> | ||
<tbody>{children}</tbody> | ||
</table> | ||
); | ||
|
||
const getBoxShadowTheme = themeGet('shadows.lg', '0 0 5px #000'); | ||
const boxShadow = (props: ITableCellProps | ITableProps) => | ||
props.isSelection && { | ||
boxShadow: getBoxShadowTheme(props), | ||
}; | ||
|
||
export const Table = styled<ITableProps, 'table'>(Box as any).attrs({ | ||
as: () => TableView, | ||
border: 'none', | ||
borderTop: 'sm', | ||
borderColor: 'colors.border', | ||
css: { | ||
'border-collapse': 'collapse', | ||
}, | ||
})( | ||
// @ts-ignore | ||
boxShadow | ||
); | ||
|
||
export const TableRow = styled<ITableProps, 'tr'>(Box as any).attrs({ | ||
as: 'tr', | ||
border: 'none', | ||
borderBottom: 'sm', | ||
borderRight: 'sm', | ||
borderColor: 'colors.border', | ||
})``; | ||
|
||
export const TableHeadCell = styled<ITableCellProps, 'th'>(Box as any).attrs({ | ||
as: 'td', | ||
border: 'none', | ||
borderLeft: 'sm', | ||
borderColor: 'colors.border', | ||
})( | ||
// @ts-ignore | ||
boxShadow | ||
); | ||
|
||
export const TableCell = styled<ITableCellProps, 'td'>(Box as any).attrs({ | ||
as: 'td', | ||
border: 'none', | ||
borderLeft: 'sm', | ||
borderColor: 'colors.border', | ||
})( | ||
// @ts-ignore | ||
boxShadow | ||
); |
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,50 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import { mount, shallow } from 'enzyme'; | ||
import 'jest-enzyme'; | ||
import * as React from 'react'; | ||
import { Table, TableCell, TableHeadCell, TableRow } from '../'; | ||
|
||
describe('Table', () => { | ||
it('renders children', () => { | ||
const children = <tr />; | ||
|
||
expect(shallow(<Table>{children}</Table>)).toContainReact(children); | ||
}); | ||
|
||
it('always renders tbody underneath', () => { | ||
const wrapper = mount( | ||
<Table> | ||
<tr /> | ||
</Table> | ||
); | ||
|
||
expect(wrapper).toContainMatchingElement('tbody'); | ||
wrapper.unmount(); | ||
}); | ||
}); | ||
|
||
describe('TableRow', () => { | ||
it('renders children', () => { | ||
const children = <td />; | ||
|
||
expect(shallow(<TableRow>{children}</TableRow>)).toContainReact(children); | ||
}); | ||
}); | ||
|
||
describe('TableCell', () => { | ||
it('renders children', () => { | ||
const children = <span>some content</span>; | ||
|
||
expect(shallow(<TableCell>{children}</TableCell>)).toContainReact(children); | ||
}); | ||
}); | ||
|
||
describe('TableHeadCell', () => { | ||
it('renders children', () => { | ||
const children = <span>some content</span>; | ||
|
||
expect(shallow(<TableHeadCell>{children}</TableHeadCell>)).toContainReact(children); | ||
}); | ||
}); |
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
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
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,11 +1,12 @@ | ||
import { IThemeInterface } from '../types'; | ||
|
||
import { base } from './base'; | ||
import { colors, components } from './components'; | ||
import { colors, components, shadows } from './components'; | ||
|
||
export const baseTheme: IThemeInterface = { | ||
base, | ||
|
||
...shadows, | ||
...colors, | ||
...components, | ||
}; |
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
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,57 @@ | ||
import * as React from 'react'; | ||
|
||
import { withKnobs } from '@storybook/addon-knobs'; | ||
import { storiesOf } from '@storybook/react'; | ||
|
||
import { Table, TableCell, TableHeadCell, TableRow } from '../src/'; | ||
|
||
storiesOf('Table', module) | ||
.addDecorator(withKnobs) | ||
.add('with defaults', () => ( | ||
<Table> | ||
<TableRow> | ||
<TableHeadCell>Site</TableHeadCell> | ||
<TableHeadCell>Views</TableHeadCell> | ||
</TableRow> | ||
<TableRow> | ||
<TableCell>stoplight.io</TableCell> | ||
<TableCell>27341</TableCell> | ||
</TableRow> | ||
<TableRow> | ||
<TableCell>example.com</TableCell> | ||
<TableCell>2351</TableCell> | ||
</TableRow> | ||
</Table> | ||
)) | ||
.add('with minWidth', () => ( | ||
<Table> | ||
<TableRow> | ||
<TableHeadCell minWidth="300px">Site</TableHeadCell> | ||
<TableHeadCell>Views</TableHeadCell> | ||
</TableRow> | ||
<TableRow> | ||
<TableCell>stoplight.io</TableCell> | ||
<TableCell>27341</TableCell> | ||
</TableRow> | ||
<TableRow> | ||
<TableCell>example.com</TableCell> | ||
<TableCell>2351</TableCell> | ||
</TableRow> | ||
</Table> | ||
)) | ||
.add('with selection', () => ( | ||
<Table> | ||
<TableRow> | ||
<TableHeadCell>Site</TableHeadCell> | ||
<TableHeadCell>Views</TableHeadCell> | ||
</TableRow> | ||
<TableRow> | ||
<TableCell isSelection>stoplight.io</TableCell> | ||
<TableCell>27341</TableCell> | ||
</TableRow> | ||
<TableRow> | ||
<TableCell>example.com</TableCell> | ||
<TableCell>2351</TableCell> | ||
</TableRow> | ||
</Table> | ||
)); |
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
Oops, something went wrong.