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 new feature: Created Table Component #103

Merged
merged 4 commits into from
Oct 6, 2023
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
39 changes: 39 additions & 0 deletions src/packages/Table/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React, { ReactNode } from 'react'
import * as S from './style'

export interface TableColumn {
title: string
key: string
}

export interface TableRow {
[key: string]: ReactNode
}

export interface TableProps {
columns: TableColumn[]
data: TableRow[]
}

const Table: React.FC<TableProps> = ({ columns, data }) => {
return (
<S.Table>
<S.TableHead>
{columns.map((column) => (
<S.TableHeaderCell key={column.key}>{column.title}</S.TableHeaderCell>
))}
</S.TableHead>
<S.TableBody>
{data.map((row, index) => (
<tr key={index}>
{columns.map((column) => (
<S.TableCell key={column.key}>{row[column.key]}</S.TableCell>
))}
</tr>
))}
</S.TableBody>
</S.Table>
)
}

export default Table
28 changes: 28 additions & 0 deletions src/packages/Table/stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react'
import { StoryFn, Meta } from '@storybook/react'
import Table, { TableProps } from '.'

export default {
title: 'Table',
component: Table
} as Meta

const columns = [
{ title: 'Name', key: 'name' },
{ title: 'Age', key: 'age' },
{ title: 'Country', key: 'country' }
]

const data = [
{ name: 'John', age: 30, country: 'USA' },
{ name: 'Alice', age: 25, country: 'Canada' },
{ name: 'Bob', age: 35, country: 'UK' }
]

const Template: StoryFn<TableProps> = (args) => <Table {...args} />

export const Default = Template.bind({})
Default.args = {
columns,
data
}
35 changes: 35 additions & 0 deletions src/packages/Table/style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import styled, { css } from 'styled-components'

export const Table = styled.table`
${({ theme }) => css`
width: 100%;
border-collapse: collapse;
border-width: ${theme.border.xxsmall}
border-style: solid;
border-color: ${theme.colors.primary.light};
`}
`

export const TableHead = styled.thead`
${({ theme }) => css`
background-color: ${theme.colors.base.info};
`}
`

export const TableHeaderCell = styled.th`
${({ theme }) => css`
padding: ${theme.spacings.xxsmall};
border: ${theme.border.mini} solid ${theme.colors.primary.dark};
`}
`

export const TableBody = styled.tbody``

export const TableCell = styled.td`
${({ theme }) => css`
padding: ${theme.spacings.xxsmall};
border: ${theme.border.mini} solid ${theme.colors.primary.dark};
background-color: ${theme.colors.neutral.lighter};
text-align: center;
`}
`
1 change: 1 addition & 0 deletions src/packages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ export { default as Alert } from './Alert'
export { default as Breadcrumb } from './Breadcrumb'
export { default as Skeleton } from './Skeleton'
export { default as Switch } from './Switch'
export { default as Table } from './Table'
// export { default as Pagination } from './Pagination' TODO: review pagination styles and logic