Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add table caption #850

Merged
merged 1 commit into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/storybook-react/stories/Table.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styled from 'styled-components'
import { Table, Typography } from '@equinor/eds-core-react'
import './../style.css'

const { Body, Row, Cell, Head } = Table
const { Caption, Body, Row, Cell, Head } = Table

export default {
title: 'Components/Table',
Expand All @@ -18,6 +18,7 @@ export const simpleTable = () => (
<div className="">
<div className="group">
<Table>
<Caption>Star Wars Kill Count</Caption>
<Head>
<Row>
<Cell as="th" scope="col">
Expand Down
17 changes: 17 additions & 0 deletions libraries/core-react/src/Table/Caption.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'

const StyledCaption = styled.caption(({ captionSide }) => ({ captionSide }))

export const Caption = (props) => {
return <StyledCaption {...props} />
}

Caption.propTypes = {
captionSide: PropTypes.oneOf(['left', 'top', 'right', 'bottom']),
}

Caption.defaultProps = {
captionSide: 'top',
}
43 changes: 43 additions & 0 deletions libraries/core-react/src/Table/Table.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* eslint-disable no-undef */
import React from 'react'
import { render, cleanup } from '@testing-library/react'
import '@testing-library/jest-dom'
import 'jest-styled-components'
import { Table } from '.'

const { Caption } = Table

afterEach(cleanup)

describe('Caption', () => {
it('Renders a table with caption element present in the document', () => {
const { container } = render(
<Table>
<Caption>test</Caption>
</Table>,
)
expect(container.querySelector('Caption')).toBeInTheDocument()
})
it('Renders a table with caption, and caption-side set default to top', () => {
const { container } = render(
<Table>
<Caption>test</Caption>
</Table>,
)
expect(container.querySelector('Caption')).toHaveStyleRule(
'caption-side',
'top',
)
})
it('Renders a table with caption, and caption-side set to bottom', () => {
const { container } = render(
<Table>
<Caption captionSide="bottom">test</Caption>
</Table>,
)
expect(container.querySelector('Caption')).toHaveStyleRule(
'caption-side',
'bottom',
)
})
})
2 changes: 2 additions & 0 deletions libraries/core-react/src/Table/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Table } from './Table'
import { Caption } from './Caption'
import { Body } from './Body'
import { Cell } from './Cell'
import { Head } from './Head'
import { Row } from './Row'

Table.Caption = Caption
Table.Body = Body
Table.Cell = Cell
Table.Head = Head
Expand Down