-
Notifications
You must be signed in to change notification settings - Fork 20
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(ui): #1977: TableCell
#1979
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3e77426
feat(ui): add Skeleton component
VanishMax fcf909a
feat(ui): implement responsive typography
VanishMax 3a3e223
feat(ui): add `bodyTechnical` text style
VanishMax ad8e3dc
chore: changeset
VanishMax 3fb7a47
feat(ui): #1977: add `TableCell` UI component
VanishMax 0420f00
chore: changeset
VanishMax 4dd9e52
Merge remote-tracking branch 'origin/main' into feat/ui-skeleton-texts
VanishMax f402ec2
Merge remote-tracking branch 'origin/feat/ui-skeleton-texts' into fea…
VanishMax 2d636a5
Merge remote-tracking branch 'origin/main' into feat/#1977-table-cell
VanishMax 4aa7c96
fix(ui): add `as` param to TableCell
VanishMax File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@penumbra-zone/ui': minor | ||
--- | ||
|
||
Add `TableCell` UI component |
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,54 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { TableCell } from '.'; | ||
import { Pill } from '../Pill'; | ||
|
||
const meta: Meta<typeof TableCell> = { | ||
component: TableCell, | ||
tags: ['autodocs', '!dev', 'density'], | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof TableCell>; | ||
|
||
export const Basic: Story = { | ||
render: function Render() { | ||
return ( | ||
<div className='grid grid-cols-5'> | ||
<div className='col-span-5 grid grid-cols-subgrid'> | ||
<TableCell heading>Name</TableCell> | ||
<TableCell heading>Loading</TableCell> | ||
<TableCell heading>Price</TableCell> | ||
<TableCell heading>Amount</TableCell> | ||
<TableCell heading>Number</TableCell> | ||
</div> | ||
<div className='col-span-5 grid grid-cols-subgrid'> | ||
<TableCell cell>Hello</TableCell> | ||
<TableCell cell loading={true}> | ||
World | ||
</TableCell> | ||
<TableCell cell>What</TableCell> | ||
<TableCell cell> | ||
<Pill>Pending</Pill> | ||
</TableCell> | ||
<TableCell cell numeric> | ||
11.1111 | ||
</TableCell> | ||
</div> | ||
<div className='col-span-5 grid grid-cols-subgrid'> | ||
<TableCell footer>Hello</TableCell> | ||
<TableCell footer loading={true}> | ||
World | ||
</TableCell> | ||
<TableCell footer>What</TableCell> | ||
<TableCell footer> | ||
<Pill>Pending</Pill> | ||
</TableCell> | ||
<TableCell footer numeric> | ||
88.2222 | ||
</TableCell> | ||
</div> | ||
</div> | ||
); | ||
}, | ||
}; |
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,133 @@ | ||
import cn from 'clsx'; | ||
import { ElementType, ReactNode } from 'react'; | ||
import { Density, useDensity } from '../utils/density'; | ||
import { Skeleton } from '../Skeleton'; | ||
import { | ||
tableHeading, | ||
tableHeadingMedium, | ||
tableHeadingSmall, | ||
tableItem, | ||
tableItemMedium, | ||
tableItemSmall, | ||
} from '../utils/typography'; | ||
|
||
export type TableCellVariant = 'title' | 'heading' | 'cell' | 'lastCell' | 'footer'; | ||
|
||
type TableCellType = { | ||
[K in TableCellVariant]: Record<K, true> & Partial<Record<Exclude<TableCellVariant, K>, never>>; | ||
}[TableCellVariant]; | ||
|
||
type TableCellPropType = | ||
| (TableCellType & { variant?: never }) | ||
| (Partial<Record<TableCellVariant, never>> & { | ||
/** dynamic table cell type: `'title' | 'heading' | 'cell' | 'lastCell' | 'footer'` */ | ||
variant?: TableCellVariant; | ||
}); | ||
|
||
export type TableCellProps = TableCellPropType & { | ||
children: ReactNode; | ||
as?: ElementType; | ||
loading?: boolean; | ||
/** Renders numbers in a monospace font with letters of equal size */ | ||
numeric?: boolean; | ||
}; | ||
|
||
const classesByVariant: Record<TableCellVariant, string> = { | ||
title: cn('text-text-primary'), | ||
heading: cn('text-text-secondary border-b border-b-other-tonalStroke'), | ||
cell: cn('text-text-primary border-b border-b-other-tonalStroke'), | ||
lastCell: cn('text-text-primary'), | ||
footer: cn('text-text-secondary'), | ||
}; | ||
|
||
const classesByDensity: Record<Density, string> = { | ||
sparse: 'py-1 px-3 h-14', | ||
compact: 'py-1 px-3 h-12', | ||
slim: 'py-1 px-3 h-8', | ||
}; | ||
|
||
const defaultFont: Record<Density, string> = { | ||
sparse: tableItem, | ||
compact: tableItemMedium, | ||
slim: tableItemSmall, | ||
}; | ||
|
||
const headingFont: Record<Density, string> = { | ||
sparse: tableHeading, | ||
compact: tableHeadingMedium, | ||
slim: tableHeadingSmall, | ||
}; | ||
|
||
/** | ||
* **TableCell** is a unified component for tables within Penumbra ecosystem. | ||
* It has multiple style variants: | ||
* | ||
* 1. `heading` – darkened bold text | ||
* 2. `cell` – regular info cell | ||
* 3. `title` – emphasized cell | ||
* 4. `lastCell` – borderless cell | ||
* 5. `footer` – borderless darkened cell | ||
* | ||
* You can pass the variant as a named prop (`<TableCell heading />`) or dynamically as a string (`<TableCell variant='heading' />`). | ||
* | ||
* Use `numeric` prop to render numbers in a monospace font with letters of equal size. | ||
* | ||
* Example table with **TableCell**: | ||
* | ||
* ```tsx | ||
* <div className='grid grid-cols-3'> | ||
* <div className='col-span-3 grid grid-cols-subgrid'> | ||
* <TableCell heading>Name</TableCell> | ||
* <TableCell heading>Pill</TableCell> | ||
* <TableCell heading>Amount</TableCell> | ||
* </div> | ||
* <div className='col-span-3 grid grid-cols-subgrid'> | ||
* <TableCell cell loading>Hello</TableCell> | ||
* <TableCell cell> | ||
* <Pill>Pending</Pill> | ||
* </TableCell> | ||
* <TableCell cell numeric> | ||
* 11.1111 | ||
* </TableCell> | ||
* </div> | ||
* </div> | ||
* ``` | ||
*/ | ||
export const TableCell = ({ | ||
children, | ||
loading, | ||
numeric, | ||
as: Container = 'div', | ||
...props | ||
}: TableCellProps) => { | ||
const density = useDensity(); | ||
const type: TableCellVariant = | ||
props.variant ?? | ||
(props.title && 'title') ?? | ||
(props.heading && 'heading') ?? | ||
(props.lastCell && 'lastCell') ?? | ||
(props.footer && 'footer') ?? | ||
(props.cell && 'cell') ?? | ||
'cell'; | ||
|
||
return ( | ||
<Container | ||
className={cn( | ||
'flex items-center gap-2', | ||
classesByVariant[type], | ||
classesByDensity[density], | ||
type === 'heading' ? headingFont[density] : defaultFont[density], | ||
numeric && 'font-mono tabular-nums', | ||
)} | ||
> | ||
{loading ? ( | ||
<div className='h-1/2 w-full max-w-14'> | ||
<Skeleton /> | ||
</div> | ||
) : ( | ||
children | ||
)} | ||
</Container> | ||
); | ||
}; | ||
TableCell.displayName = 'TableCell'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference between title and heading?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copied from Figma but never seen
title
being actually used in there