Skip to content

Commit

Permalink
feat(table,tablebody,tabledatacell,tablehead,tableheadcell,tablerow):…
Browse files Browse the repository at this point in the history
… convert to TypeScript and export types
  • Loading branch information
WesSouza authored and arturbien committed Jul 27, 2022
1 parent 64e4279 commit 33f52e9
Show file tree
Hide file tree
Showing 19 changed files with 241 additions and 262 deletions.
20 changes: 10 additions & 10 deletions src/Table/Table.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ name: Table
menu: Components
---

import Table from './Table'
import TableBody from '../TableBody/TableBody'
import TableHead from '../TableHead/TableHead'
import TableRow from '../TableRow/TableRow'
import TableHeadCell from '../TableHeadCell/TableHeadCell'
import TableDataCell from '../TableDataCell/TableDataCell'
import Window from '../Window/Window'
import WindowHeader from '../WindowHeader/WindowHeader'
import WindowContent from '../WindowContent/WindowContent'
import { Table } from './Table';
import { TableBody } from '../TableBody/TableBody';
import { TableHead } from '../TableHead/TableHead';
import { TableRow } from '../TableRow/TableRow';
import { TableHeadCell } from '../TableHeadCell/TableHeadCell';
import { TableDataCell } from '../TableDataCell/TableDataCell';
import Window from '../Window/Window';
import WindowHeader from '../WindowHeader/WindowHeader';
import WindowContent from '../WindowContent/WindowContent';

# Table

## Usage

<Playground>
<Window style={{ width: 320 }}>
<Window style={{ width: 320 }}>
<WindowHeader>Pokedex.exe</WindowHeader>
<WindowContent>
<Table>
Expand Down
8 changes: 3 additions & 5 deletions src/Table/Table.spec.js → src/Table/Table.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import React from 'react';

import { renderWithTheme } from '../../test/utils';

import Table from './Table';
import { Table } from './Table';

describe('<Table />', () => {
it('renders Table', () => {
const { container } = renderWithTheme(<Table />);
const list = container.firstChild;
const table = container.firstElementChild;

expect(list).toBeInTheDocument();
expect(table).toBeInTheDocument();
});
it('renders table element', () => {
const { getByRole } = renderWithTheme(<Table />);
Expand Down
17 changes: 8 additions & 9 deletions src/Table/Table.stories.js → src/Table/Table.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import React from 'react';
import styled from 'styled-components';

import { ComponentMeta } from '@storybook/react';
import {
Table,
TableBody,
TableDataCell,
TableHead,
TableRow,
TableHeadCell,
TableDataCell,
TableRow,
Window,
WindowHeader,
WindowContent
WindowContent,
WindowHeader
} from 'react95';
import styled from 'styled-components';

const Wrapper = styled.div`
padding: 5rem;
Expand All @@ -30,7 +29,7 @@ export default {
TableDataCell
},
decorators: [story => <Wrapper>{story()}</Wrapper>]
};
} as ComponentMeta<typeof Table>;

export function Default() {
return (
Expand All @@ -39,7 +38,7 @@ export function Default() {
<WindowContent>
<Table>
<TableHead>
<TableRow head>
<TableRow>
<TableHeadCell>Type</TableHeadCell>
<TableHeadCell>Name</TableHeadCell>
<TableHeadCell disabled>Level</TableHeadCell>
Expand Down
27 changes: 12 additions & 15 deletions src/Table/Table.js → src/Table/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import React from 'react';
import propTypes from 'prop-types';

import React, { forwardRef } from 'react';
import styled from 'styled-components';
import { StyledCutout } from '../Cutout/Cutout';
import { CommonStyledProps } from '../types';

type TableProps = {
children?: React.ReactNode;
} & React.TableHTMLAttributes<HTMLTableElement> &
CommonStyledProps;

const StyledTable = styled.table`
display: table;
Expand All @@ -18,9 +22,10 @@ const Wrapper = styled(StyledCutout)`
}
`;

const Table = React.forwardRef(function Table(props, ref) {
const { children, ...otherProps } = props;

const Table = forwardRef<HTMLTableElement, TableProps>(function Table(
{ children, ...otherProps },
ref
) {
return (
<Wrapper>
<StyledTable ref={ref} {...otherProps}>
Expand All @@ -30,12 +35,4 @@ const Table = React.forwardRef(function Table(props, ref) {
);
});

Table.defaultProps = {
children: null
};

Table.propTypes = {
children: propTypes.node
};

export default Table;
export { Table, TableProps };
32 changes: 0 additions & 32 deletions src/TableBody/TableBody.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import React from 'react';

import { renderWithTheme } from '../../test/utils';

import TableBody from './TableBody';
import { TableBody } from './TableBody';

describe('<TableBody />', () => {
function mountInTable(node) {
function mountInTable(node: React.ReactNode) {
const { container, getByTestId } = renderWithTheme(<table>{node}</table>);
return {
tbody: container.querySelector('table').firstChild,
tbody: container.querySelector('table')?.firstElementChild,
getByTestId
};
}
Expand All @@ -17,7 +17,7 @@ describe('<TableBody />', () => {
const { tbody } = mountInTable(<TableBody />);

expect(tbody).toBeInTheDocument();
expect(tbody.tagName).toBe('TBODY');
expect(tbody?.tagName).toBe('TBODY');
});

it('renders children', () => {
Expand Down
28 changes: 28 additions & 0 deletions src/TableBody/TableBody.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { forwardRef } from 'react';
import styled from 'styled-components';
import { insetShadow } from '../common';
import { CommonStyledProps } from '../types';

type TableBodyProps = {
children?: React.ReactNode;
} & React.HTMLAttributes<HTMLTableSectionElement> &
CommonStyledProps;

const StyledTableBody = styled.tbody`
background: ${({ theme }) => theme.canvas};
display: table-row-group;
box-shadow: ${insetShadow};
overflow-y: auto;
`;

const TableBody = forwardRef<HTMLTableSectionElement, TableBodyProps>(
function TableBody({ children, ...otherProps }, ref) {
return (
<StyledTableBody ref={ref} {...otherProps}>
{children}
</StyledTableBody>
);
}
);

export { TableBody, TableBodyProps };
26 changes: 0 additions & 26 deletions src/TableDataCell/TableDataCell.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import React from 'react';

import { renderWithTheme } from '../../test/utils';

import TableDataCell from './TableDataCell';
import { TableDataCell } from './TableDataCell';

describe('<TableDataCell />', () => {
function mountInTable(node) {
function mountInTable(node: React.ReactNode) {
const { container, getByText } = renderWithTheme(
<table>
<tbody>
Expand All @@ -14,14 +14,14 @@ describe('<TableDataCell />', () => {
</table>
);
return {
td: container.querySelector('tr').firstChild,
td: container.querySelector('tr')?.firstElementChild,
getByText
};
}

it('renders TableDataCell', () => {
const { td } = mountInTable(<TableDataCell />);
expect(td.tagName).toBe('TD');
expect(td?.tagName).toBe('TD');
});

it('renders children', () => {
Expand Down
24 changes: 24 additions & 0 deletions src/TableDataCell/TableDataCell.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, { forwardRef } from 'react';
import styled from 'styled-components';
import { CommonStyledProps } from '../types';

type TableDataCellProps = {
children?: React.ReactNode;
} & React.HTMLAttributes<HTMLTableCellElement> &
CommonStyledProps;

const StyledTd = styled.td`
padding: 0 8px;
`;

const TableDataCell = forwardRef<HTMLTableCellElement, TableDataCellProps>(
function TableDataCell({ children, ...otherProps }, ref) {
return (
<StyledTd ref={ref} {...otherProps}>
{children}
</StyledTd>
);
}
);

export { TableDataCell, TableDataCellProps };
25 changes: 0 additions & 25 deletions src/TableHead/TableHead.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import React from 'react';

import { renderWithTheme } from '../../test/utils';

import TableHead from './TableHead';
import { TableHead } from './TableHead';

describe('<TableHead />', () => {
function mountInTable(node) {
function mountInTable(node: React.ReactNode) {
const { container, getByTestId } = renderWithTheme(<table>{node}</table>);
return {
tbody: container.querySelector('table').firstChild,
tbody: container.querySelector('table')?.firstElementChild,
getByTestId
};
}
Expand All @@ -17,7 +17,7 @@ describe('<TableHead />', () => {
const { tbody } = mountInTable(<TableHead />);

expect(tbody).toBeInTheDocument();
expect(tbody.tagName).toBe('THEAD');
expect(tbody?.tagName).toBe('THEAD');
});

it('renders children', () => {
Expand Down
23 changes: 23 additions & 0 deletions src/TableHead/TableHead.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React, { forwardRef } from 'react';
import styled from 'styled-components';
import { CommonStyledProps } from '../types';

type TableHeadProps = {
children?: React.ReactNode;
} & React.HTMLAttributes<HTMLTableSectionElement> &
CommonStyledProps;

const StyledTableHead = styled.thead`
display: table-header-group;
`;
const TableHead = forwardRef<HTMLTableSectionElement, TableHeadProps>(
function TableHead({ children, ...otherProps }, ref) {
return (
<StyledTableHead ref={ref} {...otherProps}>
{children}
</StyledTableHead>
);
}
);

export { TableHead, TableHeadProps };
Loading

0 comments on commit 33f52e9

Please sign in to comment.