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

feat: update default table style #114

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
11 changes: 3 additions & 8 deletions apps/mibao-ui-docs/src/app/pages/table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ export default {
control: { type: 'select' }
},
variant: {
options: ['unstyled', 'simple', 'striped'],
control: { type: 'select' }
},
theadVariant: {
options: ['filled', 'unstyled'],
options: ['unstyled', 'simple', 'striped', 'filled'],
control: { type: 'select' }
}
}
Expand All @@ -39,14 +35,13 @@ const args = {
size: 'md',
isNumeric: false,
placement: 'bottom' as 'top' | 'bottom',
variant: 'simple',
theadVariant: 'filled' as 'filled' | 'unstyled'
variant: 'simple'
}

const Template: Story<typeof args> = (args) => <MibaoProvider>
<MibaoTable size={args.size} variant={args.variant} colorScheme="primary">
<TableCaption placement={args.placement}>Imperial to metric conversion factors</TableCaption>
<Thead variant={args.theadVariant}>
<Thead>
<Tr>
<Th>Type</Th>
<Th>Order</Th>
Expand Down
73 changes: 48 additions & 25 deletions libs/mibao-ui/src/lib/table/table.tsx
Original file line number Diff line number Diff line change
@@ -1,59 +1,82 @@
import './table.module.scss'

import {
Table,
Thead as RowThead,
Table as RawTable,
Thead,
Tbody,
Tfoot,
Tr,
Th as RowTh,
Th,
Td,
TableCaption as RowTableCaption,
TableCaption,
TableHeadProps,
TableBodyProps,
TableProps,
TableProps as RawTableProps,
TableRowProps,
TableColumnHeaderProps,
TableCellProps,
TableCaptionProps
} from '@chakra-ui/react'
import React from 'react'
import styled from '@emotion/styled'

export {
Table,
Thead,
Tbody,
Tfoot,
Tr,
Th,
Td,
TableCaption,
TableHeadProps,
TableBodyProps,
TableProps,
TableRowProps,
TableColumnHeaderProps,
TableCellProps,
TableCaptionProps
}

export const Thead: React.FC<TableHeadProps & { variant: 'filled' | 'unstyled' }> = (props) => {
const variant = props.variant ?? 'unstyled'
return <RowThead
bg={variant === 'filled' ? 'var(--chakra-colors-primary-100)' : undefined}
{...props}
>{props.children}</RowThead>
export interface TableProps extends RawTableProps {
variant: RawTableProps['variant'] | 'filled'
}

export const Th: React.FC<TableColumnHeaderProps> = (props) => {
return (
<RowTh
textTransform="none"
>{props.children}</RowTh>
)
const TableStyled = styled(RawTable)`
${({ _variant }: TableProps & { _variant?: TableProps['variant'] }) => _variant === 'filled'
? `
thead, tfoot {
th {
background-color: var(--chakra-colors-primary-100);
}
}
thead {
th:first-child {
border-top-left-radius: 6px;
}
th:last-child {
border-top-right-radius: 6px;
}
}
tfoot {
th:first-child {
border-bottom-left-radius: 6px;
}
th:last-child {
border-bottom-right-radius: 6px;
}
}
`
: undefined
}
`

export const TableCaption: React.FC<TableCaptionProps> = (props) => {
return (
<RowTableCaption
textTransform="none"
>{props.children}</RowTableCaption>
)
export const Table: React.FC<TableProps> = ({
children,
variant = 'simple',
...props
}) => {
return <TableStyled
variant={variant === 'filled' ? 'simple' : variant}
_variant={variant}
{...props}
>{children}</TableStyled>
}
26 changes: 26 additions & 0 deletions libs/mibao-ui/src/theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,32 @@ export const mibaoTheme = extendTheme({
fallbacks: {
avatar: FALL_BACK_SRC,
nft: FALL_BACK_SRC
},
components: {
Table: {
baseStyle: {
th: {
textTransform: 'none'
}
},
sizes: {
sm: {
td: {
fontSize: '12px'
}
},
md: {
td: {
fontSize: '14px'
}
},
lg: {
td: {
fontSize: '14px'
}
}
}
}
}
})

Expand Down